I have a problem of an app that open a site every time open the browser.
I found the id of the app with this intent by adb and now I'm wondering if there is a way to find the package name by the app id without root permissions.
For UnRooted devices following works for me:
Set up adb in a PC, connect the device to the PC, launch a shell on the PC and enter:
adb shell "dumpsys package | grep -A1 'userId=UID'"
Replace UID with the ID you're looking for, such as 10102.
Example:
bash-4.2# adb shell "dumpsys package | grep -A1 'userId=10102'"
userId=10102
pkg=Package{46171ce com.android.chrome}
bash-4.2#
The line containing Package{would show the package name of the app in between whitespace and}. You can do adb shell dumpsys package PKG_NAME (PKG_NAME → package name of an app) to know more details about that package/app.
Related
I'm working on a voice assistant, and every time the app is deployed on the phone, I need to change again the default assistant to my app. Just a few clicks, but 100 times a day, that's some time gone !!
Something similar exists for setting the default launcher
adb shell cmd package set-home-activity "the.package/.TheLauncherActivity"
So I tried
adb shell cmd package set-assistant "the.package/.TheLauncherActivity"
adb shell cmd package set-voice-assistant "the.package/.TheLauncherActivity"
adb shell cmd package set-assist "the.package/.TheLauncherActivity"
adb shell cmd package set-voice-assist "the.package/.TheLauncherActivity"
It's weird because the assistant itself is more a service than an activity, but anyways, all I got is:
Unknown command: set-voice-assist (and the others)
So I guess I'm not even close.
I'm not sure if you were looking for something like this:
$ adb shell cmd role remove-role-holder --user 10 android.app.role.ASSISTANT com.google.android.carassistant
$ adb shell cmd role add-role-holder --user 10 android.app.role.ASSISTANT CUSTOM.PACKAGE.NAME
Good information about Role managing can be found here:
http://aospxref.com/android-12.0.0_r3/xref/packages/modules/Permission/PermissionController/src/com/android/permissioncontroller/role/Role.md
and list of the roles: http://aospxref.com/android-12.0.0_r3/xref/packages/modules/Permission/framework-s/api/current.txt#8
If your device contains custom build of AOSP and you have the platform key you are able write own app which will change role holders with method RoleManager.addRoleHolderAsUser.
What I have:
I have application installed in device
I have a Mac system and I am using terminal
I am connected to device via terminal
What I am trying to do:
I am trying to launch the installed application via terminal ( I
don't want to reinstall the app and run )
I need to find the app via package name and run it
What I have tried:
admins-MacBook-Pro:platform-tools devrath$ ./adb shell monkey -p com.cnx.dictionary -c android.intent.category.LAUNCHER 1
Error I am getting:
** No activities found to run, monkey aborted.
To find the package, use adb shell pm list packages. There will more than likely be a lot of packages listed. If you know a part of the package name, you can use grep to limit your results. If you were looking for the Facebook package name, you could use adb shell pm list packages | grep facebook and it would only show results with facebook in it.
From there, you need you find the class to start.
adb shell
dumpsys package | grep -Eo "^[[:space:]]+[0-9a-f]+[[:space:]]+com.packagename/[^[:space:]]+" | grep -oE "[^[:space:]]+$" (make sure you change the "com.packagename" part to the name of your package.
Find the class you want to use from the output list. Most apps will have a class of .SplashActivity, .HomeActivity, or .Main but you will have to find the one for your app
When you have that, use am start -n com.packagename/.Class where your package name replaces com.packagename and the class you chose replaces .Class.
One thing to note. In step 1, we used the command adb shell so we are in the of the android device issuing the commands after. If you are issuing the am start command at the main terminal screen, you will have to add adb shell before am start.
I used the zebra site a while back to get this info initially so i left it here for your reference as well.
When I just run adb shell, I get shell running from uid=2000(shell) gid=2000(shell), without ptrace access to my application.
How to open a shell with the same UID as launched application?
Use run-as <your package name> to switch to your app's UID or run-as <your package name> <command> to run a single command with your app's UID.
From this answer:
The packages.xml file present in /data/system
The packages.list file present in /data/system
Contain the list of applications installed and their corresponding UID's.
Another answer in the same question suggests:
adb shell dumpsys package com.example.myapp | grep userId=
You can then open your shell as normal and run:
$ su <UID>
You should then have the same access and privileges as the app that uses that UID.
Workaround way using socat:
Add android.permission.INTERNET to your application;
Put socat binary (mirror) to /data/local/tmp/. Ensure everybody can start it;
Add Runtime.getRuntime().exec("/data/local/tmp/socat tcp-l:4446,fork,reuseaddr exec:/system/bin/sh,pty,stderr,setsid"); at startup of your Java-based application;
adb forward tcp:4446 tcp:4446
Use socat `tty`,raw,echo=0,opost=1 tcp:127.0.0.1:4446 on host to connect to the shell in your application context.
Note that this setup is not secure and should not be left in production app.
I can install an apk through adb without any issue.
But after I install it, I want to OPEN that package through adb. I want to send an Intent to the package that opens the MAIN or LAUNCHER activity just how the launcher would.
But adb seems to always want to me include an activity name in my intent.
How do I get around this?
Can I scan an apk for all the package names? For the main one?
Is there a way to open it through adb without an Activity name?
With aapt you can find the launchable activity, for example:
$ aapt dump badging file.apk | grep package
package: name='com.triposo.droidguide.world' versionCode='161' versionName='2.1'
$ aapt dump badging file.apk | grep launchable
launchable-activity: name='com.triposo.droidguide.world.SplashActivity' label='' icon=''
To specify an intent when you launch an activity, you can use a MonkeyRunner script and MonkeyDevice.startActivity:
from com.android.monkeyrunner import MonkeyRunner
device = MonkeyRunner.waitForConnection()
package = 'com.triposo.droidguide.world'
launchable_activity = 'com.triposo.droidguide.world.SplashActivity'
device.startActivity(component='%s/%s' % (package, launchable_activity)))
Through adb you can simplify the app opening process by using monkey from adb itself without needing to find the launchable activity.
For example, to open Facebook:
adb shell monkey -p com.facebook.katana 1
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.