RESTRICT AUTOMERGE Make VPN by Google One always appear in VPN settings
Bug: 233559781 Test: manually test Change-Id: I175ab126ff92f773ab25a1fa64e4262b324fd353
This commit is contained in:
@@ -42,4 +42,9 @@ public interface AdvancedVpnFeatureProvider {
|
||||
* Returns the title of vpn preference group.
|
||||
*/
|
||||
String getVpnPreferenceGroupTitle(Context context);
|
||||
|
||||
/**
|
||||
* Returns {@code true} advanced vpn is removable.
|
||||
*/
|
||||
boolean isAdvancedVpnRemovable();
|
||||
}
|
||||
|
@@ -41,4 +41,9 @@ public class AdvancedVpnFeatureProviderImpl implements AdvancedVpnFeatureProvide
|
||||
public String getVpnPreferenceGroupTitle(Context context) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAdvancedVpnRemovable() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -48,6 +48,7 @@ import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
@@ -71,6 +72,7 @@ public class AppManagementFragment extends SettingsPreferenceFragment
|
||||
private PackageManager mPackageManager;
|
||||
private DevicePolicyManager mDevicePolicyManager;
|
||||
private VpnManager mVpnManager;
|
||||
private AdvancedVpnFeatureProvider mFeatureProvider;
|
||||
|
||||
// VPN app info
|
||||
private final int mUserId = UserHandle.myUserId();
|
||||
@@ -122,6 +124,7 @@ public class AppManagementFragment extends SettingsPreferenceFragment
|
||||
mPackageManager = getContext().getPackageManager();
|
||||
mDevicePolicyManager = getContext().getSystemService(DevicePolicyManager.class);
|
||||
mVpnManager = getContext().getSystemService(VpnManager.class);
|
||||
mFeatureProvider = FeatureFactory.getFactory(getContext()).getAdvancedVpnFeatureProvider();
|
||||
|
||||
mPreferenceAlwaysOn = (RestrictedSwitchPreference) findPreference(KEY_ALWAYS_ON_VPN);
|
||||
mPreferenceLockdown = (RestrictedSwitchPreference) findPreference(KEY_LOCKDOWN_VPN);
|
||||
@@ -283,7 +286,16 @@ public class AppManagementFragment extends SettingsPreferenceFragment
|
||||
}
|
||||
}
|
||||
|
||||
private void updateRestrictedViews() {
|
||||
@VisibleForTesting
|
||||
void updateRestrictedViews() {
|
||||
if (mFeatureProvider.isAdvancedVpnSupported(getContext())
|
||||
&& !mFeatureProvider.isAdvancedVpnRemovable()
|
||||
&& TextUtils.equals(mPackageName, mFeatureProvider.getAdvancedVpnPackageName())) {
|
||||
mPreferenceForget.setVisible(false);
|
||||
} else {
|
||||
mPreferenceForget.setVisible(true);
|
||||
}
|
||||
|
||||
if (isAdded()) {
|
||||
mPreferenceAlwaysOn.checkRestrictionAndSetDisabled(UserManager.DISALLOW_CONFIG_VPN,
|
||||
mUserId);
|
||||
@@ -314,6 +326,14 @@ public class AppManagementFragment extends SettingsPreferenceFragment
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void init(String packageName, AdvancedVpnFeatureProvider featureProvider,
|
||||
RestrictedPreference preference) {
|
||||
mPackageName = packageName;
|
||||
mFeatureProvider = featureProvider;
|
||||
mPreferenceForget = preference;
|
||||
}
|
||||
|
||||
private String getAlwaysOnVpnPackage() {
|
||||
return mVpnManager.getAlwaysOnVpnPackageForUser(mUserId);
|
||||
}
|
||||
|
@@ -241,7 +241,8 @@ public class VpnSettings extends RestrictedSettingsFragment implements
|
||||
|
||||
// Run heavy RPCs before switching to UI thread
|
||||
final List<VpnProfile> vpnProfiles = loadVpnProfiles();
|
||||
final List<AppVpnInfo> vpnApps = getVpnApps(context, /* includeProfiles */ true);
|
||||
final List<AppVpnInfo> vpnApps = getVpnApps(context, /* includeProfiles */ true,
|
||||
mFeatureProvider);
|
||||
|
||||
final Map<String, LegacyVpnInfo> connectedLegacyVpns = getConnectedLegacyVpns();
|
||||
final Set<AppVpnInfo> connectedAppVpns = getConnectedAppVpns();
|
||||
@@ -571,7 +572,15 @@ public class VpnSettings extends RestrictedSettingsFragment implements
|
||||
return result;
|
||||
}
|
||||
|
||||
static List<AppVpnInfo> getVpnApps(Context context, boolean includeProfiles) {
|
||||
static List<AppVpnInfo> getVpnApps(Context context, boolean includeProfiles,
|
||||
AdvancedVpnFeatureProvider featureProvider) {
|
||||
return getVpnApps(context, includeProfiles, featureProvider,
|
||||
context.getSystemService(AppOpsManager.class));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static List<AppVpnInfo> getVpnApps(Context context, boolean includeProfiles,
|
||||
AdvancedVpnFeatureProvider featureProvider, AppOpsManager aom) {
|
||||
List<AppVpnInfo> result = Lists.newArrayList();
|
||||
|
||||
final Set<Integer> profileIds;
|
||||
@@ -584,8 +593,6 @@ public class VpnSettings extends RestrictedSettingsFragment implements
|
||||
profileIds = Collections.singleton(UserHandle.myUserId());
|
||||
}
|
||||
|
||||
// Fetch VPN-enabled apps from AppOps.
|
||||
AppOpsManager aom = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
|
||||
List<AppOpsManager.PackageOps> apps =
|
||||
aom.getPackagesForOps(new int[] {OP_ACTIVATE_VPN, OP_ACTIVATE_PLATFORM_VPN});
|
||||
if (apps != null) {
|
||||
@@ -603,7 +610,7 @@ public class VpnSettings extends RestrictedSettingsFragment implements
|
||||
allowed = true;
|
||||
}
|
||||
}
|
||||
if (allowed) {
|
||||
if (allowed || isAdvancedVpn(featureProvider, pkg.getPackageName(), context)) {
|
||||
result.add(new AppVpnInfo(userId, pkg.getPackageName()));
|
||||
}
|
||||
}
|
||||
@@ -613,6 +620,12 @@ public class VpnSettings extends RestrictedSettingsFragment implements
|
||||
return result;
|
||||
}
|
||||
|
||||
private static boolean isAdvancedVpn(AdvancedVpnFeatureProvider featureProvider,
|
||||
String packageName, Context context) {
|
||||
return featureProvider.isAdvancedVpnSupported(context)
|
||||
&& TextUtils.equals(packageName, featureProvider.getAdvancedVpnPackageName());
|
||||
}
|
||||
|
||||
private static List<VpnProfile> loadVpnProfiles() {
|
||||
final ArrayList<VpnProfile> result = Lists.newArrayList();
|
||||
|
||||
|
Reference in New Issue
Block a user