Fix 6414061: Add new ACTION_ASSIST intent.

Change-Id: I3d334f67723ac89f6001267e0f06ad76190b929f
diff --git a/api/current.txt b/api/current.txt
index 8340eda9..2d0ffd3 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -141,6 +141,7 @@
   public static final class Manifest.permission_group {
     ctor public Manifest.permission_group();
     field public static final java.lang.String ACCOUNTS = "android.permission-group.ACCOUNTS";
+    field public static final java.lang.String AFFECTS_BATTERY = "android.permission-group.AFFECTS_BATTERY";
     field public static final java.lang.String APP_INFO = "android.permission-group.APP_INFO";
     field public static final java.lang.String AUDIO_SETTINGS = "android.permission-group.AUDIO_SETTINGS";
     field public static final java.lang.String BOOKMARKS = "android.permission-group.BOOKMARKS";
@@ -150,7 +151,6 @@
     field public static final java.lang.String DEVELOPMENT_TOOLS = "android.permission-group.DEVELOPMENT_TOOLS";
     field public static final java.lang.String DEVICE_ALARMS = "android.permission-group.DEVICE_ALARMS";
     field public static final java.lang.String DISPLAY = "android.permission-group.DISPLAY";
-    field public static final java.lang.String AFFECTS_BATTERY = "android.permission-group.AFFECTS_BATTERY";
     field public static final java.lang.String HARDWARE_CONTROLS = "android.permission-group.HARDWARE_CONTROLS";
     field public static final java.lang.String LOCATION = "android.permission-group.LOCATION";
     field public static final java.lang.String MESSAGES = "android.permission-group.MESSAGES";
@@ -5669,6 +5669,7 @@
     field public static final java.lang.String ACTION_ALL_APPS = "android.intent.action.ALL_APPS";
     field public static final java.lang.String ACTION_ANSWER = "android.intent.action.ANSWER";
     field public static final java.lang.String ACTION_APP_ERROR = "android.intent.action.APP_ERROR";
+    field public static final java.lang.String ACTION_ASSIST = "android.intent.action.ASSIST";
     field public static final java.lang.String ACTION_ATTACH_DATA = "android.intent.action.ATTACH_DATA";
     field public static final java.lang.String ACTION_BATTERY_CHANGED = "android.intent.action.BATTERY_CHANGED";
     field public static final java.lang.String ACTION_BATTERY_LOW = "android.intent.action.BATTERY_LOW";
diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java
index cb8fea21..4ed6f25 100644
--- a/core/java/android/content/Intent.java
+++ b/core/java/android/content/Intent.java
@@ -1099,6 +1099,14 @@
     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
     public static final String ACTION_WEB_SEARCH = "android.intent.action.WEB_SEARCH";
     /**
+     * Activity Action: Perform assist action.
+     * <p>
+     * Input: nothing
+     * Output: nothing.
+     */
+    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
+    public static final String ACTION_ASSIST = "android.intent.action.ASSIST";
+    /**
      * Activity Action: List all available applications
      * <p>Input: Nothing.
      * <p>Output: nothing.
diff --git a/packages/SystemUI/src/com/android/systemui/SearchPanelView.java b/packages/SystemUI/src/com/android/systemui/SearchPanelView.java
index f3b9e30..185ca5b 100644
--- a/packages/SystemUI/src/com/android/systemui/SearchPanelView.java
+++ b/packages/SystemUI/src/com/android/systemui/SearchPanelView.java
@@ -52,7 +52,6 @@
     private boolean mShowing;
     private View mSearchTargetsContainer;
     private MultiWaveView mMultiWaveView;
-    private SearchManager mSearchManager;
 
     public SearchPanelView(Context context, AttributeSet attrs) {
         this(context, attrs, 0);
@@ -67,10 +66,30 @@
         }
     }
 
-    public boolean isSearchAvailable() {
+    private SearchManager mSearchManager;
+
+    public boolean isAssistantAvailable() {
         return mSearchManager != null && mSearchManager.getGlobalSearchActivity() != null;
     }
 
+    private void startAssistActivity() {
+        if (mSearchManager != null) {
+            ComponentName globalSearchActivity = mSearchManager.getGlobalSearchActivity();
+            if (globalSearchActivity != null) {
+                Intent intent = new Intent(Intent.ACTION_ASSIST);
+                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+                intent.setPackage(globalSearchActivity.getPackageName());
+                try {
+                    mContext.startActivity(intent);
+                } catch (ActivityNotFoundException e) {
+                    Slog.w(TAG, "Activity not found for " + intent.getAction());
+                }
+            } else {
+                Slog.w(TAG, "No global search activity");
+            }
+        }
+    }
+
     final MultiWaveView.OnTriggerListener mMultiWaveViewListener
             = new MultiWaveView.OnTriggerListener() {
 
@@ -90,29 +109,11 @@
             final int resId = mMultiWaveView.getResourceIdForTarget(target);
             switch (resId) {
                 case com.android.internal.R.drawable.ic_lockscreen_search:
-                    startGlobalSearch();
+                    startAssistActivity();
                 break;
             }
             mBar.hideSearchPanel();
         }
-
-        private void startGlobalSearch() {
-            if (mSearchManager != null) {
-                ComponentName globalSearchActivity = mSearchManager.getGlobalSearchActivity();
-                if (globalSearchActivity != null) {
-                    Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
-                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-                    intent.setComponent(globalSearchActivity);
-                    try {
-                        mContext.startActivity(intent);
-                    } catch (ActivityNotFoundException e) {
-                        Slog.w(TAG, "Application not found for action " + intent.getAction());
-                    }
-                } else {
-                    Slog.w(TAG, "No global search activity");
-                }
-            }
-        }
     };
 
     @Override
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
index 4125704..7317c5c 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
@@ -397,7 +397,7 @@
                   break;
              case MSG_OPEN_SEARCH_PANEL:
                  if (DEBUG) Slog.d(TAG, "opening search panel");
-                 if (mSearchPanelView != null && mSearchPanelView.isSearchAvailable()) {
+                 if (mSearchPanelView != null && mSearchPanelView.isAssistantAvailable()) {
                      mSearchPanelView.show(true, true);
                  }
                  break;
diff --git a/policy/src/com/android/internal/policy/impl/LockScreen.java b/policy/src/com/android/internal/policy/impl/LockScreen.java
index dacaeb5..8b0d858 100644
--- a/policy/src/com/android/internal/policy/impl/LockScreen.java
+++ b/policy/src/com/android/internal/policy/impl/LockScreen.java
@@ -29,6 +29,7 @@
 import android.app.ActivityManagerNative;
 import android.app.SearchManager;
 import android.content.ActivityNotFoundException;
+import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
 import android.content.res.Configuration;
@@ -38,8 +39,8 @@
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.*;
-import android.speech.RecognizerIntent;
 import android.util.Log;
+import android.util.Slog;
 import android.media.AudioManager;
 import android.os.RemoteException;
 import android.provider.MediaStore;
@@ -80,6 +81,7 @@
     private View mUnlockWidget;
     private boolean mCameraDisabled;
     private boolean mSearchDisabled;
+    private SearchManager mSearchManager;
 
     InfoCallbackImpl mInfoCallback = new InfoCallbackImpl() {
 
@@ -237,6 +239,25 @@
         }
     }
 
+    private Intent getAssistIntent() {
+        Intent intent = null;
+        if (mSearchManager == null) {
+            mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
+        }
+        if (mSearchManager != null) {
+            ComponentName globalSearchActivity = mSearchManager.getGlobalSearchActivity();
+            if (globalSearchActivity != null) {
+                intent = new Intent(Intent.ACTION_ASSIST);
+                intent.setPackage(globalSearchActivity.getPackageName());
+            } else {
+                Slog.w(TAG, "No global search activity");
+            }
+        } else {
+            Slog.w(TAG, "No SearchManager");
+        }
+        return intent;
+    }
+
     class MultiWaveViewMethods implements MultiWaveView.OnTriggerListener,
             UnlockWidgetCommonMethods {
         private final MultiWaveView mMultiWaveView;
@@ -279,7 +300,12 @@
             final int resId = mMultiWaveView.getResourceIdForTarget(target);
             switch (resId) {
                 case com.android.internal.R.drawable.ic_lockscreen_search:
-                    launchActivity(new Intent(RecognizerIntent.ACTION_WEB_SEARCH));
+                    Intent assistIntent = getAssistIntent();
+                    if (assistIntent != null) {
+                        launchActivity(assistIntent);
+                    } else {
+                        Log.w(TAG, "Failed to get intent for assist activity");
+                    }
                     mCallback.pokeWakelock();
                     break;