diff --git a/README.md b/README.md index d32c32d..d856b36 100644 --- a/README.md +++ b/README.md @@ -40,8 +40,11 @@ Other languages: [:gb: English](./README.en.md) * [与应用交互](#与应用交互) * [调起 Activity](#调起-activity) * [调起 Service](#调起-service) + * [停止 Service](#停止-service) * [发送广播](#发送广播) * [强制停止应用](#强制停止应用) + * [启动应用](#启动应用) + * [收紧内存](#收紧内存) * [文件管理](#文件管理) * [复制设备里的文件到电脑](#复制设备里的文件到电脑) * [复制电脑里的文件到设备](#复制电脑里的文件到设备) @@ -858,6 +861,14 @@ adb shell am startservice -n com.tencent.mm/.plugin.accountsync.model.AccountAut 表示调起微信的某 Service。 +### 停止 Service + +命令格式: + +```sh +adb shell am stopservice [options] +``` + ### 发送广播 命令格式: @@ -927,6 +938,39 @@ adb shell am force-stop com.qihoo360.mobilesafe 表示停止 360 安全卫士的一切进程与服务。 +### 启动应用 + +命令: +```sh +adb shell am start -n +``` + +命令示例: +```sh +adb shell am start -n com.baidu.searchbox/com.baidu.searchbox.SplashActivity +``` + +表示启动手机百度 + +### 收紧内存 + +命令: +```sh +adb shell am send-trim-memory + +pid:进程ID +level: + HIDDEN、RUNNING_MODERATE、BACKGROUND、 + RUNNING_LOW、MODERATE、RUNNING_CRITICAL、COMPLETE +``` + +命令示例: +```sh +adb shell am send-trim-memory 12345 RUNNING_LOW +``` +表示向pid=12345的进程,发出level=RUNNING_LOW的收紧内存命令 + + ## 文件管理 ### 复制设备里的文件到电脑 diff --git a/aapt.md b/aapt.md new file mode 100644 index 0000000..5fda718 --- /dev/null +++ b/aapt.md @@ -0,0 +1,187 @@ +# aapt 相关命令 + +```sh +Android Asset Packaging Tool + +Usage: + aapt l[ist] [-v] [-a] file.{zip,jar,apk} + List contents of Zip-compatible archive. + + aapt d[ump] [--values] [--include-meta-data] WHAT file.{apk} [asset [asset ...]] + strings Print the contents of the resource table string pool in the APK. + badging Print the label and icon for the app declared in APK. + permissions Print the permissions from the APK. + resources Print the resource table from the APK. + configurations Print the configurations in the APK. + xmltree Print the compiled xmls in the given assets. + xmlstrings Print the strings of the given compiled xml assets. + + aapt p[ackage] [-d][-f][-m][-u][-v][-x][-z][-M AndroidManifest.xml] \ + [-0 extension [-0 extension ...]] [-g tolerance] [-j jarfile] \ + [--debug-mode] [--min-sdk-version VAL] [--target-sdk-version VAL] \ + [--app-version VAL] [--app-version-name TEXT] [--custom-package VAL] \ + [--rename-manifest-package PACKAGE] \ + [--rename-instrumentation-target-package PACKAGE] \ + [--utf16] [--auto-add-overlay] \ + [--max-res-version VAL] \ + [-I base-package [-I base-package ...]] \ + [-A asset-source-dir] [-G class-list-file] [-P public-definitions-file] \ + [-D main-dex-class-list-file] \ + [-S resource-sources [-S resource-sources ...]] \ + [-F apk-file] [-J R-file-dir] \ + [--product product1,product2,...] \ + [-c CONFIGS] [--preferred-density DENSITY] \ + [--split CONFIGS [--split CONFIGS]] \ + [--feature-of package [--feature-after package]] \ + [raw-files-dir [raw-files-dir] ...] \ + [--output-text-symbols DIR] + + Package the android resources. It will read assets and resources that are + supplied with the -M -A -S or raw-files-dir arguments. The -J -P -F and -R + options control which files are output. + + aapt r[emove] [-v] file.{zip,jar,apk} file1 [file2 ...] + Delete specified files from Zip-compatible archive. + + aapt a[dd] [-v] file.{zip,jar,apk} file1 [file2 ...] + Add specified files to Zip-compatible archive. + + aapt c[runch] [-v] -S resource-sources ... -C output-folder ... + Do PNG preprocessing on one or several resource folders + and store the results in the output folder. + + aapt s[ingleCrunch] [-v] -i input-file -o outputfile + Do PNG preprocessing on a single file. + + aapt v[ersion] + Print program version. + + Modifiers: + -a print Android-specific data (resources, manifest) when listing + -c specify which configurations to include. The default is all + configurations. The value of the parameter should be a comma + separated list of configuration values. Locales should be specified + as either a language or language-region pair. Some examples: + en + port,en + port,land,en_US + -d one or more device assets to include, separated by commas + -f force overwrite of existing files + -g specify a pixel tolerance to force images to grayscale, default 0 + -j specify a jar or zip file containing classes to include + -k junk path of file(s) added + -m make package directories under location specified by -J + -u update existing packages (add new, replace older, remove deleted files) + -v verbose output + -x create extending (non-application) resource IDs + -z require localization of resource attributes marked with + localization="suggested" + -A additional directory in which to find raw asset files + -G A file to output proguard options into. + -D A file to output proguard options for the main dex into. + -F specify the apk file to output + -I add an existing package to base include set + -J specify where to output R.java resource constant definitions + -M specify full path to AndroidManifest.xml to include in zip + -P specify where to output public resource definitions + -S directory in which to find resources. Multiple directories will be scanned + and the first match found (left to right) will take precedence. + -0 specifies an additional extension for which such files will not + be stored compressed in the .apk. An empty string means to not + compress any files at all. + --debug-mode + inserts android:debuggable="true" in to the application node of the + manifest, making the application debuggable even on production devices. + --include-meta-data + when used with "dump badging" also includes meta-data tags. + --pseudo-localize + generate resources for pseudo-locales (en-XA and ar-XB). + --min-sdk-version + inserts android:minSdkVersion in to manifest. If the version is 7 or + higher, the default encoding for resources will be in UTF-8. + --target-sdk-version + inserts android:targetSdkVersion in to manifest. + --max-res-version + ignores versioned resource directories above the given value. + --values + when used with "dump resources" also includes resource values. + --version-code + inserts android:versionCode in to manifest. + --version-name + inserts android:versionName in to manifest. + --replace-version + If --version-code and/or --version-name are specified, these + values will replace any value already in the manifest. By + default, nothing is changed if the manifest already defines + these attributes. + --custom-package + generates R.java into a different package. + --extra-packages + generate R.java for libraries. Separate libraries with ':'. + --generate-dependencies + generate dependency files in the same directories for R.java and resource package + --auto-add-overlay + Automatically add resources that are only in overlays. + --preferred-density + Specifies a preference for a particular density. Resources that do not + match this density and have variants that are a closer match are removed. + --split + Builds a separate split APK for the configurations listed. This can + be loaded alongside the base APK at runtime. + --feature-of + Builds a split APK that is a feature of the apk specified here. Resources + in the base APK can be referenced from the the feature APK. + --feature-after + An app can have multiple Feature Split APKs which must be totally ordered. + If --feature-of is specified, this flag specifies which Feature Split APK + comes before this one. The first Feature Split APK should not define + anything here. + --rename-manifest-package + Rewrite the manifest so that its package name is the package name + given here. Relative class names (for example .Foo) will be + changed to absolute names with the old package so that the code + does not need to change. + --rename-instrumentation-target-package + Rewrite the manifest so that all of its instrumentation + components target the given package. Useful when used in + conjunction with --rename-manifest-package to fix tests against + a package that has been renamed. + --product + Specifies which variant to choose for strings that have + product variants + --utf16 + changes default encoding for resources to UTF-16. Only useful when API + level is set to 7 or higher where the default encoding is UTF-8. + --non-constant-id + Make the resources ID non constant. This is required to make an R java class + that does not contain the final value but is used to make reusable compiled + libraries that need to access resources. + --shared-lib + Make a shared library resource package that can be loaded by an application + at runtime to access the libraries resources. Implies --non-constant-id. + --app-as-shared-lib + Make an app resource package that also can be loaded as shared library at runtime. + Implies --non-constant-id. + --error-on-failed-insert + Forces aapt to return an error if it fails to insert values into the manifest + with --debug-mode, --min-sdk-version, --target-sdk-version --version-code + and --version-name. + Insertion typically fails if the manifest already defines the attribute. + --error-on-missing-config-entry + Forces aapt to return an error if it fails to find an entry for a configuration. + --output-text-symbols + Generates a text file containing the resource symbols of the R class in the + specified folder. + --ignore-assets + Assets to be ignored. Default pattern is: + !.svn:!.git:!.ds_store:!*.scc:.*:_*:!CVS:!thumbs.db:!picasa.ini:!*~ + --skip-symbols-without-default-localization + Prevents symbols from being generated for strings that do not have a default + localization + --no-version-vectors + Do not automatically generate versioned copies of vector XML resources. + --no-version-transitions + Do not automatically generate versioned copies of transition XML resources. + --private-symbols + Java package name to use when generating R.java for private resources. +``` diff --git a/am.md b/am.md new file mode 100644 index 0000000..a83ab69 --- /dev/null +++ b/am.md @@ -0,0 +1,240 @@ +# am 相关命令 + +```sh +usage: am [subcommand] [options] +usage: am start [-D] [-W] [-P ] [--start-profiler ] + [--sampling INTERVAL] [-R COUNT] [-S] [--opengl-trace] + [--user | current] + am startservice [--user | current] + am stopservice [--user | current] + am force-stop [--user | all | current] + am kill [--user | all | current] + am kill-all + am broadcast [--user | all | current] + am instrument [-r] [-e ] [-p ] [-w] + [--user | current] + [--no-window-animation] [--abi ] + am profile start [--user current] [--sampling INTERVAL] + am profile stop [--user current] [] + am dumpheap [--user current] [-n] + am set-debug-app [-w] [--persistent] + am clear-debug-app + am set-watch-heap + am clear-watch-heap + am monitor [--gdb ] + am hang [--allow-restart] + am restart + am idle-maintenance + am screen-compat [on|off] + am package-importance + am to-uri [INTENT] + am to-intent-uri [INTENT] + am to-app-uri [INTENT] + am switch-user + am start-user + am stop-user [-w] + am stack start + am stack movetask [true|false] + am stack resize + am stack split [INTENT] + am stack list + am stack info + am task lock + am task lock stop + am task resizeable [true|false] + am task resize + am get-config + am set-inactive [--user ] true|false + am get-inactive [--user ] + am send-trim-memory [--user ] + [HIDDEN|RUNNING_MODERATE|BACKGROUND|RUNNING_LOW|MODERATE|RUNNING_CRITICAL|COMPLETE] + +am start: start an Activity. Options are: + -D: enable debugging + -W: wait for launch to complete + --start-profiler : start profiler and send results to + --sampling INTERVAL: use sample profiling with INTERVAL microseconds + between samples (use with --start-profiler) + -P : like above, but profiling stops when app goes idle + -R: repeat the activity launch times. Prior to each repeat, + the top activity will be finished. + -S: force stop the target app before starting the activity + --opengl-trace: enable tracing of OpenGL functions + --user | current: Specify which user to run as; if not + specified then run as the current user. + +am startservice: start a Service. Options are: + --user | current: Specify which user to run as; if not + specified then run as the current user. + +am stopservice: stop a Service. Options are: + --user | current: Specify which user to run as; if not + specified then run as the current user. + +am force-stop: force stop everything associated with . + --user | all | current: Specify user to force stop; + all users if not specified. + +am kill: Kill all processes associated with . Only kills. + processes that are safe to kill -- that is, will not impact the user + experience. + --user | all | current: Specify user whose processes to kill; + all users if not specified. + +am kill-all: Kill all background processes. + +am broadcast: send a broadcast Intent. Options are: + --user | all | current: Specify which user to send to; if not + specified then send to all users. + --receiver-permission : Require receiver to hold permission. + +am instrument: start an Instrumentation. Typically this target + is the form /. Options are: + -r: print raw results (otherwise decode REPORT_KEY_STREAMRESULT). Use with + [-e perf true] to generate raw output for performance measurements. + -e : set argument to . For test runners a + common form is [-e [,...]]. + -p : write profiling data to + -w: wait for instrumentation to finish before returning. Required for + test runners. + --user | current: Specify user instrumentation runs in; + current user if not specified. + --no-window-animation: turn off window animations while running. + --abi : Launch the instrumented process with the selected ABI. + This assumes that the process supports the selected ABI. + +am profile: start and stop profiler on a process. The given argument + may be either a process name or pid. Options are: + --user | current: When supplying a process name, + specify user of process to profile; uses current user if not specified. + +am dumpheap: dump the heap of a process. The given argument may + be either a process name or pid. Options are: + -n: dump native heap instead of managed heap + --user | current: When supplying a process name, + specify user of process to dump; uses current user if not specified. + +am set-debug-app: set application to debug. Options are: + -w: wait for debugger when application starts + --persistent: retain this value + +am clear-debug-app: clear the previously set-debug-app. + +am set-watch-heap: start monitoring pss size of , if it is at or + above then a heap dump is collected for the user to report + +am clear-watch-heap: clear the previously set-watch-heap. + +am bug-report: request bug report generation; will launch UI + when done to select where it should be delivered. + +am monitor: start monitoring for crashes or ANRs. + --gdb: start gdbserv on the given port at crash/ANR + +am hang: hang the system. + --allow-restart: allow watchdog to perform normal system restart + +am restart: restart the user-space system. + +am idle-maintenance: perform idle maintenance now. + +am screen-compat: control screen compatibility mode of . + +am package-importance: print current importance of . + +am to-uri: print the given Intent specification as a URI. + +am to-intent-uri: print the given Intent specification as an intent: URI. + +am to-app-uri: print the given Intent specification as an android-app: URI. + +am switch-user: switch to put USER_ID in the foreground, starting + execution of that user if it is currently stopped. + +am start-user: start USER_ID in background if it is currently stopped, + use switch-user if you want to start the user in foreground. + +am stop-user: stop execution of USER_ID, not allowing it to run any + code until a later explicit start or switch to it. + -w: wait for stop-user to complete. + +am stack start: start a new activity on using . + +am stack movetask: move from its current stack to the top (true) or bottom (false) of . + +am stack resize: change size and position to . + +am stack split: split into 2 stacks ertically or orizontally + starting the new stack with [INTENT] if specified. If [INTENT] isn't + specified and the current stack has more than one task, then the top task + of the current task will be moved to the new stack. Command will also force + all current tasks in both stacks to be resizeable. + +am stack list: list all of the activity stacks and their sizes. + +am stack info: display the information about activity stack . + +am task lock: bring to the front and don't allow other tasks to run. + +am task lock stop: end the current task lock. + +am task resizeable: change if is resizeable (true) or not (false). + +am task resize: makes sure is in a stack with the specified bounds. + Forces the task to be resizeable and creates a stack if no existing stack + has the specified bounds. + +am get-config: retrieve the configuration and any recent configurations + of the device. + +am set-inactive: sets the inactive state of an app. + +am get-inactive: returns the inactive state of an app. + +am send-trim-memory: Send a memory trim event to a . + + specifications include these flags and arguments: + [-a ] [-d ] [-t ] + [-c [-c ] ...] + [-e|--es ...] + [--esn ...] + [--ez ...] + [--ei ...] + [--el ...] + [--ef ...] + [--eu ...] + [--ecn ] + [--eia [, [,) + [--ela [, [,) + [--efa [, [,) + [--esa [, [,; to embed a comma into a string, + escape it using "\,") + [--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] + [--selector] + [ | | ] +``` diff --git a/dumpsys.md b/dumpsys.md new file mode 100644 index 0000000..fb00def --- /dev/null +++ b/dumpsys.md @@ -0,0 +1,26 @@ +# dumpsys 相关命令 + + +* [获取当前Activity](#获取当前activity) +* [获取当前Window](#获取当前window) + + + +### 获取当前Activity + +Linux: +```sh +adb shell dumpsys activity | grep "mFocusedActivity" +``` + +Windows: +```sh +adb shell dumpsys activity | findstr "mFocusedActicity" +``` + +### 获取当前Window + +```sh +adb shell dumpsys window w | grep \/ | grep name= +``` + diff --git a/pm.md b/pm.md new file mode 100644 index 0000000..00d6ea4 --- /dev/null +++ b/pm.md @@ -0,0 +1,160 @@ +# pm 相关命令 + + + + +* [pm --help](#pm---help) +* [查看手机中APK的存放位置](#查看手机中apk的存放位置) + + + +## pm --help +```sh +usage: pm list packages [-f] [-d] [-e] [-s] [-3] [-i] [-u] [--user USER_ID] [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 list users + pm path 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 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] USER_NAME + pm remove-user USER_ID + pm get-max-users + +pm list packages: prints all packages, optionally only + those whose package name contains the text in FILTER. Options: + -f: see their associated file. + -d: filter to only show disbled 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. + +pm list permission-groups: prints all known permission groups. + +pm list permissions: 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. + +pm list instrumentation: use to list all test packages; optionally + supply to list the test packages for a particular + application. Options: + -f: list the .apk file for the test package. + +pm list features: prints all features of the system. + +pm list users: prints all users on the system. + +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 + -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: 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 +``` + +## 查看手机中APK的存放位置 +```sh +adb shell pm list packages -f +``` + +示例: +```sh +adb shell pm list packages -f | grep vivo + +output: +package:/system/app/BBKWeatherProvider/BBKWeatherProvider.apk=com.vivo.weather.provider +package:/system/app/VivoSmartMultiWindow/VivoSmartMultiWindow.apk=com.vivo.smartmultiwindow +package:/system/app/CoffeeTime/CoffeeTime.apk=com.vivo.livewallpaper.coffeetime +package:/system/app/SetupWizard/SetupWizard.apk=com.vivo.setupwizard +... +``` diff --git a/uiautomator.md b/uiautomator.md new file mode 100644 index 0000000..26a93ee --- /dev/null +++ b/uiautomator.md @@ -0,0 +1,11 @@ +# uiautomator 相关命令 + + +* [获取当前页面布局](#获取当前页面布局) + + + +### 获取当前页面布局 +```sh +adb shell uiautomator dump /data/local/tmp/uidump.xml && adb pull /data/local/tmp/uidump.xml uidump.xml +```