Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 69084b3a authored by Ben Lin's avatar Ben Lin
Browse files

Add ability to show/hide assist_and_voice_input preference.

This adds a new boolean flag, config_show_assist_and_voice_input, which
when set to false will hide the assist_and_voice_input preference item.

Bug: 62379282
Test: make RunSettingsRoboTests
ROBOTEST_FILTER=DefaultAssistPreferenceControllerTest
Change-Id: I3bfc84f0fba07cd52679269daadbdcfccd205ff1
parent ac870bed
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -80,4 +80,7 @@

    <!-- Whether accessibility shortcut preference should be shown or not. -->
    <bool name="config_show_accessibility_shortcut_preference">true</bool>

    <!-- Whether assist_and_voice_input should be shown or not. -->
    <bool name="config_show_assist_and_voice_input">true</bool>
</resources>
+2 −1
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.service.voice.VoiceInteractionServiceInfo;
import android.support.annotation.VisibleForTesting;

import com.android.internal.app.AssistUtils;
import com.android.settings.R;
import com.android.settings.applications.defaultapps.DefaultAppInfo;
import com.android.settings.applications.defaultapps.DefaultAppPreferenceController;

@@ -73,7 +74,7 @@ public class DefaultAssistPreferenceController extends DefaultAppPreferenceContr

    @Override
    public boolean isAvailable() {
        return true;
        return mContext.getResources().getBoolean(R.bool.config_show_assist_and_voice_input);
    }

    @Override
+1 −0
Original line number Diff line number Diff line
@@ -30,4 +30,5 @@
    <bool name="config_show_wallpaper_attribution">false</bool>
    <bool name="config_show_default_home">false</bool>
    <bool name="config_show_accessibility_shortcut_preference">false</bool>
    <bool name="config_show_assist_and_voice_input">false</bool>
</resources>
+13 −4
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.util.ReflectionHelpers;

import java.util.ArrayList;
@@ -61,26 +62,33 @@ public class DefaultAssistPreferenceControllerTest {

    private static final String TEST_KEY = "test_pref_key";

    @Mock
    private Context mContext;
    @Mock
    private SearchManager mSearchManager;
    @Mock
    private PackageManager mPackageManager;

    private Context mContext;
    private DefaultAssistPreferenceController mController;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        mContext = spy(RuntimeEnvironment.application);
        mController = new DefaultAssistPreferenceController(mContext, TEST_KEY,
                true /* showSetting */);
    }

    @Test
    public void isAlwaysAvailable() {
    public void testAssistAndVoiceInput_byDefault_shouldBeShown() {
        assertThat(mController.isAvailable()).isTrue();
    }

    @Test
    @Config(qualifiers = "mcc999")
    public void testAssistAndVoiceInput_ifDisabled_shouldNotBeShown() {
        assertThat(mController.isAvailable()).isFalse();
    }

    @Test
    public void getPrefKey_shouldReturnKey() {
        assertThat(mController.getPreferenceKey())
@@ -91,7 +99,8 @@ public class DefaultAssistPreferenceControllerTest {
    @Config(shadows = {ShadowSecureSettings.class})
    public void getDefaultAppInfo_hasDefaultAssist_shouldReturnKey() {
        final String flattenKey = "com.android.settings/assist";
        Settings.Secure.putString(null, Settings.Secure.ASSISTANT, flattenKey);
        Settings.Secure.putString(mContext.getContentResolver(), Settings.Secure.ASSISTANT,
                flattenKey);
        DefaultAppInfo appInfo = mController.getDefaultAppInfo();

        assertThat(appInfo.getKey()).isEqualTo(flattenKey);