• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settings.accounts;
18 
19 import android.content.Context;
20 
21 import androidx.annotation.VisibleForTesting;
22 import androidx.preference.PreferenceScreen;
23 
24 import com.android.settings.core.BasePreferenceController;
25 import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
26 import com.android.settings.overlay.FeatureFactory;
27 import com.android.settingslib.widget.FooterPreference;
28 import com.android.settingslib.widget.FooterPreferenceMixinCompat;
29 
30 public class EnterpriseDisclosurePreferenceController extends BasePreferenceController {
31 
32     private final EnterprisePrivacyFeatureProvider mFeatureProvider;
33     private FooterPreferenceMixinCompat mFooterPreferenceMixin;
34     private PreferenceScreen mScreen;
35 
EnterpriseDisclosurePreferenceController(Context context)36     public EnterpriseDisclosurePreferenceController(Context context) {
37         // Preference key doesn't matter as we are creating the preference in code.
38         super(context, "add_account_enterprise_disclosure_footer");
39 
40         mFeatureProvider = FeatureFactory.getFactory(mContext)
41                 .getEnterprisePrivacyFeatureProvider(mContext);
42     }
43 
setFooterPreferenceMixin(FooterPreferenceMixinCompat footerPreferenceMixin)44     public void setFooterPreferenceMixin(FooterPreferenceMixinCompat footerPreferenceMixin) {
45         mFooterPreferenceMixin = footerPreferenceMixin;
46     }
47 
48     @Override
getAvailabilityStatus()49     public int getAvailabilityStatus() {
50         if (getDisclosure() == null) {
51             return UNSUPPORTED_ON_DEVICE;
52         }
53         return AVAILABLE;
54     }
55 
56     @Override
displayPreference(PreferenceScreen screen)57     public void displayPreference(PreferenceScreen screen) {
58         super.displayPreference(screen);
59         mScreen = screen;
60         addEnterpriseDisclosure();
61     }
62 
63     @VisibleForTesting
getDisclosure()64     CharSequence getDisclosure() {
65         return mFeatureProvider.getDeviceOwnerDisclosure();
66     }
67 
addEnterpriseDisclosure()68     private void addEnterpriseDisclosure() {
69         final CharSequence disclosure = getDisclosure();
70         if (disclosure == null) {
71             return;
72         }
73         final FooterPreference enterpriseDisclosurePreference =
74                 mFooterPreferenceMixin.createFooterPreference();
75         enterpriseDisclosurePreference.setSelectable(false);
76         enterpriseDisclosurePreference.setTitle(disclosure);
77         mScreen.addPreference(enterpriseDisclosurePreference);
78     }
79 }
80