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

Commit 8f77a3bf authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Make Media Vibration setting configurable" am: dcb1dbc7

parents 65d9917e dcb1dbc7
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -217,6 +217,10 @@
    -->
    <integer name="config_vibration_supported_intensity_levels">1</integer>

    <!-- Whether or not to show Media vibration settings in the vibration and haptics screen.
         Can be overridden for specific product builds if the target device does not support it -->
    <bool name="config_media_vibration_supported">true</bool>

    <!--
        Whether or not the homepage should be powered by legacy suggestion (versus contextual cards)
        Default to true as not all devices support contextual cards.
+4 −1
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ import android.content.Context;
import android.os.VibrationAttributes;
import android.provider.Settings;

import com.android.settings.R;

/** Preference controller for am vibration intensity */
public class MediaVibrationIntensityPreferenceController
        extends VibrationIntensityPreferenceController {
@@ -46,6 +48,7 @@ public class MediaVibrationIntensityPreferenceController

    @Override
    public int getAvailabilityStatus() {
        return AVAILABLE;
        return mContext.getResources().getBoolean(R.bool.config_media_vibration_supported) ?
                AVAILABLE : UNSUPPORTED_ON_DEVICE;
    }
}
+3 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.settings.accessibility;
import android.content.Context;

import com.android.settings.accessibility.MediaVibrationIntensityPreferenceController.MediaVibrationPreferenceConfig;
import com.android.settings.R;

/** Preference controller for alarm vibration with only a toggle for on/off states. */
public class MediaVibrationTogglePreferenceController extends VibrationTogglePreferenceController {
@@ -29,6 +30,7 @@ public class MediaVibrationTogglePreferenceController extends VibrationTogglePre

    @Override
    public int getAvailabilityStatus() {
        return AVAILABLE;
        return mContext.getResources().getBoolean(R.bool.config_media_vibration_supported) ?
                AVAILABLE : UNSUPPORTED_ON_DEVICE;
    }
}
+35 −1
Original line number Diff line number Diff line
@@ -31,10 +31,13 @@ import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider;

import com.android.settings.core.BasePreferenceController;
import com.android.settings.R;
import com.android.settings.testutils.shadow.ShadowInteractionJankMonitor;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settings.widget.SeekBarPreference;
import com.android.settingslib.core.lifecycle.Lifecycle;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -45,7 +48,7 @@ import org.robolectric.annotation.Config;

/** Test for {@link MediaVibrationIntensityPreferenceController}. */
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {ShadowInteractionJankMonitor.class})
@Config(shadows = {ShadowInteractionJankMonitor.class, SettingsShadowResources.class})
public class MediaVibrationIntensityPreferenceControllerTest {

    private static final String PREFERENCE_KEY = "preference_key";
@@ -76,6 +79,11 @@ public class MediaVibrationIntensityPreferenceControllerTest {
        mController.displayPreference(mScreen);
    }

    @After
    public void tearDown() {
        SettingsShadowResources.reset();
    }

    @Test
    public void verifyConstants() {
        assertThat(mController.getPreferenceKey()).isEqualTo(PREFERENCE_KEY);
@@ -156,6 +164,32 @@ public class MediaVibrationIntensityPreferenceControllerTest {
                .isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH);
    }

    @Test
    public void configForMediaVibration_enabled_shouldShowSlider() {
        SettingsShadowResources.overrideResource(R.bool.config_media_vibration_supported, true);
        mController.updateState(mPreference);

        final boolean mediaVibrationConfig = mContext.getResources()
                .getBoolean(R.bool.config_media_vibration_supported);

        assertThat(mediaVibrationConfig).isTrue();
        assertThat(mController.isAvailable()).isTrue();
        assertThat(mController.isSupported()).isTrue();
    }

    @Test
    public void configForMediaVibration_disabled_shouldHideSlider() {
        SettingsShadowResources.overrideResource(R.bool.config_media_vibration_supported, false);
        mController.updateState(mPreference);

        final boolean mediaVibrationConfig = mContext.getResources()
                .getBoolean(R.bool.config_media_vibration_supported);

        assertThat(mediaVibrationConfig).isFalse();
        assertThat(mController.isAvailable()).isFalse();
        assertThat(mController.isSupported()).isFalse();
    }

    private void updateSetting(String key, int value) {
        Settings.System.putInt(mContext.getContentResolver(), key, value);
    }
+36 −0
Original line number Diff line number Diff line
@@ -32,17 +32,22 @@ import androidx.preference.SwitchPreference;
import androidx.test.core.app.ApplicationProvider;

import com.android.settings.core.BasePreferenceController;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settings.R;
import com.android.settingslib.core.lifecycle.Lifecycle;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import org.robolectric.RobolectricTestRunner;

/** Test for {@link MediaVibrationIntensityPreferenceController}. */
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {SettingsShadowResources.class})
public class MediaVibrationTogglePreferenceControllerTest {

    private static final String PREFERENCE_KEY = "preference_key";
@@ -72,6 +77,11 @@ public class MediaVibrationTogglePreferenceControllerTest {
        mController.displayPreference(mScreen);
    }

    @After
    public void tearDown() {
        SettingsShadowResources.reset();
    }

    @Test
    public void verifyConstants() {
        assertThat(mController.getPreferenceKey()).isEqualTo(PREFERENCE_KEY);
@@ -144,6 +154,32 @@ public class MediaVibrationTogglePreferenceControllerTest {
                .isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
    }

    @Test
    public void configForMediaVibration_enabled_shouldShowToogle() {
        SettingsShadowResources.overrideResource(R.bool.config_media_vibration_supported, true);
        mController.updateState(mPreference);

        final boolean mediaVibrationConfig = mContext.getResources()
                .getBoolean(R.bool.config_media_vibration_supported);

        assertThat(mediaVibrationConfig).isTrue();
        assertThat(mController.isAvailable()).isTrue();
        assertThat(mController.isSupported()).isTrue();
    }

    @Test
    public void configForMediaVibration_disabled_shouldHideToggle() {
        SettingsShadowResources.overrideResource(R.bool.config_media_vibration_supported, false);
        mController.updateState(mPreference);

        final boolean mediaVibrationConfig = mContext.getResources()
                .getBoolean(R.bool.config_media_vibration_supported);

        assertThat(mediaVibrationConfig).isFalse();
        assertThat(mController.isAvailable()).isFalse();
        assertThat(mController.isSupported()).isFalse();
    }

    private void updateSetting(String key, int value) {
        Settings.System.putInt(mContext.getContentResolver(), key, value);
    }