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

Commit 66e4a2b8 authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Do not allow ephemeral apps to access ShortcutManager

Bug: 34178279
Test: adb shell am instrument -e class com.android.server.pm.ShortcutManagerTest1 -w com.android.frameworks.servicestests
Test: adb shell am instrument -e class com.android.server.pm.ShortcutManagerTest2 -w com.android.frameworks.servicestests
Test: adb shell am instrument -e class com.android.server.pm.ShortcutManagerTest3 -w com.android.frameworks.servicestests
Test: adb shell am instrument -e class com.android.server.pm.ShortcutManagerTest4 -w com.android.frameworks.servicestests
Test: adb shell am instrument -e class com.android.server.pm.ShortcutManagerTest5 -w com.android.frameworks.servicestests
Test: adb shell am instrument -e class com.android.server.pm.ShortcutManagerTest6 -w com.android.frameworks.servicestests
Test: adb shell am instrument -e class com.android.server.pm.ShortcutManagerTest7 -w com.android.frameworks.servicestests
Test: adb shell am instrument -e class com.android.server.pm.ShortcutManagerTest8 -w com.android.frameworks.servicestests
Test: adb shell am instrument -e class com.android.server.pm.ShortcutManagerTest9 -w com.android.frameworks.servicestests
Test: adb shell am instrument -e class com.android.server.pm.ShortcutManagerTest10 -w com.android.frameworks.servicestests

Change-Id: I5672f15705a1bf6568a8df58b66e48c802c11852
parent 22040a53
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -1529,11 +1529,12 @@ public class ShortcutService extends IShortcutService.Stub {
        if (UserHandle.getUserId(callingUid) != userId) {
            throw new SecurityException("Invalid user-ID");
        }
        if (injectGetPackageUid(packageName, userId) == callingUid) {
            return; // Caller is valid.
        }
        if (injectGetPackageUid(packageName, userId) != callingUid) {
            throw new SecurityException("Calling package name mismatch");
        }
        Preconditions.checkState(!isEphemeralApp(packageName, userId),
                "Ephemeral apps can't use ShortcutManager");
    }

    // Overridden in unit tests to execute r synchronously.
    void injectPostToHandler(Runnable r) {
@@ -3073,6 +3074,10 @@ public class ShortcutService extends IShortcutService.Stub {
        return (ai != null) && (ai.flags & ApplicationInfo.FLAG_INSTALLED) != 0;
    }

    private static boolean isEphemeralApp(@Nullable ApplicationInfo ai) {
        return (ai != null) && ai.isEphemeralApp();
    }

    private static boolean isInstalled(@Nullable PackageInfo pi) {
        return (pi != null) && isInstalled(pi.applicationInfo);
    }
@@ -3097,6 +3102,10 @@ public class ShortcutService extends IShortcutService.Stub {
        return getApplicationInfo(packageName, userId) != null;
    }

    boolean isEphemeralApp(String packageName, int userId) {
        return isEphemeralApp(getApplicationInfo(packageName, userId));
    }

    @Nullable
    XmlResourceParser injectXmlMetaData(ActivityInfo activityInfo, String key) {
        return activityInfo.loadXmlMetaData(mContext.getPackageManager(), key);
+5 −0
Original line number Diff line number Diff line
@@ -566,6 +566,7 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase {
    protected Map<String, PackageInfo> mInjectedPackages;

    protected Set<PackageWithUser> mUninstalledPackages;
    protected Set<PackageWithUser> mEphemeralPackages;
    protected Set<String> mSystemPackages;

    protected PackageManager mMockPackageManager;
@@ -731,6 +732,7 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase {

        mUninstalledPackages = new HashSet<>();
        mSystemPackages = new HashSet<>();
        mEphemeralPackages = new HashSet<>();

        mInjectedFilePathRoot = new File(getTestContext().getCacheDir(), "test-files");

@@ -1034,6 +1036,9 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase {
        if (mUninstalledPackages.contains(PackageWithUser.of(userId, packageName))) {
            ret.applicationInfo.flags &= ~ApplicationInfo.FLAG_INSTALLED;
        }
        if (mEphemeralPackages.contains(PackageWithUser.of(userId, packageName))) {
            ret.applicationInfo.privateFlags |= ApplicationInfo.PRIVATE_FLAG_EPHEMERAL;
        }
        if (mSystemPackages.contains(packageName)) {
            ret.applicationInfo.flags |= ApplicationInfo.FLAG_SYSTEM;
        }
+29 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import android.test.suitebuilder.annotation.SmallTest;

import com.android.frameworks.servicestests.R;
import com.android.server.pm.ShortcutService.ConfigConstants;
import com.android.server.pm.ShortcutUser.PackageWithUser;

import java.io.File;
import java.io.FileWriter;
@@ -2037,4 +2038,32 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest {
        assertFalse(mService.isUserUnlockedL(USER_0));
        assertFalse(mService.isUserUnlockedL(USER_10));
    }

    public void testEphemeralApp() {
        mRunningUsers.put(USER_10, true); // this test needs user 10.

        runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
            assertWith(mManager.getDynamicShortcuts()).isEmpty();
        });
        runWithCaller(CALLING_PACKAGE_1, USER_10, () -> {
            assertWith(mManager.getDynamicShortcuts()).isEmpty();
        });
        runWithCaller(CALLING_PACKAGE_2, USER_0, () -> {
            assertWith(mManager.getDynamicShortcuts()).isEmpty();
        });
        // Make package 1 ephemeral.
        mEphemeralPackages.add(PackageWithUser.of(USER_0, CALLING_PACKAGE_1));

        runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
            assertExpectException(IllegalStateException.class, "Ephemeral apps", () -> {
                mManager.getDynamicShortcuts();
            });
        });
        runWithCaller(CALLING_PACKAGE_1, USER_10, () -> {
            assertWith(mManager.getDynamicShortcuts()).isEmpty();
        });
        runWithCaller(CALLING_PACKAGE_2, USER_0, () -> {
            assertWith(mManager.getDynamicShortcuts()).isEmpty();
        });
    }
}