This repository has been archived by the owner on Nov 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 954
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Added concept of a tree observer which is responsible for listening to the changes for a portion of the UI tree. This structure nests so Tree observers can hold child tree observers which emit events on a different cadence. This structure should allow us to incorporate different UI frameworks down the road as well as native android views. We push the tree updates from the tree observers onto a channel and setup a coroutine to consume this channel, serialize and send down the wire. Reviewed By: lblasa Differential Revision: D39276681 fbshipit-source-id: a4bc23b3578a8a10b57dd11fe88b273e1ce09ad8
- Loading branch information
1 parent
c76c993
commit 9a270cd
Showing
16 changed files
with
480 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,3 +49,5 @@ website/src/embedded-pages/docs/plugins/ | |
|
||
# Logs | ||
**/*/flipper-server-log.out | ||
|
||
*.salive |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...rc/main/java/com/facebook/flipper/plugins/uidebugger/observers/ApplicationTreeObserver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.facebook.flipper.plugins.uidebugger.observers | ||
|
||
import android.app.Activity | ||
import android.content.ContextWrapper | ||
import android.util.Log | ||
import android.view.View | ||
import com.facebook.flipper.plugins.uidebugger.LogTag | ||
import com.facebook.flipper.plugins.uidebugger.SubtreeUpdate | ||
import com.facebook.flipper.plugins.uidebugger.TreeObserver | ||
import com.facebook.flipper.plugins.uidebugger.core.ApplicationRef | ||
import com.facebook.flipper.plugins.uidebugger.core.Context | ||
import com.facebook.flipper.plugins.uidebugger.identityHashCode | ||
|
||
/** | ||
* responsible for observing the activity stack and managing the subscription to the top most | ||
* content view (decor view) | ||
*/ | ||
class ApplicationTreeObserver(val context: Context) : TreeObserver<ApplicationRef>() { | ||
|
||
override fun subscribe(node: Any) { | ||
Log.i(LogTag, "subscribing to application / activity changes") | ||
|
||
val applicationRef = node as ApplicationRef | ||
|
||
val addRemoveListener = | ||
object : ApplicationRef.ActivityStackChangedListener { | ||
|
||
override fun onActivityAdded(activity: Activity, stack: List<Activity>) { | ||
val start = System.currentTimeMillis() | ||
val (nodes, skipped) = context.layoutTraversal.traverse(applicationRef) | ||
val observer = | ||
context.observerFactory.createObserver(activity.window.decorView, context)!! | ||
observer.subscribe(activity.window.decorView) | ||
children[activity.window.decorView.identityHashCode()] = observer | ||
context.treeObserverManager.emit( | ||
SubtreeUpdate("Application", nodes, start, System.currentTimeMillis())) | ||
Log.i( | ||
LogTag, | ||
"Activity added,stack size ${stack.size} found ${nodes.size} skipped $skipped Listeners $children") | ||
} | ||
|
||
override fun onActivityStackChanged(stack: List<Activity>) {} | ||
|
||
override fun onActivityDestroyed(activity: Activity, stack: List<Activity>) { | ||
val start = System.currentTimeMillis() | ||
|
||
val (nodes, skipped) = context.layoutTraversal.traverse(applicationRef) | ||
|
||
val observer = children[activity.window.decorView.identityHashCode()] | ||
children.remove(activity.window.decorView.identityHashCode()) | ||
observer?.cleanUpRecursive() | ||
|
||
context.treeObserverManager.emit( | ||
SubtreeUpdate("Application", nodes, start, System.currentTimeMillis())) | ||
|
||
Log.i( | ||
LogTag, | ||
"Activity removed,stack size ${stack.size} found ${nodes.size} skipped $skipped Listeners $children") | ||
} | ||
} | ||
|
||
context.applicationRef.setActivityStackChangedListener(addRemoveListener) | ||
|
||
Log.i(LogTag, "${context.applicationRef.rootViews.size} root views") | ||
Log.i(LogTag, "${context.applicationRef.activitiesStack.size} activities") | ||
|
||
val stack = context.applicationRef.activitiesStack | ||
for (activity in stack) { | ||
addRemoveListener.onActivityAdded(activity, stack) | ||
} | ||
} | ||
private fun getActivity(view: View): Activity? { | ||
var context: android.content.Context? = view.context | ||
while (context is ContextWrapper) { | ||
if (context is Activity) { | ||
return context | ||
} | ||
context = context.baseContext | ||
} | ||
return null | ||
} | ||
|
||
override fun unsubscribe() { | ||
context.applicationRef.setActivityStackChangedListener(null) | ||
} | ||
} |
Oops, something went wrong.