Merge "Enforce owner rights check to setSplashScreenTheme" into sc-v2-dev
This commit is contained in:
@@ -28825,8 +28825,12 @@ public class PackageManagerService extends IPackageManager.Stub
|
|||||||
@Override
|
@Override
|
||||||
public void setSplashScreenTheme(@NonNull String packageName, @Nullable String themeId,
|
public void setSplashScreenTheme(@NonNull String packageName, @Nullable String themeId,
|
||||||
int userId) {
|
int userId) {
|
||||||
int callingUid = Binder.getCallingUid();
|
final int callingUid = Binder.getCallingUid();
|
||||||
PackageSetting packageSetting = getPackageSettingForUser(packageName, callingUid, userId);
|
enforceCrossUserPermission(callingUid, userId, false /* requireFullPermission */,
|
||||||
|
false /* checkShell */, "setSplashScreenTheme");
|
||||||
|
enforceOwnerRights(packageName, callingUid);
|
||||||
|
final PackageSetting packageSetting = getPackageSettingForUser(packageName, callingUid,
|
||||||
|
userId);
|
||||||
if (packageSetting != null) {
|
if (packageSetting != null) {
|
||||||
packageSetting.setSplashScreenTheme(userId, themeId);
|
packageSetting.setSplashScreenTheme(userId, themeId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ android_test {
|
|||||||
|
|
||||||
data: [
|
data: [
|
||||||
":JobTestApp",
|
":JobTestApp",
|
||||||
|
":StubTestApp",
|
||||||
],
|
],
|
||||||
|
|
||||||
java_resources: [
|
java_resources: [
|
||||||
|
|||||||
@@ -28,6 +28,17 @@
|
|||||||
<option name="test-file-name" value="SimpleServiceTestApp3.apk" />
|
<option name="test-file-name" value="SimpleServiceTestApp3.apk" />
|
||||||
</target_preparer>
|
</target_preparer>
|
||||||
|
|
||||||
|
<!-- Create place to store apks -->
|
||||||
|
<target_preparer class="com.android.tradefed.targetprep.RunCommandTargetPreparer">
|
||||||
|
<option name="run-command" value="mkdir -p /data/local/tmp/servicestests" />
|
||||||
|
<option name="teardown-command" value="rm -rf /data/local/tmp/servicestests"/>
|
||||||
|
</target_preparer>
|
||||||
|
|
||||||
|
<!-- Load additional APKs onto device -->
|
||||||
|
<target_preparer class="com.android.compatibility.common.tradefed.targetprep.FilePusher">
|
||||||
|
<option name="push" value="StubTestApp.apk->/data/local/tmp/servicestests/StubTestApp.apk"/>
|
||||||
|
</target_preparer>
|
||||||
|
|
||||||
<option name="test-tag" value="FrameworksServicesTests" />
|
<option name="test-tag" value="FrameworksServicesTests" />
|
||||||
<test class="com.android.tradefed.testtype.AndroidJUnitTest" >
|
<test class="com.android.tradefed.testtype.AndroidJUnitTest" >
|
||||||
<option name="package" value="com.android.frameworks.servicestests" />
|
<option name="package" value="com.android.frameworks.servicestests" />
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.android.server.pm;
|
package com.android.server.pm;
|
||||||
|
|
||||||
|
import static com.android.compatibility.common.util.ShellUtils.runShellCommand;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertWithMessage;
|
import static com.google.common.truth.Truth.assertWithMessage;
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
@@ -27,9 +29,12 @@ import static java.lang.reflect.Modifier.isPublic;
|
|||||||
import static java.lang.reflect.Modifier.isStatic;
|
import static java.lang.reflect.Modifier.isStatic;
|
||||||
|
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
|
import android.app.AppGlobals;
|
||||||
import android.content.IIntentReceiver;
|
import android.content.IIntentReceiver;
|
||||||
|
import android.content.pm.IPackageManager;
|
||||||
import android.content.pm.PackageManagerInternal;
|
import android.content.pm.PackageManagerInternal;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.UserHandle;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
|
|
||||||
import androidx.test.runner.AndroidJUnit4;
|
import androidx.test.runner.AndroidJUnit4;
|
||||||
@@ -62,8 +67,18 @@ import java.util.regex.Pattern;
|
|||||||
// bit FrameworksServicesTests:com.android.server.pm.PackageManagerServiceTest
|
// bit FrameworksServicesTests:com.android.server.pm.PackageManagerServiceTest
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class PackageManagerServiceTest {
|
public class PackageManagerServiceTest {
|
||||||
|
|
||||||
|
private static final String PACKAGE_NAME = "com.android.frameworks.servicestests";
|
||||||
|
|
||||||
|
private static final String TEST_DATA_PATH = "/data/local/tmp/servicestests/";
|
||||||
|
private static final String TEST_APP_APK = "StubTestApp.apk";
|
||||||
|
private static final String TEST_PKG_NAME = "com.android.servicestests.apps.stubapp";
|
||||||
|
|
||||||
|
private IPackageManager mIPackageManager;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
mIPackageManager = AppGlobals.getPackageManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
@@ -599,4 +614,26 @@ public class PackageManagerServiceTest {
|
|||||||
Collections.sort(knownPackageIds);
|
Collections.sort(knownPackageIds);
|
||||||
return knownPackageIds;
|
return knownPackageIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetSplashScreenTheme_samePackage_succeeds() throws Exception {
|
||||||
|
mIPackageManager.setSplashScreenTheme(PACKAGE_NAME, null /* themeName */,
|
||||||
|
UserHandle.myUserId());
|
||||||
|
// Invoking setSplashScreenTheme on the same package shouldn't get any exception.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetSplashScreenTheme_differentPackage_fails() throws Exception {
|
||||||
|
final File testApk = new File(TEST_DATA_PATH, TEST_APP_APK);
|
||||||
|
try {
|
||||||
|
runShellCommand("pm install " + testApk);
|
||||||
|
mIPackageManager.setSplashScreenTheme(TEST_PKG_NAME, null /* themeName */,
|
||||||
|
UserHandle.myUserId());
|
||||||
|
fail("setSplashScreenTheme did not throw SecurityException as expected");
|
||||||
|
} catch (SecurityException e) {
|
||||||
|
// expected
|
||||||
|
} finally {
|
||||||
|
runShellCommand("pm uninstall " + TEST_PKG_NAME);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
37
services/tests/servicestests/test-apps/StubApp/Android.bp
Normal file
37
services/tests/servicestests/test-apps/StubApp/Android.bp
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
// Copyright (C) 2021 The Android Open Source Project
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package {
|
||||||
|
// See: http://go/android-license-faq
|
||||||
|
// A large-scale-change added 'default_applicable_licenses' to import
|
||||||
|
// all of the 'license_kinds' from "frameworks_base_license"
|
||||||
|
// to get the below license kinds:
|
||||||
|
// SPDX-license-identifier-Apache-2.0
|
||||||
|
default_applicable_licenses: ["frameworks_base_license"],
|
||||||
|
}
|
||||||
|
|
||||||
|
android_test_helper_app {
|
||||||
|
name: "StubTestApp",
|
||||||
|
|
||||||
|
sdk_version: "current",
|
||||||
|
|
||||||
|
srcs: ["**/*.java"],
|
||||||
|
|
||||||
|
dex_preopt: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
|
optimize: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2021 The Android Open Source Project
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="com.android.servicestests.apps.stubapp">
|
||||||
|
|
||||||
|
<application android:label="StubTestApp">
|
||||||
|
<activity android:name=".TestActivity"
|
||||||
|
android:exported="true" />
|
||||||
|
</application>
|
||||||
|
|
||||||
|
</manifest>
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.servicestests.apps.stubapp;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
|
||||||
|
public class TestActivity extends Activity {
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user