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 }
@@ -419,7 +410,7 @@ void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
419410
420411 private void ensureStateLoadedLocked () {
421412 if (!mStateLoaded ) {
422- loadAppWidgetListLocked ();
413+ loadAppWidgetList ();
423414 loadStateLocked ();
424415 mStateLoaded = true ;
425416 }
@@ -440,7 +431,7 @@ public int allocateAppWidgetId(String packageName, int hostId) {
440431 host .instances .add (id );
441432 mAppWidgetIds .add (id );
442433
443- saveStateAsync ();
434+ saveStateLocked ();
444435 if (DBG ) log ("Allocating AppWidgetId for " + packageName + " host=" + hostId
445436 + " id=" + appWidgetId );
446437 return appWidgetId ;
@@ -453,7 +444,7 @@ public void deleteAppWidgetId(int appWidgetId) {
453444 AppWidgetId id = lookupAppWidgetIdLocked (appWidgetId );
454445 if (id != null ) {
455446 deleteAppWidgetLocked (id );
456- saveStateAsync ();
447+ saveStateLocked ();
457448 }
458449 }
459450 }
@@ -465,7 +456,7 @@ public void deleteHost(int hostId) {
465456 Host host = lookupHostLocked (callingUid , hostId );
466457 if (host != null ) {
467458 deleteHostLocked (host );
468- saveStateAsync ();
459+ saveStateLocked ();
469460 }
470461 }
471462 }
@@ -484,7 +475,7 @@ public void deleteAllHosts() {
484475 }
485476 }
486477 if (changed ) {
487- saveStateAsync ();
478+ saveStateLocked ();
488479 }
489480 }
490481 }
@@ -600,7 +591,7 @@ private void bindAppWidgetIdImpl(int appWidgetId, ComponentName provider, Bundle
600591
601592 // schedule the future updates
602593 registerForBroadcastsLocked (p , getAppWidgetIds (p ));
603- saveStateAsync ();
594+ saveStateLocked ();
604595 }
605596 } finally {
606597 Binder .restoreCallingIdentity (ident );
@@ -664,8 +655,8 @@ public void setBindAppWidgetPermission(String packageName, boolean permission) {
664655 } else {
665656 mPackagesWithBindWidgetPermission .remove (packageName );
666657 }
667- saveStateAsync ();
668658 }
659+ saveStateLocked ();
669660 }
670661
671662 // Binds to a specific RemoteViewsService
@@ -902,20 +893,6 @@ public void updateAppWidgetIds(int[] appWidgetIds, RemoteViews views) {
902893 }
903894 }
904895
905- private void saveStateAsync () {
906- mSaveStateHandler .post (mSaveStateRunnable );
907- }
908-
909- private final Runnable mSaveStateRunnable = new Runnable () {
910- @ Override
911- public void run () {
912- synchronized (mAppWidgetIds ) {
913- ensureStateLoadedLocked ();
914- saveStateLocked ();
915- }
916- }
917- };
918-
919896 public void updateAppWidgetOptions (int appWidgetId , Bundle options ) {
920897 synchronized (mAppWidgetIds ) {
921898 options = cloneIfLocalBinder (options );
@@ -936,7 +913,7 @@ public void updateAppWidgetOptions(int appWidgetId, Bundle options) {
936913 intent .putExtra (AppWidgetManager .EXTRA_APPWIDGET_ID , id .appWidgetId );
937914 intent .putExtra (AppWidgetManager .EXTRA_APPWIDGET_OPTIONS , id .options );
938915 mContext .sendBroadcastAsUser (intent , new UserHandle (mUserId ));
939- saveStateAsync ();
916+ saveStateLocked ();
940917 }
941918 }
942919
@@ -1237,7 +1214,7 @@ void pruneHostLocked(Host host) {
12371214 }
12381215 }
12391216
1240- void loadAppWidgetListLocked () {
1217+ void loadAppWidgetList () {
12411218 Intent intent = new Intent (AppWidgetManager .ACTION_APPWIDGET_UPDATE );
12421219 try {
12431220 List <ResolveInfo > broadcastReceivers = mPm .queryIntentReceivers (intent ,
0 commit comments