SoFunction
Updated on 2025-03-04

Description of the function and usage of pm tool in Android adb command

Everyone who plays Android knows adb, and everyone who plays adb knows install and uninstall, but why should there be a pm in the middle of the adb shell pm install packagename command? What does pm mean and what does it work? I'm afraid not everyone can answer this question.

The pm tool is the abbreviation of package manager. You can use the pm tool to execute application installation and query application package information, system permissions, and control applications. PM tool is an indispensable tool in Android development and testing, usually placed under /system/bin/.

Enter pm in command line mode, the system provides the help manual as follows:


usage: pm [list|path|install|uninstall]
 pm list packages [-f] [-d] [-e] [-u] [FILTER]
 pm list permission-groups
 pm list permissions [-g] [-f] [-d] [-u] [GROUP]
 pm list instrumentation [-f] [TARGET-PACKAGE]
 pm list features
 pm list libraries
 pm path PACKAGE
 pm install [-l] [-r] [-t] [-i INSTALLER_PACKAGE_NAME] [-s] [-f] PATH
 pm uninstall [-k] PACKAGE
 pm clear PACKAGE
 pm enable PACKAGE_OR_COMPONENT
 pm disable PACKAGE_OR_COMPONENT
 pm setInstallLocation [0/auto] [1/internal] [2/external]

....Omitted....

It can be seen that it is meaningless when used alone. It must be used with relevant commands and placed before the corresponding commands. If other commands are not prefixed by pm, they cannot be used either. For example, you can enter a list packages command on the command line and try it, and the system will prompt "list: permission denied!" In other words, any command related to the application package must be in the format of pm + "specific commands" to be valid, otherwise it will be invalid!

OK, let’s explain the basic usage of pm tools, so let’s analyze some commonly used commands in pm tools (the so-called frequent use is not commonly used, which means my personal feeling. If you find any omissions, please inform me ^_^):

1. Query category

list packages: list all application packages (including system applications and user applications) that have been installed in the device;

list features: list all hardware-related information;

list libraries: list libs supported by the current device;

list users: list all users on the system;

list permissions: list all known permissions;

list 'pkgname': lists the associated file (APK archive file) with the specified package name;

path 'pkgname': query the installation location of the package.

2. Operation category

install [-lrtsfd] [PATH]: Install command;

** -l: Lock the application;

** -r: Reinstall the application and retain the application data;

** -i: Specify the package name of the installation package;

** -s: Install to the SD card;

** -f: Installed into the system built-in storage (default installation location);

** -g: Grant all permissions listed in the application manifest (only available in 6.0 systems);

uninstall [options] ‘pkgname’: uninstall command;

** -k: Uninstall the application and retain data and cache (if -k is not added, delete all);

clear 'pkgname': delete all data on the specified package;

enable 'pkgname' : Make package or component available. (For example: pm enable “package/class”);

disable 'pkgname': Makes the package or component unavailable. (For example: pm disable "package/class");

grant 'pkgname': authorized to the application;

revoke 'pkgname': revoke permission;

set-install-location 'location': Set the default installation location. Among them 0: Let the system automatically select the best installation location.

1: Install to the internal device storage space.

2: Install to external device storage space;

get-install-location: Returns the current installation location. Return the result and the parameter options are the same as above;

create-user ‘USER_NAME’: add a new USER;

remove-user ‘USER_ID’: delete a USER;

Supplementary knowledge:adb command pm hide and disable

pm disable <PACKAGE_OR_COMPONENT>: Make the package or component unavailable. (For example: pm disable "package/class") (disables the specified package, but getComponentEnabledSettingThe components in the package are still enabled. The same principle as disable-user.) Root permission is required.

Equivalent code:


getActivity().getPackageManager().
 setApplicationEnabledSetting(getActivity().getPackageName(),
 PackageManager.COMPONENT_ENABLED_STATE_DISABLED,  
PackageManager.DONT_KILL_APP);//Don't killapp,appIt will only be hidden after the process terminates;0Terminate immediately

pm hide <PACKAGE_OR_COMPONENT>: Make the package or component unavailable.

hide

disable

getPackageManager().getInstalledPackages

(PackageManager.GET_UNINSTALLED_PACKAGES);

visible

visible

getPackageManager().getInstalledPackages

(PackageManager.GET_DISABLED_COMPONENTS);

Not visible

visible

getPackageManager().getInstalledPackages(0);

Not visible

visible

pm lf

Not visible

visible

pm list package -d

Not visible

visible

pm list package -u

visible

visible

Settings - Application Management has been downloaded

Meizu installation app is not visible

Meizu installation app is not visible

Settings-Application Management is all

Meizu installation app is not visible

Meizu installation app is not visible

am start

Not available

Not available

The above explanation of the function and usage of pm tools in the Android adb command is all the content I have shared with you. I hope you can give you a reference and I hope you can support me more.