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.content.browser; | 5 package org.chromium.content.browser; |
6 | 6 |
7 import android.content.BroadcastReceiver; | 7 import android.content.BroadcastReceiver; |
8 import android.content.Context; | 8 import android.content.Context; |
9 import android.content.Intent; | 9 import android.content.Intent; |
10 import android.content.IntentFilter; | 10 import android.content.IntentFilter; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 gotBatteryStatus(true, 0, Double.POSITIVE_INFINITY, 1); | 97 gotBatteryStatus(true, 0, Double.POSITIVE_INFINITY, 1); |
98 return; | 98 return; |
99 } | 99 } |
100 | 100 |
101 boolean charging = pluggedStatus != 0; | 101 boolean charging = pluggedStatus != 0; |
102 int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1); | 102 int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1); |
103 boolean batteryFull = status == BatteryManager.BATTERY_STATUS_FULL; | 103 boolean batteryFull = status == BatteryManager.BATTERY_STATUS_FULL; |
104 | 104 |
105 int current = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); | 105 int current = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); |
106 int max = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1); | 106 int max = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1); |
107 double level = (double)current / (double)max; | 107 double level = (double) current / (double) max; |
108 if (level < 0 || level > 1) { | 108 if (level < 0 || level > 1) { |
109 // Sanity check, assume default value in this case. | 109 // Sanity check, assume default value in this case. |
110 level = 1.0; | 110 level = 1.0; |
111 } | 111 } |
112 | 112 |
113 // Currently Android does not provide charging/discharging time, as a wor
k-around | 113 // Currently Android does not provide charging/discharging time, as a wor
k-around |
114 // we could compute it manually based on level delta. | 114 // we could compute it manually based on level delta. |
115 // TODO(timvolodine): add proper projection for chargingTime, discharging
Time | 115 // TODO(timvolodine): add proper projection for chargingTime, discharging
Time |
116 // (see crbug.com/401553). | 116 // (see crbug.com/401553). |
117 double chargingTime = (charging & batteryFull) ? 0 : Double.POSITIVE_INFI
NITY; | 117 double chargingTime = (charging & batteryFull) ? 0 : Double.POSITIVE_INFI
NITY; |
(...skipping 21 matching lines...) Expand all Loading... |
139 } | 139 } |
140 } | 140 } |
141 | 141 |
142 /** | 142 /** |
143 * Native JNI call | 143 * Native JNI call |
144 * see content/browser/battery_status/battery_status_manager.cc | 144 * see content/browser/battery_status/battery_status_manager.cc |
145 */ | 145 */ |
146 private native void nativeGotBatteryStatus(long nativeBatteryStatusManagerAn
droid, | 146 private native void nativeGotBatteryStatus(long nativeBatteryStatusManagerAn
droid, |
147 boolean charging, double chargingTime, double dischargingTime, doubl
e level); | 147 boolean charging, double chargingTime, double dischargingTime, doubl
e level); |
148 } | 148 } |
OLD | NEW |