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

Commit 0a6909cd authored by Kenny Guy's avatar Kenny Guy Committed by Android (Google) Code Review
Browse files

Merge "Don't load profile widgets until parent is unlocked." into nyc-dev

parents bdcc9b77 63f4ef0b
Loading
Loading
Loading
Loading
+32 −3
Original line number Diff line number Diff line
@@ -353,7 +353,10 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
    }

    private void onPackageBroadcastReceived(Intent intent, int userId) {
        if (!mUserManager.isUserUnlocked(userId)) return;
        if (!mUserManager.isUserUnlocked(userId) ||
                isProfileWithLockedParent(userId)) {
            return;
        }

        final String action = intent.getAction();
        boolean added = false;
@@ -435,7 +438,10 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
     * due to user not being available and package suspension.
     */
    private void reloadWidgetsMaskedStateForUser(int userId) {
        if (!mUserManager.isUserUnlocked(userId)) return;
        if (!mUserManager.isUserUnlocked(userId) ||
                isProfileWithLockedParent(userId)) {
            return;
        }
        synchronized (mLock) {
            reloadWidgetPackageSuspensionMaskedStateLocked(userId);
            List<UserInfo> profiles = mUserManager.getEnabledProfiles(userId);
@@ -606,7 +612,10 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
            throw new IllegalStateException(
                    "User " + userId + " must be unlocked for widgets to be available");
        }

        if (isProfileWithLockedParent(userId)) {
            throw new IllegalStateException(
                    "Profile " + userId + " must have unlocked parent");
        }
        final int[] profileIds = mSecurityPolicy.getEnabledGroupProfileIds(userId);

        // Careful lad, we may have already loaded the state for some
@@ -2458,6 +2467,9 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
    }

    private void onUserUnlocked(int userId) {
        if (isProfileWithLockedParent(userId)) {
            return;
        }
        synchronized (mLock) {
            ensureGroupStateLoadedLocked(userId);
            reloadWidgetsMaskedStateForUser(userId);
@@ -3306,6 +3318,23 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
        }
    }

    private boolean isProfileWithLockedParent(int userId) {
        long token = Binder.clearCallingIdentity();
        try {
            UserInfo userInfo = mUserManager.getUserInfo(userId);
            if (userInfo != null && userInfo.isManagedProfile()) {
                UserInfo parentInfo = mUserManager.getProfileParent(userId);
                if (parentInfo != null
                        && !mUserManager.isUserUnlocked(parentInfo.getUserHandle())) {
                    return true;
                }
            }
        } finally {
            Binder.restoreCallingIdentity(token);
        }
        return false;
    }

    private boolean isProfileWithUnlockedParent(int userId) {
        UserInfo userInfo = mUserManager.getUserInfo(userId);
        if (userInfo != null && userInfo.isManagedProfile()) {