1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 * except in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the 10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 11 * KIND, either express or implied. See the License for the specific language governing 12 * permissions and limitations under the License. 13 */ 14 package com.android.settings.enterprise; 15 16 import static android.app.admin.DevicePolicyResources.Strings.Settings.ALWAYS_ON_VPN_DEVICE; 17 import static android.app.admin.DevicePolicyResources.Strings.Settings.ALWAYS_ON_VPN_PERSONAL_PROFILE; 18 19 import android.app.admin.DevicePolicyManager; 20 import android.content.Context; 21 22 import androidx.preference.Preference; 23 24 import com.android.settings.R; 25 import com.android.settings.core.PreferenceControllerMixin; 26 import com.android.settings.overlay.FeatureFactory; 27 import com.android.settingslib.core.AbstractPreferenceController; 28 29 public class AlwaysOnVpnCurrentUserPreferenceController 30 extends AbstractPreferenceController implements PreferenceControllerMixin { 31 32 private static final String KEY_ALWAYS_ON_VPN_PRIMARY_USER = "always_on_vpn_primary_user"; 33 private final EnterprisePrivacyFeatureProvider mFeatureProvider; 34 private final DevicePolicyManager mDevicePolicyManager; 35 AlwaysOnVpnCurrentUserPreferenceController(Context context)36 public AlwaysOnVpnCurrentUserPreferenceController(Context context) { 37 super(context); 38 mFeatureProvider = FeatureFactory.getFeatureFactory() 39 .getEnterprisePrivacyFeatureProvider(); 40 mDevicePolicyManager = context.getSystemService(DevicePolicyManager.class); 41 } 42 43 @Override updateState(Preference preference)44 public void updateState(Preference preference) { 45 if (mFeatureProvider.isInCompMode()) { 46 preference.setTitle( 47 mDevicePolicyManager.getResources().getString( 48 ALWAYS_ON_VPN_PERSONAL_PROFILE, 49 () -> mContext.getString( 50 R.string.enterprise_privacy_always_on_vpn_personal))); 51 } else { 52 preference.setTitle( 53 mDevicePolicyManager.getResources().getString(ALWAYS_ON_VPN_DEVICE, 54 () -> mContext.getString( 55 R.string.enterprise_privacy_always_on_vpn_device))); 56 } 57 } 58 59 @Override isAvailable()60 public boolean isAvailable() { 61 return mFeatureProvider.isAlwaysOnVpnSetInCurrentUser(); 62 } 63 64 @Override getPreferenceKey()65 public String getPreferenceKey() { 66 return KEY_ALWAYS_ON_VPN_PRIMARY_USER; 67 } 68 } 69