Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fac43abf authored by Jackal Guo's avatar Jackal Guo Committed by Automerger Merge Worker
Browse files

Merge "Enforce owner rights check to setSplashScreenTheme" into sc-v2-dev am: 7cbd05ad

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16366224

Change-Id: I24871985ff51c96fa6679ad984b99acbf99d11bf
parents b578401c 7cbd05ad
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -28859,8 +28859,12 @@ public class PackageManagerService extends IPackageManager.Stub
    @Override
    public void setSplashScreenTheme(@NonNull String packageName, @Nullable String themeId,
            int userId) {
        int callingUid = Binder.getCallingUid();
        PackageSetting packageSetting = getPackageSettingForUser(packageName, callingUid, userId);
        final int callingUid = Binder.getCallingUid();
        enforceCrossUserPermission(callingUid, userId, false /* requireFullPermission */,
                false /* checkShell */, "setSplashScreenTheme");
        enforceOwnerRights(packageName, callingUid);
        final PackageSetting packageSetting = getPackageSettingForUser(packageName, callingUid,
                userId);
        if (packageSetting != null) {
            packageSetting.setSplashScreenTheme(userId, themeId);
        }
+1 −0
Original line number Diff line number Diff line
@@ -110,6 +110,7 @@ android_test {

    data: [
        ":JobTestApp",
        ":StubTestApp",
    ],

    java_resources: [
+11 −0
Original line number Diff line number Diff line
@@ -28,6 +28,17 @@
        <option name="test-file-name" value="SimpleServiceTestApp3.apk" />
    </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" />
    <test class="com.android.tradefed.testtype.AndroidJUnitTest" >
        <option name="package" value="com.android.frameworks.servicestests" />
+37 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.server.pm;

import static com.android.compatibility.common.util.ShellUtils.runShellCommand;

import static com.google.common.truth.Truth.assertWithMessage;

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 android.annotation.Nullable;
import android.app.AppGlobals;
import android.content.IIntentReceiver;
import android.content.pm.IPackageManager;
import android.content.pm.PackageManagerInternal;
import android.os.Bundle;
import android.os.UserHandle;
import android.util.SparseArray;

import androidx.test.runner.AndroidJUnit4;
@@ -62,8 +67,18 @@ import java.util.regex.Pattern;
// bit FrameworksServicesTests:com.android.server.pm.PackageManagerServiceTest
@RunWith(AndroidJUnit4.class)
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
    public void setUp() throws Exception {
        mIPackageManager = AppGlobals.getPackageManager();
    }

    @After
@@ -599,4 +614,26 @@ public class PackageManagerServiceTest {
        Collections.sort(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 −0
Original line number Diff line number Diff line
// 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,
    },
}
Loading