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

Commit 63f4ef0b authored by Kenny Guy's avatar Kenny Guy
Browse files

Don't load profile widgets until parent is unlocked.

Wait for parent user to be unlocked before attempting
to load widgets for a user.
Fixes issue with profile being unlocked and AppWidgetServiceImpl
thinking it has loaded parents widgets while locked and
therefore not seeing any widgets.

Bug: 27037962
Change-Id: Ice9c5e6e1dd062a622c5f984eeb3531de893f9be
parent 0822a7e2
Loading
Loading
Loading
Loading
+32 −3
Original line number Original line Diff line number Diff line
@@ -353,7 +353,10 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
    }
    }


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


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


        // Careful lad, we may have already loaded the state for some
        // 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) {
    private void onUserUnlocked(int userId) {
        if (isProfileWithLockedParent(userId)) {
            return;
        }
        synchronized (mLock) {
        synchronized (mLock) {
            ensureGroupStateLoadedLocked(userId);
            ensureGroupStateLoadedLocked(userId);
            reloadWidgetsMaskedStateForUser(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) {
    private boolean isProfileWithUnlockedParent(int userId) {
        UserInfo userInfo = mUserManager.getUserInfo(userId);
        UserInfo userInfo = mUserManager.getUserInfo(userId);
        if (userInfo != null && userInfo.isManagedProfile()) {
        if (userInfo != null && userInfo.isManagedProfile()) {