Loading core/java/com/android/internal/compat/IPlatformCompat.aidl +22 −0 Original line number Diff line number Diff line Loading @@ -47,6 +47,7 @@ interface IPlatformCompat { * @param appInfo representing the affected app * @throws SecurityException if logging is not allowed */ @EnforcePermission("LOG_COMPAT_CHANGE") void reportChange(long changeId, in ApplicationInfo appInfo); /** Loading @@ -60,6 +61,7 @@ interface IPlatformCompat { * @param packageName the package name of the app in question * @throws SecurityException if logging is not allowed */ @EnforcePermission("LOG_COMPAT_CHANGE") void reportChangeByPackageName(long changeId, in String packageName, int userId); /** Loading @@ -72,6 +74,7 @@ interface IPlatformCompat { * @param uid the UID of the app in question * @throws SecurityException if logging is not allowed */ @EnforcePermission("LOG_COMPAT_CHANGE") void reportChangeByUid(long changeId, int uid); /** Loading @@ -90,6 +93,7 @@ interface IPlatformCompat { * @return {@code true} if the change is enabled for the current app * @throws SecurityException if logging or reading compat confis is not allowed */ @EnforcePermission(allOf={"LOG_COMPAT_CHANGE", "READ_COMPAT_CHANGE_CONFIG"}) boolean isChangeEnabled(long changeId, in ApplicationInfo appInfo); /** Loading @@ -115,6 +119,7 @@ interface IPlatformCompat { * @return {@code true} if the change is enabled for the current app * @throws SecurityException if logging or reading compat confis is not allowed */ @EnforcePermission(allOf={"LOG_COMPAT_CHANGE", "READ_COMPAT_CHANGE_CONFIG"}) boolean isChangeEnabledByPackageName(long changeId, in String packageName, int userId); /** Loading @@ -140,6 +145,7 @@ interface IPlatformCompat { * @return {@code true} if the change is enabled for the current app * @throws SecurityException if logging or reading compat confis is not allowed */ @EnforcePermission(allOf={"LOG_COMPAT_CHANGE", "READ_COMPAT_CHANGE_CONFIG"}) boolean isChangeEnabledByUid(long changeId, int uid); /** Loading @@ -151,6 +157,7 @@ interface IPlatformCompat { * @param packageName the package name of the app whose changes will be overridden * @throws SecurityException if overriding changes is not permitted */ @EnforcePermission("OVERRIDE_COMPAT_CHANGE_CONFIG") void setOverrides(in CompatibilityChangeConfig overrides, in String packageName); /** Loading @@ -171,6 +178,7 @@ interface IPlatformCompat { * on specific apps by their package name * @throws SecurityException if overriding changes is not permitted */ @EnforcePermission("OVERRIDE_COMPAT_CHANGE_CONFIG_ON_RELEASE_BUILD") void putAllOverridesOnReleaseBuilds(in CompatibilityOverridesByPackageConfig overridesByPackage); /** Loading @@ -190,6 +198,7 @@ interface IPlatformCompat { * @param packageName the package name of the app whose changes will be overridden * @throws SecurityException if overriding changes is not permitted */ @EnforcePermission("OVERRIDE_COMPAT_CHANGE_CONFIG_ON_RELEASE_BUILD") void putOverridesOnReleaseBuilds(in CompatibilityOverrideConfig overrides, in String packageName); /** Loading @@ -201,6 +210,7 @@ interface IPlatformCompat { * @param packageName the package name of the app whose changes will be overridden * @throws SecurityException if overriding changes is not permitted. */ @EnforcePermission("OVERRIDE_COMPAT_CHANGE_CONFIG") void setOverridesForTest(in CompatibilityChangeConfig overrides, in String packageName); /** Loading @@ -213,6 +223,7 @@ interface IPlatformCompat { * @return {@code true} if an override existed * @throws SecurityException if overriding changes is not permitted */ @EnforcePermission("OVERRIDE_COMPAT_CHANGE_CONFIG") boolean clearOverride(long changeId, String packageName); /** Loading @@ -225,6 +236,7 @@ interface IPlatformCompat { * @return {@code true} if an override existed * @throws SecurityException if overriding changes is not permitted */ @EnforcePermission("OVERRIDE_COMPAT_CHANGE_CONFIG") boolean clearOverrideForTest(long changeId, String packageName); /** Loading @@ -245,6 +257,7 @@ interface IPlatformCompat { * removed for specific apps by their package name * @throws SecurityException if overriding changes is not permitted */ @EnforcePermission("OVERRIDE_COMPAT_CHANGE_CONFIG_ON_RELEASE_BUILD") void removeAllOverridesOnReleaseBuilds(in CompatibilityOverridesToRemoveByPackageConfig overridesToRemoveByPackage); /** Loading @@ -266,6 +279,7 @@ interface IPlatformCompat { * default behaviour * @throws SecurityException if overriding changes is not permitted */ @EnforcePermission("OVERRIDE_COMPAT_CHANGE_CONFIG_ON_RELEASE_BUILD") void removeOverridesOnReleaseBuilds(in CompatibilityOverridesToRemoveConfig overridesToRemove, in String packageName); /** Loading @@ -280,6 +294,7 @@ interface IPlatformCompat { * @return The number of changes that were enabled. * @throws SecurityException if overriding changes is not permitted. */ @EnforcePermission("OVERRIDE_COMPAT_CHANGE_CONFIG") int enableTargetSdkChanges(in String packageName, int targetSdkVersion); /** Loading @@ -294,6 +309,7 @@ interface IPlatformCompat { * @return the number of changes that were disabled * @throws SecurityException if overriding changes is not permitted. */ @EnforcePermission("OVERRIDE_COMPAT_CHANGE_CONFIG") int disableTargetSdkChanges(in String packageName, int targetSdkVersion); /** Loading @@ -304,6 +320,7 @@ interface IPlatformCompat { * @param packageName the package name of the app whose overrides will be cleared * @throws SecurityException if overriding changes is not permitted */ @EnforcePermission("OVERRIDE_COMPAT_CHANGE_CONFIG") void clearOverrides(in String packageName); /** Loading @@ -314,6 +331,7 @@ interface IPlatformCompat { * @param packageName the package name of the app whose overrides will be cleared * @throws SecurityException if overriding changes is not permitted */ @EnforcePermission("OVERRIDE_COMPAT_CHANGE_CONFIG") void clearOverridesForTest(in String packageName); /** Loading @@ -323,6 +341,7 @@ interface IPlatformCompat { * @return a {@link CompatibilityChangeConfig}, representing whether a change is enabled for * the given app or not */ @EnforcePermission(allOf={"LOG_COMPAT_CHANGE", "READ_COMPAT_CHANGE_CONFIG"}) CompatibilityChangeConfig getAppConfig(in ApplicationInfo appInfo); /** Loading @@ -330,6 +349,7 @@ interface IPlatformCompat { * * @return an array of {@link CompatibilityChangeInfo} known to the service */ @EnforcePermission("READ_COMPAT_CHANGE_CONFIG") CompatibilityChangeInfo[] listAllChanges(); /** Loading @@ -338,10 +358,12 @@ interface IPlatformCompat { * * @return an array of {@link CompatibilityChangeInfo} */ @RequiresNoPermission CompatibilityChangeInfo[] listUIChanges(); /** * Gets an instance that can determine whether a changeid can be overridden for a package name. */ @RequiresNoPermission IOverrideValidator getOverrideValidator(); } services/core/java/com/android/server/compat/PlatformCompat.java +28 −71 Original line number Diff line number Diff line Loading @@ -20,9 +20,9 @@ import static android.Manifest.permission.LOG_COMPAT_CHANGE; import static android.Manifest.permission.OVERRIDE_COMPAT_CHANGE_CONFIG; import static android.Manifest.permission.OVERRIDE_COMPAT_CHANGE_CONFIG_ON_RELEASE_BUILD; import static android.Manifest.permission.READ_COMPAT_CHANGE_CONFIG; import static android.content.pm.PackageManager.PERMISSION_GRANTED; import static android.os.Process.SYSTEM_UID; import android.annotation.EnforcePermission; import android.annotation.RequiresNoPermission; import android.annotation.UserIdInt; import android.app.ActivityManager; import android.app.IActivityManager; Loading Loading @@ -93,15 +93,15 @@ public class PlatformCompat extends IPlatformCompat.Stub { } @Override @EnforcePermission(LOG_COMPAT_CHANGE) public void reportChange(long changeId, ApplicationInfo appInfo) { checkCompatChangeLogPermission(); reportChangeInternal(changeId, appInfo.uid, ChangeReporter.STATE_LOGGED); } @Override @EnforcePermission(LOG_COMPAT_CHANGE) public void reportChangeByPackageName(long changeId, String packageName, @UserIdInt int userId) { checkCompatChangeLogPermission(); ApplicationInfo appInfo = getApplicationInfo(packageName, userId); if (appInfo != null) { reportChangeInternal(changeId, appInfo.uid, ChangeReporter.STATE_LOGGED); Loading @@ -109,8 +109,8 @@ public class PlatformCompat extends IPlatformCompat.Stub { } @Override @EnforcePermission(LOG_COMPAT_CHANGE) public void reportChangeByUid(long changeId, int uid) { checkCompatChangeLogPermission(); reportChangeInternal(changeId, uid, ChangeReporter.STATE_LOGGED); } Loading @@ -119,15 +119,15 @@ public class PlatformCompat extends IPlatformCompat.Stub { } @Override @EnforcePermission(allOf = {LOG_COMPAT_CHANGE, READ_COMPAT_CHANGE_CONFIG}) public boolean isChangeEnabled(long changeId, ApplicationInfo appInfo) { checkCompatChangeReadAndLogPermission(); return isChangeEnabledInternal(changeId, appInfo); } @Override @EnforcePermission(allOf = {LOG_COMPAT_CHANGE, READ_COMPAT_CHANGE_CONFIG}) public boolean isChangeEnabledByPackageName(long changeId, String packageName, @UserIdInt int userId) { checkCompatChangeReadAndLogPermission(); ApplicationInfo appInfo = getApplicationInfo(packageName, userId); if (appInfo == null) { return mCompatConfig.willChangeBeEnabled(changeId, packageName); Loading @@ -136,8 +136,8 @@ public class PlatformCompat extends IPlatformCompat.Stub { } @Override @EnforcePermission(allOf = {LOG_COMPAT_CHANGE, READ_COMPAT_CHANGE_CONFIG}) public boolean isChangeEnabledByUid(long changeId, int uid) { checkCompatChangeReadAndLogPermission(); String[] packages = mContext.getPackageManager().getPackagesForUid(uid); if (packages == null || packages.length == 0) { return mCompatConfig.defaultChangeIdValue(changeId); Loading Loading @@ -197,8 +197,8 @@ public class PlatformCompat extends IPlatformCompat.Stub { } @Override @EnforcePermission(OVERRIDE_COMPAT_CHANGE_CONFIG) public void setOverrides(CompatibilityChangeConfig overrides, String packageName) { checkCompatChangeOverridePermission(); Map<Long, PackageOverride> overridesMap = new HashMap<>(); for (long change : overrides.enabledChanges()) { overridesMap.put(change, new PackageOverride.Builder().setEnabled(true).build()); Loading @@ -213,8 +213,8 @@ public class PlatformCompat extends IPlatformCompat.Stub { } @Override @EnforcePermission(OVERRIDE_COMPAT_CHANGE_CONFIG) public void setOverridesForTest(CompatibilityChangeConfig overrides, String packageName) { checkCompatChangeOverridePermission(); Map<Long, PackageOverride> overridesMap = new HashMap<>(); for (long change : overrides.enabledChanges()) { overridesMap.put(change, new PackageOverride.Builder().setEnabled(true).build()); Loading @@ -228,9 +228,9 @@ public class PlatformCompat extends IPlatformCompat.Stub { } @Override @EnforcePermission(OVERRIDE_COMPAT_CHANGE_CONFIG_ON_RELEASE_BUILD) public void putAllOverridesOnReleaseBuilds( CompatibilityOverridesByPackageConfig overridesByPackage) { checkCompatChangeOverrideOverridablePermission(); for (CompatibilityOverrideConfig overrides : overridesByPackage.packageNameToOverrides.values()) { checkAllCompatOverridesAreOverridable(overrides.overrides.keySet()); Loading @@ -239,16 +239,16 @@ public class PlatformCompat extends IPlatformCompat.Stub { } @Override @EnforcePermission(OVERRIDE_COMPAT_CHANGE_CONFIG_ON_RELEASE_BUILD) public void putOverridesOnReleaseBuilds(CompatibilityOverrideConfig overrides, String packageName) { checkCompatChangeOverrideOverridablePermission(); checkAllCompatOverridesAreOverridable(overrides.overrides.keySet()); mCompatConfig.addPackageOverrides(overrides, packageName, /* skipUnknownChangeIds= */ true); } @Override @EnforcePermission(OVERRIDE_COMPAT_CHANGE_CONFIG) public int enableTargetSdkChanges(String packageName, int targetSdkVersion) { checkCompatChangeOverridePermission(); int numChanges = mCompatConfig.enableTargetSdkChangesForPackage(packageName, targetSdkVersion); killPackage(packageName); Loading @@ -256,8 +256,8 @@ public class PlatformCompat extends IPlatformCompat.Stub { } @Override @EnforcePermission(OVERRIDE_COMPAT_CHANGE_CONFIG) public int disableTargetSdkChanges(String packageName, int targetSdkVersion) { checkCompatChangeOverridePermission(); int numChanges = mCompatConfig.disableTargetSdkChangesForPackage(packageName, targetSdkVersion); killPackage(packageName); Loading @@ -265,36 +265,36 @@ public class PlatformCompat extends IPlatformCompat.Stub { } @Override @EnforcePermission(OVERRIDE_COMPAT_CHANGE_CONFIG) public void clearOverrides(String packageName) { checkCompatChangeOverridePermission(); mCompatConfig.removePackageOverrides(packageName); killPackage(packageName); } @Override @EnforcePermission(OVERRIDE_COMPAT_CHANGE_CONFIG) public void clearOverridesForTest(String packageName) { checkCompatChangeOverridePermission(); mCompatConfig.removePackageOverrides(packageName); } @Override @EnforcePermission(OVERRIDE_COMPAT_CHANGE_CONFIG) public boolean clearOverride(long changeId, String packageName) { checkCompatChangeOverridePermission(); boolean existed = mCompatConfig.removeOverride(changeId, packageName); killPackage(packageName); return existed; } @Override @EnforcePermission(OVERRIDE_COMPAT_CHANGE_CONFIG) public boolean clearOverrideForTest(long changeId, String packageName) { checkCompatChangeOverridePermission(); return mCompatConfig.removeOverride(changeId, packageName); } @Override @EnforcePermission(OVERRIDE_COMPAT_CHANGE_CONFIG_ON_RELEASE_BUILD) public void removeAllOverridesOnReleaseBuilds( CompatibilityOverridesToRemoveByPackageConfig overridesToRemoveByPackage) { checkCompatChangeOverrideOverridablePermission(); for (CompatibilityOverridesToRemoveConfig overridesToRemove : overridesToRemoveByPackage.packageNameToOverridesToRemove.values()) { checkAllCompatOverridesAreOverridable(overridesToRemove.changeIds); Loading @@ -303,27 +303,28 @@ public class PlatformCompat extends IPlatformCompat.Stub { } @Override @EnforcePermission(OVERRIDE_COMPAT_CHANGE_CONFIG_ON_RELEASE_BUILD) public void removeOverridesOnReleaseBuilds( CompatibilityOverridesToRemoveConfig overridesToRemove, String packageName) { checkCompatChangeOverrideOverridablePermission(); checkAllCompatOverridesAreOverridable(overridesToRemove.changeIds); mCompatConfig.removePackageOverrides(overridesToRemove, packageName); } @Override @EnforcePermission(allOf = {LOG_COMPAT_CHANGE, READ_COMPAT_CHANGE_CONFIG}) public CompatibilityChangeConfig getAppConfig(ApplicationInfo appInfo) { checkCompatChangeReadAndLogPermission(); return mCompatConfig.getAppConfig(appInfo); } @Override @EnforcePermission(READ_COMPAT_CHANGE_CONFIG) public CompatibilityChangeInfo[] listAllChanges() { checkCompatChangeReadPermission(); return mCompatConfig.dumpChanges(); } @Override @RequiresNoPermission public CompatibilityChangeInfo[] listUIChanges() { return Arrays.stream(listAllChanges()).filter(this::isShownInUI).toArray( CompatibilityChangeInfo[]::new); Loading Loading @@ -362,11 +363,15 @@ public class PlatformCompat extends IPlatformCompat.Stub { if (!DumpUtils.checkDumpAndUsageStatsPermission(mContext, "platform_compat", pw)) { return; } checkCompatChangeReadAndLogPermission(); mContext.enforceCallingOrSelfPermission( READ_COMPAT_CHANGE_CONFIG, "Cannot read compat change"); mContext.enforceCallingOrSelfPermission( LOG_COMPAT_CHANGE, "Cannot read log compat change usage"); mCompatConfig.dumpConfig(pw); } @Override @RequiresNoPermission public IOverrideValidator getOverrideValidator() { return mCompatConfig.getOverrideValidator(); } Loading Loading @@ -414,49 +419,6 @@ public class PlatformCompat extends IPlatformCompat.Stub { } } private void checkCompatChangeLogPermission() throws SecurityException { // Don't check for permissions within the system process if (Binder.getCallingUid() == SYSTEM_UID) { return; } if (mContext.checkCallingOrSelfPermission(LOG_COMPAT_CHANGE) != PERMISSION_GRANTED) { throw new SecurityException("Cannot log compat change usage"); } } private void checkCompatChangeReadPermission() { // Don't check for permissions within the system process if (Binder.getCallingUid() == SYSTEM_UID) { return; } if (mContext.checkCallingOrSelfPermission(READ_COMPAT_CHANGE_CONFIG) != PERMISSION_GRANTED) { throw new SecurityException("Cannot read compat change"); } } private void checkCompatChangeOverridePermission() { // Don't check for permissions within the system process if (Binder.getCallingUid() == SYSTEM_UID) { return; } if (mContext.checkCallingOrSelfPermission(OVERRIDE_COMPAT_CHANGE_CONFIG) != PERMISSION_GRANTED) { throw new SecurityException("Cannot override compat change"); } } private void checkCompatChangeOverrideOverridablePermission() { // Don't check for permissions within the system process if (Binder.getCallingUid() == SYSTEM_UID) { return; } if (mContext.checkCallingOrSelfPermission(OVERRIDE_COMPAT_CHANGE_CONFIG_ON_RELEASE_BUILD) != PERMISSION_GRANTED) { throw new SecurityException("Cannot override compat change"); } } private void checkAllCompatOverridesAreOverridable(Collection<Long> changeIds) { for (Long changeId : changeIds) { if (isKnownChangeId(changeId) && !mCompatConfig.isOverridable(changeId)) { Loading @@ -466,11 +428,6 @@ public class PlatformCompat extends IPlatformCompat.Stub { } } private void checkCompatChangeReadAndLogPermission() { checkCompatChangeReadPermission(); checkCompatChangeLogPermission(); } private boolean isShownInUI(CompatibilityChangeInfo change) { if (change.getLoggingOnly()) { return false; Loading Loading
core/java/com/android/internal/compat/IPlatformCompat.aidl +22 −0 Original line number Diff line number Diff line Loading @@ -47,6 +47,7 @@ interface IPlatformCompat { * @param appInfo representing the affected app * @throws SecurityException if logging is not allowed */ @EnforcePermission("LOG_COMPAT_CHANGE") void reportChange(long changeId, in ApplicationInfo appInfo); /** Loading @@ -60,6 +61,7 @@ interface IPlatformCompat { * @param packageName the package name of the app in question * @throws SecurityException if logging is not allowed */ @EnforcePermission("LOG_COMPAT_CHANGE") void reportChangeByPackageName(long changeId, in String packageName, int userId); /** Loading @@ -72,6 +74,7 @@ interface IPlatformCompat { * @param uid the UID of the app in question * @throws SecurityException if logging is not allowed */ @EnforcePermission("LOG_COMPAT_CHANGE") void reportChangeByUid(long changeId, int uid); /** Loading @@ -90,6 +93,7 @@ interface IPlatformCompat { * @return {@code true} if the change is enabled for the current app * @throws SecurityException if logging or reading compat confis is not allowed */ @EnforcePermission(allOf={"LOG_COMPAT_CHANGE", "READ_COMPAT_CHANGE_CONFIG"}) boolean isChangeEnabled(long changeId, in ApplicationInfo appInfo); /** Loading @@ -115,6 +119,7 @@ interface IPlatformCompat { * @return {@code true} if the change is enabled for the current app * @throws SecurityException if logging or reading compat confis is not allowed */ @EnforcePermission(allOf={"LOG_COMPAT_CHANGE", "READ_COMPAT_CHANGE_CONFIG"}) boolean isChangeEnabledByPackageName(long changeId, in String packageName, int userId); /** Loading @@ -140,6 +145,7 @@ interface IPlatformCompat { * @return {@code true} if the change is enabled for the current app * @throws SecurityException if logging or reading compat confis is not allowed */ @EnforcePermission(allOf={"LOG_COMPAT_CHANGE", "READ_COMPAT_CHANGE_CONFIG"}) boolean isChangeEnabledByUid(long changeId, int uid); /** Loading @@ -151,6 +157,7 @@ interface IPlatformCompat { * @param packageName the package name of the app whose changes will be overridden * @throws SecurityException if overriding changes is not permitted */ @EnforcePermission("OVERRIDE_COMPAT_CHANGE_CONFIG") void setOverrides(in CompatibilityChangeConfig overrides, in String packageName); /** Loading @@ -171,6 +178,7 @@ interface IPlatformCompat { * on specific apps by their package name * @throws SecurityException if overriding changes is not permitted */ @EnforcePermission("OVERRIDE_COMPAT_CHANGE_CONFIG_ON_RELEASE_BUILD") void putAllOverridesOnReleaseBuilds(in CompatibilityOverridesByPackageConfig overridesByPackage); /** Loading @@ -190,6 +198,7 @@ interface IPlatformCompat { * @param packageName the package name of the app whose changes will be overridden * @throws SecurityException if overriding changes is not permitted */ @EnforcePermission("OVERRIDE_COMPAT_CHANGE_CONFIG_ON_RELEASE_BUILD") void putOverridesOnReleaseBuilds(in CompatibilityOverrideConfig overrides, in String packageName); /** Loading @@ -201,6 +210,7 @@ interface IPlatformCompat { * @param packageName the package name of the app whose changes will be overridden * @throws SecurityException if overriding changes is not permitted. */ @EnforcePermission("OVERRIDE_COMPAT_CHANGE_CONFIG") void setOverridesForTest(in CompatibilityChangeConfig overrides, in String packageName); /** Loading @@ -213,6 +223,7 @@ interface IPlatformCompat { * @return {@code true} if an override existed * @throws SecurityException if overriding changes is not permitted */ @EnforcePermission("OVERRIDE_COMPAT_CHANGE_CONFIG") boolean clearOverride(long changeId, String packageName); /** Loading @@ -225,6 +236,7 @@ interface IPlatformCompat { * @return {@code true} if an override existed * @throws SecurityException if overriding changes is not permitted */ @EnforcePermission("OVERRIDE_COMPAT_CHANGE_CONFIG") boolean clearOverrideForTest(long changeId, String packageName); /** Loading @@ -245,6 +257,7 @@ interface IPlatformCompat { * removed for specific apps by their package name * @throws SecurityException if overriding changes is not permitted */ @EnforcePermission("OVERRIDE_COMPAT_CHANGE_CONFIG_ON_RELEASE_BUILD") void removeAllOverridesOnReleaseBuilds(in CompatibilityOverridesToRemoveByPackageConfig overridesToRemoveByPackage); /** Loading @@ -266,6 +279,7 @@ interface IPlatformCompat { * default behaviour * @throws SecurityException if overriding changes is not permitted */ @EnforcePermission("OVERRIDE_COMPAT_CHANGE_CONFIG_ON_RELEASE_BUILD") void removeOverridesOnReleaseBuilds(in CompatibilityOverridesToRemoveConfig overridesToRemove, in String packageName); /** Loading @@ -280,6 +294,7 @@ interface IPlatformCompat { * @return The number of changes that were enabled. * @throws SecurityException if overriding changes is not permitted. */ @EnforcePermission("OVERRIDE_COMPAT_CHANGE_CONFIG") int enableTargetSdkChanges(in String packageName, int targetSdkVersion); /** Loading @@ -294,6 +309,7 @@ interface IPlatformCompat { * @return the number of changes that were disabled * @throws SecurityException if overriding changes is not permitted. */ @EnforcePermission("OVERRIDE_COMPAT_CHANGE_CONFIG") int disableTargetSdkChanges(in String packageName, int targetSdkVersion); /** Loading @@ -304,6 +320,7 @@ interface IPlatformCompat { * @param packageName the package name of the app whose overrides will be cleared * @throws SecurityException if overriding changes is not permitted */ @EnforcePermission("OVERRIDE_COMPAT_CHANGE_CONFIG") void clearOverrides(in String packageName); /** Loading @@ -314,6 +331,7 @@ interface IPlatformCompat { * @param packageName the package name of the app whose overrides will be cleared * @throws SecurityException if overriding changes is not permitted */ @EnforcePermission("OVERRIDE_COMPAT_CHANGE_CONFIG") void clearOverridesForTest(in String packageName); /** Loading @@ -323,6 +341,7 @@ interface IPlatformCompat { * @return a {@link CompatibilityChangeConfig}, representing whether a change is enabled for * the given app or not */ @EnforcePermission(allOf={"LOG_COMPAT_CHANGE", "READ_COMPAT_CHANGE_CONFIG"}) CompatibilityChangeConfig getAppConfig(in ApplicationInfo appInfo); /** Loading @@ -330,6 +349,7 @@ interface IPlatformCompat { * * @return an array of {@link CompatibilityChangeInfo} known to the service */ @EnforcePermission("READ_COMPAT_CHANGE_CONFIG") CompatibilityChangeInfo[] listAllChanges(); /** Loading @@ -338,10 +358,12 @@ interface IPlatformCompat { * * @return an array of {@link CompatibilityChangeInfo} */ @RequiresNoPermission CompatibilityChangeInfo[] listUIChanges(); /** * Gets an instance that can determine whether a changeid can be overridden for a package name. */ @RequiresNoPermission IOverrideValidator getOverrideValidator(); }
services/core/java/com/android/server/compat/PlatformCompat.java +28 −71 Original line number Diff line number Diff line Loading @@ -20,9 +20,9 @@ import static android.Manifest.permission.LOG_COMPAT_CHANGE; import static android.Manifest.permission.OVERRIDE_COMPAT_CHANGE_CONFIG; import static android.Manifest.permission.OVERRIDE_COMPAT_CHANGE_CONFIG_ON_RELEASE_BUILD; import static android.Manifest.permission.READ_COMPAT_CHANGE_CONFIG; import static android.content.pm.PackageManager.PERMISSION_GRANTED; import static android.os.Process.SYSTEM_UID; import android.annotation.EnforcePermission; import android.annotation.RequiresNoPermission; import android.annotation.UserIdInt; import android.app.ActivityManager; import android.app.IActivityManager; Loading Loading @@ -93,15 +93,15 @@ public class PlatformCompat extends IPlatformCompat.Stub { } @Override @EnforcePermission(LOG_COMPAT_CHANGE) public void reportChange(long changeId, ApplicationInfo appInfo) { checkCompatChangeLogPermission(); reportChangeInternal(changeId, appInfo.uid, ChangeReporter.STATE_LOGGED); } @Override @EnforcePermission(LOG_COMPAT_CHANGE) public void reportChangeByPackageName(long changeId, String packageName, @UserIdInt int userId) { checkCompatChangeLogPermission(); ApplicationInfo appInfo = getApplicationInfo(packageName, userId); if (appInfo != null) { reportChangeInternal(changeId, appInfo.uid, ChangeReporter.STATE_LOGGED); Loading @@ -109,8 +109,8 @@ public class PlatformCompat extends IPlatformCompat.Stub { } @Override @EnforcePermission(LOG_COMPAT_CHANGE) public void reportChangeByUid(long changeId, int uid) { checkCompatChangeLogPermission(); reportChangeInternal(changeId, uid, ChangeReporter.STATE_LOGGED); } Loading @@ -119,15 +119,15 @@ public class PlatformCompat extends IPlatformCompat.Stub { } @Override @EnforcePermission(allOf = {LOG_COMPAT_CHANGE, READ_COMPAT_CHANGE_CONFIG}) public boolean isChangeEnabled(long changeId, ApplicationInfo appInfo) { checkCompatChangeReadAndLogPermission(); return isChangeEnabledInternal(changeId, appInfo); } @Override @EnforcePermission(allOf = {LOG_COMPAT_CHANGE, READ_COMPAT_CHANGE_CONFIG}) public boolean isChangeEnabledByPackageName(long changeId, String packageName, @UserIdInt int userId) { checkCompatChangeReadAndLogPermission(); ApplicationInfo appInfo = getApplicationInfo(packageName, userId); if (appInfo == null) { return mCompatConfig.willChangeBeEnabled(changeId, packageName); Loading @@ -136,8 +136,8 @@ public class PlatformCompat extends IPlatformCompat.Stub { } @Override @EnforcePermission(allOf = {LOG_COMPAT_CHANGE, READ_COMPAT_CHANGE_CONFIG}) public boolean isChangeEnabledByUid(long changeId, int uid) { checkCompatChangeReadAndLogPermission(); String[] packages = mContext.getPackageManager().getPackagesForUid(uid); if (packages == null || packages.length == 0) { return mCompatConfig.defaultChangeIdValue(changeId); Loading Loading @@ -197,8 +197,8 @@ public class PlatformCompat extends IPlatformCompat.Stub { } @Override @EnforcePermission(OVERRIDE_COMPAT_CHANGE_CONFIG) public void setOverrides(CompatibilityChangeConfig overrides, String packageName) { checkCompatChangeOverridePermission(); Map<Long, PackageOverride> overridesMap = new HashMap<>(); for (long change : overrides.enabledChanges()) { overridesMap.put(change, new PackageOverride.Builder().setEnabled(true).build()); Loading @@ -213,8 +213,8 @@ public class PlatformCompat extends IPlatformCompat.Stub { } @Override @EnforcePermission(OVERRIDE_COMPAT_CHANGE_CONFIG) public void setOverridesForTest(CompatibilityChangeConfig overrides, String packageName) { checkCompatChangeOverridePermission(); Map<Long, PackageOverride> overridesMap = new HashMap<>(); for (long change : overrides.enabledChanges()) { overridesMap.put(change, new PackageOverride.Builder().setEnabled(true).build()); Loading @@ -228,9 +228,9 @@ public class PlatformCompat extends IPlatformCompat.Stub { } @Override @EnforcePermission(OVERRIDE_COMPAT_CHANGE_CONFIG_ON_RELEASE_BUILD) public void putAllOverridesOnReleaseBuilds( CompatibilityOverridesByPackageConfig overridesByPackage) { checkCompatChangeOverrideOverridablePermission(); for (CompatibilityOverrideConfig overrides : overridesByPackage.packageNameToOverrides.values()) { checkAllCompatOverridesAreOverridable(overrides.overrides.keySet()); Loading @@ -239,16 +239,16 @@ public class PlatformCompat extends IPlatformCompat.Stub { } @Override @EnforcePermission(OVERRIDE_COMPAT_CHANGE_CONFIG_ON_RELEASE_BUILD) public void putOverridesOnReleaseBuilds(CompatibilityOverrideConfig overrides, String packageName) { checkCompatChangeOverrideOverridablePermission(); checkAllCompatOverridesAreOverridable(overrides.overrides.keySet()); mCompatConfig.addPackageOverrides(overrides, packageName, /* skipUnknownChangeIds= */ true); } @Override @EnforcePermission(OVERRIDE_COMPAT_CHANGE_CONFIG) public int enableTargetSdkChanges(String packageName, int targetSdkVersion) { checkCompatChangeOverridePermission(); int numChanges = mCompatConfig.enableTargetSdkChangesForPackage(packageName, targetSdkVersion); killPackage(packageName); Loading @@ -256,8 +256,8 @@ public class PlatformCompat extends IPlatformCompat.Stub { } @Override @EnforcePermission(OVERRIDE_COMPAT_CHANGE_CONFIG) public int disableTargetSdkChanges(String packageName, int targetSdkVersion) { checkCompatChangeOverridePermission(); int numChanges = mCompatConfig.disableTargetSdkChangesForPackage(packageName, targetSdkVersion); killPackage(packageName); Loading @@ -265,36 +265,36 @@ public class PlatformCompat extends IPlatformCompat.Stub { } @Override @EnforcePermission(OVERRIDE_COMPAT_CHANGE_CONFIG) public void clearOverrides(String packageName) { checkCompatChangeOverridePermission(); mCompatConfig.removePackageOverrides(packageName); killPackage(packageName); } @Override @EnforcePermission(OVERRIDE_COMPAT_CHANGE_CONFIG) public void clearOverridesForTest(String packageName) { checkCompatChangeOverridePermission(); mCompatConfig.removePackageOverrides(packageName); } @Override @EnforcePermission(OVERRIDE_COMPAT_CHANGE_CONFIG) public boolean clearOverride(long changeId, String packageName) { checkCompatChangeOverridePermission(); boolean existed = mCompatConfig.removeOverride(changeId, packageName); killPackage(packageName); return existed; } @Override @EnforcePermission(OVERRIDE_COMPAT_CHANGE_CONFIG) public boolean clearOverrideForTest(long changeId, String packageName) { checkCompatChangeOverridePermission(); return mCompatConfig.removeOverride(changeId, packageName); } @Override @EnforcePermission(OVERRIDE_COMPAT_CHANGE_CONFIG_ON_RELEASE_BUILD) public void removeAllOverridesOnReleaseBuilds( CompatibilityOverridesToRemoveByPackageConfig overridesToRemoveByPackage) { checkCompatChangeOverrideOverridablePermission(); for (CompatibilityOverridesToRemoveConfig overridesToRemove : overridesToRemoveByPackage.packageNameToOverridesToRemove.values()) { checkAllCompatOverridesAreOverridable(overridesToRemove.changeIds); Loading @@ -303,27 +303,28 @@ public class PlatformCompat extends IPlatformCompat.Stub { } @Override @EnforcePermission(OVERRIDE_COMPAT_CHANGE_CONFIG_ON_RELEASE_BUILD) public void removeOverridesOnReleaseBuilds( CompatibilityOverridesToRemoveConfig overridesToRemove, String packageName) { checkCompatChangeOverrideOverridablePermission(); checkAllCompatOverridesAreOverridable(overridesToRemove.changeIds); mCompatConfig.removePackageOverrides(overridesToRemove, packageName); } @Override @EnforcePermission(allOf = {LOG_COMPAT_CHANGE, READ_COMPAT_CHANGE_CONFIG}) public CompatibilityChangeConfig getAppConfig(ApplicationInfo appInfo) { checkCompatChangeReadAndLogPermission(); return mCompatConfig.getAppConfig(appInfo); } @Override @EnforcePermission(READ_COMPAT_CHANGE_CONFIG) public CompatibilityChangeInfo[] listAllChanges() { checkCompatChangeReadPermission(); return mCompatConfig.dumpChanges(); } @Override @RequiresNoPermission public CompatibilityChangeInfo[] listUIChanges() { return Arrays.stream(listAllChanges()).filter(this::isShownInUI).toArray( CompatibilityChangeInfo[]::new); Loading Loading @@ -362,11 +363,15 @@ public class PlatformCompat extends IPlatformCompat.Stub { if (!DumpUtils.checkDumpAndUsageStatsPermission(mContext, "platform_compat", pw)) { return; } checkCompatChangeReadAndLogPermission(); mContext.enforceCallingOrSelfPermission( READ_COMPAT_CHANGE_CONFIG, "Cannot read compat change"); mContext.enforceCallingOrSelfPermission( LOG_COMPAT_CHANGE, "Cannot read log compat change usage"); mCompatConfig.dumpConfig(pw); } @Override @RequiresNoPermission public IOverrideValidator getOverrideValidator() { return mCompatConfig.getOverrideValidator(); } Loading Loading @@ -414,49 +419,6 @@ public class PlatformCompat extends IPlatformCompat.Stub { } } private void checkCompatChangeLogPermission() throws SecurityException { // Don't check for permissions within the system process if (Binder.getCallingUid() == SYSTEM_UID) { return; } if (mContext.checkCallingOrSelfPermission(LOG_COMPAT_CHANGE) != PERMISSION_GRANTED) { throw new SecurityException("Cannot log compat change usage"); } } private void checkCompatChangeReadPermission() { // Don't check for permissions within the system process if (Binder.getCallingUid() == SYSTEM_UID) { return; } if (mContext.checkCallingOrSelfPermission(READ_COMPAT_CHANGE_CONFIG) != PERMISSION_GRANTED) { throw new SecurityException("Cannot read compat change"); } } private void checkCompatChangeOverridePermission() { // Don't check for permissions within the system process if (Binder.getCallingUid() == SYSTEM_UID) { return; } if (mContext.checkCallingOrSelfPermission(OVERRIDE_COMPAT_CHANGE_CONFIG) != PERMISSION_GRANTED) { throw new SecurityException("Cannot override compat change"); } } private void checkCompatChangeOverrideOverridablePermission() { // Don't check for permissions within the system process if (Binder.getCallingUid() == SYSTEM_UID) { return; } if (mContext.checkCallingOrSelfPermission(OVERRIDE_COMPAT_CHANGE_CONFIG_ON_RELEASE_BUILD) != PERMISSION_GRANTED) { throw new SecurityException("Cannot override compat change"); } } private void checkAllCompatOverridesAreOverridable(Collection<Long> changeIds) { for (Long changeId : changeIds) { if (isKnownChangeId(changeId) && !mCompatConfig.isOverridable(changeId)) { Loading @@ -466,11 +428,6 @@ public class PlatformCompat extends IPlatformCompat.Stub { } } private void checkCompatChangeReadAndLogPermission() { checkCompatChangeReadPermission(); checkCompatChangeLogPermission(); } private boolean isShownInUI(CompatibilityChangeInfo change) { if (change.getLoggingOnly()) { return false; Loading