[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.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.VisibleForTesting;
@@ -110,21 +109,11 @@ public class RoamingPreferenceController extends TelephonyTogglePreferenceContro
: AVAILABLE_UNSEARCHABLE;
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
if (TextUtils.equals(preference.getKey(), getPreferenceKey())) {
if (isDialogNeeded()) {
showDialog();
}
return true;
}
return false;
}
@Override
public boolean setChecked(boolean isChecked) {
if (!isDialogNeeded()) {
if (isDialogNeeded()) {
showDialog();
} else {
// Update data directly if we don't need dialog
mTelephonyManager.setDataRoamingEnabled(isChecked);
return true;

View File

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