Allow an app to see its update owner

Same as installer of record, an app is automatically granted package
visibility to its update owner. This CL also adds the corresponding
unit test.

Fix: 264605593
Test: atest PackageManagerServiceServerTests:AppsFilterImplTest
Change-Id: I96aa03e25d8668654681c4c64b0ec56c71874676
This commit is contained in:
Jackal Guo
2023-01-10 10:43:10 +08:00
parent ec1c3c0193
commit 8cbb2bd397
3 changed files with 47 additions and 6 deletions

View File

@@ -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());

View File

@@ -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()) {

View File

@@ -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