Merge "Pushing state persistence to a background thread" into jb-mr1-lockscreen-dev
This commit is contained in:
@ -41,7 +41,10 @@ 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;
|
||||
@ -180,6 +183,8 @@ 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>();
|
||||
@ -189,6 +194,10 @@ 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();
|
||||
}
|
||||
|
||||
@ -236,7 +245,7 @@ class AppWidgetServiceImpl {
|
||||
updateProvidersForPackageLocked(cn.getPackageName(), removedProviders);
|
||||
}
|
||||
}
|
||||
saveStateLocked();
|
||||
saveStateAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -286,7 +295,7 @@ class AppWidgetServiceImpl {
|
||||
providersModified |= addProvidersForPackageLocked(pkgName);
|
||||
}
|
||||
}
|
||||
saveStateLocked();
|
||||
saveStateAsync();
|
||||
}
|
||||
} else {
|
||||
Bundle extras = intent.getExtras();
|
||||
@ -297,7 +306,7 @@ class AppWidgetServiceImpl {
|
||||
ensureStateLoadedLocked();
|
||||
for (String pkgName : pkgList) {
|
||||
providersModified |= removeProvidersForPackageLocked(pkgName);
|
||||
saveStateLocked();
|
||||
saveStateAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -410,7 +419,7 @@ class AppWidgetServiceImpl {
|
||||
|
||||
private void ensureStateLoadedLocked() {
|
||||
if (!mStateLoaded) {
|
||||
loadAppWidgetList();
|
||||
loadAppWidgetListLocked();
|
||||
loadStateLocked();
|
||||
mStateLoaded = true;
|
||||
}
|
||||
@ -431,7 +440,7 @@ class AppWidgetServiceImpl {
|
||||
host.instances.add(id);
|
||||
mAppWidgetIds.add(id);
|
||||
|
||||
saveStateLocked();
|
||||
saveStateAsync();
|
||||
if (DBG) log("Allocating AppWidgetId for " + packageName + " host=" + hostId
|
||||
+ " id=" + appWidgetId);
|
||||
return appWidgetId;
|
||||
@ -444,7 +453,7 @@ class AppWidgetServiceImpl {
|
||||
AppWidgetId id = lookupAppWidgetIdLocked(appWidgetId);
|
||||
if (id != null) {
|
||||
deleteAppWidgetLocked(id);
|
||||
saveStateLocked();
|
||||
saveStateAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -456,7 +465,7 @@ class AppWidgetServiceImpl {
|
||||
Host host = lookupHostLocked(callingUid, hostId);
|
||||
if (host != null) {
|
||||
deleteHostLocked(host);
|
||||
saveStateLocked();
|
||||
saveStateAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -475,7 +484,7 @@ class AppWidgetServiceImpl {
|
||||
}
|
||||
}
|
||||
if (changed) {
|
||||
saveStateLocked();
|
||||
saveStateAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -591,7 +600,7 @@ class AppWidgetServiceImpl {
|
||||
|
||||
// schedule the future updates
|
||||
registerForBroadcastsLocked(p, getAppWidgetIds(p));
|
||||
saveStateLocked();
|
||||
saveStateAsync();
|
||||
}
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(ident);
|
||||
@ -655,8 +664,8 @@ class AppWidgetServiceImpl {
|
||||
} else {
|
||||
mPackagesWithBindWidgetPermission.remove(packageName);
|
||||
}
|
||||
saveStateAsync();
|
||||
}
|
||||
saveStateLocked();
|
||||
}
|
||||
|
||||
// Binds to a specific RemoteViewsService
|
||||
@ -893,6 +902,20 @@ 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);
|
||||
@ -913,7 +936,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));
|
||||
saveStateLocked();
|
||||
saveStateAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1214,7 +1237,7 @@ class AppWidgetServiceImpl {
|
||||
}
|
||||
}
|
||||
|
||||
void loadAppWidgetList() {
|
||||
void loadAppWidgetListLocked() {
|
||||
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
|
||||
try {
|
||||
List<ResolveInfo> broadcastReceivers = mPm.queryIntentReceivers(intent,
|
||||
|
Reference in New Issue
Block a user