Disable VPN prefs for restriction or lockdown case
Change-Id: I2fcf84876bf23b92cdcd00ce93514106914d0c29
This commit is contained in:
@@ -223,6 +223,8 @@ public class VpnSettings extends SettingsPreferenceFragment implements
|
||||
final List<LegacyVpnInfo> connectedLegacyVpns = getConnectedLegacyVpns();
|
||||
final List<AppVpnInfo> connectedAppVpns = getConnectedAppVpns();
|
||||
|
||||
final Set<Integer> readOnlyUsers = getReadOnlyUserProfiles();
|
||||
|
||||
// Refresh the PreferenceGroup which lists VPNs
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
@@ -233,11 +235,13 @@ public class VpnSettings extends SettingsPreferenceFragment implements
|
||||
for (VpnProfile profile : vpnProfiles) {
|
||||
ConfigPreference p = findOrCreatePreference(profile);
|
||||
p.setState(ConfigPreference.STATE_NONE);
|
||||
p.setEnabled(!readOnlyUsers.contains(UserHandle.myUserId()));
|
||||
updates.add(p);
|
||||
}
|
||||
for (AppVpnInfo app : vpnApps) {
|
||||
AppPreference p = findOrCreatePreference(app);
|
||||
p.setState(AppPreference.STATE_DISCONNECTED);
|
||||
p.setEnabled(!readOnlyUsers.contains(app.userId));
|
||||
updates.add(p);
|
||||
}
|
||||
|
||||
@@ -417,6 +421,19 @@ public class VpnSettings extends SettingsPreferenceFragment implements
|
||||
return connections;
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
private Set<Integer> getReadOnlyUserProfiles() {
|
||||
Set<Integer> result = new ArraySet<>();
|
||||
for (UserHandle profile : mUserManager.getUserProfiles()) {
|
||||
final int profileId = profile.getIdentifier();
|
||||
if (mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_VPN, profile)
|
||||
|| mConnectivityManager.getAlwaysOnVpnPackageForUser(profileId) != null) {
|
||||
result.add(profileId);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static List<AppVpnInfo> getVpnApps(Context context, boolean includeProfiles) {
|
||||
List<AppVpnInfo> result = Lists.newArrayList();
|
||||
|
||||
|
Reference in New Issue
Block a user