зеркало из https://github.com/mozilla/gecko-dev.git
Bug 699742 - (4/4) battery.level should be a double (android backend). r=cjones
This commit is contained in:
Родитель
a586195b8a
Коммит
7157bc2786
|
@ -114,7 +114,7 @@ public class GeckoAppShell
|
|||
|
||||
public static native void processNextNativeEvent();
|
||||
|
||||
public static native void notifyBatteryChange(float aLevel, boolean aCharging);
|
||||
public static native void notifyBatteryChange(double aLevel, boolean aCharging);
|
||||
|
||||
// A looper thread, accessed by GeckoAppShell.getHandler
|
||||
private static class LooperThread extends Thread {
|
||||
|
@ -1628,7 +1628,7 @@ public class GeckoAppShell
|
|||
GeckoBatteryManager.disableNotifications();
|
||||
}
|
||||
|
||||
public static float[] getCurrentBatteryInformation() {
|
||||
public static double[] getCurrentBatteryInformation() {
|
||||
return GeckoBatteryManager.getCurrentInformation();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,11 +50,13 @@ import android.os.BatteryManager;
|
|||
public class GeckoBatteryManager
|
||||
extends BroadcastReceiver
|
||||
{
|
||||
private final static float kDefaultLevel = 1.0f;
|
||||
// Those constants should be keep in sync with the ones in:
|
||||
// dom/battery/Constants.h
|
||||
private final static double kDefaultLevel = 1.0;
|
||||
private final static boolean kDefaultCharging = true;
|
||||
|
||||
private static boolean sNotificationsEnabled = false;
|
||||
private static float sLevel = kDefaultLevel;
|
||||
private static double sLevel = kDefaultLevel;
|
||||
private static boolean sCharging = kDefaultCharging;
|
||||
|
||||
@Override
|
||||
|
@ -65,7 +67,7 @@ public class GeckoBatteryManager
|
|||
}
|
||||
|
||||
boolean previousCharging = isCharging();
|
||||
float previousLevel = getLevel();
|
||||
double previousLevel = getLevel();
|
||||
|
||||
if (intent.getBooleanExtra(BatteryManager.EXTRA_PRESENT, false)) {
|
||||
int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
|
||||
|
@ -78,9 +80,9 @@ public class GeckoBatteryManager
|
|||
sCharging = plugged != 0;
|
||||
}
|
||||
|
||||
// We need two floats because sLevel is a float.
|
||||
float current = (float)intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
|
||||
float max = (float)intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
|
||||
// We need two doubles because sLevel is a double.
|
||||
double current = (double)intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
|
||||
double max = (double)intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
|
||||
if (current == -1 || max == -1) {
|
||||
Log.e("GeckoBatteryManager", "Failed to get battery level!");
|
||||
sLevel = kDefaultLevel;
|
||||
|
@ -110,7 +112,7 @@ public class GeckoBatteryManager
|
|||
return sCharging;
|
||||
}
|
||||
|
||||
public static float getLevel() {
|
||||
public static double getLevel() {
|
||||
return sLevel;
|
||||
}
|
||||
|
||||
|
@ -122,7 +124,7 @@ public class GeckoBatteryManager
|
|||
sNotificationsEnabled = false;
|
||||
}
|
||||
|
||||
public static float[] getCurrentInformation() {
|
||||
return new float[] { getLevel(), isCharging() ? 1.0f : 0.0f };
|
||||
public static double[] getCurrentInformation() {
|
||||
return new double[] { getLevel(), isCharging() ? 1.0 : 0.0 };
|
||||
}
|
||||
}
|
||||
|
|
|
@ -241,7 +241,7 @@ SHELL_WRAPPER1(onChangeNetworkLinkStatus, jstring)
|
|||
SHELL_WRAPPER1(reportJavaCrash, jstring)
|
||||
SHELL_WRAPPER0(executeNextRunnable)
|
||||
SHELL_WRAPPER1(cameraCallbackBridge, jbyteArray)
|
||||
SHELL_WRAPPER2(notifyBatteryChange, jfloat, jboolean);
|
||||
SHELL_WRAPPER2(notifyBatteryChange, jdouble, jboolean);
|
||||
|
||||
static void * xul_handle = NULL;
|
||||
static time_t apk_mtime = 0;
|
||||
|
|
|
@ -159,7 +159,7 @@ AndroidBridge::Init(JNIEnv *jEnv,
|
|||
jCloseCamera = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "closeCamera", "()V");
|
||||
jEnableBatteryNotifications = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "enableBatteryNotifications", "()V");
|
||||
jDisableBatteryNotifications = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "disableBatteryNotifications", "()V");
|
||||
jGetCurrentBatteryInformation = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getCurrentBatteryInformation", "()[F");
|
||||
jGetCurrentBatteryInformation = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getCurrentBatteryInformation", "()[D");
|
||||
|
||||
jEGLContextClass = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("javax/microedition/khronos/egl/EGLContext"));
|
||||
jEGL10Class = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("javax/microedition/khronos/egl/EGL10"));
|
||||
|
@ -1251,19 +1251,19 @@ AndroidBridge::GetCurrentBatteryInformation(hal::BatteryInformation* aBatteryInf
|
|||
AutoLocalJNIFrame jniFrame;
|
||||
|
||||
// To prevent calling too many methods through JNI, the Java method returns
|
||||
// an array of float even if we actually want a float and a boolean.
|
||||
// an array of double even if we actually want a double and a boolean.
|
||||
jobject obj = mJNIEnv->CallStaticObjectMethod(mGeckoAppShellClass, jGetCurrentBatteryInformation);
|
||||
jfloatArray arr = static_cast<jfloatArray>(obj);
|
||||
jdoubleArray arr = static_cast<jdoubleArray>(obj);
|
||||
if (!arr || mJNIEnv->GetArrayLength(arr) != 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
jfloat* info = mJNIEnv->GetFloatArrayElements(arr, 0);
|
||||
jdouble* info = mJNIEnv->GetDoubleArrayElements(arr, 0);
|
||||
|
||||
aBatteryInfo->level() = info[0];
|
||||
aBatteryInfo->charging() = info[1] == 1.0f;
|
||||
|
||||
mJNIEnv->ReleaseFloatArrayElements(arr, info, 0);
|
||||
mJNIEnv->ReleaseDoubleArrayElements(arr, info, 0);
|
||||
}
|
||||
|
||||
void *
|
||||
|
|
|
@ -74,7 +74,7 @@ extern "C" {
|
|||
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_onChangeNetworkLinkStatus(JNIEnv *, jclass, jstring status);
|
||||
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_reportJavaCrash(JNIEnv *, jclass, jstring stack);
|
||||
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_executeNextRunnable(JNIEnv *, jclass);
|
||||
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_notifyBatteryChange(JNIEnv* jenv, jclass, jfloat, jboolean);
|
||||
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_notifyBatteryChange(JNIEnv* jenv, jclass, jdouble, jboolean);
|
||||
}
|
||||
|
||||
|
||||
|
@ -191,12 +191,12 @@ Java_org_mozilla_gecko_GeckoAppShell_executeNextRunnable(JNIEnv *, jclass)
|
|||
|
||||
NS_EXPORT void JNICALL
|
||||
Java_org_mozilla_gecko_GeckoAppShell_notifyBatteryChange(JNIEnv* jenv, jclass,
|
||||
jfloat aLevel,
|
||||
jdouble aLevel,
|
||||
jboolean aCharging)
|
||||
{
|
||||
class NotifyBatteryChangeRunnable : public nsRunnable {
|
||||
public:
|
||||
NotifyBatteryChangeRunnable(float aLevel, bool aCharging)
|
||||
NotifyBatteryChangeRunnable(double aLevel, bool aCharging)
|
||||
: mLevel(aLevel)
|
||||
, mCharging(aCharging)
|
||||
{}
|
||||
|
@ -207,8 +207,8 @@ Java_org_mozilla_gecko_GeckoAppShell_notifyBatteryChange(JNIEnv* jenv, jclass,
|
|||
}
|
||||
|
||||
private:
|
||||
float mLevel;
|
||||
bool mCharging;
|
||||
double mLevel;
|
||||
bool mCharging;
|
||||
};
|
||||
|
||||
nsCOMPtr<nsIRunnable> runnable = new NotifyBatteryChangeRunnable(aLevel, aCharging);
|
||||
|
|
Загрузка…
Ссылка в новой задаче