Merge "Handle multiple users when adding and rechecking overrides." into sc-dev

This commit is contained in:
Tom Natan
2021-07-03 11:56:43 +00:00
committed by Android (Google) Code Review
4 changed files with 21 additions and 10 deletions

View File

@@ -16,6 +16,8 @@
package com.android.server.compat;
import static android.content.pm.PackageManager.MATCH_ANY_USER;
import android.annotation.Nullable;
import android.app.compat.ChangeIdStateCache;
import android.app.compat.PackageOverride;
@@ -693,7 +695,7 @@ final class CompatConfig {
private Long getVersionCodeOrNull(String packageName) {
try {
ApplicationInfo applicationInfo = mContext.getPackageManager().getApplicationInfo(
packageName, 0);
packageName, MATCH_ANY_USER);
return applicationInfo.longVersionCode;
} catch (PackageManager.NameNotFoundException e) {
return null;

View File

@@ -17,6 +17,7 @@
package com.android.server.compat;
import static android.Manifest.permission.OVERRIDE_COMPAT_CHANGE_CONFIG_ON_RELEASE_BUILD;
import static android.content.pm.PackageManager.MATCH_ANY_USER;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static com.android.internal.compat.OverrideAllowedState.ALLOWED;
@@ -116,7 +117,7 @@ public class OverrideValidatorImpl extends IOverrideValidator.Stub {
}
ApplicationInfo applicationInfo;
try {
applicationInfo = packageManager.getApplicationInfo(packageName, 0);
applicationInfo = packageManager.getApplicationInfo(packageName, MATCH_ANY_USER);
} catch (NameNotFoundException e) {
return new OverrideAllowedState(DEFERRED_VERIFICATION, -1, -1);
}

View File

@@ -81,7 +81,7 @@ public class PlatformCompat extends IPlatformCompat.Stub {
@VisibleForTesting
PlatformCompat(Context context, CompatConfig compatConfig,
AndroidBuildClassifier buildClassifier) {
AndroidBuildClassifier buildClassifier) {
mContext = context;
mChangeReporter = new ChangeReporter(ChangeReporter.SOURCE_SYSTEM_SERVER);
mCompatConfig = compatConfig;
@@ -178,8 +178,8 @@ public class PlatformCompat extends IPlatformCompat.Stub {
*
* <p>Does not perform costly permission check.
*
* @param changeId the ID of the change in question
* @param packageName package name to check for
* @param changeId the ID of the change in question
* @param packageName package name to check for
* @param targetSdkVersion target sdk version to check for
* @return {@code true} if the change would be enabled for this package name.
*/
@@ -456,7 +456,7 @@ public class PlatformCompat extends IPlatformCompat.Stub {
}
if (change.getEnableSinceTargetSdk() > 0) {
return change.getEnableSinceTargetSdk() >= Build.VERSION_CODES.Q
&& change.getEnableSinceTargetSdk() <= mBuildClassifier.platformTargetSdk();
&& change.getEnableSinceTargetSdk() <= mBuildClassifier.platformTargetSdk();
}
return true;
}
@@ -508,7 +508,8 @@ public class PlatformCompat extends IPlatformCompat.Stub {
filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
filter.addDataScheme("package");
context.registerReceiver(receiver, filter);
context.registerReceiverForAllUsers(receiver, filter, /* broadcastPermission= */
null, /* scheduler= */ null);
}
/**

View File

@@ -16,6 +16,7 @@
package com.android.tests.gating;
import static android.Manifest.permission.INTERACT_ACROSS_USERS_FULL;
import static android.Manifest.permission.LOG_COMPAT_CHANGE;
import static android.Manifest.permission.OVERRIDE_COMPAT_CHANGE_CONFIG;
import static android.Manifest.permission.READ_COMPAT_CHANGE_CONFIG;
@@ -261,13 +262,15 @@ public final class PlatformCompatPermissionsTest {
public void clearOverrides_noOverridesPermission_throwsSecurityException()
throws Throwable {
thrown.expect(SecurityException.class);
mUiAutomation.adoptShellPermissionIdentity(INTERACT_ACROSS_USERS_FULL);
mPlatformCompat.clearOverrides("foo.bar");
}
@Test
public void clearOverrides_overridesPermission_noThrow()
throws Throwable {
mUiAutomation.adoptShellPermissionIdentity(OVERRIDE_COMPAT_CHANGE_CONFIG);
mUiAutomation.adoptShellPermissionIdentity(OVERRIDE_COMPAT_CHANGE_CONFIG,
INTERACT_ACROSS_USERS_FULL);
mPlatformCompat.clearOverrides("foo.bar");
}
@@ -276,13 +279,15 @@ public final class PlatformCompatPermissionsTest {
public void clearOverridesForTest_noOverridesPermission_throwsSecurityException()
throws Throwable {
thrown.expect(SecurityException.class);
mUiAutomation.adoptShellPermissionIdentity(INTERACT_ACROSS_USERS_FULL);
mPlatformCompat.clearOverridesForTest("foo.bar");
}
@Test
public void clearOverridesForTest_overridesPermission_noThrow()
throws Throwable {
mUiAutomation.adoptShellPermissionIdentity(OVERRIDE_COMPAT_CHANGE_CONFIG);
mUiAutomation.adoptShellPermissionIdentity(OVERRIDE_COMPAT_CHANGE_CONFIG,
INTERACT_ACROSS_USERS_FULL);
mPlatformCompat.clearOverridesForTest("foo.bar");
}
@@ -291,13 +296,15 @@ public final class PlatformCompatPermissionsTest {
public void clearOverride_noOverridesPermission_throwsSecurityException()
throws Throwable {
thrown.expect(SecurityException.class);
mUiAutomation.adoptShellPermissionIdentity(INTERACT_ACROSS_USERS_FULL);
mPlatformCompat.clearOverride(1, "foo.bar");
}
@Test
public void clearOverride_overridesPermission_noThrow()
throws Throwable {
mUiAutomation.adoptShellPermissionIdentity(OVERRIDE_COMPAT_CHANGE_CONFIG);
mUiAutomation.adoptShellPermissionIdentity(OVERRIDE_COMPAT_CHANGE_CONFIG,
INTERACT_ACROSS_USERS_FULL);
mPlatformCompat.clearOverride(1, "foo.bar");
}