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

Commit 78c48f6c authored by Jim Miller's avatar Jim Miller
Browse files

Fix multi-user support in keyguard.

This fixes a bug where user0's credentials were required of all users.

LockPatternUtils used to check for the system process of the caller
to determine which user id to use.  Now that keyguard is in its own
process, this can no longer be used.

The fix is to use the permission system to see if the calling process
is allowed to interact across users and if so, use the id of the current
user.

Change-Id: I2d7111938bb3bf381f72698c9fa4fb848d237153
parent 83178a67
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.internal.widget;

import android.Manifest;
import android.app.ActivityManagerNative;
import android.app.admin.DevicePolicyManager;
import android.appwidget.AppWidgetManager;
@@ -145,6 +146,8 @@ public class LockPatternUtils {
    private DevicePolicyManager mDevicePolicyManager;
    private ILockSettings mLockSettingsService;

    private final boolean mMultiUserMode;

    // The current user is set by KeyguardViewMediator and shared by all LockPatternUtils.
    private static volatile int sCurrentUserId = UserHandle.USER_NULL;

@@ -166,6 +169,12 @@ public class LockPatternUtils {
    public LockPatternUtils(Context context) {
        mContext = context;
        mContentResolver = context.getContentResolver();

        // If this is being called by the system or by an application like keyguard that
        // has permision INTERACT_ACROSS_USERS, then LockPatternUtils will operate in multi-user
        // mode where calls are for the current user rather than the user of the calling process.
        mMultiUserMode = context.checkCallingOrSelfPermission(
            Manifest.permission.INTERACT_ACROSS_USERS_FULL) == PackageManager.PERMISSION_GRANTED;
    }

    private ILockSettings getLockSettings() {
@@ -260,13 +269,12 @@ public class LockPatternUtils {
    }

    private int getCurrentOrCallingUserId() {
        int callingUid = Binder.getCallingUid();
        if (callingUid == android.os.Process.SYSTEM_UID) {
        if (mMultiUserMode) {
            // TODO: This is a little inefficient. See if all users of this are able to
            // handle USER_CURRENT and pass that instead.
            return getCurrentUser();
        } else {
            return UserHandle.getUserId(callingUid);
            return UserHandle.getCallingUserId();
        }
    }