void AndroidCameraPrivate::fetchLastPreviewFrame() { QJNIEnvironmentPrivate env; QJNIObjectPrivate data = m_cameraListener.callObjectMethod("lockAndFetchPreviewBuffer", "()[B"); if (!data.isValid()) { m_cameraListener.callMethod<void>("unlockPreviewBuffer"); return; } const int arrayLength = env->GetArrayLength(static_cast<jbyteArray>(data.object())); QByteArray bytes(arrayLength, Qt::Uninitialized); env->GetByteArrayRegion(static_cast<jbyteArray>(data.object()), 0, arrayLength, reinterpret_cast<jbyte *>(bytes.data())); m_cameraListener.callMethod<void>("unlockPreviewBuffer"); emit previewFetched(bytes); }
QList<QByteArray> QAndroidTimeZonePrivate::availableTimeZoneIds() const { QList<QByteArray> availableTimeZoneIdList; QJNIObjectPrivate androidAvailableIdList = QJNIObjectPrivate::callStaticObjectMethod("java.util.TimeZone", "getAvailableIDs", "()[Ljava/lang/String;"); QJNIEnvironmentPrivate jniEnv; int androidTZcount = jniEnv->GetArrayLength( static_cast<jarray>(androidAvailableIdList.object()) ); // need separate jobject and QAndroidJniObject here so that we can delete (DeleteLocalRef) the reference to the jobject // (or else the JNI reference table fills after 512 entries from GetObjectArrayElement) jobject androidTZobject; QJNIObjectPrivate androidTZ; for (int i=0; i<androidTZcount; i++ ) { androidTZobject = jniEnv->GetObjectArrayElement( static_cast<jobjectArray>( androidAvailableIdList.object() ), i ); androidTZ = androidTZobject; availableTimeZoneIdList.append( androidTZ.toString().toUtf8() ); jniEnv->DeleteLocalRef(androidTZobject); } return availableTimeZoneIdList; }
QList<AndroidNetworkInfo> AndroidConnectivityManager::getAllNetworkInfo() const { QJNIEnvironmentPrivate env; QJNIObjectPrivate objArray = m_connectivityManager.callObjectMethod("getAllNetworkInfo", "()[Landroid/net/NetworkInfo;"); QList<AndroidNetworkInfo> list; if (!objArray.isValid()) return list; const jsize length = env->GetArrayLength(static_cast<jarray>(objArray.object())); if (exceptionCheckAndClear(env)) return list; for (int i = 0; i != length; ++i) { jobject lref = env->GetObjectArrayElement(static_cast<jobjectArray>(objArray.object()), i); if (exceptionCheckAndClear(env)) break; list << AndroidNetworkInfo(lref); env->DeleteLocalRef(lref); } return list; }