mSettings.writeRuntimePermissionsForUserLPr(userId, false);
}
- if (READ_EXTERNAL_STORAGE.equals(name)
- || WRITE_EXTERNAL_STORAGE.equals(name)) {
+ // Only need to do this if user is initialized. Otherwise it's a new user
+ // and there are no processes running as the user yet and there's no need
+ // to make an expensive call to remount processes for the changed permissions.
+ if ((READ_EXTERNAL_STORAGE.equals(name)
+ || WRITE_EXTERNAL_STORAGE.equals(name))
+ && sUserManager.isInitialized(userId)) {
final long token = Binder.clearCallingIdentity();
try {
final StorageManager storage = mContext.getSystemService(StorageManager.class);
}
}
- void newUserCreatedLILPw(final int userHandle) {
- // We cannot grant the default permissions with a lock held as
- // we query providers from other components for default handlers
- // such as enabled IMEs, etc.
- mHandler.post(new Runnable() {
- @Override
- public void run() {
- mDefaultPermissionPolicy.grantDefaultPermissions(userHandle);
- }
- });
+ void newUserCreated(final int userHandle) {
+ mDefaultPermissionPolicy.grantDefaultPermissions(userHandle);
}
@Override
final boolean isManagedProfile = (flags & UserInfo.FLAG_MANAGED_PROFILE) != 0;
final long ident = Binder.clearCallingIdentity();
UserInfo userInfo = null;
+ final int userId;
try {
synchronized (mInstallLock) {
synchronized (mPackagesLock) {
if (isGuest && findCurrentGuestUserLocked() != null) {
return null;
}
- int userId = getNextAvailableIdLocked();
+ userId = getNextAvailableIdLocked();
userInfo = new UserInfo(userId, name, null, flags);
userInfo.serialNumber = mNextSerialNumber++;
long now = System.currentTimeMillis();
updateUserIdsLocked();
Bundle restrictions = new Bundle();
mUserRestrictions.append(userId, restrictions);
- mPm.newUserCreatedLILPw(userId);
}
}
+ mPm.newUserCreated(userId);
if (userInfo != null) {
Intent addedIntent = new Intent(Intent.ACTION_USER_ADDED);
addedIntent.putExtra(Intent.EXTRA_USER_HANDLE, userInfo.id);
}
}
}
+
+ /**
+ * @param userId
+ * @return whether the user has been initialized yet
+ */
+ boolean isInitialized(int userId) {
+ return (getUserInfo(userId).flags & UserInfo.FLAG_INITIALIZED) != 0;
+ }
}