From b6f83374cc706e5da95a137e9d0f6bd6bbf3220e Mon Sep 17 00:00:00 2001 From: Adam Cohen Date: Thu, 1 Nov 2012 15:12:07 -0700 Subject: [PATCH] Revert "Pushing state persistence to a background thread" This reverts commit 039206a9b40d2188eb735f56ee51f131555c9dd3 Change-Id: I30fa07bf55a489562831b6334768b28bed638ef8 --- .../android/server/AppWidgetServiceImpl.java | 47 +++++-------------- 1 file changed, 12 insertions(+), 35 deletions(-) diff --git a/services/java/com/android/server/AppWidgetServiceImpl.java b/services/java/com/android/server/AppWidgetServiceImpl.java index 4f72abb102a4e..6a313a00dc0a8 100644 --- a/services/java/com/android/server/AppWidgetServiceImpl.java +++ b/services/java/com/android/server/AppWidgetServiceImpl.java @@ -41,10 +41,7 @@ import android.net.Uri; import android.os.Binder; import android.os.Bundle; import android.os.Environment; -import android.os.Handler; -import android.os.HandlerThread; import android.os.IBinder; -import android.os.Looper; import android.os.Process; import android.os.RemoteException; import android.os.SystemClock; @@ -183,8 +180,6 @@ class AppWidgetServiceImpl { boolean mStateLoaded; int mMaxWidgetBitmapMemory; - private final Handler mSaveStateHandler; - // These are for debugging only -- widgets are going missing in some rare instances ArrayList mDeletedProviders = new ArrayList(); ArrayList mDeletedHosts = new ArrayList(); @@ -194,10 +189,6 @@ class AppWidgetServiceImpl { mPm = AppGlobals.getPackageManager(); mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); mUserId = userId; - - HandlerThread handlerThread = new HandlerThread("AppWidgetServiceImpl -- Save state"); - handlerThread.start(); - mSaveStateHandler = new Handler(handlerThread.getLooper()); computeMaximumWidgetBitmapMemory(); } @@ -245,7 +236,7 @@ class AppWidgetServiceImpl { updateProvidersForPackageLocked(cn.getPackageName(), removedProviders); } } - saveStateAsync(); + saveStateLocked(); } } } @@ -295,7 +286,7 @@ class AppWidgetServiceImpl { providersModified |= addProvidersForPackageLocked(pkgName); } } - saveStateAsync(); + saveStateLocked(); } } else { Bundle extras = intent.getExtras(); @@ -306,7 +297,7 @@ class AppWidgetServiceImpl { ensureStateLoadedLocked(); for (String pkgName : pkgList) { providersModified |= removeProvidersForPackageLocked(pkgName); - saveStateAsync(); + saveStateLocked(); } } } @@ -420,7 +411,7 @@ class AppWidgetServiceImpl { private void ensureStateLoadedLocked() { if (!mStateLoaded) { - loadAppWidgetListLocked(); + loadAppWidgetList(); loadStateLocked(); mStateLoaded = true; } @@ -441,7 +432,7 @@ class AppWidgetServiceImpl { host.instances.add(id); mAppWidgetIds.add(id); - saveStateAsync(); + saveStateLocked(); if (DBG) log("Allocating AppWidgetId for " + packageName + " host=" + hostId + " id=" + appWidgetId); return appWidgetId; @@ -454,7 +445,7 @@ class AppWidgetServiceImpl { AppWidgetId id = lookupAppWidgetIdLocked(appWidgetId); if (id != null) { deleteAppWidgetLocked(id); - saveStateAsync(); + saveStateLocked(); } } } @@ -466,7 +457,7 @@ class AppWidgetServiceImpl { Host host = lookupHostLocked(callingUid, hostId); if (host != null) { deleteHostLocked(host); - saveStateAsync(); + saveStateLocked(); } } } @@ -485,7 +476,7 @@ class AppWidgetServiceImpl { } } if (changed) { - saveStateAsync(); + saveStateLocked(); } } } @@ -601,7 +592,7 @@ class AppWidgetServiceImpl { // schedule the future updates registerForBroadcastsLocked(p, getAppWidgetIds(p)); - saveStateAsync(); + saveStateLocked(); } } finally { Binder.restoreCallingIdentity(ident); @@ -665,8 +656,8 @@ class AppWidgetServiceImpl { } else { mPackagesWithBindWidgetPermission.remove(packageName); } - saveStateAsync(); } + saveStateLocked(); } // Binds to a specific RemoteViewsService @@ -903,20 +894,6 @@ class AppWidgetServiceImpl { } } - private void saveStateAsync() { - mSaveStateHandler.post(mSaveStateRunnable); - } - - private final Runnable mSaveStateRunnable = new Runnable() { - @Override - public void run() { - synchronized (mAppWidgetIds) { - ensureStateLoadedLocked(); - saveStateLocked(); - } - } - }; - public void updateAppWidgetOptions(int appWidgetId, Bundle options) { synchronized (mAppWidgetIds) { options = cloneIfLocalBinder(options); @@ -937,7 +914,7 @@ class AppWidgetServiceImpl { intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id.appWidgetId); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, id.options); mContext.sendBroadcastAsUser(intent, new UserHandle(mUserId)); - saveStateAsync(); + saveStateLocked(); } } @@ -1238,7 +1215,7 @@ class AppWidgetServiceImpl { } } - void loadAppWidgetListLocked() { + void loadAppWidgetList() { Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE); try { List broadcastReceivers = mPm.queryIntentReceivers(intent,