diff options
| -rw-r--r-- | services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java | 45 | ||||
| -rw-r--r-- | services/core/java/com/android/server/am/ActivityManagerService.java | 11 |
2 files changed, 30 insertions, 26 deletions
diff --git a/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java b/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java index 449063d95770..d4bd5adb7b25 100644 --- a/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java +++ b/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java @@ -222,6 +222,7 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku private final SparseIntArray mLoadedUserIds = new SparseIntArray(); + private final Object mWidgetPackagesLock = new Object(); private final SparseArray<ArraySet<String>> mWidgetPackages = new SparseArray<>(); private BackupRestoreController mBackupRestoreController; @@ -2941,11 +2942,13 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku if (widget.provider == null) return; int userId = widget.provider.getUserId(); - ArraySet<String> packages = mWidgetPackages.get(userId); - if (packages == null) { - mWidgetPackages.put(userId, packages = new ArraySet<String>()); + synchronized (mWidgetPackagesLock) { + ArraySet<String> packages = mWidgetPackages.get(userId); + if (packages == null) { + mWidgetPackages.put(userId, packages = new ArraySet<String>()); + } + packages.add(widget.provider.info.provider.getPackageName()); } - packages.add(widget.provider.info.provider.getPackageName()); // If we are adding a widget it might be for a provider that // is currently masked, if so mask the widget. @@ -2972,22 +2975,24 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku final int userId = widget.provider.getUserId(); final String packageName = widget.provider.info.provider.getPackageName(); - ArraySet<String> packages = mWidgetPackages.get(userId); - if (packages == null) { - return; - } - // Check if there is any other widget with the same package name. - // Remove packageName if none. - final int N = mWidgets.size(); - for (int i = 0; i < N; i++) { - Widget w = mWidgets.get(i); - if (w.provider == null) continue; - if (w.provider.getUserId() == userId - && packageName.equals(w.provider.info.provider.getPackageName())) { + synchronized (mWidgetPackagesLock) { + ArraySet<String> packages = mWidgetPackages.get(userId); + if (packages == null) { return; } + // Check if there is any other widget with the same package name. + // Remove packageName if none. + final int N = mWidgets.size(); + for (int i = 0; i < N; i++) { + Widget w = mWidgets.get(i); + if (w.provider == null) continue; + if (w.provider.getUserId() == userId + && packageName.equals(w.provider.info.provider.getPackageName())) { + return; + } + } + packages.remove(packageName); } - packages.remove(packageName); } /** @@ -3000,7 +3005,9 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku } private void onWidgetsClearedLocked() { - mWidgetPackages.clear(); + synchronized (mWidgetPackagesLock) { + mWidgetPackages.clear(); + } } @Override @@ -3008,7 +3015,7 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku if (Binder.getCallingUid() != Process.SYSTEM_UID) { throw new SecurityException("Only the system process can call this"); } - synchronized (mLock) { + synchronized (mWidgetPackagesLock) { final ArraySet<String> packages = mWidgetPackages.get(userId); if (packages != null) { return packages.contains(packageName); diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index be1d1bcbdfff..558caff4aa66 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -16723,16 +16723,13 @@ public class ActivityManagerService extends IActivityManager.Stub @Override public void setDeviceOwnerUid(int uid) { - synchronized (ActivityManagerService.this) { - mDeviceOwnerUid = uid; - } + mDeviceOwnerUid = uid; } @Override public boolean isDeviceOwner(int uid) { - synchronized (ActivityManagerService.this) { - return uid >= 0 && mDeviceOwnerUid == uid; - } + int cachedUid = mDeviceOwnerUid; + return uid >= 0 && cachedUid == uid; } @@ -16768,7 +16765,7 @@ public class ActivityManagerService extends IActivityManager.Stub @Override public void addPendingTopUid(int uid, int pid) { - mPendingStartActivityUids.add(uid, pid); + mPendingStartActivityUids.add(uid, pid); } @Override |