[Settings] Data roaming warning only when turn ON

handlePreferenceTreeClick() goes after setChecked() however
configuration may have been altered within setChecked().

Follow same design within MobileDataPreferenceController to fix this
issue. A boolean state will be maintained as the condition when warning
dialog is required when click.

Bug: 148491064
Test: m RunSettingsRoboTests -j ROBOTEST_FILTER=RoamingPreferenceControllerTest
Change-Id: I63c4e2149b0e9efa16fd9ee402652c67eb9c5a4d
This commit is contained in:
Bonian Chen
2020-02-03 21:31:24 +08:00
parent 040c548d81
commit 19135546a3
2 changed files with 5 additions and 16 deletions

View File

@@ -22,7 +22,6 @@ import android.provider.Settings;
import android.telephony.CarrierConfigManager; import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
@@ -111,20 +110,10 @@ public class RoamingPreferenceController extends TelephonyTogglePreferenceContro
} }
@Override @Override
public boolean handlePreferenceTreeClick(Preference preference) { public boolean setChecked(boolean isChecked) {
if (TextUtils.equals(preference.getKey(), getPreferenceKey())) {
if (isDialogNeeded()) { if (isDialogNeeded()) {
showDialog(); showDialog();
} } else {
return true;
}
return false;
}
@Override
public boolean setChecked(boolean isChecked) {
if (!isDialogNeeded()) {
// Update data directly if we don't need dialog // Update data directly if we don't need dialog
mTelephonyManager.setDataRoamingEnabled(isChecked); mTelephonyManager.setDataRoamingEnabled(isChecked);
return true; return true;

View File

@@ -117,10 +117,10 @@ public class RoamingPreferenceControllerTest {
} }
@Test @Test
public void handlePreferenceTreeClick_needDialog_showDialog() { public void setChecked_needDialog_showDialog() {
doReturn(true).when(mController).isDialogNeeded(); doReturn(true).when(mController).isDialogNeeded();
mController.handlePreferenceTreeClick(mPreference); mController.setChecked(true);
verify(mFragmentManager).beginTransaction(); verify(mFragmentManager).beginTransaction();
} }