Update text for Languages & Input.

- update preference title to include gesture
- if assist gesture is supported, set summary text to reflect assist
status

Change-Id: I79477f331ae447d2505a1519da09886bf07ba1a2
Fix: 62219660
Test: make RunSettingsRoboTests
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 9b5339a..cd505d6 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -543,7 +543,7 @@
         </activity>
 
         <activity android:name=".Settings$LanguageAndInputSettingsActivity"
-            android:label="@string/language_keyboard_settings_title"
+            android:label="@string/language_input_gesture_title"
             android:icon="@drawable/ic_settings_language"
             android:taskAffinity="com.android.settings"
             android:parentActivityName="Settings$SystemDashboardActivity">
@@ -619,7 +619,7 @@
 
         <!-- Keep compatibility with old shortcuts. -->
         <activity-alias android:name="LanguageSettings"
-                android:label="@string/language_keyboard_settings_title"
+                android:label="@string/language_input_gesture_title"
                 android:clearTaskOnLaunch="true"
                 android:exported="true"
                 android:targetActivity="Settings$LanguageAndInputSettingsActivity">
diff --git a/res/xml/language_and_input.xml b/res/xml/language_and_input.xml
index d88cd11..5ea8836 100644
--- a/res/xml/language_and_input.xml
+++ b/res/xml/language_and_input.xml
@@ -18,7 +18,7 @@
 <PreferenceScreen
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
-    android:title="@string/language_keyboard_settings_title" >
+    android:title="@string/language_input_gesture_title" >
 
     <Preference
         android:key="phone_language"
diff --git a/src/com/android/settings/language/LanguageAndInputSettings.java b/src/com/android/settings/language/LanguageAndInputSettings.java
index 3818511..8bba103 100644
--- a/src/com/android/settings/language/LanguageAndInputSettings.java
+++ b/src/com/android/settings/language/LanguageAndInputSettings.java
@@ -38,6 +38,7 @@
 import com.android.settings.core.PreferenceController;
 import com.android.settings.dashboard.DashboardFragment;
 import com.android.settings.dashboard.SummaryLoader;
+import com.android.settings.gestures.AssistGestureFeatureProvider;
 import com.android.settings.gestures.AssistGesturePreferenceController;
 import com.android.settings.gestures.CameraLiftTriggerPreferenceController;
 import com.android.settings.gestures.DoubleTapPowerPreferenceController;
@@ -49,6 +50,7 @@
 import com.android.settings.inputmethod.PhysicalKeyboardPreferenceController;
 import com.android.settings.inputmethod.SpellCheckerPreferenceController;
 import com.android.settings.inputmethod.VirtualKeyboardPreferenceController;
+import com.android.settings.overlay.FeatureFactory;
 import com.android.settings.search.BaseSearchIndexProvider;
 import com.android.settingslib.core.lifecycle.Lifecycle;
 
@@ -98,7 +100,7 @@
         if (activity == null) {
             return;
         }
-        activity.setTitle(R.string.language_keyboard_settings_title);
+        activity.setTitle(R.string.language_input_gesture_title);
     }
 
     @Override
@@ -160,32 +162,42 @@
 
         private final Context mContext;
         private final SummaryLoader mSummaryLoader;
+        private final AssistGestureFeatureProvider mFeatureProvider;
 
         public SummaryProvider(Context context, SummaryLoader summaryLoader) {
             mContext = context;
             mSummaryLoader = summaryLoader;
+            mFeatureProvider = FeatureFactory.getFactory(context).getAssistGestureFeatureProvider();
         }
 
         @Override
         public void setListening(boolean listening) {
             if (listening) {
-                final String flattenComponent = Settings.Secure.getString(
+                if (mFeatureProvider.isSupported(mContext)) {
+                    final int assistGestureEnabled = Settings.Secure.getInt(
+                        mContext.getContentResolver(), Settings.Secure.ASSIST_GESTURE_ENABLED, 1);
+                    mSummaryLoader.setSummary(this, mContext.getString(assistGestureEnabled == 0
+                        ? R.string.language_input_gesture_summary_off
+                        : R.string.language_input_gesture_summary_on_with_assist));
+                } else {
+                    final String flattenComponent = Settings.Secure.getString(
                         mContext.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
-                if (!TextUtils.isEmpty(flattenComponent)) {
-                    final PackageManager packageManage = mContext.getPackageManager();
-                    final String pkg = ComponentName.unflattenFromString(flattenComponent)
+                    if (!TextUtils.isEmpty(flattenComponent)) {
+                        final PackageManager packageManage = mContext.getPackageManager();
+                        final String pkg = ComponentName.unflattenFromString(flattenComponent)
                             .getPackageName();
-                    final InputMethodManager imm = (InputMethodManager) mContext.getSystemService(
-                            Context.INPUT_METHOD_SERVICE);
-                    final List<InputMethodInfo> imis = imm.getInputMethodList();
-                    for (InputMethodInfo imi : imis) {
-                        if (TextUtils.equals(imi.getPackageName(), pkg)) {
-                            mSummaryLoader.setSummary(this, imi.loadLabel(packageManage));
-                            return;
+                        final InputMethodManager imm = (InputMethodManager)
+                            mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
+                        final List<InputMethodInfo> imis = imm.getInputMethodList();
+                        for (InputMethodInfo imi : imis) {
+                            if (TextUtils.equals(imi.getPackageName(), pkg)) {
+                                mSummaryLoader.setSummary(this, imi.loadLabel(packageManage));
+                                return;
+                            }
                         }
                     }
+                    mSummaryLoader.setSummary(this, "");
                 }
-                mSummaryLoader.setSummary(this, "");
             }
         }
     }
diff --git a/tests/robotests/src/com/android/settings/language/LanguageAndInputSettingsTest.java b/tests/robotests/src/com/android/settings/language/LanguageAndInputSettingsTest.java
index 873b408..598917d 100644
--- a/tests/robotests/src/com/android/settings/language/LanguageAndInputSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/language/LanguageAndInputSettingsTest.java
@@ -37,7 +37,6 @@
 import com.android.settings.dashboard.SummaryLoader;
 import com.android.settings.testutils.FakeFeatureFactory;
 import com.android.settings.testutils.XmlTestUtils;
-import com.android.settings.testutils.FakeFeatureFactory;
 import com.android.settings.testutils.shadow.ShadowSecureSettings;
 import com.android.settingslib.core.lifecycle.Lifecycle;
 import com.android.settingslib.core.lifecycle.LifecycleObserver;
@@ -68,7 +67,7 @@
 public class LanguageAndInputSettingsTest {
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
-    private Context mContext;
+    private Activity mActivity;
     @Mock
     private PackageManager mPackageManager;
     @Mock
@@ -86,17 +85,18 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mock(UserManager.class));
-        when(mContext.getSystemService(Context.INPUT_SERVICE)).thenReturn(mock(InputManager.class));
-        when(mContext.getSystemService(Context.INPUT_SERVICE)).thenReturn(mIm);
-        when(mContext.getSystemService(Context.TEXT_SERVICES_MANAGER_SERVICE))
+        FakeFeatureFactory.setupForTest(mActivity);
+        when(mActivity.getSystemService(Context.USER_SERVICE)).thenReturn(mock(UserManager.class));
+        when(mActivity.getSystemService(Context.INPUT_SERVICE))
+                .thenReturn(mock(InputManager.class));
+        when(mActivity.getSystemService(Context.INPUT_SERVICE)).thenReturn(mIm);
+        when(mActivity.getSystemService(Context.TEXT_SERVICES_MANAGER_SERVICE))
                 .thenReturn(mock(TextServicesManager.class));
-        when(mContext.getSystemService(Context.DEVICE_POLICY_SERVICE)).thenReturn(mDpm);
-        when(mContext.getSystemService(Context.INPUT_METHOD_SERVICE)).thenReturn(mImm);
-        when((Object) mContext.getSystemService(AutofillManager.class))
+        when(mActivity.getSystemService(Context.DEVICE_POLICY_SERVICE)).thenReturn(mDpm);
+        when(mActivity.getSystemService(Context.INPUT_METHOD_SERVICE)).thenReturn(mImm);
+        when((Object) mActivity.getSystemService(AutofillManager.class))
                 .thenReturn(mAutofillManager);
-        mFragment = new TestFragment(mContext);
+        mFragment = new TestFragment(mActivity);
     }
 
     @Test
@@ -106,7 +106,8 @@
 
     @Test
     public void testGetPreferenceControllers_shouldRegisterLifecycleObservers() {
-        final List<PreferenceController> controllers = mFragment.getPreferenceControllers(mContext);
+        final List<PreferenceController> controllers =
+                mFragment.getPreferenceControllers(mActivity);
         int lifecycleObserverCount = 0;
         for (PreferenceController controller : controllers) {
             if (controller instanceof LifecycleObserver) {
@@ -120,7 +121,8 @@
     @Test
 
     public void testGetPreferenceControllers_shouldAllBeCreated() {
-        final List<PreferenceController> controllers = mFragment.getPreferenceControllers(mContext);
+        final List<PreferenceController> controllers =
+                mFragment.getPreferenceControllers(mActivity);
 
         assertThat(controllers.isEmpty()).isFalse();
     }
@@ -153,6 +155,29 @@
     }
 
     @Test
+    @Config(shadows = {
+            ShadowSecureSettings.class,
+    })
+    public void testSummary_assistSupported_shouldSetToAssistGestureStatus() {
+        final FakeFeatureFactory featureFactory =
+            (FakeFeatureFactory) FakeFeatureFactory.getFactory(mActivity);
+        when(featureFactory.assistGestureFeatureProvider.isSupported(any(Context.class)))
+            .thenReturn(true);
+
+        final SummaryLoader loader = mock(SummaryLoader.class);
+        SummaryLoader.SummaryProvider provider = mFragment.SUMMARY_PROVIDER_FACTORY
+                .createSummaryProvider(mActivity, loader);
+
+        ShadowSecureSettings.putInt(null, Settings.Secure.ASSIST_GESTURE_ENABLED, 0);
+        provider.setListening(true);
+        verify(mActivity).getString(R.string.language_input_gesture_summary_off);
+
+        ShadowSecureSettings.putInt(null, Settings.Secure.ASSIST_GESTURE_ENABLED, 1);
+        provider.setListening(true);
+        verify(mActivity).getString(R.string.language_input_gesture_summary_on_with_assist);
+    }
+
+    @Test
     public void testNonIndexableKeys_existInXmlLayout() {
         final Context context = spy(RuntimeEnvironment.application);
         //(InputManager) context.getSystemService(Context.INPUT_SERVICE);