Allow advanced VPN to manage connection status via its UI
Bug: 238641532 Test: atest -c VpnSettingsTest Change-Id: Ia6f1d84bba38bab7f13f46dc8a4fdb4eb0505f8f Merged-In: Ia6f1d84bba38bab7f13f46dc8a4fdb4eb0505f8f
This commit is contained in:
@@ -47,4 +47,9 @@ public interface AdvancedVpnFeatureProvider {
|
||||
* Returns {@code true} advanced vpn is removable.
|
||||
*/
|
||||
boolean isAdvancedVpnRemovable();
|
||||
|
||||
/**
|
||||
* Returns {@code true} if the disconnect dialog is enabled when advanced vpn is connected.
|
||||
*/
|
||||
boolean isDisconnectDialogEnabled();
|
||||
}
|
||||
|
@@ -46,4 +46,9 @@ public class AdvancedVpnFeatureProviderImpl implements AdvancedVpnFeatureProvide
|
||||
public boolean isAdvancedVpnRemovable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisconnectDialogEnabled() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -366,7 +366,7 @@ public class VpnSettings extends RestrictedSettingsFragment implements
|
||||
public void setShownPreferences(final Collection<Preference> updates) {
|
||||
retainAllPreference(updates);
|
||||
|
||||
final PreferenceGroup vpnGroup = getPreferenceScreen();
|
||||
final PreferenceGroup vpnGroup = mPreferenceScreen;
|
||||
updatePreferenceGroup(vpnGroup, updates);
|
||||
|
||||
// Show all new preferences on the screen
|
||||
@@ -448,14 +448,16 @@ public class VpnSettings extends RestrictedSettingsFragment implements
|
||||
} else if (preference instanceof AppPreference) {
|
||||
AppPreference pref = (AppPreference) preference;
|
||||
boolean connected = (pref.getState() == AppPreference.STATE_CONNECTED);
|
||||
String vpnPackageName = pref.getPackageName();
|
||||
|
||||
if (!connected) {
|
||||
if ((!connected) || (isAdvancedVpn(mFeatureProvider, vpnPackageName, getContext())
|
||||
&& !mFeatureProvider.isDisconnectDialogEnabled())) {
|
||||
try {
|
||||
UserHandle user = UserHandle.of(pref.getUserId());
|
||||
Context userContext = getActivity().createPackageContextAsUser(
|
||||
getActivity().getPackageName(), 0 /* flags */, user);
|
||||
Context userContext = getContext().createPackageContextAsUser(
|
||||
getContext().getPackageName(), 0 /* flags */, user);
|
||||
PackageManager pm = userContext.getPackageManager();
|
||||
Intent appIntent = pm.getLaunchIntentForPackage(pref.getPackageName());
|
||||
Intent appIntent = pm.getLaunchIntentForPackage(vpnPackageName);
|
||||
if (appIntent != null) {
|
||||
userContext.startActivityAsUser(appIntent, user);
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user