Merge "Register receiver for package added in clone profile."
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<ApplicationInfo> 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user