For #21296: add ProfilerMarkers.addForDispatchTouchEvent.

upstream-sync
Michael Comella 3 years ago committed by mergify[bot]
parent bb632c7b3b
commit 7232fedb20

@ -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

@ -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)
}
}
}
/**

Loading…
Cancel
Save