[ADB Command] Package Manager(pm) 호출

2018. 9. 10. 13:44Programing/Android / Java

adb 셸 내에서는, 기기에 설치된 애플리케이션 패키지에서 작업과 쿼리를 수행하기 위해 package manager(pm) 도구로 명령을 실행할 수 있습니다. 셸에 있을 때의 구문은 다음과 같습니다.

 
pm command

또한 원격 셸에 들어가지 않고 adb에서 직접 package manager 명령을 실행할 수도 있습니다. 예:

 
adb shell pm uninstall com.example.MyApp

표 3. 사용 가능한 package manager 명령.

명령 설명
list packages [options] filter 모든 패키지를 출력하며, 선택적으로 패키지 이름의 filter에 텍스트가 포함된 패키지만 출력합니다.

옵션:

  • -f: 연결된 파일을 확인합니다.
  • -d: 비활성화된 패키지만을 표시하도록 필터링합니다.
  • -e: 활성화된 패키지만을 표시하도록 필터링합니다.
  • -s: 시스템 패키지만을 표시하도록 필터링합니다.
  • -3: 타사 패키지만을 표시하도록 필터링합니다.
  • -i: 패키지의 설치 프로그램을 확인합니다.
  • -u: 또한 제거된 패키지도 포함합니다.
  • --user user_id: 쿼리할 사용자 공간입니다.
list permission-groups 알려진 모든 권한 그룹을 출력합니다.
list permissions [options] group 알려진 모든 권한을 출력하며, group에 있는 권한만을 선택적으로 출력합니다.

옵션:

  • -g: 그룹별로 구성합니다.
  • -f: 모든 정보를 출력합니다.
  • -s: 간단한 요약입니다.
  • -d: 위험한 권한만을 나열합니다.
  • -u: 사용자가 보는 권한만을 나열합니다.
list instrumentation [options] 모든 테스트 패키지를 나열합니다.

옵션:

  • -f: 테스트 패키지의 APK 파일을 나열합니다.
  • target_package: 이 앱에 대해서만 테스트 패키지를 나열합니다.
list features 시스템의 모든 기능을 출력합니다.
list libraries 현재 기기가 지원하는 모든 라이브러리를 출력합니다.
list users 시스템의 모든 사용자를 출력합니다.
path package 주어진 package의 APK의 경로를 출력합니다.
install [options] path path로 지정된 패키지를 시스템에 설치합니다.

옵션:

  • -l: 전송 잠금으로 패키지를 설치합니다.
  • -r: 기존 앱을 다시 설치하고 그 데이터는 유지합니다.
  • -t: 테스트 APK를 설치하도록 허용합니다.
  • -i installer_package_name: 설치 프로그램 패키지 이름을 지정합니다.
  • -s: 공유 대용량 저장소(예: SD 카드)에 패키지를 설치합니다.
  • -f: 내부 시스템 메모리에 패키지를 설치합니다.
  • -d: 버전 코드 다운그레이드를 허용합니다.
  • -g: 앱 매니페스트에 나열된 모든 권한을 부여합니다.
uninstall [options] package 시스템에서 패키지를 제거합니다.

옵션:

  • -k: 패키지 제거 후에 데이터와 캐시 디렉토리를 유지합니다.
clear package 패키지에 연결된 모든 데이터를 삭제합니다.
enable package_or_component ("패키지/클래스"로 작성된) 주어진 패키지나 구성 요소를 활성화합니다.
disable package_or_component ("패키지/클래스"로 작성된) 주어진 패키지나 구성 요소를 비활성화합니다.
disable-user [options] package_or_component

옵션:

  • --user user_id: 비활성화할 사용자입니다.
grant package_name permission 앱에 권한을 부여합니다. Android 6.0(API 레벨 23) 이상을 실행 중인 기기에서는, 모든 권한이 앱 매니페스트에 선언될 수도 있습니다. Android 5.1(API 레벨 22) 이하를 실행 중인 기기에서는, 선택적 권한이 앱에 의해 정의되어야 합니다.
revoke package_name permission 앱에서 권한을 취소합니다. Android 6.0(API 레벨 23) 이상을 실행 중인 기기에서는, 모든 권한이 앱 매니페스트에 선언될 수도 있습니다. Android 5.1(API 레벨 22) 이하를 실행 중인 기기에서는, 선택적 권한이 앱에 의해 정의되어야 합니다.
set-install-location location 기본 설치 위치를 변경합니다. 위치 값:
  • 0: Auto—최적의 위치를 시스템이 결정하도록 합니다.
  • 1: Internal—내부 기기 저장소에 설치합니다.
  • 2: External—외부 미디어에 설치합니다.

참고: 이것은 디버깅 용도로만 사용되며, 이것을 사용할 경우 애플리케이션이 작동 중단되거나 다른 원치 않는 동작이 발생할 수 있습니다.

get-install-location 현재 설치 위치를 반환합니다. 반환 값:
  • 0 [auto]: 최적의 위치를 시스템이 결정하도록 합니다
  • 1 [internal]: 내부 기기 저장소에 설치합니다
  • 2 [external]: 외부 미디어에 설치합니다
set-permission-enforced permission [true|false] 주어진 권한의 적용 여부를 지정합니다.
trim-caches desired_free_space 주어진 여유 공간에 도달하는 캐시 파일을 트리밍합니다.
create-user user_name 주어진 user_name으로 새 사용자를 생성하고, 이 사용자의 새 사용자 식별자를 출력합니다.
remove-user user_id 주어진 user_id의 사용자를 제거하고, 이 사용자에 연결된 모든 데이터를 삭제합니다.
get-max-users 기기가 지원하는 최대 사용자 수를 출력합니다.

 

 

[ADB Command]

  1. usage: pm path [--user USER_ID] PACKAGE
    pm dump PACKAGE
    pm install [-lrtsfd] [-i PACKAGE] [--user USER_ID] [PATH]
    pm install-create [-lrtsfdp] [-i PACKAGE] [-S BYTES]
    [--install-location 0/1/2]
    [--force-uuid internal|UUID]
    pm install-write [-S BYTES] SESSION_ID SPLIT_NAME [PATH]
    pm install-commit SESSION_ID
    pm install-abandon SESSION_ID
    pm uninstall [-k] [--user USER_ID] [--versionCode VERSION_CODE] PACKAGE
    pm set-installer PACKAGE INSTALLER
    pm move-package PACKAGE [internal|UUID]
    pm move-primary-storage [internal|UUID]
    pm clear [--user USER_ID] PACKAGE
    pm enable [--user USER_ID] PACKAGE_OR_COMPONENT
    pm disable [--user USER_ID] PACKAGE_OR_COMPONENT
    pm disable-user [--user USER_ID] PACKAGE_OR_COMPONENT
    pm disable-until-used [--user USER_ID] PACKAGE_OR_COMPONENT
    pm default-state [--user USER_ID] PACKAGE_OR_COMPONENT
    pm set-user-restriction [--user USER_ID] RESTRICTION VALUE
    pm hide [--user USER_ID] PACKAGE_OR_COMPONENT
    pm unhide [--user USER_ID] PACKAGE_OR_COMPONENT
    pm grant [--user USER_ID] PACKAGE PERMISSION
    pm revoke [--user USER_ID] PACKAGE PERMISSION
    pm reset-permissions
    pm set-app-link [--user USER_ID] PACKAGE {always|ask|never|undefined}
    pm get-app-link [--user USER_ID] PACKAGE
    pm set-install-location [0/auto] [1/internal] [2/external]
    pm get-install-location
    pm set-permission-enforced PERMISSION [true|false]
    pm trim-caches DESIRED_FREE_SPACE [internal|UUID]
    pm create-user [--profileOf USER_ID] [--managed] [--restricted] [--ephemeral] [--guest] USER_NAME
    pm remove-user USER_ID
    pm get-max-users

    NOTE: 'pm list' commands have moved! Run 'adb shell cmd package' to display the new commands.

  2. pm path: print the path to the .apk of the given PACKAGE.

  3. pm dump: print system state associated with the given PACKAGE.

  4. pm install: install a single legacy package
    pm install-create: create an install session
    -l: forward lock application
    -r: replace existing application
    -t: allow test packages
    -i: specify the installer package name
    -s: install application on sdcard
    -f: install application on internal flash
    -d: allow version code downgrade (debuggable packages only)
    -p: partial application install
    -g: grant all runtime permissions
    -S: size in bytes of entire session

  5. pm install-write: write a package into existing session; path maybe '-' to read from stdin
    -S: size in bytes of package, required for stdin

  6. pm install-commit: perform install of fully staged session

  7. pm install-abandon: abandon session

  8. pm set-installer: set installer package name

  9. pm uninstall: removes a package from the system. Options:
    -k: keep the data and cache directories around after package removal.

  10. pm clear: deletes all data associated with a package.

  11. pm enable, disable, disable-user, disable-until-used, default-state:
    these commands change the enabled state of a given package or component (written as "package/class").

  12. pm grant, revoke: these commands either grant or revoke permissions to apps. The permissions must be declared as used in the app's manifest, be runtime permissions (protection level dangerous), and the app targeting SDK greater than Lollipop MR1.

  13. pm reset-permissions: revert all runtime permissions to their default state.

  14. pm get-install-location: returns the current install location.
    0 [auto]: Let system decide the best location
    1 [internal]: Install on internal device storage
    2 [external]: Install on external media

  15. pm set-install-location: changes the default install location.
    NOTE: this is only intended for debugging; using this can cause applications to break and other undersireable behavior.
    0 [auto]: Let system decide the best location
    1 [internal]: Install on internal device storage
    2 [external]: Install on external media

  16. pm trim-caches: trim cache files to reach the given free space.

  17. pm create-user: create a new user with the given USER_NAME, printing the new user identifier of the user.

  18. pm remove-user: remove the user with the given USER_IDENTIFIER, deleting all data associated with that user

 

https://developer.android.com/studio/command-line/adb?hl=ko