From 97eaacba10529a100306635be8a2aa7cd308d0f0 Mon Sep 17 00:00:00 2001 From: Evan Laird Date: Tue, 4 Sep 2018 15:06:37 -0400 Subject: [PATCH] Don't request profile owner as user if we don't have a valid user ag/4891733 changed DevicePolicyManager#getProfileOwnerAsUser() to call into DPMService.getProfileOwnerAsUser() instead of getProfileOwner(). It turns out that getProfileOwnerAsUser doesn't accept invalid userIds but the latter method did. This CL guards against calling that method if we don't have a valid userId. The calling code just wants to know if a profile is managed but I'm pretty sure a UserRecord pointing at a non-user can't be managed. Test: Expand QS, tap user switcher icon Change-Id: Idfe46cb6c0d25ba3817ae3639f87de70bbce2d0b Fixes: 113777483 --- .../settingslib/drawable/UserIconDrawable.java | 12 +++++++----- .../statusbar/policy/UserSwitcherController.java | 4 +++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/SettingsLib/src/com/android/settingslib/drawable/UserIconDrawable.java b/packages/SettingsLib/src/com/android/settingslib/drawable/UserIconDrawable.java index 2213db88f2fd3..274696bfec0ed 100644 --- a/packages/SettingsLib/src/com/android/settingslib/drawable/UserIconDrawable.java +++ b/packages/SettingsLib/src/com/android/settingslib/drawable/UserIconDrawable.java @@ -172,11 +172,13 @@ public class UserIconDrawable extends Drawable implements Drawable.Callback { public UserIconDrawable setBadgeIfManagedUser(Context context, int userId) { Drawable badge = null; - boolean isManaged = context.getSystemService(DevicePolicyManager.class) - .getProfileOwnerAsUser(userId) != null; - if (isManaged) { - badge = getDrawableForDisplayDensity( - context, com.android.internal.R.drawable.ic_corp_badge_case); + if (userId != UserHandle.USER_NULL) { + boolean isManaged = context.getSystemService(DevicePolicyManager.class) + .getProfileOwnerAsUser(userId) != null; + if (isManaged) { + badge = getDrawableForDisplayDensity( + context, com.android.internal.R.drawable.ic_corp_badge_case); + } } return setBadge(badge); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java index dbfbdd79dc3b4..15b2f2bcb7551 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java @@ -51,6 +51,7 @@ import com.android.internal.util.UserIcons; import com.android.settingslib.RestrictedLockUtilsInternal; import com.android.settingslib.Utils; import com.android.systemui.Dependency; +import com.android.systemui.Dumpable; import com.android.systemui.GuestResumeSessionReceiver; import com.android.systemui.Prefs; import com.android.systemui.Prefs.Key; @@ -70,7 +71,7 @@ import java.util.List; /** * Keeps a list of all users on the device for user switching. */ -public class UserSwitcherController { +public class UserSwitcherController implements Dumpable { private static final String TAG = "UserSwitcherController"; private static final boolean DEBUG = false; @@ -549,6 +550,7 @@ public class UserSwitcherController { }; }; + @Override public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { pw.println("UserSwitcherController state:"); pw.println(" mLastNonGuestUser=" + mLastNonGuestUser);