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 android.content.Context; 17 import android.support.v7.preference.Preference; 18 19 import com.android.settings.R; 20 import com.android.settings.core.PreferenceControllerMixin; 21 import com.android.settings.overlay.FeatureFactory; 22 import com.android.settingslib.core.AbstractPreferenceController; 23 24 public class EnterprisePrivacyPreferenceController extends AbstractPreferenceController implements 25 PreferenceControllerMixin { 26 27 private static final String KEY_ENTERPRISE_PRIVACY = "enterprise_privacy"; 28 private final EnterprisePrivacyFeatureProvider mFeatureProvider; 29 EnterprisePrivacyPreferenceController(Context context)30 public EnterprisePrivacyPreferenceController(Context context) { 31 super(context); 32 mFeatureProvider = FeatureFactory.getFactory(context) 33 .getEnterprisePrivacyFeatureProvider(context); 34 } 35 36 @Override updateState(Preference preference)37 public void updateState(Preference preference) { 38 if (preference == null) { 39 return; 40 } 41 final String organizationName = mFeatureProvider.getDeviceOwnerOrganizationName(); 42 if (organizationName == null) { 43 preference.setSummary(R.string.enterprise_privacy_settings_summary_generic); 44 } else { 45 preference.setSummary(mContext.getResources().getString( 46 R.string.enterprise_privacy_settings_summary_with_name, organizationName)); 47 } 48 } 49 50 @Override isAvailable()51 public boolean isAvailable() { 52 return mFeatureProvider.hasDeviceOwner(); 53 } 54 55 @Override getPreferenceKey()56 public String getPreferenceKey() { 57 return KEY_ENTERPRISE_PRIVACY; 58 } 59 } 60