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 3922249709)
This commit is contained in:
Jeremy Goldman
2021-03-11 13:29:46 +08:00
parent 006b8db0b6
commit ab8eeca966
3 changed files with 39 additions and 2 deletions

View File

@@ -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>

View File

@@ -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);
}
}
}

View File

@@ -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);
}