Skip to content

Commit

Permalink
For mozilla-mobile#21296: add ProfilerMarkers.addForDispatchTouchEvent.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcomella authored and mergify[bot] committed Sep 17, 2021
1 parent bb632c7 commit 7232fed
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/src/main/java/org/mozilla/fenix/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/java/org/mozilla/fenix/perf/ProfilerMarkers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}
}

/**
Expand Down

0 comments on commit 7232fed

Please sign in to comment.