Implement always-on VPN separate lockdown setting
Allows Settings to control whether always-on VPN is required for the connection to complete, or if it is offered on a best-efforts basis. Change-Id: I5eb273a99e7559adc66b05e647c9130a819f99d4 Test: runtest -x tests/app/src/com/android/settings/vpn2/VpnTests.java Fix: 32420810
This commit is contained in:
@@ -29,7 +29,7 @@ import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
public class ConfirmLockdownFragment extends InstrumentedDialogFragment
|
||||
implements DialogInterface.OnClickListener {
|
||||
public interface ConfirmLockdownListener {
|
||||
public void onConfirmLockdown(Bundle options, boolean isEnabled);
|
||||
public void onConfirmLockdown(Bundle options, boolean isEnabled, boolean isLockdown);
|
||||
}
|
||||
|
||||
private static final String TAG = "ConfirmLockdown";
|
||||
@@ -40,6 +40,7 @@ public class ConfirmLockdownFragment extends InstrumentedDialogFragment
|
||||
}
|
||||
|
||||
private static final String ARG_REPLACING = "replacing";
|
||||
private static final String ARG_ALWAYS_ON = "always_on";
|
||||
private static final String ARG_LOCKDOWN_SRC = "lockdown_old";
|
||||
private static final String ARG_LOCKDOWN_DST = "lockdown_new";
|
||||
private static final String ARG_OPTIONS = "options";
|
||||
@@ -47,11 +48,11 @@ public class ConfirmLockdownFragment extends InstrumentedDialogFragment
|
||||
public static boolean shouldShow(boolean replacing, boolean fromLockdown, boolean toLockdown) {
|
||||
// We only need to show this if we are:
|
||||
// - replacing an existing connection
|
||||
// - switching on always-on mode where it was not enabled before.
|
||||
// - switching on always-on mode with lockdown enabled where it was not enabled before.
|
||||
return replacing || (toLockdown && !fromLockdown);
|
||||
}
|
||||
|
||||
public static void show(Fragment parent, boolean replacing,
|
||||
public static void show(Fragment parent, boolean replacing, boolean alwaysOn,
|
||||
boolean fromLockdown, boolean toLockdown, Bundle options) {
|
||||
if (parent.getFragmentManager().findFragmentByTag(TAG) != null) {
|
||||
// Already exists. Don't show it twice.
|
||||
@@ -59,6 +60,7 @@ public class ConfirmLockdownFragment extends InstrumentedDialogFragment
|
||||
}
|
||||
final Bundle args = new Bundle();
|
||||
args.putBoolean(ARG_REPLACING, replacing);
|
||||
args.putBoolean(ARG_ALWAYS_ON, alwaysOn);
|
||||
args.putBoolean(ARG_LOCKDOWN_SRC, fromLockdown);
|
||||
args.putBoolean(ARG_LOCKDOWN_DST, toLockdown);
|
||||
args.putParcelable(ARG_OPTIONS, options);
|
||||
@@ -72,20 +74,21 @@ public class ConfirmLockdownFragment extends InstrumentedDialogFragment
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
final boolean replacing = getArguments().getBoolean(ARG_REPLACING);
|
||||
final boolean wasAlwaysOn = getArguments().getBoolean(ARG_LOCKDOWN_SRC);
|
||||
final boolean nowAlwaysOn = getArguments().getBoolean(ARG_LOCKDOWN_DST);
|
||||
final boolean alwaysOn = getArguments().getBoolean(ARG_ALWAYS_ON);
|
||||
final boolean wasLockdown = getArguments().getBoolean(ARG_LOCKDOWN_SRC);
|
||||
final boolean nowLockdown = getArguments().getBoolean(ARG_LOCKDOWN_DST);
|
||||
|
||||
final int titleId = replacing ? R.string.vpn_replace_vpn_title : R.string.vpn_set_vpn_title;
|
||||
final int actionId =
|
||||
(replacing ? R.string.vpn_replace :
|
||||
(nowAlwaysOn ? R.string.vpn_turn_on : R.string.okay));
|
||||
(nowLockdown ? R.string.vpn_turn_on : R.string.okay));
|
||||
final int messageId;
|
||||
if (nowAlwaysOn) {
|
||||
if (nowLockdown) {
|
||||
messageId = replacing
|
||||
? R.string.vpn_replace_always_on_vpn_enable_message
|
||||
: R.string.vpn_first_always_on_vpn_message;
|
||||
} else {
|
||||
messageId = wasAlwaysOn
|
||||
messageId = wasLockdown
|
||||
? R.string.vpn_replace_always_on_vpn_disable_message
|
||||
: R.string.vpn_replace_vpn_message;
|
||||
}
|
||||
@@ -103,6 +106,7 @@ public class ConfirmLockdownFragment extends InstrumentedDialogFragment
|
||||
if (getTargetFragment() instanceof ConfirmLockdownListener) {
|
||||
((ConfirmLockdownListener) getTargetFragment()).onConfirmLockdown(
|
||||
getArguments().getParcelable(ARG_OPTIONS),
|
||||
getArguments().getBoolean(ARG_ALWAYS_ON),
|
||||
getArguments().getBoolean(ARG_LOCKDOWN_DST));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user