/** {@hide} */
public boolean isUserRunning(int userId) {
- // TODO Switch to using UMS internal isUserRunning
try {
return ActivityManagerNative.getDefault().isUserRunning(userId, 0);
} catch (RemoteException re) {
/*
- * 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");
* you may not use this file except in compliance with the License.
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
- * limitations under the License
+ * limitations under the License.
*/
package android.os;
/**
* Return whether the given user is running in an
- * {@code UserState.STATE_RUNNING_UNLOCKING} or
- * {@code UserState.STATE_RUNNING_UNLOCKED} state.
+ * {@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 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);
-
- /**
- * Set user's running state
- */
- public abstract void setUserState(int userId, int userState);
-
- /**
- * Remove user's running state
- */
- public abstract void removeUserState(int userId);
+ public abstract void setUserUnlockingOrUnlocked(int userId, boolean unlockingOrUnlocked);
}
import static android.Manifest.permission.INTERACT_ACROSS_USERS;
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_RELATED_USERS_CANNOT_STOP;
import static android.app.ActivityManager.USER_OP_IS_CURRENT;
// but we might immediately step into RUNNING below if the user
// storage is already unlocked.
if (uss.setState(STATE_BOOTING, STATE_RUNNING_LOCKED)) {
- getUserManagerInternal().setUserState(userId, uss.state);
Intent intent = new Intent(Intent.ACTION_LOCKED_BOOT_COMPLETED, null);
intent.putExtra(Intent.EXTRA_USER_HANDLE, userId);
intent.addFlags(Intent.FLAG_RECEIVER_NO_ABORT
if (!StorageManager.isUserKeyUnlocked(userId)) return;
if (uss.setState(STATE_RUNNING_LOCKED, STATE_RUNNING_UNLOCKING)) {
- getUserManagerInternal().setUserState(userId, uss.state);
+ getUserManagerInternal().setUserUnlockingOrUnlocked(userId, true);
uss.mUnlockProgress.start();
// Prepare app storage before we go any further
if (!StorageManager.isUserKeyUnlocked(userId)) return;
if (uss.setState(STATE_RUNNING_UNLOCKING, STATE_RUNNING_UNLOCKED)) {
- getUserManagerInternal().setUserState(userId, uss.state);
+ getUserManagerInternal().setUserUnlockingOrUnlocked(userId, true);
uss.mUnlockProgress.finish();
// Dispatch unlocked to external apps
if (uss.state != UserState.STATE_STOPPING
&& uss.state != UserState.STATE_SHUTDOWN) {
uss.setState(UserState.STATE_STOPPING);
- getUserManagerInternal().setUserState(userId, uss.state);
+ getUserManagerInternal().setUserUnlockingOrUnlocked(userId, false);
updateStartedUserArrayLocked();
long ident = Binder.clearCallingIdentity();
}
uss.setState(UserState.STATE_SHUTDOWN);
}
- getUserManagerInternal().setUserState(userId, uss.state);
+ getUserManagerInternal().setUserUnlockingOrUnlocked(userId, false);
mService.mBatteryStatsService.noteEvent(
BatteryStats.HistoryItem.EVENT_USER_RUNNING_FINISH,
stopped = true;
// User can no longer run.
mStartedUsers.remove(userId);
- getUserManagerInternal().removeUserState(userId);
mUserLru.remove(Integer.valueOf(userId));
updateStartedUserArrayLocked();
// If the user we are switching to is not currently started, then
// we need to start it now.
if (mStartedUsers.get(userId) == null) {
- UserState userState = new UserState(UserHandle.of(userId));
- mStartedUsers.put(userId, userState);
- getUserManagerInternal().setUserState(userId, userState.state);
+ mStartedUsers.put(userId, new UserState(UserHandle.of(userId)));
updateStartedUserArrayLocked();
needStart = true;
}
// so we can just fairly silently bring the user back from
// the almost-dead.
uss.setState(uss.lastState);
- getUserManagerInternal().setUserState(userId, uss.state);
+ if (isUserRunningLocked(userId, FLAG_AND_UNLOCKING_OR_UNLOCKED)) {
+ getUserManagerInternal().setUserUnlockingOrUnlocked(userId, true);
+ }
updateStartedUserArrayLocked();
needStart = true;
} else if (uss.state == UserState.STATE_SHUTDOWN) {
// This means ACTION_SHUTDOWN has been sent, so we will
// need to treat this as a new boot of the user.
uss.setState(UserState.STATE_BOOTING);
- getUserManagerInternal().setUserState(userId, uss.state);
updateStartedUserArrayLocked();
needStart = true;
}
final int appId = UserHandle.getAppId(pkg.applicationInfo.uid);
removeKeystoreDataIfNeeded(userId, appId);
- UserManagerInternal umInternal = getUserManagerInternal();
+ final UserManager um = mContext.getSystemService(UserManager.class);
final int flags;
- if (umInternal.isUserUnlockingOrUnlocked(userId)) {
+ if (um.isUserUnlockingOrUnlocked(userId)) {
flags = StorageManager.FLAG_STORAGE_DE | StorageManager.FLAG_STORAGE_CE;
- } else if (umInternal.isUserRunning(userId)) {
+ } else if (um.isUserRunning(userId)) {
flags = StorageManager.FLAG_STORAGE_DE;
} else {
flags = 0;
// Reconcile app data for all started/unlocked users
final StorageManager sm = mContext.getSystemService(StorageManager.class);
final UserManager um = mContext.getSystemService(UserManager.class);
- UserManagerInternal umInternal = getUserManagerInternal();
for (UserInfo user : um.getUsers()) {
final int flags;
- if (umInternal.isUserUnlockingOrUnlocked(user.id)) {
+ if (um.isUserUnlockingOrUnlocked(user.id)) {
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;
} else {
continue;
}
final UserManager um = mContext.getSystemService(UserManager.class);
- UserManagerInternal umInternal = getUserManagerInternal();
for (UserInfo user : um.getUsers()) {
final int flags;
- if (umInternal.isUserUnlockingOrUnlocked(user.id)) {
+ if (um.isUserUnlockingOrUnlocked(user.id)) {
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;
} else {
continue;
import android.Manifest;
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.annotation.SystemApi;
import android.annotation.UserIdInt;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.IActivityManager;
import android.app.IStopUserCallback;
import android.app.KeyguardManager;
+import android.app.admin.DevicePolicyManager;
import android.content.BroadcastReceiver;
+import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.util.Slog;
import android.util.SparseArray;
import android.util.SparseBooleanArray;
-import android.util.SparseIntArray;
import android.util.TimeUtils;
import android.util.Xml;
import com.android.internal.util.XmlUtils;
import com.android.internal.widget.LockPatternUtils;
import com.android.server.LocalServices;
-import com.android.server.am.UserState;
import libcore.io.IoUtils;
import libcore.util.Objects;
@GuardedBy("mUsersLock")
private boolean mForceEphemeralUsers;
- @GuardedBy("mUserStates")
- private final SparseIntArray mUserStates = new SparseIntArray();
+ @GuardedBy("mUsersLock")
+ private final SparseBooleanArray mUnlockingOrUnlockedUsers = new SparseBooleanArray();
private static UserManagerService sInstance;
mLocalService = new LocalService();
LocalServices.addService(UserManagerInternal.class, mLocalService);
mLockPatternUtils = new LockPatternUtils(mContext);
- mUserStates.put(UserHandle.USER_SYSTEM, UserState.STATE_BOOTING);
}
void systemReady() {
synchronized (mUsersLock) {
mUsers.remove(userHandle);
mIsUserManaged.delete(userHandle);
- }
- synchronized (mUserStates) {
- mUserStates.delete(userHandle);
+ mUnlockingOrUnlockedUsers.delete(userHandle);
}
synchronized (mRestrictionsLock) {
mBaseUserRestrictions.remove(userHandle);
pw.println();
pw.println(" Device managed: " + mIsDeviceManaged);
}
- synchronized (mUserStates) {
- pw.println(" Started users state: " + mUserStates);
- }
// Dump some capabilities
pw.println();
pw.println(" Max users: " + UserManager.getMaxSupportedUsers());
}
@Override
- public boolean isUserRunning(int userId) {
- synchronized (mUserStates) {
- return mUserStates.get(userId, -1) >= 0;
- }
- }
-
- @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);
+ public void setUserUnlockingOrUnlocked(int userId, boolean unlockingOrUnlocked) {
+ synchronized (mUsersLock) {
+ mUnlockingOrUnlockedUsers.put(userId, unlockingOrUnlocked);
}
}
@Override
public boolean isUserUnlockingOrUnlocked(int userId) {
- synchronized (mUserStates) {
- int state = mUserStates.get(userId, -1);
- return (state == UserState.STATE_RUNNING_UNLOCKING)
- || (state == UserState.STATE_RUNNING_UNLOCKED);
+ synchronized (mUsersLock) {
+ return mUnlockingOrUnlockedUsers.get(userId);
}
}
}