Bug 1322650 - Add jni::GetAPIVersion() to get Android API version r=jchen
MozReview-Commit-ID: EfPMfS7RmcH
--- a/widget/android/AndroidBridge.cpp
+++ b/widget/android/AndroidBridge.cpp
@@ -168,19 +168,17 @@ AndroidBridge::AndroidBridge()
jEnv, msgQueueClass.Get(), "next", "()Landroid/os/Message;");
// mMessageQueueMessages may be null (e.g. due to proguard optimization)
mMessageQueueMessages = jEnv->GetFieldID(
msgQueueClass.Get(), "mMessages", "Landroid/os/Message;");
AutoJNIClass string(jEnv, "java/lang/String");
jStringClass = string.getGlobalRef();
- if (!GetStaticIntField("android/os/Build$VERSION", "SDK_INT", &mAPIVersion, jEnv)) {
- ALOG_BRIDGE("Failed to find API version");
- }
+ mAPIVersion = jni::GetAPIVersion();
AutoJNIClass channels(jEnv, "java/nio/channels/Channels");
jChannels = channels.getGlobalRef();
jChannelCreate = channels.getStaticMethod("newChannel", "(Ljava/io/InputStream;)Ljava/nio/channels/ReadableByteChannel;");
AutoJNIClass readableByteChannel(jEnv, "java/nio/channels/ReadableByteChannel");
jReadableByteChannel = readableByteChannel.getGlobalRef();
jByteBufferRead = readableByteChannel.getMethod("read", "(Ljava/nio/ByteBuffer;)I");
new file mode 100644
--- /dev/null
+++ b/widget/android/bindings/AndroidBuild-classes.txt
@@ -0,0 +1,1 @@
+android.os.Build$VERSION
--- a/widget/android/bindings/moz.build
+++ b/widget/android/bindings/moz.build
@@ -5,16 +5,17 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
with Files("**"):
BUG_COMPONENT = ("Firefox for Android", "Graphics, Panning and Zooming")
# List of stems to generate .cpp and .h files for. To add a stem, add it to
# this list and ensure that $(stem)-classes.txt exists in this directory.
generated = [
+ 'AndroidBuild',
'AndroidRect',
'Bundle',
'KeyEvent',
'MediaCodec',
'MotionEvent',
'SurfaceTexture',
'ViewConfiguration'
]
--- a/widget/android/jni/Utils.cpp
+++ b/widget/android/jni/Utils.cpp
@@ -2,16 +2,17 @@
#include "Types.h"
#include <android/log.h>
#include <pthread.h>
#include "mozilla/Assertions.h"
#include "GeneratedJNIWrappers.h"
+#include "AndroidBuild.h"
#include "nsAppShell.h"
#ifdef MOZ_CRASHREPORTER
#include "nsExceptionHandler.h"
#endif
namespace mozilla {
namespace jni {
@@ -307,10 +308,18 @@ void DispatchToGeckoPriorityQueue(Unique
nsAppShell::PostEvent(MakeUnique<AbstractCallEvent>(Move(aCall)));
}
bool IsFennec()
{
return sIsFennec;
}
+int GetAPIVersion() {
+ static int32_t apiVersion = 0;
+ if (!apiVersion) {
+ java::sdk::VERSION::SDK_INT(&apiVersion);
+ }
+ return apiVersion;
+}
+
} // jni
} // mozilla
--- a/widget/android/jni/Utils.h
+++ b/widget/android/jni/Utils.h
@@ -141,12 +141,14 @@ struct AbstractCall
void DispatchToGeckoPriorityQueue(UniquePtr<AbstractCall>&& aCall);
/**
* Returns whether Gecko is running in a Fennec environment, as determined by
* the presence of the GeckoApp class.
*/
bool IsFennec();
+int GetAPIVersion();
+
} // jni
} // mozilla
#endif // mozilla_jni_Utils_h__