Loading services/core/java/com/android/server/pm/PackageManagerService.java +41 −31 Original line number Diff line number Diff line Loading @@ -965,7 +965,7 @@ public class PackageManagerService extends IPackageManager.Stub volatile boolean mSystemReady; volatile boolean mSafeMode; volatile boolean mHasSystemUidErrors; private volatile boolean mEphemeralAppsDisabled; private volatile boolean mWebInstantAppsDisabled; ApplicationInfo mAndroidApplication; final ActivityInfo mResolveActivity = new ActivityInfo(); Loading Loading @@ -5951,11 +5951,11 @@ public class PackageManagerService extends IPackageManager.Stub /** * Returns whether or not instant apps have been disabled remotely. */ private boolean isEphemeralDisabled() { return mEphemeralAppsDisabled; private boolean areWebInstantAppsDisabled() { return mWebInstantAppsDisabled; } private boolean isInstantAppAllowed( private boolean isInstantAppResolutionAllowed( Intent intent, List<ResolveInfo> resolvedActivities, int userId, boolean skipPackageCheck) { if (mInstantAppResolverConnection == null) { Loading @@ -5980,9 +5980,13 @@ public class PackageManagerService extends IPackageManager.Stub || (intent.getFlags() & Intent.FLAG_ACTIVITY_MATCH_EXTERNAL) == 0) { return false; } } else if (intent.getData() == null || TextUtils.isEmpty(intent.getData().getHost())) { } else { if (intent.getData() == null || TextUtils.isEmpty(intent.getData().getHost())) { return false; } else if (areWebInstantAppsDisabled()) { return false; } } // Deny ephemeral apps if the user chose _ALWAYS or _ALWAYS_ASK for intent resolution. // Or if there's already an ephemeral app installed that handles the action synchronized (mPackages) { Loading Loading @@ -6512,14 +6516,13 @@ public class PackageManagerService extends IPackageManager.Stub } } return applyPostResolutionFilter( list, instantAppPkgName, allowDynamicSplits, filterCallingUid, userId); list, instantAppPkgName, allowDynamicSplits, filterCallingUid, userId, intent); } // reader boolean sortResult = false; boolean addEphemeral = false; boolean addInstant = false; List<ResolveInfo> result; final boolean ephemeralDisabled = isEphemeralDisabled(); synchronized (mPackages) { if (pkgName == null) { List<CrossProfileIntentFilter> matchingFilters = Loading @@ -6532,14 +6535,14 @@ public class PackageManagerService extends IPackageManager.Stub xpResult.add(xpResolveInfo); return applyPostResolutionFilter( filterIfNotSystemUser(xpResult, userId), instantAppPkgName, allowDynamicSplits, filterCallingUid, userId); allowDynamicSplits, filterCallingUid, userId, intent); } // Check for results in the current profile. result = filterIfNotSystemUser(mActivities.queryIntent( intent, resolvedType, flags, userId), userId); addEphemeral = !ephemeralDisabled && isInstantAppAllowed(intent, result, userId, false /*skipPackageCheck*/); addInstant = isInstantAppResolutionAllowed(intent, result, userId, false /*skipPackageCheck*/); // Check for cross profile results. boolean hasNonNegativePriorityResult = hasNonNegativePriority(result); xpResolveInfo = queryCrossProfileIntents( Loading @@ -6566,20 +6569,20 @@ public class PackageManagerService extends IPackageManager.Stub // in the result. result.remove(xpResolveInfo); } if (result.size() == 0 && !addEphemeral) { if (result.size() == 0 && !addInstant) { // No result in current profile, but found candidate in parent user. // And we are not going to add emphemeral app, so we can return the // result straight away. result.add(xpDomainInfo.resolveInfo); return applyPostResolutionFilter(result, instantAppPkgName, allowDynamicSplits, filterCallingUid, userId); allowDynamicSplits, filterCallingUid, userId, intent); } } else if (result.size() <= 1 && !addEphemeral) { } else if (result.size() <= 1 && !addInstant) { // No result in parent user and <= 1 result in current profile, and we // are not going to add emphemeral app, so we can return the result without // further processing. return applyPostResolutionFilter(result, instantAppPkgName, allowDynamicSplits, filterCallingUid, userId); allowDynamicSplits, filterCallingUid, userId, intent); } // We have more than one candidate (combining results from current and parent // profile), so we need filtering and sorting. Loading @@ -6599,8 +6602,7 @@ public class PackageManagerService extends IPackageManager.Stub if (result == null || result.size() == 0) { // the caller wants to resolve for a particular package; however, there // were no installed results, so, try to find an ephemeral result addEphemeral = !ephemeralDisabled && isInstantAppAllowed( addInstant = isInstantAppResolutionAllowed( intent, null /*result*/, userId, true /*skipPackageCheck*/); if (result == null) { result = new ArrayList<>(); Loading @@ -6608,7 +6610,7 @@ public class PackageManagerService extends IPackageManager.Stub } } } if (addEphemeral) { if (addInstant) { result = maybeAddInstantAppInstaller( result, intent, resolvedType, flags, userId, resolveForStart); } Loading @@ -6616,7 +6618,7 @@ public class PackageManagerService extends IPackageManager.Stub Collections.sort(result, mResolvePrioritySorter); } return applyPostResolutionFilter( result, instantAppPkgName, allowDynamicSplits, filterCallingUid, userId); result, instantAppPkgName, allowDynamicSplits, filterCallingUid, userId, intent); } private List<ResolveInfo> maybeAddInstantAppInstaller(List<ResolveInfo> result, Intent intent, Loading Loading @@ -6820,12 +6822,20 @@ public class PackageManagerService extends IPackageManager.Stub * @param resolveInfos The pre-filtered list of resolved activities * @param ephemeralPkgName The ephemeral package name. If {@code null}, no filtering * is performed. * @param intent * @return A filtered list of resolved activities. */ private List<ResolveInfo> applyPostResolutionFilter(List<ResolveInfo> resolveInfos, String ephemeralPkgName, boolean allowDynamicSplits, int filterCallingUid, int userId) { String ephemeralPkgName, boolean allowDynamicSplits, int filterCallingUid, int userId, Intent intent) { final boolean blockInstant = intent.isWebIntent() && areWebInstantAppsDisabled(); for (int i = resolveInfos.size() - 1; i >= 0; i--) { final ResolveInfo info = resolveInfos.get(i); // remove locally resolved instant app web results when disabled if (info.isInstantAppAvailable && blockInstant) { resolveInfos.remove(i); continue; } // allow activities that are defined in the provided package if (allowDynamicSplits && info.activityInfo != null Loading Loading @@ -7457,7 +7467,7 @@ public class PackageManagerService extends IPackageManager.Stub } } return applyPostResolutionFilter( list, instantAppPkgName, allowDynamicSplits, callingUid, userId); list, instantAppPkgName, allowDynamicSplits, callingUid, userId, intent); } // reader Loading @@ -7467,14 +7477,14 @@ public class PackageManagerService extends IPackageManager.Stub final List<ResolveInfo> result = mReceivers.queryIntent(intent, resolvedType, flags, userId); return applyPostResolutionFilter( result, instantAppPkgName, allowDynamicSplits, callingUid, userId); result, instantAppPkgName, allowDynamicSplits, callingUid, userId, intent); } final PackageParser.Package pkg = mPackages.get(pkgName); if (pkg != null) { final List<ResolveInfo> result = mReceivers.queryIntentForPackage( intent, resolvedType, flags, pkg.receivers, userId); return applyPostResolutionFilter( result, instantAppPkgName, allowDynamicSplits, callingUid, userId); result, instantAppPkgName, allowDynamicSplits, callingUid, userId, intent); } return Collections.emptyList(); } Loading Loading @@ -7944,7 +7954,7 @@ public class PackageManagerService extends IPackageManager.Stub @Override public ParceledListSlice<InstantAppInfo> getInstantApps(int userId) { if (HIDE_EPHEMERAL_APIS || isEphemeralDisabled()) { if (HIDE_EPHEMERAL_APIS) { return null; } if (!canViewInstantApps(Binder.getCallingUid(), userId)) { Loading @@ -7969,7 +7979,7 @@ public class PackageManagerService extends IPackageManager.Stub mPermissionManager.enforceCrossUserPermission(Binder.getCallingUid(), userId, true /* requireFullPermission */, false /* checkShell */, "isInstantApp"); if (HIDE_EPHEMERAL_APIS || isEphemeralDisabled()) { if (HIDE_EPHEMERAL_APIS) { return false; } Loading @@ -7995,7 +8005,7 @@ public class PackageManagerService extends IPackageManager.Stub @Override public byte[] getInstantAppCookie(String packageName, int userId) { if (HIDE_EPHEMERAL_APIS || isEphemeralDisabled()) { if (HIDE_EPHEMERAL_APIS) { return null; } Loading @@ -8013,7 +8023,7 @@ public class PackageManagerService extends IPackageManager.Stub @Override public boolean setInstantAppCookie(String packageName, byte[] cookie, int userId) { if (HIDE_EPHEMERAL_APIS || isEphemeralDisabled()) { if (HIDE_EPHEMERAL_APIS) { return true; } Loading @@ -8031,7 +8041,7 @@ public class PackageManagerService extends IPackageManager.Stub @Override public Bitmap getInstantAppIcon(String packageName, int userId) { if (HIDE_EPHEMERAL_APIS || isEphemeralDisabled()) { if (HIDE_EPHEMERAL_APIS) { return null; } Loading Loading @@ -20705,7 +20715,7 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName()); ContentObserver co = new ContentObserver(mHandler) { @Override public void onChange(boolean selfChange) { mEphemeralAppsDisabled = mWebInstantAppsDisabled = (Global.getInt(resolver, Global.ENABLE_EPHEMERAL_FEATURE, 1) == 0) || (Secure.getInt(resolver, Secure.INSTANT_APPS_ENABLED, 1) == 0); } Loading @@ -20713,7 +20723,7 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName()); mContext.getContentResolver().registerContentObserver(android.provider.Settings.Global .getUriFor(Global.ENABLE_EPHEMERAL_FEATURE), false, co, UserHandle.USER_SYSTEM); mContext.getContentResolver().registerContentObserver(android.provider.Settings.Global mContext.getContentResolver().registerContentObserver(android.provider.Settings.Secure .getUriFor(Secure.INSTANT_APPS_ENABLED), false, co, UserHandle.USER_SYSTEM); co.onChange(true); Loading
services/core/java/com/android/server/pm/PackageManagerService.java +41 −31 Original line number Diff line number Diff line Loading @@ -965,7 +965,7 @@ public class PackageManagerService extends IPackageManager.Stub volatile boolean mSystemReady; volatile boolean mSafeMode; volatile boolean mHasSystemUidErrors; private volatile boolean mEphemeralAppsDisabled; private volatile boolean mWebInstantAppsDisabled; ApplicationInfo mAndroidApplication; final ActivityInfo mResolveActivity = new ActivityInfo(); Loading Loading @@ -5951,11 +5951,11 @@ public class PackageManagerService extends IPackageManager.Stub /** * Returns whether or not instant apps have been disabled remotely. */ private boolean isEphemeralDisabled() { return mEphemeralAppsDisabled; private boolean areWebInstantAppsDisabled() { return mWebInstantAppsDisabled; } private boolean isInstantAppAllowed( private boolean isInstantAppResolutionAllowed( Intent intent, List<ResolveInfo> resolvedActivities, int userId, boolean skipPackageCheck) { if (mInstantAppResolverConnection == null) { Loading @@ -5980,9 +5980,13 @@ public class PackageManagerService extends IPackageManager.Stub || (intent.getFlags() & Intent.FLAG_ACTIVITY_MATCH_EXTERNAL) == 0) { return false; } } else if (intent.getData() == null || TextUtils.isEmpty(intent.getData().getHost())) { } else { if (intent.getData() == null || TextUtils.isEmpty(intent.getData().getHost())) { return false; } else if (areWebInstantAppsDisabled()) { return false; } } // Deny ephemeral apps if the user chose _ALWAYS or _ALWAYS_ASK for intent resolution. // Or if there's already an ephemeral app installed that handles the action synchronized (mPackages) { Loading Loading @@ -6512,14 +6516,13 @@ public class PackageManagerService extends IPackageManager.Stub } } return applyPostResolutionFilter( list, instantAppPkgName, allowDynamicSplits, filterCallingUid, userId); list, instantAppPkgName, allowDynamicSplits, filterCallingUid, userId, intent); } // reader boolean sortResult = false; boolean addEphemeral = false; boolean addInstant = false; List<ResolveInfo> result; final boolean ephemeralDisabled = isEphemeralDisabled(); synchronized (mPackages) { if (pkgName == null) { List<CrossProfileIntentFilter> matchingFilters = Loading @@ -6532,14 +6535,14 @@ public class PackageManagerService extends IPackageManager.Stub xpResult.add(xpResolveInfo); return applyPostResolutionFilter( filterIfNotSystemUser(xpResult, userId), instantAppPkgName, allowDynamicSplits, filterCallingUid, userId); allowDynamicSplits, filterCallingUid, userId, intent); } // Check for results in the current profile. result = filterIfNotSystemUser(mActivities.queryIntent( intent, resolvedType, flags, userId), userId); addEphemeral = !ephemeralDisabled && isInstantAppAllowed(intent, result, userId, false /*skipPackageCheck*/); addInstant = isInstantAppResolutionAllowed(intent, result, userId, false /*skipPackageCheck*/); // Check for cross profile results. boolean hasNonNegativePriorityResult = hasNonNegativePriority(result); xpResolveInfo = queryCrossProfileIntents( Loading @@ -6566,20 +6569,20 @@ public class PackageManagerService extends IPackageManager.Stub // in the result. result.remove(xpResolveInfo); } if (result.size() == 0 && !addEphemeral) { if (result.size() == 0 && !addInstant) { // No result in current profile, but found candidate in parent user. // And we are not going to add emphemeral app, so we can return the // result straight away. result.add(xpDomainInfo.resolveInfo); return applyPostResolutionFilter(result, instantAppPkgName, allowDynamicSplits, filterCallingUid, userId); allowDynamicSplits, filterCallingUid, userId, intent); } } else if (result.size() <= 1 && !addEphemeral) { } else if (result.size() <= 1 && !addInstant) { // No result in parent user and <= 1 result in current profile, and we // are not going to add emphemeral app, so we can return the result without // further processing. return applyPostResolutionFilter(result, instantAppPkgName, allowDynamicSplits, filterCallingUid, userId); allowDynamicSplits, filterCallingUid, userId, intent); } // We have more than one candidate (combining results from current and parent // profile), so we need filtering and sorting. Loading @@ -6599,8 +6602,7 @@ public class PackageManagerService extends IPackageManager.Stub if (result == null || result.size() == 0) { // the caller wants to resolve for a particular package; however, there // were no installed results, so, try to find an ephemeral result addEphemeral = !ephemeralDisabled && isInstantAppAllowed( addInstant = isInstantAppResolutionAllowed( intent, null /*result*/, userId, true /*skipPackageCheck*/); if (result == null) { result = new ArrayList<>(); Loading @@ -6608,7 +6610,7 @@ public class PackageManagerService extends IPackageManager.Stub } } } if (addEphemeral) { if (addInstant) { result = maybeAddInstantAppInstaller( result, intent, resolvedType, flags, userId, resolveForStart); } Loading @@ -6616,7 +6618,7 @@ public class PackageManagerService extends IPackageManager.Stub Collections.sort(result, mResolvePrioritySorter); } return applyPostResolutionFilter( result, instantAppPkgName, allowDynamicSplits, filterCallingUid, userId); result, instantAppPkgName, allowDynamicSplits, filterCallingUid, userId, intent); } private List<ResolveInfo> maybeAddInstantAppInstaller(List<ResolveInfo> result, Intent intent, Loading Loading @@ -6820,12 +6822,20 @@ public class PackageManagerService extends IPackageManager.Stub * @param resolveInfos The pre-filtered list of resolved activities * @param ephemeralPkgName The ephemeral package name. If {@code null}, no filtering * is performed. * @param intent * @return A filtered list of resolved activities. */ private List<ResolveInfo> applyPostResolutionFilter(List<ResolveInfo> resolveInfos, String ephemeralPkgName, boolean allowDynamicSplits, int filterCallingUid, int userId) { String ephemeralPkgName, boolean allowDynamicSplits, int filterCallingUid, int userId, Intent intent) { final boolean blockInstant = intent.isWebIntent() && areWebInstantAppsDisabled(); for (int i = resolveInfos.size() - 1; i >= 0; i--) { final ResolveInfo info = resolveInfos.get(i); // remove locally resolved instant app web results when disabled if (info.isInstantAppAvailable && blockInstant) { resolveInfos.remove(i); continue; } // allow activities that are defined in the provided package if (allowDynamicSplits && info.activityInfo != null Loading Loading @@ -7457,7 +7467,7 @@ public class PackageManagerService extends IPackageManager.Stub } } return applyPostResolutionFilter( list, instantAppPkgName, allowDynamicSplits, callingUid, userId); list, instantAppPkgName, allowDynamicSplits, callingUid, userId, intent); } // reader Loading @@ -7467,14 +7477,14 @@ public class PackageManagerService extends IPackageManager.Stub final List<ResolveInfo> result = mReceivers.queryIntent(intent, resolvedType, flags, userId); return applyPostResolutionFilter( result, instantAppPkgName, allowDynamicSplits, callingUid, userId); result, instantAppPkgName, allowDynamicSplits, callingUid, userId, intent); } final PackageParser.Package pkg = mPackages.get(pkgName); if (pkg != null) { final List<ResolveInfo> result = mReceivers.queryIntentForPackage( intent, resolvedType, flags, pkg.receivers, userId); return applyPostResolutionFilter( result, instantAppPkgName, allowDynamicSplits, callingUid, userId); result, instantAppPkgName, allowDynamicSplits, callingUid, userId, intent); } return Collections.emptyList(); } Loading Loading @@ -7944,7 +7954,7 @@ public class PackageManagerService extends IPackageManager.Stub @Override public ParceledListSlice<InstantAppInfo> getInstantApps(int userId) { if (HIDE_EPHEMERAL_APIS || isEphemeralDisabled()) { if (HIDE_EPHEMERAL_APIS) { return null; } if (!canViewInstantApps(Binder.getCallingUid(), userId)) { Loading @@ -7969,7 +7979,7 @@ public class PackageManagerService extends IPackageManager.Stub mPermissionManager.enforceCrossUserPermission(Binder.getCallingUid(), userId, true /* requireFullPermission */, false /* checkShell */, "isInstantApp"); if (HIDE_EPHEMERAL_APIS || isEphemeralDisabled()) { if (HIDE_EPHEMERAL_APIS) { return false; } Loading @@ -7995,7 +8005,7 @@ public class PackageManagerService extends IPackageManager.Stub @Override public byte[] getInstantAppCookie(String packageName, int userId) { if (HIDE_EPHEMERAL_APIS || isEphemeralDisabled()) { if (HIDE_EPHEMERAL_APIS) { return null; } Loading @@ -8013,7 +8023,7 @@ public class PackageManagerService extends IPackageManager.Stub @Override public boolean setInstantAppCookie(String packageName, byte[] cookie, int userId) { if (HIDE_EPHEMERAL_APIS || isEphemeralDisabled()) { if (HIDE_EPHEMERAL_APIS) { return true; } Loading @@ -8031,7 +8041,7 @@ public class PackageManagerService extends IPackageManager.Stub @Override public Bitmap getInstantAppIcon(String packageName, int userId) { if (HIDE_EPHEMERAL_APIS || isEphemeralDisabled()) { if (HIDE_EPHEMERAL_APIS) { return null; } Loading Loading @@ -20705,7 +20715,7 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName()); ContentObserver co = new ContentObserver(mHandler) { @Override public void onChange(boolean selfChange) { mEphemeralAppsDisabled = mWebInstantAppsDisabled = (Global.getInt(resolver, Global.ENABLE_EPHEMERAL_FEATURE, 1) == 0) || (Secure.getInt(resolver, Secure.INSTANT_APPS_ENABLED, 1) == 0); } Loading @@ -20713,7 +20723,7 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName()); mContext.getContentResolver().registerContentObserver(android.provider.Settings.Global .getUriFor(Global.ENABLE_EPHEMERAL_FEATURE), false, co, UserHandle.USER_SYSTEM); mContext.getContentResolver().registerContentObserver(android.provider.Settings.Global mContext.getContentResolver().registerContentObserver(android.provider.Settings.Secure .getUriFor(Secure.INSTANT_APPS_ENABLED), false, co, UserHandle.USER_SYSTEM); co.onChange(true);