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

Commit 65c732f5 authored by Hai Zhang's avatar Hai Zhang Committed by Android (Google) Code Review
Browse files

Merge "Use existing API to implement isInstantApp(int uid)."

parents 4e9148e9 94ef1856
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -636,7 +636,7 @@ public class RoleManagerService extends SystemService implements RoleUserState.C
                getContext().enforceCallingOrSelfPermission(
                        android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, null);
            }
            if (mPackageManagerInternal.getInstantAppPackageName(callingUid) != null) {
            if (isInstantApp(callingUid)) {
                return null;
            }

@@ -649,6 +649,25 @@ public class RoleManagerService extends SystemService implements RoleUserState.C
            }
        }

        private boolean isInstantApp(int uid) {
            final long identity = Binder.clearCallingIdentity();
            try {
                final UserHandle user = UserHandle.getUserHandleForUid(uid);
                final Context userContext = getContext().createContextAsUser(user, 0);
                final PackageManager userPackageManager = userContext.getPackageManager();
                // Instant apps can not have shared UID, so it's safe to check only the first
                // package name here.
                final String packageName = ArrayUtils.firstOrNull(
                        userPackageManager.getPackagesForUid(uid));
                if (packageName == null) {
                    return false;
                }
                return userPackageManager.isInstantApp(packageName);
            } finally {
                Binder.restoreCallingIdentity(identity);
            }
        }

        @Override
        public boolean setBrowserRoleHolder(@Nullable String packageName, @UserIdInt int userId) {
            final Context context = getContext();