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

Commit 4cdc2674 authored by Todd Kennedy's avatar Todd Kennedy Committed by android-build-merger
Browse files

Merge "System installed launcher can see instant apps" into oc-dev

am: 1de10d66

Change-Id: I70d707c25ed793bd2ad8e58f3558d2a4d0b6e980
parents 8187781e 1de10d66
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -343,5 +343,5 @@ public abstract class PackageManagerInternal {
    public abstract int getUidTargetSdkVersion(int uid);
    public abstract int getUidTargetSdkVersion(int uid);


    /** Whether the binder caller can access instant apps. */
    /** Whether the binder caller can access instant apps. */
    public abstract boolean canAccessInstantApps(int callingUid);
    public abstract boolean canAccessInstantApps(int callingUid, int userId);
}
}
+6 −2
Original line number Original line Diff line number Diff line
@@ -3334,12 +3334,16 @@
         confirmation UI for full backup/restore -->
         confirmation UI for full backup/restore -->
    <uses-permission android:name="android.permission.CONFIRM_FULL_BACKUP"/>
    <uses-permission android:name="android.permission.CONFIRM_FULL_BACKUP"/>



    <!-- Allows the holder to access and manage instant applications on the device.
    <!-- Allows the holder to access the instant applications on the device.
    @hide -->
    @hide -->
    <permission android:name="android.permission.ACCESS_INSTANT_APPS"
    <permission android:name="android.permission.ACCESS_INSTANT_APPS"
            android:protectionLevel="signature|installer|verifier" />
            android:protectionLevel="signature|installer|verifier" />


    <!-- Allows the holder to view the instant applications on the device.
    @hide -->
    <permission android:name="android.permission.VIEW_INSTANT_APPS"
            android:protectionLevel="signature|preinstalled" />

    <!-- Allows receiving the usage of media resource e.g. video/audio codec and
    <!-- Allows receiving the usage of media resource e.g. video/audio codec and
         graphic memory.
         graphic memory.
         @hide -->
         @hide -->
+26 −18
Original line number Original line Diff line number Diff line
@@ -3517,16 +3517,25 @@ public class PackageManagerService extends IPackageManager.Stub
     *     system partition.</li>
     *     system partition.</li>
     * </ol>
     * </ol>
     */
     */
    private boolean canAccessInstantApps(int callingUid) {
    private boolean canViewInstantApps(int callingUid, int userId) {
        final boolean isSpecialProcess =
        if (callingUid == Process.SYSTEM_UID
                callingUid == Process.SYSTEM_UID
                || callingUid == Process.SHELL_UID
                || callingUid == Process.SHELL_UID
                        || callingUid == Process.ROOT_UID;
                || callingUid == Process.ROOT_UID) {
        final boolean allowMatchInstant =
            return true;
                isSpecialProcess
        }
                        || mContext.checkCallingOrSelfPermission(
        if (mContext.checkCallingOrSelfPermission(
                        android.Manifest.permission.ACCESS_INSTANT_APPS) == PERMISSION_GRANTED;
                android.Manifest.permission.ACCESS_INSTANT_APPS) == PERMISSION_GRANTED) {
        return allowMatchInstant;
            return true;
        }
        if (mContext.checkCallingOrSelfPermission(
                android.Manifest.permission.VIEW_INSTANT_APPS) == PERMISSION_GRANTED) {
            final ComponentName homeComponent = getDefaultHomeActivity(userId);
            if (homeComponent != null
                    && isCallerSameApp(homeComponent.getPackageName(), callingUid)) {
                return true;
            }
        }
        return false;
    }
    }
    private PackageInfo generatePackageInfo(PackageSetting ps, int flags, int userId) {
    private PackageInfo generatePackageInfo(PackageSetting ps, int flags, int userId) {
@@ -3784,7 +3793,7 @@ public class PackageManagerService extends IPackageManager.Stub
        }
        }
        if (ps.getInstantApp(userId)) {
        if (ps.getInstantApp(userId)) {
            // caller can see all components of all instant applications, don't filter
            // caller can see all components of all instant applications, don't filter
            if (canAccessInstantApps(callingUid)) {
            if (canViewInstantApps(callingUid, userId)) {
                return false;
                return false;
            }
            }
            // request for a specific instant application component, filter
            // request for a specific instant application component, filter
@@ -4408,11 +4417,12 @@ public class PackageManagerService extends IPackageManager.Stub
            flags |= PackageManager.MATCH_VISIBLE_TO_INSTANT_APP_ONLY;
            flags |= PackageManager.MATCH_VISIBLE_TO_INSTANT_APP_ONLY;
            flags |= PackageManager.MATCH_INSTANT;
            flags |= PackageManager.MATCH_INSTANT;
        } else {
        } else {
            final boolean wantMatchInstant = (flags & PackageManager.MATCH_INSTANT) != 0;
            final boolean allowMatchInstant =
            final boolean allowMatchInstant =
                    (wantInstantApps
                    (wantInstantApps
                            && Intent.ACTION_VIEW.equals(intent.getAction())
                            && Intent.ACTION_VIEW.equals(intent.getAction())
                            && hasWebURI(intent))
                            && hasWebURI(intent))
                    || canAccessInstantApps(callingUid);
                    || (wantMatchInstant && canViewInstantApps(callingUid, userId));
            flags &= ~(PackageManager.MATCH_VISIBLE_TO_INSTANT_APP_ONLY
            flags &= ~(PackageManager.MATCH_VISIBLE_TO_INSTANT_APP_ONLY
                    | PackageManager.MATCH_EXPLICITLY_VISIBLE_ONLY);
                    | PackageManager.MATCH_EXPLICITLY_VISIBLE_ONLY);
            if (!allowMatchInstant) {
            if (!allowMatchInstant) {
@@ -5937,7 +5947,7 @@ public class PackageManagerService extends IPackageManager.Stub
        final int callingUid = Binder.getCallingUid();
        final int callingUid = Binder.getCallingUid();
        final int callingUserId = UserHandle.getUserId(callingUid);
        final int callingUserId = UserHandle.getUserId(callingUid);
        synchronized (mPackages) {
        synchronized (mPackages) {
            if (canAccessInstantApps(callingUid)) {
            if (canViewInstantApps(callingUid, callingUserId)) {
                return new ArrayList<String>(mPackages.keySet());
                return new ArrayList<String>(mPackages.keySet());
            }
            }
            final String instantAppPkgName = getInstantAppPackageName(callingUid);
            final String instantAppPkgName = getInstantAppPackageName(callingUid);
@@ -8146,9 +8156,7 @@ public class PackageManagerService extends IPackageManager.Stub
            final boolean returnAllowed =
            final boolean returnAllowed =
                    ps != null
                    ps != null
                    && (isCallerSameApp(packageName, callingUid)
                    && (isCallerSameApp(packageName, callingUid)
                            || mContext.checkCallingOrSelfPermission(
                            || canViewInstantApps(callingUid, userId)
                                    android.Manifest.permission.ACCESS_INSTANT_APPS)
                                            == PERMISSION_GRANTED
                            || mInstantAppRegistry.isInstantAccessGranted(
                            || mInstantAppRegistry.isInstantAccessGranted(
                                    userId, UserHandle.getAppId(callingUid), ps.appId));
                                    userId, UserHandle.getAppId(callingUid), ps.appId));
            if (returnAllowed) {
            if (returnAllowed) {
@@ -24381,8 +24389,8 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
        }
        }
        @Override
        @Override
        public boolean canAccessInstantApps(int callingUid) {
        public boolean canAccessInstantApps(int callingUid, int userId) {
            return PackageManagerService.this.canAccessInstantApps(callingUid);
            return PackageManagerService.this.canViewInstantApps(callingUid, userId);
        }
        }
    }
    }
+5 −5
Original line number Original line Diff line number Diff line
@@ -411,8 +411,8 @@ public class UsageStatsService extends SystemService implements
        }
        }
    }
    }


    private boolean shouldObfuscateInstantAppsForCaller(int callingUid) {
    private boolean shouldObfuscateInstantAppsForCaller(int callingUid, int userId) {
        return !mPackageManagerInternal.canAccessInstantApps(callingUid);
        return !mPackageManagerInternal.canAccessInstantApps(callingUid, userId);
    }
    }


    void clearAppIdleForPackage(String packageName, int userId) {
    void clearAppIdleForPackage(String packageName, int userId) {
@@ -1390,7 +1390,7 @@ public class UsageStatsService extends SystemService implements
            }
            }


            final boolean obfuscateInstantApps = shouldObfuscateInstantAppsForCaller(
            final boolean obfuscateInstantApps = shouldObfuscateInstantAppsForCaller(
                    Binder.getCallingUid());
                    Binder.getCallingUid(), UserHandle.getCallingUserId());


            final int userId = UserHandle.getCallingUserId();
            final int userId = UserHandle.getCallingUserId();
            final long token = Binder.clearCallingIdentity();
            final long token = Binder.clearCallingIdentity();
@@ -1435,7 +1435,7 @@ public class UsageStatsService extends SystemService implements
            }
            }


            final boolean obfuscateInstantApps = shouldObfuscateInstantAppsForCaller(
            final boolean obfuscateInstantApps = shouldObfuscateInstantAppsForCaller(
                    Binder.getCallingUid());
                    Binder.getCallingUid(), UserHandle.getCallingUserId());


            final int userId = UserHandle.getCallingUserId();
            final int userId = UserHandle.getCallingUserId();
            final long token = Binder.clearCallingIdentity();
            final long token = Binder.clearCallingIdentity();
@@ -1456,7 +1456,7 @@ public class UsageStatsService extends SystemService implements
                throw re.rethrowFromSystemServer();
                throw re.rethrowFromSystemServer();
            }
            }
            final boolean obfuscateInstantApps = shouldObfuscateInstantAppsForCaller(
            final boolean obfuscateInstantApps = shouldObfuscateInstantAppsForCaller(
                    Binder.getCallingUid());
                    Binder.getCallingUid(), userId);
            final long token = Binder.clearCallingIdentity();
            final long token = Binder.clearCallingIdentity();
            try {
            try {
                return UsageStatsService.this.isAppIdleFilteredOrParoled(packageName, userId,
                return UsageStatsService.this.isAppIdleFilteredOrParoled(packageName, userId,