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)
diff --git a/res/values/strings.xml b/res/values/strings.xml
index d306ea9..16629d5 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -7054,6 +7054,8 @@
<string name="vpn_always_on_summary_not_supported">Not supported by this app</string>
<!-- Preference summary for a VPN app that is set to be always-on. [CHAR LIMIT=40] -->
<string name="vpn_always_on_summary_active">Always-on active</string>
+ <!-- Preference summary for a VPN app that has an insecure type. [CHAR LIMIT=40] -->
+ <string name="vpn_insecure_summary">not secure VPN</string>
<!-- Preference title for the toggle that controls whether to force all network connections to
go through VPN. [CHAR LIMIT=40] -->
<string name="vpn_require_connection">Block connections without VPN</string>
diff --git a/src/com/android/settings/vpn2/ManageablePreference.java b/src/com/android/settings/vpn2/ManageablePreference.java
index 68971f2..c65073f 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 static int STATE_NONE = -1;
boolean mIsAlwaysOn = false;
+ boolean mIsInsecureVpn = false;
int mState = STATE_NONE;
int mUserId;
@@ -57,6 +63,10 @@
return mIsAlwaysOn;
}
+ public boolean isInsecureVpn() {
+ return mIsInsecureVpn;
+ }
+
public int getState() {
return mState;
}
@@ -77,8 +87,19 @@
}
/**
+ * 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 @@
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 7635733..cdc6537 100644
--- a/src/com/android/settings/vpn2/VpnSettings.java
+++ b/src/com/android/settings/vpn2/VpnSettings.java
@@ -294,6 +294,7 @@
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 @@
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);
}