Android cmd package 获取安装包名
平台:Android 7.1
根据一个问题来记录下知识点
就是安装了APK之后,想去找到该apk后启动该apk ,发现apk 在Android 中找不到,apk设置了不可显示
# pm install -r /storage/B07E-CC22/Magic.apk
那么可以通过am 命令来start,需要找到该apk 的package name and main activity name
输入,这个可以先通过pm 命令
# pm list
Error: didn't specify type of data to list
看来命令不能用了,输入pm 获取帮助
# pm
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] 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 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.
pm path: print the path to the .apk of the given PACKAGE.
pm dump: print system state associated with the given PACKAGE.
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
pm install-write: write a package into existing session; path may
be '-' to read from stdin
-S: size in bytes of package, required for stdin
pm install-commit: perform install of fully staged session
pm install-abandon: abandon session
pm set-installer: set installer package name
pm uninstall: removes a package from the system. Options:
-k: keep the data and cache directories around after package removal.
pm clear: deletes all data associated with a package.
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").
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.
pm reset-permissions: revert all runtime permissions to their default state.
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
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
pm trim-caches: trim cache files to reach the given free space.
pm create-user: create a new user with the given USER_NAME,
printing the new user identifier of the user.
pm remove-user: remove the user with the given USER_IDENTIFIER,
deleting all data associated with that user
可以看到 上述输出中有个提示
NOTE: 'pm list' commands have moved! Run 'adb shell cmd package'
to display the new commands.
输入cmd package 看看
# cmd package
Package manager (package) commands:
help
Print this help text.
compile [-m MODE | -r REASON] [-f] [-c]
[--reset] [--check-prof (true | false)] (-a | TARGET-PACKAGE)
Trigger compilation of TARGET-PACKAGE or all packages if "-a".
Options:
-a: compile all packages
-c: clear profile data before compiling
-f: force compilation even if not needed
-m: select compilation mode
MODE is one of the dex2oat compiler filters:
verify-none
verify-at-runtime
verify-profile
interpret-only
space-profile
space
speed-profile
speed
everything
-r: select compilation reason
REASON is one of:
first-boot
boot
install
bg-dexopt
ab-ota
nsys-library
shared-apk
forced-dexopt
core-app
--reset: restore package to its post-install state
--check-prof (true | false): look at profiles when doing dexopt?
list features
Prints all features of the system.
list instrumentation [-f] [TARGET-PACKAGE]
Prints all test packages; optionally only those targeting TARGET-PACKAGE
Options:
-f: dump the name of the .apk file containing the test package
list libraries
Prints all system libraries.
list packages [-f] [-d] [-e] [-s] [-3] [-i] [-u] [--user USER_ID] [FILTER]
Prints all packages; optionally only those whose name contains
the text in FILTER.
Options:
-f: see their associated file
-d: filter to only show disabled packages
-e: filter to only show enabled packages
-s: filter to only show system packages
-3: filter to only show third party packages
-i: see the installer for the packages
-u: also include uninstalled packages
list permission-groups
Prints all known permission groups.
list permissions [-g] [-f] [-d] [-u] [GROUP]
Prints all known permissions; optionally only those in GROUP.
Options:
-g: organize by group
-f: print all information
-s: short summary
-d: only list dangerous permissions
-u: list only the permissions users will see
dump-profiles TARGET-PACKAGE
Dumps method/class profile files to
/data/misc/profman/TARGET-PACKAGE.txt
resolve-activity [--brief] [--components] [--user USER_ID] INTENT
Prints the activity that resolves to the given Intent.
query-activities [--brief] [--components] [--user USER_ID] INTENT
Prints all activities that can handle the given Intent.
query-services [--brief] [--components] [--user USER_ID] INTENT
Prints all services that can handle the given Intent.
query-receivers [--brief] [--components] [--user USER_ID] INTENT
Prints all broadcast receivers that can handle the given Intent.
suspend [--user USER_ID] TARGET-PACKAGE
Suspends the specified package (as user).
unsuspend [--user USER_ID] TARGET-PACKAGE
Unsuspends the specified package (as user).
set-home-activity [--user USER_ID] TARGET-COMPONENT
set the default home activity (aka launcher).
<INTENT> specifications include these flags and arguments:
[-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>]
[-c <CATEGORY> [-c <CATEGORY>] ...]
[-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]
[--esn <EXTRA_KEY> ...]
[--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...]
[--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]
[--el <EXTRA_KEY> <EXTRA_LONG_VALUE> ...]
[--ef <EXTRA_KEY> <EXTRA_FLOAT_VALUE> ...]
[--eu <EXTRA_KEY> <EXTRA_URI_VALUE> ...]
[--ecn <EXTRA_KEY> <EXTRA_COMPONENT_NAME_VALUE>]
[--eia <EXTRA_KEY> <EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE...]]
(mutiple extras passed as Integer[])
[--eial <EXTRA_KEY> <EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE...]]
(mutiple extras passed as List<Integer>)
[--ela <EXTRA_KEY> <EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE...]]
(mutiple extras passed as Long[])
[--elal <EXTRA_KEY> <EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE...]]
(mutiple extras passed as List<Long>)
[--efa <EXTRA_KEY> <EXTRA_FLOAT_VALUE>[,<EXTRA_FLOAT_VALUE...]]
(mutiple extras passed as Float[])
[--efal <EXTRA_KEY> <EXTRA_FLOAT_VALUE>[,<EXTRA_FLOAT_VALUE...]]
(mutiple extras passed as List<Float>)
[--esa <EXTRA_KEY> <EXTRA_STRING_VALUE>[,<EXTRA_STRING_VALUE...]]
(mutiple extras passed as String[]; to embed a comma into a string,
escape it using "\,")
[--esal <EXTRA_KEY> <EXTRA_STRING_VALUE>[,<EXTRA_STRING_VALUE...]]
(mutiple extras passed as List<String>; to embed a comma into a string,
escape it using "\,")
[--f <FLAG>]
[--grant-read-uri-permission] [--grant-write-uri-permission]
[--grant-persistable-uri-permission] [--grant-prefix-uri-permission]
[--debug-log-resolution] [--exclude-stopped-packages]
[--include-stopped-packages]
[--activity-brought-to-front] [--activity-clear-top]
[--activity-clear-when-task-reset] [--activity-exclude-from-recents]
[--activity-launched-from-history] [--activity-multiple-task]
[--activity-no-animation] [--activity-no-history]
[--activity-no-user-action] [--activity-previous-is-top]
[--activity-reorder-to-front] [--activity-reset-task-if-needed]
[--activity-single-top] [--activity-clear-task]
[--activity-task-on-home]
[--receiver-registered-only] [--receiver-replace-pending]
[--receiver-foreground]
[--selector]
[<URI> | <PACKAGE> | <COMPONENT>]
看到这个信息是可以用到
list packages [-f] [-d] [-e] [-s] [-3] [-i] [-u] [--user USER_ID] [FILTER]
Prints all packages; optionally only those whose name contains
the text in FILTER.
Options:
-f: see their associated file
-d: filter to only show disabled packages
-e: filter to only show enabled packages
-s: filter to only show system packages
-3: filter to only show third party packages
输入cmd package list packages
# cmd package list packages -3
package:com.nextdoordeveloper.miperf.miperf
由前面pm 命令可以了解到有pm dump PACKAGE命令
如下是截取的一部分输出结果就可以看到 com.nextdoordeveloper.miperf.miperf/.MainActivity 这个我们想要的信息
# pm dump com.nextdoordeveloper.miperf.miperf
DUMP OF SERVICE package:
Activity Resolver Table:
Non-Data Actions:
android.intent.action.MAIN:
4317777 com.nextdoordeveloper.miperf.miperf/.MainActivity filter 3b00903
Action: "android.intent.action.MAIN"
Category: "android.intent.category.LAUNCHER"
AutoVerify=false
Key Set Manager:
[com.nextdoordeveloper.miperf.miperf]
Signing KeySets: 10
Packages:
Package [com.nextdoordeveloper.miperf.miperf] (f3ac8c5):
userId=10036
pkg=Package{8804fe4 com.nextdoordeveloper.miperf.miperf}
codePath=/data/app/com.nextdoordeveloper.miperf.miperf-1
resourcePath=/data/app/com.nextdoordeveloper.miperf.miperf-1
legacyNativeLibraryDir=/data/app/com.nextdoordeveloper.miperf.miperf-1/lib
primaryCpuAbi=null
secondaryCpuAbi=null
versionCode=1 minSdk=19 targetSdk=23
versionName=1.0
splits=[base]
apkSigningVersion=1
applicationInfo=ApplicationInfo{551ac4d com.nextdoordeveloper.miperf.miperf}
flags=[ HAS_CODE ALLOW_CLEAR_USER_DATA ALLOW_BACKUP ]
dataDir=/data/user/0/com.nextdoordeveloper.miperf.miperf
supportsScreens=[small, medium, large, xlarge, resizeable, anyDensity]
timeStamp=2020-08-07 11:36:15
firstInstallTime=2015-01-01 08:04:34
lastUpdateTime=2020-08-07 11:36:18
signatures=PackageSignatures{f35c728 [3041a970]}
installPermissionsFixed=true installStatus=1
pkgFlags=[ HAS_CODE ALLOW_CLEAR_USER_DATA ALLOW_BACKUP ]
requested permissions:
android.permission.INTERNET
android.permission.ACCESS_NETWORK_STATE
android.permission.CHANGE_NETWORK_STATE
android.permission.ACCESS_WIFI_STATE
android.permission.CHANGE_WIFI_STATE
android.permission.READ_EXTERNAL_STORAGE
android.permission.WRITE_EXTERNAL_STORAGE
install permissions:
android.permission.CHANGE_NETWORK_STATE: granted=true
android.permission.INTERNET: granted=true
android.permission.CHANGE_WIFI_STATE: granted=true
android.permission.ACCESS_NETWORK_STATE: granted=true
android.permission.ACCESS_WIFI_STATE: granted=true
User 0: ceDataInode=65789 installed=true hidden=false suspended=false stopped=false notLaunched=false enabled=0
gids=[3003]
runtime permissions:
Dexopt state:
[com.nextdoordeveloper.miperf.miperf]
Instruction Set: arm
path: /data/app/com.nextdoordeveloper.miperf.miperf-1/base.apk
status: /data/app/com.nextdoordeveloper.miperf.miperf-1/oat/arm/base.odex [compilation_filter=interpret-only, stat
us=kOatUpToDate]
Compiler stats:
[com.nextdoordeveloper.miperf.miperf]
base.apk - 528
DUMP OF SERVICE activity:
ACTIVITY MANAGER PENDING INTENTS (dumpsys activity intents)
(nothing)
输入如下命令 就可以解决我们一开始的需求想要启动该apk了
# am start -n com.nextdoordeveloper.miperf.miperf/.MainActivity
To Do
了解更多关于 cmd package的功能