From 039206a9b40d2188eb735f56ee51f131555c9dd3 Mon Sep 17 00:00:00 2001 From: Adam Cohen Date: Thu, 1 Nov 2012 14:06:16 -0700 Subject: Pushing state persistence to a background thread Change-Id: If776bc22c48525ba91dc7e4dd0e27de92612f2f5 --- .../com/android/server/AppWidgetServiceImpl.java | 47 ++++++++++++++++------ 1 file changed, 35 insertions(+), 12 deletions(-) (limited to 'services') diff --git a/services/java/com/android/server/AppWidgetServiceImpl.java b/services/java/com/android/server/AppWidgetServiceImpl.java index 6a313a0..4f72abb 100644 --- a/services/java/com/android/server/AppWidgetServiceImpl.java +++ b/services/java/com/android/server/AppWidgetServiceImpl.java @@ -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 mDeletedProviders = new ArrayList(); ArrayList mDeletedHosts = new ArrayList(); @@ -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(); } } } @@ -411,7 +420,7 @@ class AppWidgetServiceImpl { private void ensureStateLoadedLocked() { if (!mStateLoaded) { - loadAppWidgetList(); + loadAppWidgetListLocked(); loadStateLocked(); mStateLoaded = true; } @@ -432,7 +441,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; @@ -445,7 +454,7 @@ class AppWidgetServiceImpl { AppWidgetId id = lookupAppWidgetIdLocked(appWidgetId); if (id != null) { deleteAppWidgetLocked(id); - saveStateLocked(); + saveStateAsync(); } } } @@ -457,7 +466,7 @@ class AppWidgetServiceImpl { Host host = lookupHostLocked(callingUid, hostId); if (host != null) { deleteHostLocked(host); - saveStateLocked(); + saveStateAsync(); } } } @@ -476,7 +485,7 @@ class AppWidgetServiceImpl { } } if (changed) { - saveStateLocked(); + saveStateAsync(); } } } @@ -592,7 +601,7 @@ class AppWidgetServiceImpl { // schedule the future updates registerForBroadcastsLocked(p, getAppWidgetIds(p)); - saveStateLocked(); + saveStateAsync(); } } finally { Binder.restoreCallingIdentity(ident); @@ -656,8 +665,8 @@ class AppWidgetServiceImpl { } else { mPackagesWithBindWidgetPermission.remove(packageName); } + saveStateAsync(); } - saveStateLocked(); } // Binds to a specific RemoteViewsService @@ -894,6 +903,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); @@ -914,7 +937,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(); } } @@ -1215,7 +1238,7 @@ class AppWidgetServiceImpl { } } - void loadAppWidgetList() { + void loadAppWidgetListLocked() { Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE); try { List broadcastReceivers = mPm.queryIntentReceivers(intent, -- cgit v1.1 From b6f83374cc706e5da95a137e9d0f6bd6bbf3220e Mon Sep 17 00:00:00 2001 From: Adam Cohen Date: Thu, 1 Nov 2012 15:12:07 -0700 Subject: Revert "Pushing state persistence to a background thread" This reverts commit 039206a9b40d2188eb735f56ee51f131555c9dd3 Change-Id: I30fa07bf55a489562831b6334768b28bed638ef8 --- .../com/android/server/AppWidgetServiceImpl.java | 47 ++++++---------------- 1 file changed, 12 insertions(+), 35 deletions(-) (limited to 'services') diff --git a/services/java/com/android/server/AppWidgetServiceImpl.java b/services/java/com/android/server/AppWidgetServiceImpl.java index 4f72abb..6a313a0 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, -- cgit v1.1 From 67a871d85732e582c70a2a1d85ef4419eb658a12 Mon Sep 17 00:00:00 2001 From: Michael Jurka Date: Thu, 1 Nov 2012 18:26:01 -0700 Subject: Use clock's widget as the default keyguard widget Also, if we have no widgets in lockscreen, reinflate the default widget. If that fails, inflate the built-in clock (KeyguardStatusView) Change-Id: I2e90ab0893c993a755700e075e4a8ac5a685e0f2 --- services/java/com/android/server/AppWidgetServiceImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'services') diff --git a/services/java/com/android/server/AppWidgetServiceImpl.java b/services/java/com/android/server/AppWidgetServiceImpl.java index d0dd9cf..daa82f2 100644 --- a/services/java/com/android/server/AppWidgetServiceImpl.java +++ b/services/java/com/android/server/AppWidgetServiceImpl.java @@ -599,7 +599,7 @@ class AppWidgetServiceImpl { } public void bindAppWidgetId(int appWidgetId, ComponentName provider, Bundle options) { - mContext.enforceCallingPermission(android.Manifest.permission.BIND_APPWIDGET, + mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BIND_APPWIDGET, "bindAppWidgetId appWidgetId=" + appWidgetId + " provider=" + provider); bindAppWidgetIdImpl(appWidgetId, provider, options); } @@ -607,7 +607,7 @@ class AppWidgetServiceImpl { public boolean bindAppWidgetIdIfAllowed( String packageName, int appWidgetId, ComponentName provider, Bundle options) { try { - mContext.enforceCallingPermission(android.Manifest.permission.BIND_APPWIDGET, null); + mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BIND_APPWIDGET, null); } catch (SecurityException se) { if (!callerHasBindAppWidgetPermission(packageName)) { return false; -- cgit v1.1