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
(cherry picked from commit 97eaacba10529a100306635be8a2aa7cd308d0f0)
diff --git a/packages/SettingsLib/src/com/android/settingslib/drawable/UserIconDrawable.java b/packages/SettingsLib/src/com/android/settingslib/drawable/UserIconDrawable.java
index 2213db8..274696b 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 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 dbfbdd7..15b2f2b 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.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 @@
 /**
  * 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 @@
         };
     };
 
+    @Override
     public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
         pw.println("UserSwitcherController state:");
         pw.println("  mLastNonGuestUser=" + mLastNonGuestUser);