0

I have some logcat outputs saved as txt file. I need to parse them looking only for entries that correspond to my app. However, it always takes me quite some time to find the exact process ID of my in order to filter for it.

Is there a way to get the process ID automatically when starting the apk via adb?

This is the line in my script that starts the app on a device

adb -s $device_name  shell am start -S -n $pkg_name/com.unity3d.player.UnityPlayerActivity

Some more context:
My script installs and starts an apk on an android device. The script is running on a cloudplatform for device testing (Kobiton) which probably uses Appium to run apks in a sandbox on real devices. After running the app for a the Kobiton server sends back the logcat output as a txt file.

This is what such an output looks like:

2022-08-04 16:10:28.722 -0400  4197  4500 D SdpManagerService.SDPLog: com.android.server.SdpManagerService$SdpEngineDatabase$EngineListHandler.getEngineListXmlFile(SdpManagerService.java:2635)
2022-08-04 16:10:28.722 -0400  4197  4500 D SdpManagerService.SDPLog: com.android.server.SdpManagerService$SdpEngineDatabase$EngineListHandler.getEngineListXmlFile(SdpManagerService.java:2623)
2022-08-04 16:10:28.722 -0400  4197  4500 D SdpManagerService.SDPLog: com.android.server.SdpManagerService$SdpEngineDatabase$EngineListHandler.getEngineListLocked(SdpManagerService.java:2721)
2022-08-04 16:10:28.722 -0400  4197  4500 D SdpManagerService.SDPLog: com.android.server.SdpManagerService$SdpEngineDatabase$EngineListHandler.access$2300(SdpManagerService.java:2612)
2022-08-04 16:10:28.722 -0400  4197  4500 D SdpManagerService.SDPLog: com.android.server.SdpManagerService$SdpEngineDatabase.getEngineListLocked(SdpManagerService.java:2592) 
2022-08-04 16:10:28.722 -0400  4197  4500 D SdpManagerService.SDPLog: com.android.server.SdpManagerService$SdpEngineDatabase.access$1700(SdpManagerService.java:2570)
2022-08-04 16:10:28.722 -0400  4197  4500 D SdpManagerService.SDPLog: com.android.server.SdpManagerService.readEngineList(SdpManagerService.java:2543)
2022-08-04 16:10:28.722 -0400  4197  4500 D SdpManagerService.SDPLog: com.android.server.SdpManagerService.handlePackageRemoved(SdpManagerService.java:4755)
2022-08-04 16:10:28.723 -0400  4197  4500 D SdpManagerService.SDPLog: com.android.server.SdpManagerService.access$6100(SdpManagerService.java:171)
2022-08-04 16:10:28.723 -0400  4197  4500 D SdpManagerService.SDPLog: com.android.server.SdpManagerService$SdpHandler.handleMessage(SdpManagerService.java:6105)
2022-08-04 16:10:28.723 -0400  4197  4500 D SdpManagerService.SDPLog: android.os.Handler.dispatchMessage(Handler.java:106)
2022-08-04 16:10:28.723 -0400  4197  4500 D SdpManagerService.SDPLog: android.os.Looper.loop(Looper.java:214)
2022-08-04 16:10:28.723 -0400  4197  4500 D SdpManagerService.SDPLog: android.os.HandlerThread.run(HandlerThread.java:65)
2022-08-04 16:10:28.723 -0400  4197  4500 E SdpManagerService: read engine - No any engine found
2022-08-04 16:10:28.734 -0400  4197  4197 D ZenModeHelper: Set zen mode for exception case : 0
2022-08-04 16:10:28.745 -0400 20156 20156 I SKBD    : anc isTosAccept false
2022-08-04 16:10:28.749 -0400  4197  4197 D UniversalCredentialManagerService: ****MSG_CLEAN_INFO block started****
2022-08-04 16:10:28.749 -0400  4197  4197 D UniversalCredentialManagerService: uid - 15747, userId-0
2022-08-04 16:10:28.749 -0400  4197  4197 D UniversalCredentialManagerService: notifyChangeToPlugin is called for package uninstalled...
2022-08-04 16:10:28.749 -0400  4197  4197 D UcmService: notifyChangeToPlugin event 12
2022-08-04 16:10:28.749 -0400  4197  4197 D UcmService: checkCallerPermissionFor is called for method-notifyChangeToPlugin
2022-08-04 16:10:28.749 -0400  4197  4197 D UniversalCredentialManagerService: ****MSG_CLEAN_INFO block ended****
2022-08-04 16:10:28.790 -0400 19812 19812 D Notification.Badge: onNotificationRankingUpdate().sIsDnDModeChanged[false]
2022-08-04 16:10:28.790 -0400 19812 19812 D Notification.Badge: [invalid] onNotificationRankingUpdate : sNotificationListenerInstance = com.android.launcher3.framework.device.notification.NotificationListener@d63fa54 sIsConnected[true]
2022-08-04 16:10:28.793 -0400 22587 27587 V SysAbnormalItemManager: updated column : com.MoveBook.MoveBookFarmAdventures / flag : false
2022-08-04 16:10:28.798 -0400 22587 27587 V SysAbnormalItemManager: updated column : 15747 / flag : false
2022-08-04 16:10:28.801 -0400  4197  4223 V MARsDBManager: getManagedPackagesFromDB!
2022-08-04 16:10:28.802 -0400  4197  4197 W Looper  : Drained
2022-08-04 16:10:28.813 -0400 28468 28468 I cr_SplitCompatApp: aunched version=95.0.4638.50 minSdkVersion=24 isBundle=true processName=com.android.chrome isIsolated=false    
2022-08-04 16:10:28.816 -0400  4197  4223 V MARsPolicyManager: getPkgInfoFromSMToMARs size = 29
2022-08-04 16:10:28.830 -0400  4197  4223 E EdmStorageProvider: Admin not in database, something went wrong
2022-08-04 16:10:28.844 -0400  5426  5426 D io_stats: !@ 179,0 r 4229839 195915004 w 12884332 278363688 d 857544 165056904 f 2502218 2756314 iot 11859272 12140884 th 51200 0 
0 pt 0 inp 2 0 5407919.174
2022-08-04 16:10:28.850 -0400  4197  4223 I chatty  : uid=1000(system) MARsDBThread identical 7 lines
2022-08-04 16:10:28.852 -0400  4197  4223 E EdmStorageProvider: Admin not in database, something went wrong
2022-08-04 16:10:28.859 -0400 11692 11692 I StackScroller: ADJUST STACK.TRANSLATION
2022-08-04 16:10:28.860 -0400  4197  4223 E EdmStorageProvider: Admin not in database, something went wrong
2022-08-04 16:10:28.864 -0400 11692 11692 I StackScroller: ADJUST STACK.TRANSLATION
2022-08-04 16:10:28.864 -0400 11692 11692 I StackScroller: ADJUST STACK.TRANSLATION
2022-08-04 16:10:28.865 -0400  4197  4223 E EdmStorageProvider: Admin not in database, something went wrong

As one can see: it has an additional column "-0400" before the process ID and thread ID column

1
  • You can use something like pidcat to take logcat. Or simply combine ps with grep / sed / awk. Commented Aug 9, 2022 at 12:33

1 Answer 1

0

I don't know a direct way to get the process ID of a started app/activity. But if you have a PC connected to the phone via USB one very easy way would be to use frita-ps to get the full list of active apps and the filter it by the known package name to get the process ID of the started app:

frida-ps -a -U

(list all apps -a on the phone connected via USB -U) from frida tools. Frida is a Python based reverse-engineering and hooking framework that can be installed via pip install frida-tools. frida-ps is just one tool from this collection.

It shows app package name, app display name and process ID and it works on unrooted devices (no frida-server or app-modification required for frida-ps).

Truncated example output from an unrooted Pixel 4a device:

D:\>frida-ps -Ua
  PID  Name                   Identifier
-----  ---------------------  ---------------------------------------
24507  Android Auto           com.google.android.projection.gearhead
16334  Chrome                 com.android.chrome
24906  Duo                    com.google.android.apps.tachyon
20700  Einstellungen          com.android.settings
 2292  Gboard                 com.google.android.inputmethod.latin
 1727  Google                 com.google.android.googlequicksearchbox
22699  Google Play Store      com.android.vending
20585  Google Wallet          com.google.android.apps.walletnfcrel
24221  Maps                   com.google.android.apps.maps
19359  Pixel-Tipps            com.google.android.apps.tips
 2806  SIM-Toolkit            com.android.stk
1
  • I just realized that I asked my question wrongly. I don't have access to any console / python on Kobiton (the cloud service I'm using). Since your answer fits my question, I'll get back to it once I could try it out / verify
    – mcExchange
    Commented Aug 10, 2022 at 8:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .