Bug 1322650 - Add jni::GetAPIVersion() to get Android API version r=jchen
☠☠ backed out by a5e2d088c2ed ☠ ☠
authorJames Willcox <snorp@snorp.net>
Tue, 11 Apr 2017 10:05:04 -0500
changeset 357998 4d486c7469eba3ee71aa220cb5a95b4e78a51bcb
parent 357997 4cf8f4d5064c46c36ef21ffc0f2f0979c238b89b
child 357999 31bd912fba5472349b3b1dd49536e901f5955c05
push id31808
push usercbook@mozilla.com
push dateFri, 12 May 2017 12:37:49 +0000
treeherdermozilla-central@030c0a7c8781 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjchen
bugs1322650
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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,2 @@
+[android.os.Build$VERSION]
+<field> = noLiteral:true
\ No newline at end of file
--- 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',
     '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 && IsAvailable()) {
+        apiVersion = java::sdk::VERSION::SDK_INT();
+    }
+    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__