WallpaperManagerService: Get rid of removed UIDs that have set dim

If the UID changes while a dim was set it'd never be set back to 0
This was actually triggered for some users:

setting the dim with no UID via adb immediately reverted to whatever the app set
dumpsys wallpaper showed a UID under mUidToDimAmount
only settings the dim for that UID via adb allowed having 0 dim back again.

Change-Id: I3c2a90e60c4fd3e5339f0276a5f176ee9cd91c59
diff --git a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
index c3efcb1..04ec11c 100644
--- a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
+++ b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
@@ -2684,6 +2684,20 @@
                 WallpaperData wallpaper = mWallpaperMap.get(mCurrentUserId);
                 WallpaperData lockWallpaper = mLockWallpaperMap.get(mCurrentUserId);
 
+                // remove gone UIDs from the map
+                boolean arrayChanged = false;
+                final int uidCount = wallpaper.mUidToDimAmount.size();
+                int[] uids = new int[uidCount];
+                for (int i = 0; i < uidCount; i++) {
+                    uids[i] = wallpaper.mUidToDimAmount.keyAt(i);
+                }
+                for (Integer u : uids) {
+                    final String cname = mPackageManagerInternal.getNameForUid(u);
+                    if (cname != null && !cname.isEmpty()) continue;
+                    wallpaper.mUidToDimAmount.remove(u);
+                    arrayChanged = true;
+                }
+
                 if (dimAmount == 0.0f) {
                     wallpaper.mUidToDimAmount.remove(uid);
                 } else {
@@ -2718,7 +2732,7 @@
                         changed = true;
                     }
                 }
-                if (changed) {
+                if (changed || arrayChanged) {
                     saveSettingsLocked(wallpaper.userId);
                 }
             }