Make sure the ROLE_HOME is always set in RoleManager

bug: 159814579
Test: Install a 3p launcher and verfiy that the default launcher doesn't changes
Test: Uninstall the default 3p launcher, and verify that it falls back to the system launcher
Change-Id: I09673778917f6fa6ca5bd915b963fae00fa3b33b
This commit is contained in:
Mehdi Alizadeh
2020-08-25 12:58:16 -07:00
parent 944d885dbd
commit 1bf7390062

View File

@@ -13793,7 +13793,7 @@ public class PackageManagerService extends IPackageManager.Stub
final boolean isCallerOwner = isCallerDeviceOrProfileOwner(userId);
final long callingId = Binder.clearCallingIdentity();
try {
final String activeLauncherPackageName = getActiveLauncherPackageName(userId);
final String activeLauncherPackageName = mPermissionManager.getDefaultHome(userId);
final String dialerPackageName = mPermissionManager.getDefaultDialer(userId);
for (int i = 0; i < packageNames.length; i++) {
canSuspend[i] = false;
@@ -13869,18 +13869,6 @@ public class PackageManagerService extends IPackageManager.Stub
return canSuspend;
}
private String getActiveLauncherPackageName(int userId) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
ResolveInfo resolveInfo = resolveIntent(
intent,
intent.resolveTypeIfNeeded(mContext.getContentResolver()),
PackageManager.MATCH_DEFAULT_ONLY,
userId);
return resolveInfo == null ? null : resolveInfo.activityInfo.packageName;
}
@Override
public void verifyPendingInstall(int id, int verificationCode) throws RemoteException {
mContext.enforceCallingOrSelfPermission(
@@ -20545,6 +20533,9 @@ public class PackageManagerService extends IPackageManager.Stub
if (cn != null) {
return cn;
}
// TODO: This should not happen since there should always be a default package set for
// ROLE_HOME in RoleManager. Continue with a warning log for now.
Slog.w(TAG, "Default package for ROLE_HOME is not set in RoleManager");
// Find the launcher with the highest priority and return that component if there are no
// other home activity with the same priority.
@@ -20593,6 +20584,7 @@ public class PackageManagerService extends IPackageManager.Stub
if (packageName == null) {
return null;
}
int resolveInfosSize = resolveInfos.size();
for (int i = 0; i < resolveInfosSize; i++) {
ResolveInfo resolveInfo = resolveInfos.get(i);
@@ -20652,6 +20644,11 @@ public class PackageManagerService extends IPackageManager.Stub
// PermissionController manages default home directly.
return false;
}
if (packageName == null) {
// Keep the default home package in RoleManager.
return false;
}
mPermissionManager.setDefaultHome(packageName, userId, (successful) -> {
if (successful) {
postPreferredActivityChangedBroadcast(userId);