Merge "Revert^2 "Migrate to CompoundButton.OnCheckedChangeListener"" into main

This commit is contained in:
Chaohui Wang
2023-11-08 09:05:22 +00:00
committed by Android (Google) Code Review
49 changed files with 174 additions and 188 deletions

View File

@@ -142,7 +142,7 @@ public class CaptioningTogglePreferenceControllerTest {
public void onSwitchChanged_switchChecked_shouldSetCaptionEnabled() {
mController.displayPreference(mScreen);
mController.onSwitchChanged(/* switchView= */ null, /* isChecked= */ true);
mController.onCheckedChanged(/* buttonView= */ null, /* isChecked= */ true);
assertThat(isCaptionEnabled()).isTrue();
}
@@ -151,7 +151,7 @@ public class CaptioningTogglePreferenceControllerTest {
public void onSwitchChanged_switchUnchecked_shouldSetCaptionDisabled() {
mController.displayPreference(mScreen);
mController.onSwitchChanged(/* switchView= */ null, /* isChecked= */ false);
mController.onCheckedChanged(/* buttonView= */ null, /* isChecked= */ false);
assertThat(isCaptionEnabled()).isFalse();
}

View File

@@ -115,11 +115,11 @@ public class WorkModePreferenceControllerTest {
@Test
public void onPreferenceChange_shouldRequestQuietModeEnabled() {
mController.onSwitchChanged(mSwitch, true);
mController.onCheckedChanged(mSwitch, true);
verify(mUserManager).requestQuietModeEnabled(false, mManagedUser);
mController.onSwitchChanged(mSwitch, false);
mController.onCheckedChanged(mSwitch, false);
verify(mUserManager).requestQuietModeEnabled(true, mManagedUser);
}

View File

@@ -80,7 +80,7 @@ public class AutomaticStorageManagerSwitchBarControllerTest {
@Test
public void onSwitchChanged_false_recordsAMetric() {
mController.onSwitchChanged(null, false);
mController.onCheckedChanged(null, false);
verify(mMetricsFeatureProvider)
.action(
@@ -91,7 +91,7 @@ public class AutomaticStorageManagerSwitchBarControllerTest {
@Test
public void onSwitchChanged_true_recordsAMetric() {
mController.onSwitchChanged(null, true);
mController.onCheckedChanged(null, true);
verify(mMetricsFeatureProvider)
.action(
@@ -102,7 +102,7 @@ public class AutomaticStorageManagerSwitchBarControllerTest {
@Test
public void onSwitchChanged_showWarningFragmentIfNotEnabledByDefault() {
mController.onSwitchChanged(null, true);
mController.onCheckedChanged(null, true);
verify(mFragmentManager.beginTransaction())
.add(any(Fragment.class), eq(ActivationWarningFragment.TAG));
@@ -112,7 +112,7 @@ public class AutomaticStorageManagerSwitchBarControllerTest {
public void onSwitchChange_doNotShowWarningFragmentIfEnabledByDefault() {
SystemProperties.set("ro.storage_manager.enabled", "true");
mController.onSwitchChanged(null, true);
mController.onCheckedChanged(null, true);
verify(mFragmentManager.beginTransaction(), never())
.add(any(Fragment.class), eq(ActivationWarningFragment.TAG));

View File

@@ -160,7 +160,7 @@ public class DevelopmentSettingsDashboardFragmentTest {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
mDashboard.onSwitchChanged(null, false /* isChecked */);
mDashboard.onCheckedChanged(null, false /* isChecked */);
assertThat(ShadowEnableDevelopmentSettingWarningDialog.mShown).isFalse();
}
@@ -172,7 +172,7 @@ public class DevelopmentSettingsDashboardFragmentTest {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
mDashboard.onSwitchChanged(null, true /* isChecked */);
mDashboard.onCheckedChanged(null, true /* isChecked */);
assertThat(ShadowEnableDevelopmentSettingWarningDialog.mShown).isTrue();
}
@@ -184,7 +184,7 @@ public class DevelopmentSettingsDashboardFragmentTest {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
mDashboard.onSwitchChanged(null, false /* isChecked */);
mDashboard.onCheckedChanged(null, false /* isChecked */);
assertThat(ShadowEnableDevelopmentSettingWarningDialog.mShown).isFalse();
assertThat(DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(mContext)).isFalse();
@@ -203,7 +203,7 @@ public class DevelopmentSettingsDashboardFragmentTest {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
mDashboard.onSwitchChanged(null, false /* isChecked */);
mDashboard.onCheckedChanged(null, false /* isChecked */);
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
assertThat(dialog).isNotNull();

View File

@@ -24,6 +24,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.widget.CompoundButton.OnCheckedChangeListener;
import androidx.lifecycle.LifecycleOwner;
@@ -31,7 +32,6 @@ import com.android.settings.testutils.shadow.ShadowUserManager;
import com.android.settings.testutils.shadow.ShadowUtils;
import com.android.settings.widget.SettingsMainSwitchBar;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.widget.OnMainSwitchChangeListener;
import org.junit.After;
import org.junit.Before;
@@ -78,7 +78,7 @@ public class DevelopmentSwitchBarControllerTest {
ShadowUtils.setIsUserAMonkey(true);
new DevelopmentSwitchBarController(mSettings, mSwitchBar,
true /* isAvailable */, mLifecycle);
final List<OnMainSwitchChangeListener> listeners =
final List<OnCheckedChangeListener> listeners =
ReflectionHelpers.getField(mSwitchBar, "mSwitchChangeListeners");
mLifecycle.handleLifecycleEvent(ON_START);
@@ -93,7 +93,7 @@ public class DevelopmentSwitchBarControllerTest {
ShadowUtils.setIsUserAMonkey(false);
new DevelopmentSwitchBarController(mSettings, mSwitchBar,
true /* isAvailable */, mLifecycle);
final List<OnMainSwitchChangeListener> listeners =
final List<OnCheckedChangeListener> listeners =
ReflectionHelpers.getField(mSwitchBar, "mSwitchChangeListeners");
mLifecycle.handleLifecycleEvent(ON_START);
@@ -109,7 +109,7 @@ public class DevelopmentSwitchBarControllerTest {
ShadowUtils.setIsUserAMonkey(false);
new DevelopmentSwitchBarController(mSettings, mSwitchBar,
true /* isAvailable */, mLifecycle);
final List<OnMainSwitchChangeListener> listeners =
final List<OnCheckedChangeListener> listeners =
ReflectionHelpers.getField(mSwitchBar, "mSwitchChangeListeners");
mLifecycle.handleLifecycleEvent(ON_START);

View File

@@ -104,7 +104,7 @@ public class NightDisplayActivationPreferenceControllerTest {
final NightDisplayActivationPreferenceController controller =
new NightDisplayActivationPreferenceController(mContext, "night_display_activated");
controller.onSwitchChanged(null, true);
controller.onCheckedChanged(null, true);
assertThat(mColorDisplayManager.isNightDisplayActivated()).isEqualTo(true);
}
@@ -115,7 +115,7 @@ public class NightDisplayActivationPreferenceControllerTest {
final NightDisplayActivationPreferenceController controller =
new NightDisplayActivationPreferenceController(mContext, "night_display_activated");
controller.onSwitchChanged(null, false);
controller.onCheckedChanged(null, false);
assertThat(mColorDisplayManager.isNightDisplayActivated()).isEqualTo(false);
}

View File

@@ -28,7 +28,6 @@ import androidx.test.core.app.ApplicationProvider;
import com.android.settingslib.dream.DreamBackend;
import com.android.settingslib.widget.MainSwitchPreference;
import com.android.settingslib.widget.OnMainSwitchChangeListener;
import org.junit.After;
import org.junit.Before;
@@ -53,8 +52,6 @@ public class DreamMainSwitchPreferenceControllerTest {
private DreamMainSwitchPreferenceController mController;
private MainSwitchPreference mPreference;
private DreamBackend mBackend;
@Mock
private OnMainSwitchChangeListener mChangeListener;
private ShadowContentResolver mShadowContentResolver;
@Before

View File

@@ -39,7 +39,7 @@ import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.UserHandle;
import android.widget.Switch;
import android.widget.CompoundButton;
import androidx.fragment.app.FragmentActivity;
import androidx.loader.app.LoaderManager;
@@ -109,7 +109,7 @@ public class PowerBackgroundUsageDetailTest {
@Mock private BackupManager mBackupManager;
@Mock private PackageManager mPackageManager;
@Mock private AppOpsManager mAppOpsManager;
@Mock private Switch mMockSwitch;
@Mock private CompoundButton mMockSwitch;
@Before
public void setUp() {
@@ -259,7 +259,7 @@ public class PowerBackgroundUsageDetailTest {
final int optimizedMode = BatteryOptimizeUtils.MODE_OPTIMIZED;
mFragment.mOptimizationMode = optimizedMode;
mFragment.onSwitchChanged(mMockSwitch, /* isChecked= */ false);
mFragment.onCheckedChanged(mMockSwitch, /* isChecked= */ false);
verify(mOptimizePreference).setEnabled(false);
verify(mUnrestrictedPreference).setEnabled(false);
@@ -275,7 +275,7 @@ public class PowerBackgroundUsageDetailTest {
final int optimizedMode = BatteryOptimizeUtils.MODE_OPTIMIZED;
mFragment.mOptimizationMode = restrictedMode;
mFragment.onSwitchChanged(mMockSwitch, /* isChecked= */ true);
mFragment.onCheckedChanged(mMockSwitch, /* isChecked= */ true);
verify(mOptimizePreference).setEnabled(true);
verify(mUnrestrictedPreference).setEnabled(true);

View File

@@ -116,7 +116,7 @@ public class PreventRingingSwitchPreferenceControllerTest {
Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE,
VOLUME_HUSH_OFF);
mController.onSwitchChanged(null, true);
mController.onCheckedChanged(null, true);
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.VOLUME_HUSH_GESTURE, UNKNOWN)).isEqualTo(VOLUME_HUSH_VIBRATE);
@@ -127,7 +127,7 @@ public class PreventRingingSwitchPreferenceControllerTest {
Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE,
VOLUME_HUSH_MUTE);
mController.onSwitchChanged(null, false);
mController.onCheckedChanged(null, false);
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.VOLUME_HUSH_GESTURE, UNKNOWN)).isEqualTo(VOLUME_HUSH_OFF);
@@ -139,7 +139,7 @@ public class PreventRingingSwitchPreferenceControllerTest {
Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE,
VOLUME_HUSH_MUTE);
mController.onSwitchChanged(null, true);
mController.onCheckedChanged(null, true);
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.VOLUME_HUSH_GESTURE, UNKNOWN)).isEqualTo(VOLUME_HUSH_MUTE);
@@ -151,7 +151,7 @@ public class PreventRingingSwitchPreferenceControllerTest {
Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE,
VOLUME_HUSH_VIBRATE);
mController.onSwitchChanged(null, true);
mController.onCheckedChanged(null, true);
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.VOLUME_HUSH_GESTURE, UNKNOWN)).isEqualTo(VOLUME_HUSH_VIBRATE);

View File

@@ -85,14 +85,14 @@ public class LocationSwitchBarControllerTest {
@Test
public void onSwitchChanged_switchChecked_shouldSetLocationEnabled() {
mController.onSwitchChanged(mSwitch, true);
mController.onCheckedChanged(mSwitch, true);
verify(mEnabler).setLocationEnabled(true);
}
@Test
public void onSwitchChanged_switchUnchecked_shouldSetLocationDisabled() {
mController.onSwitchChanged(mSwitch, false);
mController.onCheckedChanged(mSwitch, false);
verify(mEnabler).setLocationEnabled(false);
}

View File

@@ -112,7 +112,7 @@ public class BubbleNotificationPreferenceControllerTest {
public void onSwitchChanged_true_settingIsOff_flagShouldOn() {
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, OFF);
mController.onSwitchChanged(mSwitch, true);
mController.onCheckedChanged(mSwitch, true);
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
NOTIFICATION_BUBBLES, OFF)).isEqualTo(ON);
@@ -122,7 +122,7 @@ public class BubbleNotificationPreferenceControllerTest {
public void onSwitchChanged_false_settingIsOn_flagShouldOff() {
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, ON);
mController.onSwitchChanged(mSwitch, false);
mController.onCheckedChanged(mSwitch, false);
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
NOTIFICATION_BUBBLES, ON)).isEqualTo(OFF);

View File

@@ -101,7 +101,7 @@ public class BlockPreferenceControllerTest {
@Test
public void testNoCrashIfNoOnResume() {
mController.isAvailable();
mController.onSwitchChanged(null, false);
mController.onCheckedChanged(null, false);
}
@Test
@@ -355,11 +355,11 @@ public class BlockPreferenceControllerTest {
mController.onResume(appRow, channel, null, null, null, null, null);
mController.updateState(mPreference);
mController.onSwitchChanged(null, false);
mController.onCheckedChanged(null, false);
assertEquals(IMPORTANCE_NONE, channel.getImportance());
assertTrue(appRow.banned);
mController.onSwitchChanged(null, true);
mController.onCheckedChanged(null, true);
assertEquals(IMPORTANCE_UNSPECIFIED, channel.getImportance());
assertFalse(appRow.banned);
@@ -377,10 +377,10 @@ public class BlockPreferenceControllerTest {
mController.onResume(appRow, channel, null, null, null, null, null);
mController.updateState(mPreference);
mController.onSwitchChanged(null, false);
mController.onCheckedChanged(null, false);
assertEquals(IMPORTANCE_NONE, channel.getImportance());
mController.onSwitchChanged(null, true);
mController.onCheckedChanged(null, true);
assertEquals(IMPORTANCE_HIGH, channel.getImportance());
verify(mBackend, times(2)).updateChannel(any(), anyInt(), any());

View File

@@ -292,7 +292,7 @@ public class WifiCallingSettingsForSubTest {
public void onSwitchChanged_enableSetting_shouldLaunchWfcDisclaimerFragment() {
final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
mFragment.onSwitchChanged(null, true);
mFragment.onCheckedChanged(null, true);
// Check the WFC disclaimer fragment is launched.
verify(mFragment).startActivityForResult(intentCaptor.capture(),
@@ -337,7 +337,7 @@ public class WifiCallingSettingsForSubTest {
@Test
public void onSwitchChanged_disableSetting_shouldNotLaunchWfcDisclaimerFragment() {
mFragment.onSwitchChanged(null, false);
mFragment.onCheckedChanged(null, false);
// Check the WFC disclaimer fragment is not launched.
verify(mFragment, never()).startActivityForResult(any(Intent.class), anyInt());

View File

@@ -150,7 +150,7 @@ public class WifiTetherSwitchBarControllerTest {
public void onSwitchChanged_switchNotEnabled_doNothingForTethering() {
when(mSwitch.isEnabled()).thenReturn(false);
mController.onSwitchChanged(mSwitch, mSwitch.isChecked());
mController.onCheckedChanged(mSwitch, true);
verify(mConnectivityManager, never()).startTethering(anyInt(), anyBoolean(), any(), any());
verify(mConnectivityManager, never()).stopTethering(anyInt());
@@ -158,9 +158,7 @@ public class WifiTetherSwitchBarControllerTest {
@Test
public void onSwitchChanged_isChecked_startTethering() {
when(mSwitch.isChecked()).thenReturn(true);
mController.onSwitchChanged(mSwitch, mSwitch.isChecked());
mController.onCheckedChanged(mSwitch, true);
verify(mConnectivityManager).startTethering(anyInt(), anyBoolean(), any(), any());
}
@@ -168,9 +166,7 @@ public class WifiTetherSwitchBarControllerTest {
@Test
public void onSwitchChanged_isNotChecked_stopTethering() {
when(mWifiManager.getWifiApState()).thenReturn(WIFI_AP_STATE_ENABLED);
when(mSwitch.isChecked()).thenReturn(false);
mController.onSwitchChanged(mSwitch, mSwitch.isChecked());
mController.onCheckedChanged(mSwitch, false);
verify(mConnectivityManager).stopTethering(anyInt());
}