1 /*
2  * Copyright (C) 2021 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.enterprise;
18 
19 import android.content.Context;
20 
21 import androidx.preference.Preference;
22 
23 import com.android.internal.annotations.VisibleForTesting;
24 import com.android.settings.core.PreferenceControllerMixin;
25 import com.android.settingslib.core.AbstractPreferenceController;
26 
27 import java.util.Objects;
28 
29 /** Preference controller which displays a financed preference for financed devices. */
30 public class FinancedPrivacyPreferenceController extends AbstractPreferenceController implements
31         PreferenceControllerMixin {
32 
33     private static final String PREF_KEY_FINANCED_PRIVACY = "financed_privacy";
34     private final PrivacyPreferenceControllerHelper mPrivacyPreferenceControllerHelper;
35     private final String mPreferenceKey;
36 
FinancedPrivacyPreferenceController(Context context)37     public FinancedPrivacyPreferenceController(Context context) {
38         this(Objects.requireNonNull(context), PREF_KEY_FINANCED_PRIVACY);
39     }
40 
FinancedPrivacyPreferenceController(Context context, String key)41     public FinancedPrivacyPreferenceController(Context context, String key) {
42         this(Objects.requireNonNull(context), new PrivacyPreferenceControllerHelper(context), key);
43     }
44 
45     @VisibleForTesting
FinancedPrivacyPreferenceController(Context context, PrivacyPreferenceControllerHelper privacyPreferenceControllerHelper, String key)46     FinancedPrivacyPreferenceController(Context context,
47             PrivacyPreferenceControllerHelper privacyPreferenceControllerHelper, String key) {
48         super(Objects.requireNonNull(context));
49         mPrivacyPreferenceControllerHelper = Objects.requireNonNull(
50                 privacyPreferenceControllerHelper);
51         this.mPreferenceKey = key;
52     }
53 
54     @Override
updateState(Preference preference)55     public void updateState(Preference preference) {
56         mPrivacyPreferenceControllerHelper.updateState(preference);
57     }
58 
59     @Override
isAvailable()60     public boolean isAvailable() {
61         return mPrivacyPreferenceControllerHelper.isFinancedDevice();
62     }
63 
64     @Override
getPreferenceKey()65     public String getPreferenceKey() {
66         return mPreferenceKey;
67     }
68 }
69