• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.DynamicAvailabilityPreferenceController;
21 import com.android.settings.core.lifecycle.Lifecycle;
22 import com.android.settings.overlay.FeatureFactory;
23 
24 public class EnterprisePrivacyPreferenceController extends DynamicAvailabilityPreferenceController {
25 
26     private static final String KEY_ENTERPRISE_PRIVACY = "enterprise_privacy";
27     private final EnterprisePrivacyFeatureProvider mFeatureProvider;
28 
EnterprisePrivacyPreferenceController(Context context, Lifecycle lifecycle)29     public EnterprisePrivacyPreferenceController(Context context, Lifecycle lifecycle) {
30         super(context, lifecycle);
31         mFeatureProvider = FeatureFactory.getFactory(context)
32                 .getEnterprisePrivacyFeatureProvider(context);
33     }
34 
35     @Override
updateState(Preference preference)36     public void updateState(Preference preference) {
37         final String organizationName = mFeatureProvider.getDeviceOwnerOrganizationName();
38         if (organizationName == null) {
39             preference.setSummary(R.string.enterprise_privacy_settings_summary_generic);
40         } else {
41             preference.setSummary(mContext.getResources().getString(
42                     R.string.enterprise_privacy_settings_summary_with_name, organizationName));
43         }
44     }
45 
46     @Override
isAvailable()47     public boolean isAvailable() {
48         final boolean available = mFeatureProvider.hasDeviceOwner();
49         notifyOnAvailabilityUpdate(available);
50         return available;
51     }
52 
53     @Override
getPreferenceKey()54     public String getPreferenceKey() {
55         return KEY_ENTERPRISE_PRIVACY;
56     }
57 }
58