RESTRICT AUTOMERGE Let advanced VPN profile visible immediately before the user consent to use VPN feature
- This CL will check whether advanced VPN apk is exist or not, and if so then show the preference of advanced VPN in the "Settings > Network & internet > VPN". Bug: 239984274 Test: atest -c VpnSettingsTest Change-Id: I8c11c7f2079d6ebec6c691b8bf2fb26dfc450663
This commit is contained in:
@@ -26,6 +26,7 @@ import android.app.AppOpsManager;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.ConnectivityManager;
|
||||
@@ -534,9 +535,32 @@ public class VpnSettings extends RestrictedSettingsFragment implements
|
||||
pref.setOnPreferenceClickListener(this);
|
||||
mAppPreferences.put(app, pref);
|
||||
}
|
||||
enableAdvancedVpnGearIconIfNecessary(pref);
|
||||
return pref;
|
||||
}
|
||||
|
||||
private void enableAdvancedVpnGearIconIfNecessary(AppPreference pref) {
|
||||
Context context = getContext();
|
||||
if (!isAdvancedVpn(mFeatureProvider, pref.getPackageName(), context)) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean isEnabled = false;
|
||||
AppOpsManager appOpsManager = getContext().getSystemService(AppOpsManager.class);
|
||||
List<AppOpsManager.PackageOps> apps =
|
||||
appOpsManager.getPackagesForOps(
|
||||
new int[] {OP_ACTIVATE_VPN, OP_ACTIVATE_PLATFORM_VPN});
|
||||
if (apps != null) {
|
||||
for (AppOpsManager.PackageOps pkg : apps) {
|
||||
if (isAdvancedVpn(mFeatureProvider, pkg.getPackageName(), context)) {
|
||||
isEnabled = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
pref.setOnGearClickListener(isEnabled ? mGearListener : null);
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
private Map<String, LegacyVpnInfo> getConnectedLegacyVpns() {
|
||||
mConnectedLegacyVpn = mVpnManager.getLegacyVpnInfo(UserHandle.myUserId());
|
||||
@@ -593,6 +617,19 @@ public class VpnSettings extends RestrictedSettingsFragment implements
|
||||
profileIds = Collections.singleton(UserHandle.myUserId());
|
||||
}
|
||||
|
||||
if (featureProvider.isAdvancedVpnSupported(context)) {
|
||||
PackageManager pm = context.getPackageManager();
|
||||
try {
|
||||
ApplicationInfo appInfo =
|
||||
pm.getApplicationInfo(
|
||||
featureProvider.getAdvancedVpnPackageName(), /* flags= */ 0);
|
||||
int userId = UserHandle.getUserId(appInfo.uid);
|
||||
result.add(new AppVpnInfo(userId, featureProvider.getAdvancedVpnPackageName()));
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
Log.e(LOG_TAG, "Advanced VPN package name not found.", e);
|
||||
}
|
||||
}
|
||||
|
||||
List<AppOpsManager.PackageOps> apps =
|
||||
aom.getPackagesForOps(new int[] {OP_ACTIVATE_VPN, OP_ACTIVATE_PLATFORM_VPN});
|
||||
if (apps != null) {
|
||||
@@ -602,6 +639,9 @@ public class VpnSettings extends RestrictedSettingsFragment implements
|
||||
// Skip packages for users outside of our profile group.
|
||||
continue;
|
||||
}
|
||||
if (isAdvancedVpn(featureProvider, pkg.getPackageName(), context)) {
|
||||
continue;
|
||||
}
|
||||
// Look for a MODE_ALLOWED permission to activate VPN.
|
||||
boolean allowed = false;
|
||||
for (AppOpsManager.OpEntry op : pkg.getOps()) {
|
||||
@@ -610,7 +650,7 @@ public class VpnSettings extends RestrictedSettingsFragment implements
|
||||
allowed = true;
|
||||
}
|
||||
}
|
||||
if (allowed || isAdvancedVpn(featureProvider, pkg.getPackageName(), context)) {
|
||||
if (allowed) {
|
||||
result.add(new AppVpnInfo(userId, pkg.getPackageName()));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user