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

Commit aabbfc55 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

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

parents 7ee84180 ea1b9d79
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -924,6 +924,7 @@ 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) {
+16 −8
Original line number Original line 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");
 * 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,15 +129,23 @@ public abstract class UserManagerInternal {


    /**
    /**
     * Return whether the given user is running in an
     * Return whether the given user is running in an
     * {@link com.android.server.am.UserState#STATE_RUNNING_UNLOCKING "unlocking"} or
     * {@code UserState.STATE_RUNNING_UNLOCKING} or
     * {@link com.android.server.am.UserState#STATE_RUNNING_UNLOCKED "unlocked"} state.
     * {@code UserState.STATE_RUNNING_UNLOCKED} state.
     */
     */
    public abstract boolean isUserUnlockingOrUnlocked(int userId);
    public abstract boolean isUserUnlockingOrUnlocked(int userId);


    /**
    /**
     * Sets whether the given user is running in an
     * Return whether the given user is running
     * {@link com.android.server.am.UserState#STATE_RUNNING_UNLOCKING "unlocking"} or
     * {@link com.android.server.am.UserState#STATE_RUNNING_UNLOCKED "unlocked"} state.
     */
     */
    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 Original line 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;
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;
@@ -234,6 +233,7 @@ 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().setUserUnlockingOrUnlocked(userId, true);
                getUserManagerInternal().setUserState(userId, uss.state);
                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().setUserUnlockingOrUnlocked(userId, true);
                getUserManagerInternal().setUserState(userId, uss.state);
                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().setUserUnlockingOrUnlocked(userId, false);
            getUserManagerInternal().setUserState(userId, uss.state);
            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().setUserUnlockingOrUnlocked(userId, false);
        getUserManagerInternal().setUserState(userId, uss.state);


        mService.mBatteryStatsService.noteEvent(
        mService.mBatteryStatsService.noteEvent(
                BatteryStats.HistoryItem.EVENT_USER_RUNNING_FINISH,
                BatteryStats.HistoryItem.EVENT_USER_RUNNING_FINISH,
@@ -573,6 +573,7 @@ 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();


@@ -780,7 +781,9 @@ 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) {
                    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();
                    updateStartedUserArrayLocked();
                    needStart = true;
                    needStart = true;
                }
                }
@@ -814,15 +817,14 @@ 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);
                    if (isUserRunningLocked(userId, FLAG_AND_UNLOCKING_OR_UNLOCKED)) {
                    getUserManagerInternal().setUserState(userId, uss.state);
                        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;
                }
                }
+9 −7
Original line number Original line Diff line number Diff line
@@ -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);
        final UserManager um = mContext.getSystemService(UserManager.class);
        UserManagerInternal umInternal = getUserManagerInternal();
        final int flags;
        final int flags;
        if (um.isUserUnlockingOrUnlocked(userId)) {
        if (umInternal.isUserUnlockingOrUnlocked(userId)) {
            flags = StorageManager.FLAG_STORAGE_DE | StorageManager.FLAG_STORAGE_CE;
            flags = StorageManager.FLAG_STORAGE_DE | StorageManager.FLAG_STORAGE_CE;
        } else if (um.isUserRunning(userId)) {
        } else if (umInternal.isUserRunning(userId)) {
            flags = StorageManager.FLAG_STORAGE_DE;
            flags = StorageManager.FLAG_STORAGE_DE;
        } else {
        } else {
            flags = 0;
            flags = 0;
@@ -19063,11 +19063,12 @@ 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 (um.isUserUnlockingOrUnlocked(user.id)) {
            if (umInternal.isUserUnlockingOrUnlocked(user.id)) {
                flags = StorageManager.FLAG_STORAGE_DE | StorageManager.FLAG_STORAGE_CE;
                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;
                flags = StorageManager.FLAG_STORAGE_DE;
            } else {
            } else {
                continue;
                continue;
@@ -19491,11 +19492,12 @@ 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 (um.isUserUnlockingOrUnlocked(user.id)) {
            if (umInternal.isUserUnlockingOrUnlocked(user.id)) {
                flags = StorageManager.FLAG_STORAGE_DE | StorageManager.FLAG_STORAGE_CE;
                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;
                flags = StorageManager.FLAG_STORAGE_DE;
            } else {
            } else {
                continue;
                continue;
+32 −10
Original line number Original line Diff line number Diff line
@@ -22,7 +22,6 @@ 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;
@@ -32,7 +31,6 @@ 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.ComponentName;
import android.content.Context;
import android.content.Context;
@@ -78,6 +76,7 @@ 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;


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


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


    private static UserManagerService sInstance;
    private static UserManagerService sInstance;


@@ -379,6 +379,7 @@ 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,7 +2381,9 @@ 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);
@@ -3081,6 +3084,9 @@ 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());
@@ -3267,16 +3273,32 @@ public class UserManagerService extends IUserManager.Stub {
        }
        }


        @Override
        @Override
        public void setUserUnlockingOrUnlocked(int userId, boolean unlockingOrUnlocked) {
        public boolean isUserRunning(int userId) {
            synchronized (mUsersLock) {
            synchronized (mUserStates) {
                mUnlockingOrUnlockedUsers.put(userId, unlockingOrUnlocked);
                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
        @Override
        public boolean isUserUnlockingOrUnlocked(int userId) {
        public boolean isUserUnlockingOrUnlocked(int userId) {
            synchronized (mUsersLock) {
            synchronized (mUserStates) {
                return mUnlockingOrUnlockedUsers.get(userId);
                int state = mUserStates.get(userId, -1);
                return (state == UserState.STATE_RUNNING_UNLOCKING)
                        || (state == UserState.STATE_RUNNING_UNLOCKED);
            }
            }
        }
        }
    }
    }