Merge "Improve the UI of Press & hold power button settings" into tm-qpr-dev
This commit is contained in:
@@ -1,220 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.gestures;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.res.Resources;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class LongPressPowerButtonPreferenceControllerTest {
|
||||
|
||||
private static final String KEY_LONG_PRESS_POWER_BUTTON =
|
||||
"gesture_power_menu_long_press_for_assist";
|
||||
|
||||
private Application mContext;
|
||||
private Resources mResources;
|
||||
private LongPressPowerButtonPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
mResources = mock(Resources.class);
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
when(mResources.getString(anyInt())).thenAnswer((Answer<String>) invocation -> {
|
||||
int id = invocation.getArgument(0);
|
||||
return getString(id);
|
||||
});
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
|
||||
.thenReturn(true);
|
||||
mController = new LongPressPowerButtonPreferenceController(mContext,
|
||||
KEY_LONG_PRESS_POWER_BUTTON);
|
||||
mController.mAssistSwitch = mock(Preference.class);
|
||||
mController.mFooterHint = mock(Preference.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_configIsTrue_shouldReturnTrue() {
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
|
||||
.thenReturn(true);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_configIsFalse_shouldReturnFalse() {
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
|
||||
.thenReturn(false);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preferenceChecked_powerMenuHintTextShown() {
|
||||
mController.onPreferenceChange(null, true);
|
||||
|
||||
verify(mController.mFooterHint).setSummary(
|
||||
getString(
|
||||
R.string.power_menu_power_volume_up_hint));
|
||||
verify(mController.mFooterHint).setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void preferenceUnchecked_keyChordEnabled_powerMenuHintTextShown() {
|
||||
when(mResources.getInteger(
|
||||
com.android.internal.R.integer.config_keyChordPowerVolumeUp))
|
||||
.thenReturn(
|
||||
LongPressPowerButtonPreferenceController.KEY_CHORD_POWER_VOLUME_UP_GLOBAL_ACTIONS);
|
||||
|
||||
mController.onPreferenceChange(null, false);
|
||||
|
||||
verify(mController.mFooterHint).setSummary(
|
||||
getString(
|
||||
R.string.power_menu_power_volume_up_hint));
|
||||
verify(mController.mFooterHint).setVisible(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preferenceChecked_hushGestureEnabled_powerMenuHintTextIncludesHushHint() {
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool.config_volumeHushGestureEnabled))
|
||||
.thenReturn(true);
|
||||
|
||||
mController.onPreferenceChange(null, true);
|
||||
|
||||
verify(mController.mFooterHint).setSummary(
|
||||
getString(
|
||||
R.string.power_menu_power_volume_up_hint) + "\n\n"
|
||||
+ getString(
|
||||
R.string.power_menu_power_prevent_ringing_hint));
|
||||
verify(mController.mFooterHint).setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void preferenceUnchecked_keyChordDisabled_powerMenuHintTextHidden() {
|
||||
mController.onPreferenceChange(null, false);
|
||||
when(mResources.getInteger(
|
||||
com.android.internal.R.integer.config_keyChordPowerVolumeUp))
|
||||
.thenReturn(
|
||||
LongPressPowerButtonPreferenceController.KEY_CHORD_POWER_VOLUME_UP_NO_ACTION);
|
||||
|
||||
verify(mController.mFooterHint).setVisible(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preferenceChecked_longPressPowerSettingSetToAssistant() {
|
||||
mController.onPreferenceChange(null, true);
|
||||
|
||||
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.POWER_BUTTON_LONG_PRESS, -1)).isEqualTo(
|
||||
PowerMenuSettingsUtils.LONG_PRESS_POWER_ASSISTANT_VALUE);
|
||||
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.KEY_CHORD_POWER_VOLUME_UP, -1)).isEqualTo(
|
||||
LongPressPowerButtonPreferenceController.KEY_CHORD_POWER_VOLUME_UP_GLOBAL_ACTIONS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preferenceUnchecked_longPressPowerSettingSetToDefaultValue() {
|
||||
when(mResources.getInteger(
|
||||
com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||
.thenReturn(
|
||||
PowerMenuSettingsUtils.LONG_PRESS_POWER_GLOBAL_ACTIONS);
|
||||
|
||||
mController.onPreferenceChange(null, false);
|
||||
|
||||
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.POWER_BUTTON_LONG_PRESS, -1)).isEqualTo(
|
||||
PowerMenuSettingsUtils.LONG_PRESS_POWER_GLOBAL_ACTIONS);
|
||||
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.KEY_CHORD_POWER_VOLUME_UP, -1)).isEqualTo(
|
||||
LongPressPowerButtonPreferenceController.KEY_CHORD_POWER_VOLUME_UP_NO_ACTION);
|
||||
verify(mController.mAssistSwitch).setSummary(
|
||||
getString(
|
||||
R.string.power_menu_summary_long_press_for_assist_disabled_with_power_menu));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preferenceUnchecked_muteChordDefault_longPressPowerSettingSetToDefaultValue() {
|
||||
// Value out of range chosen deliberately.
|
||||
when(mResources.getInteger(
|
||||
com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||
.thenReturn(8);
|
||||
when(mResources.getInteger(
|
||||
com.android.internal.R.integer.config_keyChordPowerVolumeUp))
|
||||
.thenReturn(
|
||||
LongPressPowerButtonPreferenceController.KEY_CHORD_POWER_VOLUME_UP_MUTE_TOGGLE);
|
||||
|
||||
mController.onPreferenceChange(null, false);
|
||||
|
||||
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.POWER_BUTTON_LONG_PRESS, -1)).isEqualTo(8);
|
||||
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.KEY_CHORD_POWER_VOLUME_UP, -1)).isEqualTo(
|
||||
LongPressPowerButtonPreferenceController.KEY_CHORD_POWER_VOLUME_UP_MUTE_TOGGLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preferenceUnchecked_assistDefault_setNoAction() {
|
||||
// Ensure that the Assistant is the default behavior for LPP.
|
||||
when(mResources.getInteger(
|
||||
com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||
.thenReturn(
|
||||
PowerMenuSettingsUtils.LONG_PRESS_POWER_ASSISTANT_VALUE);
|
||||
|
||||
mController.onPreferenceChange(null, false);
|
||||
|
||||
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.POWER_BUTTON_LONG_PRESS, -1)).isEqualTo(
|
||||
PowerMenuSettingsUtils.LONG_PRESS_POWER_GLOBAL_ACTIONS);
|
||||
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.KEY_CHORD_POWER_VOLUME_UP, -1)).isEqualTo(
|
||||
LongPressPowerButtonPreferenceController.KEY_CHORD_POWER_VOLUME_UP_NO_ACTION);
|
||||
verify(mController.mAssistSwitch).setSummary(getString(
|
||||
R.string.power_menu_summary_long_press_for_assist_disabled_with_power_menu));
|
||||
}
|
||||
|
||||
private String getString(@StringRes int id) {
|
||||
return ApplicationProvider.getApplicationContext().getString(id);
|
||||
}
|
||||
}
|
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.gestures;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.res.Resources;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.widget.FooterPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class LongPressPowerFooterPreferenceControllerTest {
|
||||
|
||||
private Application mContext;
|
||||
private Resources mResources;
|
||||
private Preference mPreference;
|
||||
private LongPressPowerFooterPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
mResources = spy(mContext.getResources());
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
mPreference = new FooterPreference(mContext);
|
||||
mController = new LongPressPowerFooterPreferenceController(mContext, "test_key");
|
||||
|
||||
PreferenceScreen mScreen = mock(PreferenceScreen.class);
|
||||
when(mScreen.findPreference("test_key")).thenReturn(mPreference);
|
||||
mController.displayPreference(mScreen);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_longPressPowerForPowerMenu_hidesPreference() {
|
||||
PowerMenuSettingsUtils.setLongPressPowerForPowerMenu(mContext);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isVisible()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_longPressPowerForAssistant_showsPreference() {
|
||||
PowerMenuSettingsUtils.setLongPressPowerForAssistant(mContext);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isVisible()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_notEligible_showsPreference() {
|
||||
PowerMenuSettingsUtils.setLongPressPowerForAssistant(mContext);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isVisible()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_hushGestureEnabled_includesPreventRingingHint() {
|
||||
when(mResources.getBoolean(com.android.internal.R.bool.config_volumeHushGestureEnabled))
|
||||
.thenReturn(true);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.getSummary().toString())
|
||||
.isEqualTo(
|
||||
TextUtils.concat(
|
||||
mContext.getString(R.string.power_menu_power_volume_up_hint),
|
||||
"\n\n",
|
||||
mContext.getString(
|
||||
R.string.power_menu_power_prevent_ringing_hint)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_hushGestureDisabled_doesNotIncludePreventRingingHint() {
|
||||
when(mResources.getBoolean(com.android.internal.R.bool.config_volumeHushGestureEnabled))
|
||||
.thenReturn(false);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.getSummary().toString())
|
||||
.isEqualTo(mContext.getString(R.string.power_menu_power_volume_up_hint));
|
||||
}
|
||||
}
|
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.gestures;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.res.Resources;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.widget.SelectorWithWidgetPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class LongPressPowerForAssistantPreferenceControllerTest {
|
||||
|
||||
private Application mContext;
|
||||
private Resources mResources;
|
||||
private SelectorWithWidgetPreference mPreference;
|
||||
private LongPressPowerForAssistantPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
mResources = spy(mContext.getResources());
|
||||
mPreference = new SelectorWithWidgetPreference(mContext);
|
||||
mController = new LongPressPowerForAssistantPreferenceController(mContext, "test_key");
|
||||
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool
|
||||
.config_longPressOnPowerForAssistantSettingAvailable))
|
||||
.thenReturn(true);
|
||||
when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||
.thenReturn(5); // Default to Assistant
|
||||
|
||||
PreferenceScreen mScreen = mock(PreferenceScreen.class);
|
||||
when(mScreen.findPreference("test_key")).thenReturn(mPreference);
|
||||
mController.displayPreference(mScreen);
|
||||
mController.onStart();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initialState_longPressPowerForPowerMenu_preferenceNotChecked() {
|
||||
PowerMenuSettingsUtils.setLongPressPowerForPowerMenu(mContext);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initialState_longPressPowerForAssistant_preferenceChecked() {
|
||||
PowerMenuSettingsUtils.setLongPressPowerForAssistant(mContext);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_longPressPowerSettingAvailable_returnsAvailable() {
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_longPressPowerSettingNotAvailable_returnsNotAvailable() {
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool
|
||||
.config_longPressOnPowerForAssistantSettingAvailable))
|
||||
.thenReturn(false);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onClick_updatesSettingsValue_checksPreference() {
|
||||
// Initial state: preference not checked
|
||||
PowerMenuSettingsUtils.setLongPressPowerForPowerMenu(mContext);
|
||||
mController.updateState(mPreference);
|
||||
assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext)).isFalse();
|
||||
assertThat(mPreference.isChecked()).isFalse();
|
||||
|
||||
mPreference.performClick();
|
||||
|
||||
assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext)).isTrue();
|
||||
assertThat(mPreference.isChecked()).isTrue();
|
||||
}
|
||||
}
|
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.gestures;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.res.Resources;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.widget.SelectorWithWidgetPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class LongPressPowerForPowerMenuPreferenceControllerTest {
|
||||
|
||||
private Application mContext;
|
||||
private Resources mResources;
|
||||
private SelectorWithWidgetPreference mPreference;
|
||||
private LongPressPowerForPowerMenuPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
mResources = spy(mContext.getResources());
|
||||
mPreference = new SelectorWithWidgetPreference(mContext);
|
||||
mController = new LongPressPowerForPowerMenuPreferenceController(mContext, "test_key");
|
||||
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool
|
||||
.config_longPressOnPowerForAssistantSettingAvailable))
|
||||
.thenReturn(true);
|
||||
when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||
.thenReturn(5); // Default to Assistant
|
||||
|
||||
PreferenceScreen mScreen = mock(PreferenceScreen.class);
|
||||
when(mScreen.findPreference("test_key")).thenReturn(mPreference);
|
||||
mController.displayPreference(mScreen);
|
||||
mController.onStart();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initialState_longPressPowerForPowerMenu_preferenceChecked() {
|
||||
PowerMenuSettingsUtils.setLongPressPowerForPowerMenu(mContext);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initialState_longPressPowerForAssistant_preferenceNotChecked() {
|
||||
PowerMenuSettingsUtils.setLongPressPowerForAssistant(mContext);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_longPressPowerSettingAvailable_returnsAvailable() {
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_longPressPowerSettingNotAvailable_returnsNotAvailable() {
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool
|
||||
.config_longPressOnPowerForAssistantSettingAvailable))
|
||||
.thenReturn(false);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onClick_updatesSettingsValue_checksPreference() {
|
||||
// Initial state: preference not checked
|
||||
PowerMenuSettingsUtils.setLongPressPowerForAssistant(mContext);
|
||||
mController.updateState(mPreference);
|
||||
assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext)).isTrue();
|
||||
assertThat(mPreference.isChecked()).isFalse();
|
||||
|
||||
mPreference.performClick();
|
||||
|
||||
assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext)).isFalse();
|
||||
assertThat(mPreference.isChecked()).isTrue();
|
||||
}
|
||||
}
|
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.gestures;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.widget.IllustrationPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class LongPressPowerIllustrationPreferenceControllerTest {
|
||||
|
||||
private Application mContext;
|
||||
private IllustrationPreference mPreference;
|
||||
private LongPressPowerIllustrationPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = ApplicationProvider.getApplicationContext();
|
||||
mPreference = new IllustrationPreference(mContext);
|
||||
mController = new LongPressPowerIllustrationPreferenceController(mContext, "test_key");
|
||||
|
||||
PreferenceScreen mScreen = mock(PreferenceScreen.class);
|
||||
when(mScreen.findPreference("test_key")).thenReturn(mPreference);
|
||||
mController.displayPreference(mScreen);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_longPressPowerForPowerMenu_showsPowerMenuAnimation() {
|
||||
PowerMenuSettingsUtils.setLongPressPowerForPowerMenu(mContext);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.getLottieAnimationResId())
|
||||
.isEqualTo(R.raw.lottie_long_press_power_for_power_menu);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_longPressPowerForAssistant_showsAssistantAnimation() {
|
||||
PowerMenuSettingsUtils.setLongPressPowerForAssistant(mContext);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.getLottieAnimationResId())
|
||||
.isEqualTo(R.raw.lottie_long_press_power_for_assistant);
|
||||
}
|
||||
}
|
@@ -26,14 +26,20 @@ import android.app.Application;
|
||||
import android.content.res.Resources;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.widget.LabeledSeekBarPreference;
|
||||
import com.android.settingslib.testutils.shadow.ShadowInteractionJankMonitor;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowInteractionJankMonitor.class})
|
||||
public class LongPressPowerSensitivityPreferenceControllerTest {
|
||||
|
||||
private static final String KEY_LONG_PRESS_SENSITIVITY =
|
||||
@@ -43,7 +49,9 @@ public class LongPressPowerSensitivityPreferenceControllerTest {
|
||||
|
||||
private Application mContext;
|
||||
private Resources mResources;
|
||||
private LabeledSeekBarPreference mPreference;
|
||||
private LongPressPowerSensitivityPreferenceController mController;
|
||||
private PreferenceScreen mScreen;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -52,11 +60,22 @@ public class LongPressPowerSensitivityPreferenceControllerTest {
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
|
||||
when(mResources.getIntArray(
|
||||
com.android.internal.R.array.config_longPressOnPowerDurationSettings))
|
||||
com.android.internal.R.array.config_longPressOnPowerDurationSettings))
|
||||
.thenReturn(SENSITIVITY_VALUES);
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool
|
||||
.config_longPressOnPowerForAssistantSettingAvailable))
|
||||
.thenReturn(true);
|
||||
when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||
.thenReturn(5); // Default to Assistant
|
||||
|
||||
mPreference = new LabeledSeekBarPreference(mContext, null);
|
||||
mController = new LongPressPowerSensitivityPreferenceController(mContext,
|
||||
KEY_LONG_PRESS_SENSITIVITY);
|
||||
|
||||
mScreen = mock(PreferenceScreen.class);
|
||||
when(mScreen.findPreference(KEY_LONG_PRESS_SENSITIVITY)).thenReturn(mPreference);
|
||||
mController.displayPreference(mScreen);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -98,46 +117,64 @@ public class LongPressPowerSensitivityPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void longPressForAssistEnabled_isAvailable() {
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.POWER_BUTTON_LONG_PRESS,
|
||||
PowerMenuSettingsUtils.LONG_PRESS_POWER_ASSISTANT_VALUE);
|
||||
public void longPressForAssistant_isVisible() {
|
||||
PowerMenuSettingsUtils.setLongPressPowerForAssistant(mContext);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
LongPressPowerSensitivityPreferenceController.AVAILABLE);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isVisible()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void longPressForAssistDisabled_isNotAvailableDueToDependentSetting() {
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.POWER_BUTTON_LONG_PRESS,
|
||||
PowerMenuSettingsUtils.LONG_PRESS_POWER_NO_ACTION);
|
||||
public void longPressForPowerMenu_isHidden() {
|
||||
PowerMenuSettingsUtils.setLongPressPowerForPowerMenu(mContext);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
LongPressPowerSensitivityPreferenceController.DISABLED_DEPENDENT_SETTING);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isVisible()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sensitivityValuesAreNull_notAvailable() {
|
||||
public void longPressPowerSettingNotAvailable_notAvailable_isHidden() {
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool
|
||||
.config_longPressOnPowerForAssistantSettingAvailable))
|
||||
.thenReturn(false);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(LongPressPowerSensitivityPreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||
assertThat(mPreference.isVisible()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sensitivityValuesAreNull_notAvailable_isHidden() {
|
||||
when(mResources.getIntArray(
|
||||
com.android.internal.R.array.config_longPressOnPowerDurationSettings))
|
||||
.thenReturn(null);
|
||||
mController = new LongPressPowerSensitivityPreferenceController(mContext,
|
||||
KEY_LONG_PRESS_SENSITIVITY);
|
||||
mController.displayPreference(mScreen);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
LongPressPowerSensitivityPreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||
assertThat(mPreference.isVisible()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sensitivityValuesArrayTooShort_notAvailable() {
|
||||
public void sensitivityValuesArrayTooShort_notAvailable_isHidden() {
|
||||
when(mResources.getIntArray(
|
||||
com.android.internal.R.array.config_longPressOnPowerDurationSettings))
|
||||
.thenReturn(new int[]{200});
|
||||
mController = new LongPressPowerSensitivityPreferenceController(mContext,
|
||||
KEY_LONG_PRESS_SENSITIVITY);
|
||||
mController.displayPreference(mScreen);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
LongPressPowerSensitivityPreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||
assertThat(mPreference.isVisible()).isFalse();
|
||||
}
|
||||
}
|
||||
|
@@ -18,20 +18,21 @@ package com.android.settings.gestures;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class PowerMenuPreferenceControllerTest {
|
||||
@@ -41,35 +42,75 @@ public class PowerMenuPreferenceControllerTest {
|
||||
|
||||
private static final String KEY_GESTURE_POWER_MENU = "gesture_power_menu";
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mResources = mock(Resources.class);
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
|
||||
.thenReturn(true);
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
mResources = spy(mContext.getResources());
|
||||
mController = new PowerMenuPreferenceController(mContext, KEY_GESTURE_POWER_MENU);
|
||||
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool
|
||||
.config_longPressOnPowerForAssistantSettingAvailable))
|
||||
.thenReturn(true);
|
||||
when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||
.thenReturn(1); // Default to power menu
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_assistAvailable_available() {
|
||||
public void getAvailabilityStatus_settingsAvailable_returnsAvailable() {
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
|
||||
.thenReturn(true);
|
||||
com.android.internal.R.bool
|
||||
.config_longPressOnPowerForAssistantSettingAvailable))
|
||||
.thenReturn(true);
|
||||
when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||
.thenReturn(1); // Default to power menu
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.AVAILABLE);
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_assistUnavailable_unavailable() {
|
||||
public void getAvailabilityStatus_settingsNotAvailable_returnsNotAvailable() {
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
|
||||
.thenReturn(false);
|
||||
com.android.internal.R.bool
|
||||
.config_longPressOnPowerForAssistantSettingAvailable))
|
||||
.thenReturn(false);
|
||||
when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||
.thenReturn(1); // Default to power menu
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_longPressPowerSettingNotAvailable_returnsNotAvailable() {
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool
|
||||
.config_longPressOnPowerForAssistantSettingAvailable))
|
||||
.thenReturn(true);
|
||||
when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||
.thenReturn(3); // Default to power off (unsupported setup)
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_longPressPowerToAssistant_returnsNotAvailable() {
|
||||
PowerMenuSettingsUtils.setLongPressPowerForAssistant(mContext);
|
||||
|
||||
assertThat(mController.getSummary().toString())
|
||||
.isEqualTo(
|
||||
mContext.getString(R.string.power_menu_summary_long_press_for_assistant));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_longPressPowerToPowerMenu_returnsNotAvailable() {
|
||||
PowerMenuSettingsUtils.setLongPressPowerForPowerMenu(mContext);
|
||||
|
||||
assertThat(mController.getSummary().toString())
|
||||
.isEqualTo(
|
||||
mContext.getString(R.string.power_menu_summary_long_press_for_power_menu));
|
||||
}
|
||||
}
|
||||
|
@@ -44,48 +44,123 @@ public class PowerMenuSettingsUtilsTest {
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
mResources = mock(Resources.class);
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool
|
||||
.config_longPressOnPowerForAssistantSettingAvailable))
|
||||
.thenReturn(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void longPressBehaviourValuePresent_returnsValue() {
|
||||
when(mResources.getInteger(
|
||||
com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||
.thenReturn(0);
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.POWER_BUTTON_LONG_PRESS, 1);
|
||||
|
||||
assertThat(PowerMenuSettingsUtils.getPowerButtonSettingValue(mContext)).isEqualTo(1);
|
||||
public void isLongPressPowerForAssistantEnabled_valueSetToAssistant_returnsTrue() {
|
||||
Settings.Global.putInt(
|
||||
mContext.getContentResolver(), Settings.Global.POWER_BUTTON_LONG_PRESS, 5);
|
||||
assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void longPressBehaviourValueNotPresent_returnsDefault() {
|
||||
when(mResources.getInteger(
|
||||
com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||
.thenReturn(2);
|
||||
|
||||
assertThat(PowerMenuSettingsUtils.getPowerButtonSettingValue(mContext)).isEqualTo(2);
|
||||
public void isLongPressPowerForAssistantEnabled_valueNotSetToAssistant_returnsFalse() {
|
||||
Settings.Global.putInt(
|
||||
mContext.getContentResolver(), Settings.Global.POWER_BUTTON_LONG_PRESS, 3);
|
||||
assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void longPressBehaviourValueSetToAssistant_isAssistEnabledReturnsTrue() {
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.POWER_BUTTON_LONG_PRESS, 5);
|
||||
assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistEnabled(mContext)).isTrue();
|
||||
public void isLongPressPowerForAssistantEnabled_valueNotSet_defaultToAssistant_returnsTrue() {
|
||||
when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||
.thenReturn(5);
|
||||
|
||||
assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void longPressBehaviourValueNotSetToAssistant_isAssistEnabledReturnsFalse() {
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.POWER_BUTTON_LONG_PRESS, 3);
|
||||
assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistEnabled(mContext)).isFalse();
|
||||
public void isLongPressPowerForAssistantEnabled_valueNotSet_defaultToPowerMenu_returnsFalse() {
|
||||
when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||
.thenReturn(1);
|
||||
|
||||
assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void longPressBehaviourDefaultSetToAssistant_isAssistEnabledReturnsFalse() {
|
||||
when(mResources.getInteger(
|
||||
com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||
public void isLongPressPowerSettingAvailable_defaultToAssistant_returnsTrue() {
|
||||
when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||
.thenReturn(5);
|
||||
assertThat(PowerMenuSettingsUtils.isLongPressPowerSettingAvailable(mContext)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isLongPressPowerSettingAvailable_defaultToPowerMenu_returnsTrue() {
|
||||
when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||
.thenReturn(1);
|
||||
assertThat(PowerMenuSettingsUtils.isLongPressPowerSettingAvailable(mContext)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isLongPressPowerSettingAvailable_defaultToPowerOff_returnsFalse() {
|
||||
// Power off is the unsupported option in long press power settings
|
||||
when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||
.thenReturn(3);
|
||||
assertThat(PowerMenuSettingsUtils.isLongPressPowerSettingAvailable(mContext)).isFalse();
|
||||
}
|
||||
|
||||
assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistEnabled(mContext)).isFalse();
|
||||
@Test
|
||||
public void isLongPressPowerSettingAvailable_settingDisabled_returnsFalse() {
|
||||
// Disable the setting
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool
|
||||
.config_longPressOnPowerForAssistantSettingAvailable))
|
||||
.thenReturn(false);
|
||||
when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||
.thenReturn(1);
|
||||
|
||||
assertThat(PowerMenuSettingsUtils.isLongPressPowerSettingAvailable(mContext)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setLongPressPowerForAssistant_updatesValue() throws Exception {
|
||||
boolean result = PowerMenuSettingsUtils.setLongPressPowerForAssistant(mContext);
|
||||
|
||||
assertThat(result).isTrue();
|
||||
assertThat(
|
||||
Settings.Global.getInt(
|
||||
mContext.getContentResolver(),
|
||||
Settings.Global.POWER_BUTTON_LONG_PRESS))
|
||||
.isEqualTo(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setLongPressPowerForAssistant_updatesKeyChordValueToPowerMenu() throws Exception {
|
||||
PowerMenuSettingsUtils.setLongPressPowerForAssistant(mContext);
|
||||
assertThat(
|
||||
Settings.Global.getInt(
|
||||
mContext.getContentResolver(),
|
||||
Settings.Global.KEY_CHORD_POWER_VOLUME_UP))
|
||||
.isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setLongPressPowerForPowerMenu_updatesValue() throws Exception {
|
||||
boolean result = PowerMenuSettingsUtils.setLongPressPowerForPowerMenu(mContext);
|
||||
|
||||
assertThat(result).isTrue();
|
||||
assertThat(
|
||||
Settings.Global.getInt(
|
||||
mContext.getContentResolver(),
|
||||
Settings.Global.POWER_BUTTON_LONG_PRESS))
|
||||
.isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setLongPressPowerForPowerMenu_updatesKeyChordValueToDefault() throws Exception {
|
||||
when(mResources.getInteger(com.android.internal.R.integer.config_keyChordPowerVolumeUp))
|
||||
.thenReturn(1);
|
||||
|
||||
PowerMenuSettingsUtils.setLongPressPowerForPowerMenu(mContext);
|
||||
|
||||
assertThat(
|
||||
Settings.Global.getInt(
|
||||
mContext.getContentResolver(),
|
||||
Settings.Global.KEY_CHORD_POWER_VOLUME_UP))
|
||||
.isEqualTo(1);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user