Files
packages_apps_Settings/src/com/android/settings/vpn2/ManageablePreference.java
Victor Chang 14c2ac4dcb 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
2016-03-21 12:36:44 +00:00

80 lines
2.4 KiB
Java

/*
* 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.
*/
package com.android.settings.vpn2;
import android.content.Context;
import android.content.res.Resources;
import android.os.UserHandle;
import android.os.UserManager;
import android.text.TextUtils;
import android.util.AttributeSet;
import com.android.settings.GearPreference;
import com.android.settings.R;
/**
* This class sets appropriate enabled state and user admin message when userId is set
*/
public abstract class ManageablePreference extends GearPreference {
public static int STATE_NONE = -1;
boolean mIsAlwaysOn = false;
int mUserId;
public ManageablePreference(Context context, AttributeSet attrs) {
super(context, attrs);
setPersistent(false);
setOrder(0);
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;
}
/**
* 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;
}
}