From ab8eeca96652192a97b841d868aa1939a3b85c1d Mon Sep 17 00:00:00 2001 From: Jeremy Goldman Date: Thu, 11 Mar 2021 13:29:46 +0800 Subject: [PATCH] Gear Preference on VPN page includes subtitle if the vpn is an insecure type Test: atest SettingsUnitTests Screenshot: https://screenshot.googleplex.com/BWfUf6hcHNnbLvH Bug: 176821216 Change-Id: I2bee3ba100bfe636221264492a2ce98b6a664cd5 Merged-In: I2bee3ba100bfe636221264492a2ce98b6a664cd5 (cherry picked from commit 39222497094a59e1d40b2209bb382eef6d920a75) --- res/values/strings.xml | 2 + .../settings/vpn2/ManageablePreference.java | 37 ++++++++++++++++++- .../android/settings/vpn2/VpnSettings.java | 2 + 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index d306ea9b5b5..16629d5ccbc 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -7054,6 +7054,8 @@ Not supported by this app Always-on active + + not secure VPN Block connections without VPN diff --git a/src/com/android/settings/vpn2/ManageablePreference.java b/src/com/android/settings/vpn2/ManageablePreference.java index 68971f2f2fb..c65073f2d60 100644 --- a/src/com/android/settings/vpn2/ManageablePreference.java +++ b/src/com/android/settings/vpn2/ManageablePreference.java @@ -16,15 +16,20 @@ package com.android.settings.vpn2; +import static android.text.Spanned.SPAN_EXCLUSIVE_INCLUSIVE; + import android.content.Context; import android.content.res.Resources; import android.os.UserHandle; import android.os.UserManager; +import android.text.SpannableString; import android.text.TextUtils; +import android.text.style.ForegroundColorSpan; import android.util.AttributeSet; import com.android.settings.R; import com.android.settings.widget.GearPreference; +import com.android.settingslib.Utils; /** * This class sets appropriate enabled state and user admin message when userId is set @@ -34,6 +39,7 @@ public abstract class ManageablePreference extends GearPreference { public static int STATE_NONE = -1; boolean mIsAlwaysOn = false; + boolean mIsInsecureVpn = false; int mState = STATE_NONE; int mUserId; @@ -57,6 +63,10 @@ public abstract class ManageablePreference extends GearPreference { return mIsAlwaysOn; } + public boolean isInsecureVpn() { + return mIsInsecureVpn; + } + public int getState() { return mState; } @@ -76,9 +86,20 @@ public abstract class ManageablePreference extends GearPreference { } } + /** + * Set whether the VPN associated with this preference has an insecure type. + * By default the value will be False. + */ + public void setInsecureVpn(boolean isInsecureVpn) { + if (mIsInsecureVpn != isInsecureVpn) { + mIsInsecureVpn = isInsecureVpn; + updateSummary(); + } + } + /** * Update the preference summary string (see {@see Preference#setSummary}) with a string - * reflecting connection status and always-on setting. + * reflecting connection status, always-on setting and whether the vpn is insecure. * * State is not shown for {@code STATE_NONE}. */ @@ -91,6 +112,18 @@ public abstract class ManageablePreference extends GearPreference { summary = TextUtils.isEmpty(summary) ? alwaysOnString : res.getString( R.string.join_two_unrelated_items, summary, alwaysOnString); } - setSummary(summary); + if (mIsInsecureVpn) { + final String insecureString = res.getString(R.string.vpn_insecure_summary); + summary = TextUtils.isEmpty(summary) ? insecureString : res.getString( + R.string.join_two_unrelated_items, summary, insecureString); + + SpannableString summarySpan = new SpannableString(summary); + final int colorError = Utils.getColorErrorDefaultColor(getContext()); + summarySpan.setSpan(new ForegroundColorSpan(colorError), 0, summary.length(), + SPAN_EXCLUSIVE_INCLUSIVE); + setSummary(summarySpan); + } else { + setSummary(summary); + } } } diff --git a/src/com/android/settings/vpn2/VpnSettings.java b/src/com/android/settings/vpn2/VpnSettings.java index 7635733d77f..cdc65372aed 100644 --- a/src/com/android/settings/vpn2/VpnSettings.java +++ b/src/com/android/settings/vpn2/VpnSettings.java @@ -294,6 +294,7 @@ public class VpnSettings extends RestrictedSettingsFragment implements p.setState(LegacyVpnPreference.STATE_NONE); } p.setAlwaysOn(lockdownVpnKey != null && lockdownVpnKey.equals(profile.key)); + p.setInsecureVpn(VpnProfile.isLegacyType(profile.type)); updates.add(p); } @@ -303,6 +304,7 @@ public class VpnSettings extends RestrictedSettingsFragment implements LegacyVpnPreference p = mSettings.findOrCreatePreference(stubProfile, false); p.setState(vpn.state); p.setAlwaysOn(lockdownVpnKey != null && lockdownVpnKey.equals(vpn.key)); + p.setInsecureVpn(VpnProfile.isLegacyType(stubProfile.type)); updates.add(p); }