4141import android .os .Binder ;
4242import android .os .Bundle ;
4343import android .os .Environment ;
44- import android .os .Handler ;
45- import android .os .HandlerThread ;
4644import android .os .IBinder ;
47- import android .os .Looper ;
4845import android .os .Process ;
4946import android .os .RemoteException ;
5047import android .os .SystemClock ;
@@ -183,8 +180,6 @@ public void disconnect() {
183180 boolean mStateLoaded ;
184181 int mMaxWidgetBitmapMemory ;
185182
186- private final Handler mSaveStateHandler ;
187-
188183 // These are for debugging only -- widgets are going missing in some rare instances
189184 ArrayList <Provider > mDeletedProviders = new ArrayList <Provider >();
190185 ArrayList <Host > mDeletedHosts = new ArrayList <Host >();
@@ -194,10 +189,6 @@ public void disconnect() {
194189 mPm = AppGlobals .getPackageManager ();
195190 mAlarmManager = (AlarmManager ) mContext .getSystemService (Context .ALARM_SERVICE );
196191 mUserId = userId ;
197-
198- HandlerThread handlerThread = new HandlerThread ("AppWidgetServiceImpl -- Save state" );
199- handlerThread .start ();
200- mSaveStateHandler = new Handler (handlerThread .getLooper ());
201192 computeMaximumWidgetBitmapMemory ();
202193 }
203194
@@ -245,7 +236,7 @@ void onConfigurationChanged() {
245236 updateProvidersForPackageLocked (cn .getPackageName (), removedProviders );
246237 }
247238 }
248- saveStateAsync ();
239+ saveStateLocked ();
249240 }
250241 }
251242 }
@@ -295,7 +286,7 @@ void onBroadcastReceived(Intent intent) {
295286 providersModified |= addProvidersForPackageLocked (pkgName );
296287 }
297288 }
298- saveStateAsync ();
289+ saveStateLocked ();
299290 }
300291 } else {
301292 Bundle extras = intent .getExtras ();
@@ -306,7 +297,7 @@ void onBroadcastReceived(Intent intent) {
306297 ensureStateLoadedLocked ();
307298 for (String pkgName : pkgList ) {
308299 providersModified |= removeProvidersForPackageLocked (pkgName );
309- saveStateAsync ();
300+ saveStateLocked ();
310301 }
311302 }
312303 }
@@ -420,7 +411,7 @@ void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
420411
421412 private void ensureStateLoadedLocked () {
422413 if (!mStateLoaded ) {
423- loadAppWidgetListLocked ();
414+ loadAppWidgetList ();
424415 loadStateLocked ();
425416 mStateLoaded = true ;
426417 }
@@ -441,7 +432,7 @@ public int allocateAppWidgetId(String packageName, int hostId) {
441432 host .instances .add (id );
442433 mAppWidgetIds .add (id );
443434
444- saveStateAsync ();
435+ saveStateLocked ();
445436 if (DBG ) log ("Allocating AppWidgetId for " + packageName + " host=" + hostId
446437 + " id=" + appWidgetId );
447438 return appWidgetId ;
@@ -454,7 +445,7 @@ public void deleteAppWidgetId(int appWidgetId) {
454445 AppWidgetId id = lookupAppWidgetIdLocked (appWidgetId );
455446 if (id != null ) {
456447 deleteAppWidgetLocked (id );
457- saveStateAsync ();
448+ saveStateLocked ();
458449 }
459450 }
460451 }
@@ -466,7 +457,7 @@ public void deleteHost(int hostId) {
466457 Host host = lookupHostLocked (callingUid , hostId );
467458 if (host != null ) {
468459 deleteHostLocked (host );
469- saveStateAsync ();
460+ saveStateLocked ();
470461 }
471462 }
472463 }
@@ -485,7 +476,7 @@ public void deleteAllHosts() {
485476 }
486477 }
487478 if (changed ) {
488- saveStateAsync ();
479+ saveStateLocked ();
489480 }
490481 }
491482 }
@@ -601,7 +592,7 @@ private void bindAppWidgetIdImpl(int appWidgetId, ComponentName provider, Bundle
601592
602593 // schedule the future updates
603594 registerForBroadcastsLocked (p , getAppWidgetIds (p ));
604- saveStateAsync ();
595+ saveStateLocked ();
605596 }
606597 } finally {
607598 Binder .restoreCallingIdentity (ident );
@@ -665,8 +656,8 @@ public void setBindAppWidgetPermission(String packageName, boolean permission) {
665656 } else {
666657 mPackagesWithBindWidgetPermission .remove (packageName );
667658 }
668- saveStateAsync ();
669659 }
660+ saveStateLocked ();
670661 }
671662
672663 // Binds to a specific RemoteViewsService
@@ -903,20 +894,6 @@ public void updateAppWidgetIds(int[] appWidgetIds, RemoteViews views) {
903894 }
904895 }
905896
906- private void saveStateAsync () {
907- mSaveStateHandler .post (mSaveStateRunnable );
908- }
909-
910- private final Runnable mSaveStateRunnable = new Runnable () {
911- @ Override
912- public void run () {
913- synchronized (mAppWidgetIds ) {
914- ensureStateLoadedLocked ();
915- saveStateLocked ();
916- }
917- }
918- };
919-
920897 public void updateAppWidgetOptions (int appWidgetId , Bundle options ) {
921898 synchronized (mAppWidgetIds ) {
922899 options = cloneIfLocalBinder (options );
@@ -937,7 +914,7 @@ public void updateAppWidgetOptions(int appWidgetId, Bundle options) {
937914 intent .putExtra (AppWidgetManager .EXTRA_APPWIDGET_ID , id .appWidgetId );
938915 intent .putExtra (AppWidgetManager .EXTRA_APPWIDGET_OPTIONS , id .options );
939916 mContext .sendBroadcastAsUser (intent , new UserHandle (mUserId ));
940- saveStateAsync ();
917+ saveStateLocked ();
941918 }
942919 }
943920
@@ -1238,7 +1215,7 @@ void pruneHostLocked(Host host) {
12381215 }
12391216 }
12401217
1241- void loadAppWidgetListLocked () {
1218+ void loadAppWidgetList () {
12421219 Intent intent = new Intent (AppWidgetManager .ACTION_APPWIDGET_UPDATE );
12431220 try {
12441221 List <ResolveInfo > broadcastReceivers = mPm .queryIntentReceivers (intent ,
0 commit comments