Merge sc-qpr1-dev-plus-aosp-without-vendor@7810918
Bug: 205056467 Merged-In: I9ac05f5da437030e1b5db082ddaf7959f82acccd Change-Id: Iaf8ebc4877a8276672354b45db0dd502c0f71bd3
This commit is contained in:
@@ -183,7 +183,7 @@ public class UsbDefaultFragmentTest {
|
||||
|
||||
@Test
|
||||
public void onTetheringStarted_currentFunctionsIsRndis_setsRndisAsDefaultUsbFunctions() {
|
||||
mFragment.mCurrentFunctions = UsbManager.FUNCTION_RNDIS;
|
||||
when(mUsbBackend.getCurrentFunctions()).thenReturn(UsbManager.FUNCTION_RNDIS);
|
||||
|
||||
mFragment.mOnStartTetheringCallback.onTetheringStarted();
|
||||
|
||||
@@ -192,7 +192,7 @@ public class UsbDefaultFragmentTest {
|
||||
|
||||
@Test
|
||||
public void onTetheringStarted_currentFunctionsIsNcm_setsNcmAsDefaultUsbFunctions() {
|
||||
mFragment.mCurrentFunctions = UsbManager.FUNCTION_NCM;
|
||||
when(mUsbBackend.getCurrentFunctions()).thenReturn(UsbManager.FUNCTION_NCM);
|
||||
|
||||
mFragment.mOnStartTetheringCallback.onTetheringStarted();
|
||||
|
||||
|
||||
@@ -152,7 +152,8 @@ public class BrightnessLevelPreferenceControllerTest {
|
||||
System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
|
||||
|
||||
when(mDisplay.getBrightnessInfo()).thenReturn(
|
||||
new BrightnessInfo(0.1f, 0.0f, 1.0f, BrightnessInfo.HIGH_BRIGHTNESS_MODE_OFF));
|
||||
new BrightnessInfo(0.1f, 0.0f, 1.0f, BrightnessInfo.HIGH_BRIGHTNESS_MODE_OFF,
|
||||
0.5f));
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
@@ -166,7 +167,8 @@ public class BrightnessLevelPreferenceControllerTest {
|
||||
System.SCREEN_BRIGHTNESS_MODE_MANUAL);
|
||||
|
||||
when(mDisplay.getBrightnessInfo()).thenReturn(
|
||||
new BrightnessInfo(0.5f, 0.0f, 1.0f, BrightnessInfo.HIGH_BRIGHTNESS_MODE_OFF));
|
||||
new BrightnessInfo(0.5f, 0.0f, 1.0f, BrightnessInfo.HIGH_BRIGHTNESS_MODE_OFF,
|
||||
0.5f));
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
|
||||
@@ -50,7 +50,6 @@ import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
@@ -65,7 +64,6 @@ import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public final class BatteryChartPreferenceControllerTest {
|
||||
@@ -125,37 +123,6 @@ public final class BatteryChartPreferenceControllerTest {
|
||||
createBatteryHistoryMap());
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testOnResume_uiModeIsChanged_clearBatteryDiffEntryCache() {
|
||||
doReturn(mResources).when(mContext).getResources();
|
||||
doReturn(mConfiguration).when(mResources).getConfiguration();
|
||||
mConfiguration.uiMode = Configuration.UI_MODE_NIGHT_UNDEFINED;
|
||||
// Ensures the testing environment is correct.
|
||||
assertThat(BatteryDiffEntry.sResourceCache).hasSize(1);
|
||||
mBatteryChartPreferenceController.onResume();
|
||||
// Changes the uiMode in the configuration.
|
||||
mConfiguration.uiMode = Configuration.UI_MODE_NIGHT_YES;
|
||||
|
||||
mBatteryChartPreferenceController.onResume();
|
||||
assertThat(BatteryDiffEntry.sResourceCache).isEmpty();
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testOnResume_uiModeIsNotChanged_notClearBatteryDiffEntryCache() {
|
||||
doReturn(mResources).when(mContext).getResources();
|
||||
doReturn(mConfiguration).when(mResources).getConfiguration();
|
||||
mConfiguration.uiMode = Configuration.UI_MODE_NIGHT_UNDEFINED;
|
||||
// Ensures the testing environment is correct.
|
||||
assertThat(BatteryDiffEntry.sResourceCache).hasSize(1);
|
||||
|
||||
mBatteryChartPreferenceController.onResume();
|
||||
assertThat(BatteryDiffEntry.sResourceCache).isNotEmpty();
|
||||
verify(mMetricsFeatureProvider)
|
||||
.action(mContext, SettingsEnums.OPEN_BATTERY_USAGE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnDestroy_activityIsChanging_clearBatteryEntryCache() {
|
||||
doReturn(true).when(mSettingsActivity).isChangingConfigurations();
|
||||
@@ -579,12 +546,12 @@ public final class BatteryChartPreferenceControllerTest {
|
||||
// Verifies the title in the preference group.
|
||||
verify(mBatteryChartPreferenceController.mAppListPrefGroup)
|
||||
.setTitle(captor.capture());
|
||||
assertThat(captor.getValue()).isEqualTo("App usage for 4 - 7");
|
||||
assertThat(captor.getValue()).isNotEqualTo("App usage for past 24 hr");
|
||||
// Verifies the title in the expandable divider.
|
||||
captor = ArgumentCaptor.forClass(String.class);
|
||||
verify(mBatteryChartPreferenceController.mExpandDividerPreference)
|
||||
.setTitle(captor.capture());
|
||||
assertThat(captor.getValue()).isEqualTo("System usage for 4 - 7");
|
||||
assertThat(captor.getValue()).isNotEqualTo("System usage for past 24 hr");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -722,9 +689,6 @@ public final class BatteryChartPreferenceControllerTest {
|
||||
new long[] {1619196786769L, 0L, 1619247636826L};
|
||||
ConvertUtils.utcToLocalTimeHour(
|
||||
mContext, /*timestamp=*/ 0, /*is24HourFormat=*/ false);
|
||||
// Simulates the locale in GMT.
|
||||
ConvertUtils.sSimpleDateFormatForHour
|
||||
.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
}
|
||||
|
||||
private BatteryChartPreferenceController createController() {
|
||||
|
||||
@@ -33,7 +33,6 @@ import android.view.accessibility.AccessibilityManager;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
@@ -44,7 +43,6 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public final class BatteryChartViewTest {
|
||||
@@ -233,21 +231,4 @@ public final class BatteryChartViewTest {
|
||||
verify(mBatteryChartView.mHandler)
|
||||
.postDelayed(mBatteryChartView.mUpdateClickableStateRun, 500L);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testSetLatestTimestamp_generateExpectedTimestamps() {
|
||||
final long timestamp = 1619196786769L;
|
||||
ConvertUtils.sSimpleDateFormatForHour = null;
|
||||
// Invokes the method first to create the SimpleDateFormat.
|
||||
ConvertUtils.utcToLocalTimeHour(
|
||||
mContext, /*timestamp=*/ 0, /*is24HourFormat=*/ false);
|
||||
ConvertUtils.sSimpleDateFormatForHour
|
||||
.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
|
||||
final String[] expectedTimestamps = new String[] {"00", "06", "12", "18", "00"};
|
||||
|
||||
mBatteryChartView.setLatestTimestamp(timestamp);
|
||||
|
||||
assertThat(mBatteryChartView.mTimestamps).isEqualTo(expectedTimestamps);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ import android.os.UserHandle;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
@@ -320,71 +319,6 @@ public final class ConvertUtilsTest {
|
||||
.isEqualTo(entry.mConsumePower * ratio);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testUtcToLocalTime_returnExpectedResult() {
|
||||
ConvertUtils.sZoneId = null;
|
||||
ConvertUtils.sLocale = null;
|
||||
final long timestamp = 1619196786769L;
|
||||
final String expectedZoneId = "America/Los_Angeles";
|
||||
ConvertUtils.sSimpleDateFormat = null;
|
||||
// Invokes the method first to create the SimpleDateFormat.
|
||||
ConvertUtils.utcToLocalTime(mContext, /*timestamp=*/ 0);
|
||||
ConvertUtils.sSimpleDateFormat
|
||||
.setTimeZone(TimeZone.getTimeZone(expectedZoneId));
|
||||
mContext.getResources().getConfiguration().setLocales(
|
||||
new LocaleList(new Locale("en_US")));
|
||||
|
||||
assertThat(ConvertUtils.utcToLocalTime(mContext, timestamp))
|
||||
.isEqualTo("Apr 24,2021 00:53:06");
|
||||
assertThat(ConvertUtils.sZoneId).isNotEqualTo(expectedZoneId);
|
||||
assertThat(ConvertUtils.sLocale).isEqualTo(new Locale("en_US"));
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testUtcToLocalTimeHour_12HourFormat_returnExpectedResult() {
|
||||
ConvertUtils.sZoneIdForHour = null;
|
||||
ConvertUtils.sLocaleForHour = null;
|
||||
final long timestamp = 1619000086769L;
|
||||
final String expectedZoneId = "America/Los_Angeles";
|
||||
ConvertUtils.sSimpleDateFormatForHour = null;
|
||||
// Invokes the method first to create the SimpleDateFormat.
|
||||
ConvertUtils.utcToLocalTimeHour(
|
||||
mContext, /*timestamp=*/ 0, /*is24HourFormat=*/ false);
|
||||
ConvertUtils.sSimpleDateFormatForHour
|
||||
.setTimeZone(TimeZone.getTimeZone(expectedZoneId));
|
||||
mContext.getResources().getConfiguration().setLocales(
|
||||
new LocaleList(new Locale("en_US")));
|
||||
|
||||
assertThat(ConvertUtils.utcToLocalTimeHour(
|
||||
mContext, timestamp, /*is24HourFormat=*/ false)).isEqualTo("6");
|
||||
assertThat(ConvertUtils.sZoneIdForHour).isNotEqualTo(expectedZoneId);
|
||||
assertThat(ConvertUtils.sLocaleForHour).isEqualTo(new Locale("en_US"));
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testUtcToLocalTimeHour_24HourFormat_returnExpectedResult() {
|
||||
ConvertUtils.sZoneIdForHour = null;
|
||||
ConvertUtils.sLocaleForHour = null;
|
||||
final long timestamp = 1619000086769L;
|
||||
final String expectedZoneId = "America/Los_Angeles";
|
||||
ConvertUtils.sSimpleDateFormatForHour = null;
|
||||
// Invokes the method first to create the SimpleDateFormat.
|
||||
ConvertUtils.utcToLocalTimeHour(
|
||||
mContext, /*timestamp=*/ 0, /*is24HourFormat=*/ false);
|
||||
ConvertUtils.sSimpleDateFormatForHour
|
||||
.setTimeZone(TimeZone.getTimeZone(expectedZoneId));
|
||||
mContext.getResources().getConfiguration().setLocales(
|
||||
new LocaleList(new Locale("en_US")));
|
||||
|
||||
assertThat(ConvertUtils.utcToLocalTimeHour(
|
||||
mContext, timestamp, /*is24HourFormat=*/ true)).isEqualTo("18");
|
||||
assertThat(ConvertUtils.sZoneIdForHour).isNotEqualTo(expectedZoneId);
|
||||
assertThat(ConvertUtils.sLocaleForHour).isEqualTo(new Locale("en_US"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetIndexedUsageMap_hideBackgroundUsageTime_returnsExpectedResult() {
|
||||
final long[] batteryHistoryKeys = new long[] {101L, 102L, 103L};
|
||||
|
||||
@@ -155,4 +155,9 @@ public class PowerUsageFeatureProviderImplTest {
|
||||
|
||||
assertThat(mPowerFeatureProvider.isSmartBatterySupported()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetResumeChargeIntent_returnNull() {
|
||||
assertThat(mPowerFeatureProvider.getResumeChargeIntent()).isNull();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryDefenderTip;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.HighUsageTip;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip;
|
||||
@@ -74,6 +75,7 @@ public class BatteryTipDialogFragmentTest {
|
||||
private RestrictAppTip mRestrictTwoAppsTip;
|
||||
private UnrestrictAppTip mUnrestrictAppTip;
|
||||
private SummaryTip mSummaryTip;
|
||||
private BatteryDefenderTip mDefenderTip;
|
||||
private AppInfo mAppInfo;
|
||||
private ShadowPackageManager mPackageManager;
|
||||
|
||||
@@ -116,6 +118,7 @@ public class BatteryTipDialogFragmentTest {
|
||||
mUnrestrictAppTip = new UnrestrictAppTip(BatteryTip.StateType.NEW, mAppInfo);
|
||||
mSummaryTip = spy(new SummaryTip(BatteryTip.StateType.NEW,
|
||||
EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN));
|
||||
mDefenderTip = new BatteryDefenderTip(BatteryTip.StateType.NEW);
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -243,4 +246,20 @@ public class BatteryTipDialogFragmentTest {
|
||||
+ "your phone will suggest actions you can take.\n\nYou can always turn"
|
||||
+ " on Battery Saver if you’re running low on battery.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnCreateDialog_defenderTip_fireDialog() {
|
||||
mDialogFragment = BatteryTipDialogFragment.newInstance(mDefenderTip, METRICS_KEY);
|
||||
|
||||
FragmentController.setupFragment(mDialogFragment, FragmentActivity.class,
|
||||
0 /* containerViewId */, null /* bundle */);
|
||||
|
||||
final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||
ShadowAlertDialogCompat shadowDialog = ShadowAlertDialogCompat.shadowOf(dialog);
|
||||
|
||||
assertThat(shadowDialog.getTitle()).isEqualTo(
|
||||
mContext.getString(R.string.battery_tip_limited_temporarily_title));
|
||||
assertThat(shadowDialog.getMessage()).isEqualTo(
|
||||
mContext.getString(R.string.battery_tip_limited_temporarily_dialog_msg, "80%"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,70 +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.fuelgauge.batterytip.actions;
|
||||
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public final class BatteryDefenderActionTest {
|
||||
|
||||
private Context mContext;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
private BatteryDefenderAction mBatteryDefenderAction;
|
||||
private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
|
||||
@Mock private SettingsActivity mSettingsActivity;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
mMetricsFeatureProvider = mFeatureFactory.metricsFeatureProvider;
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
doReturn(mContext).when(mSettingsActivity).getApplicationContext();
|
||||
mBatteryDefenderAction = new BatteryDefenderAction(mSettingsActivity);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandlePositiveAction_logMetric() {
|
||||
final int metricKey = 10;
|
||||
mBatteryDefenderAction.handlePositiveAction(metricKey);
|
||||
|
||||
verify(mMetricsFeatureProvider).action(mContext,
|
||||
SettingsEnums.ACTION_TIP_BATTERY_DEFENDER, metricKey);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -199,23 +199,22 @@ public class LongPressPowerButtonPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void preferenceUnchecked_assistDefault_setNoAction() {
|
||||
// Value out of range chosen deliberately.
|
||||
// Ensure that the Assistant is the default behavior for LPP.
|
||||
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_NO_ACTION);
|
||||
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_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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -159,7 +159,7 @@ public class RenameMobileNetworkDialogFragmentTest {
|
||||
eq(SubscriptionManager.NAME_SOURCE_USER_INPUT));
|
||||
assertThat(captor.getValue()).isEqualTo("test2");
|
||||
verify(mSubscriptionMgr)
|
||||
.setIconTint(eq(Color.parseColor("#ff00796b" /* teal */)), eq(mSubscriptionId));
|
||||
.setIconTint(eq(Color.parseColor("#ff006D74" /* cyan */)), eq(mSubscriptionId));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -174,6 +174,34 @@ public class RenameMobileNetworkDialogFragmentTest {
|
||||
assertThat(view.findViewById(R.id.number_label).getVisibility()).isEqualTo(View.GONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void populateView_getPreviousSimColor_setCorrectSelection() {
|
||||
final View view = LayoutInflater.from(mActivity).inflate(
|
||||
R.layout.dialog_mobile_network_rename, null);
|
||||
when(mSubscriptionInfo.getIconTint())
|
||||
.thenReturn(Color.parseColor("#ff3367d6"/* blue700 */));
|
||||
|
||||
startDialog();
|
||||
mFragment.populateView(view);
|
||||
|
||||
final Spinner colorSpinnerView = mFragment.getColorSpinnerView();
|
||||
assertThat(colorSpinnerView.getSelectedItemPosition()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void populateView_getUpdatedSimColor_setCorrectSelection() {
|
||||
final View view = LayoutInflater.from(mActivity).inflate(
|
||||
R.layout.dialog_mobile_network_rename, null);
|
||||
when(mSubscriptionInfo.getIconTint())
|
||||
.thenReturn(Color.parseColor("#ff137333"/* Green800 */));
|
||||
|
||||
startDialog();
|
||||
mFragment.populateView(view);
|
||||
|
||||
final Spinner colorSpinnerView = mFragment.getColorSpinnerView();
|
||||
assertThat(colorSpinnerView.getSelectedItemPosition()).isEqualTo(2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to start the dialog
|
||||
*/
|
||||
|
||||
@@ -36,6 +36,7 @@ import android.content.pm.ShortcutInfo;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.text.SpannedString;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
@@ -338,4 +339,36 @@ public class RecentConversationsPreferenceControllerTest {
|
||||
// one for the preference, none for 'clear all'
|
||||
verify(outerContainer, times(1)).addPreference(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpans() {
|
||||
ShortcutInfo si = mock(ShortcutInfo.class);
|
||||
when(si.getLabel()).thenReturn(new SpannedString("hello"));
|
||||
ConversationChannel ccw = new ConversationChannel(si, 6,
|
||||
new NotificationChannel("hi", "hi", 4),
|
||||
null, 7,
|
||||
true /* hasactivenotifs */);
|
||||
ShortcutInfo si2 = mock(ShortcutInfo.class);
|
||||
when(si2.getLabel()).thenReturn("hello");
|
||||
ConversationChannel ccw2 = new ConversationChannel(si2, 6,
|
||||
new NotificationChannel("hi2", "hi2", 4),
|
||||
null, 7,
|
||||
true /* hasactivenotifs */);
|
||||
// no crash
|
||||
mController.mConversationComparator.compare(ccw, ccw2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullSpans() {
|
||||
ConversationChannel ccw = new ConversationChannel(mock(ShortcutInfo.class), 6,
|
||||
new NotificationChannel("hi", "hi", 4),
|
||||
null, 7,
|
||||
true /* hasactivenotifs */);
|
||||
ConversationChannel ccw2 = new ConversationChannel(mock(ShortcutInfo.class), 6,
|
||||
new NotificationChannel("hi2", "hi2", 4),
|
||||
null, 7,
|
||||
true /* hasactivenotifs */);
|
||||
// no crash
|
||||
mController.mConversationComparator.compare(ccw, ccw2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import static android.app.admin.DevicePolicyManager.PASSWORD_COMPLEXITY_MEDIUM;
|
||||
import static android.app.admin.DevicePolicyManager.PASSWORD_COMPLEXITY_NONE;
|
||||
import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC;
|
||||
import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_COMPLEX;
|
||||
import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_MANAGED;
|
||||
import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_NUMERIC;
|
||||
import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX;
|
||||
import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_SOMETHING;
|
||||
@@ -189,6 +190,16 @@ public class ChooseLockGenericControllerTest {
|
||||
assertThat(mController.isScreenLockEnabled(ScreenLockType.PASSWORD)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isScreenLockEnabled_QualityManaged() {
|
||||
setDevicePolicyPasswordQuality(PASSWORD_QUALITY_MANAGED);
|
||||
assertThat(mController.isScreenLockEnabled(ScreenLockType.NONE)).isFalse();
|
||||
assertThat(mController.isScreenLockEnabled(ScreenLockType.SWIPE)).isFalse();
|
||||
assertThat(mController.isScreenLockEnabled(ScreenLockType.PATTERN)).isFalse();
|
||||
assertThat(mController.isScreenLockEnabled(ScreenLockType.PIN)).isFalse();
|
||||
assertThat(mController.isScreenLockEnabled(ScreenLockType.PASSWORD)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isScreenLockEnabled_NoneComplexity() {
|
||||
when(mLockPatternUtils.getRequestedPasswordComplexity(anyInt(), anyBoolean()))
|
||||
@@ -353,6 +364,9 @@ public class ChooseLockGenericControllerTest {
|
||||
|
||||
when(mLockPatternUtils.getRequestedPasswordMetrics(anyInt(), anyBoolean()))
|
||||
.thenReturn(policy.getMinMetrics());
|
||||
|
||||
when(mLockPatternUtils.isCredentialsDisabledForUser(anyInt()))
|
||||
.thenReturn(quality == PASSWORD_QUALITY_MANAGED);
|
||||
}
|
||||
|
||||
private ChooseLockGenericController.Builder createBuilder() {
|
||||
|
||||
@@ -404,18 +404,6 @@ public class ChooseLockPasswordTest {
|
||||
"Must be fewer than 17 characters");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertThat_chooseLockIconChanged_WhenFingerprintExtraSet() {
|
||||
ShadowDrawable drawable = setActivityAndGetIconDrawable(true);
|
||||
assertThat(drawable.getCreatedFromResId()).isEqualTo(R.drawable.ic_fingerprint_header);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertThat_chooseLockIconNotChanged_WhenFingerprintExtraSet() {
|
||||
ShadowDrawable drawable = setActivityAndGetIconDrawable(false);
|
||||
assertThat(drawable.getCreatedFromResId()).isNotEqualTo(R.drawable.ic_fingerprint_header);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateComplexityMergedFromDpmOnCreate() {
|
||||
ShadowLockPatternUtils.setRequiredPasswordComplexity(PASSWORD_COMPLEXITY_LOW);
|
||||
|
||||
@@ -31,9 +31,6 @@ import com.android.settings.R;
|
||||
import com.android.settings.password.ChooseLockPattern.ChooseLockPatternFragment;
|
||||
import com.android.settings.password.ChooseLockPattern.IntentBuilder;
|
||||
import com.android.settings.testutils.shadow.ShadowUtils;
|
||||
import com.android.settingslib.testutils.DrawableTestHelper;
|
||||
|
||||
import com.google.android.setupdesign.GlifLayout;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -99,16 +96,6 @@ public class ChooseLockPatternTest {
|
||||
.isNotNull();
|
||||
}
|
||||
|
||||
@Config(qualifiers = "sw400dp")
|
||||
@Test
|
||||
public void fingerprintExtraSet_shouldDisplayFingerprintIcon() {
|
||||
ChooseLockPattern activity = createActivity(true);
|
||||
ChooseLockPatternFragment fragment = (ChooseLockPatternFragment)
|
||||
activity.getSupportFragmentManager().findFragmentById(R.id.main_content);
|
||||
DrawableTestHelper.assertDrawableResId(((GlifLayout) fragment.getView()).getIcon(),
|
||||
R.drawable.ic_fingerprint_header);
|
||||
}
|
||||
|
||||
@Config(qualifiers = "sw300dp")
|
||||
@Test
|
||||
public void smallScreens_shouldHideIcon() {
|
||||
|
||||
@@ -16,25 +16,12 @@
|
||||
|
||||
package com.android.settings.wifi;
|
||||
|
||||
import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
|
||||
import static android.Manifest.permission.ACCESS_FINE_LOCATION;
|
||||
|
||||
import static com.android.settings.wifi.WifiDialogActivity.REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER;
|
||||
import static com.android.settings.wifi.WifiDialogActivity.RESULT_CONNECTED;
|
||||
import static com.android.settings.wifi.WifiDialogActivity.RESULT_OK;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
|
||||
import androidx.lifecycle.Lifecycle.State;
|
||||
import androidx.test.core.app.ActivityScenario;
|
||||
@@ -44,7 +31,6 @@ import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
|
||||
import com.android.settings.testutils.shadow.ShadowConnectivityManager;
|
||||
import com.android.settings.testutils.shadow.ShadowNetworkDetailsTracker;
|
||||
import com.android.settings.testutils.shadow.ShadowWifiManager;
|
||||
import com.android.settingslib.wifi.AccessPoint;
|
||||
|
||||
import com.google.android.setupcompat.util.WizardManagerHelper;
|
||||
|
||||
@@ -69,25 +55,7 @@ import org.robolectric.util.ReflectionHelpers;
|
||||
})
|
||||
public class WifiDialogActivityTest {
|
||||
|
||||
private static final String CALLING_PACKAGE = "calling_package";
|
||||
private static final String AP1_SSID = "\"ap1\"";
|
||||
|
||||
@Mock
|
||||
PackageManager mPackageManager;
|
||||
@Mock
|
||||
WifiManager mWifiManager;
|
||||
@Mock
|
||||
WifiDialog mWifiDialog;
|
||||
@Mock
|
||||
WifiConfiguration mWifiConfiguration;
|
||||
@Mock
|
||||
AccessPoint mAccessPoint;
|
||||
@Mock
|
||||
WifiDialog2 mWifiDialog2;
|
||||
@Mock
|
||||
WifiConfigController2 mWifiConfiguration2;
|
||||
@Mock
|
||||
Intent mResultData;
|
||||
@Mock
|
||||
private WifiConfigController mController;
|
||||
@Mock
|
||||
@@ -98,10 +66,6 @@ public class WifiDialogActivityTest {
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mWifiDialog.getController()).thenReturn(mController);
|
||||
when(mController.getConfig()).thenReturn(mWifiConfiguration);
|
||||
when(mController.getAccessPoint()).thenReturn(mAccessPoint);
|
||||
when(mWifiDialog2.getController()).thenReturn(mWifiConfiguration2);
|
||||
|
||||
WifiConfiguration wifiConfig = new WifiConfiguration();
|
||||
wifiConfig.SSID = AP1_SSID;
|
||||
@@ -133,52 +97,6 @@ public class WifiDialogActivityTest {
|
||||
assertThat(ShadowWifiManager.get().savedWifiConfig.SSID).isEqualTo(AP1_SSID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onSubmit_noPermissionForResult_setResultWithoutData() {
|
||||
WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
|
||||
when(activity.hasPermissionForResult()).thenReturn(false);
|
||||
when(activity.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
|
||||
|
||||
activity.onSubmit(mWifiDialog);
|
||||
|
||||
verify(activity).setResult(RESULT_CONNECTED, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onSubmit_hasPermissionForResult_setResultWithData() {
|
||||
WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
|
||||
when(activity.hasPermissionForResult()).thenReturn(true);
|
||||
when(activity.createResultData(any(), any())).thenReturn(mResultData);
|
||||
when(activity.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
|
||||
|
||||
activity.onSubmit(mWifiDialog);
|
||||
|
||||
verify(activity).setResult(RESULT_CONNECTED, mResultData);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onSubmit2_noPermissionForResult_setResultWithoutData() {
|
||||
WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
|
||||
when(activity.hasPermissionForResult()).thenReturn(false);
|
||||
when(activity.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
|
||||
|
||||
activity.onSubmit(mWifiDialog2);
|
||||
|
||||
verify(activity).setResult(RESULT_CONNECTED, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onSubmit2_hasPermissionForResult_setResultWithData() {
|
||||
WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
|
||||
when(activity.hasPermissionForResult()).thenReturn(true);
|
||||
when(activity.createResultData(any(), any())).thenReturn(mResultData);
|
||||
when(activity.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
|
||||
|
||||
activity.onSubmit(mWifiDialog2);
|
||||
|
||||
verify(activity).setResult(RESULT_CONNECTED, mResultData);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void onSubmit2_whenConnectForCallerIsTrue_shouldConnectToNetwork() {
|
||||
@@ -260,97 +178,4 @@ public class WifiDialogActivityTest {
|
||||
assertThat(dialog.getContext().getThemeResId())
|
||||
.isEqualTo(R.style.SuwAlertDialogThemeCompat_Light);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onActivityResult_noPermissionForResult_setResultWithoutData() {
|
||||
WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
|
||||
when(activity.hasPermissionForResult()).thenReturn(false);
|
||||
final Intent data = new Intent();
|
||||
|
||||
activity.onActivityResult(REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER, RESULT_OK,
|
||||
data);
|
||||
|
||||
verify(activity).setResult(RESULT_CONNECTED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onActivityResult_hasPermissionForResult_setResultWithData() {
|
||||
WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
|
||||
when(activity.hasPermissionForResult()).thenReturn(true);
|
||||
final Intent data = new Intent();
|
||||
|
||||
activity.onActivityResult(REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER, RESULT_OK,
|
||||
data);
|
||||
|
||||
verify(activity).setResult(RESULT_CONNECTED, data);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasPermissionForResult_noCallingPackage_returnFalse() {
|
||||
WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
|
||||
when(activity.getCallingPackage()).thenReturn(null);
|
||||
|
||||
final boolean result = activity.hasPermissionForResult();
|
||||
|
||||
assertThat(result).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasPermissionForResult_noPermission_returnFalse() {
|
||||
WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
|
||||
when(activity.getCallingPackage()).thenReturn(null);
|
||||
when(mPackageManager.checkPermission(ACCESS_COARSE_LOCATION, CALLING_PACKAGE))
|
||||
.thenReturn(PackageManager.PERMISSION_DENIED);
|
||||
when(mPackageManager.checkPermission(ACCESS_FINE_LOCATION, CALLING_PACKAGE))
|
||||
.thenReturn(PackageManager.PERMISSION_DENIED);
|
||||
|
||||
final boolean result = activity.hasPermissionForResult();
|
||||
|
||||
assertThat(result).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasPermissionForResult_hasCoarseLocationPermission_returnTrue() {
|
||||
WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
|
||||
when(activity.getCallingPackage()).thenReturn(CALLING_PACKAGE);
|
||||
when(activity.getPackageManager()).thenReturn(mPackageManager);
|
||||
when(mPackageManager.checkPermission(ACCESS_COARSE_LOCATION, CALLING_PACKAGE))
|
||||
.thenReturn(PackageManager.PERMISSION_GRANTED);
|
||||
when(mPackageManager.checkPermission(ACCESS_FINE_LOCATION, CALLING_PACKAGE))
|
||||
.thenReturn(PackageManager.PERMISSION_DENIED);
|
||||
|
||||
final boolean result = activity.hasPermissionForResult();
|
||||
|
||||
assertThat(result).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasPermissionForResult_hasFineLocationPermission_returnTrue() {
|
||||
WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
|
||||
when(activity.getCallingPackage()).thenReturn(CALLING_PACKAGE);
|
||||
when(activity.getPackageManager()).thenReturn(mPackageManager);
|
||||
when(mPackageManager.checkPermission(ACCESS_COARSE_LOCATION, CALLING_PACKAGE))
|
||||
.thenReturn(PackageManager.PERMISSION_DENIED);
|
||||
when(mPackageManager.checkPermission(ACCESS_FINE_LOCATION, CALLING_PACKAGE))
|
||||
.thenReturn(PackageManager.PERMISSION_GRANTED);
|
||||
|
||||
final boolean result = activity.hasPermissionForResult();
|
||||
|
||||
assertThat(result).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasPermissionForResult_haveBothLocationPermissions_returnTrue() {
|
||||
WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
|
||||
when(activity.getCallingPackage()).thenReturn(CALLING_PACKAGE);
|
||||
when(activity.getPackageManager()).thenReturn(mPackageManager);
|
||||
when(mPackageManager.checkPermission(ACCESS_COARSE_LOCATION, CALLING_PACKAGE))
|
||||
.thenReturn(PackageManager.PERMISSION_GRANTED);
|
||||
when(mPackageManager.checkPermission(ACCESS_FINE_LOCATION, CALLING_PACKAGE))
|
||||
.thenReturn(PackageManager.PERMISSION_GRANTED);
|
||||
|
||||
final boolean result = activity.hasPermissionForResult();
|
||||
|
||||
assertThat(result).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
* 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.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.wifi.details2;
|
||||
package com.android.settings.wifi.details;
|
||||
|
||||
import static com.android.settings.wifi.WifiSettings.WIFI_DIALOG_ID;
|
||||
|
||||
@@ -54,9 +54,9 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class WifiNetworkDetailsFragment2Test {
|
||||
public class WifiNetworkDetailsFragmentTest {
|
||||
|
||||
final String TEST_PREFERENCE_KEY = "TEST_PREFERENCE_KEY";
|
||||
private static final String TEST_PREFERENCE_KEY = "TEST_PREFERENCE_KEY";
|
||||
|
||||
@Mock
|
||||
WifiEntry mWifiEntry;
|
||||
@@ -64,7 +64,7 @@ public class WifiNetworkDetailsFragment2Test {
|
||||
NetworkDetailsTracker mNetworkDetailsTracker;
|
||||
@Mock
|
||||
Menu mMenu;
|
||||
private WifiNetworkDetailsFragment2 mFragment;
|
||||
private WifiNetworkDetailsFragment mFragment;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -72,7 +72,7 @@ public class WifiNetworkDetailsFragment2Test {
|
||||
doReturn(mWifiEntry).when(mNetworkDetailsTracker).getWifiEntry();
|
||||
doReturn(true).when(mWifiEntry).isSaved();
|
||||
|
||||
mFragment = new WifiNetworkDetailsFragment2();
|
||||
mFragment = new WifiNetworkDetailsFragment();
|
||||
mFragment.mNetworkDetailsTracker = mNetworkDetailsTracker;
|
||||
}
|
||||
|
||||
@@ -165,8 +165,8 @@ public class WifiNetworkDetailsFragment2Test {
|
||||
verify(controller).displayPreference(screen);
|
||||
}
|
||||
|
||||
// Fake WifiNetworkDetailsFragment2 to override the protected method as public.
|
||||
public class FakeFragment extends WifiNetworkDetailsFragment2 {
|
||||
// Fake WifiNetworkDetailsFragment to override the protected method as public.
|
||||
public static class FakeFragment extends WifiNetworkDetailsFragment {
|
||||
|
||||
@Override
|
||||
public void addPreferenceController(AbstractPreferenceController controller) {
|
||||
@@ -179,7 +179,7 @@ public class WifiNetworkDetailsFragment2Test {
|
||||
}
|
||||
}
|
||||
|
||||
public class TestController extends BasePreferenceController {
|
||||
public static class TestController extends BasePreferenceController {
|
||||
|
||||
public TestController() {
|
||||
super(RuntimeEnvironment.application, TEST_PREFERENCE_KEY);
|
||||
@@ -76,6 +76,7 @@ import com.android.settings.Utils;
|
||||
import com.android.settings.testutils.shadow.ShadowDevicePolicyManager;
|
||||
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
|
||||
import com.android.settings.widget.EntityHeaderController;
|
||||
import com.android.settings.wifi.details.WifiNetworkDetailsFragment;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.utils.StringUtil;
|
||||
@@ -145,7 +146,7 @@ public class WifiDetailPreferenceController2Test {
|
||||
@Mock
|
||||
private WifiInfo mMockWifiInfo;
|
||||
@Mock
|
||||
private WifiNetworkDetailsFragment2 mMockFragment;
|
||||
private WifiNetworkDetailsFragment mMockFragment;
|
||||
@Mock
|
||||
private WifiManager mMockWifiManager;
|
||||
@Mock
|
||||
|
||||
Reference in New Issue
Block a user