LinuxCommandLibrary

adb-shell-pm

Manage Android packages

TLDR

List installed packages

$ adb shell pm list packages
copy

Install an app package from a given path
$ adb shell pm install /[path/to/app.apk]
copy

Uninstall a package from the device
$ adb shell pm uninstall [package]
copy

Clear all app data for a package
$ adb shell pm clear [package]
copy

Enable a package or component
$ adb shell pm enable [package_or_class]
copy

Disable a package or component
$ adb shell pm disable-user [package_or_class]
copy

Grant a permission for an app
$ adb shell pm grant [package] [android.permission.CAMERA|android.permission.ACCESS_FINE_LOCATION|android.permission.READ_CONTACTS|...]
copy

Revoke a permission for an app
$ adb shell pm revoke [package] [android.permission.CAMERA|android.permission.ACCESS_FINE_LOCATION|android.permission.READ_CONTACTS|...]
copy

SYNOPSIS

adb shell pm [options] [arguments]
For example:
adb shell pm list packages -f
adb shell pm install /sdcard/Download/MyApp.apk

PARAMETERS

list packages [options]
    Lists all installed packages, optionally filtering by various criteria (e.g., system packages, third-party apps, enabled/disabled).

path
    Prints the full path to the APK file for the specified package.

install [options]
    Installs an application package from a specified path (either on the host or device). Common options include -r (reinstall), -t (allow test APKs), -d (allow version downgrade).

uninstall [options]
    Uninstalls a package from the device. Options include -k (keep data and cache directories).

clear
    Deletes all data associated with a package, effectively resetting it to its initial state.

enable
    Enables a package or a specific component (e.g., activity, service) if it was previously disabled.

disable
    Disables a package or a specific component, preventing it from being launched or used.

grant
    Grants a runtime permission (e.g., android.permission.CAMERA) to a package.

revoke
    Revokes a previously granted runtime permission from a package.

hide
    Hides a package, making it inaccessible and invisible to the user. Often requires root or specific OEM firmware.

unhide
    Unhides a previously hidden package, restoring its visibility and accessibility.

get-install-location
    Returns the current default install location for applications (e.g., 0: auto, 1: internal, 2: external).

set-install-location
    Sets the default install location for applications (0: auto, 1: internal, 2: external).

trim-caches
    Trims application caches to free up storage space, attempting to reduce total cache size below .

DESCRIPTION

The adb shell pm command provides a powerful command-line interface to interact with the Android Package Manager (PM) service directly from a host computer, leveraging the Android Debug Bridge (ADB). It allows developers, testers, and advanced users to perform a wide range of package-related operations on a connected Android device, emulator, or Wear OS device.

These operations include listing installed applications, installing new APK files, uninstalling existing packages, clearing application data, managing runtime permissions, and enabling or disabling application components. It offers granular control over the application lifecycle, which is crucial for debugging, automating tasks, and advanced device management scenarios that go beyond the capabilities of the device's graphical user interface. As a core Android utility, pm is instrumental in maintaining and troubleshooting the application environment.

CAVEATS

Using adb shell pm requires a properly configured adb environment and an Android device that is connected and authorized for debugging.

Many operations, especially those that affect system applications or critical device functions, may require root privileges on the Android device. Without root, some commands might fail with permission errors.

The exact set of available subcommands and their specific options can vary across different Android versions and device manufacturers. Always consult the output of adb shell pm help on your specific device for the most accurate information.

Incorrect or careless use of pm commands can lead to application instability, data loss, or even render the device unstable or unusable. Exercise caution, especially when disabling system components or modifying permissions.

SECURITY IMPLICATIONS

While powerful, modifying package permissions, enabling/disabling system components, or installing untrusted APKs via adb shell pm carries significant security risks. Granting excessive permissions or tampering with critical system apps can compromise device security, expose sensitive data, or lead to system instability.

AUTOMATION AND SCRIPTING

adb shell pm is widely used in automated testing frameworks, continuous integration/continuous deployment (CI/CD) pipelines, and custom scripts. It enables precise control over application states, allowing for the installation of specific builds, resetting app data between tests, granting necessary permissions, and verifying package integrity in a consistent and reproducible manner.

HISTORY

The pm (Package Manager) command-line utility has been a foundational component of the Android operating system since its inception. It provides a programmatic interface to the underlying PackageManager service, which is essential for managing how applications are installed, updated, and interact with the system. Its functionality has consistently evolved with each Android release, incorporating new subcommands and options to address changes in the platform's architecture, security model (e.g., runtime permissions introduced in Android 6.0 Marshmallow), and application distribution mechanisms (e.g., split APKs, instant apps). Its seamless integration with adb shell has solidified its role as an indispensable tool for Android development, debugging, and system administration.

SEE ALSO

adb(1), adb shell(1), am(1), input(1), dumpsys(1), logcat(1)

Copied to clipboard