diff --git a/android/jni/com/mapswithme/platform/Platform.cpp b/android/jni/com/mapswithme/platform/Platform.cpp index af2ebd288c..f36bf641b4 100644 --- a/android/jni/com/mapswithme/platform/Platform.cpp +++ b/android/jni/com/mapswithme/platform/Platform.cpp @@ -127,9 +127,10 @@ Platform::ChargingStatus Platform::GetChargingStatus() ASSERT(clazzBatteryState, ()); static jmethodID const getChargingMethodId = - jni::GetStaticMethodID(env, clazzBatteryState, "getChargingStatus", "()I"); + jni::GetStaticMethodID(env, clazzBatteryState, "getChargingStatus", "(Landroid/content/Context;)I"); + jobject context = android::Platform::Instance().GetContext(); return static_cast( - env->CallStaticIntMethod(clazzBatteryState, getChargingMethodId)); + env->CallStaticIntMethod(clazzBatteryState, getChargingMethodId, context)); } uint8_t Platform::GetBatteryLevel() @@ -143,9 +144,9 @@ uint8_t Platform::GetBatteryLevel() ASSERT(clazzBatteryState, ()); static auto const getLevelMethodId = - jni::GetStaticMethodID(env, clazzBatteryState, "getLevel", "()I"); - - return static_cast(env->CallStaticIntMethod(clazzBatteryState, getLevelMethodId)); + jni::GetStaticMethodID(env, clazzBatteryState, "getLevel", "(Landroid/content/Context;)I"); + jobject context = android::Platform::Instance().GetContext(); + return static_cast(env->CallStaticIntMethod(clazzBatteryState, getLevelMethodId, context)); } namespace platform diff --git a/android/src/com/mapswithme/util/BatteryState.java b/android/src/com/mapswithme/util/BatteryState.java index ca39ebc50e..64be40c1d6 100644 --- a/android/src/com/mapswithme/util/BatteryState.java +++ b/android/src/com/mapswithme/util/BatteryState.java @@ -38,6 +38,8 @@ public final class BatteryState return new State(getLevel(batteryStatus), getChargingStatus(batteryStatus)); } + // Called from JNI. + @SuppressWarnings("unused") @IntRange(from=0, to=100) public static int getLevel(@NonNull Context context) { @@ -50,6 +52,14 @@ public final class BatteryState return batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, 0); } + // Called from JNI. + @SuppressWarnings("unused") + @ChargingStatus + public static int getChargingStatus(@NonNull Context context) + { + return getState(context).getChargingStatus(); + } + @ChargingStatus private static int getChargingStatus(@NonNull Intent batteryStatus) {