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

Commit 94ef1856 authored by Hai Zhang's avatar Hai Zhang
Browse files

Use existing API to implement isInstantApp(int uid).

Bug: 158736025
Test: presubmit
Change-Id: I9e07fe3086f688a0bb86bee7004fd5e8ec645da2
parent f2fc3e30
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();