diff --git a/packages/SettingsLib/src/com/android/settingslib/applications/AppUtils.java b/packages/SettingsLib/src/com/android/settingslib/applications/AppUtils.java index 7f65837d57167..cac3103a43280 100644 --- a/packages/SettingsLib/src/com/android/settingslib/applications/AppUtils.java +++ b/packages/SettingsLib/src/com/android/settingslib/applications/AppUtils.java @@ -32,6 +32,7 @@ import android.os.Environment; import android.os.RemoteException; import android.os.SystemProperties; import android.os.UserHandle; +import android.os.UserManager; import android.text.TextUtils; import android.util.Log; @@ -306,4 +307,17 @@ public class AppUtils { } } } + + /** + * Returns clone user profile id if present. Returns -1 if not present. + */ + public static int getCloneUserId(Context context) { + UserManager userManager = context.getSystemService(UserManager.class); + for (UserHandle userHandle : userManager.getUserProfiles()) { + if (userManager.getUserInfo(userHandle.getIdentifier()).isCloneProfile()) { + return userHandle.getIdentifier(); + } + } + return -1; + } } diff --git a/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java b/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java index ca5f57d3d6973..21e7d816d7273 100644 --- a/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java +++ b/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java @@ -123,6 +123,7 @@ public class ApplicationsState { final int mAdminRetrieveFlags; final int mRetrieveFlags; PackageIntentReceiver mPackageIntentReceiver; + PackageIntentReceiver mClonePackageIntentReceiver; boolean mResumed; boolean mHaveDisabledApps; @@ -265,6 +266,15 @@ public class ApplicationsState { mPackageIntentReceiver.registerReceiver(); } + // Listen to any package additions in clone user to refresh the app list. + if (mClonePackageIntentReceiver == null) { + int cloneUserId = AppUtils.getCloneUserId(mContext); + if (cloneUserId != -1) { + mClonePackageIntentReceiver = new PackageIntentReceiver(); + mClonePackageIntentReceiver.registerReceiverForClone(cloneUserId); + } + } + final List prevApplications = mApplications; mApplications = new ArrayList<>(); for (UserInfo user : mUm.getProfiles(UserHandle.myUserId())) { @@ -456,6 +466,10 @@ public class ApplicationsState { mPackageIntentReceiver.unregisterReceiver(); mPackageIntentReceiver = null; } + if (mClonePackageIntentReceiver != null) { + mClonePackageIntentReceiver.unregisterReceiver(); + mClonePackageIntentReceiver = null; + } } public AppEntry getEntry(String packageName, int userId) { @@ -1526,6 +1540,12 @@ public class ApplicationsState { removeUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL)); } } + + public void registerReceiverForClone(int cloneId) { + IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED); + filter.addDataScheme("package"); + mContext.registerReceiverAsUser(this, UserHandle.of(cloneId), filter, null, null); + } } /**