ADB - Android - Getting the name of the current activity - android
Is there a way to get the details of the current activity that is running via adb.
I prefer parsing results of dumpsys window windows over dumpsys activity
adb shell dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'
Keyguard or Recent tasks list used to not show up as Activities but you were able to see them with mCurrentFocus. I have explained why in this answer.
You can use this command,
adb shell dumpsys activity
You can find current activity name in activity stack.
Output :-
Sticky broadcasts:
* Sticky action android.intent.action.BATTERY_CHANGED:
Intent: act=android.intent.action.BATTERY_CHANGED flg=0x60000000
Bundle[{icon-small=17302169, present=true, scale=100, level=50, technology=Li-ion, status=2, voltage=0, plugged=1, health=2, temperature=0}]
* Sticky action android.net.thrott.THROTTLE_ACTION:
Intent: act=android.net.thrott.THROTTLE_ACTION
Bundle[{level=-1}]
* Sticky action android.intent.action.NETWORK_SET_TIMEZONE:
Intent: act=android.intent.action.NETWORK_SET_TIMEZONE flg=0x20000000
Bundle[mParcelledData.dataSize=68]
* Sticky action android.provider.Telephony.SPN_STRINGS_UPDATED:
Intent: act=android.provider.Telephony.SPN_STRINGS_UPDATED flg=0x20000000
Bundle[mParcelledData.dataSize=156]
* Sticky action android.net.thrott.POLL_ACTION:
Intent: act=android.net.thrott.POLL_ACTION
Bundle[{cycleRead=0, cycleStart=1349893800000, cycleEnd=1352572200000, cycleWrite=0}]
* Sticky action android.intent.action.SIM_STATE_CHANGED:
Intent: act=android.intent.action.SIM_STATE_CHANGED flg=0x20000000
Bundle[mParcelledData.dataSize=116]
* Sticky action android.intent.action.SIG_STR:
Intent: act=android.intent.action.SIG_STR flg=0x20000000
Bundle[{EvdoSnr=-1, CdmaDbm=-1, GsmBitErrorRate=-1, CdmaEcio=-1, EvdoDbm=-1, GsmSignalStrength=7, EvdoEcio=-1, isGsm=true}]
* Sticky action android.intent.action.SERVICE_STATE:
Intent: act=android.intent.action.SERVICE_STATE flg=0x20000000
Bundle[{cdmaRoamingIndicator=0, operator-numeric=310260, networkId=0, state=0, emergencyOnly=false, operator-alpha-short=Android, radioTechnology=3, manual=false, cssIndicator=false, operator-alpha-long=Android, systemId=0, roaming=false, cdmaDefaultRoamingIndicator=0}]
* Sticky action android.net.conn.CONNECTIVITY_CHANGE:
Intent: act=android.net.conn.CONNECTIVITY_CHANGE flg=0x30000000
Bundle[{networkInfo=NetworkInfo: type: mobile[UMTS], state: CONNECTED/CONNECTED, reason: simLoaded, extra: internet, roaming: false, failover: false, isAvailable: true, reason=simLoaded, extraInfo=internet}]
* Sticky action android.intent.action.NETWORK_SET_TIME:
Intent: act=android.intent.action.NETWORK_SET_TIME flg=0x20000000
Bundle[mParcelledData.dataSize=36]
* Sticky action android.media.RINGER_MODE_CHANGED:
Intent: act=android.media.RINGER_MODE_CHANGED flg=0x70000000
Bundle[{android.media.EXTRA_RINGER_MODE=2}]
* Sticky action android.intent.action.ANY_DATA_STATE:
Intent: act=android.intent.action.ANY_DATA_STATE flg=0x20000000
Bundle[{state=CONNECTED, apnType=*, iface=/dev/omap_csmi_tty1, apn=internet, reason=simLoaded}]
Activity stack:
* TaskRecord{450adb90 #22 A org.chanakyastocktipps.com}
clearOnBackground=false numActivities=2 rootWasReset=false
affinity=org.chanakyastocktipps.com
intent={act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=org.chanakyastocktipps.com/.ui.SplashScreen}
realActivity=org.chanakyastocktipps.com/.ui.SplashScreen
lastActiveTime=15107753 (inactive for 4879s)
* Hist #2: HistoryRecord{450d7ab0 org.chanakyastocktipps.com/.ui.Profile}
packageName=org.chanakyastocktipps.com processName=org.chanakyastocktipps.com
launchedFromUid=10046 app=ProcessRecord{44fa3450 1065:org.chanakyastocktipps.com/10046}
Intent { cmp=org.chanakyastocktipps.com/.ui.Profile }
frontOfTask=false task=TaskRecord{450adb90 #22 A org.chanakyastocktipps.com}
taskAffinity=org.chanakyastocktipps.com
realActivity=org.chanakyastocktipps.com/.ui.Profile
base=/data/app/org.chanakyastocktipps.com-1.apk/data/app/org.chanakyastocktipps.com-1.apk data=/data/data/org.chanakyastocktipps.com
labelRes=0x7f09000b icon=0x7f020065 theme=0x1030007
stateNotNeeded=false componentSpecified=true isHomeActivity=false
configuration={ scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 orien=1 layout=18 uiMode=17 seq=3}
resultTo=HistoryRecord{44f523c0 org.chanakyastocktipps.com/.ui.MainScreen} resultWho=null resultCode=4
launchFailed=false haveState=false icicle=null
state=RESUMED stopped=false delayedResume=false finishing=false
keysPaused=false inHistory=true persistent=false launchMode=0
fullscreen=true visible=true frozenBeforeDestroy=false thumbnailNeeded=false idle=true
waitingVisible=false nowVisible=true
* Hist #1: HistoryRecord{44f523c0 org.chanakyastocktipps.com/.ui.MainScreen}
packageName=org.chanakyastocktipps.com processName=org.chanakyastocktipps.com
launchedFromUid=10046 app=ProcessRecord{44fa3450 1065:org.chanakyastocktipps.com/10046}
Intent { cmp=org.chanakyastocktipps.com/.ui.MainScreen }
frontOfTask=true task=TaskRecord{450adb90 #22 A org.chanakyastocktipps.com}
taskAffinity=org.chanakyastocktipps.com
realActivity=org.chanakyastocktipps.com/.ui.MainScreen
base=/data/app/org.chanakyastocktipps.com-1.apk/data/app/org.chanakyastocktipps.com-1.apk data=/data/data/org.chanakyastocktipps.com
labelRes=0x7f09000b icon=0x7f020065 theme=0x1030007
stateNotNeeded=false componentSpecified=true isHomeActivity=false
configuration={ scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 orien=1 layout=18 uiMode=17 seq=3}
launchFailed=false haveState=true icicle=Bundle[mParcelledData.dataSize=1344]
state=STOPPED stopped=true delayedResume=false finishing=false
keysPaused=false inHistory=true persistent=false launchMode=0
fullscreen=true visible=false frozenBeforeDestroy=false thumbnailNeeded=false idle=true
* TaskRecord{450615a0 #2 A com.android.launcher}
clearOnBackground=true numActivities=1 rootWasReset=false
affinity=com.android.launcher
intent={act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10000000 cmp=com.android.launcher/com.android.launcher2.Launcher}
realActivity=com.android.launcher/com.android.launcher2.Launcher
lastActiveTime=12263090 (inactive for 7724s)
* Hist #0: HistoryRecord{4505d838 com.android.launcher/com.android.launcher2.Launcher}
packageName=com.android.launcher processName=com.android.launcher
launchedFromUid=0 app=ProcessRecord{45062558 129:com.android.launcher/10025}
Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10000000 cmp=com.android.launcher/com.android.launcher2.Launcher }
frontOfTask=true task=TaskRecord{450615a0 #2 A com.android.launcher}
taskAffinity=com.android.launcher
realActivity=com.android.launcher/com.android.launcher2.Launcher
base=/system/app/Launcher2.apk/system/app/Launcher2.apk data=/data/data/com.android.launcher
labelRes=0x7f0c0002 icon=0x7f020044 theme=0x7f0d0000
stateNotNeeded=true componentSpecified=false isHomeActivity=true
configuration={ scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 orien=1 layout=18 uiMode=17 seq=3}
launchFailed=false haveState=true icicle=Bundle[mParcelledData.dataSize=3608]
state=STOPPED stopped=true delayedResume=false finishing=false
keysPaused=false inHistory=true persistent=false launchMode=2
fullscreen=true visible=false frozenBeforeDestroy=false thumbnailNeeded=false idle=true
Running activities (most recent first):
TaskRecord{450adb90 #22 A org.chanakyastocktipps.com}
Run #2: HistoryRecord{450d7ab0 org.chanakyastocktipps.com/.ui.Profile}
Run #1: HistoryRecord{44f523c0 org.chanakyastocktipps.com/.ui.MainScreen}
TaskRecord{450615a0 #2 A com.android.launcher}
Run #0: HistoryRecord{4505d838 com.android.launcher/com.android.launcher2.Launcher}
mPausingActivity: null
mResumedActivity: HistoryRecord{450d7ab0 org.chanakyastocktipps.com/.ui.Profile}
mFocusedActivity: HistoryRecord{450d7ab0 org.chanakyastocktipps.com/.ui.Profile}
mLastPausedActivity: HistoryRecord{44f523c0 org.chanakyastocktipps.com/.ui.MainScreen}
mCurTask: 22
Running processes (most recent first):
App #13: adj=vis /F 45052120 119:com.android.inputmethod.latin/10003 (service)
com.android.inputmethod.latin.LatinIME<=ProcessRecord{44ec2698 59:system/1000}
PERS #12: adj=sys /F 44ec2698 59:system/1000 (fixed)
App #11: adj=fore /F 44fa3450 1065:org.chanakyastocktipps.com/10046 (top-activity)
App #10: adj=bak /B 44e7c4c0 299:com.svox.pico/10028 (bg-empty)
App # 9: adj=bak+1/B 450f7ef0 288:com.dreamreminder.org:feather_system_receiver/10057 (bg-empty)
App # 8: adj=bak+2/B 4503cc38 201:com.android.defcontainer/10010 (bg-empty)
App # 7: adj=home /B 45062558 129:com.android.launcher/10025 (home)
App # 6: adj=bak+3/B 450244d8 276:android.process.media/10002 (bg-empty)
App # 5: adj=bak+4/B 44f2b9b8 263:com.android.quicksearchbox/10012 (bg-empty)
App # 4: adj=bak+5/B 450beec0 257:com.android.protips/10007 (bg-empty)
App # 3: adj=bak+6/B 44ff37b8 270:com.android.music/10022 (bg-empty)
PERS # 2: adj=core /F 45056818 124:com.android.phone/1001 (fixed)
App # 1: adj=bak+7/B 45080c38 238:com.dreamreminder.org/10057 (bg-empty)
App # 0: adj=empty/B 4507d030 229:com.android.email/10030 (bg-empty)
PID mappings:
PID #59: ProcessRecord{44ec2698 59:system/1000}
PID #119: ProcessRecord{45052120 119:com.android.inputmethod.latin/10003}
PID #124: ProcessRecord{45056818 124:com.android.phone/1001}
PID #129: ProcessRecord{45062558 129:com.android.launcher/10025}
PID #201: ProcessRecord{4503cc38 201:com.android.defcontainer/10010}
PID #229: ProcessRecord{4507d030 229:com.android.email/10030}
PID #238: ProcessRecord{45080c38 238:com.dreamreminder.org/10057}
PID #257: ProcessRecord{450beec0 257:com.android.protips/10007}
PID #263: ProcessRecord{44f2b9b8 263:com.android.quicksearchbox/10012}
PID #270: ProcessRecord{44ff37b8 270:com.android.music/10022}
PID #276: ProcessRecord{450244d8 276:android.process.media/10002}
PID #288: ProcessRecord{450f7ef0 288:com.dreamreminder.org:feather_system_receiver/10057}
PID #299: ProcessRecord{44e7c4c0 299:com.svox.pico/10028}
PID #1065: ProcessRecord{44fa3450 1065:org.chanakyastocktipps.com/10046}
mHomeProcess: ProcessRecord{45062558 129:com.android.launcher/10025}
mConfiguration: { scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 orien=1 layout=18 uiMode=17 seq=3}
mConfigWillChange: false
mSleeping=false mShuttingDown=false
Android Q broke most of these for me. Here's a new one that seems to be working (at least on Android Q).
adb shell "dumpsys activity activities | grep mResumedActivity"
Output looks like:
mResumedActivity: ActivityRecord{7f6df99 u0 com.sample.app/.feature.SampleActivity t92}
Edit: Works on Android R for me as well
dumpsys window windows gives more detail about the current activity:
adb shell "dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'"
mCurrentFocus=Window{41d2c970 u0 com.android.launcher/com.android.launcher2.Launcher}
mFocusedApp=AppWindowToken{4203c170 token=Token{41b77280 ActivityRecord{41b77a28 u0 com.android.launcher/com.android.launcher2.Launcher t3}}}
However in order to find the process ID (e.g. to kill the current activity), use dumpsys activity, and grep on "top-activity":
adb shell "dumpsys activity | grep top-activity"
Proc # 0: fore F/A/T trm: 0 3074:com.android.launcher/u0a8 (top-activity)
adb shell "kill 3074"
This works for me:
adb shell dumpsys activity
And this to show current activity name:
adb shell dumpsys activity activities | grep mFocusedActivity | cut -d . -f 5 | cut -d ' ' -f 1
If you want to filter out only your app's activities currently running/paused, you can use this command:
adb shell dumpsys activity activities | grep 'Hist #' | grep 'YOUR_PACKAGE_NAME'
For example:
adb shell dumpsys activity activities | grep 'Hist #' | grep 'com.supercell.clashroyale'
The output will be something like:
* Hist #2: ActivityRecord{26ba44b u10 com.supercell.clashroyale/StartActivity t27770}
* Hist #1: ActivityRecord{2f3a0236 u10 com.supercell.clashroyale/SomeActivity t27770}
* Hist #0: ActivityRecord{20bbb4ae u10 com.supercell.clashroyale/OtherActivity t27770}
Do notice that the output shows the actual stack of activities i.e. the topmost activity is the one that is currently being displayed.
Old answers stopped working in new android versions. Now I use the following:
adb shell "dumpsys activity activities | grep ResumedActivity"
You can try this command,
adb shell dumpsys activity recents
There you can find current activity name in activity stack.
To get most recent activity name:
adb shell dumpsys activity recents | find "Recent #0"
In windows, this command works for me to show current activity name
adb shell dumpsys window windows | find "mCurrentFocus"
Output:
mCurrentFocus=Window{a43a55b u0 com.android.contacts/com.android.contacts.activities.TwelveKeyDialer}
Other solutions with "grep" command produce error in my windows pc
'grep' is not recognized as an internal or external command, operable program or batch file.
So, using "find" solve the error in my case.
Here is a solution that is easier than the command line adb solution (which does work). It is easier because it is more graphical and can be done from within Eclipse.
In Eclipse with Android device attached go to Window menu > Show View > Other ... use filter text "Windows" to pull up Android > Windows ... show this. The top item in the list is the current activity.
Another way to pull this up is by showing the "Hierarchy View" perspective, which by default will show the Windows window.
Below command can be used for finding both package and current Activity name. Found this very useful command to quickly fetch these two information about an app especially when developing tests with Appium.
adb shell dumpsys window windows | grep -E 'mCurrentFocus'
Response of this command contains both package name and current Activity. For example: in following "com.android.contacts" is the package and "com.android.contacts.activities.TwelveKeyDialer" is current Activity launched on the phone which is connected via adb.
mCurrentFocus=Window{2089af8 u0 com.android.contacts/com.android.contacts.activities.TwelveKeyDialer}
Reference: http://www.automationtestinghub.com/apppackage-and-appactivity-name/
adb shell dumpsys activity activities | grep mFocusedApp works for me.
adb shell "dumpsys activity activities | grep mResumedActivity" does not work for me for my device: Google Pixel 4 Android 12, API 32
adb shell "dumpsys activity activities | grep -E 'mCurrentFocus|mFocusedApp'"
works for me as well.
My version which works for Linux and Windows:
adb shell "dumpsys activity activities | grep mResumedActivity | cut -d "{" -f2 | cut -d ' ' -f3 | cut -d "/" -f1"
Related
How to fix Error: Unknown component while launching activity when pushing the app to a device?
Sometimes (not all times) when I try to push (simply run) the code the from android-studio to my phone (Motorola 3G, though not phone specific), I am getting this error :- 04/22 23:00:14: Launching app No local changes, not deploying APK $ adb shell am start -n "com.xxxx.test/com.horntell.test.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER Error while executing: am start -n "com.horntell.test/com.horntell.test.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.horntell.test/.MainActivity } usage: am [subcommand] [options] usage: am start [-D] [-W] [-P <FILE>] [--start-profiler <FILE>] [--sampling INTERVAL] [-R COUNT] [-S] [--opengl-trace] [--user <USER_ID> | current] <INTENT> am startservice [--user <USER_ID> | current] <INTENT> am stopservice [--user <USER_ID> | current] <INTENT> am force-stop [--user <USER_ID> | all | current] <PACKAGE> am kill [--user <USER_ID> | all | current] <PACKAGE> am kill-all am broadcast [--user <USER_ID> | all | current] <INTENT> am instrument [-r] [-e <NAME> <VALUE>] [-p <FILE>] [-w] [--user <USER_ID> | current] [--no-window-animation] [--abi <ABI>] <COMPONENT> am profile start [--user <USER_ID> current] [--sampling INTERVAL] <PROCESS> <FILE> am profile stop [--user <USER_ID> current] [<PROCESS>] am dumpheap [--user <USER_ID> current] [-n] <PROCESS> <FILE> am set-debug-app [-w] [--persistent] <PACKAGE> am clear-debug-app am set-watch-heap <PROCESS> <MEM-LIMIT> am clear-watch-heap am monitor [--gdb <port>] am hang [--allow-restart] am restart am idle-maintenance am screen-compat [on|off] <PACKAGE> am package-importance <PACKAGE> am to-uri [INTENT] am to-intent-uri [INTENT] am to-app-uri [INTENT] am switch-user <USER_ID> am start-user <USER_ID> am stop-user [-w] <USER_ID> am stack start <DISPLAY_ID> <INTENT> am stack movetask <TASK_ID> <STACK_ID> [true|false] am stack resize <STACK_ID> <LEFT,TOP,RIGHT,BOTTOM> am stack split <STACK_ID> <v|h> [INTENT] am stack list am stack info <STACK_ID> am task lock <TASK_ID> am task lock stop am task resizeable <TASK_ID> [true|false] am task resize <TASK_ID> <LEFT,TOP,RIGHT,BOTTOM> am get-config am set-inactive [--user <USER_ID>] <PACKAGE> true|false am get-inactive [--user <USER_ID>] <PACKAGE> am send-trim-memory [--user <USER_ID>] <PROCESS> [HIDDEN|RUNNING_MODERATE|BACKGROUND|RUNNING_LOW|MODERATE|RUNNING_CRITICAL|COMPLETE] am start: start an Activity. Options are: -D: enable debugging -W: wait for launch to complete --start-profiler <FILE>: start profiler and send results to <FILE> --sampling INTERVAL: use sample profiling with INTERVAL microseconds between samples (use with --start-profiler) -P <FILE>: like above, but profiling stops when app goes idle -R: repeat the activity launch <COUNT> times. Prior to each repeat, the top activity will be finished. -S: force stop the target app before starting the activity --opengl-trace: enable tracing of OpenGL functions --user <USER_ID> | current: Specify which user to run as; if not specified then run as the current user. am startservice: start a Service. Options are: --user <USER_ID> | current: Specify which user to run as; if not specified then run as the current user. am stopservice: stop a Service. Options are: --user <USER_ID> | current: Specify which user to run as; if not specified then run as the current user. am force-stop: force stop everything associated with <PACKAGE>. --user <USER_ID> | all | current: Specify user to force stop; all users if not specified. am kill: Kill all processes associated with <PACKAGE>. Only kills. processes that are safe to kill -- that is, will not impact the user experience. --user <USER_ID> | all | current: Specify user whose processes to kill; all users if not specified. am kill-all: Kill all background processes. am broadcast: send a broadcast Intent. Options are: --user <USER_ID> | all | current: Specify which user to send to; if not specified then send to all users. --receiver-permission <PERMISSION>: Require receiver to hold permission. am instrument: start an Instrumentation. Typically this target <COMPONENT> is the form <TEST_PACKAGE>/<RUNNER_CLASS>. Options are: -r: print raw results (otherwise decode REPORT_KEY_STREAMRESULT). Use with [-e perf true] to generate raw output for performance measurements. -e <NAME> <VALUE>: set argument <NAME> to <VALUE>. For test runners a common form is [-e <testrunner_flag> <value>[,<value>...]]. -p <FILE>: write profiling data to <FILE> -w: wait for instrumentation to finish before returning. Required for test runners. --user <USER_ID> | current: Specify user instrumentation runs in; current user if not specified. --no-window-animation: turn off window animations while running. --abi <ABI>: Launch the instrumented process with the selected ABI. This assumes that the process supports the selected ABI. am profile: start and stop profiler on a process. The given <PROCESS> argument may be either a process name or pid. Options are: --user <USER_ID> | current: When supplying a process name, specify user of process to profile; uses current user if not specified. am dumpheap: dump the heap of a process. The given <PROCESS> argument may be either a process name or pid. Options are: -n: dump native heap instead of managed heap --user <USER_ID> | current: When supplying a process name, specify user of process to dump; uses current user if not specified. am set-debug-app: set application <PACKAGE> to debug. Options are: -w: wait for debugger when application starts --persistent: retain this value am clear-debug-app: clear the previously set-debug-app. am set-watch-heap: start monitoring pss size of <PROCESS>, if it is at or above <HEAP-LIMIT> then a heap dump is collected for the user to report am clear-watch-heap: clear the previously set-watch-heap. am bug-report: request bug report generation; will launch UI when done to select where it should be delivered. am monitor: start monitoring for crashes or ANRs. --gdb: start gdbserv on the given port at crash/ANR am hang: hang the system. --allow-restart: allow watchdog to perform normal system restart am restart: restart the user-space system. am idle-maintenance: perform idle maintenance now. am screen-compat: control screen compatibility mode of <PACKAGE>. am package-importance: print current importance of <PACKAGE>. am to-uri: print the given Intent specification as a URI. am to-intent-uri: print the given Intent specification as an intent: URI. am to-app-uri: print the given Intent specification as an android-app: URI. am switch-user: switch to put USER_ID in the foreground, starting execution of that user if it is currently stopped. am start-user: start USER_ID in background if it is currently stopped, use switch-user if you want to start the user in foreground. am stop-user: stop execution of USER_ID, not allowing it to run any code until a later explicit start or switch to it. -w: wait for stop-user to complete. am stack start: start a new activity on <DISPLAY_ID> using <INTENT>. am stack movetask: move <TASK_ID> from its current stack to the top (true) or bottom (false) of <STACK_ID>. am stack resize: change <STACK_ID> size and position to <LEFT,TOP,RIGHT,BOTTOM>. am stack split: split <STACK_ID> into 2 stacks <v>ertically or <h>orizontally starting the new stack with [INTENT] if specified. If [INTENT] isn't specified and the current stack has more than one task, then the top task of the current task will be moved to the new stack. Command will also force all current tasks in both stacks to be resizeable. am stack list: list all of the activity stacks and their sizes. am stack info: display the information about activity stack <STACK_ID>. am task lock: bring <TASK_ID> to the front and don't allow other tasks to run. am task lock stop: end the current task lock. am task resizeable: change if <TASK_ID> is resizeable (true) or not (false). am task resize: makes sure <TASK_ID> is in a stack with the specified bounds. Forces the task to be resizeable and creates a stack if no existing stack has the specified bounds. am get-config: retrieve the configuration and any recent configurations of the device. am set-inactive: sets the inactive state of an app. am get-inactive: returns the inactive state of an app. am send-trim-memory: Send a memory trim event to a <PROCESS>. <INTENT> specifications include these flags and arguments: [-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>] [-c <CATEGORY> [-c <CATEGORY>] ...] [-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...] [--esn <EXTRA_KEY> ...] [--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...] [--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...] [--el <EXTRA_KEY> <EXTRA_LONG_VALUE> ...] [--ef <EXTRA_KEY> <EXTRA_FLOAT_VALUE> ...] [--eu <EXTRA_KEY> <EXTRA_URI_VALUE> ...] [--ecn <EXTRA_KEY> <EXTRA_COMPONENT_NAME_VALUE>] [--eia <EXTRA_KEY> <EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE...]] (mutiple extras passed as Integer[]) [--eial <EXTRA_KEY> <EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE...]] (mutiple extras passed as List<Integer>) [--ela <EXTRA_KEY> <EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE...]] (mutiple extras passed as Long[]) [--elal <EXTRA_KEY> <EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE...]] (mutiple extras passed as List<Long>) [--efa <EXTRA_KEY> <EXTRA_FLOAT_VALUE>[,<EXTRA_FLOAT_VALUE...]] (mutiple extras passed as Float[]) [--efal <EXTRA_KEY> <EXTRA_FLOAT_VALUE>[,<EXTRA_FLOAT_VALUE...]] (mutiple extras passed as List<Float>) [--esa <EXTRA_KEY> <EXTRA_STRING_VALUE>[,<EXTRA_STRING_VALUE...]] (mutiple extras passed as String[]; to embed a comma into a string, escape it using "\,") [--esal <EXTRA_KEY> <EXTRA_STRING_VALUE>[,<EXTRA_STRING_VALUE...]] (mutiple extras passed as List<String>; to embed a comma into a string, escape it using "\,") [--grant-read-uri-permission] [--grant-write-uri-permission] [--grant-persistable-uri-permission] [--grant-prefix-uri-permission] [--debug-log-resolution] [--exclude-stopped-packages] [--include-stopped-packages] [--activity-brought-to-front] [--activity-clear-top] [--activity-clear-when-task-reset] [--activity-exclude-from-recents] [--activity-launched-from-history] [--activity-multiple-task] [--activity-no-animation] [--activity-no-history] [--activity-no-user-action] [--activity-previous-is-top] [--activity-reorder-to-front] [--activity-reset-task-if-needed] [--activity-single-top] [--activity-clear-task] [--activity-task-on-home] [--receiver-registered-only] [--receiver-replace-pending] [--selector] [<URI> | <PACKAGE> | <COMPONENT>] Error: Unknown component: com.horntell.test/com.horntell.test.MainActivity Error while Launching activity This problem occur mostly when I try to push the code for the first time. i.e. App is not already present in the phone. Sometimes, I have to restart the IDE, or phone or both to resolve this issue and it gets really frustrating sometimes.
I am not sure but I faced a similar problem with Moto mobiles. In Motorola there are user profiles. So if I had more than one user profile then I got similar error in the case when the app was uninstalled from one of the profiles but not the other. So you should try uninstalling the app from all the user profiles before installing it again.
Is there a way to check if Android device screen is locked via adb?
I know that PowerManager and/or KeyguardManager can help me check if a device screen is locked/unlocked. Is there a way to check this via adb?
This command will output everything relating to power for the device: adb shell dumpsys power You can pipe this to a grep to get the values of mHoldingWakeLockSuspendBlocker and mHoldingDisplaySuspendBlocker: adb shell dumpsys power | grep 'mHolding' If both are false, the display is off. If mHoldingWakeLockSuspendBlocker is false, and mHoldingDisplaySuspendBlocker is true, the display is on, but locked. If both are true, the display is on.
Since Lollipop PowerManager.isInteractive() and TrustManager.isDeviceLocked() are the proper methods to check if the device's screen is on and unlocked. And their corresponding service call commands would be: adb shell service call power 12 and adb shell service call trust 7 And this is how it can be checked from Python code without having to find Android version specific service call codes for your device - https://gist.github.com/ktnr74/60ac7bcc2cd17b43f2cb
This works only when device has NFC: # returns one of: mScreenState=OFF|ON_LOCKED|ON_UNLOCKED adb shell dumpsys nfc | grep 'mScreenState=' OFF - Screen off ON_LOCKED - Screen displays locked screen ON_UNLOCKED - device unlocked
Summry other (#Vouskopes, etc) answer here: My Phone: XiaoMi 9 Android: 10 use adb to check status of screen locked method 1: (universal) use mDreamingLockscreen Command: adb shell dumpsys window | grep mDreamingLockscreen Output: mShowingDream=false mDreamingLockscreen=true mDreamingSleepToken=null -> Screen Locked no matter Screen is ON or OFF mShowingDream=false mDreamingLockscreen=false mDreamingSleepToken=null -> Scrren Unlocked method 2: use nfc (if android has NFC module) Command: adb shell dumpsys nfc | grep 'mScreenState=' Output: mScreenState=OFF_LOCKED -> Screen OFF and Locked mScreenState=ON_LOCKED -> Screen ON and Locked mScreenState=ON_UNLOCKED -> Screen ON and Unlocked
Bryan's solution didn't work for my device (Samsung Galaxy S3 running version 4.4.2). For my KitKat GS3: I can reliably tell if the screen is on by checking for mScreenOn=true (works regardless of screen lock state). I can reliably tell if screen is unlocked by checking for mUserActivityTimeoutOverrideFromWindowManager=-1 (works regardless of screen ON or OFF). If that doesn't work for you, I'd recommend you try the following: Lock phone & turn off screen then run: adb shell dumpsys power > dumpsys.power.screen_off.locked.txt Wake phone & keep it locked then run: adb shell dumpsys power > dumpsys.power.screen_on.locked.txt Keep phone awake and unlock screen then run: adb shell dumpsys power > dumpsys.power.screen_on.unlocked.txt Turn screen off, but don't lock it then run: adb shell dumpsys power > dumpsys.power.screen_off.unlocked.txt Then use a text diffing tool (like winmerge) to look for differences between the .txt files.
One adb command I'm using is: adb shell dumpsys window This returns a few system variables that are useful such as mAwake, mShowingLockscreen, mScreenOnEarly, mScreenOnFully. To figure out which correspond to a locked/unlocked screen, I used adb shell dumpsys window > <textFileNameOfYourChoice> tl;dr The combination that I'm finding to be persistent is: Device is locked AND screen is off: mAwake=false AND mShowingLockscreen=true Device is locked AND screen is on: mAwake=true AND mShowingLockscreen=true Device is unlocked AND screen is on: mAwake=true AND mShowingLockscreen=false
Attach a phone and run this code. Press the power button, and see the changes that happen. Unlock the phone and see the changes that happen. Experiment. Have fun. import re import subprocess import time states = { 'no_cached_wake_locks': '', 'mDirty': '', 'mWakefulness': '', 'mWakefulnessChanging': '', 'mIsPowered': '', 'mPlugType': '', 'mBatteryLevel': '', 'mBatteryLevelCriticalLow': '', 'mLastBatteryLevelCriticalLowTime': '', 'mBatteryLevelWhenDreamStarted': '', 'mDockState': '', 'mStayOn': '', 'mProximityPositive': '', 'mBootCompleted': '', 'mSystemReady': '', 'mHalAutoSuspendModeEnabled': '', 'mHalInteractiveModeEnabled': '', 'mWakeLockSummary': '', 'mUserActivitySummary': '', 'mRequestWaitForNegativeProximity': '', 'mSandmanScheduled': '', 'mSandmanSummoned': '', 'mLowPowerModeEnabled': '', 'mBatteryLevelLow': '', 'mLightDeviceIdleMode': '', 'mDeviceIdleMode': '', 'mScreenBrightnessBoostInProgress': '', 'mDisplayReady': '', 'mHoldingWakeLockSuspendBlocker': '', 'mHoldingDisplaySuspendBlocker': '', } def checkit(): cmd = ['adb', 'shell', 'dumpsys', 'power'] proc = subprocess.Popen(cmd, bufsize=0, universal_newlines=True, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) changes = 0 for line2 in proc.stdout.readlines(): line = line2.strip() for state, value in states.items(): m = re.search(r'{}=(.*)'.format(state), line) if m: if value != m.group(1): changes += 1 print("changed: state={} old={} new={}".format(state, value, m.group(1))) states[state] = m.group(1) if changes > 0: print("---- {} changes".format(changes)) while True: checkit() time.sleep(0.5) For exanple, these are the changes that happen after you lock the phone and the screen is black: changed: state=mWakefulness old=Awake new=Asleep changed: state=mHalAutoSuspendModeEnabled old=false new=true changed: state=mHalInteractiveModeEnabled old=true new=false changed: state=mUserActivitySummary old=0x4 new=0x0 changed: state=mHoldingDisplaySuspendBlocker old=true new=false ---- 5 changes changed: state=mWakeLockSummary old=0x1 new=0x0 changed: state=mHoldingWakeLockSuspendBlocker old=true new=false ---- 2 changes changed: state=mWakeLockSummary old=0x0 new=0x1 changed: state=mHoldingWakeLockSuspendBlocker old=false new=true ---- 2 changes changed: state=mWakeLockSummary old=0x1 new=0x0 changed: state=mHoldingWakeLockSuspendBlocker old=true new=false ---- 2 changes
If its a rooted phone you can check some fields related to lock in settings.db. settings.db is located at /data/data/com.android.providers.settings/databases
try adb shell dumpsys window | grep mCurrentFocus | grep StatusBar; since all unlocked status(include wrong PIN) executed by this CMD return mCurrentFocus=Window{343b978 u0 StatusBar} example like: #!/bin/bash if adb shell dumpsys window | grep mCurrentFocus | grep -q StatusBar; then echo 'phone is locked'; exit 0; fi echo 'phone is unlocked' By Android 10;
Worked with my Galaxy Note + (Locked with passcode) unlock() { if adb shell dumpsys window | grep mCurrentFocus | grep -n NotificationShade; then adb shell 'input keyevent 26 && input keyevent 82' if adb shell dumpsys window | grep mCurrentFocus | grep -n Bouncer; then echo "Device was locked" adb shell 'input text 12345678 && input keyevent 66' fi fi }
Omitting the lock status ; things that work on Android 12 and 13 : IMPORTANT : those return nothing after the device been restarted. if the three commands below return "", use "adb shell input keyevent 26" and try again. adb shell getprop debug.tracing.screen_state "2" means screen ON Note : Does NOT work on older Android versions (9, 10 .. ) adb shell dumpsys input_method | grep -i screenon Result : "screenOn = false" or "screenOn = true" Notes : slower than other two commands (~2 sec) does not work on all models; use the two other options in those case adb shell dumpsys power | grep mWakefulness= | head -1 Screen ON gives mWakefulness=Awake Notes : grep with "=" to avoid "mWakefulnessChanging" make sure to look for "=Awake" because some device return "Partial awake" just after screen turned off does not work on all models; use the two other options
How to start this activity use adb shell am start -D -d pg/xx.The activity name is Main$Activity
I want to debug android's so file. I use start an Activity: am start [-D] [-W] to start activitey. the applicationg package name is com.dualboot.apps.springzen . the main activity is com.dualboot.apps.springzen.Main$Activity . i use command 'adb shell am start com.dualboot.apps.springzen/com.dualboot.springzen.Main$Actinity' it's not exist Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.dualboot.apps.springzen/com.dualboot.springzen.Main } Error type 3 Error: Activity class {com.dualboot.apps.springzen/com.dualboot.springzen.Main} does not exist. how to start this activity
Since you are calling a component you need to include the component -n option tag. Use this: adb shell am start -n com.dualboot.apps.springzen/.MainActivity if you actually have the $ in your class name (I doubt it) which usually refers to an inner class then you need to use: adb shell am start -n com.dualboot.apps.springzen/.Main\$Activity
How do I get the content of excuting commend with Su?
When I excuted a commend, such as am start -W -n com.xxx.xxx/.xxActivity I can see the content. Starting: Intent { cmp=com.xxx.xxx/.xxActivity } Status: ok Activity: com.xxx.xxx/.xxActivity ThisTime: 52 TotalTime: 71 Complete But when I excuted a commend with su ,such as su -c "am start -W -n com.xxx.xxx/.xxActivity" there is nothing to output, how can I get the output with su?
The standard Android su works as expected if run properly: $ su 0 am start -W -n com.android.settings/.Settings Starting: Intent { cmp=com.android.settings/.Settings } Warning: Activity not started, its current task has been brought to the front Status: ok Activity: com.android.settings/.Settings ThisTime: 0 TotalTime: 0 Complete Here's an excerpt from the su.c code: /* * SU can be given a specific command to exec. UID _must_ be * specified for this (ie argc => 3). * * Usage: * su 1000 * su 1000 ls -l * or * su [uid[,gid[,group1]...] [cmd]] * E.g. * su 1000,shell,net_bw_acct,net_bw_stats id * will return * uid=1000(system) gid=2000(shell) groups=3006(net_bw_stats),3007(net_bw_acct) */
Android dumpsys activity output format
After this command adb shell dumpsys activity p | grep <package> I get this output: *APP* UID 10060 ProcessRecord{41941528 23873:com.example.testservicestate/u0a60} dir=/data/app/com.example.testservicestate-1.apk publicDir=/data/app/com.example.testservicestate-1.apk data=/data/data/com.example.testservicestate packageList={com.example.testservicestate} - ActivityRecord{42073a50 u0 com.example.testservicestate/.MainActivity t211} Proc # 0: fore F/A/T trm: 0 23873:com.example.testservicestate/u0a60 (top-activity) PID #23873: ProcessRecord{41941528 23873:com.example.testservicestate/u0a60} Which is the meaning of those infos or where can I find the format for this command. Especially Iḿ interested in those letters F/A/T . Thanks!
As usual you can find all the info in the Android source code. In this case F/A/T stands for the activity in question being a foreground activity (A) and its process being in PROCESS_STATE_TOP state (T) and belonging to the THREAD_GROUP_DEFAULT scheduling group (F)