From 669a604bb6d165e56226404426ad8abbfb98c274 Mon Sep 17 00:00:00 2001 From: Roman Tsisyk Date: Thu, 7 Jan 2021 00:36:03 +0300 Subject: [PATCH] [android] Fix crash in GetBatteryLevel()/GetBatteryLevel() Follow up aa7ef4a189ea81892f5c1caca90b28bef6236020 Fixes #60 Fixes #81 Signed-off-by: Roman Tsisyk --- android/gradle.properties | 4 ++-- android/jni/com/mapswithme/platform/Platform.cpp | 11 ++++++----- android/src/com/mapswithme/util/BatteryState.java | 6 ++++++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/android/gradle.properties b/android/gradle.properties index 69ce1fc1ca..3011d73030 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -2,8 +2,8 @@ propMinSdkVersion=21 propTargetSdkVersion=29 propCompileSdkVersion=29 propBuildToolsVersion=27.0.3 -propVersionCode=1049 -propVersionName=10.4.9 +propVersionCode=1050 +propVersionName=10.5.0 propDebugNdkFlags=V=1 NDK_DEBUG=1 DEBUG=1 propReleaseNdkFlags=V=1 NDK_DEBUG=0 PRODUCTION=1 propMultiDexVersion=2.0.1 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..9dbbe64931 100644 --- a/android/src/com/mapswithme/util/BatteryState.java +++ b/android/src/com/mapswithme/util/BatteryState.java @@ -50,6 +50,12 @@ public final class BatteryState return batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, 0); } + @ChargingStatus + public static int getChargingStatus(@NonNull Context context) + { + return getState(context).getChargingStatus(); + } + @ChargingStatus private static int getChargingStatus(@NonNull Intent batteryStatus) {