Loading core/java/android/content/pm/PackageManagerInternal.java +6 −0 Original line number Diff line number Diff line Loading @@ -306,4 +306,10 @@ public abstract class PackageManagerInternal { */ public abstract boolean setEnabledOverlayPackages(int userId, String targetPackageName, List<String> overlayPackageNames); /** * Resolves an intent, allowing instant apps to be resolved. */ public abstract ResolveInfo resolveIntent(Intent intent, String resolvedType, int flags, int userId); } services/core/java/com/android/server/am/ActivityStackSupervisor.java +2 −4 Original line number Diff line number Diff line Loading @@ -1196,13 +1196,11 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D } ResolveInfo resolveIntent(Intent intent, String resolvedType, int userId, int flags) { try { return AppGlobals.getPackageManager().resolveIntent(intent, resolvedType, synchronized (mService) { return mService.getPackageManagerInternalLocked().resolveIntent(intent, resolvedType, PackageManager.MATCH_INSTANT | PackageManager.MATCH_DEFAULT_ONLY | flags | ActivityManagerService.STOCK_PM_FLAGS, userId); } catch (RemoteException e) { } return null; } ActivityInfo resolveActivity(Intent intent, String resolvedType, int startFlags, Loading services/core/java/com/android/server/pm/PackageManagerService.java +59 −18 Original line number Diff line number Diff line Loading @@ -4037,8 +4037,17 @@ public class PackageManagerService extends IPackageManager.Stub { /** * Update given flags when being used to request {@link ResolveInfo}. * <p>Instant apps are resolved specially, depending upon context. Minimally, * {@code}flags{@code} must have the {@link PackageManager#MATCH_INSTANT} * flag set. However, this flag is only honoured in three circumstances: * <ul> * <li>when called from a system process</li> * <li>when the caller holds the permission {@code android.permission.ACCESS_INSTANT_APPS}</li> * <li>when resolution occurs to start an activity with a {@code android.intent.action.VIEW} * action and a {@code android.intent.category.BROWSABLE} category</li> * </ul> */ int updateFlagsForResolve(int flags, int userId, Object cookie) { int updateFlagsForResolve(int flags, int userId, Intent intent, boolean includeInstantApp) { // Safe mode means we shouldn't match any third-party components if (mSafeMode) { flags |= PackageManager.MATCH_SYSTEM_ONLY; Loading @@ -4050,15 +4059,24 @@ public class PackageManagerService extends IPackageManager.Stub { flags |= PackageManager.MATCH_INSTANT; } else { // Otherwise, prevent leaking ephemeral components final boolean isSpecialProcess = callingUid == Process.SYSTEM_UID || callingUid == Process.SHELL_UID || callingUid == 0; final boolean allowMatchInstant = (includeInstantApp && Intent.ACTION_VIEW.equals(intent.getAction()) && intent.hasCategory(Intent.CATEGORY_BROWSABLE) && hasWebURI(intent)) || isSpecialProcess || mContext.checkCallingOrSelfPermission( android.Manifest.permission.ACCESS_INSTANT_APPS) == PERMISSION_GRANTED; flags &= ~PackageManager.MATCH_VISIBLE_TO_INSTANT_APP_ONLY; if (callingUid != Process.SYSTEM_UID && callingUid != Process.SHELL_UID && callingUid != 0) { // Unless called from the system process if (!allowMatchInstant) { flags &= ~PackageManager.MATCH_INSTANT; } } return updateFlagsForComponent(flags, userId, cookie); return updateFlagsForComponent(flags, userId, intent /*cookie*/); } @Override Loading Loading @@ -5583,17 +5601,23 @@ public class PackageManagerService extends IPackageManager.Stub { @Override public ResolveInfo resolveIntent(Intent intent, String resolvedType, int flags, int userId) { return resolveIntentInternal( intent, resolvedType, flags, userId, false /*includeInstantApp*/); } private ResolveInfo resolveIntentInternal(Intent intent, String resolvedType, int flags, int userId, boolean includeInstantApp) { try { Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "resolveIntent"); if (!sUserManager.exists(userId)) return null; flags = updateFlagsForResolve(flags, userId, intent); flags = updateFlagsForResolve(flags, userId, intent, includeInstantApp); enforceCrossUserPermission(Binder.getCallingUid(), userId, false /*requireFullPermission*/, false /*checkShell*/, "resolve intent"); Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "queryIntentActivities"); final List<ResolveInfo> query = queryIntentActivitiesInternal(intent, resolvedType, flags, userId); flags, userId, includeInstantApp); Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER); final ResolveInfo bestChoice = Loading @@ -5615,7 +5639,7 @@ public class PackageManagerService extends IPackageManager.Stub { } intent = updateIntentForResolve(intent); final String resolvedType = intent.resolveTypeIfNeeded(mContext.getContentResolver()); final int flags = updateFlagsForResolve(0, userId, intent); final int flags = updateFlagsForResolve(0, userId, intent, false); final List<ResolveInfo> query = queryIntentActivitiesInternal(intent, resolvedType, flags, userId); synchronized (mPackages) { Loading Loading @@ -5774,6 +5798,13 @@ public class PackageManagerService extends IPackageManager.Stub { if (ri != null) { return ri; } // If we have an ephemeral app, use it for (int i = 0; i < N; i++) { ri = query.get(i); if (ri.activityInfo.applicationInfo.isInstantApp()) { return ri; } } ri = new ResolveInfo(mResolveInfo); ri.activityInfo = new ActivityInfo(ri.activityInfo); ri.activityInfo.labelRes = ResolverActivity.getLabelRes(intent.getAction()); Loading Loading @@ -5892,7 +5923,7 @@ public class PackageManagerService extends IPackageManager.Stub { List<ResolveInfo> query, int priority, boolean always, boolean removeMatches, boolean debug, int userId) { if (!sUserManager.exists(userId)) return null; flags = updateFlagsForResolve(flags, userId, intent); flags = updateFlagsForResolve(flags, userId, intent, false); intent = updateIntentForResolve(intent); // writer synchronized (mPackages) { Loading Loading @@ -6060,7 +6091,7 @@ public class PackageManagerService extends IPackageManager.Stub { // cross-profile app linking works only towards the parent. final UserInfo parent = getProfileParent(sourceUserId); synchronized(mPackages) { int flags = updateFlagsForResolve(0, parent.id, intent); int flags = updateFlagsForResolve(0, parent.id, intent, false); CrossProfileDomainInfo xpDomainInfo = getCrossProfileDomainPreferredLpr( intent, resolvedType, flags, sourceUserId, parent.id); return xpDomainInfo != null; Loading Loading @@ -6119,9 +6150,14 @@ public class PackageManagerService extends IPackageManager.Stub { private @NonNull List<ResolveInfo> queryIntentActivitiesInternal(Intent intent, String resolvedType, int flags, int userId) { return queryIntentActivitiesInternal(intent, resolvedType, flags, userId, false); } private @NonNull List<ResolveInfo> queryIntentActivitiesInternal(Intent intent, String resolvedType, int flags, int userId, boolean includeInstantApp) { if (!sUserManager.exists(userId)) return Collections.emptyList(); final String instantAppPkgName = getInstantAppPackageName(Binder.getCallingUid()); flags = updateFlagsForResolve(flags, userId, intent); flags = updateFlagsForResolve(flags, userId, intent, includeInstantApp); enforceCrossUserPermission(Binder.getCallingUid(), userId, false /* requireFullPermission */, false /* checkShell */, "query intent activities"); Loading Loading @@ -6748,7 +6784,7 @@ public class PackageManagerService extends IPackageManager.Stub { Intent[] specifics, String[] specificTypes, Intent intent, String resolvedType, int flags, int userId) { if (!sUserManager.exists(userId)) return Collections.emptyList(); flags = updateFlagsForResolve(flags, userId, intent); flags = updateFlagsForResolve(flags, userId, intent, false); enforceCrossUserPermission(Binder.getCallingUid(), userId, false /* requireFullPermission */, false /* checkShell */, "query intent activity options"); Loading Loading @@ -6928,7 +6964,7 @@ public class PackageManagerService extends IPackageManager.Stub { private @NonNull List<ResolveInfo> queryIntentReceiversInternal(Intent intent, String resolvedType, int flags, int userId) { if (!sUserManager.exists(userId)) return Collections.emptyList(); flags = updateFlagsForResolve(flags, userId, intent); flags = updateFlagsForResolve(flags, userId, intent, false); ComponentName comp = intent.getComponent(); if (comp == null) { if (intent.getSelector() != null) { Loading Loading @@ -6965,7 +7001,7 @@ public class PackageManagerService extends IPackageManager.Stub { @Override public ResolveInfo resolveService(Intent intent, String resolvedType, int flags, int userId) { if (!sUserManager.exists(userId)) return null; flags = updateFlagsForResolve(flags, userId, intent); flags = updateFlagsForResolve(flags, userId, intent, false); List<ResolveInfo> query = queryIntentServicesInternal(intent, resolvedType, flags, userId); if (query != null) { if (query.size() >= 1) { Loading @@ -6987,7 +7023,7 @@ public class PackageManagerService extends IPackageManager.Stub { private @NonNull List<ResolveInfo> queryIntentServicesInternal(Intent intent, String resolvedType, int flags, int userId) { if (!sUserManager.exists(userId)) return Collections.emptyList(); flags = updateFlagsForResolve(flags, userId, intent); flags = updateFlagsForResolve(flags, userId, intent, false); ComponentName comp = intent.getComponent(); if (comp == null) { if (intent.getSelector() != null) { Loading Loading @@ -7031,7 +7067,7 @@ public class PackageManagerService extends IPackageManager.Stub { private @NonNull List<ResolveInfo> queryIntentContentProvidersInternal( Intent intent, String resolvedType, int flags, int userId) { if (!sUserManager.exists(userId)) return Collections.emptyList(); flags = updateFlagsForResolve(flags, userId, intent); flags = updateFlagsForResolve(flags, userId, intent, false); ComponentName comp = intent.getComponent(); if (comp == null) { if (intent.getSelector() != null) { Loading Loading @@ -22975,7 +23011,6 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName()); return targetPackages; } @Override public boolean setEnabledOverlayPackages(int userId, @NonNull String targetPackageName, @Nullable List<String> overlayPackageNames) { Loading Loading @@ -23015,6 +23050,12 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName()); return true; } } public ResolveInfo resolveIntent(Intent intent, String resolvedType, int flags, int userId) { return resolveIntentInternal( intent, resolvedType, flags, userId, true /*includeInstantApp*/); } } @Override services/core/java/com/android/server/pm/Settings.java +1 −1 Original line number Diff line number Diff line Loading @@ -3370,7 +3370,7 @@ final class Settings { private void applyDefaultPreferredActivityLPw(PackageManagerService service, Intent intent, int flags, ComponentName cn, String scheme, PatternMatcher ssp, IntentFilter.AuthorityEntry auth, PatternMatcher path, int userId) { flags = service.updateFlagsForResolve(flags, userId, intent); flags = service.updateFlagsForResolve(flags, userId, intent, false); List<ResolveInfo> ri = service.mActivities.queryIntent(intent, intent.getType(), flags, 0); if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Queried " + intent Loading Loading
core/java/android/content/pm/PackageManagerInternal.java +6 −0 Original line number Diff line number Diff line Loading @@ -306,4 +306,10 @@ public abstract class PackageManagerInternal { */ public abstract boolean setEnabledOverlayPackages(int userId, String targetPackageName, List<String> overlayPackageNames); /** * Resolves an intent, allowing instant apps to be resolved. */ public abstract ResolveInfo resolveIntent(Intent intent, String resolvedType, int flags, int userId); }
services/core/java/com/android/server/am/ActivityStackSupervisor.java +2 −4 Original line number Diff line number Diff line Loading @@ -1196,13 +1196,11 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D } ResolveInfo resolveIntent(Intent intent, String resolvedType, int userId, int flags) { try { return AppGlobals.getPackageManager().resolveIntent(intent, resolvedType, synchronized (mService) { return mService.getPackageManagerInternalLocked().resolveIntent(intent, resolvedType, PackageManager.MATCH_INSTANT | PackageManager.MATCH_DEFAULT_ONLY | flags | ActivityManagerService.STOCK_PM_FLAGS, userId); } catch (RemoteException e) { } return null; } ActivityInfo resolveActivity(Intent intent, String resolvedType, int startFlags, Loading
services/core/java/com/android/server/pm/PackageManagerService.java +59 −18 Original line number Diff line number Diff line Loading @@ -4037,8 +4037,17 @@ public class PackageManagerService extends IPackageManager.Stub { /** * Update given flags when being used to request {@link ResolveInfo}. * <p>Instant apps are resolved specially, depending upon context. Minimally, * {@code}flags{@code} must have the {@link PackageManager#MATCH_INSTANT} * flag set. However, this flag is only honoured in three circumstances: * <ul> * <li>when called from a system process</li> * <li>when the caller holds the permission {@code android.permission.ACCESS_INSTANT_APPS}</li> * <li>when resolution occurs to start an activity with a {@code android.intent.action.VIEW} * action and a {@code android.intent.category.BROWSABLE} category</li> * </ul> */ int updateFlagsForResolve(int flags, int userId, Object cookie) { int updateFlagsForResolve(int flags, int userId, Intent intent, boolean includeInstantApp) { // Safe mode means we shouldn't match any third-party components if (mSafeMode) { flags |= PackageManager.MATCH_SYSTEM_ONLY; Loading @@ -4050,15 +4059,24 @@ public class PackageManagerService extends IPackageManager.Stub { flags |= PackageManager.MATCH_INSTANT; } else { // Otherwise, prevent leaking ephemeral components final boolean isSpecialProcess = callingUid == Process.SYSTEM_UID || callingUid == Process.SHELL_UID || callingUid == 0; final boolean allowMatchInstant = (includeInstantApp && Intent.ACTION_VIEW.equals(intent.getAction()) && intent.hasCategory(Intent.CATEGORY_BROWSABLE) && hasWebURI(intent)) || isSpecialProcess || mContext.checkCallingOrSelfPermission( android.Manifest.permission.ACCESS_INSTANT_APPS) == PERMISSION_GRANTED; flags &= ~PackageManager.MATCH_VISIBLE_TO_INSTANT_APP_ONLY; if (callingUid != Process.SYSTEM_UID && callingUid != Process.SHELL_UID && callingUid != 0) { // Unless called from the system process if (!allowMatchInstant) { flags &= ~PackageManager.MATCH_INSTANT; } } return updateFlagsForComponent(flags, userId, cookie); return updateFlagsForComponent(flags, userId, intent /*cookie*/); } @Override Loading Loading @@ -5583,17 +5601,23 @@ public class PackageManagerService extends IPackageManager.Stub { @Override public ResolveInfo resolveIntent(Intent intent, String resolvedType, int flags, int userId) { return resolveIntentInternal( intent, resolvedType, flags, userId, false /*includeInstantApp*/); } private ResolveInfo resolveIntentInternal(Intent intent, String resolvedType, int flags, int userId, boolean includeInstantApp) { try { Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "resolveIntent"); if (!sUserManager.exists(userId)) return null; flags = updateFlagsForResolve(flags, userId, intent); flags = updateFlagsForResolve(flags, userId, intent, includeInstantApp); enforceCrossUserPermission(Binder.getCallingUid(), userId, false /*requireFullPermission*/, false /*checkShell*/, "resolve intent"); Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "queryIntentActivities"); final List<ResolveInfo> query = queryIntentActivitiesInternal(intent, resolvedType, flags, userId); flags, userId, includeInstantApp); Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER); final ResolveInfo bestChoice = Loading @@ -5615,7 +5639,7 @@ public class PackageManagerService extends IPackageManager.Stub { } intent = updateIntentForResolve(intent); final String resolvedType = intent.resolveTypeIfNeeded(mContext.getContentResolver()); final int flags = updateFlagsForResolve(0, userId, intent); final int flags = updateFlagsForResolve(0, userId, intent, false); final List<ResolveInfo> query = queryIntentActivitiesInternal(intent, resolvedType, flags, userId); synchronized (mPackages) { Loading Loading @@ -5774,6 +5798,13 @@ public class PackageManagerService extends IPackageManager.Stub { if (ri != null) { return ri; } // If we have an ephemeral app, use it for (int i = 0; i < N; i++) { ri = query.get(i); if (ri.activityInfo.applicationInfo.isInstantApp()) { return ri; } } ri = new ResolveInfo(mResolveInfo); ri.activityInfo = new ActivityInfo(ri.activityInfo); ri.activityInfo.labelRes = ResolverActivity.getLabelRes(intent.getAction()); Loading Loading @@ -5892,7 +5923,7 @@ public class PackageManagerService extends IPackageManager.Stub { List<ResolveInfo> query, int priority, boolean always, boolean removeMatches, boolean debug, int userId) { if (!sUserManager.exists(userId)) return null; flags = updateFlagsForResolve(flags, userId, intent); flags = updateFlagsForResolve(flags, userId, intent, false); intent = updateIntentForResolve(intent); // writer synchronized (mPackages) { Loading Loading @@ -6060,7 +6091,7 @@ public class PackageManagerService extends IPackageManager.Stub { // cross-profile app linking works only towards the parent. final UserInfo parent = getProfileParent(sourceUserId); synchronized(mPackages) { int flags = updateFlagsForResolve(0, parent.id, intent); int flags = updateFlagsForResolve(0, parent.id, intent, false); CrossProfileDomainInfo xpDomainInfo = getCrossProfileDomainPreferredLpr( intent, resolvedType, flags, sourceUserId, parent.id); return xpDomainInfo != null; Loading Loading @@ -6119,9 +6150,14 @@ public class PackageManagerService extends IPackageManager.Stub { private @NonNull List<ResolveInfo> queryIntentActivitiesInternal(Intent intent, String resolvedType, int flags, int userId) { return queryIntentActivitiesInternal(intent, resolvedType, flags, userId, false); } private @NonNull List<ResolveInfo> queryIntentActivitiesInternal(Intent intent, String resolvedType, int flags, int userId, boolean includeInstantApp) { if (!sUserManager.exists(userId)) return Collections.emptyList(); final String instantAppPkgName = getInstantAppPackageName(Binder.getCallingUid()); flags = updateFlagsForResolve(flags, userId, intent); flags = updateFlagsForResolve(flags, userId, intent, includeInstantApp); enforceCrossUserPermission(Binder.getCallingUid(), userId, false /* requireFullPermission */, false /* checkShell */, "query intent activities"); Loading Loading @@ -6748,7 +6784,7 @@ public class PackageManagerService extends IPackageManager.Stub { Intent[] specifics, String[] specificTypes, Intent intent, String resolvedType, int flags, int userId) { if (!sUserManager.exists(userId)) return Collections.emptyList(); flags = updateFlagsForResolve(flags, userId, intent); flags = updateFlagsForResolve(flags, userId, intent, false); enforceCrossUserPermission(Binder.getCallingUid(), userId, false /* requireFullPermission */, false /* checkShell */, "query intent activity options"); Loading Loading @@ -6928,7 +6964,7 @@ public class PackageManagerService extends IPackageManager.Stub { private @NonNull List<ResolveInfo> queryIntentReceiversInternal(Intent intent, String resolvedType, int flags, int userId) { if (!sUserManager.exists(userId)) return Collections.emptyList(); flags = updateFlagsForResolve(flags, userId, intent); flags = updateFlagsForResolve(flags, userId, intent, false); ComponentName comp = intent.getComponent(); if (comp == null) { if (intent.getSelector() != null) { Loading Loading @@ -6965,7 +7001,7 @@ public class PackageManagerService extends IPackageManager.Stub { @Override public ResolveInfo resolveService(Intent intent, String resolvedType, int flags, int userId) { if (!sUserManager.exists(userId)) return null; flags = updateFlagsForResolve(flags, userId, intent); flags = updateFlagsForResolve(flags, userId, intent, false); List<ResolveInfo> query = queryIntentServicesInternal(intent, resolvedType, flags, userId); if (query != null) { if (query.size() >= 1) { Loading @@ -6987,7 +7023,7 @@ public class PackageManagerService extends IPackageManager.Stub { private @NonNull List<ResolveInfo> queryIntentServicesInternal(Intent intent, String resolvedType, int flags, int userId) { if (!sUserManager.exists(userId)) return Collections.emptyList(); flags = updateFlagsForResolve(flags, userId, intent); flags = updateFlagsForResolve(flags, userId, intent, false); ComponentName comp = intent.getComponent(); if (comp == null) { if (intent.getSelector() != null) { Loading Loading @@ -7031,7 +7067,7 @@ public class PackageManagerService extends IPackageManager.Stub { private @NonNull List<ResolveInfo> queryIntentContentProvidersInternal( Intent intent, String resolvedType, int flags, int userId) { if (!sUserManager.exists(userId)) return Collections.emptyList(); flags = updateFlagsForResolve(flags, userId, intent); flags = updateFlagsForResolve(flags, userId, intent, false); ComponentName comp = intent.getComponent(); if (comp == null) { if (intent.getSelector() != null) { Loading Loading @@ -22975,7 +23011,6 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName()); return targetPackages; } @Override public boolean setEnabledOverlayPackages(int userId, @NonNull String targetPackageName, @Nullable List<String> overlayPackageNames) { Loading Loading @@ -23015,6 +23050,12 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName()); return true; } } public ResolveInfo resolveIntent(Intent intent, String resolvedType, int flags, int userId) { return resolveIntentInternal( intent, resolvedType, flags, userId, true /*includeInstantApp*/); } } @Override
services/core/java/com/android/server/pm/Settings.java +1 −1 Original line number Diff line number Diff line Loading @@ -3370,7 +3370,7 @@ final class Settings { private void applyDefaultPreferredActivityLPw(PackageManagerService service, Intent intent, int flags, ComponentName cn, String scheme, PatternMatcher ssp, IntentFilter.AuthorityEntry auth, PatternMatcher path, int userId) { flags = service.updateFlagsForResolve(flags, userId, intent); flags = service.updateFlagsForResolve(flags, userId, intent, false); List<ResolveInfo> ri = service.mActivities.queryIntent(intent, intent.getType(), flags, 0); if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Queried " + intent Loading