Allow pinning of Assistant app

Use bool config_pinnerAssistantApp (config.xml) to enable pinning for Assistant.

Test:  Set config_pinnerAssistantApp to true in config.xml, build & flash, run adb shell dumpsys pinner , check if assistant package is listed as pinned
Bug: 133211801
Bug: 133218284
Change-Id: If2e4c63156d4dd8f63f3318b5e8fb2db6bc4cc8b
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index 4d6e7da..ee0d595 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -3483,6 +3483,9 @@
     <!-- True if home app should be pinned via Pinner Service -->
     <bool name="config_pinnerHomeApp">false</bool>
 
+    <!-- True if assistant app should be pinned via Pinner Service -->
+    <bool name="config_pinnerAssistantApp">false</bool>
+
     <!-- List of files pinned by the Pinner Service with the apex boot image b/119800099 -->
     <string-array translatable="false" name="config_apexBootImagePinnerServiceFiles">
     </string-array>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 4094bf4..88833b1 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -3118,6 +3118,7 @@
   <java-symbol type="array" name="config_defaultPinnerServiceFiles" />
   <java-symbol type="bool" name="config_pinnerCameraApp" />
   <java-symbol type="bool" name="config_pinnerHomeApp" />
+  <java-symbol type="bool" name="config_pinnerAssistantApp" />
   <java-symbol type="array" name="config_apexBootImagePinnerServiceFiles" />
 
   <java-symbol type="string" name="config_doubleTouchGestureEnableFile" />
diff --git a/services/core/java/com/android/server/PinnerService.java b/services/core/java/com/android/server/PinnerService.java
index 80facbb..49ef164 100644
--- a/services/core/java/com/android/server/PinnerService.java
+++ b/services/core/java/com/android/server/PinnerService.java
@@ -25,6 +25,7 @@
 import android.app.ActivityManagerInternal;
 import android.app.IActivityManager;
 import android.app.IUidObserver;
+import android.app.SearchManager;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
@@ -94,6 +95,7 @@
 
     private static final int KEY_CAMERA = 0;
     private static final int KEY_HOME = 1;
+    private static final int KEY_ASSISTANT = 2;
 
     // Pin the camera application.
     private static boolean PROP_PIN_CAMERA = SystemProperties.getBoolean(
@@ -107,8 +109,9 @@
 
     private static final int MAX_CAMERA_PIN_SIZE = 80 * (1 << 20); // 80MB max for camera app.
     private static final int MAX_HOME_PIN_SIZE = 6 * (1 << 20); // 6MB max for home app.
+    private static final int MAX_ASSISTANT_PIN_SIZE = 60 * (1 << 20); // 60MB max for assistant app.
 
-    @IntDef({KEY_CAMERA, KEY_HOME})
+    @IntDef({KEY_CAMERA, KEY_HOME, KEY_ASSISTANT})
     @Retention(RetentionPolicy.SOURCE)
     public @interface AppKey {}
 
@@ -117,6 +120,7 @@
     private final ActivityManagerInternal mAmInternal;
     private final IActivityManager mAm;
     private final UserManager mUserManager;
+    private SearchManager mSearchManager;
 
     /** The list of the statically pinned files. */
     @GuardedBy("this")
@@ -167,6 +171,8 @@
                 com.android.internal.R.bool.config_pinnerCameraApp);
         boolean shouldPinHome = context.getResources().getBoolean(
                 com.android.internal.R.bool.config_pinnerHomeApp);
+        boolean shouldPinAssistant = context.getResources().getBoolean(
+                com.android.internal.R.bool.config_pinnerAssistantApp);
         if (shouldPinCamera) {
             if (PROP_PIN_CAMERA) {
                 mPinKeys.add(KEY_CAMERA);
@@ -177,6 +183,9 @@
         if (shouldPinHome) {
             mPinKeys.add(KEY_HOME);
         }
+        if (shouldPinAssistant) {
+            mPinKeys.add(KEY_ASSISTANT);
+        }
         mPinnerHandler = new PinnerHandler(BackgroundThread.get().getLooper());
 
         mAtmInternal = LocalServices.getService(ActivityTaskManagerInternal.class);
@@ -207,6 +216,15 @@
         sendPinAppsMessage(UserHandle.USER_SYSTEM);
     }
 
+    @Override
+    public void onBootPhase(int phase) {
+        // SearchManagerService is started after PinnerService, wait for PHASE_SYSTEM_SERVICES_READY
+        if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) {
+            mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
+            sendPinAppsMessage(UserHandle.USER_SYSTEM);
+        }
+    }
+
     /**
      * Repin apps on user switch.
      * <p>
@@ -408,6 +426,14 @@
         return getApplicationInfoForIntent(intent, userHandle, false);
     }
 
+    private ApplicationInfo getAssistantInfo(int userHandle) {
+        if (mSearchManager != null) {
+            Intent intent = mSearchManager.getAssistIntent(false);
+            return getApplicationInfoForIntent(intent, userHandle, true);
+        }
+        return null;
+    }
+
     private ApplicationInfo getApplicationInfoForIntent(Intent intent, int userHandle,
             boolean defaultToSystemApp) {
         if (intent == null) {
@@ -520,6 +546,8 @@
                 return getCameraInfo(userHandle);
             case KEY_HOME:
                 return getHomeInfo(userHandle);
+            case KEY_ASSISTANT:
+                return getAssistantInfo(userHandle);
             default:
                 return null;
         }
@@ -534,6 +562,8 @@
                 return "Camera";
             case KEY_HOME:
                 return "Home";
+            case KEY_ASSISTANT:
+                return "Assistant";
             default:
                 return null;
         }
@@ -548,6 +578,8 @@
                 return MAX_CAMERA_PIN_SIZE;
             case KEY_HOME:
                 return MAX_HOME_PIN_SIZE;
+            case KEY_ASSISTANT:
+                return MAX_ASSISTANT_PIN_SIZE;
             default:
                 return 0;
         }