Unable To get Activity name from adb command Android 10 - android

I'm trying to get activity name for current focused app on the device by running this command:
adb shell "dumpsys window windows | grep -E 'mCurrentFocusApp|mFocusedApp'"
It works on older phone with Android 6.0 but on Pixel XL running Android 10 its returns nothing.
If I run only dumpsys window windows it returns bunch of unfiltered info which is not very efficient for me.

adb shell dumpsys activity a . | grep -E 'mResumedActivity' | cut -d ' ' -f 8

John answer is great but u can use:
adb shell dumpsys window windows | grep mActivityRecord
in that case u get list of all current run app in memory
if u kill all app and run the one u want u get 2 records
# launcher
mActivityRecord=ActivityRecord{99197dc u0 com.sec.android.app.launcher/.activities.LauncherActivity t3161}
# active app
mActivityRecord=ActivityRecord{6dec4d5 u0 com.google.android.googlequicksearchbox/com.google.android.apps.gsa.monet.MonetActivity t3711}

adb shell dumpsys activity activities | grep "mFocused"
It worked on android 10 & 11.

Related

How to launch the previous screen app activity to my emulator?

While on a certain window of the android Settings I run the command in terminal
adb shell dumpsys window windows | grep 'mCurrentFocus'
and I was able to get the result
mCurrentFocus=Window{f167e7a u0
com.android.settings/com.android.settings.Settings$NetworkDashboardActivity}
Now, how am I able to launch the mCurrentFocus using an ADB command on my emulator?
dumpsys window windows grep -e 'mCurrentFocus'

why i can't get adb shell top works?

I'm testing an android app by my PC. I try to catch the CPU usage of it.
if I use
adb shell top -m 10 |tee aa.txt
it works fine.
but if i modify it like this
adb shell top -m 10 |grep myAPPname|tee aa.txt
it can not. Why and how to make it work again?
try the command below:
while true; do
adb shell top -m 10 -n 1 | grep kso >> aa
done
-n means only show the current status instead of updating frequently.
However, I suggest you use Android Profiler which is a built-in function in Android Studio to achieve your monitoring work.

Unpin application with adb shell commands in android lollipop

Summary
Is there a way to unpin apps in lollipop using shell commands
with adb iv tried:
adb shell input keyevent --longpress 4 187
but this never worked
Why i want to do this
1) i'm making a root application that replaces the on screen navigation buttons and need a way to unpin other apps
2) when using a virtual device and i pin a app there is no way for me to press back and recents at the same time with my mouse
Try this command to unpin the foreground app:
am task lock stop `dumpsys activity | grep -A2 "(dumpsys activity recents)"| grep '#'| cut -d ' ' -f 7| cut -c 2-`
adb shell am task lock stop `dumpsys activity | grep -A2 '(dumpsys
activity recents)'| grep '#'| cut -d ' ' " \
"-f 7| cut -c 2-
This works with Android 9+ devices
This works with android 4.4.2
adb shell su -c 'sqlite3 /data/data/com.android.launcher/databases/launcher.db "DELETE from favorites"'

Using ADB command know the name of application focussed using adb [duplicate]

This question already has answers here:
ADB - Android - Getting the name of the current activity
(13 answers)
Closed 4 years ago.
I am using the
adb shell input keyevent KEYCODE_DPAD_LEFT
to focus on an application, now i want to know the name of the application on which this has focussed using adb shell command.
NOTE: not exactly the name of application, it can focus on anything. SO i want to get the Text on which it focusses.
Ok. To do it, you need to use grep terminal application on your phone (the easiest way with rooted phone with busybox package). Let do the same steps as below:
C:\Users\Hasan>adb shell input keyevent KEYCODE_DPAD_LEFT
C:\Users\Hasan>adb shell
shell#android:/ $ su
su
root#android:/ # dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'
dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'
mCurrentFocus=Window{42079c60 com.jrummy.liberty.toolboxpro/com.jrummy.apps.rom.toolbox.RomToolboxActivity paused=false}
mFocusedApp=AppWindowToken{4283d918 token=Token{426709a8 ActivityRecord{41e37c60 com.jrummy.liberty.toolboxpro/com.jrummy.apps.rom.toolbox.RomToolboxActivity}}}
root#android:/ #
Now you'll see which activity has focus :)
You can use:
adb shell uiautomator dump /dev/tty
You will get an XML describing the current screen, one of the many <node>-elements will have an attribute focused="true". It may also have a text-attribute and a lot more UI-informations.

get launchable activity name of package from adb

Is there a way to get the launchable activity for a package from using adb? For an unroot phone (i.e. without having the pull the apk from /data/app directory and inspect with appt).
I tried dumpsys, but it does not include information on default launchable activity.
Thanks
You don't need root to pull the apk files from /data/app. Sure, you might not have permissions to list the contents of that directory, but you can find the file locations of APKs with:
adb shell pm list packages -f
Then you can use adb pull:
adb pull <APK path from previous command>
and then aapt to get the information you want:
aapt dump badging <pulledfile.apk>
$ adb shell pm dump PACKAGE_NAME | grep -A 1 MAIN
Since Android 7.0 you can use adb shell cmd package resolve-activity command to get the default activity of an installed app like this:
adb shell "cmd package resolve-activity --brief com.google.android.calculator | tail -n 1"
com.google.android.calculator/com.android.calculator2.Calculator
#!/bin/bash
#file getActivity.sh
package_name=$1
#launch app by package name
adb shell monkey -p ${package_name} -c android.intent.category.LAUNCHER 1;
sleep 1;
#get Activity name
adb shell logcat -d | grep 'START u0' | tail -n 1 | sed 's/.*cmp=\(.*\)} .*/\1/g'
sample:
getActivity.sh com.tencent.mm
com.tencent.mm/.ui.LauncherUI
I didn't find it listed so updating the list.
You need to have the apk installed and running in front on your phone for this solution:
Windows CMD line:
adb shell dumpsys window windows | findstr <any unique string from your pkg Name>
Linux Terminal:
adb shell dumpsys window windows | grep -i <any unique string from your Pkg Name>
OUTPUT for Calculator package would be:
Window #7 Window{39ced4b1 u0 com.android.calculator2/com.android.calculator2.Calculator}:
mOwnerUid=10036 mShowToOwnerOnly=true package=com.android.calculator2 appop=NONE
mToken=AppWindowToken{29a4bed4 token=Token{2f850b1a ActivityRecord{eefe5c5 u0 com.android.calculator2/.Calculator t322}}}
mRootToken=AppWindowToken{29a4bed4 token=Token{2f850b1a ActivityRecord{eefe5c5 u0 com.android.calculator2/.Calculator t322}}}
mAppToken=AppWindowToken{29a4bed4 token=Token{2f850b1a ActivityRecord{eefe5c5 u0 com.android.calculator2/.Calculator t322}}}
WindowStateAnimator{3e160d22 com.android.calculator2/com.android.calculator2.Calculator}:
mSurface=Surface(name=com.android.calculator2/com.android.calculator2.Calculator)
mCurrentFocus=Window{39ced4b1 u0 com.android.calculator2/com.android.calculator2.Calculator}
mFocusedApp=AppWindowToken{29a4bed4 token=Token{2f850b1a ActivityRecord{eefe5c5 u0 com.android.calculator2/.Calculator t322}}}
Main part is, First Line:
Window #7 Window{39ced4b1 u0 com.android.calculator2/com.android.calculator2.Calculator}:
First part of the output is package name:
com.android.calculator2
Second Part of output (which is after /) can be two things, in our case its:
com.android.calculator2.Calculator
<PKg name>.<activity name> =
<com.android.calculator2>.<Calculator>
so .Calculator is our activity
If second part is entirely different from Package name and doesn't seem to contain pkg name which was before / in out output, then entire
second part can be used as main activity.
Here is another way to find out apps package name and launcher activity.
Step1: Start "adb logcat" in command prompt.
Step2: Open the app (either in emulator or real device)
You can also use ddms for logcat logs where just giving search of the app name you will all info but you have to select Info instead of verbose or other options. check this below image.
Launch your app and keep it in foreground.
Run the below command:
adb shell dumpsys window windows | find "mcurrentfocus"
mCurrentFocus doesn't work for me on Android 12 device.
Here is the right step to go:
Connect the device and open the app.
adb shell dumpsys window windows | grep -E mObscuringWindow
mObscuringWindow=Window{bc78a3 u0 com.yds.demo/com.test.activity.AppActivity}
com.test.activity.AppActivity is the activity.

Categories

Resources