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

Commit ce18c816 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Introduce "unlocking" vs "unlocked" nuance.

There is a narrow window of time during user unlock where we're
reconciling user storage and dispatching the "unlock" status to
various internal system services.  While in this "unlocking" state,
apps need to be told that the user still isn't actually "unlocked"
so they don't try making calls to AccountManager, etc.

The majority of internal services are interested in merging together
both the "unlocking" and "unlocked" state, so update them.

Clarify naming in AccountManagerService to make it clear that a local
list is being used, which mirrors the naming in MountService.

To match UX/PM requested behavior, move PRE_BOOT_COMPLETED dispatch
after the user is unlocked, but block BOOT_COMPLETED dispatch until
after all PRE_BOOT receivers are finished to avoid ANRs.

Bug: 28040947, 28164677
Change-Id: I57af2351633d9159f4483f19657ce0b62118d1ce
parent 32c1169a
Loading
Loading
Loading
Loading
+2 −20
Original line number Diff line number Diff line
@@ -3430,6 +3430,8 @@ public class ActivityManager {
    public static final int FLAG_AND_LOCKED = 1 << 1;
    /** {@hide} */
    public static final int FLAG_AND_UNLOCKED = 1 << 2;
    /** {@hide} */
    public static final int FLAG_AND_UNLOCKING_OR_UNLOCKED = 1 << 3;

    /**
     * Return whether the given user is actively running.  This means that
@@ -3448,26 +3450,6 @@ public class ActivityManager {
        }
    }

    /** {@hide} */
    public boolean isUserRunningAndLocked(int userId) {
        try {
            return ActivityManagerNative.getDefault().isUserRunning(userId,
                    ActivityManager.FLAG_AND_LOCKED);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /** {@hide} */
    public boolean isUserRunningAndUnlocked(int userId) {
        try {
            return ActivityManagerNative.getDefault().isUserRunning(userId,
                    ActivityManager.FLAG_AND_UNLOCKED);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /** {@hide} */
    public boolean isVrModePackageEnabled(ComponentName component) {
        try {
+21 −5
Original line number Diff line number Diff line
@@ -36,7 +36,6 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.storage.StorageManager;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.view.WindowManager.LayoutParams;
@@ -984,10 +983,27 @@ public class UserManager {

    /** {@hide} */
    public boolean isUserUnlocked(@UserIdInt int userId) {
        // TODO: eventually pivot this back to look at ActivityManager state,
        // but there is race where we can start a non-encryption-aware launcher
        // before that lifecycle has entered the running unlocked state.
        return mContext.getSystemService(StorageManager.class).isUserKeyUnlocked(userId);
        try {
            return ActivityManagerNative.getDefault().isUserRunning(userId,
                    ActivityManager.FLAG_AND_UNLOCKED);
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
    }

    /** {@hide} */
    public boolean isUserUnlockingOrUnlocked(UserHandle user) {
        return isUserUnlockingOrUnlocked(user.getIdentifier());
    }

    /** {@hide} */
    public boolean isUserUnlockingOrUnlocked(@UserIdInt int userId) {
        try {
            return ActivityManagerNative.getDefault().isUserRunning(userId,
                    ActivityManager.FLAG_AND_UNLOCKING_OR_UNLOCKED);
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
    }

    /**
+13 −3
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.IPackageMoveObserver;
import android.content.pm.PackageManager;
import android.os.Binder;
import android.os.Environment;
import android.os.FileUtils;
import android.os.Handler;
@@ -1062,11 +1063,20 @@ public class StorageManager {
    }

    /** {@hide} */
    public boolean isUserKeyUnlocked(int userId) {
    public static boolean isUserKeyUnlocked(int userId) {
        final IMountService mount = IMountService.Stub
                .asInterface(ServiceManager.getService("mount"));
        if (mount == null) {
            Slog.w(TAG, "Early during boot, assuming locked");
            return false;
        }
        final long token = Binder.clearCallingIdentity();
        try {
            return mMountService.isUserKeyUnlocked(userId);
            return mount.isUserKeyUnlocked(userId);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowAsRuntimeException();
        } finally {
            Binder.restoreCallingIdentity(token);
        }
    }

+2 −0
Original line number Diff line number Diff line
@@ -824,6 +824,8 @@ public class CallLog {
                UserHandle user, ContentValues values) {
            final ContentResolver resolver = context.getContentResolver();

            // Since we're doing this operation on behalf of an app, we only
            // want to use the actual "unlocked" state.
            final Uri uri = ContentProvider.maybeAddUserId(
                    userManager.isUserUnlocked(user) ? CONTENT_URI : SHADOW_CONTENT_URI,
                    user.getIdentifier());
+3 −0
Original line number Diff line number Diff line
@@ -2530,6 +2530,9 @@
  <java-symbol type="string" name="profile_encrypted_message" />
  <java-symbol type="drawable" name="ic_user_secure" />

  <java-symbol type="string" name="android_upgrading_notification_title" />
  <java-symbol type="string" name="android_upgrading_notification_body" />

  <java-symbol type="string" name="usb_mtp_launch_notification_title" />
  <java-symbol type="string" name="usb_mtp_launch_notification_description" />

Loading