Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can HierarchyViewer tool of android studio know the properties of views of android screen

I want to know how hierarchyViewer tool works in android. As all the android app runs in different processes, how can it know the layout of views. Who pushes the views and its properties to hierarchyViewer.

Which service of android push data to HierarchyViewer tool. Can someone please explain me this please?

like image 357
user3265443 Avatar asked Jan 16 '16 12:01

user3265443


People also ask

What does view View do in Android Studio?

It holds references to single piece of UI. See link above. Passing View view as argument in methods in most cases gives you opportunity to call method associated with this view. For example if you click on some elements, view is passed in listener so you can know which view was clicked and what attributes it have.

Is Android a monitoring tool?

Android Device Monitor is a stand-alone tool that provides a graphical user interface for several Android application debugging and analysis tools. The Monitor tool does not require installation of an integrated development environment, such as Android Studio, and encapsulates the following tools: DDMS.

What is the purpose of Android device monitor in Android Studio?

To inspect . trace files captured by instrumenting your app with the Debug class, record new method traces, export .


1 Answers

Lets first look at how adb is organized. It has 3 main components as described here -

  1. client - A clients running on the machine being used for the development. Client is invoked from shell by issuing a adb command. Hierarchy viewer also creates adb client.
  2. server - A server which runs as a background process on your development machine.It communicates the commands issued from the adb client to the adbd(adb daemon).
  3. adbd - Adb daemon runs as a background process on each emulator or device. adb daemon is responsible for the communication of the data from the emulator or device to the adb server. adb daemon communicates to various services running on the device via Binder which is an IPC like mechanism.

For example when we issue a command like adb install example.apk on shell. It first invokes adb client on the machine and tells it wants to install example.apk. Then server then sends the apk along with the command to the the adb daemon running on the device. The communication is done done by adb bridge communicating via TCP connection generally running at port 5554. Then adb daemon calls the System server to carry out the command.

Now lets have a look at the android device side of the story -

On every android device there is a server called as a System Server. You can find the status of this by issuing the command adb shell ps | grep system_server. The System server is responsible for management of services. Some services run by the System Server are

  • Device Policy
  • Audio Service
  • Power Manager
  • Package Manager
  • Content Providers
  • Window Manager
  • Activity Manager and many more....

The Window Manager has information like - Main Thread, Window manipulation, orientation, layering, input event management, focus etc. The information on your views is already available with the Windows Manager.

So now putting everything together the final flow for the hierarchy viewer is -

  1. Hierarchy viewer creates adb client asking the information on viewswhen issued a command like REMOTE_COMMAND_CAPTURE_LAYERS or COMMAND_WINDOW_MANAGER_LIST.

  2. The request reaches adb server which forwards it to the adbd on device running the application.

  3. adbd forwards the request to the System Server who identifies the service to which the request has to be forwarded. Which in this case is Window Manger.

  4. Window Manger then asks View Manager which is responsible for the managing of the thread pool for the main UI thread of application.

  5. View Manager returns this information to the Window Manager.

  6. Window Manager sends data back to adbd.

  7. Adbd communicates it back to adb server.

  8. adb server gives data back to hierarchy viewer.

    Hope it helps.

like image 144
sandeep Avatar answered Nov 14 '22 23:11

sandeep