Loading res/layout/preference_vpn.xmldeleted 100644 → 0 +0 −39 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2015 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="match_parent" android:orientation="horizontal"> <View android:id="@+id/divider_manage" android:layout_width="2dip" android:layout_height="match_parent" android:layout_marginTop="5dip" android:layout_marginBottom="5dip" android:background="@android:drawable/divider_horizontal_dark" /> <ImageView android:id="@+id/manage" android:layout_width="wrap_content" android:layout_height="fill_parent" android:paddingStart="16dip" android:paddingEnd="16dip" android:src="@drawable/ic_sysbar_quicksettings" android:contentDescription="@string/settings_label" android:layout_gravity="center" android:background="?android:attr/selectableItemBackground" /> </LinearLayout> res/values/strings.xml +4 −0 Original line number Diff line number Diff line Loading @@ -3396,6 +3396,8 @@ because it runs in the same process as <xliff:g id="additional_apps_list">%2$s</xliff:g>:</string> <!-- [CHAR_LIMIT=NONE] Format to put together two items in a list. --> <string name="join_two_items"><xliff:g id="first_item">%1$s</xliff:g> and <xliff:g id="second_item">%2$s</xliff:g></string> <!-- [CHAR_LIMIT=NONE] Format to put together two unrelated items in a list when "and" is not an appropriate conjunction for these 2 items --> <string name="join_two_unrelated_items"><xliff:g id="first_item">%1$s</xliff:g>, <xliff:g id="second_item">%2$s</xliff:g></string> <!-- [CHAR_LIMIT=NONE] Format to put the last item at the end of a series of 3 or more items in a list --> <string name="join_many_items_last"><xliff:g id="all_but_last_item">%1$s</xliff:g> and <xliff:g id="last_item">%2$s</xliff:g></string> <!-- [CHAR_LIMIT=NONE] Format to put the first item at the start of a series of 3 or more items in a list --> Loading Loading @@ -5207,6 +5209,8 @@ <string name="vpn_menu_lockdown">Always-on VPN</string> <!-- Placeholder when VPN settings is open but no VPNs have been created. [CHAR LIMIT=100] --> <string name="vpn_no_vpns_added">No VPNs added.</string> <!-- Preference summary for active always-on vpn [CHAR LIMIT=40] --> <string name="vpn_always_on_active">Always-on active</string> <!-- Summary describing the always-on VPN feature. [CHAR LIMIT=NONE] --> <string name="vpn_lockdown_summary">Select a VPN profile to always remain connected to. Network traffic will only be allowed when connected to this VPN.</string> Loading src/com/android/settings/vpn2/AppPreference.java +11 −18 Original line number Diff line number Diff line Loading @@ -22,11 +22,9 @@ import android.content.pm.PackageManager; import android.graphics.drawable.Drawable; import android.os.UserHandle; import android.support.v7.preference.Preference; import android.view.View.OnClickListener; import com.android.internal.net.LegacyVpnInfo; import com.android.internal.net.VpnConfig; import com.android.settings.R; /** * {@link android.support.v7.preference.Preference} containing information about a VPN Loading @@ -39,10 +37,15 @@ public class AppPreference extends ManageablePreference { private int mState = STATE_DISCONNECTED; private String mPackageName; private String mName; private int mUserId = UserHandle.USER_NULL; public AppPreference(Context context, OnClickListener onManage) { super(context, null /* attrs */, onManage); public AppPreference(Context context) { super(context, null /* attrs */); } @Override public void setUserId(int userId) { super.setUserId(userId); update(); } public PackageInfo getPackageInfo() { Loading @@ -67,15 +70,6 @@ public class AppPreference extends ManageablePreference { update(); } public int getUserId() { return mUserId; } public void setUserId(int userId) { mUserId = userId; update(); } public int getState() { return mState; } Loading @@ -90,8 +84,7 @@ public class AppPreference extends ManageablePreference { return; } final String[] states = getContext().getResources().getStringArray(R.array.vpn_states); setSummary(mState != STATE_DISCONNECTED ? states[mState] : ""); setSummary(getSummaryString(mState == STATE_DISCONNECTED ? STATE_NONE : mState)); mName = mPackageName; Drawable icon = null; Loading Loading @@ -140,9 +133,9 @@ public class AppPreference extends ManageablePreference { result = mUserId - another.mUserId; } return result; } else if (preference instanceof ConfigPreference) { } else if (preference instanceof LegacyVpnPreference) { // Use comparator from ConfigPreference ConfigPreference another = (ConfigPreference) preference; LegacyVpnPreference another = (LegacyVpnPreference) preference; return -another.compareTo(this); } else { return super.compareTo(preference); Loading src/com/android/settings/vpn2/ConfigPreference.java→src/com/android/settings/vpn2/LegacyVpnPreference.java +19 −19 Original line number Diff line number Diff line Loading @@ -18,28 +18,24 @@ package com.android.settings.vpn2; import android.content.Context; import android.support.v7.preference.Preference; import android.view.View.OnClickListener; import android.view.View; import com.android.internal.net.VpnProfile; import com.android.settings.R; import static com.android.internal.net.LegacyVpnInfo.STATE_CONNECTED; /** * {@link android.support.v7.preference.Preference} referencing a VPN * configuration. Tracks the underlying profile and its connection * state. * {@link android.support.v7.preference.Preference} tracks the underlying legacy vpn profile and * its connection state. */ public class ConfigPreference extends ManageablePreference { public static int STATE_NONE = -1; public class LegacyVpnPreference extends ManageablePreference { private VpnProfile mProfile; /** One of the STATE_* fields from LegacyVpnInfo, or STATE_NONE */ private int mState = STATE_NONE; ConfigPreference(Context context, OnClickListener onManage) { super(context, null /* attrs */, onManage); LegacyVpnPreference(Context context) { super(context, null /* attrs */); } public VpnProfile getProfile() { Loading @@ -57,12 +53,7 @@ public class ConfigPreference extends ManageablePreference { } private void update() { if (mState == STATE_NONE) { setSummary(""); } else { final String[] states = getContext().getResources().getStringArray(R.array.vpn_states); setSummary(states[mState]); } setSummary(getSummaryString(mState)); if (mProfile != null) { setIcon(R.mipmap.ic_launcher_settings); setTitle(mProfile.name); Loading @@ -72,8 +63,8 @@ public class ConfigPreference extends ManageablePreference { @Override public int compareTo(Preference preference) { if (preference instanceof ConfigPreference) { ConfigPreference another = (ConfigPreference) preference; if (preference instanceof LegacyVpnPreference) { LegacyVpnPreference another = (LegacyVpnPreference) preference; int result; if ((result = another.mState - mState) == 0 && (result = mProfile.name.compareToIgnoreCase(another.mProfile.name)) == 0 && Loading @@ -93,5 +84,14 @@ public class ConfigPreference extends ManageablePreference { return super.compareTo(preference); } } @Override public void onClick(View v) { if (v.getId() == R.id.settings_button && isDisabledByAdmin()) { performClick(); return; } super.onClick(v); } } No newline at end of file src/com/android/settings/vpn2/ManageablePreference.java +46 −18 Original line number Diff line number Diff line Loading @@ -17,35 +17,63 @@ package com.android.settings.vpn2; import android.content.Context; import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceViewHolder; import android.content.res.Resources; import android.os.UserHandle; import android.os.UserManager; import android.text.TextUtils; import android.util.AttributeSet; import android.view.View; import android.view.View.OnClickListener; import com.android.settings.GearPreference; import com.android.settings.R; /** * Preference with an additional gear icon. Touching the gear icon triggers an * onChange event. * This class sets appropriate enabled state and user admin message when userId is set */ public class ManageablePreference extends Preference { OnClickListener mListener; View mManageView; public abstract class ManageablePreference extends GearPreference { public ManageablePreference(Context context, AttributeSet attrs, OnClickListener onManage) { public static int STATE_NONE = -1; boolean mIsAlwaysOn = false; int mUserId; public ManageablePreference(Context context, AttributeSet attrs) { super(context, attrs); mListener = onManage; setPersistent(false); setOrder(0); setWidgetLayoutResource(R.layout.preference_vpn); setUserId(UserHandle.myUserId()); } public int getUserId() { return mUserId; } public void setUserId(int userId) { mUserId = userId; checkRestrictionAndSetDisabled(UserManager.DISALLOW_CONFIG_VPN, userId); } public boolean isAlwaysOn() { return mIsAlwaysOn; } public void setAlwaysOn(boolean isEnabled) { mIsAlwaysOn = isEnabled; } @Override public void onBindViewHolder(PreferenceViewHolder view) { mManageView = view.findViewById(R.id.manage); mManageView.setOnClickListener(mListener); mManageView.setTag(this); super.onBindViewHolder(view); /** * State is not shown for {@code STATE_NONE} * * @return summary string showing current connection state and always-on-vpn state */ protected String getSummaryString(int state) { final Resources res = getContext().getResources(); final String[] states = res.getStringArray(R.array.vpn_states); String summary = state == STATE_NONE ? "" : states[state]; if (mIsAlwaysOn) { final String alwaysOnString = res.getString(R.string.vpn_always_on_active); summary = TextUtils.isEmpty(summary) ? alwaysOnString : res.getString( R.string.join_two_unrelated_items, summary, alwaysOnString); } return summary; } } Loading
res/layout/preference_vpn.xmldeleted 100644 → 0 +0 −39 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2015 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="match_parent" android:orientation="horizontal"> <View android:id="@+id/divider_manage" android:layout_width="2dip" android:layout_height="match_parent" android:layout_marginTop="5dip" android:layout_marginBottom="5dip" android:background="@android:drawable/divider_horizontal_dark" /> <ImageView android:id="@+id/manage" android:layout_width="wrap_content" android:layout_height="fill_parent" android:paddingStart="16dip" android:paddingEnd="16dip" android:src="@drawable/ic_sysbar_quicksettings" android:contentDescription="@string/settings_label" android:layout_gravity="center" android:background="?android:attr/selectableItemBackground" /> </LinearLayout>
res/values/strings.xml +4 −0 Original line number Diff line number Diff line Loading @@ -3396,6 +3396,8 @@ because it runs in the same process as <xliff:g id="additional_apps_list">%2$s</xliff:g>:</string> <!-- [CHAR_LIMIT=NONE] Format to put together two items in a list. --> <string name="join_two_items"><xliff:g id="first_item">%1$s</xliff:g> and <xliff:g id="second_item">%2$s</xliff:g></string> <!-- [CHAR_LIMIT=NONE] Format to put together two unrelated items in a list when "and" is not an appropriate conjunction for these 2 items --> <string name="join_two_unrelated_items"><xliff:g id="first_item">%1$s</xliff:g>, <xliff:g id="second_item">%2$s</xliff:g></string> <!-- [CHAR_LIMIT=NONE] Format to put the last item at the end of a series of 3 or more items in a list --> <string name="join_many_items_last"><xliff:g id="all_but_last_item">%1$s</xliff:g> and <xliff:g id="last_item">%2$s</xliff:g></string> <!-- [CHAR_LIMIT=NONE] Format to put the first item at the start of a series of 3 or more items in a list --> Loading Loading @@ -5207,6 +5209,8 @@ <string name="vpn_menu_lockdown">Always-on VPN</string> <!-- Placeholder when VPN settings is open but no VPNs have been created. [CHAR LIMIT=100] --> <string name="vpn_no_vpns_added">No VPNs added.</string> <!-- Preference summary for active always-on vpn [CHAR LIMIT=40] --> <string name="vpn_always_on_active">Always-on active</string> <!-- Summary describing the always-on VPN feature. [CHAR LIMIT=NONE] --> <string name="vpn_lockdown_summary">Select a VPN profile to always remain connected to. Network traffic will only be allowed when connected to this VPN.</string> Loading
src/com/android/settings/vpn2/AppPreference.java +11 −18 Original line number Diff line number Diff line Loading @@ -22,11 +22,9 @@ import android.content.pm.PackageManager; import android.graphics.drawable.Drawable; import android.os.UserHandle; import android.support.v7.preference.Preference; import android.view.View.OnClickListener; import com.android.internal.net.LegacyVpnInfo; import com.android.internal.net.VpnConfig; import com.android.settings.R; /** * {@link android.support.v7.preference.Preference} containing information about a VPN Loading @@ -39,10 +37,15 @@ public class AppPreference extends ManageablePreference { private int mState = STATE_DISCONNECTED; private String mPackageName; private String mName; private int mUserId = UserHandle.USER_NULL; public AppPreference(Context context, OnClickListener onManage) { super(context, null /* attrs */, onManage); public AppPreference(Context context) { super(context, null /* attrs */); } @Override public void setUserId(int userId) { super.setUserId(userId); update(); } public PackageInfo getPackageInfo() { Loading @@ -67,15 +70,6 @@ public class AppPreference extends ManageablePreference { update(); } public int getUserId() { return mUserId; } public void setUserId(int userId) { mUserId = userId; update(); } public int getState() { return mState; } Loading @@ -90,8 +84,7 @@ public class AppPreference extends ManageablePreference { return; } final String[] states = getContext().getResources().getStringArray(R.array.vpn_states); setSummary(mState != STATE_DISCONNECTED ? states[mState] : ""); setSummary(getSummaryString(mState == STATE_DISCONNECTED ? STATE_NONE : mState)); mName = mPackageName; Drawable icon = null; Loading Loading @@ -140,9 +133,9 @@ public class AppPreference extends ManageablePreference { result = mUserId - another.mUserId; } return result; } else if (preference instanceof ConfigPreference) { } else if (preference instanceof LegacyVpnPreference) { // Use comparator from ConfigPreference ConfigPreference another = (ConfigPreference) preference; LegacyVpnPreference another = (LegacyVpnPreference) preference; return -another.compareTo(this); } else { return super.compareTo(preference); Loading
src/com/android/settings/vpn2/ConfigPreference.java→src/com/android/settings/vpn2/LegacyVpnPreference.java +19 −19 Original line number Diff line number Diff line Loading @@ -18,28 +18,24 @@ package com.android.settings.vpn2; import android.content.Context; import android.support.v7.preference.Preference; import android.view.View.OnClickListener; import android.view.View; import com.android.internal.net.VpnProfile; import com.android.settings.R; import static com.android.internal.net.LegacyVpnInfo.STATE_CONNECTED; /** * {@link android.support.v7.preference.Preference} referencing a VPN * configuration. Tracks the underlying profile and its connection * state. * {@link android.support.v7.preference.Preference} tracks the underlying legacy vpn profile and * its connection state. */ public class ConfigPreference extends ManageablePreference { public static int STATE_NONE = -1; public class LegacyVpnPreference extends ManageablePreference { private VpnProfile mProfile; /** One of the STATE_* fields from LegacyVpnInfo, or STATE_NONE */ private int mState = STATE_NONE; ConfigPreference(Context context, OnClickListener onManage) { super(context, null /* attrs */, onManage); LegacyVpnPreference(Context context) { super(context, null /* attrs */); } public VpnProfile getProfile() { Loading @@ -57,12 +53,7 @@ public class ConfigPreference extends ManageablePreference { } private void update() { if (mState == STATE_NONE) { setSummary(""); } else { final String[] states = getContext().getResources().getStringArray(R.array.vpn_states); setSummary(states[mState]); } setSummary(getSummaryString(mState)); if (mProfile != null) { setIcon(R.mipmap.ic_launcher_settings); setTitle(mProfile.name); Loading @@ -72,8 +63,8 @@ public class ConfigPreference extends ManageablePreference { @Override public int compareTo(Preference preference) { if (preference instanceof ConfigPreference) { ConfigPreference another = (ConfigPreference) preference; if (preference instanceof LegacyVpnPreference) { LegacyVpnPreference another = (LegacyVpnPreference) preference; int result; if ((result = another.mState - mState) == 0 && (result = mProfile.name.compareToIgnoreCase(another.mProfile.name)) == 0 && Loading @@ -93,5 +84,14 @@ public class ConfigPreference extends ManageablePreference { return super.compareTo(preference); } } @Override public void onClick(View v) { if (v.getId() == R.id.settings_button && isDisabledByAdmin()) { performClick(); return; } super.onClick(v); } } No newline at end of file
src/com/android/settings/vpn2/ManageablePreference.java +46 −18 Original line number Diff line number Diff line Loading @@ -17,35 +17,63 @@ package com.android.settings.vpn2; import android.content.Context; import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceViewHolder; import android.content.res.Resources; import android.os.UserHandle; import android.os.UserManager; import android.text.TextUtils; import android.util.AttributeSet; import android.view.View; import android.view.View.OnClickListener; import com.android.settings.GearPreference; import com.android.settings.R; /** * Preference with an additional gear icon. Touching the gear icon triggers an * onChange event. * This class sets appropriate enabled state and user admin message when userId is set */ public class ManageablePreference extends Preference { OnClickListener mListener; View mManageView; public abstract class ManageablePreference extends GearPreference { public ManageablePreference(Context context, AttributeSet attrs, OnClickListener onManage) { public static int STATE_NONE = -1; boolean mIsAlwaysOn = false; int mUserId; public ManageablePreference(Context context, AttributeSet attrs) { super(context, attrs); mListener = onManage; setPersistent(false); setOrder(0); setWidgetLayoutResource(R.layout.preference_vpn); setUserId(UserHandle.myUserId()); } public int getUserId() { return mUserId; } public void setUserId(int userId) { mUserId = userId; checkRestrictionAndSetDisabled(UserManager.DISALLOW_CONFIG_VPN, userId); } public boolean isAlwaysOn() { return mIsAlwaysOn; } public void setAlwaysOn(boolean isEnabled) { mIsAlwaysOn = isEnabled; } @Override public void onBindViewHolder(PreferenceViewHolder view) { mManageView = view.findViewById(R.id.manage); mManageView.setOnClickListener(mListener); mManageView.setTag(this); super.onBindViewHolder(view); /** * State is not shown for {@code STATE_NONE} * * @return summary string showing current connection state and always-on-vpn state */ protected String getSummaryString(int state) { final Resources res = getContext().getResources(); final String[] states = res.getStringArray(R.array.vpn_states); String summary = state == STATE_NONE ? "" : states[state]; if (mIsAlwaysOn) { final String alwaysOnString = res.getString(R.string.vpn_always_on_active); summary = TextUtils.isEmpty(summary) ? alwaysOnString : res.getString( R.string.join_two_unrelated_items, summary, alwaysOnString); } return summary; } }