• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.display;
18 
19 import android.content.Context;
20 
21 import androidx.annotation.NonNull;
22 import androidx.annotation.Nullable;
23 import androidx.preference.Preference;
24 import androidx.preference.PreferenceScreen;
25 
26 import com.android.settings.accessibility.Flags;
27 import com.android.settingslib.RestrictedPreferenceHelper;
28 import com.android.settingslib.RestrictedPreferenceHelperProvider;
29 import com.android.settingslib.core.lifecycle.Lifecycle;
30 
31 /**
32  * The top-level preference controller that updates the adaptive brightness level in the
33  * SetupWizard.
34  */
35 public class BrightnessLevelPreferenceControllerForSetupWizard extends
36         BrightnessLevelPreferenceController {
37 
38     private RestrictedPreferenceHelper mRestrictedPreferenceHelper;
39 
BrightnessLevelPreferenceControllerForSetupWizard(@onNull Context context, @Nullable Lifecycle lifecycle)40     public BrightnessLevelPreferenceControllerForSetupWizard(@NonNull Context context,
41             @Nullable Lifecycle lifecycle) {
42         super(context, lifecycle);
43     }
44 
isRestricted()45     private boolean isRestricted() {
46         if (mRestrictedPreferenceHelper == null) {
47             return false;
48         }
49         return mRestrictedPreferenceHelper.isDisabledByAdmin()
50                 || mRestrictedPreferenceHelper.isDisabledByEcm();
51     }
52 
53     @Override
displayPreference(PreferenceScreen screen)54     public void displayPreference(PreferenceScreen screen) {
55         final Preference preference = screen.findPreference(getPreferenceKey());
56         if (preference instanceof RestrictedPreferenceHelperProvider helperProvider) {
57             mRestrictedPreferenceHelper = helperProvider.getRestrictedPreferenceHelper();
58         }
59         super.displayPreference(screen);
60     }
61 
62     @Override
63     @AvailabilityStatus
getAvailabilityStatus()64     public int getAvailabilityStatus() {
65         if (!Flags.addBrightnessSettingsInSuw() || isRestricted()) {
66             return CONDITIONALLY_UNAVAILABLE;
67         }
68         return super.getAvailabilityStatus();
69     }
70 }