Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit de9d6413 authored by Jeremy Goldman's avatar Jeremy Goldman
Browse files

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
parent 025301da
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -6398,6 +6398,10 @@
    <!-- Title of preference to enter the VPN settings activity -->
    <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] -->
    <string name="adaptive_connectivity_title">Adaptive connectivity</string>
+27 −6
Original line number Diff line number Diff line
@@ -124,6 +124,7 @@ public class VpnPreferenceController extends AbstractPreferenceController
        // Copied from SystemUI::SecurityControllerImpl
        SparseArray<VpnConfig> vpns = new SparseArray<>();
        final List<UserInfo> users = mUserManager.getUsers();
        int connectedLegacyVpnCount = 0;
        for (UserInfo user : users) {
            VpnConfig cfg = mVpnManager.getVpnConfig(user.id);
            if (cfg == null) {
@@ -134,6 +135,8 @@ public class VpnPreferenceController extends AbstractPreferenceController
                final LegacyVpnInfo legacyVpn = mVpnManager.getLegacyVpnInfo(user.id);
                if (legacyVpn == null || legacyVpn.state != LegacyVpnInfo.STATE_CONNECTED) {
                    continue;
                } else {
                    connectedLegacyVpnCount++;
                }
            }
            vpns.put(user.id, cfg);
@@ -146,7 +149,7 @@ public class VpnPreferenceController extends AbstractPreferenceController
            uid = userInfo.id;
        }
        VpnConfig vpn = vpns.get(uid);
        final String summary;
        String summary;
        if (vpn == null) {
            summary = mContext.getString(R.string.vpn_disconnected_summary);
        } else {
@@ -154,9 +157,26 @@ public class VpnPreferenceController extends AbstractPreferenceController
        }
        // Optionally add warning icon if an insecure VPN is present.
        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
@@ -177,17 +197,18 @@ public class VpnPreferenceController extends AbstractPreferenceController
    }

    @VisibleForTesting
    protected boolean hasInsecureVpn() {
    protected int getInsecureVpnCount() {
        int count = 0;
        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;
                count++;
            }
        }
        // We did not find any insecure VPNs.
        return false;
        return count;
    }

    // Copied from SystemUI::SecurityControllerImpl