Bug 1322650 - Add jni::GetAPIVersion() to get Android API version r=jchen draft
authorJames Willcox <snorp@snorp.net>
Tue, 11 Apr 2017 10:05:04 -0500
changeset 572886 c8b3fe7b2713a057eb2a1f91351558381d7f0984
parent 572885 8c0ccc9ef41397957b81e47d71e8029f316d64d6
child 572887 db97a82c47d3f3e671926b8401323125fd26eaac
push id57212
push userbmo:snorp@snorp.net
push dateThu, 04 May 2017 21:08:01 +0000
reviewersjchen
bugs1322650
milestone55.0a1
Bug 1322650 - Add jni::GetAPIVersion() to get Android API version r=jchen MozReview-Commit-ID: EfPMfS7RmcH
widget/android/AndroidBridge.cpp
widget/android/bindings/AndroidBuild-classes.txt
widget/android/bindings/moz.build
widget/android/jni/Utils.cpp
widget/android/jni/Utils.h
--- 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__