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.settingslib.utils.AsyncLoaderCompat; 23 24 /** 25 * Loader that can be used by classes to load BatteryInfo in a background thread. This loader will 26 * automatically grab enhanced battery estimates if available or fall back to the system estimate 27 * when not available. 28 */ 29 public class BatteryInfoLoader extends AsyncLoaderCompat<BatteryInfo>{ 30 private static final String LOG_TAG = "BatteryInfoLoader"; 31 32 @VisibleForTesting 33 BatteryUtils mBatteryUtils; 34 BatteryInfoLoader(Context context)35 public BatteryInfoLoader(Context context) { 36 super(context); 37 mBatteryUtils = BatteryUtils.getInstance(context); 38 } 39 40 @Override onDiscardResult(BatteryInfo result)41 protected void onDiscardResult(BatteryInfo result) { 42 43 } 44 45 @Override loadInBackground()46 public BatteryInfo loadInBackground() { 47 return mBatteryUtils.getBatteryInfo(LOG_TAG); 48 } 49 } 50