Bug 727477 - Workaround Galaxy Nexus bug that prevented Battery API to work. r=dougt

This is also changing the default values sent if the device has no battery.
This commit is contained in:
Mounir Lamouri 2012-02-22 00:30:51 +01:00
Родитель 2224cef968
Коммит 8a0a3831de
1 изменённых файлов: 10 добавлений и 2 удалений

Просмотреть файл

@ -47,6 +47,7 @@ import android.content.Context;
import android.content.Intent;
import android.os.BatteryManager;
import android.os.Build;
import android.os.SystemClock;
public class GeckoBatteryManager
@ -77,7 +78,14 @@ public class GeckoBatteryManager
boolean previousCharging = isCharging();
double previousLevel = getLevel();
if (intent.getBooleanExtra(BatteryManager.EXTRA_PRESENT, false)) {
// NOTE: it might not be common (in 2012) but technically, Android can run
// on a device that has no battery so we want to make sure it's not the case
// before bothering checking for battery state.
// However, the Galaxy Nexus phone advertizes itself as battery-less which
// force us to special-case the logic.
// See the Google bug: https://code.google.com/p/android/issues/detail?id=22035
if (intent.getBooleanExtra(BatteryManager.EXTRA_PRESENT, false) ||
Build.MODEL.equals("Galaxy Nexus")) {
int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
if (plugged == -1) {
sCharging = kDefaultCharging;
@ -140,7 +148,7 @@ public class GeckoBatteryManager
} else {
sLevel = kDefaultLevel;
sCharging = kDefaultCharging;
sRemainingTime = kDefaultRemainingTime;
sRemainingTime = 0;
}
/*