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

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'

Related

Unable To get Activity name from adb command Android 10

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.

What is the "window name" in android?

I want to execute the adb command "dumpsys SurfaceFlinger --latency[window name]". But I don't know what "window name" means. What does that mean, and how do you get it?
It is the window name in which you are interested.
You can get the window name by tapping on the activity window you are interested in and then typing
adb shell dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'
Here is what you will get something like this
mCurrentFocus=Window{a3dfcbc u0 com.android.chrome/com.google.android.apps.chrome.Main}
mFocusedApp=AppWindowToken{27e3a63 token=Token{d08ff65 ActivityRecord{973205c u0 com.android.chrome/com.google.android.apps.chrome.Main t647}}}
Here your window is com.android.chrome/com.google.android.apps.chrome.Main
Here is link for more information.

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"'

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.

How to kill native applications from 'adb shell'?

I am able to start native applications using am start -a action -n packagename/activity. How can I kill/stop a native application from adb shell?
adb shell am force-stop packagename
Chirag deleted it, so here it is again:
adb shell ps | grep com.myapp | awk '{print $2}' | xargs adb shell kill
This is to be run outside of the emulator. It is one long Unix command, not four commands with a visual separation. | is syntax, interpreted by your (Ubuntu's) shell, which then pipes the output from adb, grep, etc., into the next. Only ps is executed in the emulator.
Another way to kill your app is to send your app to backround (using home button) and call:
adb shell am kill com.your.package
It works not on all of my devices, however, on devices where it works it behaves the same way as if the app was killed in background due to lack of resources and this state is often handy to test different aspects of your process recreation.
For example, if you have Broadcast Receivers registered in Manifest, they will still start without restarting your app manually, comparing to force stop that you can achieve using:
adb shell am force-stop com.your.package
Please try the below command in adb shell.
adb shell kill <PID>

Categories

Resources