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

Commit d92e9987 authored by Craig Mautner's avatar Craig Mautner Committed by The Android Automerger
Browse files

Fix deadlock in LockPatternUtils by using local id.

Activity manager now updates window manager's current user id
directly and immediately rather than waiting for a broadcast
update. Window manager passes this through policy to the
KeyguardViewMediator and into LockPatternUtils. LockPatternUtils
no longer goes to Activity to get the current user id if it finds
that its local id is non-default.

Fixes bug 7193726.

Change-Id: Id5613e7a9fe9e5b49e83c26b74504f587c3998c2
parent 4fc45055
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -1111,7 +1111,15 @@ public interface WindowManagerPolicy {
     * @param attrs The window's LayoutParams.
     * @return Whether magnification can be applied.
     */
    public boolean canMagnifyWindow(WindowManager.LayoutParams attrs);
    public boolean canMagnifyWindowLw(WindowManager.LayoutParams attrs);

    /**
     * Called when the current user changes. Guaranteed to be called before the broadcast
     * of the new user id is made to all listeners.
     *
     * @param newUserId The id of the incoming user.
     */
    public void setCurrentUserLw(int newUserId);

    /**
     * Print the WindowManagerPolicy's state into the given stream.
+6 −11
Original line number Diff line number Diff line
@@ -22,14 +22,11 @@ import com.google.android.collect.Lists;

import android.app.ActivityManagerNative;
import android.app.admin.DevicePolicyManager;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.Binder;
import android.os.FileObserver;
import android.os.IBinder;
import android.os.Process;
import android.os.RemoteException;
@@ -45,16 +42,10 @@ import android.util.Log;
import android.view.View;
import android.widget.Button;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * Utilities for the lock pattern and its settings.
@@ -134,7 +125,7 @@ public class LockPatternUtils {
    private final ContentResolver mContentResolver;
    private DevicePolicyManager mDevicePolicyManager;
    private ILockSettings mLockSettingsService;
    private int mCurrentUserId = 0;
    private int mCurrentUserId = UserHandle.USER_NULL;

    public DevicePolicyManager getDevicePolicyManager() {
        if (mDevicePolicyManager == null) {
@@ -233,10 +224,14 @@ public class LockPatternUtils {

    public int getCurrentUser() {
        if (Process.myUid() == Process.SYSTEM_UID) {
            if (mCurrentUserId != UserHandle.USER_NULL) {
                // Someone is regularly updating using setCurrentUser() use that value.
                return mCurrentUserId;
            }
            try {
                return ActivityManagerNative.getDefault().getCurrentUser().id;
            } catch (RemoteException re) {
                return mCurrentUserId;
                return UserHandle.USER_OWNER;
            }
        } else {
            throw new SecurityException("Only the system process can get the current user");
+11 −2
Original line number Diff line number Diff line
@@ -71,7 +71,6 @@ import android.util.EventLog;
import android.util.Log;
import android.util.Slog;
import android.util.SparseArray;
import android.util.SparseIntArray;
import android.view.Display;
import android.view.Gravity;
import android.view.HapticFeedbackConstants;
@@ -722,6 +721,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    }

    private final Runnable mPowerLongPress = new Runnable() {
        @Override
        public void run() {
            // The context isn't read
            if (mLongPressOnPowerBehavior < 0) {
@@ -4316,7 +4316,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        mLastInputMethodTargetWindow = target;
    }

    public boolean canMagnifyWindow(WindowManager.LayoutParams attrs) {
    @Override
    public boolean canMagnifyWindowLw(WindowManager.LayoutParams attrs) {
        switch (attrs.type) {
            case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
            case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
@@ -4328,6 +4329,14 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        return true;
    }

    @Override
    public void setCurrentUserLw(int newUserId) {
        if (mKeyguardMediator != null) {
            mKeyguardMediator.setCurrentUser(newUserId);
        }
    }

    @Override
    public void dump(String prefix, PrintWriter pw, String[] args) {
        pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
                pw.print(" mSystemReady="); pw.print(mSystemReady);
+11 −2
Original line number Diff line number Diff line
@@ -131,7 +131,7 @@ public class KeyguardViewMediator {
    private static final int KEYGUARD_LOCK_AFTER_DELAY_DEFAULT = 5000;

    /**
     * How long we'll wait for the {@link KeyguardViewCallback#keyguardDoneDrawing()}
     * How long we'll wait for the {@link ViewMediatorCallback#keyguardDoneDrawing()}
     * callback before unblocking a call to {@link #setKeyguardEnabled(boolean)}
     * that is reenabling the keyguard.
     */
@@ -297,7 +297,7 @@ public class KeyguardViewMediator {

        @Override
        public void onUserSwitched(int userId) {
            mLockPatternUtils.setCurrentUser(userId);
            // Note that the mLockPatternUtils user has already been updated from setCurrentUser.
            synchronized (KeyguardViewMediator.this) {
                resetStateLocked();
            }
@@ -465,6 +465,7 @@ public class KeyguardViewMediator {

        mLockPatternUtils = lockPatternUtils != null
                ? lockPatternUtils : new LockPatternUtils(mContext);
        mLockPatternUtils.setCurrentUser(UserHandle.USER_OWNER);

        WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);

@@ -890,6 +891,14 @@ public class KeyguardViewMediator {
            || KeyguardUpdateMonitor.getInstance(mContext).isSimPinSecure();
    }

    /**
     * Update the newUserId. Call while holding WindowManagerService lock.
     * @param newUserId The id of the incoming user.
     */
    public void setCurrentUser(int newUserId) {
        mLockPatternUtils.setCurrentUser(newUserId);
    }

    private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
+3 −1
Original line number Diff line number Diff line
@@ -13969,6 +13969,8 @@ public final class ActivityManagerService extends ActivityManagerNative
                mUserLru.remove(userIdInt);
                mUserLru.add(userIdInt);
                mWindowManager.setCurrentUser(userId);
                final UserStartedState uss = mStartedUsers.get(userId);
                mHandler.removeMessages(REPORT_USER_SWITCH_MSG);
Loading