B08b: Try Monitor App
In this example you try out the User Switch Monitor App described in the AAOS slides.
Install
First build the application
m -j24 UserSwitchMonitorApp
Then see the output on the console. It's built and put into the directory
out/target/product/vsoc_x86_64_only/system/priv-app/UserSwitchMonitorApp/UserSwitchMonitorApp.apk
Install the application and grant the necessary runtime permission:
adb install --user 0 $OUT/system/priv-app/UserSwitchMonitorApp/UserSwitchMonitorApp.apk adb shell pm grant --user 0 com.google.android.car.userswitchmonitor android.permission.INTERACT_ACROSS_USERS
Run
Start the (foreground) service
adb shell am start-foreground-service --user 0 com.google.android.car.userswitchmonitor/.UserSwitchMonitorService
Now the app is running and the service within the application has started. See the tag mentioned in the logcat output
adb logcat -s UserSwitchMonitor
Also, see the dumpsys output of the service.
adb shell dumpsys activity service com.google.android.car.userswitchmonitor/.UserSwitchMonitorService
Try it Out
Next, try a user switch in the running Android system. In the top right corner you can switch between the Driver and the Guest user.
Do this now and re-execute the logcat and dumpsys commands. You should see additional log messages and events.
Extra Tasks
Locate the source code of the application in the source tree. E.g., the function that prints the output seen in the dumpsys command. Use both: cs.android.com and the local source tree.
Tip
Use a string that is printed on the console as a search term.
Also, try to use the mgrep and godir commands in the AOSP build environment.
Also, locate the AndroidManifest.xml and review the (foreground) service definition used for am start-foreground-service.
And question: What is the difference between the folder /system/priv-app and /system/app/ in the system partition?
Note
If you write your own native or (foreground) service, add a dumpsys debug interface. It's super useful to query the internal state of our service on the command line adb.