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

Commit bd9a65cc authored by Jeremy Goldman's avatar Jeremy Goldman Committed by Android (Google) Code Review
Browse files

Merge "Gear Preference on VPN page includes subtitle if the vpn is an insecure type" into sc-dev

parents 3bc4e930 ab8eeca9
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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>
+35 −2
Original line number Diff line number Diff line
@@ -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);
        }
        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);
        }
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -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);
            }