diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index b6b28ede86802..de51bd415dfcc 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -102,6 +102,7 @@ import static com.android.server.pm.PermissionsState.PERMISSION_OPERATION_SUCCES import static dalvik.system.DexFile.getNonProfileGuidedCompilerFilter; import android.Manifest; +import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.ActivityManager; @@ -300,6 +301,8 @@ import java.io.FileReader; import java.io.FilenameFilter; import java.io.IOException; import java.io.PrintWriter; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.nio.charset.StandardCharsets; import java.security.DigestInputStream; import java.security.MessageDigest; @@ -438,6 +441,21 @@ public class PackageManagerService extends IPackageManager.Stub private static final int[] EMPTY_INT_ARRAY = new int[0]; + private static final int TYPE_UNKNOWN = 0; + private static final int TYPE_ACTIVITY = 1; + private static final int TYPE_RECEIVER = 2; + private static final int TYPE_SERVICE = 3; + private static final int TYPE_PROVIDER = 4; + @IntDef(prefix = { "TYPE_" }, value = { + TYPE_UNKNOWN, + TYPE_ACTIVITY, + TYPE_RECEIVER, + TYPE_SERVICE, + TYPE_PROVIDER, + }) + @Retention(RetentionPolicy.SOURCE) + public @interface ComponentType {} + /** * Timeout (in milliseconds) after which the watchdog should declare that * our handler thread is wedged. The usual default for such things is one @@ -3527,25 +3545,8 @@ public class PackageManagerService extends IPackageManager.Stub // and 2) ephemeral apps that have explicitly interacted with it // * Ephemeral apps can only see their own data and exposed installed apps // * Holding a signature permission allows seeing instant apps - if (!canAccessInstantApps(callingUid)) { - final String instantAppPackageName = getInstantAppPackageName(callingUid); - if (instantAppPackageName != null) { - // ephemeral apps can only get information on themselves or - // installed apps that are exposed. - if (!instantAppPackageName.equals(p.packageName) - && (ps.getInstantApp(userId) || !p.visibleToInstantApps)) { - return null; - } - } else { - if (ps.getInstantApp(userId)) { - // only get access to the ephemeral app if we've been granted access - final int callingAppId = UserHandle.getAppId(callingUid); - if (!mInstantAppRegistry.isInstantAccessGranted( - userId, callingAppId, ps.appId)) { - return null; - } - } - } + if (filterAppAccessLPr(ps, callingUid, userId)) { + return null; } final PermissionsState permissionsState = ps.getPermissionsState(); @@ -3705,6 +3706,47 @@ public class PackageManagerService extends IPackageManager.Stub return null; } + private boolean isComponentVisibleToInstantApp(@Nullable ComponentName component) { + if (isComponentVisibleToInstantApp(component, TYPE_ACTIVITY)) { + return true; + } + if (isComponentVisibleToInstantApp(component, TYPE_SERVICE)) { + return true; + } + if (isComponentVisibleToInstantApp(component, TYPE_PROVIDER)) { + return true; + } + return false; + } + + private boolean isComponentVisibleToInstantApp( + @Nullable ComponentName component, @ComponentType int type) { + if (type == TYPE_ACTIVITY) { + final PackageParser.Activity activity = mActivities.mActivities.get(component); + return activity != null + ? (activity.info.flags & ActivityInfo.FLAG_VISIBLE_TO_INSTANT_APP) != 0 + : false; + } else if (type == TYPE_RECEIVER) { + final PackageParser.Activity activity = mReceivers.mActivities.get(component); + return activity != null + ? (activity.info.flags & ActivityInfo.FLAG_VISIBLE_TO_INSTANT_APP) != 0 + : false; + } else if (type == TYPE_SERVICE) { + final PackageParser.Service service = mServices.mServices.get(component); + return service != null + ? (service.info.flags & ServiceInfo.FLAG_VISIBLE_TO_INSTANT_APP) != 0 + : false; + } else if (type == TYPE_PROVIDER) { + final PackageParser.Provider provider = mProviders.mProviders.get(component); + return provider != null + ? (provider.info.flags & ProviderInfo.FLAG_VISIBLE_TO_INSTANT_APP) != 0 + : false; + } else if (type == TYPE_UNKNOWN) { + return isComponentVisibleToInstantApp(component); + } + return false; + } + /** * Returns whether or not access to the application should be filtered. *
@@ -3714,7 +3756,7 @@ public class PackageManagerService extends IPackageManager.Stub
* @see #canAccessInstantApps(int)
*/
private boolean filterAppAccessLPr(@Nullable PackageSetting ps, int callingUid,
- @Nullable ComponentName component, boolean componentVisibleToInstantApp, int userId) {
+ @Nullable ComponentName component, @ComponentType int componentType, int userId) {
// if we're in an isolated process, get the real calling UID
if (Process.isIsolated(callingUid)) {
callingUid = mIsolatedOwners.get(callingUid);
@@ -3735,10 +3777,10 @@ public class PackageManagerService extends IPackageManager.Stub
if (callerIsInstantApp) {
// request for a specific component; if it hasn't been explicitly exposed, filter
if (component != null) {
- return !componentVisibleToInstantApp;
+ return !isComponentVisibleToInstantApp(component, componentType);
}
// request for application; if no components have been explicitly exposed, filter
- return !ps.pkg.visibleToInstantApps;
+ return ps.getInstantApp(userId) || !ps.pkg.visibleToInstantApps;
}
if (ps.getInstantApp(userId)) {
// caller can see all components of all instant applications, don't filter
@@ -3760,7 +3802,7 @@ public class PackageManagerService extends IPackageManager.Stub
* @see #filterAppAccessLPr(PackageSetting, int, ComponentName, boolean, int)
*/
private boolean filterAppAccessLPr(@Nullable PackageSetting ps, int callingUid, int userId) {
- return filterAppAccessLPr(ps, callingUid, null, false, userId);
+ return filterAppAccessLPr(ps, callingUid, null, TYPE_UNKNOWN, userId);
}
private boolean filterSharedLibPackageLPr(@Nullable PackageSetting ps, int uid, int userId,
@@ -4412,9 +4454,7 @@ public class PackageManagerService extends IPackageManager.Stub
if (a != null && mSettings.isEnabledAndMatchLPr(a.info, flags, userId)) {
PackageSetting ps = mSettings.mPackages.get(component.getPackageName());
if (ps == null) return null;
- final boolean visibleToInstantApp =
- (a.info.flags & ActivityInfo.FLAG_VISIBLE_TO_INSTANT_APP) != 0;
- if (filterAppAccessLPr(ps, callingUid, component, visibleToInstantApp, userId)) {
+ if (filterAppAccessLPr(ps, callingUid, component, TYPE_ACTIVITY, userId)) {
return null;
}
return generateActivityInfo(a, flags, ps.readUserState(userId), userId);
@@ -4445,9 +4485,7 @@ public class PackageManagerService extends IPackageManager.Stub
if (ps == null) {
return false;
}
- final boolean visibleToInstantApp =
- (a.info.flags & ActivityInfo.FLAG_VISIBLE_TO_INSTANT_APP) != 0;
- if (filterAppAccessLPr(ps, callingUid, component, visibleToInstantApp, callingUserId)) {
+ if (filterAppAccessLPr(ps, callingUid, component, TYPE_ACTIVITY, callingUserId)) {
return false;
}
for (int i=0; i