背景
前面文章的一些汇总命令:
https://mp.weixin.qq.com/s/VL0MlSuthsAj7yi40zs6og
本节在这个基础上进行额外增加一些实战工作提效命令,方便新手vip学员查阅,后续熟悉了其实也就不在需要查阅,大家一定要多在实际工作学习中多使用文章中命令,用这些命令来提升你的工作效率等。
工作中提效命令
settings和provider直接使用命令操作调试
settings相关命令
经常做系统开发,经常会与Settings进行打交道,一般我们可能大部分去设置app里面找相关开关ui进行操作,但是经常有一些情况下一些新加的settings或者不常见的settings无法使用,这种可以直接使用命令进行调试就不要每次编写demo代码进行测试
相关使用帮助
Settings provider (settings) commands:
help
Print this help text.
get [--user <USER_ID> | current] NAMESPACE KEY
Retrieve the current value of KEY.
put [--user <USER_ID> | current] NAMESPACE KEY VALUE [TAG] [default]
Change the contents of KEY to VALUE.
TAG to associate with the setting.
{default} to set as the default, case-insensitive only for global/secure namespace
delete [--user <USER_ID> | current] NAMESPACE KEY
Delete the entry for KEY.
reset [--user <USER_ID> | current] NAMESPACE {PACKAGE_NAME | RESET_MODE}
Reset the global/secure table for a package with mode.
RESET_MODE is one of {untrusted_defaults, untrusted_clear, trusted_defaults}, case-insensitive
list [--user <USER_ID> | current] NAMESPACE
Print all defined keys.
NAMESPACE is one of {system, secure, global}, case-insensitive
使用方法:
adb shell settings get system show_touches // 获取system类型的show_touches的值
adb shell settings put global adb_enabled 0 // 设置global类型的adb_enabled值为0
adb shell settings get secure android_id // 获取secure类型的android_id的值
其实这块常用主要就是get和put居多,其他的delete大家根据上面帮助来就可以根据帮助来
接下来介绍contentprovider的相关命令
emu64x:/ # content -h
usage: adb shell content [subcommand] [options]
usage: adb shell content insert --uri <URI> [--user <USER_ID>] --bind <BINDING> [--bind <BINDING>...] [--extra <BINDING>...]
<URI> a content provider URI.
<BINDING> binds a typed value to a column and is formatted:
<COLUMN_NAME>:<TYPE>:<COLUMN_VALUE> where:
<TYPE> specifies data type such as:
b - boolean, s - string, i - integer, l - long, f - float, d - double, n - null
Note: Omit the value for passing an empty string, e.g column:s:
Example:
# Add "new_setting" secure setting with value "new_value".
adb shell content insert --uri content://settings/secure --bind name:s:new_setting --bind value:s:new_value
usage: adb shell content update --uri <URI> [--user <USER_ID>] [--where <WHERE>] [--extra <BINDING>...]
<WHERE> is a SQL style where clause in quotes (You have to escape single quotes - see example below).
Example:
# Change "new_setting" secure setting to "newer_value".
adb shell content update --uri content://settings/secure --bind value:s:newer_value --where "name='new_setting'"
usage: adb shell content delete --uri <URI> [--user <USER_ID>] --bind <BINDING> [--bind <BINDING>...] [--where <WHERE>] [--extra <BINDING>...]
Example:
# Remove "new_setting" secure setting.
adb shell content delete --uri content://settings/secure --where "name='new_setting'"
usage: adb shell content query --uri <URI> [--user <USER_ID>] [--projection <PROJECTION>] [--where <WHERE>] [--sort <SORT_ORDER>] [--extra <BINDING>...]
<PROJECTION> is a list of colon separated column names and is formatted:
<COLUMN_NAME>[:<COLUMN_NAME>...]
<SORT_ORDER> is the order in which rows in the result should be sorted.
Example:
# Select "name" and "value" columns from secure settings where "name" is equal to "new_setting" and sort the result by name in ascending order.
adb shell content query --uri content://settings/secure --projection name:value --where "name='new_setting'" --sort "name ASC"
usage: adb shell content call --uri <URI> --method <METHOD> [--arg <ARG>]
[--extra <BINDING> ...]
<METHOD> is the name of a provider-defined method
<ARG> is an optional string argument
<BINDING> is like --bind above, typed data of the form <KEY>:{b,s,i,l,f,d}:<VAL>
usage: adb shell content read --uri <URI> [--user <USER_ID>]
Example:
adb shell 'content read --uri content://settings/system/ringtone_cache' > host.ogg
usage: adb shell content write --uri <URI> [--user <USER_ID>]
Example:
adb shell 'content write --uri content://settings/system/ringtone_cache' < host.ogg
usage: adb shell content gettype --uri <URI> [--user <USER_ID>]
Example:
adb shell content gettype --uri content://media/internal/audio/media/
这里的content使用帮助相对来说非常详细,这里重点展示一下ContentProvider的call方法相关调用命令:
content call --uri content://com.example.audiotrackdemo.testprovider --method test --arg testarg --extra "key:s:name" --extra "value:s:qianlima"
日志相关命令
native 开启logcat
一般需要把cpp的如下屏蔽的define进行开放
#define LOG_NDEBUG 0
logcat命令进行命令分享:
抓取系统所有日志
logcat -b all> logcat.txt
logcat -b main -b events -b radio -b system -b crash > logcat.txt
抓取日志中使用grep进行过滤:
#过滤单字符
logcat | grep lsm666888
#过滤多字符
logcat | grep -E "lsm666888|InputDispatcher"
设置来开放系统核心服务的一些日志:
针对InputDispatcher部分可以用如下命令进行开放日志,当然前提得系统服务本身有日志打印这块的控制
adb shell setprop log.tag.InputDispatcherDispatchCycle DEBUG
相关原理剖析
https://mp.weixin.qq.com/s/ixXOAa8fby39HxHIqYos9w
获取进程pid号及杀进程
老方法一般如下:
先获取launcher进程pid
test@test:~$ adb shell ps -A | grep launcher
u0_a121 1218 318 15929568 208004 do_epoll_wait 0 S com.android.launcher3
知道进程号然后调用kill
test@test:~$ adb shell kill 1218
新方法直接使用pidof命令获取进程号
pidof com.android.launcher3
4186
kill $(pidof com.android.launcher3)
kill `pidof com.android.launcher3`
分析疑难问题相关命令
冻屏黑屏显示异常场景
adb shell bugreport > bugreport.txt # 新版本直接使用 adb bugreport
adb pull /data/tombstones
adb pull /data/anr
adb shell dumpsys window > w.txt # 打印 window 信息
adb shell dumpsys input > i.txt # 打印 input 信息
adb shell dumpsys SurfaceFlinger > sf.txt # 打印 SurfaceFlinger 信息
#dump 进程 traces
adb shell kill -3 <process_pid>
adb shell debuggerd -j <process_pid>
当然如果有条件抓取Winscope最好。
更多framework实战开发干货,请关注下面“千里马学框架”