diff --git a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt index 1b77c363de..201a5b5281 100644 --- a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt +++ b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt @@ -19,6 +19,7 @@ import android.view.KeyEvent import android.view.LayoutInflater import android.view.View import android.view.ActionMode +import android.view.MotionEvent import android.view.ViewConfiguration import android.view.WindowManager.LayoutParams.FLAG_SECURE import androidx.annotation.CallSuper @@ -581,6 +582,11 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity { return false } + override fun dispatchTouchEvent(ev: MotionEvent?): Boolean { + ProfilerMarkers.addForDispatchTouchEvent(components.core.engine.profiler, ev) + return super.dispatchTouchEvent(ev) + } + final override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean { // Inspired by https://searchfox.org/mozilla-esr68/source/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java#584-613 // Android N and Huawei devices have broken onKeyLongPress events for the back button, so we diff --git a/app/src/main/java/org/mozilla/fenix/perf/ProfilerMarkers.kt b/app/src/main/java/org/mozilla/fenix/perf/ProfilerMarkers.kt index 35f4196e3d..6b2f4ec1e3 100644 --- a/app/src/main/java/org/mozilla/fenix/perf/ProfilerMarkers.kt +++ b/app/src/main/java/org/mozilla/fenix/perf/ProfilerMarkers.kt @@ -5,6 +5,7 @@ package org.mozilla.fenix.perf import android.app.Activity +import android.view.MotionEvent import android.view.View import android.view.ViewTreeObserver import androidx.core.view.doOnPreDraw @@ -28,6 +29,20 @@ object ProfilerMarkers { profiler?.addMarker("onPreDraw", "expected first frame via HomeActivity.onStart") } } + + fun addForDispatchTouchEvent(profiler: Profiler?, ev: MotionEvent?) { + // We only run this if the profiler is active to minimize any possible delay on touch events. + if (profiler?.isProfilerActive() == true) { + // We only do this subset because 1) other actions like MOVE may be spammy and 2) doing + // a generic ev?.action::class.simpleName may be too expensive for dispatchTouchEvent. + val detailText = when (ev?.action) { + MotionEvent.ACTION_DOWN -> "ACTION_DOWN" + MotionEvent.ACTION_UP -> "ACTION_UP" + else -> return + } + profiler.addMarker("dispatchTouchEvent", detailText) + } + } } /**