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 BatteryUtils mBatteryUtils; 33 BatteryInfoLoader(Context context)34 public BatteryInfoLoader(Context context) { 35 super(context); 36 mBatteryUtils = BatteryUtils.getInstance(context); 37 } 38 39 @Override onDiscardResult(BatteryInfo result)40 protected void onDiscardResult(BatteryInfo result) {} 41 42 @Override loadInBackground()43 public BatteryInfo loadInBackground() { 44 return mBatteryUtils.getBatteryInfo(LOG_TAG); 45 } 46 } 47