From 63f4ef0b7d0988ff833e8e9f5cf8ac807b524aa4 Mon Sep 17 00:00:00 2001 From: Kenny Guy Date: Mon, 22 Feb 2016 21:12:31 +0000 Subject: [PATCH] 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 --- .../appwidget/AppWidgetServiceImpl.java | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java b/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java index 2b52799304fda..f537d182035e2 100644 --- a/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java +++ b/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java @@ -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 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()) {