summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2015-08-13 20:05:11 (GMT)
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-08-13 20:05:11 (GMT)
commit81056da1def5d872d26b6f8a4e4163f9d94871a3 (patch)
treee0162c507e8a5693f36fa12ccacb75a82eb5b897
parentf29471c751b173b91989709b9ce9ca811bf20244 (diff)
parent2d648b057fa2d6410b1472c1b9dd5b65cd9c9414 (diff)
downloadandroid_packages_apps_Trebuchet-81056da1def5d872d26b6f8a4e4163f9d94871a3.zip
android_packages_apps_Trebuchet-81056da1def5d872d26b6f8a4e4163f9d94871a3.tar.gz
android_packages_apps_Trebuchet-81056da1def5d872d26b6f8a4e4163f9d94871a3.tar.bz2
Merge "Refreshing widget list when a package containing a widget changes" into ub-launcher3-burnaby
-rw-r--r--src/com/android/launcher3/LauncherAppWidgetHost.java2
-rw-r--r--src/com/android/launcher3/LauncherModel.java49
-rw-r--r--src/com/android/launcher3/WidgetPreviewLoader.java2
3 files changed, 39 insertions, 14 deletions
diff --git a/src/com/android/launcher3/LauncherAppWidgetHost.java b/src/com/android/launcher3/LauncherAppWidgetHost.java
index de7c610..6c3a1e8 100644
--- a/src/com/android/launcher3/LauncherAppWidgetHost.java
+++ b/src/com/android/launcher3/LauncherAppWidgetHost.java
@@ -95,8 +95,6 @@ public class LauncherAppWidgetHost extends AppWidgetHost {
}
protected void onProvidersChanged() {
- mLauncher.getModel().loadAndBindWidgetsAndShortcuts(mLauncher, mLauncher,
- true /* refresh */);
if (!mProviderChangeListeners.isEmpty()) {
for (Runnable callback : new ArrayList<>(mProviderChangeListeners)) {
callback.run();
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index d9b0cd4..397db6d 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -17,6 +17,7 @@
package com.android.launcher3;
import android.app.SearchManager;
+import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProviderInfo;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
@@ -2864,8 +2865,7 @@ public class LauncherModel extends BroadcastReceiver
// Cleanup any data stored for a deleted user.
ManagedProfileHeuristic.processAllUsers(profiles, mContext);
- loadAndBindWidgetsAndShortcuts(mApp.getContext(), tryGetCallbacks(oldCallbacks),
- true /* refresh */);
+ loadAndBindWidgetsAndShortcuts(tryGetCallbacks(oldCallbacks), true /* refresh */);
if (DEBUG_LOADERS) {
Log.d(TAG, "Icons processed in "
+ (SystemClock.uptimeMillis() - loadTime) + "ms");
@@ -2934,7 +2934,7 @@ public class LauncherModel extends BroadcastReceiver
}
// Reload widget list. No need to refresh, as we only want to update the icons and labels.
- loadAndBindWidgetsAndShortcuts(mApp.getContext(), callbacks, false);
+ loadAndBindWidgetsAndShortcuts(callbacks, false);
}
void enqueuePackageUpdated(PackageUpdatedTask task) {
@@ -3276,8 +3276,36 @@ public class LauncherModel extends BroadcastReceiver
});
}
- // onProvidersChanged method (API >= 17) already refreshed the widget list
- loadAndBindWidgetsAndShortcuts(context, callbacks, Build.VERSION.SDK_INT < 17);
+ // Update widgets
+ if (mOp == OP_ADD || mOp == OP_REMOVE || mOp == OP_UPDATE) {
+ // Always refresh for a package event on secondary user
+ boolean needToRefresh = !mUser.equals(UserHandleCompat.myUserHandle());
+
+ // Refresh widget list, if the package already had a widget.
+ synchronized (sBgLock) {
+ if (sBgWidgetProviders != null) {
+ HashSet<String> pkgSet = new HashSet<>();
+ Collections.addAll(pkgSet, mPackages);
+
+ for (ComponentKey key : sBgWidgetProviders.keySet()) {
+ needToRefresh |= key.user.equals(mUser) &&
+ pkgSet.contains(key.componentName.getPackageName());
+ }
+ }
+ }
+
+ if (!needToRefresh && mOp != OP_REMOVE) {
+ // Refresh widget list, if there is any newly added widget
+ PackageManager pm = context.getPackageManager();
+ for (String pkg : mPackages) {
+ needToRefresh |= !pm.queryBroadcastReceivers(
+ new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE)
+ .setPackage(pkg), 0).isEmpty();
+ }
+ }
+
+ loadAndBindWidgetsAndShortcuts(callbacks, needToRefresh);
+ }
// Write all the logs to disk
mHandler.post(new Runnable() {
@@ -3351,13 +3379,12 @@ public class LauncherModel extends BroadcastReceiver
}
}
- public void loadAndBindWidgetsAndShortcuts(final Context context, final Callbacks callbacks,
- final boolean refresh) {
+ public void loadAndBindWidgetsAndShortcuts(final Callbacks callbacks, final boolean refresh) {
runOnWorkerThread(new Runnable() {
@Override
public void run() {
- updateWidgetsModel(context, refresh);
+ updateWidgetsModel(refresh);
final WidgetsModel model = mBgWidgetsModel.clone();
mHandler.post(new Runnable() {
@@ -3381,10 +3408,10 @@ public class LauncherModel extends BroadcastReceiver
*
* @see #loadAndBindWidgetsAndShortcuts
*/
- @Thunk void updateWidgetsModel(Context context, boolean refresh) {
- PackageManager packageManager = context.getPackageManager();
+ @Thunk void updateWidgetsModel(boolean refresh) {
+ PackageManager packageManager = mApp.getContext().getPackageManager();
final ArrayList<Object> widgetsAndShortcuts = new ArrayList<Object>();
- widgetsAndShortcuts.addAll(getWidgetProviders(context, refresh));
+ widgetsAndShortcuts.addAll(getWidgetProviders(mApp.getContext(), refresh));
Intent shortcutsIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
widgetsAndShortcuts.addAll(packageManager.queryIntentActivities(shortcutsIntent, 0));
mBgWidgetsModel.setWidgetsAndShortcuts(widgetsAndShortcuts);
diff --git a/src/com/android/launcher3/WidgetPreviewLoader.java b/src/com/android/launcher3/WidgetPreviewLoader.java
index 3d50587..3460555 100644
--- a/src/com/android/launcher3/WidgetPreviewLoader.java
+++ b/src/com/android/launcher3/WidgetPreviewLoader.java
@@ -105,7 +105,7 @@ public class WidgetPreviewLoader {
* sizes (landscape vs portrait).
*/
private static class CacheDb extends SQLiteOpenHelper {
- private static final int DB_VERSION = 3;
+ private static final int DB_VERSION = 4;
private static final String TABLE_NAME = "shortcut_and_widget_previews";
private static final String COLUMN_COMPONENT = "componentName";