Add cancel button for private dns dialog
Also update the onclick method. Change-Id: I69e92584e056a4d0a686153315b8df002d91e204 Fixes: 79479021 Test: RunSettingsRoboTests
This commit is contained in:
@@ -97,6 +97,7 @@
|
|||||||
android:order="15"
|
android:order="15"
|
||||||
android:dialogTitle="@string/select_private_dns_configuration_dialog_title"
|
android:dialogTitle="@string/select_private_dns_configuration_dialog_title"
|
||||||
android:dialogLayout="@layout/private_dns_mode_dialog"
|
android:dialogLayout="@layout/private_dns_mode_dialog"
|
||||||
android:positiveButtonText="@string/save" />
|
android:positiveButtonText="@string/save"
|
||||||
|
android:negativeButtonText="@android:string/cancel" />
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
@@ -156,16 +156,18 @@ public class PrivateDnsModeDialogPreference extends CustomDialogPreference imple
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
final Context context = getContext();
|
if (which == DialogInterface.BUTTON_POSITIVE) {
|
||||||
if (mMode.equals(PRIVATE_DNS_MODE_PROVIDER_HOSTNAME)) {
|
final Context context = getContext();
|
||||||
// Only clickable if hostname is valid, so we could save it safely
|
if (mMode.equals(PRIVATE_DNS_MODE_PROVIDER_HOSTNAME)) {
|
||||||
Settings.Global.putString(context.getContentResolver(), HOSTNAME_KEY,
|
// Only clickable if hostname is valid, so we could save it safely
|
||||||
mEditText.getText().toString());
|
Settings.Global.putString(context.getContentResolver(), HOSTNAME_KEY,
|
||||||
}
|
mEditText.getText().toString());
|
||||||
|
}
|
||||||
|
|
||||||
FeatureFactory.getFactory(context).getMetricsFeatureProvider().action(context,
|
FeatureFactory.getFactory(context).getMetricsFeatureProvider().action(context,
|
||||||
MetricsProto.MetricsEvent.ACTION_PRIVATE_DNS_MODE, mMode);
|
MetricsProto.MetricsEvent.ACTION_PRIVATE_DNS_MODE, mMode);
|
||||||
Settings.Global.putString(context.getContentResolver(), MODE_KEY, mMode);
|
Settings.Global.putString(context.getContentResolver(), MODE_KEY, mMode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -28,7 +28,10 @@ import static org.mockito.Mockito.when;
|
|||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -150,4 +153,36 @@ public class PrivateDnsModeDialogPreferenceTest {
|
|||||||
assertThat(mSaveButton.isEnabled()).named("provider: " + invalid).isFalse();
|
assertThat(mSaveButton.isEnabled()).named("provider: " + invalid).isFalse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnClick_positiveButtonClicked_saveData() {
|
||||||
|
// Set the default settings to OFF
|
||||||
|
final ContentResolver contentResolver = mContext.getContentResolver();
|
||||||
|
Settings.Global.putString(contentResolver, Settings.Global.PRIVATE_DNS_MODE,
|
||||||
|
ConnectivityManager.PRIVATE_DNS_MODE_OFF);
|
||||||
|
|
||||||
|
mPreference.mMode = ConnectivityManager.PRIVATE_DNS_MODE_OPPORTUNISTIC;
|
||||||
|
mPreference.onClick(null, DialogInterface.BUTTON_POSITIVE);
|
||||||
|
|
||||||
|
// Change to OPPORTUNISTIC
|
||||||
|
assertThat(Settings.Global.getString(contentResolver,
|
||||||
|
Settings.Global.PRIVATE_DNS_MODE)).isEqualTo(
|
||||||
|
ConnectivityManager.PRIVATE_DNS_MODE_OPPORTUNISTIC);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnClick_negativeButtonClicked_doNothing() {
|
||||||
|
// Set the default settings to OFF
|
||||||
|
final ContentResolver contentResolver = mContext.getContentResolver();
|
||||||
|
Settings.Global.putString(contentResolver, Settings.Global.PRIVATE_DNS_MODE,
|
||||||
|
ConnectivityManager.PRIVATE_DNS_MODE_OFF);
|
||||||
|
|
||||||
|
mPreference.mMode = ConnectivityManager.PRIVATE_DNS_MODE_OPPORTUNISTIC;
|
||||||
|
mPreference.onClick(null, DialogInterface.BUTTON_NEGATIVE);
|
||||||
|
|
||||||
|
// Still equal to OFF
|
||||||
|
assertThat(Settings.Global.getString(contentResolver,
|
||||||
|
Settings.Global.PRIVATE_DNS_MODE)).isEqualTo(
|
||||||
|
ConnectivityManager.PRIVATE_DNS_MODE_OFF);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user