summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/model
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2016-03-03 16:58:55 -0800
committerSunny Goyal <sunnygoyal@google.com>2016-03-09 20:21:22 -0800
commit2e1efb480a9b77a97cb623d4f5faf6802a417422 (patch)
tree8c6c0f0f7d91c7fc7d4d8ca23092f5fa4be720c9 /src/com/android/launcher3/model
parent726eb822d38ad422f37b74c4b0fc504a423ab926 (diff)
downloadandroid_packages_apps_Trebuchet-2e1efb480a9b77a97cb623d4f5faf6802a417422.tar.gz
android_packages_apps_Trebuchet-2e1efb480a9b77a97cb623d4f5faf6802a417422.tar.bz2
android_packages_apps_Trebuchet-2e1efb480a9b77a97cb623d4f5faf6802a417422.zip
Changing the widget loading strategy
Widget is loaded only when the user enters the overview mode and we keep the list updated as long as the user is in the overview mode. Once the user leaves the overview mode, we stop responding to widget updates Bug: 26077457 Change-Id: I9e4904b8f1300bfe0d77e2bc5f59aa6963fad8d1
Diffstat (limited to 'src/com/android/launcher3/model')
-rw-r--r--src/com/android/launcher3/model/GridSizeMigrationTask.java12
-rw-r--r--src/com/android/launcher3/model/WidgetsModel.java40
2 files changed, 46 insertions, 6 deletions
diff --git a/src/com/android/launcher3/model/GridSizeMigrationTask.java b/src/com/android/launcher3/model/GridSizeMigrationTask.java
index 19ec3ed64..931466c3b 100644
--- a/src/com/android/launcher3/model/GridSizeMigrationTask.java
+++ b/src/com/android/launcher3/model/GridSizeMigrationTask.java
@@ -23,8 +23,8 @@ import com.android.launcher3.LauncherSettings;
import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.Utilities;
import com.android.launcher3.backup.nano.BackupProtos;
+import com.android.launcher3.compat.AppWidgetManagerCompat;
import com.android.launcher3.compat.PackageInstallerCompat;
-import com.android.launcher3.compat.UserHandleCompat;
import com.android.launcher3.util.LongArrayMap;
import java.util.ArrayList;
@@ -696,7 +696,8 @@ public class GridSizeMigrationTask {
Favorites.SPANX, // 4
Favorites.SPANY, // 5
Favorites.INTENT, // 6
- Favorites.APPWIDGET_PROVIDER}, // 7
+ Favorites.APPWIDGET_PROVIDER, // 7
+ Favorites.APPWIDGET_ID}, // 8
Favorites.CONTAINER + " = " + Favorites.CONTAINER_DESKTOP
+ " AND " + Favorites.SCREEN + " = " + screen, null, null, null);
@@ -708,6 +709,7 @@ public class GridSizeMigrationTask {
final int indexSpanY = c.getColumnIndexOrThrow(Favorites.SPANY);
final int indexIntent = c.getColumnIndexOrThrow(Favorites.INTENT);
final int indexAppWidgetProvider = c.getColumnIndexOrThrow(Favorites.APPWIDGET_PROVIDER);
+ final int indexAppWidgetId = c.getColumnIndexOrThrow(Favorites.APPWIDGET_ID);
ArrayList<DbEntry> entries = new ArrayList<>();
while (c.moveToNext()) {
@@ -737,9 +739,9 @@ public class GridSizeMigrationTask {
entry.weight = Math.max(WT_WIDGET_MIN, WT_WIDGET_FACTOR
* entry.spanX * entry.spanY);
- // Migration happens for current user only.
- LauncherAppWidgetProviderInfo pInfo = LauncherModel.getProviderInfo(
- mContext, cn, UserHandleCompat.myUserHandle());
+ int widgetId = c.getInt(indexAppWidgetId);
+ LauncherAppWidgetProviderInfo pInfo = AppWidgetManagerCompat.getInstance(
+ mContext).getLauncherAppWidgetInfo(widgetId);
Point spans = pInfo == null ?
mWidgetMinSize.get(provider) : pInfo.getMinSpans(mIdp, mContext);
if (spans != null) {
diff --git a/src/com/android/launcher3/model/WidgetsModel.java b/src/com/android/launcher3/model/WidgetsModel.java
index 99a53ff36..e043c948f 100644
--- a/src/com/android/launcher3/model/WidgetsModel.java
+++ b/src/com/android/launcher3/model/WidgetsModel.java
@@ -1,9 +1,13 @@
package com.android.launcher3.model;
+import android.appwidget.AppWidgetProviderInfo;
import android.content.ComponentName;
import android.content.Context;
+import android.content.Intent;
import android.content.pm.ResolveInfo;
+import android.os.DeadObjectException;
+import android.os.TransactionTooLargeException;
import android.util.Log;
import com.android.launcher3.AppFilter;
@@ -16,6 +20,7 @@ import com.android.launcher3.Utilities;
import com.android.launcher3.compat.AlphabeticIndexCompat;
import com.android.launcher3.compat.AppWidgetManagerCompat;
import com.android.launcher3.compat.UserHandleCompat;
+import com.android.launcher3.config.ProviderConfig;
import java.util.ArrayList;
import java.util.Collections;
@@ -95,8 +100,41 @@ public class WidgetsModel {
return mRawList;
}
- public void setWidgetsAndShortcuts(ArrayList<Object> rawWidgetsShortcuts) {
+ public boolean isEmpty() {
+ return mRawList.isEmpty();
+ }
+
+ public WidgetsModel updateAndClone(Context context) {
Utilities.assertWorkerThread();
+
+ try {
+ final ArrayList<Object> widgetsAndShortcuts = new ArrayList<>();
+ // Widgets
+ for (AppWidgetProviderInfo widgetInfo :
+ AppWidgetManagerCompat.getInstance(context).getAllProviders()) {
+ widgetsAndShortcuts.add(LauncherAppWidgetProviderInfo
+ .fromProviderInfo(context, widgetInfo));
+ }
+ // Shortcuts
+ widgetsAndShortcuts.addAll(context.getPackageManager().queryIntentActivities(
+ new Intent(Intent.ACTION_CREATE_SHORTCUT), 0));
+ setWidgetsAndShortcuts(widgetsAndShortcuts);
+ } catch (Exception e) {
+ if (!ProviderConfig.IS_DOGFOOD_BUILD &&
+ (e.getCause() instanceof TransactionTooLargeException ||
+ e.getCause() instanceof DeadObjectException)) {
+ // the returned value may be incomplete and will not be refreshed until the next
+ // time Launcher starts.
+ // TODO: after figuring out a repro step, introduce a dirty bit to check when
+ // onResume is called to refresh the widget provider list.
+ } else {
+ throw e;
+ }
+ }
+ return clone();
+ }
+
+ private void setWidgetsAndShortcuts(ArrayList<Object> rawWidgetsShortcuts) {
mRawList = rawWidgetsShortcuts;
if (DEBUG) {
Log.d(TAG, "addWidgetsAndShortcuts, widgetsShortcuts#=" + rawWidgetsShortcuts.size());