Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 69c76ce3 authored by Amith Yamasani's avatar Amith Yamasani Committed by android-build-merger
Browse files

Merge "Revert "Revert "Remove ActivityManager calls with PM.mInstallLock...

Merge "Revert "Revert "Remove ActivityManager calls with PM.mInstallLock held""" into nyc-mr1-dev am: aabbfc55
am: a3bc135b

* commit 'a3bc135b':
  Revert "Revert "Remove ActivityManager calls with PM.mInstallLock held""

Change-Id: Ifa8f6f8e195bca93af058914c5b1797f3294df6e
parents 7c0bd203 a3bc135b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -924,6 +924,7 @@ 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) {
+16 −8
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 * Copyright (C) 2016 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,15 +129,23 @@ public abstract class UserManagerInternal {

    /**
     * Return 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.
     * {@code UserState.STATE_RUNNING_UNLOCKING} or
     * {@code UserState.STATE_RUNNING_UNLOCKED} state.
     */
    public abstract boolean isUserUnlockingOrUnlocked(int userId);

    /**
     * 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.
     * Return whether the given user is running
     */
    public abstract void setUserUnlockingOrUnlocked(int userId, boolean unlockingOrUnlocked);
    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);
}
+11 −9
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ 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;
@@ -234,6 +233,7 @@ 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().setUserUnlockingOrUnlocked(userId, true);
                getUserManagerInternal().setUserState(userId, uss.state);
                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().setUserUnlockingOrUnlocked(userId, true);
                getUserManagerInternal().setUserState(userId, uss.state);
                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().setUserUnlockingOrUnlocked(userId, false);
            getUserManagerInternal().setUserState(userId, uss.state);
            updateStartedUserArrayLocked();

            long ident = Binder.clearCallingIdentity();
@@ -544,7 +544,7 @@ final class UserController {
            }
            uss.setState(UserState.STATE_SHUTDOWN);
        }
        getUserManagerInternal().setUserUnlockingOrUnlocked(userId, false);
        getUserManagerInternal().setUserState(userId, uss.state);

        mService.mBatteryStatsService.noteEvent(
                BatteryStats.HistoryItem.EVENT_USER_RUNNING_FINISH,
@@ -573,6 +573,7 @@ final class UserController {
                stopped = true;
                // User can no longer run.
                mStartedUsers.remove(userId);
                getUserManagerInternal().removeUserState(userId);
                mUserLru.remove(Integer.valueOf(userId));
                updateStartedUserArrayLocked();

@@ -780,7 +781,9 @@ 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) {
                    mStartedUsers.put(userId, new UserState(UserHandle.of(userId)));
                    UserState userState = new UserState(UserHandle.of(userId));
                    mStartedUsers.put(userId, userState);
                    getUserManagerInternal().setUserState(userId, userState.state);
                    updateStartedUserArrayLocked();
                    needStart = true;
                }
@@ -814,15 +817,14 @@ final class UserController {
                    // so we can just fairly silently bring the user back from
                    // the almost-dead.
                    uss.setState(uss.lastState);
                    if (isUserRunningLocked(userId, FLAG_AND_UNLOCKING_OR_UNLOCKED)) {
                        getUserManagerInternal().setUserUnlockingOrUnlocked(userId, true);
                    }
                    getUserManagerInternal().setUserState(userId, uss.state);
                    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;
                }
+9 −7
Original line number Diff line number Diff line
@@ -16304,11 +16304,11 @@ public class PackageManagerService extends IPackageManager.Stub {
        final int appId = UserHandle.getAppId(pkg.applicationInfo.uid);
        removeKeystoreDataIfNeeded(userId, appId);
        final UserManager um = mContext.getSystemService(UserManager.class);
        UserManagerInternal umInternal = getUserManagerInternal();
        final int flags;
        if (um.isUserUnlockingOrUnlocked(userId)) {
        if (umInternal.isUserUnlockingOrUnlocked(userId)) {
            flags = StorageManager.FLAG_STORAGE_DE | StorageManager.FLAG_STORAGE_CE;
        } else if (um.isUserRunning(userId)) {
        } else if (umInternal.isUserRunning(userId)) {
            flags = StorageManager.FLAG_STORAGE_DE;
        } else {
            flags = 0;
@@ -19067,11 +19067,12 @@ 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 (um.isUserUnlockingOrUnlocked(user.id)) {
            if (umInternal.isUserUnlockingOrUnlocked(user.id)) {
                flags = StorageManager.FLAG_STORAGE_DE | StorageManager.FLAG_STORAGE_CE;
            } else if (um.isUserRunning(user.id)) {
            } else if (umInternal.isUserRunning(user.id)) {
                flags = StorageManager.FLAG_STORAGE_DE;
            } else {
                continue;
@@ -19495,11 +19496,12 @@ 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 (um.isUserUnlockingOrUnlocked(user.id)) {
            if (umInternal.isUserUnlockingOrUnlocked(user.id)) {
                flags = StorageManager.FLAG_STORAGE_DE | StorageManager.FLAG_STORAGE_CE;
            } else if (um.isUserRunning(user.id)) {
            } else if (umInternal.isUserRunning(user.id)) {
                flags = StorageManager.FLAG_STORAGE_DE;
            } else {
                continue;
+32 −10
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ 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;
@@ -32,7 +31,6 @@ 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;
@@ -78,6 +76,7 @@ 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;

@@ -90,6 +89,7 @@ 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;
@@ -331,8 +331,8 @@ public class UserManagerService extends IUserManager.Stub {
    @GuardedBy("mUsersLock")
    private boolean mForceEphemeralUsers;

    @GuardedBy("mUsersLock")
    private final SparseBooleanArray mUnlockingOrUnlockedUsers = new SparseBooleanArray();
    @GuardedBy("mUserStates")
    private final SparseIntArray mUserStates = new SparseIntArray();

    private static UserManagerService sInstance;

@@ -379,6 +379,7 @@ 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,7 +2381,9 @@ public class UserManagerService extends IUserManager.Stub {
        synchronized (mUsersLock) {
            mUsers.remove(userHandle);
            mIsUserManaged.delete(userHandle);
            mUnlockingOrUnlockedUsers.delete(userHandle);
        }
        synchronized (mUserStates) {
            mUserStates.delete(userHandle);
        }
        synchronized (mRestrictionsLock) {
            mBaseUserRestrictions.remove(userHandle);
@@ -3081,6 +3084,9 @@ 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());
@@ -3267,16 +3273,32 @@ public class UserManagerService extends IUserManager.Stub {
        }

        @Override
        public void setUserUnlockingOrUnlocked(int userId, boolean unlockingOrUnlocked) {
            synchronized (mUsersLock) {
                mUnlockingOrUnlockedUsers.put(userId, unlockingOrUnlocked);
        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);
            }
        }

        @Override
        public boolean isUserUnlockingOrUnlocked(int userId) {
            synchronized (mUsersLock) {
                return mUnlockingOrUnlockedUsers.get(userId);
            synchronized (mUserStates) {
                int state = mUserStates.get(userId, -1);
                return (state == UserState.STATE_RUNNING_UNLOCKING)
                        || (state == UserState.STATE_RUNNING_UNLOCKED);
            }
        }
    }