常用的几个adb命令

常用的几个adb命令:

1 抓取指定关键字的log:

adb shell "logcat -b all | grep 关键字"

还可以用下面的命令:

adb logcat | find "com.ljt.camera" >c:/1.log

2 查看当前窗口应用包名和activity名:

  adb shell "dumpsys activity | grep -i run"

3 启动指定的activity

adb shell am start -n 包名/.activity名

如:adb shell am start -n com.android.calendar/.AllInOneActivity

4 查看版本编译时间

 adb shell "getprop | grep ro.build.date"

5 seLinux问题确认

如果怀疑是seLinux权限导致了bug可以按照如下方法确认:

  • 抓取seLinux相关的log

    1.抓kernel的log
    adb shell dmesg
    

    还可以使用以下命令:

    adb shell "cat /proc/kmsg | grep avc" >avc_log.txt  
    
    2.抓logcat的log
    adb logcat –b events | find "avc: denied"
    

    如:

    02-03 09:43:59.858 18875 18875 I ndroid.settings: type=1400 audit(0.0:22265): avc: denied { read }  for name="pagetypeinfo" dev="proc" ino=4026532108 scontext=u:r:system_app:s0 tcontext=u:object_r:proc_pagetypeinfo:s0 tclass=file permissive=1
    
    3.注意下面的关键字:
    关键字 说明
    ndroid.settings 应用名称
    avc: denied { read } 操作
    tcontext=u:object_r:proc_pagetypeinfo 目标
    tclass=file 操作对象的类型
  • 查看seLinux的状态

    adb shell getenforce
    

    返回Enforcing:seLinux已经打开;
    返回Permissive:seLinux已经关闭;

    从log也可以看出,如果permissive=1说明seLinux已经关闭了,permissive=0,说明seLinux已经开启了

  • 关闭seLinux

    adb root & adb shell setenforce 0
    

    最好在刚开机以后开机动画开始播放之后就运行,否则还是可能会出现大量权限相关的问题。

    如果后续的测试未出现严重的系统性问题,说明与seLinux有关。

你可能感兴趣的:(adb,测试)