Android adb pm disable component - android

I am trying to understand the use of the following command:
adb shell pm disable <PACKAGE_OR_COMPONENT>
For example: I have a test app with package name 'com.example.com.testapp' and it has an activity called 'TestActivity'.
I ran the following from my terminal :
./adb shell pm disable com.example.com.testapp/TestActivity
From the name of the command, I thought it would disable the activity from launching, but I can launch it fine via adb as follows:
./adb shell am start -n com.example.com.testapp/.TestActivity
So what does this command disable then ?

I found the problem. It has nothing to do whether device is rooted or not.
I command had a missing dot. It should be :
./adb shell pm disable com.example.com.testapp/.TestActivity
Now if I try to launch the component, it's blocked (the app stops working).

Related

adb command to set voice assistant

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.

Did I use the wrong adb permissions for apps to not get killed in the background?

Hi so I'm new to this whole adb thing and used this code cmd appops set <package_name> RUN_ANY_IN_BACKGROUND allow in adb shell since I have android 10 then I restarted my phone. So far I think it doesn't work is there a specific command that I should use for this that I missed for some reason.
To manually apply background restrictions, run this command:
$ adb shell cmd appops set packagename RUN_ANY_IN_BACKGROUND ignore
To remove background restrictions, run this command:
$ adb shell cmd appops set packagename RUN_ANY_IN_BACKGROUND allow

Detecting if emulator has started completely

I want to check if all the emulators has booted successfully. I have tried with this command adb shell getprop sys.boot_completed this works if i am running one emulator. But if i have more than one emulator this command returns error as following: error: more than one device/emulator.How to solve this?
You should specify the device serial number on the adb command line to let it know which one you want to interact with.
Something like
adb -s emulator-5554 shell ...
Also, if you are doing it from the command line, multiple times and you are starting to be annoyed by that, you can try https://gist.github.com/dtmilano/4537110 which allows you to select the device
$ adb shell
1) 02783201431feeee device 3) emulator-5554
2) 3832380FA5F30000 device 4) emulator-5556
Select the device to use, <Q> to quit: 1
$

How can I launch the App Info screen for my app through ADB?

I want to launch the App Info screen for my app through adb. I tried to fire an intent using "adb shell am start" but nothing seems to work. I need something that works at least for API levels 18 and 19. Can anyone help?
Open App Info
adb shell am start -a android.settings.APPLICATION_DETAILS_SETTINGS package:com.your.packagename
For Example: if you want to open Chrome App Info
adb shell am start -a android.settings.APPLICATION_DETAILS_SETTINGS package:com.android.chrome
adb shell am start -n yourpackagename/.activityname

How to start an application using Android ADB tools

How do I send an intent using Android's ADB tools?
adb shell
am start -n com.package.name/com.package.name.ActivityName
Or you can use this directly:
adb shell am start -n com.package.name/com.package.name.ActivityName
You can also specify actions to be filter by your intent-filters:
am start -a com.example.ACTION_NAME -n com.package.name/com.package.name.ActivityName
It's possible to run an application specifying the package name only using the monkey tool by follow this pattern:
adb shell monkey -p your.app.package.name -c android.intent.category.LAUNCHER 1
The command is used to run the app using the monkey tool which generates random input for the application. The last part of the command is an integer which specifies the number of generated random input for the app. In this case the number is 1, which in fact is used to launch the app (icon click).
Or, you could use this:
adb shell am start -n com.package.name/.ActivityName
Linux and Mac users can also create a script to run an APK file with something like the following:
Create a file named "adb-run.sh" with these three lines:
pkg=$(aapt dump badging $1|awk -F" " '/package/ {print $2}'|awk -F"'" '/name=/ {print $2}')
act=$(aapt dump badging $1|awk -F" " '/launchable-activity/ {print $2}'|awk -F"'" '/name=/ {print $2}')
adb shell am start -n $pkg/$act
Then "chmod +x adb-run.sh" to make it executable.
Now you can simply:
adb-run.sh myapp.apk
The benefit here is that you don't need to know the package name or launchable activity name. Similarly, you can create "adb-uninstall.sh myapp.apk"
Note: This requires that you have Android Asset Packaging Tool (aapt) in your path. You can find it under the new build tools folder in the SDK.
Step 1: First get all the package names of the apps installed in your device, by using:
adb shell pm list packages
Step 2: You will get all the package names. Copy the one you want to start using ADB.
Step 3: Add your desired package name in the below command.
adb shell monkey -p 'your package name' -v 500
For example,
adb shell monkey -p com.estrongs.android.pop -v 500
to start the Es explorer.
The shortest command yet is the following:
adb shell monkey -p your.app.package.name 1
This will launch the default activity for the package that is in the launcher.
Thanks to Androiderson for the tip.
Also, I want to mention one more thing.
When you start an application from adb shell am, it automatically adds FLAG_ACTIVITY_NEW_TASK flag which makes behavior change. See the code.
For example, if you launch a Play Store activity from adb shell am, pressing the 'Back' button (hardware back button) wouldn't take you back to your app. Instead, it would take you to the previous Play Store activity if there was some (if there was not a Play store task, then it would take you back to your app). FLAG_ACTIVITY_NEW_TASK documentation says:
if a task is already running for the activity you are now starting, then a new activity will not be started; instead, the current task will simply be brought to the front of the screen with the state it was last in
This caused me to spend a few hours to find out what went wrong.
So, keep in mind that adb shell am add FLAG_ACTIVITY_NEW_TASK flag.
We can as well start an application by knowing the application type and feeding it with data:
adb shell am start -d "file:///sdcard/sample.3gp" -t "video/3gp" -a android.intent.action.VIEW
This command displays available *video players to play a sample.3gp file.
You can find your app package name by the below command:
adb shell pm list packages
The above command returns a package list of all apps. Example:
org.linphone.debug
.
.
com.android.email
Now I want to start app linphone by using the below command and this worked for me:
adb shell am start org.linphone.debug
Open file ~/.bash_profile, and add these Bash functions to the end of the file
function androidinstall(){
adb install -r ./bin/$1.apk
}
function androidrun(){
ant clean debug
adb shell am start -n $1/$1.$2
}
Then open the Android project folder:
androidinstall app-debug && androidrun com.example.app MainActivity
monkey --pct-syskeys 0 for development boards
This argument is needed for development boards without keys/display:
adb shell monkey --pct-syskeys 0 -p com.cirosantilli.android_cheat.textviewbold 1
Without it, the app won't open, and you will get an error message like:
SYS_KEYS has no physical keys but with factor 2.0%
It was tested on HiKey960, Android O AOSP.
Learned from: this GitHub issue
Also asked at: How to use the monkey command with an Android system that doesn't have physical keys?
Use:
adb shell am start -n '<appPackageName>/.<appActitivityName>
Example:
adb shell am start -n 'com.android.settings/.wifi.WifiStatusTest'
You can use the APK-INFO application to know the list of app activities with respect to each app package.
adb shell am start -n com.app.package.name/com.java.package.name.ActivityName
Example
adb shell am start -n com.google.android.googlequicksearchbox/com.google.android.search.core.google.GoogleSearch
If the Java package is the same, then it can be shortened:
adb shell am start -n com.example.package/.subpackage.ActivityName
Use:
adb shell am start -n '<appPackageName>/<appActitivityName>'
To get <appPackageName> run :
adb shell pm list packages
To get <appActitivityName> lunch app and run
adb shell dumpsys window | grep -E 'mCurrentFocus'
Try this, for opening an Android photo app and with the specific image file to open as a parameter.
adb shell am start -n com.google.android.apps.photos/.home.HomeActivity -d file:///mnt/user/0/primary/Pictures/Screenshots/Screenshot.png
It will work on latest version of Android. No pop up will come to select an application to open as you are giving the specific app to which you want to open your image with.
When you try to open a Flutter app, you can use this command:
adb shell am start -n com.package.name/io.flutter.embedding.android.FlutterActivity
Replace com.package.name with your package name. You find your package in your app/build.gradle at applicationId.

Categories

Resources