Merge "Revert "Revert "Add sensitivity configuration to long press power dialog""" into sc-qpr1-dev am: 8351a9a504 am: 26f121b673 am: f04886df8b

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/15640673

Change-Id: I6a3effb0337fc1c43c29fc34992cf3b4504cb360
This commit is contained in:
Govinda Wasserman
2021-08-20 18:02:39 +00:00
committed by Automerger Merge Worker
12 changed files with 569 additions and 62 deletions

View File

@@ -16,6 +16,8 @@
package com.android.settings.gestures;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -24,9 +26,12 @@ import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
import com.android.internal.R;
import com.android.settings.widget.LabeledSeekBarPreference;
import org.junit.Before;
@@ -41,7 +46,9 @@ import org.robolectric.RuntimeEnvironment;
public class LabeledSeekBarPreferenceTest {
private Context mContext;
private PreferenceViewHolder mViewHolder;
private SeekBar mSeekBar;
private TextView mSummary;
private LabeledSeekBarPreference mSeekBarPreference;
@Mock
@@ -57,7 +64,9 @@ public class LabeledSeekBarPreferenceTest {
final View view =
inflater.inflate(mSeekBarPreference.getLayoutResource(),
new LinearLayout(mContext), false);
mSeekBar = view.findViewById(com.android.internal.R.id.seekbar);
mViewHolder = PreferenceViewHolder.createInstanceForTests(view);
mSeekBar = (SeekBar) mViewHolder.findViewById(R.id.seekbar);
mSummary = (TextView) mViewHolder.findViewById(R.id.summary);
}
@Test
@@ -69,4 +78,23 @@ public class LabeledSeekBarPreferenceTest {
verify(mListener, times(1)).onPreferenceChange(mSeekBarPreference, 2);
}
@Test
public void seekBarPreferenceSummarySet_returnsValue() {
final String summary = "this is a summary";
mSeekBarPreference.setSummary(summary);
mSeekBarPreference.onBindViewHolder(mViewHolder);
assertThat(mSeekBarPreference.getSummary()).isEqualTo(summary);
assertThat(mSummary.getText()).isEqualTo(summary);
}
@Test
public void seekBarPreferenceSummaryNull_hidesView() {
mSeekBarPreference.setSummary(null);
mSeekBarPreference.onBindViewHolder(mViewHolder);
assertThat(mSummary.getText()).isEqualTo("");
assertThat(mSummary.getVisibility()).isEqualTo(View.GONE);
}
}

View File

@@ -137,7 +137,7 @@ public class LongPressPowerButtonPreferenceControllerTest {
when(mResources.getInteger(
com.android.internal.R.integer.config_keyChordPowerVolumeUp))
.thenReturn(
LongPressPowerButtonPreferenceController.KEY_CHORD_POWER_VOLUME_UP_NO_ACTION);
LongPressPowerButtonPreferenceController.KEY_CHORD_POWER_VOLUME_UP_NO_ACTION);
verify(mController.mFooterHint).setVisible(false);
}
@@ -148,7 +148,7 @@ public class LongPressPowerButtonPreferenceControllerTest {
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.POWER_BUTTON_LONG_PRESS, -1)).isEqualTo(
LongPressPowerButtonPreferenceController.LONG_PRESS_POWER_ASSISTANT_VALUE);
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);
@@ -162,19 +162,19 @@ public class LongPressPowerButtonPreferenceControllerTest {
when(mResources.getInteger(
com.android.internal.R.integer.config_longPressOnPowerBehavior))
.thenReturn(
LongPressPowerButtonPreferenceController.LONG_PRESS_POWER_GLOBAL_ACTIONS);
PowerMenuSettingsUtils.LONG_PRESS_POWER_GLOBAL_ACTIONS);
mController.onPreferenceChange(null, false);
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.POWER_BUTTON_LONG_PRESS, -1)).isEqualTo(
LongPressPowerButtonPreferenceController.LONG_PRESS_POWER_GLOBAL_ACTIONS);
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));
R.string.power_menu_summary_long_press_for_assist_disabled_with_power_menu));
}
@Test
@@ -203,13 +203,13 @@ public class LongPressPowerButtonPreferenceControllerTest {
when(mResources.getInteger(
com.android.internal.R.integer.config_longPressOnPowerBehavior))
.thenReturn(
LongPressPowerButtonPreferenceController.LONG_PRESS_POWER_ASSISTANT_VALUE);
PowerMenuSettingsUtils.LONG_PRESS_POWER_ASSISTANT_VALUE);
mController.onPreferenceChange(null, false);
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.POWER_BUTTON_LONG_PRESS, -1)).isEqualTo(
LongPressPowerButtonPreferenceController.LONG_PRESS_POWER_GLOBAL_ACTIONS);
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);

View File

@@ -0,0 +1,143 @@
/*
* 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.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.provider.Settings;
import androidx.test.core.app.ApplicationProvider;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
public class LongPressPowerSensitivityPreferenceControllerTest {
private static final String KEY_LONG_PRESS_SENSITIVITY =
"gesture_power_menu_long_press_for_assist_sensitivity";
private static final int[] SENSITIVITY_VALUES = {250, 350, 500, 750, 850};
private Application mContext;
private Resources mResources;
private LongPressPowerSensitivityPreferenceController mController;
@Before
public void setUp() {
mContext = spy(ApplicationProvider.getApplicationContext());
mResources = mock(Resources.class);
when(mContext.getResources()).thenReturn(mResources);
when(mResources.getIntArray(
com.android.internal.R.array.config_longPressOnPowerDurationSettings))
.thenReturn(SENSITIVITY_VALUES);
mController = new LongPressPowerSensitivityPreferenceController(mContext,
KEY_LONG_PRESS_SENSITIVITY);
}
@Test
public void getSliderPosition_returnsDefaultValue() {
when(mResources.getInteger(
com.android.internal.R.integer.config_longPressOnPowerDurationMs))
.thenReturn(750);
assertThat(mController.getSliderPosition()).isEqualTo(3);
}
@Test
public void getSliderPosition_returnsSetValue() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.POWER_BUTTON_LONG_PRESS_DURATION_MS, 350);
assertThat(mController.getSliderPosition()).isEqualTo(1);
}
@Test
public void setSliderPosition_setsValue() {
mController.setSliderPosition(4);
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.POWER_BUTTON_LONG_PRESS_DURATION_MS, 0)).isEqualTo(850);
}
@Test
public void setSliderPositionOutOfBounds_returnsFalse() {
assertThat(mController.setSliderPosition(-1)).isFalse();
assertThat(mController.setSliderPosition(10)).isFalse();
}
@Test
public void getMin_isZero() {
assertThat(mController.getMin()).isEqualTo(0);
}
@Test
public void getMax_isEqualToLastValueIndex() {
assertThat(mController.getMax()).isEqualTo(4);
}
@Test
public void longPressForAssistEnabled_isAvailable() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.POWER_BUTTON_LONG_PRESS,
PowerMenuSettingsUtils.LONG_PRESS_POWER_ASSISTANT_VALUE);
assertThat(mController.getAvailabilityStatus()).isEqualTo(
LongPressPowerSensitivityPreferenceController.AVAILABLE);
}
@Test
public void longPressForAssistDisabled_isNotAvailableDueToDependentSetting() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.POWER_BUTTON_LONG_PRESS,
PowerMenuSettingsUtils.LONG_PRESS_POWER_NO_ACTION);
assertThat(mController.getAvailabilityStatus()).isEqualTo(
LongPressPowerSensitivityPreferenceController.DISABLED_DEPENDENT_SETTING);
}
@Test
public void sensitivityValuesAreNull_notAvailable() {
when(mResources.getIntArray(
com.android.internal.R.array.config_longPressOnPowerDurationSettings))
.thenReturn(null);
mController = new LongPressPowerSensitivityPreferenceController(mContext,
KEY_LONG_PRESS_SENSITIVITY);
assertThat(mController.getAvailabilityStatus()).isEqualTo(
LongPressPowerSensitivityPreferenceController.UNSUPPORTED_ON_DEVICE);
}
@Test
public void sensitivityValuesArrayTooShort_notAvailable() {
when(mResources.getIntArray(
com.android.internal.R.array.config_longPressOnPowerDurationSettings))
.thenReturn(new int[]{200});
mController = new LongPressPowerSensitivityPreferenceController(mContext,
KEY_LONG_PRESS_SENSITIVITY);
assertThat(mController.getAvailabilityStatus()).isEqualTo(
LongPressPowerSensitivityPreferenceController.UNSUPPORTED_ON_DEVICE);
}
}

View File

@@ -0,0 +1,91 @@
/*
* 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.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.res.Resources;
import android.provider.Settings;
import androidx.test.core.app.ApplicationProvider;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
public class PowerMenuSettingsUtilsTest {
private Context mContext;
private Resources mResources;
@Before
public void setUp() {
mContext = spy(ApplicationProvider.getApplicationContext());
mResources = mock(Resources.class);
when(mContext.getResources()).thenReturn(mResources);
}
@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);
}
@Test
public void longPressBehaviourValueNotPresent_returnsDefault() {
when(mResources.getInteger(
com.android.internal.R.integer.config_longPressOnPowerBehavior))
.thenReturn(2);
assertThat(PowerMenuSettingsUtils.getPowerButtonSettingValue(mContext)).isEqualTo(2);
}
@Test
public void longPressBehaviourValueSetToAssistant_isAssistEnabledReturnsTrue() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.POWER_BUTTON_LONG_PRESS, 5);
assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistEnabled(mContext)).isTrue();
}
@Test
public void longPressBehaviourValueNotSetToAssistant_isAssistEnabledReturnsFalse() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.POWER_BUTTON_LONG_PRESS, 3);
assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistEnabled(mContext)).isFalse();
}
@Test
public void longPressBehaviourDefaultSetToAssistant_isAssistEnabledReturnsFalse() {
when(mResources.getInteger(
com.android.internal.R.integer.config_longPressOnPowerBehavior))
.thenReturn(3);
assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistEnabled(mContext)).isFalse();
}
}