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

Commit 96da6703 authored by Jackal Guo's avatar Jackal Guo Committed by Android (Google) Code Review
Browse files

Merge "Allow an app to see its update owner"

parents 8d6fb369 8cbb2bd3
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import static com.android.internal.util.FrameworkStatsLog.PACKAGE_MANAGER_APPS_F
import static com.android.internal.util.FrameworkStatsLog.PACKAGE_MANAGER_APPS_FILTER_CACHE_UPDATE_REPORTED__EVENT_TYPE__PACKAGE_DELETED;
import static com.android.internal.util.FrameworkStatsLog.PACKAGE_MANAGER_APPS_FILTER_CACHE_UPDATE_REPORTED__EVENT_TYPE__PACKAGE_REPLACED;
import static com.android.server.pm.AppsFilterUtils.canQueryAsInstaller;
import static com.android.server.pm.AppsFilterUtils.canQueryAsUpdateOwner;
import static com.android.server.pm.AppsFilterUtils.canQueryViaComponents;
import static com.android.server.pm.AppsFilterUtils.canQueryViaPackage;
import static com.android.server.pm.AppsFilterUtils.canQueryViaUsesLibrary;
@@ -670,7 +671,8 @@ public final class AppsFilterImpl extends AppsFilterLocked implements Watchable,
                    }
                }
                if (canQueryViaPackage(existingPkg, newPkg)
                        || canQueryAsInstaller(existingSetting, newPkg)) {
                        || canQueryAsInstaller(existingSetting, newPkg)
                        || canQueryAsUpdateOwner(existingSetting, newPkg)) {
                    synchronized (mQueriesViaPackageLock) {
                        mQueriesViaPackage.add(existingSetting.getAppId(),
                                newPkgSetting.getAppId());
@@ -697,7 +699,8 @@ public final class AppsFilterImpl extends AppsFilterLocked implements Watchable,
                    }
                }
                if (canQueryViaPackage(newPkg, existingPkg)
                        || canQueryAsInstaller(newPkgSetting, existingPkg)) {
                        || canQueryAsInstaller(newPkgSetting, existingPkg)
                        || canQueryAsUpdateOwner(newPkgSetting, existingPkg)) {
                    synchronized (mQueriesViaPackageLock) {
                        mQueriesViaPackage.add(newPkgSetting.getAppId(),
                                existingSetting.getAppId());
+9 −0
Original line number Diff line number Diff line
@@ -91,6 +91,15 @@ final class AppsFilterUtils {
        return false;
    }

    public static boolean canQueryAsUpdateOwner(PackageStateInternal querying,
            AndroidPackage potentialTarget) {
        final InstallSource installSource = querying.getInstallSource();
        if (potentialTarget.getPackageName().equals(installSource.mUpdateOwnerPackageName)) {
            return true;
        }
        return false;
    }

    public static boolean canQueryViaUsesLibrary(AndroidPackage querying,
            AndroidPackage potentialTarget) {
        if (potentialTarget.getLibraryNames().isEmpty()) {
+33 −4
Original line number Diff line number Diff line
@@ -283,7 +283,7 @@ public class AppsFilterImplTest {
        assertFalse(
                appsFilter.shouldFilterApplication(mSnapshot, DUMMY_CALLING_APPID, calling, target,
                        SYSTEM_USER));
        watcher.verifyNoChangeReported("shouldFilterAplication");
        watcher.verifyNoChangeReported("shouldFilterApplication");
    }

    @Test
@@ -1081,7 +1081,7 @@ public class AppsFilterImplTest {
        assertTrue(
                appsFilter.shouldFilterApplication(mSnapshot, DUMMY_CALLING_APPID, calling, target,
                        SYSTEM_USER));
        watcher.verifyNoChangeReported("shouldFilterAplication");
        watcher.verifyNoChangeReported("shouldFilterApplication");
    }

    @Test
@@ -1110,7 +1110,36 @@ public class AppsFilterImplTest {
        assertFalse(
                appsFilter.shouldFilterApplication(mSnapshot, DUMMY_CALLING_APPID, calling, target,
                        SYSTEM_USER));
        watcher.verifyNoChangeReported("shouldFilterAplication");
        watcher.verifyNoChangeReported("shouldFilterApplication");
    }

    @Test
    public void testUpdateOwner_DoesntFilter() throws Exception {
        final AppsFilterImpl appsFilter =
                new AppsFilterImpl(mFeatureConfigMock, new String[]{}, /* systemAppsQueryable */
                        false, /* overlayProvider */ null, mMockHandler);
        final WatchableTester watcher = new WatchableTester(appsFilter, "onChange");
        watcher.register();
        simulateAddBasicAndroid(appsFilter);
        watcher.verifyChangeReported("addBasicAndroid");
        appsFilter.onSystemReady(mPmInternal);
        watcher.verifyChangeReported("systemReady");

        PackageSetting target = simulateAddPackage(appsFilter, pkg("com.some.package"),
                DUMMY_TARGET_APPID);
        watcher.verifyChangeReported("add package");
        PackageSetting calling = simulateAddPackage(appsFilter, pkg("com.some.other.package"),
                DUMMY_CALLING_APPID, withInstallSource(null /* initiatingPackageName */,
                        null /* originatingPackageName */, null /* installerPackageName */,
                        INVALID_UID, target.getPackageName(),
                        null /* installerAttributionTag */,
                        false /* isInitiatingPackageUninstalled */));
        watcher.verifyChangeReported("add package");

        assertFalse(
                appsFilter.shouldFilterApplication(mSnapshot, DUMMY_CALLING_APPID, calling, target,
                        SYSTEM_USER));
        watcher.verifyNoChangeReported("shouldFilterApplication");
    }

    @Test
@@ -1139,7 +1168,7 @@ public class AppsFilterImplTest {
        assertFalse(
                appsFilter.shouldFilterApplication(mSnapshot, DUMMY_TARGET_APPID, target,
                        instrumentation, SYSTEM_USER));
        watcher.verifyNoChangeReported("shouldFilterAplication");
        watcher.verifyNoChangeReported("shouldFilterApplication");
    }

    @Test