Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f19cce18 authored by Adam Cohen's avatar Adam Cohen Committed by Android (Google) Code Review
Browse files

Merge "Revert "Pushing state persistence to a background thread"" into jb-mr1-lockscreen-dev

parents 64e59193 b6f83374
Loading
Loading
Loading
Loading
+12 −35
Original line number Diff line number Diff line
@@ -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<Provider> mDeletedProviders = new ArrayList<Provider>();
    ArrayList<Host> mDeletedHosts = new ArrayList<Host>();
@@ -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();
                    }
                }
            }
@@ -419,7 +410,7 @@ class AppWidgetServiceImpl {

    private void ensureStateLoadedLocked() {
        if (!mStateLoaded) {
            loadAppWidgetListLocked();
            loadAppWidgetList();
            loadStateLocked();
            mStateLoaded = true;
        }
@@ -440,7 +431,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;
@@ -453,7 +444,7 @@ class AppWidgetServiceImpl {
            AppWidgetId id = lookupAppWidgetIdLocked(appWidgetId);
            if (id != null) {
                deleteAppWidgetLocked(id);
                saveStateAsync();
                saveStateLocked();
            }
        }
    }
@@ -465,7 +456,7 @@ class AppWidgetServiceImpl {
            Host host = lookupHostLocked(callingUid, hostId);
            if (host != null) {
                deleteHostLocked(host);
                saveStateAsync();
                saveStateLocked();
            }
        }
    }
@@ -484,7 +475,7 @@ class AppWidgetServiceImpl {
                }
            }
            if (changed) {
                saveStateAsync();
                saveStateLocked();
            }
        }
    }
@@ -600,7 +591,7 @@ class AppWidgetServiceImpl {

                // schedule the future updates
                registerForBroadcastsLocked(p, getAppWidgetIds(p));
                saveStateAsync();
                saveStateLocked();
            }
        } finally {
            Binder.restoreCallingIdentity(ident);
@@ -664,8 +655,8 @@ class AppWidgetServiceImpl {
            } else {
                mPackagesWithBindWidgetPermission.remove(packageName);
            }
            saveStateAsync();
        }
        saveStateLocked();
    }

    // Binds to a specific RemoteViewsService
@@ -902,20 +893,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);
@@ -936,7 +913,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();
        }
    }

@@ -1237,7 +1214,7 @@ class AppWidgetServiceImpl {
        }
    }

    void loadAppWidgetListLocked() {
    void loadAppWidgetList() {
        Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
        try {
            List<ResolveInfo> broadcastReceivers = mPm.queryIntentReceivers(intent,