Function and usage of pm tool in Android adb command

  • 2021-12-05 07:21:18
  • OfStack

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

pm tool is the abbreviation of package management (package manager). pm tool can be used to perform application installation, query application package information, system authority and control application. The pm tool is an essential tool in the development and testing of Android, and is usually placed under/system/bin/.

Enter pm in command line mode, and the system gives the following help manual:



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]

.... Omit ....

Thus, the pm tool is meaningless when used alone, and it must be used with the relevant command 1 before the corresponding command. Other commands can't be used if they are not prefixed with pm. For example, you can try entering an list packages command on the command line, and the system will prompt "list: permission denied!" That is to say, any command related to the application package must be in the format of pm + "concrete command" to be valid, otherwise it is invalid!

OK, explain the basic usage of pm tool, then let's analyze some commands commonly used in pm tool (the so-called often not commonly used refers to my personal feeling, if you find any omissions, please tell me _):

1. Query class

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

list features: Lists all hardware-related information;

list libraries: Lists the libs supported by the current device;

list users: List all users on the system;

list permissions: Lists all known permissions;

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

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

2. Action classes

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

**-l: Lock the application;

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

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

**-s: Installed to sd card;

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

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

uninstall [options] 'pkgname': Uninstall command;

**-k: Uninstall the application and keep the data and cache (delete all without-k);

clear 'pkgname': Delete all data for the specified package;

enable 'pkgname': Make package or component available (e.g. pm enable "package/class");

disable 'pkgname': Make package or component unavailable (e.g. pm disable "package/class");

grant 'pkgname': Licensed to application;

revoke 'pkgname': Revoke permissions;

set-install-location 'location': Set the default installation location. Where 0: Allows the system to automatically select the best installation location.

1: Install into internal device storage space.

2. Storage space of equipment installed to the outside;

get-install-location: Returns the current installation location. The return result is the same as the above parameter option;

create-user 'USER_NAME': Add a new USER;

remove-user 'USER_ID': Delete 1 USER;

Additional knowledge: pm, hide and disable of adb command

pm disable < PACKAGE_OR_COMPONENT > Make package or component unavailable. (E. G. pm disable "package/class") (disable specifies package, but getComponentEnabledSetting components in package is still in enable state. disable-user1-like principle.) root permission is required.

Equivalent code:



getActivity().getPackageManager().
 setApplicationEnabledSetting(getActivity().getPackageName(),
 PackageManager.COMPONENT_ENABLED_STATE_DISABLED,  
PackageManager.DONT_KILL_APP);// Do not kill app , app It will not be hidden until the process terminates; 0 Terminate immediately 

pm hide < PACKAGE_OR_COMPONENT > Make package or component unavailable.

hide

disable

getPackageManager().getInstalledPackages

(PackageManager.GET_UNINSTALLED_PACKAGES);

可见

可见

getPackageManager().getInstalledPackages

(PackageManager.GET_DISABLED_COMPONENTS);

不可见

可见

getPackageManager().getInstalledPackages(0);

不可见

可见

pm lf

不可见

可见

pm list package -d

不可见

可见

pm list package -u

可见

可见

设置-应用管理已下载

魅族安装app不可见

魅族安装app不可见

设置-应用管理已全部

魅族安装app不可见

魅族安装app不可见

am start

不可用

不可用


Related articles: