Loading src/com/android/packageinstaller/role/model/Role.java +38 −8 Original line number Diff line number Diff line Loading @@ -192,7 +192,7 @@ public class Role { * @param packageName the package name of the application to get confirmation message for * @param context the {@code Context} to retrieve system services * * @return the confirmation message, or {@code null} if no confirmation is needed. * @return the confirmation message, or {@code null} if no confirmation is needed */ @Nullable public CharSequence getConfirmationMessage(@NonNull String packageName, Loading @@ -205,7 +205,7 @@ public class Role { /** * Check whether a package is qualified for this role, i.e. whether it contains all the required * components. * components (plus meeting some other general restrictions). * * @param packageName the package name to check for * @param context the {@code Context} to retrieve system services Loading @@ -213,9 +213,11 @@ public class Role { * @return whether the package is qualified for a role */ public boolean isPackageQualified(@NonNull String packageName, @NonNull Context context) { if (Objects.equals(packageName, PACKAGE_NAME_ANDROID_SYSTEM)) { if (!isPackageQualifiedWithoutCheckingRequiredComponentsAsUser(packageName, Process.myUserHandle(), context)) { return false; } int requiredComponentsSize = mRequiredComponents.size(); for (int i = 0; i < requiredComponentsSize; i++) { RequiredComponent requiredComponent = mRequiredComponents.get(i); Loading @@ -225,17 +227,18 @@ public class Role { return false; } } return true; } /** * Get the list of packages that are qualified for this role, i.e. packages containing all the * required components. * required components (plus meeting some other general restrictions). * * @param user the user to get the qualifying packages. * @param context the {@code Context} to retrieve system services * * @return the set of packages that are qualified for this role * @return the list of packages that are qualified for this role */ @NonNull public List<String> getQualifyingPackagesAsUser(@NonNull UserHandle user, Loading @@ -256,9 +259,6 @@ public class Role { ComponentName componentName = qualifyingComponents.get(qualifyingComponentsIndex); String packageName = componentName.getPackageName(); if (Objects.equals(packageName, PACKAGE_NAME_ANDROID_SYSTEM)) { continue; } Integer componentCount = packageComponentCountMap.get(packageName); packageComponentCountMap.put(packageName, componentCount == null ? 1 : componentCount + 1); Loading @@ -269,16 +269,46 @@ public class Role { int packageComponentCountMapSize = packageComponentCountMap.size(); for (int i = 0; i < packageComponentCountMapSize; i++) { int componentCount = packageComponentCountMap.valueAt(i); if (componentCount != requiredComponentsSize) { continue; } String packageName = packageComponentCountMap.keyAt(i); if (!isPackageQualifiedWithoutCheckingRequiredComponentsAsUser(packageName, user, context)) { continue; } qualifyingPackages.add(packageName); } return qualifyingPackages; } private boolean isPackageQualifiedWithoutCheckingRequiredComponentsAsUser( @NonNull String packageName, @NonNull UserHandle user, @NonNull Context context) { if (Objects.equals(packageName, PACKAGE_NAME_ANDROID_SYSTEM)) { return false; } ApplicationInfo applicationInfo = PackageUtils.getApplicationInfoAsUser(packageName, user, context); if (applicationInfo == null) { Log.w(LOG_TAG, "Cannot get ApplicationInfo for package: " + packageName + ", user: " + user.getIdentifier()); return false; } // TODO: STOPSHIP: Check for disabled packages? // TODO: STOPSHIP: Add and check PackageManager.getSharedLibraryInfo(). if (applicationInfo.isInstantApp()) { return false; } return true; } /** * Grant this role to an application. * Loading src/com/android/packageinstaller/role/service/RoleControllerServiceImpl.java +0 −14 Original line number Diff line number Diff line Loading @@ -167,20 +167,6 @@ public class RoleControllerServiceImpl extends RoleControllerService { callback.onFailure(); return; } ApplicationInfo applicationInfo = PackageUtils.getApplicationInfo(packageName, this); if (applicationInfo == null) { Log.e(LOG_TAG, "Cannot get ApplicationInfo for package: " + packageName); callback.onFailure(); return; } // TODO: STOPSHIP: Check for disabled packages? // TODO: STOPSHIP: Add and check PackageManager.getSharedLibraryInfo(). if (applicationInfo.isInstantApp()) { Log.e(LOG_TAG, "Cannot set Instant App as role holder, package: " + packageName); callback.onFailure(); return; } if (!role.isPackageQualified(packageName, this)) { Log.e(LOG_TAG, "Package does not qualify for the role, package: " + packageName + ", role: " + roleName); Loading Loading
src/com/android/packageinstaller/role/model/Role.java +38 −8 Original line number Diff line number Diff line Loading @@ -192,7 +192,7 @@ public class Role { * @param packageName the package name of the application to get confirmation message for * @param context the {@code Context} to retrieve system services * * @return the confirmation message, or {@code null} if no confirmation is needed. * @return the confirmation message, or {@code null} if no confirmation is needed */ @Nullable public CharSequence getConfirmationMessage(@NonNull String packageName, Loading @@ -205,7 +205,7 @@ public class Role { /** * Check whether a package is qualified for this role, i.e. whether it contains all the required * components. * components (plus meeting some other general restrictions). * * @param packageName the package name to check for * @param context the {@code Context} to retrieve system services Loading @@ -213,9 +213,11 @@ public class Role { * @return whether the package is qualified for a role */ public boolean isPackageQualified(@NonNull String packageName, @NonNull Context context) { if (Objects.equals(packageName, PACKAGE_NAME_ANDROID_SYSTEM)) { if (!isPackageQualifiedWithoutCheckingRequiredComponentsAsUser(packageName, Process.myUserHandle(), context)) { return false; } int requiredComponentsSize = mRequiredComponents.size(); for (int i = 0; i < requiredComponentsSize; i++) { RequiredComponent requiredComponent = mRequiredComponents.get(i); Loading @@ -225,17 +227,18 @@ public class Role { return false; } } return true; } /** * Get the list of packages that are qualified for this role, i.e. packages containing all the * required components. * required components (plus meeting some other general restrictions). * * @param user the user to get the qualifying packages. * @param context the {@code Context} to retrieve system services * * @return the set of packages that are qualified for this role * @return the list of packages that are qualified for this role */ @NonNull public List<String> getQualifyingPackagesAsUser(@NonNull UserHandle user, Loading @@ -256,9 +259,6 @@ public class Role { ComponentName componentName = qualifyingComponents.get(qualifyingComponentsIndex); String packageName = componentName.getPackageName(); if (Objects.equals(packageName, PACKAGE_NAME_ANDROID_SYSTEM)) { continue; } Integer componentCount = packageComponentCountMap.get(packageName); packageComponentCountMap.put(packageName, componentCount == null ? 1 : componentCount + 1); Loading @@ -269,16 +269,46 @@ public class Role { int packageComponentCountMapSize = packageComponentCountMap.size(); for (int i = 0; i < packageComponentCountMapSize; i++) { int componentCount = packageComponentCountMap.valueAt(i); if (componentCount != requiredComponentsSize) { continue; } String packageName = packageComponentCountMap.keyAt(i); if (!isPackageQualifiedWithoutCheckingRequiredComponentsAsUser(packageName, user, context)) { continue; } qualifyingPackages.add(packageName); } return qualifyingPackages; } private boolean isPackageQualifiedWithoutCheckingRequiredComponentsAsUser( @NonNull String packageName, @NonNull UserHandle user, @NonNull Context context) { if (Objects.equals(packageName, PACKAGE_NAME_ANDROID_SYSTEM)) { return false; } ApplicationInfo applicationInfo = PackageUtils.getApplicationInfoAsUser(packageName, user, context); if (applicationInfo == null) { Log.w(LOG_TAG, "Cannot get ApplicationInfo for package: " + packageName + ", user: " + user.getIdentifier()); return false; } // TODO: STOPSHIP: Check for disabled packages? // TODO: STOPSHIP: Add and check PackageManager.getSharedLibraryInfo(). if (applicationInfo.isInstantApp()) { return false; } return true; } /** * Grant this role to an application. * Loading
src/com/android/packageinstaller/role/service/RoleControllerServiceImpl.java +0 −14 Original line number Diff line number Diff line Loading @@ -167,20 +167,6 @@ public class RoleControllerServiceImpl extends RoleControllerService { callback.onFailure(); return; } ApplicationInfo applicationInfo = PackageUtils.getApplicationInfo(packageName, this); if (applicationInfo == null) { Log.e(LOG_TAG, "Cannot get ApplicationInfo for package: " + packageName); callback.onFailure(); return; } // TODO: STOPSHIP: Check for disabled packages? // TODO: STOPSHIP: Add and check PackageManager.getSharedLibraryInfo(). if (applicationInfo.isInstantApp()) { Log.e(LOG_TAG, "Cannot set Instant App as role holder, package: " + packageName); callback.onFailure(); return; } if (!role.isPackageQualified(packageName, this)) { Log.e(LOG_TAG, "Package does not qualify for the role, package: " + packageName + ", role: " + roleName); Loading