Merge "Reintroduce internal variant of getComponentEnabledSetting"

This commit is contained in:
Patrick Baumann
2021-11-18 21:44:14 +00:00
committed by Android (Google) Code Review
5 changed files with 39 additions and 11 deletions

View File

@@ -514,6 +514,11 @@ public interface Computer {
int getComponentEnabledSetting(@NonNull ComponentName component, int callingUid,
@UserIdInt int userId);
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
@PackageManager.EnabledState
int getComponentEnabledSettingInternal(@NonNull ComponentName component, int callingUid,
@UserIdInt int userId);
/**
* @return true if the runtime app user enabled state, runtime component user enabled state,
* install-time app manifest enabled state, and install-time component manifest enabled state

View File

@@ -5015,20 +5015,26 @@ public class ComputerEngine implements Computer {
@UserIdInt int userId) {
enforceCrossUserPermission(callingUid, userId, false /*requireFullPermission*/,
false /*checkShell*/, "getComponentEnabled");
return getComponentEnabledSettingInternal(component, callingUid, userId);
}
@PackageManager.EnabledState
@Override
public int getComponentEnabledSettingInternal(@NonNull ComponentName component, int callingUid,
@UserIdInt int userId) {
if (component == null) return COMPONENT_ENABLED_STATE_DEFAULT;
if (!mUserManager.exists(userId)) return COMPONENT_ENABLED_STATE_DISABLED;
try {
if (shouldFilterApplication(
mSettings.getPackage(component.getPackageName()), callingUid,
component, TYPE_UNKNOWN, userId)) {
throw new PackageManager.NameNotFoundException(component.getPackageName());
}
return mSettings.getComponentEnabledSetting(component, userId);
} catch (PackageManager.NameNotFoundException e) {
throw new IllegalArgumentException("Unknown component: " + component);
try {
if (shouldFilterApplication(
mSettings.getPackage(component.getPackageName()), callingUid,
component, TYPE_UNKNOWN, userId)) {
throw new PackageManager.NameNotFoundException(component.getPackageName());
}
return mSettings.getComponentEnabledSetting(component, userId);
} catch (PackageManager.NameNotFoundException e) {
throw new IllegalArgumentException("Unknown component: " + component);
}
}
@Override

View File

@@ -649,6 +649,14 @@ public final class ComputerLocked extends ComputerEngine {
}
}
@Override
public int getComponentEnabledSettingInternal(@NonNull ComponentName component, int callingUid,
@UserIdInt int userId) {
synchronized (mLock) {
return super.getComponentEnabledSettingInternal(component, callingUid, userId);
}
}
@Override
public boolean isComponentEffectivelyEnabled(@NonNull ComponentInfo componentInfo,
@UserIdInt int userId) {

View File

@@ -1089,6 +1089,15 @@ public final class ComputerTracker implements Computer {
}
}
@Override
public int getComponentEnabledSettingInternal(@NonNull ComponentName component, int callingUid,
@UserIdInt int userId) {
try (ThreadComputer current = snapshot()) {
return current.mComputer.getComponentEnabledSettingInternal(
component, callingUid, userId);
}
}
@Override
public boolean isComponentEffectivelyEnabled(@NonNull ComponentInfo componentInfo,
@UserIdInt int userId) {

View File

@@ -8195,8 +8195,8 @@ public class PackageManagerService extends IPackageManager.Stub
@Override
public @PackageManager.EnabledState int getComponentEnabledSetting(
@NonNull ComponentName componentName, int callingUid, int userId) {
return PackageManagerService.this.mComputer.getComponentEnabledSetting(componentName,
callingUid, userId);
return PackageManagerService.this.mComputer.getComponentEnabledSettingInternal(
componentName, callingUid, userId);
}
@Override