Per vpn setting change in VPN list
- Show admin support details when user taps on a cell and user restriction is on - Show always-on-vpn active status in preference summary - User can still open non-configurable per-VPN info page even when user restriction is applied - Rename ConfigPreference to LegacyVpnPreference - Move summary String handling into ManageablePreference - ManageablePreference inherits GearPreference to reuse the code - Don't show disconnect dialog when always-on is enabled BUG=26950700 Change-Id: I37b087879cf3b674df528e7787d7bb1eead3310f
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder view) {
|
||||
mManageView = view.findViewById(R.id.manage);
|
||||
mManageView.setOnClickListener(mListener);
|
||||
mManageView.setTag(this);
|
||||
super.onBindViewHolder(view);
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user