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.applications;
18 
19 
20 import android.content.Context;
21 import android.permission.PermissionControllerManager;
22 import android.provider.DeviceConfig;
23 
24 import androidx.lifecycle.Lifecycle;
25 import androidx.lifecycle.LifecycleObserver;
26 import androidx.lifecycle.OnLifecycleEvent;
27 import androidx.preference.Preference;
28 import androidx.preference.PreferenceScreen;
29 
30 import com.android.settings.R;
31 import com.android.settings.core.BasePreferenceController;
32 
33 import com.google.common.annotations.VisibleForTesting;
34 
35 import java.util.concurrent.Executor;
36 
37 /**
38  * Preference controller for handling the app battery usage list preference.
39  */
40 public final class AppBatteryUsagePreferenceController extends BasePreferenceController
41         implements LifecycleObserver {
42     private static final String TAG = "AppBatteryUsagePreferenceController";
43     private boolean mEnableAppBatteryUsagePage;
44 
AppBatteryUsagePreferenceController(Context context, String preferenceKey)45     public AppBatteryUsagePreferenceController(Context context, String preferenceKey) {
46         super(context, preferenceKey);
47         mEnableAppBatteryUsagePage =
48                 mContext.getResources().getBoolean(R.bool.config_app_battery_usage_list_enabled);
49     }
50 
51     @Override
getAvailabilityStatus()52     public int getAvailabilityStatus() {
53         return mEnableAppBatteryUsagePage ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
54     }
55 }