Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
platform_frameworks_base-old
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Farzin Kazemzadeh
platform_frameworks_base-old
Commits
b409758a
Commit
b409758a
authored
1 year ago
by
Peter Kalauskas
Committed by
Android (Google) Code Review
1 year ago
Browse files
Options
Downloads
Plain Diff
Merge "More informative trace names in repeatWhenAttached" into main
parents
9c7ce347
b5d9f36e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
packages/SystemUI/src/com/android/systemui/lifecycle/RepeatWhenAttached.kt
+33
-6
33 additions, 6 deletions
.../src/com/android/systemui/lifecycle/RepeatWhenAttached.kt
with
33 additions
and
6 deletions
packages/SystemUI/src/com/android/systemui/lifecycle/RepeatWhenAttached.kt
+
33
−
6
View file @
b409758a
...
...
@@ -26,7 +26,9 @@ import androidx.lifecycle.LifecycleRegistry
import
androidx.lifecycle.lifecycleScope
import
com.android.app.tracing.coroutines.createCoroutineTracingContext
import
com.android.app.tracing.coroutines.launch
import
com.android.systemui.Flags.coroutineTracing
import
com.android.systemui.util.Assert
import
com.android.systemui.util.Compile
import
kotlin.coroutines.CoroutineContext
import
kotlin.coroutines.EmptyCoroutineContext
import
kotlinx.coroutines.Dispatchers
...
...
@@ -69,6 +71,12 @@ fun View.repeatWhenAttached(
// presumably want to call view methods that require being called from said UI thread.
val
lifecycleCoroutineContext
=
Dispatchers
.
Main
+
createCoroutineTracingContext
()
+
coroutineContext
val
traceName
=
if
(
Compile
.
IS_DEBUG
&&
coroutineTracing
())
{
traceSectionName
()
}
else
{
DEFAULT_TRACE_NAME
}
var
lifecycleOwner
:
ViewLifecycleOwner
?
=
null
val
onAttachListener
=
object
:
View
.
OnAttachStateChangeListener
{
...
...
@@ -77,6 +85,7 @@ fun View.repeatWhenAttached(
lifecycleOwner
?.
onDestroy
()
lifecycleOwner
=
createLifecycleOwnerAndRun
(
traceName
,
view
,
lifecycleCoroutineContext
,
block
,
...
...
@@ -93,6 +102,7 @@ fun View.repeatWhenAttached(
if
(
view
.
isAttachedToWindow
)
{
lifecycleOwner
=
createLifecycleOwnerAndRun
(
traceName
,
view
,
lifecycleCoroutineContext
,
block
,
...
...
@@ -109,18 +119,14 @@ fun View.repeatWhenAttached(
}
private
fun
createLifecycleOwnerAndRun
(
nameForTrace
:
String
,
view
:
View
,
coroutineContext
:
CoroutineContext
,
block
:
suspend
LifecycleOwner
.(
View
)
->
Unit
,
):
ViewLifecycleOwner
{
return
ViewLifecycleOwner
(
view
).
apply
{
onCreate
()
lifecycleScope
.
launch
(
"ViewLifecycleOwner(${view::class.java.simpleName})"
,
coroutineContext
)
{
block
(
view
)
}
lifecycleScope
.
launch
(
nameForTrace
,
coroutineContext
)
{
block
(
view
)
}
}
}
...
...
@@ -186,3 +192,24 @@ class ViewLifecycleOwner(
}
}
}
private
fun
isFrameInteresting
(
frame
:
StackWalker
.
StackFrame
):
Boolean
=
frame
.
className
!=
CURRENT_CLASS_NAME
&&
frame
.
className
!=
JAVA_ADAPTER_CLASS_NAME
/** Get a name for the trace section include the name of the call site. */
private
fun
traceSectionName
():
String
{
val
interestingFrame
=
StackWalker
.
getInstance
().
walk
{
stream
->
stream
.
filter
(
::
isFrameInteresting
).
limit
(
5
).
findFirst
()
}
if
(
interestingFrame
.
isPresent
)
{
val
frame
=
interestingFrame
.
get
()
return
"${frame.className}#${frame.methodName}:${frame.lineNumber} [$DEFAULT_TRACE_NAME]"
}
else
{
return
DEFAULT_TRACE_NAME
}
}
private
const
val
DEFAULT_TRACE_NAME
=
"repeatWhenAttached"
private
const
val
CURRENT_CLASS_NAME
=
"com.android.systemui.lifecycle.RepeatWhenAttachedKt"
private
const
val
JAVA_ADAPTER_CLASS_NAME
=
"com.android.systemui.util.kotlin.JavaAdapterKt"
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment