summaryrefslogtreecommitdiffstats
path: root/packages/SystemUI/src/com/android/systemui/recents/misc
diff options
context:
space:
mode:
authorWinson Chung <winsonc@google.com>2015-06-03 17:31:39 -0700
committerWinson Chung <winsonc@google.com>2015-06-24 18:44:44 -0700
commitaf3bb6936786a8c14ac01da3d81d196d17b68b96 (patch)
treeffa5b5174b366056da0ad2a99720f67e5ff79c3d /packages/SystemUI/src/com/android/systemui/recents/misc
parentb8f03072d46b0d535415c07655b9fe5a8c41fb8f (diff)
downloadframeworks_base-af3bb6936786a8c14ac01da3d81d196d17b68b96.zip
frameworks_base-af3bb6936786a8c14ac01da3d81d196d17b68b96.tar.gz
frameworks_base-af3bb6936786a8c14ac01da3d81d196d17b68b96.tar.bz2
Refactoring recents search bar widget logic.
Bug: 19062975 Change-Id: I303710598675aeebca8f34ac57de6249462ec033
Diffstat (limited to 'packages/SystemUI/src/com/android/systemui/recents/misc')
-rw-r--r--packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java89
1 files changed, 55 insertions, 34 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java b/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java
index 272d39a..b60c66f 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java
@@ -62,9 +62,11 @@ import android.view.DisplayInfo;
import android.view.SurfaceControl;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityManager;
+import com.android.systemui.Prefs;
import com.android.systemui.R;
import com.android.systemui.recents.Constants;
import com.android.systemui.recents.Recents;
+import com.android.systemui.recents.RecentsAppWidgetHost;
import java.io.IOException;
import java.util.ArrayList;
@@ -527,14 +529,57 @@ public class SystemServicesProxy {
}
/**
- * Resolves and returns the first Recents widget from the same package as the global
- * assist activity.
+ * Returns the current search widget id.
*/
- public AppWidgetProviderInfo resolveSearchAppWidget() {
- if (mAwm == null) return null;
- if (mAssistComponent == null) return null;
+ public int getSearchAppWidgetId(Context context) {
+ return Prefs.getInt(context, Prefs.Key.SEARCH_APP_WIDGET_ID, -1);
+ }
+
+ /**
+ * Returns the current search widget info, binding a new one if necessary.
+ */
+ public AppWidgetProviderInfo getOrBindSearchAppWidget(Context context, AppWidgetHost host) {
+ int searchWidgetId = Prefs.getInt(context, Prefs.Key.SEARCH_APP_WIDGET_ID, -1);
+ AppWidgetProviderInfo searchWidgetInfo = mAwm.getAppWidgetInfo(searchWidgetId);
+ AppWidgetProviderInfo resolvedSearchWidgetInfo = resolveSearchAppWidget();
+
+ // Return the search widget info if it hasn't changed
+ if (searchWidgetInfo != null && resolvedSearchWidgetInfo != null &&
+ searchWidgetInfo.provider.equals(resolvedSearchWidgetInfo.provider)) {
+ if (Prefs.getString(context, Prefs.Key.SEARCH_APP_WIDGET_PACKAGE, null) == null) {
+ Prefs.putString(context, Prefs.Key.SEARCH_APP_WIDGET_PACKAGE,
+ searchWidgetInfo.provider.getPackageName());
+ }
+ return searchWidgetInfo;
+ }
+
+ // Delete the old widget
+ if (searchWidgetId != -1) {
+ host.deleteAppWidgetId(searchWidgetId);
+ }
+
+ // And rebind a new search widget
+ if (resolvedSearchWidgetInfo != null) {
+ Pair<Integer, AppWidgetProviderInfo> widgetInfo = bindSearchAppWidget(host,
+ resolvedSearchWidgetInfo);
+ if (widgetInfo != null) {
+ Prefs.putInt(context, Prefs.Key.SEARCH_APP_WIDGET_ID, widgetInfo.first);
+ Prefs.putString(context, Prefs.Key.SEARCH_APP_WIDGET_PACKAGE,
+ widgetInfo.second.provider.getPackageName());
+ return widgetInfo.second;
+ }
+ }
+
+ // If we fall through here, then there is no resolved search widget, so clear the state
+ Prefs.remove(context, Prefs.Key.SEARCH_APP_WIDGET_ID);
+ Prefs.remove(context, Prefs.Key.SEARCH_APP_WIDGET_PACKAGE);
+ return null;
+ }
- // Find the first Recents widget from the same package as the global assist activity
+ /**
+ * Returns the first Recents widget from the same package as the global assist activity.
+ */
+ private AppWidgetProviderInfo resolveSearchAppWidget() {
List<AppWidgetProviderInfo> widgets = mAwm.getInstalledProviders(
AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX);
for (AppWidgetProviderInfo info : widgets) {
@@ -548,45 +593,21 @@ public class SystemServicesProxy {
/**
* Resolves and binds the search app widget that is to appear in the recents.
*/
- public Pair<Integer, AppWidgetProviderInfo> bindSearchAppWidget(AppWidgetHost host) {
+ private Pair<Integer, AppWidgetProviderInfo> bindSearchAppWidget(AppWidgetHost host,
+ AppWidgetProviderInfo resolvedSearchWidgetInfo) {
if (mAwm == null) return null;
if (mAssistComponent == null) return null;
- // Find the first Recents widget from the same package as the global assist activity
- AppWidgetProviderInfo searchWidgetInfo = resolveSearchAppWidget();
-
- // Return early if there is no search widget
- if (searchWidgetInfo == null) return null;
-
// Allocate a new widget id and try and bind the app widget (if that fails, then just skip)
int searchWidgetId = host.allocateAppWidgetId();
Bundle opts = new Bundle();
opts.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX);
- if (!mAwm.bindAppWidgetIdIfAllowed(searchWidgetId, searchWidgetInfo.provider, opts)) {
+ if (!mAwm.bindAppWidgetIdIfAllowed(searchWidgetId, resolvedSearchWidgetInfo.provider, opts)) {
host.deleteAppWidgetId(searchWidgetId);
return null;
}
- return new Pair<Integer, AppWidgetProviderInfo>(searchWidgetId, searchWidgetInfo);
- }
-
- /**
- * Returns the app widget info for the specified app widget id.
- */
- public AppWidgetProviderInfo getAppWidgetInfo(int appWidgetId) {
- if (mAwm == null) return null;
-
- return mAwm.getAppWidgetInfo(appWidgetId);
- }
-
- /**
- * Destroys the specified app widget.
- */
- public void unbindSearchAppWidget(AppWidgetHost host, int appWidgetId) {
- if (mAwm == null) return;
-
- // Delete the app widget
- host.deleteAppWidgetId(appWidgetId);
+ return new Pair<>(searchWidgetId, resolvedSearchWidgetInfo);
}
/**