diff options
author | newt <newt@chromium.org> | 2015-03-04 12:13:06 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-03-04 20:13:34 +0000 |
commit | ad10b9efa0237699081d15c931ecf26820460c16 (patch) | |
tree | f3059967a7056777ee71477e160cde3886f04a7d | |
parent | b4394e13c04a366f11d3f3903c1427ae2a977863 (diff) | |
download | chromium_src-ad10b9efa0237699081d15c931ecf26820460c16.zip chromium_src-ad10b9efa0237699081d15c931ecf26820460c16.tar.gz chromium_src-ad10b9efa0237699081d15c931ecf26820460c16.tar.bz2 |
Address NewApi warning in device/battery.
This moves the Lollipop-specific code in BatteryStatusManager into a
separate method and annotates it with @TargetApi(LOLLIPOP) so appease
Android lint.
BUG=411461
Review URL: https://codereview.chromium.org/975963003
Cr-Commit-Position: refs/heads/master@{#319115}
-rw-r--r-- | build/android/lint/suppressions.xml | 1 | ||||
-rw-r--r-- | device/battery/android/java/src/org/chromium/device/battery/BatteryStatusManager.java | 58 |
2 files changed, 34 insertions, 25 deletions
diff --git a/build/android/lint/suppressions.xml b/build/android/lint/suppressions.xml index 11efa06..5f3ad43 100644 --- a/build/android/lint/suppressions.xml +++ b/build/android/lint/suppressions.xml @@ -85,7 +85,6 @@ Still reading? <ignore path="org/chromium/content/browser/accessibility/LollipopAccessibilityInjector.class"/> <ignore path="org/chromium/content/browser/accessibility/LollipopAccessibilityInjector$*.class"/> <ignore path="org/chromium/content/browser/accessibility/LollipopBrowserAccessibilityManager.class"/> - <ignore path="org/chromium/device/battery/BatteryStatusManager.class"/> <ignore path="org/chromium/media/AudioManagerAndroid.class"/> <ignore path="org/chromium/media/MediaCodecBridge.class"/> <ignore path="org/chromium/media/MediaDrmBridge.class"/> diff --git a/device/battery/android/java/src/org/chromium/device/battery/BatteryStatusManager.java b/device/battery/android/java/src/org/chromium/device/battery/BatteryStatusManager.java index b94c7f0..87fd280 100644 --- a/device/battery/android/java/src/org/chromium/device/battery/BatteryStatusManager.java +++ b/device/battery/android/java/src/org/chromium/device/battery/BatteryStatusManager.java @@ -4,6 +4,7 @@ package org.chromium.device.battery; +import android.annotation.TargetApi; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -133,35 +134,44 @@ class BatteryStatusManager { double chargingTimeSeconds = (charging && batteryFull) ? 0 : Double.POSITIVE_INFINITY; double dischargingTimeSeconds = Double.POSITIVE_INFINITY; - if (mLollipopBatteryManager != null) { - // On Lollipop we can provide a better estimate for chargingTime and dischargingTime. - double remainingCapacityRatio = mLollipopBatteryManager.getIntProperty( - BatteryManager.BATTERY_PROPERTY_CAPACITY) / 100.0; - double batteryCapacityMicroAh = mLollipopBatteryManager.getIntProperty( - BatteryManager.BATTERY_PROPERTY_CHARGE_COUNTER); - double averageCurrentMicroA = mLollipopBatteryManager.getIntProperty( - BatteryManager.BATTERY_PROPERTY_CURRENT_AVERAGE); - - if (charging) { - if (chargingTimeSeconds == Double.POSITIVE_INFINITY && averageCurrentMicroA > 0) { - double chargeFromEmptyHours = batteryCapacityMicroAh / averageCurrentMicroA; - chargingTimeSeconds = - Math.ceil((1 - remainingCapacityRatio) * chargeFromEmptyHours * 3600.0); - } - } else { - if (averageCurrentMicroA < 0) { - double dischargeFromFullHours = batteryCapacityMicroAh / -averageCurrentMicroA; - dischargingTimeSeconds = - Math.floor(remainingCapacityRatio * dischargeFromFullHours * 3600.0); - } - } - } - BatteryStatus batteryStatus = new BatteryStatus(); batteryStatus.charging = charging; batteryStatus.chargingTime = chargingTimeSeconds; batteryStatus.dischargingTime = dischargingTimeSeconds; batteryStatus.level = level; + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + updateBatteryStatusForLollipop(batteryStatus); + } + mCallback.onBatteryStatusChanged(batteryStatus); } + + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + private void updateBatteryStatusForLollipop(BatteryStatus batteryStatus) { + assert mLollipopBatteryManager != null; + + // On Lollipop we can provide a better estimate for chargingTime and dischargingTime. + double remainingCapacityRatio = mLollipopBatteryManager.getIntProperty( + BatteryManager.BATTERY_PROPERTY_CAPACITY) / 100.0; + double batteryCapacityMicroAh = mLollipopBatteryManager.getIntProperty( + BatteryManager.BATTERY_PROPERTY_CHARGE_COUNTER); + double averageCurrentMicroA = mLollipopBatteryManager.getIntProperty( + BatteryManager.BATTERY_PROPERTY_CURRENT_AVERAGE); + + if (batteryStatus.charging) { + if (batteryStatus.chargingTime == Double.POSITIVE_INFINITY + && averageCurrentMicroA > 0) { + double chargeFromEmptyHours = batteryCapacityMicroAh / averageCurrentMicroA; + batteryStatus.chargingTime = + Math.ceil((1 - remainingCapacityRatio) * chargeFromEmptyHours * 3600.0); + } + } else { + if (averageCurrentMicroA < 0) { + double dischargeFromFullHours = batteryCapacityMicroAh / -averageCurrentMicroA; + batteryStatus.dischargingTime = + Math.floor(remainingCapacityRatio * dischargeFromFullHours * 3600.0); + } + } + } } |