OSDN Git Service

Revert "Remove ActivityManager calls with PM.mInstallLock held"
authorBart Sears <bsears@google.com>
Fri, 27 May 2016 04:12:51 +0000 (04:12 +0000)
committerBart Sears <bsears@google.com>
Fri, 27 May 2016 04:18:50 +0000 (04:18 +0000)
This reverts commit ac06a4907bff7d5ee0612dbb85180222e1455791.

Change-Id: I27bedbd221a8d416b9040a96063e66a1ca69fe2e

core/java/android/os/UserManager.java
core/java/android/os/UserManagerInternal.java
services/core/java/com/android/server/am/UserController.java
services/core/java/com/android/server/pm/PackageManagerService.java
services/core/java/com/android/server/pm/UserManagerService.java

index b98e304..2613994 100644 (file)
@@ -924,7 +924,6 @@ public class UserManager {
 
     /** {@hide} */
     public boolean isUserRunning(int userId) {
-        // TODO Switch to using UMS internal isUserRunning
         try {
             return ActivityManagerNative.getDefault().isUserRunning(userId, 0);
         } catch (RemoteException re) {
index 93afb43..551ea6b 100644 (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");
  * 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,
  * 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;
 
@@ -129,23 +129,15 @@ public abstract class UserManagerInternal {
 
     /**
      * 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);
 }
index ee85a57..2023173 100644 (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_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;
@@ -233,7 +234,6 @@ final class UserController {
             // 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
@@ -277,7 +277,7 @@ final class UserController {
             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
@@ -308,7 +308,7 @@ final class UserController {
             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
@@ -482,7 +482,7 @@ final class UserController {
         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();
@@ -544,7 +544,7 @@ final class UserController {
             }
             uss.setState(UserState.STATE_SHUTDOWN);
         }
-        getUserManagerInternal().setUserState(userId, uss.state);
+        getUserManagerInternal().setUserUnlockingOrUnlocked(userId, false);
 
         mService.mBatteryStatsService.noteEvent(
                 BatteryStats.HistoryItem.EVENT_USER_RUNNING_FINISH,
@@ -573,7 +573,6 @@ final class UserController {
                 stopped = true;
                 // User can no longer run.
                 mStartedUsers.remove(userId);
-                getUserManagerInternal().removeUserState(userId);
                 mUserLru.remove(Integer.valueOf(userId));
                 updateStartedUserArrayLocked();
 
@@ -781,9 +780,7 @@ final class UserController {
                 // 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;
                 }
@@ -817,14 +814,15 @@ final class UserController {
                     // 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;
                 }
index 08b9c78..35bcaa9 100644 (file)
@@ -16300,11 +16300,11 @@ public class PackageManagerService extends IPackageManager.Stub {
         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;
@@ -19063,12 +19063,11 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
         // 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;
@@ -19492,12 +19491,11 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
         }
 
         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;
index 44f436e..4541e2e 100644 (file)
@@ -22,6 +22,7 @@ import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
 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;
@@ -31,7 +32,9 @@ import android.app.AppGlobals;
 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;
@@ -75,7 +78,6 @@ import android.util.Log;
 import android.util.Slog;
 import android.util.SparseArray;
 import android.util.SparseBooleanArray;
-import android.util.SparseIntArray;
 import android.util.TimeUtils;
 import android.util.Xml;
 
@@ -88,7 +90,6 @@ import com.android.internal.util.Preconditions;
 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;
@@ -330,8 +331,8 @@ public class UserManagerService extends IUserManager.Stub {
     @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;
 
@@ -378,7 +379,6 @@ public class UserManagerService extends IUserManager.Stub {
         mLocalService = new LocalService();
         LocalServices.addService(UserManagerInternal.class, mLocalService);
         mLockPatternUtils = new LockPatternUtils(mContext);
-        mUserStates.put(UserHandle.USER_SYSTEM, UserState.STATE_BOOTING);
     }
 
     void systemReady() {
@@ -2380,9 +2380,7 @@ public class UserManagerService extends IUserManager.Stub {
         synchronized (mUsersLock) {
             mUsers.remove(userHandle);
             mIsUserManaged.delete(userHandle);
-        }
-        synchronized (mUserStates) {
-            mUserStates.delete(userHandle);
+            mUnlockingOrUnlockedUsers.delete(userHandle);
         }
         synchronized (mRestrictionsLock) {
             mBaseUserRestrictions.remove(userHandle);
@@ -3083,9 +3081,6 @@ public class UserManagerService extends IUserManager.Stub {
                 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());
@@ -3272,32 +3267,16 @@ public class UserManagerService extends IUserManager.Stub {
         }
 
         @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);
             }
         }
     }