Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dfcb87cd authored by Android Build Merger (Role)'s avatar Android Build Merger (Role) Committed by Android (Google) Code Review
Browse files

Merge "Merge "Optionally let the instant app into disambig" into oc-dev am:...

Merge "Merge "Optionally let the instant app into disambig" into oc-dev am: 1f1d60c5 am: 74e39de9"
parents ea64770e 2b331164
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -97,7 +97,8 @@ public class ResolverListController {
            final List<ResolveInfo> infos = mpm.queryIntentActivities(intent,
            final List<ResolveInfo> infos = mpm.queryIntentActivities(intent,
                    PackageManager.MATCH_DEFAULT_ONLY
                    PackageManager.MATCH_DEFAULT_ONLY
                            | (shouldGetResolvedFilter ? PackageManager.GET_RESOLVED_FILTER : 0)
                            | (shouldGetResolvedFilter ? PackageManager.GET_RESOLVED_FILTER : 0)
                            | (shouldGetActivityMetadata ? PackageManager.GET_META_DATA : 0));
                            | (shouldGetActivityMetadata ? PackageManager.GET_META_DATA : 0)
                            | PackageManager.MATCH_INSTANT);
            if (infos != null) {
            if (infos != null) {
                if (resolvedComponents == null) {
                if (resolvedComponents == null) {
                    resolvedComponents = new ArrayList<>();
                    resolvedComponents = new ArrayList<>();
+87 −33
Original line number Original line Diff line number Diff line
@@ -5871,10 +5871,9 @@ public class PackageManagerService extends IPackageManager.Stub
        return mEphemeralAppsDisabled;
        return mEphemeralAppsDisabled;
    }
    }
    private boolean isEphemeralAllowed(
    private boolean isInstantAppAllowed(
            Intent intent, List<ResolveInfo> resolvedActivities, int userId,
            Intent intent, List<ResolveInfo> resolvedActivities, int userId,
            boolean skipPackageCheck) {
            boolean skipPackageCheck) {
        final int callingUser = UserHandle.getCallingUserId();
        if (mInstantAppResolverConnection == null) {
        if (mInstantAppResolverConnection == null) {
            return false;
            return false;
        }
        }
@@ -5974,9 +5973,15 @@ public class PackageManagerService extends IPackageManager.Stub
                for (int i = 0; i < N; i++) {
                for (int i = 0; i < N; i++) {
                    ri = query.get(i);
                    ri = query.get(i);
                    if (ri.activityInfo.applicationInfo.isInstantApp()) {
                    if (ri.activityInfo.applicationInfo.isInstantApp()) {
                        final String packageName = ri.activityInfo.packageName;
                        final PackageSetting ps = mSettings.mPackages.get(packageName);
                        final long packedStatus = getDomainVerificationStatusLPr(ps, userId);
                        final int status = (int)(packedStatus >> 32);
                        if (status != INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS_ASK) {
                            return ri;
                            return ri;
                        }
                        }
                    }
                    }
                }
                ri = new ResolveInfo(mResolveInfo);
                ri = new ResolveInfo(mResolveInfo);
                ri.activityInfo = new ActivityInfo(ri.activityInfo);
                ri.activityInfo = new ActivityInfo(ri.activityInfo);
                ri.activityInfo.labelRes = ResolverActivity.getLabelRes(intent.getAction());
                ri.activityInfo.labelRes = ResolverActivity.getLabelRes(intent.getAction());
@@ -6418,7 +6423,7 @@ public class PackageManagerService extends IPackageManager.Stub
                result = filterIfNotSystemUser(mActivities.queryIntent(
                result = filterIfNotSystemUser(mActivities.queryIntent(
                        intent, resolvedType, flags, userId), userId);
                        intent, resolvedType, flags, userId), userId);
                addEphemeral = !ephemeralDisabled
                addEphemeral = !ephemeralDisabled
                        && isEphemeralAllowed(intent, result, userId, false /*skipPackageCheck*/);
                        && isInstantAppAllowed(intent, result, userId, false /*skipPackageCheck*/);
                // Check for cross profile results.
                // Check for cross profile results.
                boolean hasNonNegativePriorityResult = hasNonNegativePriority(result);
                boolean hasNonNegativePriorityResult = hasNonNegativePriority(result);
                xpResolveInfo = queryCrossProfileIntents(
                xpResolveInfo = queryCrossProfileIntents(
@@ -6475,21 +6480,75 @@ public class PackageManagerService extends IPackageManager.Stub
                    // the caller wants to resolve for a particular package; however, there
                    // the caller wants to resolve for a particular package; however, there
                    // were no installed results, so, try to find an ephemeral result
                    // were no installed results, so, try to find an ephemeral result
                    addEphemeral = !ephemeralDisabled
                    addEphemeral = !ephemeralDisabled
                            && isEphemeralAllowed(
                            && isInstantAppAllowed(
                                    intent, null /*result*/, userId, true /*skipPackageCheck*/);
                                    intent, null /*result*/, userId, true /*skipPackageCheck*/);
                    result = new ArrayList<ResolveInfo>();
                    result = new ArrayList<ResolveInfo>();
                }
                }
            }
            }
        }
        }
        if (addEphemeral) {
        if (addEphemeral) {
            result = maybeAddInstantAppInstaller(result, intent, resolvedType, flags, userId);
        }
        if (sortResult) {
            Collections.sort(result, mResolvePrioritySorter);
        }
        return applyPostResolutionFilter(result, instantAppPkgName);
    }
    private List<ResolveInfo> maybeAddInstantAppInstaller(List<ResolveInfo> result, Intent intent,
            String resolvedType, int flags, int userId) {
        // first, check to see if we've got an instant app already installed
        final boolean alreadyResolvedLocally = (flags & PackageManager.MATCH_INSTANT) != 0;
        boolean localInstantAppAvailable = false;
        boolean blockResolution = false;
        if (!alreadyResolvedLocally) {
            final List<ResolveInfo> instantApps = mActivities.queryIntent(intent, resolvedType,
                    flags
                        | PackageManager.MATCH_INSTANT
                        | PackageManager.MATCH_VISIBLE_TO_INSTANT_APP_ONLY,
                    userId);
            for (int i = instantApps.size() - 1; i >= 0; --i) {
                final ResolveInfo info = instantApps.get(i);
                final String packageName = info.activityInfo.packageName;
                final PackageSetting ps = mSettings.mPackages.get(packageName);
                if (ps.getInstantApp(userId)) {
                    final long packedStatus = getDomainVerificationStatusLPr(ps, userId);
                    final int status = (int)(packedStatus >> 32);
                    final int linkGeneration = (int)(packedStatus & 0xFFFFFFFF);
                    if (status == INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_NEVER) {
                        // there's a local instant application installed, but, the user has
                        // chosen to never use it; skip resolution and don't acknowledge
                        // an instant application is even available
                        if (DEBUG_EPHEMERAL) {
                            Slog.v(TAG, "Instant app marked to never run; pkg: " + packageName);
                        }
                        blockResolution = true;
                        break;
                    } else {
                        // we have a locally installed instant application; skip resolution
                        // but acknowledge there's an instant application available
                        if (DEBUG_EPHEMERAL) {
                            Slog.v(TAG, "Found installed instant app; pkg: " + packageName);
                        }
                        localInstantAppAvailable = true;
                        break;
                    }
                }
            }
        }
        // no app installed, let's see if one's available
        AuxiliaryResolveInfo auxiliaryResponse = null;
        if (!localInstantAppAvailable && !blockResolution) {
            Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "resolveEphemeral");
            Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "resolveEphemeral");
            final InstantAppRequest requestObject = new InstantAppRequest(
            final InstantAppRequest requestObject = new InstantAppRequest(
                    null /*responseObj*/, intent /*origIntent*/, resolvedType,
                    null /*responseObj*/, intent /*origIntent*/, resolvedType,
                    null /*callingPackage*/, userId, null /*verificationBundle*/);
                    null /*callingPackage*/, userId, null /*verificationBundle*/);
            final AuxiliaryResolveInfo auxiliaryResponse =
            auxiliaryResponse =
                    InstantAppResolver.doInstantAppResolutionPhaseOne(
                    InstantAppResolver.doInstantAppResolutionPhaseOne(
                            mContext, mInstantAppResolverConnection, requestObject);
                            mContext, mInstantAppResolverConnection, requestObject);
            if (auxiliaryResponse != null) {
            Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
        }
        if (localInstantAppAvailable || auxiliaryResponse != null) {
            if (DEBUG_EPHEMERAL) {
            if (DEBUG_EPHEMERAL) {
                Slog.v(TAG, "Adding ephemeral installer to the ResolveInfo list");
                Slog.v(TAG, "Adding ephemeral installer to the ResolveInfo list");
            }
            }
@@ -6509,16 +6568,11 @@ public class PackageManagerService extends IPackageManager.Stub
                ephemeralInstaller.filter = new IntentFilter(intent.getAction());
                ephemeralInstaller.filter = new IntentFilter(intent.getAction());
                ephemeralInstaller.filter.addDataPath(
                ephemeralInstaller.filter.addDataPath(
                        intent.getData().getPath(), PatternMatcher.PATTERN_LITERAL);
                        intent.getData().getPath(), PatternMatcher.PATTERN_LITERAL);
                    ephemeralInstaller.isInstantAppAvailable = true;
                ephemeralInstaller.instantAppAvailable = true;
                result.add(ephemeralInstaller);
                result.add(ephemeralInstaller);
            }
            }
        }
        }
            Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
        return result;
        }
        if (sortResult) {
            Collections.sort(result, mResolvePrioritySorter);
        }
        return applyPostResolutionFilter(result, instantAppPkgName);
    }
    }
    private static class CrossProfileDomainInfo {
    private static class CrossProfileDomainInfo {