/* -*- Mode: c++; c-basic-offset: 2; tab-width: 20; indent-tabs-mode: nil; -*- * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
void AndroidBridge::ConstructBridge() { /* NSS hack -- bionic doesn't handle recursive unloads correctly, * because library finalizer functions are called with the dynamic * linker lock still held. This results in a deadlock when trying * to call dlclose() while we're already inside dlclose(). * Conveniently, NSS has an env var that can prevent it from unloading.
*/
putenv(const_cast<char*>("NSS_DISABLE_UNLOAD=1"));
MOZ_ASSERT(!sBridge);
sBridge = new AndroidBridge();
}
void AndroidBridge::DeconstructBridge() { if (sBridge) { delete sBridge; // AndroidBridge destruction requires sBridge to still be valid, // so we set sBridge to nullptr after deleting it.
sBridge = nullptr;
}
}
mMessageQueue = java::GeckoThread::MsgQueue(); auto msgQueueClass = jni::Class::LocalRef::Adopt(
jEnv, jEnv->GetObjectClass(mMessageQueue.Get())); // mMessageQueueNext must not be null
mMessageQueueNext =
GetMethodID(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;");
}
uint32_t len = aPattern.Length(); if (!len) {
ALOG_BRIDGE(" invalid 0-length array"); return;
}
// It's clear if this worth special-casing, but it creates less // java junk, so dodges the GC. if (len == 1) {
jlong d = aPattern[0]; if (d < 0) {
ALOG_BRIDGE(" invalid vibration duration < 0"); return;
}
java::GeckoAppShell::Vibrate(d); return;
}
// First element of the array vibrate() expects is how long to wait // *before* vibrating. For us, this is always 0.
// To prevent calling too many methods through JNI, the Java method returns // an array of double even if we actually want a double and a boolean. auto arr = java::GeckoAppShell::GetCurrentBatteryInformation();
// To prevent calling too many methods through JNI, the Java method returns // an array of double even if we actually want an integer, a boolean, and an // integer.
auto arr = java::GeckoAppShell::GetCurrentNetworkInformation();
jobject AndroidBridge::GetGlobalContextRef() { // The context object can change, so get a fresh copy every time. auto context = java::GeckoAppShell::GetApplicationContext();
sGlobalContext = jni::Object::GlobalRef(context).Forget();
MOZ_ASSERT(sGlobalContext); return sGlobalContext;
}
if (mMessageQueueMessages) { auto msg = jni::Object::LocalRef::Adopt(
env, env->GetObjectField(mMessageQueue.Get(), mMessageQueueMessages)); // if queue.mMessages is null, queue.next() will block, which we don't // want. It turns out to be an order of magnitude more performant to do // this extra check here and block less vs. one fewer checks here and // more blocking. if (!msg) { returnfalse;
}
}
auto msg = jni::Object::LocalRef::Adopt(
env, env->CallObjectMethod(mMessageQueue.Get(), mMessageQueueNext)); if (!msg) { returnfalse;
}
return java::GeckoThread::PumpMessageLoop(msg);
}
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.