• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 import android.content.Intent;
20 import android.content.IntentFilter;
21 import android.os.BatteryStats;
22 import android.os.SystemClock;
23 import com.android.internal.os.BatteryStatsHelper;
24 import com.android.settings.overlay.FeatureFactory;
25 import com.android.settings.utils.AsyncLoader;
26 import java.util.ArrayList;
27 import java.util.List;
28 
29 public class DebugEstimatesLoader extends AsyncLoader<List<BatteryInfo>> {
30     private BatteryStatsHelper mStatsHelper;
31 
DebugEstimatesLoader(Context context, BatteryStatsHelper statsHelper)32     public DebugEstimatesLoader(Context context, BatteryStatsHelper statsHelper) {
33         super(context);
34         mStatsHelper = statsHelper;
35     }
36 
37     @Override
onDiscardResult(List<BatteryInfo> result)38     protected void onDiscardResult(List<BatteryInfo> result) {
39 
40     }
41 
42     @Override
loadInBackground()43     public List<BatteryInfo> loadInBackground() {
44         Context context = getContext();
45         PowerUsageFeatureProvider powerUsageFeatureProvider =
46                 FeatureFactory.getFactory(context).getPowerUsageFeatureProvider(context);
47 
48         // get stuff we'll need for both BatteryInfo
49         final long elapsedRealtimeUs = BatteryUtils.convertMsToUs(SystemClock.elapsedRealtime());
50         Intent batteryBroadcast = getContext().registerReceiver(null,
51                 new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
52         BatteryStats stats = mStatsHelper.getStats();
53 
54         BatteryInfo oldinfo = BatteryInfo.getBatteryInfoOld(getContext(), batteryBroadcast,
55                 stats, elapsedRealtimeUs, false);
56 
57         final long timeRemainingEnhanced = BatteryUtils.convertMsToUs(
58                 powerUsageFeatureProvider.getEnhancedBatteryPrediction(getContext()));
59         BatteryInfo newinfo = BatteryInfo.getBatteryInfo(getContext(), batteryBroadcast, stats,
60                 elapsedRealtimeUs, false, timeRemainingEnhanced, true);
61 
62         List<BatteryInfo> infos = new ArrayList<>();
63         infos.add(oldinfo);
64         infos.add(newinfo);
65         return infos;
66     }
67 }
68