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

Commit e02001e2 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Marks app filtering interactions correctly"

parents 03e5c28d de37e438
Loading
Loading
Loading
Loading
+14 −14
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package android.content.pm;
package android.content.pm;


import android.annotation.AppIdInt;
import android.annotation.IntDef;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
@@ -321,25 +322,24 @@ public abstract class PackageManagerInternal {
            Bundle verificationBundle, int userId);
            Bundle verificationBundle, int userId);


    /**
    /**
     * Grants access to the package metadata for an ephemeral application.
     * Grants implicit access based on an interaction between two apps. This grants the target app
     * access to the calling application's package metadata.
     * <p>
     * <p>
     * When an ephemeral application explicitly tries to interact with a full
     * When an application explicitly tries to interact with another application [via an
     * install application [via an activity, service or provider that has been
     * activity, service or provider that is either declared in the caller's
     * exposed using the {@code visibleToInstantApp} attribute], the normal
     * manifest via the {@code <queries>} tag or has been exposed via the target apps manifest using
     * application must be able to see metadata about the connecting ephemeral
     * the {@code visibleToInstantApp} attribute], the target application must be able to see
     * app. If the ephemeral application uses an implicit intent [ie action VIEW,
     * metadata about the calling app. If the calling application uses an implicit intent [ie
     * category BROWSABLE], it remains hidden from the launched activity.
     * action VIEW, category BROWSABLE], it remains hidden from the launched app.
     * <p>
     * <p>
     * If the {@code sourceUid} is not for an ephemeral app or {@code targetUid}
     * is not for a fully installed app, this method will be a no-op.
     *
     * @param userId the user
     * @param userId the user
     * @param intent the intent that triggered the grant
     * @param intent the intent that triggered the grant
     * @param targetAppId The app ID of the fully installed application
     * @param callingAppId The app ID of the calling application
     * @param ephemeralAppId The app ID of the ephemeral application
     * @param targetAppId The app ID of the target application
     */
     */
    public abstract void grantEphemeralAccess(int userId, Intent intent,
    public abstract void grantImplicitAccess(
            int targetAppId, int ephemeralAppId);
            @UserIdInt int userId, Intent intent, @AppIdInt int callingAppId,
            @AppIdInt int targetAppId);


    public abstract boolean isInstantAppInstallerComponent(ComponentName component);
    public abstract boolean isInstantAppInstallerComponent(ComponentName component);
    /**
    /**
+5 −4
Original line number Original line Diff line number Diff line
@@ -1748,8 +1748,8 @@ public final class ActiveServices {
                    s.instanceName, s.processName);
                    s.instanceName, s.processName);
            // Once the apps have become associated, if one of them is caller is ephemeral
            // Once the apps have become associated, if one of them is caller is ephemeral
            // the target app should now be able to see the calling app
            // the target app should now be able to see the calling app
            mAm.grantEphemeralAccessLocked(callerApp.userId, service,
            mAm.grantImplicitAccess(callerApp.userId, service,
                    UserHandle.getAppId(s.appInfo.uid), UserHandle.getAppId(callerApp.uid));
                    UserHandle.getAppId(callerApp.uid), UserHandle.getAppId(s.appInfo.uid));


            AppBindRecord b = s.retrieveAppBindingLocked(service, callerApp);
            AppBindRecord b = s.retrieveAppBindingLocked(service, callerApp);
            ConnectionRecord c = new ConnectionRecord(b, activity,
            ConnectionRecord c = new ConnectionRecord(b, activity,
@@ -2802,8 +2802,9 @@ public final class ActiveServices {
                mAm.mUgmInternal.grantUriPermissionUncheckedFromIntent(si.neededGrants,
                mAm.mUgmInternal.grantUriPermissionUncheckedFromIntent(si.neededGrants,
                        si.getUriPermissionsLocked());
                        si.getUriPermissionsLocked());
            }
            }
            mAm.grantEphemeralAccessLocked(r.userId, si.intent, UserHandle.getAppId(r.appInfo.uid),
            mAm.grantImplicitAccess(r.userId, si.intent, UserHandle.getAppId(si.callingId),
                    UserHandle.getAppId(si.callingId));
                    UserHandle.getAppId(r.appInfo.uid)
            );
            bumpServiceExecutingLocked(r, execInFg, "start");
            bumpServiceExecutingLocked(r, execInFg, "start");
            if (!oomAdjusted) {
            if (!oomAdjusted) {
                oomAdjusted = true;
                oomAdjusted = true;
+6 −6
Original line number Original line Diff line number Diff line
@@ -6115,10 +6115,9 @@ public class ActivityManagerService extends IActivityManager.Stub
    }
    }
    @VisibleForTesting
    @VisibleForTesting
    public void grantEphemeralAccessLocked(int userId, Intent intent,
    public void grantImplicitAccess(int userId, Intent intent, int callingAppId, int targetAppId) {
            int targetAppId, int ephemeralAppId) {
        getPackageManagerInternalLocked().
        getPackageManagerInternalLocked().
                grantEphemeralAccess(userId, intent, targetAppId, ephemeralAppId);
                grantImplicitAccess(userId, intent, callingAppId, targetAppId);
    }
    }
    /**
    /**
@@ -7088,9 +7087,10 @@ public class ActivityManagerService extends IActivityManager.Stub
            }
            }
            checkTime(startTime, "getContentProviderImpl: done!");
            checkTime(startTime, "getContentProviderImpl: done!");
            grantEphemeralAccessLocked(userId, null /*intent*/,
            grantImplicitAccess(userId, null /*intent*/,
                    UserHandle.getAppId(cpi.applicationInfo.uid),
                    UserHandle.getAppId(Binder.getCallingUid()),
                    UserHandle.getAppId(Binder.getCallingUid()));
                    UserHandle.getAppId(cpi.applicationInfo.uid)
            );
        }
        }
        // Wait for the provider to be published...
        // Wait for the provider to be published...
+8 −12
Original line number Original line Diff line number Diff line
@@ -246,25 +246,25 @@ class AppsFilter {
    }
    }


    /**
    /**
     * Marks that a package initiated an interaction with another package, granting visibility of
     * Grants access based on an interaction between a calling and target package, granting
     * the prior from the former.
     * visibility of the caller from the target.
     *
     *
     * @param initiatingPackage the package initiating the interaction
     * @param callingPackage    the package initiating the interaction
     * @param targetPackage     the package being interacted with and thus gaining visibility of the
     * @param targetPackage     the package being interacted with and thus gaining visibility of the
     *                          initiating package.
     *                          initiating package.
     * @param userId            the user in which this interaction was taking place
     * @param userId            the user in which this interaction was taking place
     */
     */
    private void markAppInteraction(
    public void grantImplicitAccess(
            PackageSetting initiatingPackage, PackageSetting targetPackage, int userId) {
            String callingPackage, String targetPackage, int userId) {
        HashMap<String, Set<String>> currentUser = mImplicitlyQueryable.get(userId);
        HashMap<String, Set<String>> currentUser = mImplicitlyQueryable.get(userId);
        if (currentUser == null) {
        if (currentUser == null) {
            currentUser = new HashMap<>();
            currentUser = new HashMap<>();
            mImplicitlyQueryable.put(userId, currentUser);
            mImplicitlyQueryable.put(userId, currentUser);
        }
        }
        if (!currentUser.containsKey(targetPackage.pkg.packageName)) {
        if (!currentUser.containsKey(targetPackage)) {
            currentUser.put(targetPackage.pkg.packageName, new HashSet<>());
            currentUser.put(targetPackage, new HashSet<>());
        }
        }
        currentUser.get(targetPackage.pkg.packageName).add(initiatingPackage.pkg.packageName);
        currentUser.get(targetPackage).add(callingPackage);
    }
    }


    public void onSystemReady() {
    public void onSystemReady() {
@@ -374,8 +374,6 @@ class AppsFilter {
            callingPkgSetting = (PackageSetting) callingSetting;
            callingPkgSetting = (PackageSetting) callingSetting;
            if (!shouldFilterApplicationInternal(callingPkgSetting, targetPkgSetting,
            if (!shouldFilterApplicationInternal(callingPkgSetting, targetPkgSetting,
                    userId)) {
                    userId)) {
                // TODO: actually base this on a start / launch (not just a query)
                markAppInteraction(callingPkgSetting, targetPkgSetting, userId);
                return false;
                return false;
            }
            }
        } else if (callingSetting instanceof SharedUserSetting) {
        } else if (callingSetting instanceof SharedUserSetting) {
@@ -386,8 +384,6 @@ class AppsFilter {
                    final PackageSetting packageSetting = packageSettings.valueAt(i);
                    final PackageSetting packageSetting = packageSettings.valueAt(i);
                    if (!shouldFilterApplicationInternal(packageSetting, targetPkgSetting,
                    if (!shouldFilterApplicationInternal(packageSetting, targetPkgSetting,
                            userId)) {
                            userId)) {
                        // TODO: actually base this on a start / launch (not just a query)
                        markAppInteraction(packageSetting, targetPkgSetting, userId);
                        return false;
                        return false;
                    }
                    }
                    if (callingPkgSetting == null && packageSetting.pkg != null) {
                    if (callingPkgSetting == null && packageSetting.pkg != null) {
+1 −1
Original line number Original line Diff line number Diff line
@@ -401,7 +401,7 @@ class InstantAppRegistry {


    @GuardedBy("mService.mLock")
    @GuardedBy("mService.mLock")
    public void grantInstantAccessLPw(@UserIdInt int userId, @Nullable Intent intent,
    public void grantInstantAccessLPw(@UserIdInt int userId, @Nullable Intent intent,
            int targetAppId, int instantAppId) {
            int instantAppId, int targetAppId) {
        if (mInstalledInstantAppUids == null) {
        if (mInstalledInstantAppUids == null) {
            return;     // no instant apps installed; no need to grant
            return;     // no instant apps installed; no need to grant
        }
        }
Loading