1 /*
2  * Copyright (C) 2017 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 package com.android.settings.fuelgauge;
17 
18 import android.content.Context;
19 
20 import androidx.annotation.VisibleForTesting;
21 
22 import com.android.internal.os.BatteryStatsHelper;
23 import com.android.settingslib.utils.AsyncLoaderCompat;
24 
25 /**
26  * Loader that can be used by classes to load BatteryInfo in a background thread. This loader will
27  * automatically grab enhanced battery estimates if available or fall back to the system estimate
28  * when not available.
29  */
30 public class BatteryInfoLoader extends AsyncLoaderCompat<BatteryInfo>{
31 
32     BatteryStatsHelper mStatsHelper;
33     private static final String LOG_TAG = "BatteryInfoLoader";
34 
35     @VisibleForTesting
36     BatteryUtils batteryUtils;
37 
BatteryInfoLoader(Context context, BatteryStatsHelper batteryStatsHelper)38     public BatteryInfoLoader(Context context, BatteryStatsHelper batteryStatsHelper) {
39         super(context);
40         mStatsHelper = batteryStatsHelper;
41         batteryUtils = BatteryUtils.getInstance(context);
42     }
43 
44     @Override
onDiscardResult(BatteryInfo result)45     protected void onDiscardResult(BatteryInfo result) {
46 
47     }
48 
49     @Override
loadInBackground()50     public BatteryInfo loadInBackground() {
51         return batteryUtils.getBatteryInfo(mStatsHelper, LOG_TAG);
52     }
53 }
54