mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-17 22:32:51 +00:00
Bug 1049136 - Add native-code awareness of the Java UI thread so we can do thread assertions. r=snorp
This commit is contained in:
parent
80b3b6bf72
commit
c604d4ad5a
@ -183,6 +183,7 @@ public class GeckoAppShell
|
||||
/* The Android-side API: API methods that Android calls */
|
||||
|
||||
// Initialization methods
|
||||
public static native void registerJavaUiThread();
|
||||
public static native void nativeInit();
|
||||
|
||||
// helper methods
|
||||
|
@ -166,6 +166,14 @@ public class GeckoThread extends Thread implements GeckoEventListener {
|
||||
|
||||
String path = initGeckoEnvironment();
|
||||
|
||||
// This can only happen after the call to initGeckoEnvironment
|
||||
// above, because otherwise the JNI code hasn't been loaded yet.
|
||||
ThreadUtils.postToUiThread(new Runnable() {
|
||||
@Override public void run() {
|
||||
GeckoAppShell.registerJavaUiThread();
|
||||
}
|
||||
});
|
||||
|
||||
Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - runGecko");
|
||||
|
||||
String args = addCustomProfileArg(mArgs);
|
||||
|
@ -58,6 +58,25 @@ Java_org_mozilla_gecko_ANRReporter_releaseNativeStack(JNIEnv * arg0, jclass arg1
|
||||
|
||||
#ifdef JNI_STUBS
|
||||
|
||||
typedef void (*Java_org_mozilla_gecko_GeckoAppShell_registerJavaUiThread_t)(JNIEnv *, jclass);
|
||||
static Java_org_mozilla_gecko_GeckoAppShell_registerJavaUiThread_t f_Java_org_mozilla_gecko_GeckoAppShell_registerJavaUiThread;
|
||||
extern "C" NS_EXPORT void JNICALL
|
||||
Java_org_mozilla_gecko_GeckoAppShell_registerJavaUiThread(JNIEnv * arg0, jclass arg1) {
|
||||
if (!f_Java_org_mozilla_gecko_GeckoAppShell_registerJavaUiThread) {
|
||||
arg0->ThrowNew(arg0->FindClass("java/lang/UnsupportedOperationException"),
|
||||
"JNI Function called before it was loaded");
|
||||
return ;
|
||||
}
|
||||
f_Java_org_mozilla_gecko_GeckoAppShell_registerJavaUiThread(arg0, arg1);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef JNI_BINDINGS
|
||||
xul_dlsym("Java_org_mozilla_gecko_GeckoAppShell_registerJavaUiThread", &f_Java_org_mozilla_gecko_GeckoAppShell_registerJavaUiThread);
|
||||
#endif
|
||||
|
||||
#ifdef JNI_STUBS
|
||||
|
||||
typedef void (*Java_org_mozilla_gecko_GeckoAppShell_nativeInit_t)(JNIEnv *, jclass);
|
||||
static Java_org_mozilla_gecko_GeckoAppShell_nativeInit_t f_Java_org_mozilla_gecko_GeckoAppShell_nativeInit;
|
||||
extern "C" NS_EXPORT void JNICALL
|
||||
|
@ -38,7 +38,7 @@ void
|
||||
APZCCallbackHandler::NotifyDefaultPrevented(const ScrollableLayerGuid& aGuid,
|
||||
bool aDefaultPrevented)
|
||||
{
|
||||
if (NS_IsMainThread()) {
|
||||
if (!AndroidBridge::IsJavaUiThread()) {
|
||||
// The notification must reach the APZ on the Java UI thread (aka the
|
||||
// APZ "controller" thread) but we get it from the Gecko thread, so we
|
||||
// have to throw it onto the other thread.
|
||||
@ -48,7 +48,7 @@ APZCCallbackHandler::NotifyDefaultPrevented(const ScrollableLayerGuid& aGuid,
|
||||
return;
|
||||
}
|
||||
|
||||
// This should be running on the Java UI thread
|
||||
MOZ_ASSERT(AndroidBridge::IsJavaUiThread());
|
||||
APZCTreeManager* controller = nsWindow::GetAPZCTreeManager();
|
||||
if (controller) {
|
||||
controller->ContentReceivedTouch(aGuid, aDefaultPrevented);
|
||||
|
@ -47,6 +47,7 @@ using namespace mozilla::widget::android;
|
||||
using namespace mozilla::gfx;
|
||||
|
||||
AndroidBridge* AndroidBridge::sBridge;
|
||||
pthread_t AndroidBridge::sJavaUiThread = -1;
|
||||
static unsigned sJavaEnvThreadIndex = 0;
|
||||
static jobject sGlobalContext = nullptr;
|
||||
static void JavaThreadDetachFunc(void *arg);
|
||||
|
@ -131,6 +131,14 @@ public:
|
||||
LAYER_CLIENT_TYPE_GL = 2 // AndroidGeckoGLLayerClient
|
||||
};
|
||||
|
||||
static void RegisterJavaUiThread() {
|
||||
sJavaUiThread = pthread_self();
|
||||
}
|
||||
|
||||
static bool IsJavaUiThread() {
|
||||
return pthread_equal(pthread_self(), sJavaUiThread);
|
||||
}
|
||||
|
||||
static void ConstructBridge(JNIEnv *jEnv);
|
||||
|
||||
static AndroidBridge *Bridge() {
|
||||
@ -353,6 +361,7 @@ public:
|
||||
static nsresult GetExternalPublicDirectory(const nsAString& aType, nsAString& aPath);
|
||||
|
||||
protected:
|
||||
static pthread_t sJavaUiThread;
|
||||
static AndroidBridge* sBridge;
|
||||
nsTArray<nsCOMPtr<nsIMobileMessageCallback> > mSmsRequests;
|
||||
|
||||
|
@ -58,6 +58,12 @@ extern "C" {
|
||||
* Incoming JNI methods
|
||||
*/
|
||||
|
||||
NS_EXPORT void JNICALL
|
||||
Java_org_mozilla_gecko_GeckoAppShell_registerJavaUiThread(JNIEnv *jenv, jclass jc)
|
||||
{
|
||||
AndroidBridge::RegisterJavaUiThread();
|
||||
}
|
||||
|
||||
NS_EXPORT void JNICALL
|
||||
Java_org_mozilla_gecko_GeckoAppShell_nativeInit(JNIEnv *jenv, jclass jc)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user