Android - adb : logcat / shell / app_process & android.os.Process

在 Terminal 中执行 adb

  • 获取android系统读写权限
adb remount
  • 重启手机
adb reboot
  • 查看设备信息(加 -l 可查看更详细的信息)
adb devices -l
  • 修改设备id
adb shell
echo your_id > /sys/class/android_usb/android0/iSerial
exit
adb kill-server
  • 推、拉文件
adb push pcPath/pcFile androidPath/
adb pull pcPath/pcFile androidPath/

在 Terminal 中执行 shell

实用组:

  • 向设备输入内容
    (仅支持英文输入法下输入 字母 和 数字)
adb shell input text + CONTENT
    eg : adb shell input text 1a2b3c
  • 向设备发送事件
adb shell input keyevent + KEYCODE(详见 附录1)
    eg : adb shell input keyevent 26 -> 锁屏
  • 获取当前前台app的pakageName、activityName
adb shell dumpsys window windows | grep -E 'mCurrentFocus'
  • 获取/设置 屏幕密度
adb shell wm density
adb shell wm density 480
  • 获取/设置 屏幕分辨率
adb shell wm size
adb shell wm size 1080x1920
  • 修改文件权限
adb shell chmod + code + file_path
adb shell chmod 644 system/build.prop 
  • 关闭自动旋转
adb shell content insert --uri content://settings/system --bind name:s:accelerometer_rotation --bind value:i:0
  • 打开自动旋转
adb shell content insert --uri content://settings/system --bind name:s:accelerometer_rotation --bind value:i:1
  • 竖屏观看
adb shell content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:0
  • 横屏观看
adb shell content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:1

装13组:

  • 电量显示(Nexus 4 亲测无效)
adb shell content insert --uri content://settings/system --bind name:s:status_bar_show_battery_percent --bind value:i:1
  • 沉浸状态栏
adb shell settings put global policy_control immersive.status=apps
  • 沉浸导航栏
adb shell settings put global policy_control immersive.navigation=*
  • 全屏沉浸
adb shell settings put global policy_control immersive.full=apps
  • 单独控制某个app不沉浸,其他程序沉浸
    eg:以下代码设置google即时桌面不沉浸
adb shell settings put global policy_control immersive.full=apps,-com.google.android.googlequicksearchbox
  • 恢复到正常模式
adb shell settings put global policy_control null

在 Terminal 中执行 am

  • 通过 packageName 启动应用
adb shell am start -W -n packageName/activityName
  • 通过 packageName 停止应用
adb shell am force-stop packageName
  • 热启动

在 Terminal 使用 app_process 启动 java 进程

先推荐篇文章:

CSDN Venscor
简书 app_process64

下面只是一些简要记录,方便查阅:

  1. 编译 java -> class
  2. 编译 class -> dex
  3. push dex 到相应目录
  4. 使用 app_process 运行 dex 中 Main 函数

下面是一个简单的将 dex 推到 SD卡 并运行的实例:

~ » adb push /Users/zhaoyidong/Desktop/Main.dex sdcard/
/Users/zhaoyidong/Desktop/Main.dex: 1 file pushed. 6.1 MB/s (3026512 bytes in 0.472s)
~ » adb shell
shell@R9:/ $ export CLASSPATH=/sdcard/Main.dex
shell@R9:/ $ exec app_process /sdcard com.xxx.xxx.xxx.Main

  • android.os.Process 类可以将以上在命令行内执行的 adb shell 命令一直到 Android App 内部执行,具体操作之后补上。

附录1:KEYCODE对照表

0 -->  "KEYCODE_UNKNOWN"
1 -->  "KEYCODE_MENU"
2 -->  "KEYCODE_SOFT_RIGHT"
3 -->  "KEYCODE_HOME"
4 -->  "KEYCODE_BACK"
5 -->  "KEYCODE_CALL" 
6 -->  "KEYCODE_ENDCALL" 
7 -->  "KEYCODE_0" 
8 -->  "KEYCODE_1" 
9 -->  "KEYCODE_2" 
10 -->  "KEYCODE_3"
11 -->  "KEYCODE_4" 
12 -->  "KEYCODE_5" 
13 -->  "KEYCODE_6" 
14 -->  "KEYCODE_7" 
15 -->  "KEYCODE_8" 
16 -->  "KEYCODE_9" 
17 -->  "KEYCODE_STAR" 
18 -->  "KEYCODE_POUND" 
19 -->  "KEYCODE_DPAD_UP" 
20 -->  "KEYCODE_DPAD_DOWN" 
21 -->  "KEYCODE_DPAD_LEFT" 
22 -->  "KEYCODE_DPAD_RIGHT"
23 -->  "KEYCODE_DPAD_CENTER" 
24 -->  "KEYCODE_VOLUME_UP" 
25 -->  "KEYCODE_VOLUME_DOWN" 
26 -->  "KEYCODE_POWER" 
27 -->  "KEYCODE_CAMERA" 
28 -->  "KEYCODE_CLEAR" 
29 -->  "KEYCODE_A" 
30 -->  "KEYCODE_B" 
31 -->  "KEYCODE_C" 
32 -->  "KEYCODE_D" 
33 -->  "KEYCODE_E" 
34 -->  "KEYCODE_F" 
35 -->  "KEYCODE_G" 
36 -->  "KEYCODE_H" 
37 -->  "KEYCODE_I" 
38 -->  "KEYCODE_J" 
39 -->  "KEYCODE_K" 
40 -->  "KEYCODE_L" 
41 -->  "KEYCODE_M"
42 -->  "KEYCODE_N" 
43 -->  "KEYCODE_O" 
44 -->  "KEYCODE_P" 
45 -->  "KEYCODE_Q" 
46 -->  "KEYCODE_R" 
47 -->  "KEYCODE_S" 
48 -->  "KEYCODE_T" 
49 -->  "KEYCODE_U" 
50 -->  "KEYCODE_V" 
51 -->  "KEYCODE_W" 
52 -->  "KEYCODE_X"
53 -->  "KEYCODE_Y" 
54 -->  "KEYCODE_Z" 
55 -->  "KEYCODE_COMMA" 
56 -->  "KEYCODE_PERIOD"
57 -->  "KEYCODE_ALT_LEFT" 
58 -->  "KEYCODE_ALT_RIGHT" 
59 -->  "KEYCODE_SHIFT_LEFT" 
60 -->  "KEYCODE_SHIFT_RIGHT" 
61 -->  "KEYCODE_TAB" 
62 -->  "KEYCODE_SPACE" 
63 -->  "KEYCODE_SYM" 
64 -->  "KEYCODE_EXPLORER" 
65 -->  "KEYCODE_ENVELOPE" 
66 -->  "KEYCODE_ENTER" 
67 -->  "KEYCODE_DEL" 
68 -->  "KEYCODE_GRAVE" 
69 -->  "KEYCODE_MINUS" 
70 -->  "KEYCODE_EQUALS" 
71 -->  "KEYCODE_LEFT_BRACKET" 
72 -->  "KEYCODE_RIGHT_BRACKET" 
73 -->  "KEYCODE_BACKSLASH" 
74 -->  "KEYCODE_SEMICOLON" 
75 -->  "KEYCODE_APOSTROPHE"
76 -->  "KEYCODE_SLASH" 
77 -->  "KEYCODE_AT" 
78 -->  "KEYCODE_NUM" 
79 -->  "KEYCODE_HEADSETHOOK" 
80 -->  "KEYCODE_FOCUS"
81 -->  "KEYCODE_PLUS"
82 -->  "KEYCODE_MENU"
83 -->  "KEYCODE_NOTIFICATION"
84 -->  "KEYCODE_SEARCH" 
85 -->  "TAG_LAST_KEYCODE" 

你可能感兴趣的:(Android,android,adb-shell,Process)