int32_t getAndroidApiLevel()

in cxx/fbjni/detail/References.cpp [40:58]


int32_t getAndroidApiLevel() {
  // This is called from the static local initializer in
  // isObjectRefType(), and creating fbjni references can call
  // isObjectRefType().  So, to avoid recursively entering the block
  // where the static is initialized (which is undefined behavior), we
  // avoid using standard fbjni references here.

  JNIEnv* env = Environment::current();
  jclass cls = detail::findClass(env, "android/os/Build$VERSION");
  jfieldID field = env->GetStaticFieldID(cls, "SDK_INT",
                                         jtype_traits<jint>::kDescriptor.c_str());
  if (!field) {
    env->DeleteLocalRef(cls);
  }
  FACEBOOK_JNI_THROW_EXCEPTION_IF(!field);
  int32_t ret = env->GetStaticIntField(cls, field);
  env->DeleteLocalRef(cls);
  return ret;
}