Update strings in main VpnPreference.

If there is an insecure VPN, don't display the name of the vpn in the
summary. Instead, display "Not secure" if there is only 1 total vpn
available, and display the number of insecure VPNs + " not secure."

Screenshot: https://screenshot.googleplex.com/9Bxn7frDm7aVHtG
Test: manual test (because the junit test for the controller has not yet
been cherrypicked into sc-dev)
Bug: 176821216
Change-Id: Ie454d9605effd5208457e8c91b08cc382d4992af
This commit is contained in:
Jeremy Goldman
2021-03-24 13:21:58 +08:00
parent 025301da1f
commit de9d641349
2 changed files with 31 additions and 6 deletions

View File

@@ -6398,6 +6398,10 @@
<!-- Title of preference to enter the VPN settings activity --> <!-- Title of preference to enter the VPN settings activity -->
<string name="vpn_settings_title">VPN</string> <string name="vpn_settings_title">VPN</string>
<!-- Title of preference to enter the VPN settings activity [CHAR LIMIT=30] -->
<string name="vpn_settings_insecure_single">Not secure</string>
<!-- Title of preference to enter the VPN settings activity [CHAR LIMIT=30] -->
<string name="vpn_settings_insecure_multiple"><xliff:g id="vpn_count" example="1">%d</xliff:g> not secure</string>
<!-- Title of Adaptive connectivity. Adaptive connectivity is a feature which automatically manages network connections for better battery life and performance. [CHAR LIMIT=60] --> <!-- Title of Adaptive connectivity. Adaptive connectivity is a feature which automatically manages network connections for better battery life and performance. [CHAR LIMIT=60] -->
<string name="adaptive_connectivity_title">Adaptive connectivity</string> <string name="adaptive_connectivity_title">Adaptive connectivity</string>

View File

@@ -124,6 +124,7 @@ public class VpnPreferenceController extends AbstractPreferenceController
// Copied from SystemUI::SecurityControllerImpl // Copied from SystemUI::SecurityControllerImpl
SparseArray<VpnConfig> vpns = new SparseArray<>(); SparseArray<VpnConfig> vpns = new SparseArray<>();
final List<UserInfo> users = mUserManager.getUsers(); final List<UserInfo> users = mUserManager.getUsers();
int connectedLegacyVpnCount = 0;
for (UserInfo user : users) { for (UserInfo user : users) {
VpnConfig cfg = mVpnManager.getVpnConfig(user.id); VpnConfig cfg = mVpnManager.getVpnConfig(user.id);
if (cfg == null) { if (cfg == null) {
@@ -134,6 +135,8 @@ public class VpnPreferenceController extends AbstractPreferenceController
final LegacyVpnInfo legacyVpn = mVpnManager.getLegacyVpnInfo(user.id); final LegacyVpnInfo legacyVpn = mVpnManager.getLegacyVpnInfo(user.id);
if (legacyVpn == null || legacyVpn.state != LegacyVpnInfo.STATE_CONNECTED) { if (legacyVpn == null || legacyVpn.state != LegacyVpnInfo.STATE_CONNECTED) {
continue; continue;
} else {
connectedLegacyVpnCount++;
} }
} }
vpns.put(user.id, cfg); vpns.put(user.id, cfg);
@@ -146,7 +149,7 @@ public class VpnPreferenceController extends AbstractPreferenceController
uid = userInfo.id; uid = userInfo.id;
} }
VpnConfig vpn = vpns.get(uid); VpnConfig vpn = vpns.get(uid);
final String summary; String summary;
if (vpn == null) { if (vpn == null) {
summary = mContext.getString(R.string.vpn_disconnected_summary); summary = mContext.getString(R.string.vpn_disconnected_summary);
} else { } else {
@@ -154,9 +157,26 @@ public class VpnPreferenceController extends AbstractPreferenceController
} }
// Optionally add warning icon if an insecure VPN is present. // Optionally add warning icon if an insecure VPN is present.
if (Utils.isProviderModelEnabled(mContext) && mPreference instanceof VpnInfoPreference) { if (Utils.isProviderModelEnabled(mContext) && mPreference instanceof VpnInfoPreference) {
((VpnInfoPreference) mPreference).setInsecureVpn(hasInsecureVpn()); final int insecureVpnCount = getInsecureVpnCount();
boolean isInsecureVPN = insecureVpnCount > 0;
((VpnInfoPreference) mPreference).setInsecureVpn(isInsecureVPN);
// Set the summary based on the total number of VPNs and insecure VPNs.
if (isInsecureVPN) {
// Add the users and the number of legacy vpns to determine if there is more than
// one vpn, since there can be more than one VPN per user.
final int vpnCount = vpns.size()
+ LegacyVpnProfileStore.list(Credentials.VPN).length
- connectedLegacyVpnCount;
if (vpnCount == 1) {
summary = mContext.getString(R.string.vpn_settings_insecure_single);
} else {
summary = mContext.getString(
R.string.vpn_settings_insecure_multiple, insecureVpnCount);
} }
ThreadUtils.postOnMainThread(() -> mPreference.setSummary(summary)); }
}
final String finalSummary = summary;
ThreadUtils.postOnMainThread(() -> mPreference.setSummary(finalSummary));
} }
@VisibleForTesting @VisibleForTesting
@@ -177,17 +197,18 @@ public class VpnPreferenceController extends AbstractPreferenceController
} }
@VisibleForTesting @VisibleForTesting
protected boolean hasInsecureVpn() { protected int getInsecureVpnCount() {
int count = 0;
for (String key : LegacyVpnProfileStore.list(Credentials.VPN)) { for (String key : LegacyVpnProfileStore.list(Credentials.VPN)) {
final VpnProfile profile = VpnProfile.decode(key, final VpnProfile profile = VpnProfile.decode(key,
LegacyVpnProfileStore.get(Credentials.VPN + key)); LegacyVpnProfileStore.get(Credentials.VPN + key));
// Return whether any profile is an insecure type. // Return whether any profile is an insecure type.
if (VpnProfile.isLegacyType(profile.type)) { if (VpnProfile.isLegacyType(profile.type)) {
return true; count++;
} }
} }
// We did not find any insecure VPNs. // We did not find any insecure VPNs.
return false; return count;
} }
// Copied from SystemUI::SecurityControllerImpl // Copied from SystemUI::SecurityControllerImpl