OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.device.battery; | 5 package org.chromium.device.battery; |
6 | 6 |
| 7 import android.annotation.SuppressLint; |
7 import android.annotation.TargetApi; | 8 import android.annotation.TargetApi; |
8 import android.content.BroadcastReceiver; | 9 import android.content.BroadcastReceiver; |
9 import android.content.Context; | 10 import android.content.Context; |
10 import android.content.Intent; | 11 import android.content.Intent; |
11 import android.content.IntentFilter; | 12 import android.content.IntentFilter; |
12 import android.os.BatteryManager; | 13 import android.os.BatteryManager; |
13 import android.os.Build; | 14 import android.os.Build; |
14 import android.util.Log; | 15 import android.util.Log; |
15 | 16 |
16 import org.chromium.base.VisibleForTesting; | 17 import org.chromium.base.VisibleForTesting; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 private boolean mEnabled; | 52 private boolean mEnabled; |
52 | 53 |
53 @VisibleForTesting | 54 @VisibleForTesting |
54 static class AndroidBatteryManagerWrapper { | 55 static class AndroidBatteryManagerWrapper { |
55 private final BatteryManager mBatteryManager; | 56 private final BatteryManager mBatteryManager; |
56 | 57 |
57 protected AndroidBatteryManagerWrapper(BatteryManager batteryManager) { | 58 protected AndroidBatteryManagerWrapper(BatteryManager batteryManager) { |
58 mBatteryManager = batteryManager; | 59 mBatteryManager = batteryManager; |
59 } | 60 } |
60 | 61 |
| 62 @SuppressLint("NewApi") |
61 public int getIntProperty(int id) { | 63 public int getIntProperty(int id) { |
62 return mBatteryManager.getIntProperty(id); | 64 return mBatteryManager.getIntProperty(id); |
63 } | 65 } |
64 } | 66 } |
65 | 67 |
66 private BatteryStatusManager(Context context, BatteryStatusCallback callback
, | 68 private BatteryStatusManager(Context context, BatteryStatusCallback callback
, |
67 boolean ignoreBatteryPresentState, | 69 boolean ignoreBatteryPresentState, |
68 @Nullable AndroidBatteryManagerWrapper batteryManager) { | 70 @Nullable AndroidBatteryManagerWrapper batteryManager) { |
69 mAppContext = context.getApplicationContext(); | 71 mAppContext = context.getApplicationContext(); |
70 mCallback = callback; | 72 mCallback = callback; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 } | 185 } |
184 } else { | 186 } else { |
185 if (averageCurrentMicroA < 0) { | 187 if (averageCurrentMicroA < 0) { |
186 double dischargeFromFullHours = batteryCapacityMicroAh / -averag
eCurrentMicroA; | 188 double dischargeFromFullHours = batteryCapacityMicroAh / -averag
eCurrentMicroA; |
187 batteryStatus.dischargingTime = | 189 batteryStatus.dischargingTime = |
188 Math.floor(remainingCapacityRatio * dischargeFromFullHou
rs * 3600.0); | 190 Math.floor(remainingCapacityRatio * dischargeFromFullHou
rs * 3600.0); |
189 } | 191 } |
190 } | 192 } |
191 } | 193 } |
192 } | 194 } |
OLD | NEW |