Connect VPN warning help icon with the network & internet page.
New VpnInfoPreference created to control the presence or absence
of the warning icon based on the vpn type.
The VpnPreferenceController type casts the preference based on
whether the provider model is enabled. It also detects legacy vpns
by using the LegacyVpnProfileStore, and comparing VPN profile
usernames with the active VPN config's user.
Screenshot: https://screenshot.googleplex.com/AfGrH8wRusTvbf4
Test: atest -c SettingsUnitTests
Bug: Bug: 176821216
Change-Id: I1aa93be5b90b404d9d9cb9bf47ea76fdc9aad401
Merged-In: I1aa93be5b90b404d9d9cb9bf47ea76fdc9aad401
(cherry picked from commit 7a68eb3b5e
)
This commit is contained in:
@@ -27,6 +27,8 @@ import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
import android.provider.SettingsSlicesContract;
|
||||
import android.security.Credentials;
|
||||
import android.security.LegacyVpnProfileStore;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
|
||||
@@ -36,8 +38,11 @@ import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.net.LegacyVpnInfo;
|
||||
import com.android.internal.net.VpnConfig;
|
||||
import com.android.internal.net.VpnProfile;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.vpn2.VpnInfoPreference;
|
||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
@@ -147,6 +152,10 @@ public class VpnPreferenceController extends AbstractPreferenceController
|
||||
} else {
|
||||
summary = getNameForVpnConfig(vpn, UserHandle.of(uid));
|
||||
}
|
||||
// Optionally add warning icon if an insecure VPN is present.
|
||||
if (Utils.isProviderModelEnabled(mContext) && mPreference instanceof VpnInfoPreference) {
|
||||
((VpnInfoPreference) mPreference).setInsecureVpn(hasInsecureVpn());
|
||||
}
|
||||
ThreadUtils.postOnMainThread(() -> mPreference.setSummary(summary));
|
||||
}
|
||||
|
||||
@@ -167,6 +176,20 @@ public class VpnPreferenceController extends AbstractPreferenceController
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected boolean hasInsecureVpn() {
|
||||
for (String key : LegacyVpnProfileStore.list(Credentials.VPN)) {
|
||||
final VpnProfile profile = VpnProfile.decode(key,
|
||||
LegacyVpnProfileStore.get(Credentials.VPN + key));
|
||||
// Return whether any profile is an insecure type.
|
||||
if (VpnProfile.isLegacyType(profile.type)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// We did not find any insecure VPNs.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Copied from SystemUI::SecurityControllerImpl
|
||||
private final ConnectivityManager.NetworkCallback
|
||||
mNetworkCallback = new ConnectivityManager.NetworkCallback() {
|
||||
|
Reference in New Issue
Block a user