Closed Bug 2018171 Opened 9 months ago Closed 7 months ago

Investigate impact of MessageQueue behavior change

Categories

(Firefox for Android :: Tooling, task)

All
Android
task

Tracking

()

RESOLVED FIXED

People

(Reporter: mcarare, Assigned: mcarare)

References

Details

(Whiteboard: [fxdroid][group6] )

We need to investigate if any of our code relies on runtime reflection to peek inside MessageQueue.

  • One instance that we will need to address is using Robolectric with @LooperMode(LooperMode.Mode.LEGACY)
  • We need to use Espresso 3.7.0 or newer ( we already use 3.7.0)
  • We need to use Robolectric 4.17 or newer ( we currently use 4.16, but there is no 4.17 as of Feb 20 !? )
Blocks: 2018174
No longer blocks: 2018174
Depends on: 2018178

The Bugbug bot thinks this bug should belong to the 'Firefox for Android::Tooling' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: General → Tooling

Analyzing UiThreadUtils.java in GV androidTest code, this test utility is directly broken and will likely fail or crash on Android 17:

  • It uses reflection in a static initializer to access the private MessageQueue.next() method: sGetNextMessage = MessageQueue.class.getDeclaredMethod("next");
  • In Android 17, next() is part of a new lock-free "DeliQueue" implementation. Calling it via reflection bypasses the new state management logic. Furthermore, if the method signature has changed or been renamed, the static block will throw an IllegalStateException, preventing tests from running. See technical details: https://android-developers.googleblog.com/2026/02/under-hood-android-17s-lock-free.html.

Analyzing GeckoThread.java, it does not appear to use reflection on MessageQueue, only public APIs like Looper.myQueue() and addIdleHandler().

However, GeckoThread class interacts with native code via @WrapForJNI and GeckoLoader.nativeRun.

Looking into references, looks like AndroidBridge.cpp will present a problem when upgrading:

  • It reflects on the private mMessages field and the next() method of the Java MessageQueue.
    mMessageQueueNext =
        GetMethodID(jEnv, msgQueueClass.Get(), "next", "()Landroid/os/Message;");
    
   mMessageQueueMessages = jEnv->GetFieldID(msgQueueClass.Get(), "mMessages",
                                             "Landroid/os/Message;");
  • PumpMessageLoop method is the most impacted since "In the new implementation this field [mMessages] is always null", even if there are messages in the queue.
    if (mMessageQueueMessages) {
      auto msg = jni::Object::LocalRef::Adopt(
          env, env->GetObjectField(mMessageQueue.Get(), mMessageQueueMessages));
      // ...
      if (!msg) {
        return false;}
    }

Possible consequences, as far as I can see from the comments and code, the browser UI can become completely unresponsive, since it will think there are no messages to process and will stop pumping.

See Also: → 2021365

Upon investigation, 2 more bugs were opened, to be handled separately.

https://bugzilla.mozilla.org/show_bug.cgi?id=2021365
https://bugzilla.mozilla.org/show_bug.cgi?id=2021077

Status: ASSIGNED → RESOLVED
Closed: 7 months ago
Resolution: --- → FIXED
See Also: → 2021077
You need to log in before you can comment on or make changes to this bug.