Add configurable default setting for assistant componentname

By requiring an explicit default setting, it eliminates all ambiguous
states where a disambiguation would normally be shown. With this
change in place, at no point should a disambiguation be shown.

(Note: this is a fix to Change-Id: Ib32daf that clarifies
the logic if R.string.config_defaultAssistantComponentName
has not been set in a given build.)

Test: manual
Bug: 111603898
Change-Id: Id39fdf700ed4ef08ebbc333b5452223430ac2e48
Merged-In: Ib32dafbd3c6fcbe11186dc8ecab6b09c9b734067
(cherry picked from commit c6ed3a29f0e2f0f1ceb727c5ece07702987e4ba5)
diff --git a/core/java/com/android/internal/app/AssistUtils.java b/core/java/com/android/internal/app/AssistUtils.java
index 9171959..fed0a89 100644
--- a/core/java/com/android/internal/app/AssistUtils.java
+++ b/core/java/com/android/internal/app/AssistUtils.java
@@ -32,6 +32,8 @@
 import android.provider.Settings;
 import android.util.Log;
 
+import com.android.internal.R;
+
 /**
  * Utility method for dealing with the assistant aspects of
  * {@link com.android.internal.app.IVoiceInteractionManagerService IVoiceInteractionManagerService}.
@@ -40,6 +42,14 @@
 
     private static final String TAG = "AssistUtils";
 
+    /**
+     * Sentinel value for "no default assistant specified."
+     *
+     * Empty string is already used to represent an explicit setting of No Assistant. null cannot
+     * be used because we can't represent a null value in XML.
+     */
+    private static final String UNSET = "#+UNSET";
+
     private final Context mContext;
     private final IVoiceInteractionManagerService mVoiceInteractionManagerService;
 
@@ -152,10 +162,21 @@
             return ComponentName.unflattenFromString(setting);
         }
 
+        final String defaultSetting = mContext.getResources().getString(
+                R.string.config_defaultAssistantComponentName);
+        if (defaultSetting != null && !defaultSetting.equals(UNSET)) {
+            return ComponentName.unflattenFromString(defaultSetting);
+        }
+
         // Fallback to keep backward compatible behavior when there is no user setting.
         if (activeServiceSupportsAssistGesture()) {
             return getActiveServiceComponentName();
         }
+
+        if (UNSET.equals(defaultSetting)) {
+            return null;
+        }
+
         final SearchManager searchManager =
             (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
         if (searchManager == null) {