tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 75820b686f382f19f1b68e462befa51d5e369d19
parent be344b7833338e9a654d2e43a31ff47429e1b894
Author: Makoto Kato <m_kato@ga2.so-net.ne.jp>
Date:   Sun, 26 Oct 2025 03:18:51 +0000

Bug 1990660 - Avoid frequency device changed by caching pointing device values. r=geckoview-reviewers,ohall

When running tests on taskcluster, Android emulator often notifes that
virtio (Stylus) driver reports device changed. we have to update
`nsLookAndFeel` that is expensive.

So we should cache pointer capabilities and only update it when it is
changed.

Differential Revision: https://phabricator.services.mozilla.com/D268339

Diffstat:
Mmobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java | 6++----
Mmobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoSystemStateListener.java | 36++++++++++++++++++++++++++++++++++--
Mwidget/android/nsLookAndFeel.cpp | 6+++---
3 files changed, 39 insertions(+), 9 deletions(-)

diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java @@ -1438,9 +1438,8 @@ public class GeckoAppShell { return result; } - @WrapForJNI(calledFrom = "gecko") // For any-pointer and any-hover media queries features. - private static int getAllPointerCapabilities() { + /* package */ static int getAllPointerCapabilities() { int result = NO_POINTER; for (final int deviceId : InputDevice.getDeviceIds()) { @@ -1490,9 +1489,8 @@ public class GeckoAppShell { return result; } - @WrapForJNI(calledFrom = "gecko") // For pointing devices telemetry. - private static int getPointingDeviceKinds() { + /* package */ static int getPointingDeviceKinds() { int result = POINTING_DEVICE_NONE; for (final int deviceId : InputDevice.getDeviceIds()) { diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoSystemStateListener.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoSystemStateListener.java @@ -41,6 +41,8 @@ public class GeckoSystemStateListener implements InputManager.InputDeviceListene private boolean mIsNightMode; private BroadcastReceiver mBroadcastReceiver; private IntentFilter mIntentFilter; + private volatile int mAllPointerCapabilities; + private volatile int mPointingDeviceKinds; @RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE) private ContrastChangeListener mContrastChangeListener; @@ -121,6 +123,9 @@ public class GeckoSystemStateListener implements InputManager.InputDeviceListene & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES; + mAllPointerCapabilities = GeckoAppShell.getAllPointerCapabilities(); + mPointingDeviceKinds = GeckoAppShell.getPointingDeviceKinds(); + mInitialized = true; } @@ -225,6 +230,16 @@ public class GeckoSystemStateListener implements InputManager.InputDeviceListene onDeviceChanged(); } + @WrapForJNI(calledFrom = "gecko") + private static int getAllPointerCapabilities() { + return getInstance().mAllPointerCapabilities; + } + + @WrapForJNI(calledFrom = "gecko") + private static int getPointingDeviceKinds() { + return getInstance().mPointingDeviceKinds; + } + @WrapForJNI(stubName = "OnDeviceChanged", calledFrom = "any", dispatchTo = "gecko") private static native void nativeOnDeviceChanged(); @@ -237,12 +252,27 @@ public class GeckoSystemStateListener implements InputManager.InputDeviceListene } } + private boolean updatePointerCapabilities() { + final int allPointerCapabilities = GeckoAppShell.getAllPointerCapabilities(); + final int pointingDeviceKinds = GeckoAppShell.getPointingDeviceKinds(); + if (mAllPointerCapabilities == allPointerCapabilities + && mPointingDeviceKinds == pointingDeviceKinds) { + return false; + } + mAllPointerCapabilities = allPointerCapabilities; + mPointingDeviceKinds = pointingDeviceKinds; + return true; + } + private void notifyDeviceChanged(final int deviceId) { final InputDevice device = InputDevice.getDevice(deviceId); if (device == null || !InputDeviceUtils.isPointerTypeDevice(device)) { return; } - onDeviceChanged(); + + if (updatePointerCapabilities()) { + onDeviceChanged(); + } } @Override @@ -255,7 +285,9 @@ public class GeckoSystemStateListener implements InputManager.InputDeviceListene // Call onDeviceChanged directly without checking device source types // since we can no longer get a valid `InputDevice` in the case of // device removal. - onDeviceChanged(); + if (updatePointerCapabilities()) { + onDeviceChanged(); + } } @Override diff --git a/widget/android/nsLookAndFeel.cpp b/widget/android/nsLookAndFeel.cpp @@ -365,7 +365,7 @@ nsresult nsLookAndFeel::NativeGetInt(IntID aID, int32_t& aResult) { break; case IntID::PrimaryPointerCapabilities: - aResult = java::GeckoAppShell::GetAllPointerCapabilities(); + aResult = java::GeckoSystemStateListener::GetAllPointerCapabilities(); // We cannot assume what is primary device, so we use Blink's way for web // compatibility (https://crbug.com/136119#c6). If having coarse @@ -376,7 +376,7 @@ nsresult nsLookAndFeel::NativeGetInt(IntID aID, int32_t& aResult) { break; case IntID::AllPointerCapabilities: - aResult = java::GeckoAppShell::GetAllPointerCapabilities(); + aResult = java::GeckoSystemStateListener::GetAllPointerCapabilities(); break; case IntID::SystemUsesDarkTheme: { @@ -397,7 +397,7 @@ nsresult nsLookAndFeel::NativeGetInt(IntID aID, int32_t& aResult) { break; case IntID::PointingDeviceKinds: - aResult = java::GeckoAppShell::GetPointingDeviceKinds(); + aResult = java::GeckoSystemStateListener::GetPointingDeviceKinds(); break; default: