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

Commit 2deec664 authored by Todd Kennedy's avatar Todd Kennedy
Browse files

Allow instant apps to launch instant apps

Instant apps should be able to launch other instant apps indirectly
using a web URI or with the MATCH_EXTERNAL flag set..

Change-Id: I2566937dd5d47076701c49435365dedd8593067a
Fixes: 92742631
Test: atest CtsAppSecurityHostTestCases:EphemeralTest
parent e3348a25
Loading
Loading
Loading
Loading
+24 −10
Original line number Diff line number Diff line
@@ -6626,7 +6626,8 @@ public class PackageManagerService extends IPackageManager.Stub
                }
            }
            return applyPostResolutionFilter(
                    list, instantAppPkgName, allowDynamicSplits, filterCallingUid, userId, intent);
                    list, instantAppPkgName, allowDynamicSplits, filterCallingUid, resolveForStart,
                    userId, intent);
        }
        // reader
@@ -6645,7 +6646,7 @@ public class PackageManagerService extends IPackageManager.Stub
                    xpResult.add(xpResolveInfo);
                    return applyPostResolutionFilter(
                            filterIfNotSystemUser(xpResult, userId), instantAppPkgName,
                            allowDynamicSplits, filterCallingUid, userId, intent);
                            allowDynamicSplits, filterCallingUid, resolveForStart, userId, intent);
                }
                // Check for results in the current profile.
@@ -6685,14 +6686,16 @@ public class PackageManagerService extends IPackageManager.Stub
                            // result straight away.
                            result.add(xpDomainInfo.resolveInfo);
                            return applyPostResolutionFilter(result, instantAppPkgName,
                                    allowDynamicSplits, filterCallingUid, userId, intent);
                                    allowDynamicSplits, filterCallingUid, resolveForStart, userId,
                                    intent);
                        }
                    } 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, intent);
                                allowDynamicSplits, filterCallingUid, resolveForStart, userId,
                                intent);
                    }
                    // We have more than one candidate (combining results from current and parent
                    // profile), so we need filtering and sorting.
@@ -6728,7 +6731,8 @@ public class PackageManagerService extends IPackageManager.Stub
            Collections.sort(result, mResolvePrioritySorter);
        }
        return applyPostResolutionFilter(
                result, instantAppPkgName, allowDynamicSplits, filterCallingUid, userId, intent);
                result, instantAppPkgName, allowDynamicSplits, filterCallingUid, resolveForStart,
                userId, intent);
    }
    private List<ResolveInfo> maybeAddInstantAppInstaller(List<ResolveInfo> result, Intent intent,
@@ -6938,8 +6942,8 @@ public class PackageManagerService extends IPackageManager.Stub
     * @return A filtered list of resolved activities.
     */
    private List<ResolveInfo> applyPostResolutionFilter(List<ResolveInfo> resolveInfos,
            String ephemeralPkgName, boolean allowDynamicSplits, int filterCallingUid, int userId,
            Intent intent) {
            String ephemeralPkgName, boolean allowDynamicSplits, int filterCallingUid,
            boolean resolveForStart, 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);
@@ -6998,6 +7002,13 @@ public class PackageManagerService extends IPackageManager.Stub
            } else if (ephemeralPkgName.equals(info.activityInfo.packageName)) {
                // caller is same app; don't need to apply any other filtering
                continue;
            } else if (resolveForStart
                    && (intent.isWebIntent()
                            || (intent.getFlags() & Intent.FLAG_ACTIVITY_MATCH_EXTERNAL) != 0)
                    && intent.getPackage() == null
                    && intent.getComponent() == null) {
                // ephemeral apps can launch other ephemeral apps indirectly
                continue;
            }
            // allow activities that have been explicitly exposed to ephemeral apps
            final boolean isEphemeralApp = info.activityInfo.applicationInfo.isInstantApp();
@@ -7576,7 +7587,8 @@ public class PackageManagerService extends IPackageManager.Stub
                }
            }
            return applyPostResolutionFilter(
                    list, instantAppPkgName, allowDynamicSplits, callingUid, userId, intent);
                    list, instantAppPkgName, allowDynamicSplits, callingUid, false, userId,
                    intent);
        }
        // reader
@@ -7586,14 +7598,16 @@ public class PackageManagerService extends IPackageManager.Stub
                final List<ResolveInfo> result =
                        mReceivers.queryIntent(intent, resolvedType, flags, userId);
                return applyPostResolutionFilter(
                        result, instantAppPkgName, allowDynamicSplits, callingUid, userId, intent);
                        result, instantAppPkgName, allowDynamicSplits, callingUid, false, 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, intent);
                        result, instantAppPkgName, allowDynamicSplits, callingUid, false, userId,
                        intent);
            }
            return Collections.emptyList();
        }