Revert "Remove ActivityManager calls with PM.mInstallLock held"

This reverts commit ac06a4907b.

Change-Id: I27bedbd221a8d416b9040a96063e66a1ca69fe2e
This commit is contained in:
Bart Sears
2016-05-27 04:12:51 +00:00
parent 75fea11133
commit c51e725644
5 changed files with 35 additions and 69 deletions

View File

@@ -924,7 +924,6 @@ public class UserManager {
/** {@hide} */ /** {@hide} */
public boolean isUserRunning(int userId) { public boolean isUserRunning(int userId) {
// TODO Switch to using UMS internal isUserRunning
try { try {
return ActivityManagerNative.getDefault().isUserRunning(userId, 0); return ActivityManagerNative.getDefault().isUserRunning(userId, 0);
} catch (RemoteException re) { } catch (RemoteException re) {

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2016 The Android Open Source Project * Copyright (C) 2015 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -11,7 +11,7 @@
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License * limitations under the License.
*/ */
package android.os; package android.os;
@@ -129,23 +129,15 @@ public abstract class UserManagerInternal {
/** /**
* Return whether the given user is running in an * Return whether the given user is running in an
* {@code UserState.STATE_RUNNING_UNLOCKING} or * {@link com.android.server.am.UserState#STATE_RUNNING_UNLOCKING "unlocking"} or
* {@code UserState.STATE_RUNNING_UNLOCKED} state. * {@link com.android.server.am.UserState#STATE_RUNNING_UNLOCKED "unlocked"} state.
*/ */
public abstract boolean isUserUnlockingOrUnlocked(int userId); public abstract boolean isUserUnlockingOrUnlocked(int userId);
/** /**
* Return whether the given user is running * Sets whether the given user is running in an
* {@link com.android.server.am.UserState#STATE_RUNNING_UNLOCKING "unlocking"} or
* {@link com.android.server.am.UserState#STATE_RUNNING_UNLOCKED "unlocked"} state.
*/ */
public abstract boolean isUserRunning(int userId); public abstract void setUserUnlockingOrUnlocked(int userId, boolean unlockingOrUnlocked);
/**
* Set user's running state
*/
public abstract void setUserState(int userId, int userState);
/**
* Remove user's running state
*/
public abstract void removeUserState(int userId);
} }

View File

@@ -18,6 +18,7 @@ package com.android.server.am;
import static android.Manifest.permission.INTERACT_ACROSS_USERS; import static android.Manifest.permission.INTERACT_ACROSS_USERS;
import static android.Manifest.permission.INTERACT_ACROSS_USERS_FULL; import static android.Manifest.permission.INTERACT_ACROSS_USERS_FULL;
import static android.app.ActivityManager.FLAG_AND_UNLOCKING_OR_UNLOCKED;
import static android.app.ActivityManager.USER_OP_ERROR_IS_SYSTEM; import static android.app.ActivityManager.USER_OP_ERROR_IS_SYSTEM;
import static android.app.ActivityManager.USER_OP_ERROR_RELATED_USERS_CANNOT_STOP; import static android.app.ActivityManager.USER_OP_ERROR_RELATED_USERS_CANNOT_STOP;
import static android.app.ActivityManager.USER_OP_IS_CURRENT; import static android.app.ActivityManager.USER_OP_IS_CURRENT;
@@ -233,7 +234,6 @@ final class UserController {
// but we might immediately step into RUNNING below if the user // but we might immediately step into RUNNING below if the user
// storage is already unlocked. // storage is already unlocked.
if (uss.setState(STATE_BOOTING, STATE_RUNNING_LOCKED)) { if (uss.setState(STATE_BOOTING, STATE_RUNNING_LOCKED)) {
getUserManagerInternal().setUserState(userId, uss.state);
Intent intent = new Intent(Intent.ACTION_LOCKED_BOOT_COMPLETED, null); Intent intent = new Intent(Intent.ACTION_LOCKED_BOOT_COMPLETED, null);
intent.putExtra(Intent.EXTRA_USER_HANDLE, userId); intent.putExtra(Intent.EXTRA_USER_HANDLE, userId);
intent.addFlags(Intent.FLAG_RECEIVER_NO_ABORT intent.addFlags(Intent.FLAG_RECEIVER_NO_ABORT
@@ -277,7 +277,7 @@ final class UserController {
if (!StorageManager.isUserKeyUnlocked(userId)) return; if (!StorageManager.isUserKeyUnlocked(userId)) return;
if (uss.setState(STATE_RUNNING_LOCKED, STATE_RUNNING_UNLOCKING)) { if (uss.setState(STATE_RUNNING_LOCKED, STATE_RUNNING_UNLOCKING)) {
getUserManagerInternal().setUserState(userId, uss.state); getUserManagerInternal().setUserUnlockingOrUnlocked(userId, true);
uss.mUnlockProgress.start(); uss.mUnlockProgress.start();
// Prepare app storage before we go any further // Prepare app storage before we go any further
@@ -308,7 +308,7 @@ final class UserController {
if (!StorageManager.isUserKeyUnlocked(userId)) return; if (!StorageManager.isUserKeyUnlocked(userId)) return;
if (uss.setState(STATE_RUNNING_UNLOCKING, STATE_RUNNING_UNLOCKED)) { if (uss.setState(STATE_RUNNING_UNLOCKING, STATE_RUNNING_UNLOCKED)) {
getUserManagerInternal().setUserState(userId, uss.state); getUserManagerInternal().setUserUnlockingOrUnlocked(userId, true);
uss.mUnlockProgress.finish(); uss.mUnlockProgress.finish();
// Dispatch unlocked to external apps // Dispatch unlocked to external apps
@@ -482,7 +482,7 @@ final class UserController {
if (uss.state != UserState.STATE_STOPPING if (uss.state != UserState.STATE_STOPPING
&& uss.state != UserState.STATE_SHUTDOWN) { && uss.state != UserState.STATE_SHUTDOWN) {
uss.setState(UserState.STATE_STOPPING); uss.setState(UserState.STATE_STOPPING);
getUserManagerInternal().setUserState(userId, uss.state); getUserManagerInternal().setUserUnlockingOrUnlocked(userId, false);
updateStartedUserArrayLocked(); updateStartedUserArrayLocked();
long ident = Binder.clearCallingIdentity(); long ident = Binder.clearCallingIdentity();
@@ -544,7 +544,7 @@ final class UserController {
} }
uss.setState(UserState.STATE_SHUTDOWN); uss.setState(UserState.STATE_SHUTDOWN);
} }
getUserManagerInternal().setUserState(userId, uss.state); getUserManagerInternal().setUserUnlockingOrUnlocked(userId, false);
mService.mBatteryStatsService.noteEvent( mService.mBatteryStatsService.noteEvent(
BatteryStats.HistoryItem.EVENT_USER_RUNNING_FINISH, BatteryStats.HistoryItem.EVENT_USER_RUNNING_FINISH,
@@ -573,7 +573,6 @@ final class UserController {
stopped = true; stopped = true;
// User can no longer run. // User can no longer run.
mStartedUsers.remove(userId); mStartedUsers.remove(userId);
getUserManagerInternal().removeUserState(userId);
mUserLru.remove(Integer.valueOf(userId)); mUserLru.remove(Integer.valueOf(userId));
updateStartedUserArrayLocked(); updateStartedUserArrayLocked();
@@ -781,9 +780,7 @@ final class UserController {
// If the user we are switching to is not currently started, then // If the user we are switching to is not currently started, then
// we need to start it now. // we need to start it now.
if (mStartedUsers.get(userId) == null) { if (mStartedUsers.get(userId) == null) {
UserState userState = new UserState(UserHandle.of(userId)); mStartedUsers.put(userId, new UserState(UserHandle.of(userId)));
mStartedUsers.put(userId, userState);
getUserManagerInternal().setUserState(userId, userState.state);
updateStartedUserArrayLocked(); updateStartedUserArrayLocked();
needStart = true; needStart = true;
} }
@@ -817,14 +814,15 @@ final class UserController {
// so we can just fairly silently bring the user back from // so we can just fairly silently bring the user back from
// the almost-dead. // the almost-dead.
uss.setState(uss.lastState); uss.setState(uss.lastState);
getUserManagerInternal().setUserState(userId, uss.state); if (isUserRunningLocked(userId, FLAG_AND_UNLOCKING_OR_UNLOCKED)) {
getUserManagerInternal().setUserUnlockingOrUnlocked(userId, true);
}
updateStartedUserArrayLocked(); updateStartedUserArrayLocked();
needStart = true; needStart = true;
} else if (uss.state == UserState.STATE_SHUTDOWN) { } else if (uss.state == UserState.STATE_SHUTDOWN) {
// This means ACTION_SHUTDOWN has been sent, so we will // This means ACTION_SHUTDOWN has been sent, so we will
// need to treat this as a new boot of the user. // need to treat this as a new boot of the user.
uss.setState(UserState.STATE_BOOTING); uss.setState(UserState.STATE_BOOTING);
getUserManagerInternal().setUserState(userId, uss.state);
updateStartedUserArrayLocked(); updateStartedUserArrayLocked();
needStart = true; needStart = true;
} }

View File

@@ -16300,11 +16300,11 @@ public class PackageManagerService extends IPackageManager.Stub {
final int appId = UserHandle.getAppId(pkg.applicationInfo.uid); final int appId = UserHandle.getAppId(pkg.applicationInfo.uid);
removeKeystoreDataIfNeeded(userId, appId); removeKeystoreDataIfNeeded(userId, appId);
UserManagerInternal umInternal = getUserManagerInternal(); final UserManager um = mContext.getSystemService(UserManager.class);
final int flags; final int flags;
if (umInternal.isUserUnlockingOrUnlocked(userId)) { if (um.isUserUnlockingOrUnlocked(userId)) {
flags = StorageManager.FLAG_STORAGE_DE | StorageManager.FLAG_STORAGE_CE; flags = StorageManager.FLAG_STORAGE_DE | StorageManager.FLAG_STORAGE_CE;
} else if (umInternal.isUserRunning(userId)) { } else if (um.isUserRunning(userId)) {
flags = StorageManager.FLAG_STORAGE_DE; flags = StorageManager.FLAG_STORAGE_DE;
} else { } else {
flags = 0; flags = 0;
@@ -19063,12 +19063,11 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
// Reconcile app data for all started/unlocked users // Reconcile app data for all started/unlocked users
final StorageManager sm = mContext.getSystemService(StorageManager.class); final StorageManager sm = mContext.getSystemService(StorageManager.class);
final UserManager um = mContext.getSystemService(UserManager.class); final UserManager um = mContext.getSystemService(UserManager.class);
UserManagerInternal umInternal = getUserManagerInternal();
for (UserInfo user : um.getUsers()) { for (UserInfo user : um.getUsers()) {
final int flags; final int flags;
if (umInternal.isUserUnlockingOrUnlocked(user.id)) { if (um.isUserUnlockingOrUnlocked(user.id)) {
flags = StorageManager.FLAG_STORAGE_DE | StorageManager.FLAG_STORAGE_CE; flags = StorageManager.FLAG_STORAGE_DE | StorageManager.FLAG_STORAGE_CE;
} else if (umInternal.isUserRunning(user.id)) { } else if (um.isUserRunning(user.id)) {
flags = StorageManager.FLAG_STORAGE_DE; flags = StorageManager.FLAG_STORAGE_DE;
} else { } else {
continue; continue;
@@ -19492,12 +19491,11 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
} }
final UserManager um = mContext.getSystemService(UserManager.class); final UserManager um = mContext.getSystemService(UserManager.class);
UserManagerInternal umInternal = getUserManagerInternal();
for (UserInfo user : um.getUsers()) { for (UserInfo user : um.getUsers()) {
final int flags; final int flags;
if (umInternal.isUserUnlockingOrUnlocked(user.id)) { if (um.isUserUnlockingOrUnlocked(user.id)) {
flags = StorageManager.FLAG_STORAGE_DE | StorageManager.FLAG_STORAGE_CE; flags = StorageManager.FLAG_STORAGE_DE | StorageManager.FLAG_STORAGE_CE;
} else if (umInternal.isUserRunning(user.id)) { } else if (um.isUserRunning(user.id)) {
flags = StorageManager.FLAG_STORAGE_DE; flags = StorageManager.FLAG_STORAGE_DE;
} else { } else {
continue; continue;

View File

@@ -22,6 +22,7 @@ import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import android.Manifest; import android.Manifest;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.annotation.UserIdInt; import android.annotation.UserIdInt;
import android.app.Activity; import android.app.Activity;
import android.app.ActivityManager; import android.app.ActivityManager;
@@ -31,7 +32,9 @@ import android.app.AppGlobals;
import android.app.IActivityManager; import android.app.IActivityManager;
import android.app.IStopUserCallback; import android.app.IStopUserCallback;
import android.app.KeyguardManager; import android.app.KeyguardManager;
import android.app.admin.DevicePolicyManager;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
@@ -75,7 +78,6 @@ import android.util.Log;
import android.util.Slog; import android.util.Slog;
import android.util.SparseArray; import android.util.SparseArray;
import android.util.SparseBooleanArray; import android.util.SparseBooleanArray;
import android.util.SparseIntArray;
import android.util.TimeUtils; import android.util.TimeUtils;
import android.util.Xml; import android.util.Xml;
@@ -88,7 +90,6 @@ import com.android.internal.util.Preconditions;
import com.android.internal.util.XmlUtils; import com.android.internal.util.XmlUtils;
import com.android.internal.widget.LockPatternUtils; import com.android.internal.widget.LockPatternUtils;
import com.android.server.LocalServices; import com.android.server.LocalServices;
import com.android.server.am.UserState;
import libcore.io.IoUtils; import libcore.io.IoUtils;
import libcore.util.Objects; import libcore.util.Objects;
@@ -330,8 +331,8 @@ public class UserManagerService extends IUserManager.Stub {
@GuardedBy("mUsersLock") @GuardedBy("mUsersLock")
private boolean mForceEphemeralUsers; private boolean mForceEphemeralUsers;
@GuardedBy("mUserStates") @GuardedBy("mUsersLock")
private final SparseIntArray mUserStates = new SparseIntArray(); private final SparseBooleanArray mUnlockingOrUnlockedUsers = new SparseBooleanArray();
private static UserManagerService sInstance; private static UserManagerService sInstance;
@@ -378,7 +379,6 @@ public class UserManagerService extends IUserManager.Stub {
mLocalService = new LocalService(); mLocalService = new LocalService();
LocalServices.addService(UserManagerInternal.class, mLocalService); LocalServices.addService(UserManagerInternal.class, mLocalService);
mLockPatternUtils = new LockPatternUtils(mContext); mLockPatternUtils = new LockPatternUtils(mContext);
mUserStates.put(UserHandle.USER_SYSTEM, UserState.STATE_BOOTING);
} }
void systemReady() { void systemReady() {
@@ -2380,9 +2380,7 @@ public class UserManagerService extends IUserManager.Stub {
synchronized (mUsersLock) { synchronized (mUsersLock) {
mUsers.remove(userHandle); mUsers.remove(userHandle);
mIsUserManaged.delete(userHandle); mIsUserManaged.delete(userHandle);
} mUnlockingOrUnlockedUsers.delete(userHandle);
synchronized (mUserStates) {
mUserStates.delete(userHandle);
} }
synchronized (mRestrictionsLock) { synchronized (mRestrictionsLock) {
mBaseUserRestrictions.remove(userHandle); mBaseUserRestrictions.remove(userHandle);
@@ -3083,9 +3081,6 @@ public class UserManagerService extends IUserManager.Stub {
pw.println(); pw.println();
pw.println(" Device managed: " + mIsDeviceManaged); pw.println(" Device managed: " + mIsDeviceManaged);
} }
synchronized (mUserStates) {
pw.println(" Started users state: " + mUserStates);
}
// Dump some capabilities // Dump some capabilities
pw.println(); pw.println();
pw.println(" Max users: " + UserManager.getMaxSupportedUsers()); pw.println(" Max users: " + UserManager.getMaxSupportedUsers());
@@ -3272,32 +3267,16 @@ public class UserManagerService extends IUserManager.Stub {
} }
@Override @Override
public boolean isUserRunning(int userId) { public void setUserUnlockingOrUnlocked(int userId, boolean unlockingOrUnlocked) {
synchronized (mUserStates) { synchronized (mUsersLock) {
return mUserStates.get(userId, -1) >= 0; mUnlockingOrUnlockedUsers.put(userId, unlockingOrUnlocked);
}
}
@Override
public void setUserState(int userId, int userState) {
synchronized (mUserStates) {
mUserStates.put(userId, userState);
}
}
@Override
public void removeUserState(int userId) {
synchronized (mUserStates) {
mUserStates.delete(userId);
} }
} }
@Override @Override
public boolean isUserUnlockingOrUnlocked(int userId) { public boolean isUserUnlockingOrUnlocked(int userId) {
synchronized (mUserStates) { synchronized (mUsersLock) {
int state = mUserStates.get(userId, -1); return mUnlockingOrUnlockedUsers.get(userId);
return (state == UserState.STATE_RUNNING_UNLOCKING)
|| (state == UserState.STATE_RUNNING_UNLOCKED);
} }
} }
} }