Merge "Apply package visibility to the LauncherApps#isActivityEnabled" into sc-dev

This commit is contained in:
Rhed Jao
2021-04-19 06:02:09 +00:00
committed by Android (Google) Code Review
3 changed files with 36 additions and 15 deletions

View File

@@ -824,6 +824,12 @@ public abstract class PackageManagerInternal {
public abstract @PackageManager.EnabledState int getApplicationEnabledState(
String packageName, int userId);
/**
* Return the enabled setting for a package component (activity, receiver, service, provider).
*/
public abstract @PackageManager.EnabledState int getComponentEnabledSetting(
@NonNull ComponentName componentName, int callingUid, int userId);
/**
* Extra field name for the token of a request to enable rollback for a
* package.

View File

@@ -1043,22 +1043,24 @@ public class LauncherAppsService extends SystemService {
return false;
}
final PackageManagerInternal pmInt =
LocalServices.getService(PackageManagerInternal.class);
final int callingUid = injectBinderCallingUid();
final int state = pmInt.getComponentEnabledSetting(component, callingUid,
user.getIdentifier());
switch (state) {
case PackageManager.COMPONENT_ENABLED_STATE_DEFAULT:
break; // Need to check the manifest's enabled state.
case PackageManager.COMPONENT_ENABLED_STATE_ENABLED:
return true;
case PackageManager.COMPONENT_ENABLED_STATE_DISABLED:
case PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER:
case PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED:
return false;
}
final long ident = Binder.clearCallingIdentity();
try {
final int state = mIPM.getComponentEnabledSetting(component, user.getIdentifier());
switch (state) {
case PackageManager.COMPONENT_ENABLED_STATE_DEFAULT:
break; // Need to check the manifest's enabled state.
case PackageManager.COMPONENT_ENABLED_STATE_ENABLED:
return true;
case PackageManager.COMPONENT_ENABLED_STATE_DISABLED:
case PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER:
case PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED:
return false;
}
final PackageManagerInternal pmInt =
LocalServices.getService(PackageManagerInternal.class);
ActivityInfo info = pmInt.getActivityInfo(component,
PackageManager.MATCH_DIRECT_BOOT_AWARE
| PackageManager.MATCH_DIRECT_BOOT_UNAWARE,

View File

@@ -23616,11 +23616,17 @@ public class PackageManagerService extends IPackageManager.Stub
@Override
public int getComponentEnabledSetting(@NonNull ComponentName component, int userId) {
if (component == null) return COMPONENT_ENABLED_STATE_DEFAULT;
if (!mUserManager.exists(userId)) return COMPONENT_ENABLED_STATE_DISABLED;
int callingUid = Binder.getCallingUid();
enforceCrossUserPermission(callingUid, userId, false /*requireFullPermission*/,
false /*checkShell*/, "getComponentEnabled");
return getComponentEnabledSettingInternal(component, callingUid, userId);
}
private int getComponentEnabledSettingInternal(ComponentName component, int callingUid,
int userId) {
if (component == null) return COMPONENT_ENABLED_STATE_DEFAULT;
if (!mUserManager.exists(userId)) return COMPONENT_ENABLED_STATE_DISABLED;
synchronized (mLock) {
try {
if (shouldFilterApplicationLocked(
@@ -27065,6 +27071,13 @@ public class PackageManagerService extends IPackageManager.Stub
}
}
@Override
public @PackageManager.EnabledState int getComponentEnabledSetting(
@NonNull ComponentName componentName, int callingUid, int userId) {
return PackageManagerService.this.getComponentEnabledSettingInternal(componentName,
callingUid, userId);
}
@Override
public void setEnableRollbackCode(int token, int enableRollbackCode) {
PackageManagerService.this.setEnableRollbackCode(token, enableRollbackCode);