├── .gitignore
├── .idea
├── artifacts
│ └── ADBLib_jar.xml
├── misc.xml
├── modules.xml
├── uiDesigner.xml
├── vcs.xml
└── workspace.xml
├── ADBLib
├── ADBLib.iml
└── src
│ └── com
│ └── adb
│ ├── command
│ ├── ADBCmd.java
│ └── android
│ │ ├── AndroidDeviceCmd.java
│ │ ├── AndroidEventCmd.java
│ │ ├── AndroidFileCmd.java
│ │ ├── AndroidHardwareCmd.java
│ │ ├── AndroidLogcatCmd.java
│ │ ├── AndroidMemoryCmd.java
│ │ ├── AndroidNetworkCmd.java
│ │ ├── AndroidSystemCmd.java
│ │ └── app
│ │ ├── ActivityCmd.java
│ │ ├── AndroidAppCmd.java
│ │ ├── BroadcastCmd.java
│ │ └── ServiceCmd.java
│ ├── process
│ ├── ACtrl.java
│ ├── ADBCtrl.java
│ ├── Device.java
│ └── android
│ │ ├── AndroidFile.java
│ │ ├── AndroidHardware.java
│ │ ├── AndroidMemory.java
│ │ ├── AndroidNetwork.java
│ │ ├── AndroidSystem.java
│ │ ├── IAndroid.java
│ │ ├── app
│ │ ├── AndroidAPP.java
│ │ ├── ProcessInfo.java
│ │ └── ProcessManager.java
│ │ ├── context
│ │ ├── Activity.java
│ │ ├── ActivityIntentBuilder.java
│ │ ├── Broadcast.java
│ │ ├── BroadcastIntentBuilder.java
│ │ ├── IContext.java
│ │ ├── Service.java
│ │ └── ServiceInentBuilder.java
│ │ ├── event
│ │ ├── AndroidEvent.java
│ │ ├── ClickEventManager.java
│ │ ├── Event.java
│ │ └── KeyCode.java
│ │ └── logcat
│ │ ├── AndroidLogcat.java
│ │ ├── LogcatConfig.java
│ │ └── LogcatConfigBuilder.java
│ └── utils
│ ├── FileUtils.java
│ ├── JarUtils.java
│ └── StringUtils.java
├── ADBLibSample.iml
├── README.md
├── out
└── artifacts
│ └── ADBLib_jar
│ └── ADBLib.jar
└── src
└── com
└── adb
└── sample
├── APPSample.java
├── ActivitySample.java
├── BroadcastSample.java
├── CommonSample.java
├── EventSample.java
├── FileSample.java
├── HardwareSample.java
├── LogcatSample.java
├── NetworkSample.java
├── ServiceSample.java
└── SystemSample.java
/.gitignore:
--------------------------------------------------------------------------------
1 | /out/production/ADBLib/com/adb/command/andriodCmd/*.class
2 | /out/production/ADBLib/com/adb/command/window/*.class
3 | /out/production/ADBLib/com/adb/process/*.class
4 | /out/production/ADBLib/com/adb/process/android/*.class
5 | /out/production/ADBLib/com/adb/process/android/context/*.class
6 | /out/production/ADBLibSample/com/adb/sample/*.class
7 | /out/production/ADBLibSample/com/adb/sample/android/*.class
8 | /out/production/ADBLibSample/com/adb/sample/window/*.class
9 | production
10 |
--------------------------------------------------------------------------------
/.idea/artifacts/ADBLib_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | $PROJECT_DIR$/out/artifacts/ADBLib_jar
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/uiDesigner.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | -
6 |
7 |
8 | -
9 |
10 |
11 | -
12 |
13 |
14 | -
15 |
16 |
17 | -
18 |
19 |
20 |
21 |
22 |
23 | -
24 |
25 |
26 |
27 |
28 |
29 | -
30 |
31 |
32 |
33 |
34 |
35 | -
36 |
37 |
38 |
39 |
40 |
41 | -
42 |
43 |
44 |
45 |
46 | -
47 |
48 |
49 |
50 |
51 | -
52 |
53 |
54 |
55 |
56 | -
57 |
58 |
59 |
60 |
61 | -
62 |
63 |
64 |
65 |
66 | -
67 |
68 |
69 |
70 |
71 | -
72 |
73 |
74 | -
75 |
76 |
77 |
78 |
79 | -
80 |
81 |
82 |
83 |
84 | -
85 |
86 |
87 |
88 |
89 | -
90 |
91 |
92 |
93 |
94 | -
95 |
96 |
97 |
98 |
99 | -
100 |
101 |
102 | -
103 |
104 |
105 | -
106 |
107 |
108 | -
109 |
110 |
111 | -
112 |
113 |
114 |
115 |
116 | -
117 |
118 |
119 | -
120 |
121 |
122 |
123 |
124 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 | 1600014810291
181 |
182 |
183 | 1600014810291
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
--------------------------------------------------------------------------------
/ADBLib/ADBLib.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/ADBLib/src/com/adb/command/ADBCmd.java:
--------------------------------------------------------------------------------
1 | package com.adb.command;
2 |
3 | public class ADBCmd {
4 |
5 | public String version(){
6 | return "cmd /c adb version";
7 | }
8 |
9 | /**
10 | * 查询连接设备
11 | * @return
12 | *
13 | * 正常执行命令应答
14 | * List of devices attached
15 | * c447b522 device
16 | * ea446ade devic
17 | *
18 | */
19 | public String devices(){
20 | return "cmd /c adb devices";
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/ADBLib/src/com/adb/command/android/AndroidDeviceCmd.java:
--------------------------------------------------------------------------------
1 | package com.adb.command.android;
2 |
3 | public class AndroidDeviceCmd{
4 |
5 | /**
6 | * 截屏并保存到window,部分设备不支持(6.0以上设备不可行)
7 | * @param windowPath
8 | * @return
9 | *
10 | * 由于部分设备不支持,建议采用screenshot2AndroidFile然后再复制到电脑端
11 | */
12 | @Deprecated
13 | public String screenshot2WindowFile(String windowPath){
14 | return "adb exec-out screencap -p > "+windowPath;
15 | }
16 |
17 | /**
18 | * 截屏并保存到android
19 | * @param androidPath
20 | * @return
21 | */
22 | public String screenshot2AndroidFile(String androidPath){
23 | return "adb shell screencap -p "+androidPath;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/ADBLib/src/com/adb/command/android/AndroidEventCmd.java:
--------------------------------------------------------------------------------
1 | package com.adb.command.android;
2 |
3 | public class AndroidEventCmd {
4 |
5 | /**
6 | * 点击屏幕
7 | *
8 | * @param x 横坐标
9 | * @param y 纵坐标
10 | * @return 命令行
11 | */
12 | public String click(int x, int y) {
13 | return "adb shell input tap " + x + " " + y;
14 | }
15 |
16 | /**
17 | * 模拟按键
18 | * @param event
19 | * @return
20 | */
21 | public String inputKeyEvent(int event){
22 | return "adb shell input keyevent "+event;
23 | }
24 |
25 | /**
26 | * 滑屏
27 | * @param startX
28 | * @param startY
29 | * @param endX
30 | * @param endY
31 | * @return
32 | */
33 | public String swipe(int startX, int startY, int endX, int endY) {
34 | return "adb shell input swipe "+startX+" "+startY+" "+endX+" "+endY;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/ADBLib/src/com/adb/command/android/AndroidFileCmd.java:
--------------------------------------------------------------------------------
1 | package com.adb.command.android;
2 |
3 | import com.adb.process.Device;
4 |
5 | public class AndroidFileCmd{
6 |
7 | /**
8 | * 获取sdcard目录
9 | * @return
10 | * 在真机上测试返回结果为:/sdcard
11 | */
12 | public String getExternalStorageDirectoryPath(){
13 | return "adb shell echo $EXTERNAL_STORAGE";
14 | }
15 |
16 | /**
17 | * 获取文件夹目录
18 | * @param path
19 | * @return
20 | */
21 | public String listDir(String path){
22 | return "adb shell ls "+path;
23 | }
24 |
25 | /**
26 | *
27 | * @param isDelSelf 是否删除自身,为false的清空下仅删除文件夹下所有文件
28 | * @return
29 | */
30 | public String delDir(boolean isDelSelf,String path){
31 | if(isDelSelf){
32 | return "adb shell rm -r "+path;
33 | }else{
34 | return "adb shell rm "+path+"/*.*";
35 | }
36 | }
37 |
38 | /**
39 | * 删除文件夹下符合后缀的文件
40 | * @param dir
41 | * @param suffix
42 | * @return
43 | */
44 | public String delDirFileBySuffix(String dir,String suffix){
45 | if (suffix == null||suffix.trim().isEmpty()){
46 | suffix = "";
47 | }
48 |
49 | return "adb shell rm "+dir+"/*"+suffix;
50 | }
51 |
52 |
53 | /**
54 | * 拷贝文件从Android到Window
55 | * @param androidPath
56 | * @param windowPath
57 | * @return
58 | */
59 | public String copyFileAndroid2Window(String androidPath,String windowPath){
60 | return "adb pull "+androidPath+" "+windowPath;
61 | }
62 |
63 | /**
64 | * 拷贝文件从Window到Android
65 | * @param androidPath
66 | * @param windowPath
67 | * @return
68 | */
69 | public String copyFileWindow2Android(String androidPath,String windowPath){
70 | return "adb push "+windowPath+" "+androidPath;
71 | }
72 |
73 | /**
74 | * 读取终端文本文件,读取其他的就基本是乱码
75 | * @param path
76 | * @return
77 | */
78 | public String readTextFile(String path){
79 | return "adb shell cat "+path;
80 | }
81 |
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/ADBLib/src/com/adb/command/android/AndroidHardwareCmd.java:
--------------------------------------------------------------------------------
1 | package com.adb.command.android;
2 |
3 | import com.adb.process.Device;
4 |
5 | public class AndroidHardwareCmd{
6 |
7 | /**
8 | * Physical size: 1080x1920
9 | *-----
10 | * Physical size: 1080x1920
11 | * Override size: 480x1024
12 | *
13 | * 获取屏幕分辨率
14 | * @return
15 | */
16 | public String screenSize(){
17 | return "adb shell wm size";
18 | }
19 |
20 | /**
21 | * Physical density: 480
22 | * Override density: 160 //修改后
23 | * @return
24 | */
25 | public String screenDensity(){
26 | return "adb shell wm density";
27 | }
28 |
29 | /**
30 | * 屏幕信息
31 | * @return
32 | *
33 | * WINDOW MANAGER DISPLAY CONTENTS (dumpsys window displays)
34 | * Display: mDisplayId=0
35 | * init=1080x1920 420dpi cur=1080x1920 app=1080x1794 rng=1080x1017-1810x1731
36 | * deferred=false layoutNeeded=false
37 | */
38 | public String screenInfo(){
39 | return "adb shell dumpsys window displays";
40 | }
41 |
42 | /**
43 | * 获取电池信息
44 | * @return
45 | */
46 | public String getBatteryInfo() {
47 | return "adb shell dumpsys battery";
48 | }
49 |
50 |
51 | /**
52 | * 设置屏幕方向
53 | * Android 10测试无效,暂未在其他设备上测试
54 | * @param i
55 | * @return
56 | */
57 | @Deprecated
58 | public String setScreenRotation(int i) {
59 | return "adb shell content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:"+i;
60 | }
61 |
62 | /**
63 | * 是否锁定方向
64 | * Android 10测试有效(小米10)
65 | *
66 | * @param isLock
67 | * @return
68 | */
69 | public String setLockRotation(boolean isLock){
70 | return "adb shell content insert --uri content://settings/system --bind name:s:accelerometer_rotation --bind value:i:"+(isLock?0:1);
71 | }
72 |
73 | public String cpuInfo(){
74 | return "adn shell dumpsys cpuinfo";
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/ADBLib/src/com/adb/command/android/AndroidLogcatCmd.java:
--------------------------------------------------------------------------------
1 | package com.adb.command.android;
2 |
3 | public class AndroidLogcatCmd{
4 |
5 | /**
6 | * 打印日志
7 | * @param grep
8 | * @return
9 | */
10 | public String logcat(String grep){
11 | if (grep == null||grep.isEmpty()){
12 | return "adb shell logcat -v time";
13 | }else{
14 | return "adb shell logcat -v time | grep \""+grep+"\"";
15 | }
16 | }
17 |
18 | /**
19 | * 保存日志至指定文件
20 | *
21 | * @param path
22 | * @return
23 | */
24 | @Deprecated
25 | public String logcat2WindowFile(String path){
26 | return "adb logcat -v time > "+path;
27 | }
28 |
29 | /**
30 | * 保存日志到Android设备中(这里的过滤会影响该程序的所有日志的输出,包括崩溃日志:)
31 | * @param path
32 | * @param tag
33 | * @return
34 | */
35 | public String logcat2AndroidFile(String path,String tag){
36 | if (tag == null||tag.isEmpty()){
37 | tag = "*";//不过滤TAG
38 | }
39 |
40 | return "adb shell logcat -v time -f /sdcard/test.txt -s TAG:"+tag;
41 | }
42 |
43 | public String logcatByPid(String pid) {
44 | return "adb shell logcat --pid "+pid;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/ADBLib/src/com/adb/command/android/AndroidMemoryCmd.java:
--------------------------------------------------------------------------------
1 | package com.adb.command.android;
2 |
3 | import com.adb.process.Device;
4 |
5 | public class AndroidMemoryCmd{
6 |
7 | /**
8 | * 向进程,发出 level=RUNNING_LOW 的收紧内存命令。
9 | * @param pid
10 | * @param trimLevel
11 | * @return
12 | */
13 | public String sendTrimMemory(String pid, String trimLevel) {
14 | return "adb shell am send-trim-memory "+pid+" "+trimLevel;
15 | }
16 |
17 | /**
18 | * 获取内存信息
19 | * @return
20 | */
21 | public String memoryOfSystem() {
22 | return "adb shell cat /proc/meminfo";
23 | }
24 |
25 | /**
26 | * 获取资源占用前 num 的进程
27 | * @param num
28 | * @return
29 | */
30 | public String memoryTop(int num) {
31 | return "adb shell top "+num;
32 | }
33 |
34 | /**
35 | * 各个进程的内存占用情况,根据高到低排序
36 | * @return
37 | */
38 | public String memoryOfProcessList(){
39 | return "adb shell dumpsys meminfo";
40 | }
41 |
42 | public String memoryOfApp(String packageName){
43 | return "adb shell dumpsys meminfo "+packageName;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/ADBLib/src/com/adb/command/android/AndroidNetworkCmd.java:
--------------------------------------------------------------------------------
1 | package com.adb.command.android;
2 |
3 | import com.adb.process.Device;
4 |
5 | public class AndroidNetworkCmd{
6 |
7 | /**
8 | * Android 10测试可行
9 | * 如:adb shell ping -c 4 www.baidu.com
10 | * @param url
11 | * @param count
12 | * @return
13 | */
14 | public String ping(String url, int count) {
15 | return "adb shell ping -c "+count+" "+url;
16 | }
17 |
18 | /**
19 | *
20 | * Android 10测试可行
21 | * 打开/关闭 WIFI
22 | * @param isOpen
23 | * @return
24 | */
25 | public String setWifiSwitch(boolean isOpen){
26 | return "adb shell svc wifi "+(isOpen?"enable":"disable");
27 | }
28 |
29 | /**
30 | * Android 10测试可行
31 | *
32 | * (如4G通讯)流量开关
33 | * @param isOpen
34 | * @return
35 | */
36 | public String setNetSwitch(boolean isOpen){
37 | return "adb shell svc data "+(isOpen?"enable":"disable");
38 | }
39 |
40 | /**
41 | * 通讯模块及WIFI均为正常打开状态下,是否WIFI优先
42 | * @param isPreferWifi true:Wifi优先,false:4G通讯优先
43 | * @return
44 | */
45 | public String isPreferWifi(boolean isPreferWifi){
46 | if (isPreferWifi){
47 | return "adb shell svc wifi prefer";
48 | }else{
49 | return "adb shell svc data prefer";
50 | }
51 | }
52 |
53 | /**
54 | * Android 10测试可行
55 | *
56 | * 获取设备IP
57 | * @return
58 | */
59 | public String getLocalAddress() {
60 | return "adb shell ip -f inet addr show wlan0";
61 | }
62 |
63 |
64 | /**
65 | * Android 10测试可行
66 | * 网络连接状态
67 | * @return
68 | */
69 | public String connectivity(){
70 | return "adb shell dumpsys connectivity";
71 | }
72 |
73 | /**
74 | * Android 10测试可行
75 | * 网络策略
76 | * @return
77 | */
78 | public String netPolicy(){
79 | return "adb shell dumpsys netpolicy";
80 | }
81 |
82 | /**
83 | * Android 10测试可行
84 | * 网络状态
85 | * @return
86 | */
87 | public String netStatus(){
88 | return "adb shell adb shell dumpsys netstats";
89 | }
90 |
91 | /**
92 | * Android 10测试可行
93 | * 网络管理
94 | * @return
95 | */
96 | public String networkManagement(){
97 | return "adb shell dumpsys network_management";
98 | }
99 |
100 |
101 | /**
102 | * Android 10测试无可用
103 | * 查看端口信息
104 | * @return
105 | *
106 | */
107 | @Deprecated
108 | public String netcfg(){
109 | return "adb shell netcfg";
110 | }
111 |
112 |
113 | }
114 |
--------------------------------------------------------------------------------
/ADBLib/src/com/adb/command/android/AndroidSystemCmd.java:
--------------------------------------------------------------------------------
1 | package com.adb.command.android;
2 |
3 | public class AndroidSystemCmd{
4 |
5 | /**
6 | * 获取进程列表
7 | * @return
8 | */
9 | public String listProcess(String grep){
10 | if (grep == null||grep.isEmpty()){
11 | return "adb shell ps";
12 | }else{
13 | return "adb shell ps|grep "+grep;
14 | }
15 | }
16 |
17 | /**
18 | * Android 5.0以下
19 | * @return
20 | */
21 | public String devIMEI() {
22 | return "adb shell dumpsys iphonesubinfo";
23 | }
24 |
25 | /**
26 | * 型号
27 | * @return
28 | */
29 | public String devModel() {
30 | return "adb shell getprop ro.product.model";
31 | }
32 |
33 | /**
34 | * 品牌
35 | * @return
36 | */
37 | public String devBrand() {
38 | return "adb shell getprop ro.product.brand";
39 | }
40 |
41 | /**
42 | * 获取系统时间
43 | * @return
44 | */
45 | public String date() {
46 | return "adb shell date";
47 | }
48 |
49 | public String locationInfo() {
50 | return "adb shell dumpsys location";
51 | }
52 |
53 | public String SDKVersion() {
54 | return "adb shell getprop ro.build.version.sdk";
55 | }
56 |
57 | public String systemVersion() {
58 | return "adb shell getprop ro.build.version.release";
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/ADBLib/src/com/adb/command/android/app/ActivityCmd.java:
--------------------------------------------------------------------------------
1 | package com.adb.command.android.app;
2 |
3 | public class ActivityCmd{
4 |
5 | /**
6 | *启动应用的Activity
7 | * @param packageName 包名
8 | * @param canonicalName 在包名下的地址
9 | * @return
10 | */
11 | public String startActivity(String packageName, String canonicalName){
12 | if (canonicalName == null||canonicalName.trim().isEmpty()){
13 | return "adb shell am start -n "+packageName;//部分设备不可用,不建议使用
14 | }else{
15 | return "adb shell am start -n "+packageName+"/"+canonicalName;//需要有intent-filter/Action/category
16 | }
17 | }
18 |
19 | /**
20 | *启动应用的Activity
21 | * @param packageName 包名
22 | * @return
23 | */
24 | public String startActivity(String packageName){
25 | return "adb shell monkey -p "+packageName+" -c android.intent.category.LAUNCHER 1";
26 | }
27 |
28 | /**
29 | * 获取启动
30 | * @param packageName
31 | * @param canonicalName
32 | * @return
33 | */
34 | public String getTimeOfStartActivity(String packageName,String canonicalName){
35 | return "adb shell am start -W "+packageName+"/"+canonicalName;
36 | }
37 |
38 | /**
39 | * 获取前台Activity
40 | * @return
41 | */
42 | public String getForegroundActivity(){
43 | return "adb shell dumpsys activity activities | grep \"mResumedActivity\"";
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/ADBLib/src/com/adb/command/android/app/AndroidAppCmd.java:
--------------------------------------------------------------------------------
1 | package com.adb.command.android.app;
2 |
3 | public class AndroidAppCmd{
4 |
5 | /**
6 | * 安装Window上的APK文件
7 | * @param windowPath 文件路径
8 | * @param isDebugApk 是否为debug签名的APK
9 | * @param isReInstall 如果已安装,是否重新安装
10 | * @return
11 | */
12 | public String install(String windowPath,boolean isDebugApk,boolean isReInstall){
13 | return "adb install "+(isReInstall?"-r ":"")+(isDebugApk?"-t ":"")+windowPath;
14 | }
15 |
16 | /**
17 | * 卸载应用
18 | * @param packageName
19 | * @return
20 | */
21 | public String uninstall(String packageName){
22 | return "adb uninstall "+packageName;
23 | }
24 |
25 |
26 | /**
27 | * APP列表
28 | * @return
29 | */
30 | public String listAPP(){
31 | return "adb shell pm list packages";
32 | }
33 |
34 | /**
35 | * 系统APP列表
36 | * @return
37 | */
38 | public String listSystemAPP(){
39 | return "adb shell pm list packages -s";
40 | }
41 |
42 | /**
43 | * 所有第三方应用
44 | * @return
45 | */
46 | public String list3APP(){
47 | return "adb shell pm list packages -3";
48 | }
49 |
50 |
51 | /**
52 | * 强制停止应用
53 | * @param packageName 包名
54 | * @return
55 | */
56 | public String stopApp(String packageName){
57 | return "adb shell am force-stop "+packageName;
58 | }
59 |
60 | public String getPid(String packageName){
61 | return "adb shell pidof "+packageName;
62 | }
63 |
64 | /**
65 | * 清空APP数据
66 | * @return
67 | */
68 | public String cleanAPPData(String packageName){
69 | return "adb shell pm clear "+packageName;
70 | }
71 |
72 | /**
73 | * 读取应用的基本信息
74 | * @param packageName
75 | * @return
76 | */
77 | public String readAppInfo(String packageName) {
78 | return "adb shell dumpsys package "+packageName;
79 | }
80 |
81 | public String readAppInstallPath(String packageName) {
82 | return "adb shell pm path "+packageName;
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/ADBLib/src/com/adb/command/android/app/BroadcastCmd.java:
--------------------------------------------------------------------------------
1 | package com.adb.command.android.app;
2 |
3 | public class BroadcastCmd {
4 | public String send(String action){
5 | return "adb shell am broadcast -a "+action;
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/ADBLib/src/com/adb/command/android/app/ServiceCmd.java:
--------------------------------------------------------------------------------
1 | package com.adb.command.android.app;
2 |
3 | public class ServiceCmd {
4 |
5 | /**
6 | *启动应用的Activity
7 | * @param packageName 包名
8 | * @param canonicalName 在包名下的地址
9 | * @return
10 | */
11 | public String startService(String packageName,String canonicalName){
12 | return "adb shell am startservice -n "+packageName+"/"+canonicalName;
13 | }
14 |
15 | /**
16 | * 获取所有正在运行的服务
17 | * @param packageName
18 | * @return
19 | */
20 | public String getAllRunningService(String packageName) {
21 |
22 | if (packageName==null||packageName.isEmpty()){
23 | return "adb shell dumpsys activity services";
24 | }else{
25 | return "adb shell dumpsys activity services "+packageName;
26 | }
27 |
28 | }
29 |
30 | /**
31 | * 停止服务
32 | * @param packageName
33 | * @param canonicalName
34 | * @return
35 | */
36 | public String stopService(String packageName, String canonicalName) {
37 | return "adb shell am stopservice "+packageName+"/"+canonicalName;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/ADBLib/src/com/adb/process/ACtrl.java:
--------------------------------------------------------------------------------
1 | package com.adb.process;
2 |
3 | import java.io.*;
4 | import java.nio.charset.Charset;
5 |
6 | public abstract class ACtrl {
7 |
8 | protected Runtime runtime;
9 | protected String charset = "GBK";//编码格式
10 | protected boolean isPrintCmd = false;
11 | protected File runtimeDir = null;//运行位置,如adb的地址
12 |
13 | public ACtrl(){
14 | runtime = Runtime.getRuntime();
15 | }
16 |
17 | public ACtrl(String runtimePath){
18 | this();
19 |
20 | if (runtimePath != null && !runtimePath.trim().isEmpty()) {
21 | File temp = new File(runtimePath);
22 | if (!temp.exists()) {
23 | System.err.println("找不到该文件夹");
24 | this.runtimeDir = null;
25 | } else if (temp.isDirectory()) {
26 | this.runtimeDir = temp;
27 | } else{
28 | this.runtimeDir = temp.getParentFile();
29 | }
30 | }else{
31 | this.runtimeDir = null;
32 | }
33 | }
34 |
35 | /**
36 | * 设置编码格式
37 | * @param charset
38 | */
39 | public void setCharset(String charset){
40 | if (charset!=null&&!charset.isEmpty()){
41 | this.charset = charset;
42 | }
43 | }
44 |
45 | /**
46 | * 是否打印执行的命令
47 | * @param isPrintCmd
48 | */
49 | public void isPrintCmd(boolean isPrintCmd){
50 | this.isPrintCmd = isPrintCmd;
51 | }
52 |
53 |
54 | /**
55 | *
56 | * @param command
57 | * @param envp
58 | * @param dir
59 | * @return
60 | * @throws Exception
61 | */
62 | protected Process exec(String command, String[] envp, File dir) throws IOException {
63 |
64 | if (isPrintCmd) {
65 | System.out.println(command);
66 | }
67 |
68 | return runtime.exec(command, envp, dir);
69 | }
70 |
71 | /**
72 | * 执行cmd
73 | * @param cmd
74 | * @return
75 | * @throws IOException
76 | */
77 | public String exec(String cmd) throws IOException {
78 | return getReply(exec(cmd,null,runtimeDir));
79 | }
80 |
81 | /**
82 | * 执行cmd并实时输出(适用于持续输出的命令,如日志)
83 | * @param cmd
84 | * @return
85 | * @throws IOException
86 | */
87 | public void execAPrint(String cmd) throws IOException {
88 | print(exec(cmd,null,runtimeDir));
89 | }
90 |
91 | /**
92 | * 执行并将输出保存,适用于日志
93 | * @param cmd 执行的命令
94 | * @param path 保存路径
95 | * @param isPrintOutput
96 | * @throws IOException
97 | */
98 | public void execASave(String cmd,String path,boolean isPrintOutput) throws IOException {
99 | save(exec(cmd,null,runtimeDir),path,isPrintOutput);
100 | }
101 |
102 | /**
103 | *
104 | * @param cmd 命令
105 | * @param callback 回调
106 | * @param grep 每一行的过滤关键字(仅打印回调存在该关键字的日志)
107 | * @param isPrint 是否打印
108 | */
109 | public void exec(String cmd, IExecCallback callback, String grep,boolean isPrint) {
110 |
111 | if (callback == null&&!isPrint){
112 | return;
113 | }
114 |
115 | try{
116 | Process process = exec(cmd,null,null);
117 |
118 | if (callback != null){
119 | callback.onCreatedProcess(process);
120 | }
121 |
122 |
123 | BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream(), Charset.forName(charset)));
124 |
125 | String line;
126 |
127 | while ((line=br.readLine())!=null) {
128 |
129 | if (grep !=null&&!line.contains(grep)){
130 | continue;
131 | }
132 |
133 | if(isPrint){
134 | System.out.println(line);
135 | }
136 |
137 | if (callback != null){
138 | callback.onReplyLine(line);
139 | }
140 | }
141 |
142 | BufferedReader error = new BufferedReader(new InputStreamReader(process.getErrorStream(),Charset.forName(charset)));
143 | String errorLine;
144 | while ((errorLine = error.readLine())!=null) {
145 |
146 | if(isPrint){
147 | System.out.println(errorLine);
148 | }
149 |
150 | if (callback != null){
151 | callback.onErrorLine(errorLine);
152 | }
153 | }
154 |
155 | }catch (Exception e){
156 | e.printStackTrace();
157 | }
158 | }
159 |
160 |
161 | /**
162 | * 打印输出
163 | * @param process
164 | */
165 | protected void print(Process process) {
166 | try{
167 | BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream(), Charset.forName(charset)));
168 |
169 | String line;
170 |
171 | while ((line=br.readLine())!=null) {
172 | System.out.println(line);
173 | }
174 |
175 | BufferedReader error = new BufferedReader(new InputStreamReader(process.getErrorStream(),Charset.forName(charset)));
176 | String errorLine;
177 | while ((errorLine = error.readLine())!=null) {
178 | System.out.println(errorLine);
179 | }
180 |
181 | }catch (Exception e){
182 | e.printStackTrace();
183 | }
184 | }
185 |
186 | /**
187 | * 保存及打印输出
188 | * @param process
189 | * @param path
190 | * @param isPrint
191 | */
192 | private void save(Process process,String path,boolean isPrint) {
193 | try{
194 | RandomAccessFile file = new RandomAccessFile(path,"rw");
195 | BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream(), Charset.forName(charset)));
196 |
197 | file.seek(file.length());
198 |
199 | String line;
200 | while ((line=br.readLine())!=null) {
201 | if (isPrint){
202 | System.out.println(line);
203 | }
204 |
205 | file.writeBytes(line+"\r\n");
206 | }
207 |
208 | BufferedReader error = new BufferedReader(new InputStreamReader(process.getErrorStream(),Charset.forName(charset)));
209 | String errorLine;
210 | while ((errorLine = error.readLine())!=null) {
211 |
212 | if (isPrint){
213 | System.out.println(errorLine+"\r\n");
214 | }
215 |
216 | file.writeBytes(errorLine);
217 |
218 | }
219 |
220 | }catch (Exception e){
221 | e.printStackTrace();
222 | }
223 | }
224 |
225 | /**
226 | * 获取应答
227 | * @param process
228 | * @return
229 | */
230 | private String getReply(Process process){
231 |
232 | try{
233 | BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream(), Charset.forName(charset)));
234 | StringBuilder builder = new StringBuilder();
235 |
236 | String line;
237 | while ((line=br.readLine())!=null) {
238 | builder.append(line);
239 | builder.append("\r\n");
240 | }
241 |
242 | BufferedReader error = new BufferedReader(new InputStreamReader(process.getErrorStream(),Charset.forName(charset)));
243 | String errorLine;
244 |
245 | while ((errorLine = error.readLine())!=null) {
246 | builder.append(errorLine);
247 | builder.append("\r\n");
248 | }
249 |
250 | return builder.toString();
251 | }catch (Exception e){
252 | e.printStackTrace();
253 |
254 | //通常adb执行时找不到设备应答前缀为error:,这里也采用该返回
255 | return "error:"+e.getMessage();
256 | }
257 |
258 |
259 | }
260 |
261 | /**
262 | * 执行cmd并实时输出(适用于持续输出的命令,如日志)
263 | * @param cmd
264 | * @return
265 | * @throws IOException
266 | */
267 | public void execAPrint(String cmd,String grep) throws IOException {
268 | if (isPrintCmd){
269 | System.out.println(cmd);
270 | }
271 |
272 | if (grep == null||grep.trim().isEmpty()){
273 | print(exec(cmd,null,null));
274 | }else{
275 | print(exec(cmd,null,null),grep);
276 | }
277 |
278 | }
279 |
280 | /**
281 | *
282 | * 由于 grep 的指令会导致输入流的处理出现堵塞,输出的数据会相对滞后于正常命令行的输出(肉眼可见),采用contains替代解决该问题
283 | * 该方案下运行数据与命令行输出的数据时间上相差无几
284 | *
285 | * 打印输出
286 | * @param process
287 | */
288 | private void print(Process process,String grep) {
289 | if (isPrintCmd){
290 | System.out.println("grep "+grep);
291 | }
292 |
293 | try{
294 | BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream(), Charset.forName(charset)));
295 |
296 | String line;
297 |
298 | while ((line=br.readLine())!=null) {
299 | if (line.contains(grep)){
300 | System.out.println(line);
301 | }
302 | }
303 |
304 | BufferedReader error = new BufferedReader(new InputStreamReader(process.getErrorStream(),Charset.forName(charset)));
305 | String errorLine;
306 | while ((errorLine = error.readLine())!=null) {
307 | System.out.println(errorLine);
308 | }
309 |
310 | }catch (Exception e){
311 | e.printStackTrace();
312 | }
313 | }
314 |
315 | public void close(){
316 | if (runtime!=null){
317 | runtime.gc();
318 | }
319 | }
320 |
321 | public interface IExecCallback{
322 | public void onCreatedProcess(Process process);
323 | public void onReplyLine(String str);
324 | public void onErrorLine(String str);
325 | }
326 |
327 | }
328 |
--------------------------------------------------------------------------------
/ADBLib/src/com/adb/process/ADBCtrl.java:
--------------------------------------------------------------------------------
1 | package com.adb.process;
2 |
3 | import com.adb.command.ADBCmd;
4 |
5 | public class ADBCtrl extends ACtrl{
6 |
7 | private Device[] devices;
8 | private ADBCmd cmd = new ADBCmd();
9 |
10 | /**
11 | * 在已经配置adb环境变量的情况下,调用该方法
12 | */
13 | public ADBCtrl(){
14 | super();
15 | }
16 |
17 | /**
18 | *
19 | * @param adbDir ADB所在文件夹
20 | */
21 | public ADBCtrl(String adbDir){
22 | super(adbDir);
23 | }
24 |
25 | @Override
26 | public void setCharset(String charset) {
27 | super.setCharset(charset);
28 |
29 | if (devices!=null){
30 | for (Device device:devices){
31 | device.setCharset(charset);
32 | }
33 | }
34 | }
35 |
36 | @Override
37 | public void isPrintCmd(boolean isPrintCmd) {
38 | super.isPrintCmd(isPrintCmd);
39 |
40 | if (devices!=null){
41 | for (Device device:devices){
42 | device.isPrintCmd(isPrintCmd);
43 | }
44 | }
45 | }
46 |
47 |
48 |
49 | public String queryADBVersion(){
50 | try{
51 | return exec(cmd.version());
52 | }catch (Exception e){
53 | e.printStackTrace();
54 | }
55 |
56 | return "";
57 | }
58 |
59 |
60 | /**
61 | * Android 10测试可行
62 | *
63 | * 获取当前正在连接的设备
64 | * @return
65 | */
66 | public Device[] listDevices(){
67 | try{
68 | String msg = exec(cmd.devices());
69 | String[] list = msg.split("\r\n");
70 |
71 | if (list.length > 1&&list[0].equalsIgnoreCase("List of devices attached")){
72 | devices = new Device[list.length - 1];
73 |
74 | for (int i = 1;i 0) {
93 | return list[0];
94 | }else{
95 | return null;
96 | }
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/ADBLib/src/com/adb/process/Device.java:
--------------------------------------------------------------------------------
1 | package com.adb.process;
2 |
3 | import com.adb.command.android.AndroidDeviceCmd;
4 | import com.adb.process.android.*;
5 | import com.adb.process.android.app.AndroidAPP;
6 | import com.adb.process.android.context.Activity;
7 | import com.adb.process.android.context.Broadcast;
8 | import com.adb.process.android.context.Service;
9 | import com.adb.process.android.event.AndroidEvent;
10 | import com.adb.process.android.logcat.AndroidLogcat;
11 |
12 | import java.io.File;
13 | import java.io.IOException;
14 |
15 | public class Device extends ACtrl{
16 |
17 | public String deviceName;
18 | private String prefix;
19 |
20 | /**
21 | *
22 | * @param adbCtrl Device将继承ADBCtrl的基本参数配置,当设置ADBCtrl时,也会同时设置所有连接的设备,
23 | * 但如果设置Device,则只对该Device的输出数据有效
24 | * @param deviceName
25 | */
26 | protected Device(ADBCtrl adbCtrl,String deviceName) {
27 | this.runtimeDir = adbCtrl.runtimeDir;
28 | this.charset = adbCtrl.charset;
29 | this.isPrintCmd = adbCtrl.isPrintCmd;
30 |
31 | this.deviceName = deviceName;
32 | this.prefix = "adb -s "+deviceName;
33 | }
34 |
35 | public AndroidLogcat managerOfLogcat(){
36 | return new AndroidLogcat(this);
37 | }
38 |
39 | public AndroidAPP managerOfApp(){
40 | return new AndroidAPP(this);
41 | }
42 |
43 | public AndroidFile managerOfFile(){
44 | return new AndroidFile(this);
45 | }
46 |
47 | public Activity managerOfActivity(){
48 | return new Activity(this);
49 | }
50 |
51 | public Service managerOfService(){
52 | return new Service(this);
53 | }
54 |
55 | public Broadcast managerOfBroadcast(){
56 | return new Broadcast(this);
57 | }
58 |
59 | public AndroidHardware managerOfHardware(){
60 | return new AndroidHardware(this);
61 | }
62 |
63 | public AndroidSystem managerOfSystem(){
64 | return new AndroidSystem(this);
65 | }
66 |
67 | public AndroidMemory managerOfMemory(){
68 | return new AndroidMemory(this);
69 | }
70 |
71 | public AndroidNetwork managerOfNetwork(){
72 | return new AndroidNetwork(this);
73 | }
74 |
75 | public AndroidEvent managerOfEvent(){return new AndroidEvent(this);}
76 |
77 | private AndroidDeviceCmd cmd = new AndroidDeviceCmd();
78 |
79 | @Override
80 | protected Process exec(String command, String[] envp, File dir) throws IOException {
81 | if(command.startsWith("adb")){
82 | command = command.replace("adb",prefix);
83 | }
84 |
85 | return super.exec(command, envp, dir);
86 | }
87 |
88 |
89 |
90 | /**
91 | * 截屏并保存到window
92 | *
93 | * 由于ADB的已有指令仅支持低版本的设备,故而采用更通用的方案
94 | * 先截屏保存至Android,再将文件从Android复制到Window,最后删除Android上的文件
95 | * @param windowPath
96 | * @return
97 | */
98 | public boolean screenshot2WindowFile(String windowPath){
99 |
100 | AndroidFile file = new AndroidFile(this);
101 |
102 | try{
103 | String path = file.getExternalStorageDirectoryPath().trim();
104 | if (path == null||path.isEmpty()){
105 | System.err.println("获取sdcard目录失败");
106 | return false;
107 | }else{
108 | String name = new File(windowPath).getName();
109 | String androidPath = path+"/"+name;
110 |
111 | screenshot2AndroidFile(androidPath);
112 | String rs = file.copyFileAndroid2Window(androidPath,windowPath);
113 | file.delDirFileBySuffix(path,name);
114 |
115 | return rs.contains("file pulled");
116 | }
117 |
118 | }catch (Exception e){
119 | e.printStackTrace();
120 | }
121 |
122 | return false;
123 | }
124 |
125 | /**
126 | * 截屏并保存到android
127 | * @param androidPath
128 | * @return
129 | */
130 | public boolean screenshot2AndroidFile(String androidPath){
131 | try{
132 | String reply = exec(cmd.screenshot2AndroidFile(androidPath));
133 | return !reply.startsWith("error:");
134 | }catch (Exception e){
135 | e.printStackTrace();
136 | }
137 |
138 | return false;
139 | }
140 |
141 | }
142 |
--------------------------------------------------------------------------------
/ADBLib/src/com/adb/process/android/AndroidFile.java:
--------------------------------------------------------------------------------
1 | package com.adb.process.android;
2 |
3 | import com.adb.command.android.AndroidFileCmd;
4 | import com.adb.process.Device;
5 |
6 | import java.io.IOException;
7 |
8 | public class AndroidFile extends IAndroid {
9 |
10 | AndroidFileCmd cmd = new AndroidFileCmd();
11 |
12 | public AndroidFile(Device context) {
13 | super(context);
14 | }
15 |
16 | /**
17 | * 获取sdcard目录
18 | * @return
19 | * 在真机上测试返回结果为:/sdcard
20 | */
21 | public String getExternalStorageDirectoryPath(){
22 | try {
23 | return context.exec(cmd.getExternalStorageDirectoryPath());
24 | } catch (IOException e) {
25 | e.printStackTrace();
26 | }
27 | return "";
28 | }
29 |
30 | /**
31 | * Android 10测试可行
32 | *
33 | * 拷贝文件从Android到Window
34 | * @param androidPath
35 | * @param windowPath
36 | * @return 正常情况,执行成功内容为:/sdcard/pic.png: 1 file pulled. 10.0 MB/s (219974 bytes in 0.021s)
37 | */
38 | public String copyFileAndroid2Window(String androidPath,String windowPath){
39 | try {
40 | return context.exec(cmd.copyFileAndroid2Window(androidPath, windowPath));
41 | } catch (IOException e) {
42 | e.printStackTrace();
43 | }
44 | return "";
45 | }
46 |
47 | /**
48 | * Android 10亲测可行
49 | *
50 | * 拷贝文件从Window到Android
51 | * @param androidPath
52 | * @param windowPath
53 | * @return
54 | */
55 | public String copyFileWindow2Android(String androidPath,String windowPath){
56 | try {
57 | return context.exec(cmd.copyFileWindow2Android(androidPath, windowPath));
58 | } catch (IOException e) {
59 | e.printStackTrace();
60 | }
61 | return "";
62 | }
63 |
64 | /**
65 | * Android 10测试可行
66 | *
67 | * 读取终端文本文件,读取其他的就基本是乱码
68 | * @param path
69 | * @return
70 | */
71 | public String readTextFile(String path){
72 | try {
73 | return context.exec(cmd.readTextFile(path));
74 | } catch (IOException e) {
75 | e.printStackTrace();
76 | }
77 | return "";
78 | }
79 |
80 | /**
81 | * Android 10 亲测可行 测试地址为根目录:/storage/emulated/0/
82 | *
83 | * 获取文件夹目录
84 | * @return
85 | */
86 | public String listDir(String path){
87 | try {
88 | return context.exec(cmd.listDir(path));
89 | } catch (IOException e) {
90 | e.printStackTrace();
91 | }
92 | return "";
93 | }
94 |
95 | /**
96 | * Android亲测可行,测试地址为:/storage/emulated/0/新建文件夹(里面有一个文件为 1.png
97 | *
98 | * 删除文件夹
99 | * @param isDelSelf 是否删除自身,为false时,只删除文件夹下的所有文件
100 | * @return
101 | */
102 | public String deleteDir(boolean isDelSelf,String path){
103 | try {
104 | return context.exec(cmd.delDir(isDelSelf,path));
105 | } catch (IOException e) {
106 | e.printStackTrace();
107 | }
108 | return "";
109 | }
110 |
111 | /**
112 | * Android 10测试可行 测试地址为:/storage/emulated/0/新建文件夹,删除条件为 .log
113 | *
114 | * 删除文件夹下的指定后缀的文件
115 | * @param dir
116 | * @param suffix
117 | * @return 正常的情况下,执行成功后无回复内容
118 | *
119 | */
120 | public String delDirFileBySuffix(String dir,String suffix){
121 | try {
122 | return context.exec(cmd.delDirFileBySuffix(dir, suffix));
123 | } catch (IOException e) {
124 | e.printStackTrace();
125 | }
126 | return "";
127 | }
128 |
129 |
130 | }
131 |
--------------------------------------------------------------------------------
/ADBLib/src/com/adb/process/android/AndroidHardware.java:
--------------------------------------------------------------------------------
1 | package com.adb.process.android;
2 |
3 | import com.adb.command.android.AndroidHardwareCmd;
4 | import com.adb.process.Device;
5 | import com.sun.glass.ui.Size;
6 |
7 | import java.io.IOException;
8 |
9 | public class AndroidHardware extends IAndroid {
10 |
11 | AndroidHardwareCmd cmd = new AndroidHardwareCmd();
12 |
13 | public AndroidHardware(Device context) {
14 | super(context);
15 | }
16 |
17 | /* 获取屏幕分辨率
18 | * @return
19 | */
20 | public String screenSize(){
21 | try {
22 | return context.exec(cmd.screenSize());
23 | } catch (IOException e) {
24 | e.printStackTrace();
25 | }
26 | return "";
27 | }
28 |
29 | /**
30 | * 如果获取大小失败则返回空
31 | * @return
32 | */
33 | public Size getScreenSize(){
34 | try {
35 | String[] msg = screenSize().substring(15).trim().split("x");
36 |
37 | Size size = new Size();
38 | size.width = Integer.parseInt(msg[0]);
39 | size.height = Integer.parseInt(msg[1]);
40 |
41 | return size;
42 | }catch (Exception e){
43 | e.printStackTrace();
44 | }
45 |
46 | return null;
47 | }
48 |
49 | /**
50 | * Physical density: 480
51 | * Override density: 160 //修改后
52 | * @return
53 | */
54 | public String screenDensity(){
55 | try {
56 | return context.exec(cmd.screenDensity());
57 | } catch (IOException e) {
58 | e.printStackTrace();
59 | }
60 | return "";
61 | }
62 |
63 | /**
64 | * 屏幕信息
65 | * @return
66 | *
67 | * WINDOW MANAGER DISPLAY CONTENTS (dumpsys window displays)
68 | * Display: mDisplayId=0
69 | * init=1080x1920 420dpi cur=1080x1920 app=1080x1794 rng=1080x1017-1810x1731
70 | * deferred=false layoutNeeded=false
71 | */
72 | public String screenInfo(){
73 | try {
74 | return context.exec(cmd.screenInfo());
75 | } catch (IOException e) {
76 | e.printStackTrace();
77 | }
78 | return "";
79 | }
80 |
81 | /**
82 | * 由于在Android 10上测试无效,且暂未在其他设备上测试过
83 | * 设置屏幕方向,
84 | * @param i 参数范围为 0 - 3
85 | * @return
86 | */
87 | @Deprecated
88 | public String setScreenRotation(int i) {
89 | try {
90 | return context.exec(cmd.setScreenRotation(i));
91 | } catch (IOException e) {
92 | e.printStackTrace();
93 | }
94 |
95 | return "";
96 | }
97 |
98 | /**
99 | * 设置是否锁定屏幕方向
100 | * @param isLock
101 | * @return
102 | */
103 | public String isLockRotation(boolean isLock){
104 | try {
105 | return context.exec(cmd.setLockRotation(true));
106 | } catch (IOException e) {
107 | e.printStackTrace();
108 | }
109 |
110 | return "";
111 | }
112 |
113 | /**
114 | * 获取电池信息
115 | *
116 | * Current Battery Service state:
117 | * AC powered: false
118 | * USB powered: true
119 | * Wireless powered: false
120 | * status: 2
121 | * health: 2
122 | * present: true
123 | * level: 44 //剩余电量
124 | * scale: 100 //最大电量
125 | * voltage: 3872
126 | * temperature: 280
127 | * technology: Li-poly
128 | *
129 | * @return
130 | */
131 | public String getBatteryInfo(){
132 | try {
133 | return context.exec(cmd.getBatteryInfo());
134 | } catch (IOException e) {
135 | e.printStackTrace();
136 | }
137 |
138 | return "";
139 | }
140 |
141 |
142 |
143 | public String getCPUInfo(){
144 | try {
145 | return context.exec(cmd.cpuInfo());
146 | } catch (IOException e) {
147 | e.printStackTrace();
148 | }
149 |
150 | return "";
151 | }
152 |
153 |
154 | }
155 |
--------------------------------------------------------------------------------
/ADBLib/src/com/adb/process/android/AndroidMemory.java:
--------------------------------------------------------------------------------
1 | package com.adb.process.android;
2 |
3 | import com.adb.command.android.AndroidMemoryCmd;
4 | import com.adb.process.Device;
5 |
6 | import java.io.IOException;
7 |
8 | public class AndroidMemory extends IAndroid{
9 |
10 | public static final String TRIM_HIDDEN = "HIDDEN";
11 | public static final String TRIM_RUNNING_MODERATE = "RUNNING_MODERATE";
12 | public static final String TRIM_BACKGROUND = "BACKGROUND";
13 | public static final String TRIM_RUNNING_LOW = "RUNNING_LOW";
14 | public static final String TRIM_MODERATE = "MODERATE";
15 | public static final String TRIM_RUNNING_CRITICAL = "RUNNING_CRITICAL";
16 | public static final String TRIM_COMPLETE = "COMPLETE";
17 |
18 | private AndroidMemoryCmd cmd = new AndroidMemoryCmd();
19 |
20 | public AndroidMemory(Device context) {
21 | super(context);
22 | }
23 |
24 | /**
25 | * adb shell am send-trim-memory
26 | *
27 | *向进程,发出 level=RUNNING_LOW 的收紧内存命令。
28 | * @param packageName
29 | */
30 | public boolean sendTrimMemory(String packageName,String trimLevel){
31 | String pid = context.managerOfApp().getPid(packageName);
32 |
33 | if (pid.isEmpty()){
34 | return false;
35 | }
36 |
37 | try {
38 | String reply = context.exec(cmd.sendTrimMemory(pid,trimLevel));
39 | return !reply.startsWith("error:");
40 | } catch (IOException e) {
41 | e.printStackTrace();
42 | }
43 |
44 | return false;
45 |
46 | }
47 |
48 | /**
49 | * 获取内存信息
50 | * @return
51 | *
52 | * MemTotal: 7806540 kB //设备总内存
53 | * MemFree: 613952 kB //空闲内存
54 | * MemAvailable: 2290648 kB
55 | * Buffers: 1904 kB
56 | * Cached: 1927524 kB
57 | * SwapCached: 9432 kB
58 | * Active: 3154940 kB
59 | * Inactive: 1491692 kB
60 | * Active(anon): 2269868 kB
61 | * Inactive(anon): 629908 kB
62 | * Active(file): 885072 kB
63 | * Inactive(file): 861784 kB
64 | * Unevictable: 156752 kB
65 | * Mlocked: 156752 kB
66 | * SwapTotal: 2097148 kB
67 | * SwapFree: 1332944 kB
68 | * Dirty: 736 kB
69 | * Writeback: 0 kB
70 | * AnonPages: 2867976 kB
71 | * Mapped: 1076824 kB
72 | * Shmem: 27512 kB
73 | * Slab: 564204 kB
74 | * SReclaimable: 173456 kB
75 | * SUnreclaim: 390748 kB
76 | * KernelStack: 88832 kB
77 | * PageTables: 142600 kB
78 | * NFS_Unstable: 0 kB
79 | * Bounce: 0 kB
80 | * WritebackTmp: 0 kB
81 | * CommitLimit: 6000416 kB
82 | * Committed_AS: 145256200 kB
83 | * VmallocTotal: 263061440 kB
84 | * VmallocUsed: 119732 kB
85 | * VmallocChunk: 0 kB
86 | * Percpu: 19968 kB
87 | * CmaTotal: 335872 kB
88 | * CmaFree: 0 kB
89 | *
90 | */
91 | public String memoryOfSystem(){
92 | try {
93 | return context.exec(cmd.memoryOfSystem());
94 | } catch (IOException e) {
95 | e.printStackTrace();
96 | }
97 |
98 | return "";
99 | }
100 |
101 | /**
102 | * 获取内存占用大的前 num 个进程
103 | * @return
104 | */
105 | public String memoryTop(int num){
106 | try{
107 | return context.exec(cmd.memoryTop(num));
108 | }catch (Exception e){
109 | e.printStackTrace();
110 | }
111 |
112 | return "";
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/ADBLib/src/com/adb/process/android/AndroidNetwork.java:
--------------------------------------------------------------------------------
1 | package com.adb.process.android;
2 |
3 | import com.adb.command.android.AndroidNetworkCmd;
4 | import com.adb.process.Device;
5 |
6 | import java.io.IOException;
7 |
8 | public class AndroidNetwork extends IAndroid {
9 |
10 | AndroidNetworkCmd cmd = new AndroidNetworkCmd();
11 |
12 | public AndroidNetwork(Device androidCtrl) {
13 | super(androidCtrl);
14 | }
15 |
16 | public String ping(String url,int count,boolean isSynPrint){
17 | try {
18 | String c = cmd.ping(url,count);
19 |
20 | if (isSynPrint){
21 | context.execAPrint(c);
22 | }else{
23 | context.exec(c);
24 | }
25 |
26 | } catch (IOException e) {
27 | e.printStackTrace();
28 | }
29 |
30 | return "";
31 | }
32 |
33 | /**
34 | * 网络连接状态
35 | * @return
36 | */
37 | public String connectivity(){
38 | try {
39 | return context.exec(cmd.connectivity());
40 | } catch (IOException e) {
41 | e.printStackTrace();
42 | }
43 | return "";
44 | }
45 |
46 | /**
47 | * 网络策略
48 | * @return
49 | */
50 | public String netPolicy(){
51 | try {
52 | return context.exec(cmd.netPolicy());
53 | } catch (IOException e) {
54 | e.printStackTrace();
55 | }
56 | return "";
57 | }
58 |
59 | /**
60 | * 网络状态
61 | * @return
62 | */
63 | public String netStatus(){
64 | try {
65 | return context.exec(cmd.netStatus());
66 | } catch (IOException e) {
67 | e.printStackTrace();
68 | }
69 | return "";
70 | }
71 |
72 | /**
73 | * 网络管理
74 | * @return
75 | */
76 | public String networkManagement(){
77 | try {
78 | return context.exec(cmd.networkManagement());
79 | } catch (IOException e) {
80 | e.printStackTrace();
81 | }
82 | return "";
83 | }
84 |
85 | public String netcfg(){
86 | try {
87 | return context.exec(cmd.netcfg());
88 | }catch (Exception e){
89 | e.printStackTrace();
90 | }
91 |
92 | return "";
93 | }
94 |
95 | /**
96 | * 打开/关闭 WIFI
97 | * @param isOpen
98 | * @return
99 | */
100 | public String setWifiSwitch(boolean isOpen){
101 | try {
102 | return context.exec(cmd.setWifiSwitch(isOpen));
103 | } catch (IOException e) {
104 | e.printStackTrace();
105 | }
106 |
107 | return "";
108 | }
109 |
110 | /**
111 | * (如4G通讯)流量开关
112 | * @param isOpen
113 | * @return
114 | */
115 | public String setNetSwitch(boolean isOpen) {
116 | try {
117 | return context.exec(cmd.setNetSwitch(isOpen));
118 | } catch (IOException e) {
119 | e.printStackTrace();
120 | }
121 |
122 | return "";
123 | }
124 |
125 | /**
126 | * 通讯模块及WIFI均为正常打开状态下,是否WIFI优先
127 | * @param isPreferWifi true:Wifi优先,false:4G通讯优先
128 | * @return
129 | */
130 | public String isPreferWifi(boolean isPreferWifi){
131 | try {
132 | return context.exec(cmd.isPreferWifi(isPreferWifi));
133 | } catch (IOException e) {
134 | e.printStackTrace();
135 | }
136 |
137 | return "";
138 | }
139 |
140 | /**
141 | * 获取设备IP
142 | * @return
143 | */
144 | public String getLocalAddress() {
145 | try {
146 | return context.exec(cmd.getLocalAddress());
147 | } catch (IOException e) {
148 | e.printStackTrace();
149 | }
150 |
151 | return "";
152 | }
153 |
154 |
155 | }
156 |
--------------------------------------------------------------------------------
/ADBLib/src/com/adb/process/android/AndroidSystem.java:
--------------------------------------------------------------------------------
1 | package com.adb.process.android;
2 |
3 | import com.adb.command.android.AndroidSystemCmd;
4 | import com.adb.process.Device;
5 |
6 | import java.io.IOException;
7 |
8 | /**
9 | * C:\Users\admin>adb shell getprop
10 | * [DEVICE_PROVISIONED]: [1]
11 | * [aaudio.hw_burst_min_usec]: [2000]
12 | * [aaudio.mmap_exclusive_policy]: [2]
13 | * [aaudio.mmap_policy]: [1]
14 | * [af.fast_track_multiplier]: [1]
15 | * [audio.deep_buffer.media]: [true]
16 | * [audio.offload.buffer.size.kb]: [32]
17 | * [audio.offload.gapless.enabled]: [true]
18 | * [audio.offload.min.duration.secs]: [30]
19 | * [audio.offload.video]: [true]
20 | * [audio.sys.mute.latency.factor]: [2]
21 | * [audio.sys.noisy.broadcast.delay]: [500]
22 | * [audio.sys.offload.pstimeout.secs]: [3]
23 | * [audio.sys.routing.latency]: [0]
24 | * [av.offload.enable]: [true]
25 | * [cache.trigger]: [1]
26 | * [camera.disable_zsl_mode]: [true]
27 | * [config.disable_rtt]: [true]
28 | * [dalvik.vm.appimageformat]: [lz4]
29 | * [dalvik.vm.bg-dex2oat-threads]: [8]
30 | * [dalvik.vm.boot-dex2oat-threads]: [6]
31 | * [dalvik.vm.dex2oat-Xms]: [64m]
32 | * [dalvik.vm.dex2oat-Xmx]: [512m]
33 | * [dalvik.vm.dex2oat-max-image-block-size]: [524288]
34 | * [dalvik.vm.dex2oat-minidebuginfo]: [true]
35 | * [dalvik.vm.dex2oat-resolve-startup-strings]: [true]
36 | * [dalvik.vm.dex2oat-threads]: [6]
37 | * [dalvik.vm.dexopt.secondary]: [true]
38 | * [dalvik.vm.heapgrowthlimit]: [256m]
39 | * [dalvik.vm.heapmaxfree]: [8m]
40 | * [dalvik.vm.heapminfree]: [512k]
41 | * [dalvik.vm.heapsize]: [512m]
42 | * [dalvik.vm.heapstartsize]: [8m]
43 | * [dalvik.vm.heaptargetutilization]: [0.75]
44 | * [dalvik.vm.image-dex2oat-Xms]: [64m]
45 | * [dalvik.vm.image-dex2oat-Xmx]: [64m]
46 | * [dalvik.vm.isa.arm.features]: [default]
47 | * [dalvik.vm.isa.arm.variant]: [cortex-a75]
48 | * [dalvik.vm.isa.arm64.features]: [default]
49 | * [dalvik.vm.isa.arm64.variant]: [kryo300]
50 | * [dalvik.vm.minidebuginfo]: [true]
51 | * [dalvik.vm.usejit]: [true]
52 | * [dalvik.vm.usejitprofiles]: [true]
53 | * [debug.atrace.tags.enableflags]: [0]
54 | * [debug.egl.hw]: [0]
55 | * [debug.force_rtl]: [false]
56 | * [debug.mdpcomp.logs]: [0]
57 | * [debug.media.video.frc]: [false]
58 | * [debug.media.video.vpp]: [false]
59 | * [debug.media.vpp.enable]: [true]
60 | * [debug.power.monitor_tools]: [true]
61 | * [debug.sf.disable_backpressure]: [1]
62 | * [debug.sf.early_app_phase_offset_ns]: [500000]
63 | * [debug.sf.early_gl_app_phase_offset_ns]: [15000000]
64 | * [debug.sf.early_gl_phase_offset_ns]: [3000000]
65 | * [debug.sf.early_phase_offset_ns]: [500000]
66 | * [debug.sf.enable_gl_backpressure]: [1]
67 | * [debug.sf.enable_hwc_vds]: [1]
68 | * [debug.sf.high_fps_early_gl_phase_offset_ns]: [6500000]
69 | * [debug.sf.high_fps_early_phase_offset_ns]: [6100000]
70 | * [debug.sf.high_fps_late_app_phase_offset_ns]: [1000000]
71 | * [debug.sf.hw]: [0]
72 | * [debug.sf.latch_unsignaled]: [1]
73 | * [debug.sf.phase_offset_threshold_for_next_vsync_ns]: [6100000]
74 | * [debug.stagefright.ccodec]: [1]
75 | * [debug.stagefright.omx_default_rank]: [0]
76 | * [debug.stagefright.omx_default_rank.sw-audio]: [1]
77 | * [dev.bootcomplete]: [1]
78 | * [dev.mnt.blk.cache]: [sda]
79 | * [dev.mnt.blk.cust]: [sda]
80 | * [dev.mnt.blk.data]: [dm-8]
81 | * [dev.mnt.blk.dev.logfs]: [sda]
82 | * [dev.mnt.blk.metadata]: [sda]
83 | * [dev.mnt.blk.mnt.vendor.persist]: [sda]
84 | * [dev.mnt.blk.mnt.vendor.spunvm]: [sde]
85 | * [dev.mnt.blk.odm]: [dm-7]
86 | * [dev.mnt.blk.product]: [dm-5]
87 | * [dev.mnt.blk.root]: [dm-4]
88 | * [dev.mnt.blk.vendor]: [dm-6]
89 | * [dev.mnt.blk.vendor.bt_firmware]: [sde]
90 | * [dev.mnt.blk.vendor.dsp]: [sde]
91 | * [dev.mnt.blk.vendor.firmware_mnt]: [sde]
92 | * [dev.pm.dyn_samplingrate]: [1]
93 | * [drm.service.enabled]: [true]
94 | * [events.cpu]: [true]
95 | * [gsm.apn.sim.operator.numeric]: [,]
96 | * [gsm.current.phone-type]: [1,1]
97 | * [gsm.defaultpdpcontext.active]: [false]
98 | * [gsm.network.type]: [HSPAP,Unknown]
99 | * [gsm.operator.alpha]: [中国联通]
100 | * [gsm.operator.iso-country]: [cn]
101 | * [gsm.operator.isroaming]: [false,false]
102 | * [gsm.operator.numeric]: [46001]
103 | * [gsm.operator.orig.alpha]: [CHN-UNICOM]
104 | * [gsm.sim.operator.alpha]: [中国联通]
105 | * [gsm.sim.operator.iso-country]: [cn]
106 | * [gsm.sim.operator.numeric]: [46001]
107 | * [gsm.sim.operator.orig.alpha]: [CHN-UNICOM]
108 | * [gsm.sim.state]: [LOADED,ABSENT]
109 | * [gsm.version.baseband]: [r3.9326.2-0518_2337_8c9ed8e,r3.9326.2-0518_2337_8c9ed8e]
110 | * [gsm.version.ril-impl]: [Qualcomm RIL 1.0]
111 | * [hwservicemanager.ready]: [true]
112 | * [init.svc.adbd]: [running]
113 | * [init.svc.alarm-hal-1-0]: [running]
114 | * [init.svc.apexd]: [running]
115 | * [init.svc.apexd-bootstrap]: [stopped]
116 | * [init.svc.ashmemd]: [running]
117 | * [init.svc.audioserver]: [running]
118 | * [init.svc.audioshell_service]: [stopped]
119 | * [init.svc.batteryd]: [running]
120 | * [init.svc.batterysecret]: [running]
121 | * [init.svc.bootanim]: [stopped]
122 | * [init.svc.bpfloader]: [stopped]
123 | * [init.svc.cameraserver]: [running]
124 | * [init.svc.charge_logger]: [running]
125 | * [init.svc.checknv]: [stopped]
126 | * [init.svc.citsensor-hal-1-1]: [running]
127 | * [init.svc.cnss-daemon]: [running]
128 | * [init.svc.cnss_diag]: [running]
129 | * [init.svc.crashdata-sh]: [stopped]
130 | * [init.svc.display-color-hal-1-0]: [running]
131 | * [init.svc.displaycount]: [running]
132 | * [init.svc.displayfeature]: [running]
133 | * [init.svc.displayfeature-hal-1-0]: [running]
134 | * [init.svc.dpmQmiMgr]: [running]
135 | * [init.svc.dpmd]: [running]
136 | * [init.svc.drm]: [running]
137 | * [init.svc.eid-1-0]: [running]
138 | * [init.svc.fdpp]: [running]
139 | * [init.svc.feature_enabler_client]: [running]
140 | * [init.svc.flash_recovery]: [stopped]
141 | * [init.svc.gatekeeper-1-0]: [running]
142 | * [init.svc.gatekeeperd]: [running]
143 | * [init.svc.gnss_service]: [running]
144 | * [init.svc.gpu]: [running]
145 | * [init.svc.gsid]: [stopped]
146 | * [init.svc.health-hal-2-0]: [running]
147 | * [init.svc.hidl_memory]: [running]
148 | * [init.svc.hwservicemanager]: [running]
149 | * [init.svc.idmap2d]: [running]
150 | * [init.svc.incidentd]: [running]
151 | * [init.svc.installd]: [running]
152 | * [init.svc.iop-hal-2-0]: [running]
153 | * [init.svc.iorapd]: [stopped]
154 | * [init.svc.irsc_util]: [stopped]
155 | * [init.svc.keymaster-4-0]: [running]
156 | * [init.svc.keystore]: [running]
157 | * [init.svc.lmkd]: [running]
158 | * [init.svc.loc_launcher]: [running]
159 | * [init.svc.logd]: [running]
160 | * [init.svc.logd-auditctl]: [stopped]
161 | * [init.svc.logd-reinit]: [stopped]
162 | * [init.svc.mcd_init]: [stopped]
163 | * [init.svc.mcd_service]: [running]
164 | * [init.svc.mdnsd]: [running]
165 | * [init.svc.media]: [running]
166 | * [init.svc.media.swcodec]: [running]
167 | * [init.svc.mediadrm]: [running]
168 | * [init.svc.mediaextractor]: [running]
169 | * [init.svc.mediametrics]: [running]
170 | * [init.svc.mi_ic]: [stopped]
171 | * [init.svc.mi_thermald]: [running]
172 | * [init.svc.millet_binder]: [running]
173 | * [init.svc.millet_pkg]: [running]
174 | * [init.svc.millet_sig]: [running]
175 | * [init.svc.minidump64]: [stopped]
176 | * [init.svc.mioob-hal-1-0]: [running]
177 | * [init.svc.miui-early-boot]: [stopped]
178 | * [init.svc.miuibooster]: [running]
179 | * [init.svc.mlid]: [running]
180 | * [init.svc.modemservice]: [running]
181 | * [init.svc.mqsasd]: [running]
182 | * [init.svc.netd]: [running]
183 | * [init.svc.neuralnetworks_hal_service]: [running]
184 | * [init.svc.nqnfc_1_2_hal_service]: [running]
185 | * [init.svc.nqnfcinfo]: [stopped]
186 | * [init.svc.objectTracker]: [running]
187 | * [init.svc.panel-info-sh]: [stopped]
188 | * [init.svc.panorama]: [running]
189 | * [init.svc.perf-hal-2-0]: [running]
190 | * [init.svc.poweroffm64]: [stopped]
191 | * [init.svc.qcom-c_core-sh]: [stopped]
192 | * [init.svc.qcom-c_main-sh]: [stopped]
193 | * [init.svc.qcom-post-boot]: [stopped]
194 | * [init.svc.qcom-sh]: [stopped]
195 | * [init.svc.qseecom-service]: [running]
196 | * [init.svc.qseelogd]: [stopped]
197 | * [init.svc.qspmhal]: [running]
198 | * [init.svc.qspmsvc]: [running]
199 | * [init.svc.qteeconnector-hal-1-0]: [running]
200 | * [init.svc.qti_esepowermanager_service]: [running]
201 | * [init.svc.secureelement-hal]: [running]
202 | * [init.svc.sensorscal-hal-1-0]: [running]
203 | * [init.svc.servicemanager]: [running]
204 | * [init.svc.setlockstate]: [stopped]
205 | * [init.svc.shelld]: [running]
206 | * [init.svc.sla-service-hal-1-0]: [running]
207 | * [init.svc.soter-1-0]: [running]
208 | * [init.svc.spu_service]: [running]
209 | * [init.svc.statsd]: [running]
210 | * [init.svc.storaged]: [running]
211 | * [init.svc.surfaceflinger]: [running]
212 | * [init.svc.system_perf_init]: [stopped]
213 | * [init.svc.system_suspend]: [running]
214 | * [init.svc.tcpdump]: [running]
215 | * [init.svc.thermal-engine]: [running]
216 | * [init.svc.time_daemon]: [running]
217 | * [init.svc.tombstoned]: [running]
218 | * [init.svc.touchfeature-hal-1-0]: [running]
219 | * [init.svc.tui_comm-1-0]: [running]
220 | * [init.svc.ueventd]: [running]
221 | * [init.svc.urlhook]: [running]
222 | * [init.svc.usbd]: [stopped]
223 | * [init.svc.vendor-sensor-sh]: [stopped]
224 | * [init.svc.vibratorfeature-hal-1-0]: [running]
225 | * [init.svc.vndservicemanager]: [running]
226 | * [init.svc.vold]: [running]
227 | * [init.svc.wait_for_keymaster]: [stopped]
228 | * [init.svc.wfdhdcphalservice]: [running]
229 | * [init.svc.wfdvndservice]: [running]
230 | * [init.svc.wifi_mdlog_start]: [running]
231 | * [init.svc.wificond]: [running]
232 | * [init.svc.wifidisplayhalservice]: [running]
233 | * [init.svc.wireless-hal-1-0]: [running]
234 | * [init.svc.wpa_supplicant]: [running]
235 | * [init.svc.zygote]: [running]
236 | * [init.svc.zygote_secondary]: [running]
237 | * [keyguard.no_require_sim]: [true]
238 | * [log.tag.APM_AudioPolicyManager]: [D]
239 | * [log.tag.AudioPolicyManagerCustom]: [D]
240 | * [log.tag.stats_log]: [I]
241 | * [mcd.extra.params]: []
242 | * [media.aac_51_output_enabled]: [true]
243 | * [media.settings.xml]: [/vendor/etc/media_profiles_vendor.xml]
244 | * [media.stagefright.enable-aac]: [true]
245 | * [media.stagefright.enable-fma2dp]: [true]
246 | * [media.stagefright.enable-http]: [true]
247 | * [media.stagefright.enable-player]: [true]
248 | * [media.stagefright.enable-qcp]: [true]
249 | * [media.stagefright.enable-scan]: [true]
250 | * [media.stagefright.thumbnail.prefer_hw_codecs]: [true]
251 | * [miui.usb.dialog]: [1]
252 | * [mm.enable.smoothstreaming]: [true]
253 | * [mmp.enable.3g2]: [true]
254 | * [net.bt.name]: [Android]
255 | * [net.hostname]: [Mi10-xiaomishouji]
256 | * [net.qtaguid_enabled]: [1]
257 | * [net.tcp.2g_init_rwnd]: [10]
258 | * [net.tcp.default_init_rwnd]: [60]
259 | * [nfc.fw.downloadmode_force]: [0]
260 | * [nfc.initialized]: [true]
261 | * [persist.audio.button_jack.profile]: [volume]
262 | * [persist.audio.button_jack.switch]: [0]
263 | * [persist.audio.fluence.speaker]: [true]
264 | * [persist.audio.fluence.voicecall]: [true]
265 | * [persist.audio.fluence.voicerec]: [false]
266 | * [persist.audio.headset.plug.status]: [off]
267 | * [persist.backup.ntpServer]: ["0.pool.ntp.org"]
268 | * [persist.camera.privapp.list]: [org.codeaurora.snapcam]
269 | * [persist.dalvik.vm.dex2oat-threads]: [6]
270 | * [persist.data.df.agg.dl_pkt]: [10]
271 | * [persist.data.df.agg.dl_size]: [4096]
272 | * [persist.data.df.dev_name]: [rmnet_usb0]
273 | * [persist.data.df.dl_mode]: [5]
274 | * [persist.data.df.iwlan_mux]: [9]
275 | * [persist.data.df.mux_count]: [8]
276 | * [persist.data.df.ul_mode]: [5]
277 | * [persist.data.wda.enable]: [true]
278 | * [persist.debug.coresight.config]: [stm-events]
279 | * [persist.debug.wfd.enable]: [1]
280 | * [persist.enable_task_snapshots]: [false]
281 | * [persist.fuse_sdcard]: [true]
282 | * [persist.logd.size.crash]: [1M]
283 | * [persist.logd.size.radio]: [4M]
284 | * [persist.logd.size.system]: [4M]
285 | * [persist.miui.density_v2]: [440]
286 | * [persist.mm.enable.prefetch]: [true]
287 | * [persist.radio.autosms_cell1]: [114825989]
288 | * [persist.radio.autosms_cell2]: []
289 | * [persist.radio.autosms_dmok]: [yes]
290 | * [persist.radio.autosms_provision]: [true]
291 | * [persist.radio.default.data]: [0]
292 | * [persist.radio.default.voice]: [-1]
293 | * [persist.radio.display_mipi_cur]: [0]
294 | * [persist.radio.display_mipi_init_num]: [13]
295 | * [persist.radio.display_mipi_set_num]: [0]
296 | * [persist.radio.flexmap_type]: [none]
297 | * [persist.radio.goldencopy_flag]: [true]
298 | * [persist.radio.imei]: [866924048127116]
299 | * [persist.radio.imei1]: [866924048127116]
300 | * [persist.radio.imei2]: [866924048127124]
301 | * [persist.radio.meid]: [99001592456353]
302 | * [persist.radio.mtbf_flag]: [false]
303 | * [persist.radio.multisim.config]: [dsds]
304 | * [persist.radio.operating_mode]: [0]
305 | * [persist.radio.skhwc_matchres]: [MATCH]
306 | * [persist.radio.speech_codec]: []
307 | * [persist.rcs.supported]: [0]
308 | * [persist.rild.nitz_long_ons_0]: []
309 | * [persist.rild.nitz_long_ons_1]: []
310 | * [persist.rild.nitz_long_ons_2]: []
311 | * [persist.rild.nitz_long_ons_3]: []
312 | * [persist.rild.nitz_plmn]: []
313 | * [persist.rild.nitz_short_ons_0]: []
314 | * [persist.rild.nitz_short_ons_1]: []
315 | * [persist.rild.nitz_short_ons_2]: []
316 | * [persist.rild.nitz_short_ons_3]: []
317 | * [persist.rmnet.data.enable]: [true]
318 | * [persist.security.adbinput]: [1]
319 | * [persist.security.adbinstall]: [1]
320 | * [persist.sys.ai_preload_cloud]: [0]
321 | * [persist.sys.boot.reason]: []
322 | * [persist.sys.boot.reason.history]: [cold,1599062849
323 | * cold,1598614826
324 | * shutdown,userrequested,1596271454
325 | * cold,1592989611]
326 | * [persist.sys.dalvik.vm.lib.2]: [libart.so]
327 | * [persist.sys.device_provisioned]: [1]
328 | * [persist.sys.displayinset.top]: [0]
329 | * [persist.sys.enable_inputopts]: [true]
330 | * [persist.sys.enable_ioprefetch]: [false]
331 | * [persist.sys.enable_miui_booster]: [1]
332 | * [persist.sys.enable_pinfile]: [true]
333 | * [persist.sys.eyecare_cache]: [8]
334 | * [persist.sys.force_sw_gles]: [1]
335 | * [persist.sys.gps.fence]: [true]
336 | * [persist.sys.gps.lpp]: [0]
337 | * [persist.sys.gz.enable]: [true]
338 | * [persist.sys.hang]: [false]
339 | * [persist.sys.hang.logname]: []
340 | * [persist.sys.hardcoder.name]: [miui_booster]
341 | * [persist.sys.isolated_storage]: [true]
342 | * [persist.sys.labtest_flag]: [false]
343 | * [persist.sys.locale]: [zh-CN]
344 | * [persist.sys.mcd_config_file]: [/system/etc/mcd_default.conf]
345 | * [persist.sys.mem_cgated]: [1]
346 | * [persist.sys.mem_fgated]: [1]
347 | * [persist.sys.memctrl]: [on]
348 | * [persist.sys.mibridge_auth_uids]: [1000]
349 | * [persist.sys.miconnect.running]: [1]
350 | * [persist.sys.mispeed_auth_uids]: [10250]
351 | * [persist.sys.mitalk.enable]: [true]
352 | * [persist.sys.miuibooster.name]: [miui_booster]
353 | * [persist.sys.notification_rank]: [3]
354 | * [persist.sys.notification_ver]: [1]
355 | * [persist.sys.opt_accessibility]: [false]
356 | * [persist.sys.qseelogd]: [true]
357 | * [persist.sys.released]: [true]
358 | * [persist.sys.sc_allow_conn]: [true]
359 | * [persist.sys.sf.color_mode]: [0]
360 | * [persist.sys.sf.color_saturation]: [1.0]
361 | * [persist.sys.sf.native_mode]: [258]
362 | * [persist.sys.shutdown_state]: [2]
363 | * [persist.sys.smartcover_mode]: [0]
364 | * [persist.sys.strictmode.disable]: [true]
365 | * [persist.sys.support_detect_fc]: [false]
366 | * [persist.sys.support_fakecell]: [true]
367 | * [persist.sys.task_isolation]: [true]
368 | * [persist.sys.timezone]: [Asia/Shanghai]
369 | * [persist.sys.usb.config]: [adb]
370 | * [persist.sys.usb.ffbm-02.func]: [adb]
371 | * [persist.sys.watchdog_enhanced]: [true]
372 | * [persist.sys.wfd.virtual]: [0]
373 | * [persist.timed.enable]: [true]
374 | * [persist.vendor.camera.frontMain.vendorID]: [01]
375 | * [persist.vendor.camera.mi.dualcal.detail]: [0]
376 | * [persist.vendor.camera.mi.dualcal.state]: [0]
377 | * [persist.vendor.camera.mi.module.info]: [back_main=s5khmx;back_ultra=ov13b10;back_depth=gc02m1_FF;]
378 | * [persist.vendor.camera.mi.module.infoext]: [front_main=s5k3t2;back_macro2x=gc02m1;]
379 | * [persist.vendor.camera.rearDepth.vendorID]: [01]
380 | * [persist.vendor.camera.rearMacro2x.vendorID]: [01]
381 | * [persist.vendor.camera.rearMain.vendorID]: [03]
382 | * [persist.vendor.camera.rearUltra.vendorID]: [01]
383 | * [persist.vendor.dc_backlight.enable]: [false]
384 | * [persist.vendor.dc_backlight.threshold]: [440]
385 | * [persist.vendor.df.extcolor.proc]: [0]
386 | * [persist.vendor.dfps.level]: [90]
387 | * [persist.vendor.dpm.feature]: [1]
388 | * [persist.vendor.fod.modified.dc_status]: [false]
389 | * [persist.vendor.max.brightness]: [500]
390 | * [persist.vendor.power.dfps.level]: [0]
391 | * [persist.vendor.sys.cyclecount]: [43]
392 | * [persist.vendor.sys.fp.expolevel]: [0x80]
393 | * [persist.vendor.sys.fp.fod.large_field]: [0]
394 | * [persist.vendor.sys.fp.fod.location.X_Y]: [441,1808]
395 | * [persist.vendor.sys.fp.fod.size.width_height]: [197,197]
396 | * [persist.vendor.sys.fp.info]: [0xcf00004515000000]
397 | * [persist.vendor.sys.fp.module]: [Ofilm]
398 | * [persist.vendor.sys.fp.mulexposupport]: [0]
399 | * [persist.vendor.sys.fp.uid]: [47413254-37372E01-137C751A-76E70000]
400 | * [persist.vendor.sys.fp.vendor]: [goodix_fod]
401 | * [persist.vendor.sys.pay.fido]: [0058#0001]
402 | * [persist.vendor.sys.pay.ifaa]: [1]
403 | * [persist.vendor.sys.prechargefull]: [4799000]
404 | * [persist.vendor.sys.preresistance]: [62255]
405 | * [persist.vendor.sys.provision.status]: [true]
406 | * [persist.vm.stackdump.threshold]: [0]
407 | * [pm.dexopt.ab-ota]: [speed-profile]
408 | * [pm.dexopt.bg-dexopt]: [speed-profile]
409 | * [pm.dexopt.boot]: [verify]
410 | * [pm.dexopt.first-boot]: [quicken]
411 | * [pm.dexopt.inactive]: [verify]
412 | * [pm.dexopt.install]: [speed-profile]
413 | * [pm.dexopt.is_upgrade]: [false]
414 | * [pm.dexopt.shared]: [speed]
415 | * [qcom.hw.aac.encoder]: [true]
416 | * [qemu.hw.mainkeys]: [0]
417 | * [radio.dataroaming.enable.suffix.subid]: [true]
418 | * [ril.ecclist]: [112,000,08,110,120,119,118,122,911,999]
419 | * [ril.ecclist1]: [112,000,08,110,120,119,118,122,911,999]
420 | * [ril.fake_bs_flag0]: [FALSE:0]
421 | * [ril.limit_service_mnc]: [WCDMA_460]
422 | * [ril.mcc.mnc0]: [46001]
423 | * [ril.mcc.mnc1]: []
424 | * [ril.subscription.types]: [NV,RUIM]
425 | * [rild.libpath]: [/vendor/lib64/libril-qc-hal-qmi.so]
426 | * [ro.actionable_compatible_property.enabled]: [true]
427 | * [ro.adb.secure]: [1]
428 | * [ro.af.client_heap_size_kbyte]: [7168]
429 | * [ro.allow.mock.location]: [0]
430 | * [ro.apex.updatable]: [true]
431 | * [ro.audio.monitorRotation]: [true]
432 | * [ro.baseband]: [mdm]
433 | * [ro.bluetooth.library_name]: [libbluetooth_qti.so]
434 | * [ro.board.platform]: [kona]
435 | * [ro.boot.avb_version]: [1.1]
436 | * [ro.boot.baseband]: [mdm]
437 | * [ro.boot.boot_devices]: [soc/1d84000.ufshc]
438 | * [ro.boot.bootdevice]: [1d84000.ufshc]
439 | * [ro.boot.bootreason]: [cold]
440 | * [ro.boot.console]: [ttyMSM0]
441 | * [ro.boot.cpuid]: [0xffe0dfe8]
442 | * [ro.boot.dp]: [0x0]
443 | * [ro.boot.dtb_idx]: [0]
444 | * [ro.boot.dtbo_idx]: [8]
445 | * [ro.boot.dynamic_partitions]: [true]
446 | * [ro.boot.flash.locked]: [1]
447 | * [ro.boot.hardware]: [qcom]
448 | * [ro.boot.hwc]: [CN]
449 | * [ro.boot.hwlevel]: [MP]
450 | * [ro.boot.hwversion]: [2.9.0]
451 | * [ro.boot.keymaster]: [1]
452 | * [ro.boot.memcg]: [1]
453 | * [ro.boot.oled_panel_id]: [0B]
454 | * [ro.boot.oled_pmic_id]: [0B]
455 | * [ro.boot.oled_wp]: [01f3020909030104]
456 | * [ro.boot.profile_vendor_id]: [0A]
457 | * [ro.boot.ramdump]: [disable]
458 | * [ro.boot.secureboot]: [1]
459 | * [ro.boot.serialno]: [c447b522]
460 | * [ro.boot.usbcontroller]: [a600000.dwc3]
461 | * [ro.boot.vbmeta.avb_version]: [1.0]
462 | * [ro.boot.vbmeta.device_state]: [locked]
463 | * [ro.boot.vbmeta.digest]: [9cecfc12471a38ed3880ef414fbba06301c36e91be63da527bdf445833f4a8e3]
464 | * [ro.boot.vbmeta.hash_alg]: [sha256]
465 | * [ro.boot.vbmeta.invalidate_on_error]: [yes]
466 | * [ro.boot.vbmeta.size]: [9216]
467 | * [ro.boot.verifiedbootstate]: [green]
468 | * [ro.boot.veritymode]: [enforcing]
469 | * [ro.bootimage.build.date]: [Tue May 19 02:54:33 CST 2020]
470 | * [ro.bootimage.build.date.utc]: [1589828073]
471 | * [ro.bootimage.build.fingerprint]: [Xiaomi/umi/umi:10/QKQ1.191117.002/V11.0.25.0.QJBCNXM:user/release-keys]
472 | * [ro.bootloader]: [unknown]
473 | * [ro.bootmode]: [unknown]
474 | * [ro.build.ab_update]: [false]
475 | * [ro.build.characteristics]: [nosdcard]
476 | * [ro.build.date]: [Tue May 19 01:37:31 CST 2020]
477 | * [ro.build.date.utc]: [1589823451]
478 | * [ro.build.description]: [umi-user 10 QKQ1.191117.002 V11.0.25.0.QJBCNXM release-keys]
479 | * [ro.build.display.id]: [QKQ1.191117.002 test-keys]
480 | * [ro.build.fingerprint]: [Xiaomi/umi/umi:10/QKQ1.191117.002/V11.0.25.0.QJBCNXM:user/release-keys]
481 | * [ro.build.flavor]: [qssi-user]
482 | * [ro.build.hardware.version]: [V1]
483 | * [ro.build.host]: [c5-miui-ota-bd071.bj]
484 | * [ro.build.id]: [QKQ1.191117.002]
485 | * [ro.build.keys]: [test-keys]
486 | * [ro.build.product]: [umi]
487 | * [ro.build.system_root_image]: [false]
488 | * [ro.build.tags]: [release-keys]
489 | * [ro.build.type]: [user]
490 | * [ro.build.user]: [builder]
491 | * [ro.build.version.all_codenames]: [REL]
492 | * [ro.build.version.base_os]: []
493 | * [ro.build.version.codename]: [REL]
494 | * [ro.build.version.incremental]: [V11.0.25.0.QJBCNXM]
495 | * [ro.build.version.min_supported_target_sdk]: [23]
496 | * [ro.build.version.preview_sdk]: [0]
497 | * [ro.build.version.preview_sdk_fingerprint]: [REL]
498 | * [ro.build.version.release]: [10]
499 | * [ro.build.version.sdk]: [29]
500 | * [ro.build.version.security_patch]: [2020-04-01]
501 | * [ro.carrier]: [unknown]
502 | * [ro.carrier.name]: [ct]
503 | * [ro.com.android.dataroaming]: [false]
504 | * [ro.com.android.mobiledata]: [false]
505 | * [ro.config.alarm_alert]: [Alarm_Classic.ogg]
506 | * [ro.config.elder-ringtone]: [Angel.mp3]
507 | * [ro.config.gnss.support]: [true]
508 | * [ro.config.media_vol_default]: [10]
509 | * [ro.config.notification_sound]: [pixiedust.ogg]
510 | * [ro.config.ringtone]: [Ring_Synth_04.ogg]
511 | * [ro.config.sms_delivered_sound]: [MessageComplete.ogg]
512 | * [ro.config.sms_received_sound]: [FadeIn.ogg]
513 | * [ro.config.vc_call_vol_steps]: [11]
514 | * [ro.control_privapp_permissions]: [enforce]
515 | * [ro.crypto.allow_encrypt_override]: [true]
516 | * [ro.crypto.state]: [encrypted]
517 | * [ro.crypto.type]: [file]
518 | * [ro.crypto.volume.filenames_mode]: [aes-256-cts]
519 | * [ro.dalvik.vm.native.bridge]: [0]
520 | * [ro.debuggable]: [0]
521 | * [ro.device_owner]: [false]
522 | * [ro.fota.oem]: [Xiaomi]
523 | * [ro.frp.pst]: [/dev/block/bootdevice/by-name/frp]
524 | * [ro.gfx.driver.0]: [com.xiaomi.ugd]
525 | * [ro.gfx.driver.1]: [com.qualcomm.qti.gpudrivers.sm8250.api29]
526 | * [ro.hardware]: [qcom]
527 | * [ro.hardware.egl]: [adreno]
528 | * [ro.hardware.fp.fod]: [true]
529 | * [ro.hardware.keystore_desede]: [true]
530 | * [ro.hardware.vulkan]: [adreno]
531 | * [ro.hwui.drop_shadow_cache_size]: [6]
532 | * [ro.hwui.gradient_cache_size]: [1]
533 | * [ro.hwui.layer_cache_size]: [48]
534 | * [ro.hwui.path_cache_size]: [32]
535 | * [ro.hwui.r_buffer_cache_size]: [8]
536 | * [ro.hwui.text_large_cache_height]: [1024]
537 | * [ro.hwui.text_large_cache_width]: [2048]
538 | * [ro.hwui.text_small_cache_height]: [1024]
539 | * [ro.hwui.text_small_cache_width]: [1024]
540 | * [ro.hwui.texture_cache_flushrate]: [0.4]
541 | * [ro.hwui.texture_cache_size]: [72]
542 | * [ro.hwui.use_vulkan]: []
543 | * [ro.iorapd.enable]: [false]
544 | * [ro.kernel.qemu.gles]: [0]
545 | * [ro.lmk.kill_heaviest_task]: [true]
546 | * [ro.lmk.use_minfree_levels]: [true]
547 | * [ro.logd.size]: [2M]
548 | * [ro.logd.size.stats]: [64K]
549 | * [ro.malloc.impl]: [jemalloc]
550 | * [ro.mi.development]: [false]
551 | * [ro.minui.pixel_format]: [RGBX_8888]
552 | * [ro.miui.build.region]: [cn]
553 | * [ro.miui.cust_hardware]: [V1]
554 | * [ro.miui.cust_variant]: [cn_chinatelecom]
555 | * [ro.miui.has_cust_partition]: [true]
556 | * [ro.miui.has_gmscore]: [1]
557 | * [ro.miui.has_handy_mode_sf]: [1]
558 | * [ro.miui.has_real_blur]: [1]
559 | * [ro.miui.has_security_keyboard]: [1]
560 | * [ro.miui.mcc]: [9460]
561 | * [ro.miui.mnc]: [9003]
562 | * [ro.miui.notch]: [1]
563 | * [ro.miui.pm.install.buffer.size]: [49152]
564 | * [ro.miui.pm.movedtodata.apps]: [com.google.android.apps.photos,com.google.android.apps.docs,com.google.android.music,com.google.android.videos,com.google.android.apps.tachyon]
565 | * [ro.miui.region]: [CN]
566 | * [ro.miui.restrict_imei]: [1]
567 | * [ro.miui.support_miui_ime_bottom]: [1]
568 | * [ro.miui.ui.fonttype]: [mipro]
569 | * [ro.miui.ui.version.code]: [9]
570 | * [ro.miui.ui.version.name]: [V11]
571 | * [ro.miui.version.code_time]: [1575475200]
572 | * [ro.netflix.bsp_rev]: [Q8250-19134-1]
573 | * [ro.nfc.port]: [I2C]
574 | * [ro.odm.build.date]: [Tue May 19 02:54:33 CST 2020]
575 | * [ro.odm.build.date.utc]: [1589828073]
576 | * [ro.odm.build.fingerprint]: [Xiaomi/umi/umi:10/QKQ1.191117.002/V11.0.25.0.QJBCNXM:user/release-keys]
577 | * [ro.oem_unlock_supported]: [1]
578 | * [ro.opengles.version]: [196610]
579 | * [ro.postinstall.fstab.prefix]: [/system]
580 | * [ro.product.board]: [umi]
581 | * [ro.product.brand]: [Xiaomi]
582 | * [ro.product.build.date]: [Tue May 19 01:37:31 CST 2020]
583 | * [ro.product.build.date.utc]: [1589823451]
584 | * [ro.product.build.fingerprint]: [qti/qssi/qssi:10/QKQ1.191117.002/V11.0.25.0.QJBCNXM:user/release-keys]
585 | * [ro.product.build.id]: [QKQ1.191117.002]
586 | * [ro.product.build.tags]: [release-keys]
587 | * [ro.product.build.type]: [user]
588 | * [ro.product.build.version.incremental]: [V11.0.25.0.QJBCNXM]
589 | * [ro.product.build.version.release]: [10]
590 | * [ro.product.build.version.sdk]: [29]
591 | * [ro.product.cert]: [M2001J2C]
592 | * [ro.product.cpu.abi]: [arm64-v8a]
593 | * [ro.product.cpu.abilist]: [arm64-v8a,armeabi-v7a,armeabi]
594 | * [ro.product.cpu.abilist32]: [armeabi-v7a,armeabi]
595 | * [ro.product.cpu.abilist64]: [arm64-v8a]
596 | * [ro.product.cuptsm]: [XIAOMI|ESE|02|01]
597 | * [ro.product.device]: [umi]
598 | * [ro.product.first_api_level]: [29]
599 | * [ro.product.locale]: [zh-CN]
600 | * [ro.product.manufacturer]: [Xiaomi]
601 | * [ro.product.model]: [Mi 10]
602 | * [ro.product.name]: [umi]
603 | * [ro.product.odm.brand]: [Xiaomi]
604 | * [ro.product.odm.device]: [umi]
605 | * [ro.product.odm.manufacturer]: [Xiaomi]
606 | * [ro.product.odm.model]: [Mi 10]
607 | * [ro.product.odm.name]: [umi]
608 | * [ro.product.product.brand]: [qti]
609 | * [ro.product.product.device]: [qssi]
610 | * [ro.product.product.manufacturer]: [QUALCOMM]
611 | * [ro.product.product.model]: [qssi system image for arm64]
612 | * [ro.product.product.name]: [qssi]
613 | * [ro.product.property_source_order]: [odm,vendor,product,product_services,system]
614 | * [ro.product.system.brand]: [qti]
615 | * [ro.product.system.device]: [qssi]
616 | * [ro.product.system.manufacturer]: [QUALCOMM]
617 | * [ro.product.system.model]: [qssi system image for arm64]
618 | * [ro.product.system.name]: [qssi]
619 | * [ro.product.vendor.brand]: [Xiaomi]
620 | * [ro.product.vendor.device]: [umi]
621 | * [ro.product.vendor.manufacturer]: [Xiaomi]
622 | * [ro.product.vendor.model]: [Mi 10]
623 | * [ro.product.vendor.name]: [umi]
624 | * [ro.property_service.version]: [2]
625 | * [ro.qc.sdk.audio.fluencetype]: [none]
626 | * [ro.qc.sdk.audio.ssr]: [false]
627 | * [ro.revision]: [0]
628 | * [ro.ril.factory_id]: [1]
629 | * [ro.ril.miui.imei0]: [866924048127116]
630 | * [ro.ril.miui.imei1]: [866924048127124]
631 | * [ro.ril.nal]: []
632 | * [ro.ril.oem.imei]: [866924048127116]
633 | * [ro.ril.oem.imei1]: [866924048127116]
634 | * [ro.ril.oem.imei2]: [866924048127124]
635 | * [ro.ril.oem.meid]: [99001592456353]
636 | * [ro.ril.oem.psno]: [26902/20T501010]
637 | * [ro.ril.oem.sno]: [24023F021789]
638 | * [ro.ril.operator]: []
639 | * [ro.ril.region]: []
640 | * [ro.rom.zone]: [1]
641 | * [ro.secure]: [1]
642 | * [ro.secureboot.devicelock]: [1]
643 | * [ro.secureboot.lockstate]: [locked]
644 | * [ro.serialno]: [c447b522]
645 | * [ro.sf.lcd_density]: [440]
646 | * [ro.surface_flinger.has_HDR_display]: [true]
647 | * [ro.surface_flinger.has_wide_color_display]: [true]
648 | * [ro.surface_flinger.protected_contents]: [true]
649 | * [ro.surface_flinger.use_color_management]: [true]
650 | * [ro.surface_flinger.wcg_composition_dataspace]: [143261696]
651 | * [ro.system.build.date]: [Tue May 19 01:37:31 CST 2020]
652 | * [ro.system.build.date.utc]: [1589823451]
653 | * [ro.system.build.fingerprint]: [qti/qssi/qssi:10/QKQ1.191117.002/V11.0.25.0.QJBCNXM:user/release-keys]
654 | * [ro.system.build.id]: [QKQ1.191117.002]
655 | * [ro.system.build.tags]: [release-keys]
656 | * [ro.system.build.type]: [user]
657 | * [ro.system.build.version.incremental]: [V11.0.25.0.QJBCNXM]
658 | * [ro.system.build.version.release]: [10]
659 | * [ro.system.build.version.sdk]: [29]
660 | * [ro.telephony.call_ring.multiple]: [false]
661 | * [ro.telephony.default_cdma_sub]: [0]
662 | * [ro.telephony.default_network]: [22,22]
663 | * [ro.treble.enabled]: [true]
664 | * [ro.vendor.all_modes.colorpick_adjust]: [true]
665 | * [ro.vendor.bcbc.enable]: [true]
666 | * [ro.vendor.build.date]: [Tue May 19 02:54:33 CST 2020]
667 | * [ro.vendor.build.date.utc]: [1589828073]
668 | * [ro.vendor.build.fingerprint]: [Xiaomi/umi/umi:10/QKQ1.191117.002/V11.0.25.0.QJBCNXM:user/release-keys]
669 | * [ro.vendor.build.security_patch]: [2020-04-01]
670 | * [ro.vendor.cabc.enable]: [false]
671 | * [ro.vendor.colorpick_adjust]: [true]
672 | * [ro.vendor.df.effect.conflict]: [1]
673 | * [ro.vendor.dfps.enable]: [false]
674 | * [ro.vendor.display.default_fps]: [60]
675 | * [ro.vendor.display.type]: [oled]
676 | * [ro.vendor.fod.dimlayer.enable]: [true]
677 | * [ro.vendor.gcp.enable]: [1]
678 | * [ro.vendor.histogram.enable]: [true]
679 | * [ro.vendor.miui.cust_hardware]: [V1]
680 | * [ro.vendor.miui.cust_variant]: [cn_chinatelecom]
681 | * [ro.vendor.miui.mcc]: [9460]
682 | * [ro.vendor.miui.mnc]: [9003]
683 | * [ro.vendor.miui.region]: [CN]
684 | * [ro.vendor.qti.va_aosp.support]: [1]
685 | * [ro.vendor.qti.va_odm.support]: [1]
686 | * [ro.vendor.se.type]: [eSE,HCE,UICC]
687 | * [ro.vendor.soft_backlight.enable]: [true]
688 | * [ro.vendor.touchfeature.type]: [7]
689 | * [ro.vendor.whitepoint_calibration_enable]: [false]
690 | * [ro.vendor.xiaomi.bl.poll]: [true]
691 | * [ro.vndk.version]: [29]
692 | * [ro.wifi.channels]: []
693 | * [ro.zygote]: [zygote64_32]
694 | * [security.perf_harden]: [1]
695 | * [selinux.restorecon_recursive]: [/data/misc_ce/0]
696 | * [service.bootanim.exit]: [1]
697 | * [service.sf.present_timestamp]: [1]
698 | * [sys.boot.reason]: [cold]
699 | * [sys.boot.reason.last]: [reboot,]
700 | * [sys.boot_completed]: [1]
701 | * [sys.displayfeature_hidl]: [true]
702 | * [sys.dump_progress]: [1000]
703 | * [sys.haptic.down]: [5,2]
704 | * [sys.haptic.down.normal]: [2]
705 | * [sys.haptic.down.strong]: [5]
706 | * [sys.haptic.down.weak]: [0]
707 | * [sys.haptic.flick]: [5,2]
708 | * [sys.haptic.flick.light]: [7,2]
709 | * [sys.haptic.hold]: [4,0]
710 | * [sys.haptic.infinitelevel]: [true]
711 | * [sys.haptic.long.press]: [0,1]
712 | * [sys.haptic.mesh.heavy]: [8,2]
713 | * [sys.haptic.mesh.light]: [5,1]
714 | * [sys.haptic.mesh.normal]: [5,2]
715 | * [sys.haptic.motor]: [linear]
716 | * [sys.haptic.pickup]: [2,2]
717 | * [sys.haptic.popup.light]: [6,1]
718 | * [sys.haptic.popup.normal]: [6,2]
719 | * [sys.haptic.runin]: [13]
720 | * [sys.haptic.scroll.edge]: [7,0]
721 | * [sys.haptic.switch]: [9,2]
722 | * [sys.haptic.tap.light]: [5,2]
723 | * [sys.haptic.tap.normal]: [3,2]
724 | * [sys.haptic.trigger.drawer]: [2,0]
725 | * [sys.hardcoder.registered]: [true]
726 | * [sys.is_mem_low_level]: [0]
727 | * [sys.isolated_storage_snapshot]: [true]
728 | * [sys.kernel.firstboot]: [1599062867975]
729 | * [sys.keyguard.screen_off_by_lid]: [false]
730 | * [sys.logbootcomplete]: [1]
731 | * [sys.miui.ndcd]: [off]
732 | * [sys.miui.runtime.reboot]: [0]
733 | * [sys.miui.screenshot]: [false]
734 | * [sys.miui.shutdown.waittime]: [500]
735 | * [sys.miui.user_authenticated]: [true]
736 | * [sys.mtp.device_type]: [2]
737 | * [sys.net.support.netprio]: [true]
738 | * [sys.oem_unlock_allowed]: [0]
739 | * [sys.power.starttimes]: [1]
740 | * [sys.qca1530]: [detect]
741 | * [sys.rescue_boot_count]: [1]
742 | * [sys.retaildemo.enabled]: [0]
743 | * [sys.sysctl.extra_free_kbytes]: [29615]
744 | * [sys.sysctl.tcp_def_init_rwnd]: [60]
745 | * [sys.system_server.start_count]: [1]
746 | * [sys.system_server.start_elapsed]: [7733]
747 | * [sys.system_server.start_uptime]: [7733]
748 | * [sys.tp.grip_enable]: [0]
749 | * [sys.usb.config]: [adb]
750 | * [sys.usb.configfs]: [1]
751 | * [sys.usb.controller]: [a600000.dwc3]
752 | * [sys.usb.ffs.ready]: [1]
753 | * [sys.usb.state]: [adb]
754 | * [sys.use_memfd]: [false]
755 | * [sys.user.0.ce_available]: [true]
756 | * [sys.vendor.shutdown.waittime]: [500]
757 | * [sys.wifitracing.started]: [1]
758 | * [telephony.lteOnCdmaDevice]: [1]
759 | * [tunnel.audio.encode]: [true]
760 | * [use.voice.path.for.pcm.voip]: [true]
761 | * [vendor.camera.sensor.frontMain.fuseID]: [sunn001200F1C7B605F800000000000000000000000000000000000000000000]
762 | * [vendor.camera.sensor.rearDepth.fuseID]: [sunn0018153E4130303030333200000000000000000000000000000000000000]
763 | * [vendor.camera.sensor.rearMacro2x.fuseID]: [sunn001809091530303031383100000000000000000000000000000000000000]
764 | * [vendor.camera.sensor.rearMain.fuseID]: [semc003000C84B7E8D98FFFFFFFFFFFFFFFFFF00000000000000000000000000]
765 | * [vendor.camera.sensor.rearUltra.fuseID]: [sunn00321F130B01000A19020A00090305162C01000000000000000000000000]
766 | * [vendor.gralloc.disable_ubwc]: [0]
767 | * [vendor.hbm.enable]: [true]
768 | * [vendor.sys.listeners.registered]: [true]
769 | * [vendor.sys.rpmb_state]: [23]
770 | * [vold.has_adoptable]: [1]
771 | * [vold.has_quota]: [1]
772 | * [vold.has_reserved]: [1]
773 | * [vold.post_fs_data_done]: [1]
774 | * [wifi.interface]: [wlan0]
775 | */
776 | public class AndroidSystem extends IAndroid{
777 |
778 | public AndroidSystem(Device context) {
779 | super(context);
780 | }
781 |
782 | AndroidSystemCmd cmd = new AndroidSystemCmd();
783 |
784 | /**
785 | * 系统版本
786 | * @return
787 | */
788 | public String SystemVersion(){
789 | try {
790 | return context.exec(cmd.systemVersion());
791 | } catch (IOException e) {
792 | e.printStackTrace();
793 | }
794 |
795 | return "";
796 | }
797 |
798 | /**
799 | * SDK版本
800 | * @return
801 | */
802 | public String SDKVersion(){
803 | try {
804 | return context.exec(cmd.SDKVersion());
805 | } catch (IOException e) {
806 | e.printStackTrace();
807 | }
808 |
809 | return "";
810 | }
811 |
812 |
813 | public String date(){
814 | try {
815 | return context.exec(cmd.date());
816 | } catch (IOException e) {
817 | e.printStackTrace();
818 | }
819 |
820 | return "";
821 | }
822 |
823 | public String location(){
824 | try {
825 | return context.exec(cmd.locationInfo());
826 | } catch (IOException e) {
827 | e.printStackTrace();
828 | }
829 | return "";
830 | }
831 |
832 | /**
833 | * 设备型号
834 | * @return
835 | */
836 | public String devBrand(){
837 | try {
838 | return context.exec(cmd.devBrand());
839 | } catch (IOException e) {
840 | e.printStackTrace();
841 | }
842 |
843 | return "";
844 | }
845 |
846 | /**
847 | * 设备型号,如:Nexus 5、Mi 10
848 | * @return
849 | */
850 | public String devModel(){
851 | try {
852 | return context.exec(cmd.devModel());
853 | } catch (IOException e) {
854 | e.printStackTrace();
855 | }
856 | return "";
857 | }
858 |
859 | @Deprecated
860 | public String devIMEI(){
861 | try {
862 | return context.exec(cmd.devIMEI());
863 | } catch (IOException e) {
864 | e.printStackTrace();
865 | }
866 |
867 | return "";
868 | }
869 |
870 | /**
871 | *
872 | * Android 10测试可行
873 | * 获取当前正在运行进程
874 | * @param grep 为空时返回全部
875 | * @return
876 | */
877 | public String listProcess(String grep){
878 | try{
879 | return context.exec(cmd.listProcess(grep));
880 | }catch (Exception e){
881 | e.printStackTrace();
882 | }
883 |
884 | return "";
885 | }
886 |
887 | }
888 |
--------------------------------------------------------------------------------
/ADBLib/src/com/adb/process/android/IAndroid.java:
--------------------------------------------------------------------------------
1 | package com.adb.process.android;
2 |
3 | import com.adb.process.ACtrl;
4 | import com.adb.process.ADBCtrl;
5 | import com.adb.process.Device;
6 |
7 | public class IAndroid extends ACtrl {
8 | protected Device context;
9 |
10 | public IAndroid(Device context){
11 | this.context = context;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/ADBLib/src/com/adb/process/android/app/AndroidAPP.java:
--------------------------------------------------------------------------------
1 | package com.adb.process.android.app;
2 |
3 | import com.adb.command.android.app.AndroidAppCmd;
4 | import com.adb.process.Device;
5 | import com.adb.process.android.IAndroid;
6 |
7 | import java.io.IOException;
8 |
9 | public class AndroidAPP extends IAndroid {
10 |
11 | private AndroidAppCmd cmd = new AndroidAppCmd();
12 |
13 | public AndroidAPP(Device context) {
14 | super(context);
15 | }
16 |
17 | /**
18 | * 安装应用
19 | * @param windowPath 电脑端的apk文件地址
20 | * @param isDebugApk 是否为debug签名的应用
21 | * @param isReInstall 如果已经安装,是否重新安装
22 | * @return
23 | */
24 | public boolean install(String windowPath,boolean isDebugApk,boolean isReInstall){
25 | try{
26 | String msg = context.exec(cmd.install(windowPath, isDebugApk, isReInstall));
27 |
28 | if (msg.toLowerCase().contains("success")){
29 | return true;
30 | }else{
31 | System.out.println(msg);
32 | return false;
33 | }
34 |
35 | }catch (Exception e){
36 | e.printStackTrace();
37 | }
38 |
39 | return false;
40 | }
41 |
42 | /**
43 | * 卸载应用
44 | * @param packageName 包名
45 | * @return
46 | */
47 | public boolean uninstall(String packageName){
48 | try{
49 | String msg = context.exec(cmd.uninstall(packageName));
50 |
51 | if (msg.toLowerCase().contains("success")){
52 | return true;
53 | }else{
54 | System.out.println(msg);
55 | return false;
56 | }
57 | }catch (Exception e){
58 | e.printStackTrace();
59 | }
60 |
61 | return false;
62 | }
63 |
64 | /**
65 | * Android 10测试可行
66 | *
67 | * 强制停止APP
68 | * @param packageName
69 | * @return
70 | */
71 | public boolean stopApp(String packageName){
72 | try {
73 | String reply = context.exec(cmd.stopApp(packageName));
74 | return reply.trim().isEmpty();//正常情况下返回内容为空
75 | }catch (Exception e){
76 | e.printStackTrace();
77 | }
78 |
79 | return false;
80 | }
81 |
82 |
83 | /**
84 | * Android 10测试可行
85 | *
86 | * 获取APP列表
87 | * @return
88 | */
89 | public String listApp(){
90 | try{
91 | return context.exec(cmd.listAPP());
92 | }catch (Exception e){
93 | e.printStackTrace();
94 | }
95 |
96 | return "";
97 | }
98 |
99 | /**
100 | * Android 10测试可行
101 | *
102 | * 系统APP
103 | * @return
104 | */
105 | public String listSystemApp(){
106 | try{
107 | return context.exec(cmd.listSystemAPP());
108 | }catch (Exception e){
109 | e.printStackTrace();
110 | }
111 |
112 | return "";
113 | }
114 |
115 | /**
116 | * Android 10测试可行
117 | *
118 | * 获取第三方APP
119 | * @return
120 | */
121 | public String list3App(){
122 | try{
123 | return context.exec(cmd.list3APP());
124 | }catch (Exception e){
125 | e.printStackTrace();
126 | }
127 |
128 | return "";
129 | }
130 |
131 | /**
132 | * 根据包名获取PID
133 | * @param packageName
134 | * @return
135 | */
136 | public String getPid(String packageName) {
137 | try {
138 | String msg = context.exec(cmd.getPid(packageName));
139 | return msg;
140 | } catch (Exception e) {
141 | e.printStackTrace();
142 | }
143 |
144 | return "";
145 | }
146 |
147 | /**
148 | * 读取应用信息
149 | * @param packageName
150 | * @return
151 | */
152 | public String readAppInfo(String packageName){
153 | try{
154 | return context.exec(cmd.readAppInfo(packageName));
155 | }catch (Exception e){
156 | e.printStackTrace();
157 | }
158 |
159 | return "";
160 | }
161 |
162 | /**
163 | * 清空APP数据
164 | * @param packageName
165 | * @return
166 | */
167 | public boolean cleanAPPData(String packageName){
168 | try{
169 | String reply = context.exec(cmd.cleanAPPData(packageName));
170 | return reply.toLowerCase().contains("success");
171 | }catch (Exception e){
172 | e.printStackTrace();
173 | }
174 |
175 | return false;
176 | }
177 |
178 | /**
179 | * 获取应用安装路径
180 | * @param packageName 不能为空
181 | * @return
182 | */
183 | public String readAppInstallPath(String packageName){
184 |
185 | try {
186 | return context.exec(cmd.readAppInstallPath(packageName));
187 | } catch (IOException e) {
188 | e.printStackTrace();
189 | }
190 |
191 | return "";
192 | }
193 |
194 | }
195 |
--------------------------------------------------------------------------------
/ADBLib/src/com/adb/process/android/app/ProcessInfo.java:
--------------------------------------------------------------------------------
1 | package com.adb.process.android.app;
2 |
3 | public class ProcessInfo {
4 | public String packageName = "";
5 | public String pid = "";
6 | }
7 |
--------------------------------------------------------------------------------
/ADBLib/src/com/adb/process/android/app/ProcessManager.java:
--------------------------------------------------------------------------------
1 | package com.adb.process.android.app;
2 |
3 | import com.adb.process.Device;
4 | import com.adb.process.android.IAndroid;
5 | import com.adb.utils.StringUtils;
6 | import java.util.Timer;
7 | import java.util.TimerTask;
8 | import java.util.concurrent.TimeUnit;
9 |
10 | /**
11 | * 进程ID监听器,定时查询
12 | */
13 | public class ProcessManager extends IAndroid{
14 |
15 | private ProcessInfo info = new ProcessInfo();
16 | private Timer timer;
17 | private TimerTask task;
18 |
19 | public ProcessManager(Device context) {
20 | super(context);
21 | }
22 |
23 | /**
24 | * 设置监听器,监听进程变化,在设备断开后会自动结束轮询,也可以通过调用finish的方法主动结束轮询
25 | * @param packageName 包名
26 | * @param listener 监听器
27 | * @param intervalOfSeconds 定期查询进程状态的间隔(秒)
28 | */
29 | public void startListenerOfProcess(String packageName, IListenerOfProcess listener,int intervalOfSeconds){
30 |
31 | info.packageName = packageName;
32 |
33 | if (listener == null){
34 | return;
35 | }
36 |
37 | timer = new Timer();
38 | task = new TimerTask() {
39 | @Override
40 | public void run() {
41 | String reply = context.managerOfApp().getPid(packageName).trim();
42 |
43 | if (reply.isEmpty()){
44 | listener.onNoFoundPid();
45 | }else if (!info.pid.equals(reply)){
46 | if (StringUtils.isNumber(reply)){
47 | info.pid = reply;
48 | listener.onChange(info);
49 | }else{
50 | listener.onError(reply);
51 |
52 | //设备断开,主动结束
53 | if (reply.startsWith("error: no devices")&&reply.contains(context.deviceName)){
54 | finish();
55 | }
56 | }
57 | }
58 | }
59 | };
60 |
61 | timer.schedule(task,0, TimeUnit.SECONDS.toMillis(intervalOfSeconds));
62 | }
63 |
64 | public void finish(){
65 | try {
66 | if (task != null){
67 | task.cancel();
68 | task = null;
69 | timer.cancel();
70 | task = null;
71 | }
72 | }catch (Exception e){
73 | e.printStackTrace();
74 | }
75 | }
76 |
77 | public interface IListenerOfProcess{
78 | public void onChange(ProcessInfo info);
79 | public void onNoFoundPid();
80 | public void onError(String info);
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/ADBLib/src/com/adb/process/android/context/Activity.java:
--------------------------------------------------------------------------------
1 | package com.adb.process.android.context;
2 |
3 | import com.adb.command.android.app.ActivityCmd;
4 | import com.adb.process.Device;
5 | import com.adb.process.android.IAndroid;
6 |
7 | public class Activity extends IAndroid {
8 |
9 | public Activity(Device context) {
10 | super(context);
11 | }
12 |
13 | private ActivityCmd cmd = new ActivityCmd();
14 |
15 | /**
16 | * 获取当前正在前台的Activity信息
17 | * @return
18 | */
19 | public String getForegroundActivity(){
20 | try {
21 | return context.exec(cmd.getForegroundActivity());
22 | }catch (Exception e){
23 | return "";
24 | }
25 | }
26 |
27 | /**
28 | * Android 10测试可行
29 | * 带参数启动Activity
30 | * @param intent
31 | * @return
32 | */
33 | public boolean start(IContext.Intent intent) {
34 | try{
35 | String msg = context.exec(intent.cmd);
36 | System.out.println(msg);
37 | return !msg.toLowerCase().contains("error:");
38 | }catch (Exception e){
39 | e.printStackTrace();
40 | }
41 | return false;
42 | }
43 |
44 | /**
45 | * Android 10测试可行
46 | *
47 | * @param packageName 不能为空
48 | * @param canonicalName activity的完整类地址
49 | * 注:如果该Activity没有在AndroidManifest中声明intent-filter/Action/category,则无法启动
50 | * @return
51 | */
52 | public boolean start(String packageName,String canonicalName){
53 |
54 | if (!canonicalName.startsWith(packageName)){
55 | canonicalName = packageName+"."+canonicalName;
56 | }
57 |
58 | try{
59 | String msg = context.exec(cmd.startActivity(packageName, canonicalName));
60 | System.out.println(msg);
61 | /**
62 | * 异常时的应答如:
63 | * Starting: Intent { cmp=com.huangxiaowei.annotatintest/.TestActivity }
64 | * Error type 3
65 | * Error: Activity class {com.huangxiaowei.annotatintest/com.huangxiaowei.annotatintest.TestActivity} does not exist.
66 | */
67 |
68 | return !msg.toLowerCase().contains("error:");
69 | }catch (Exception e){
70 | e.printStackTrace();
71 | }
72 | return false;
73 | }
74 |
75 | /**
76 | *
77 | * @param packageName
78 | * @return
79 | */
80 | public boolean start(String packageName){
81 |
82 | try{
83 | String msg = context.exec(cmd.startActivity(packageName));
84 | System.out.println(msg);
85 | return !msg.startsWith("error:")&&!msg.contains("No activities found to run");
86 | }catch (Exception e){
87 | e.printStackTrace();
88 | }
89 | return false;
90 | }
91 |
92 | /**
93 | * Android 10测试可行
94 | *
95 | * 获取Activity启动的时长
96 | * @param packageName
97 | * @param canonicalName
98 | * @return
99 | *
100 | * 正常返回内容如:
101 | * Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.huangxiaowei.annotationtest/.MainActivity }
102 | * Status: ok //启动成功
103 | * LaunchState: WARM //热启动:即应用进程还在后台的情况(相对的为冷启动,即第一次启动)
104 | * Activity: com.huangxiaowei.annotationtest/.TestActivity
105 | * TotalTime: 137
106 | * WaitTime: 137
107 | * Complete
108 | *
109 | */
110 | public String getTimeOfStartActivity(String packageName,String canonicalName) {
111 |
112 | if (!canonicalName.startsWith(packageName)) {
113 | canonicalName = packageName + "." + canonicalName;
114 | }
115 |
116 | try {
117 | return context.exec(cmd.getTimeOfStartActivity(packageName, canonicalName));
118 | } catch (Exception e) {
119 | e.printStackTrace();
120 | }
121 |
122 | return "";
123 | }
124 |
125 |
126 | }
127 |
--------------------------------------------------------------------------------
/ADBLib/src/com/adb/process/android/context/ActivityIntentBuilder.java:
--------------------------------------------------------------------------------
1 | package com.adb.process.android.context;
2 |
3 | public class ActivityIntentBuilder extends IContext{
4 |
5 | private String packageName = "";
6 | private String canonicalName = "";
7 |
8 | /**
9 | *
10 | * @param action Activity的Action
11 | * @param packageName 包名
12 | * @param canonicalName Activity的完整类地址
13 | */
14 | public ActivityIntentBuilder(String action, String packageName, String canonicalName){
15 | this.packageName = packageName;
16 | this.canonicalName = canonicalName;
17 |
18 | builder.append("adb shell am start -a ").append(action).append(" ");
19 | }
20 |
21 | @Override
22 | public Intent build() {
23 | if (!canonicalName.startsWith(packageName)){
24 | canonicalName = packageName+"."+canonicalName;
25 | }
26 |
27 | builder.append(packageName).append("/").append(canonicalName);
28 | return super.build();
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/ADBLib/src/com/adb/process/android/context/Broadcast.java:
--------------------------------------------------------------------------------
1 | package com.adb.process.android.context;
2 |
3 | import com.adb.command.android.app.BroadcastCmd;
4 | import com.adb.process.Device;
5 | import com.adb.process.android.IAndroid;
6 |
7 | import java.io.IOException;
8 |
9 | public class Broadcast extends IAndroid {
10 |
11 | public final static String CONNECTIVITY_CHANGE = "android.net.conn.CONNECTIVITY_CHANGE";//网络连接发生变化
12 | public final static String SCREEN_ON = "android.intent.action.SCREEN_ON";//屏幕点亮
13 | public final static String SCREEN_OFF = "android.intent.action.SCREEN_OFF";//屏幕熄灭
14 | public final static String BATTERY_LOW = "android.intent.action.BATTERY_LOW";//电量低,会弹出电量低提示框
15 | public final static String BATTERY_OKAY = "android.intent.action.BATTERY_OKAY";//电量恢复了
16 | public final static String BOOT_COMPLETED = "android.intent.action.BOOT_COMPLETED";//设备启动完毕,开机广播
17 | public final static String DEVICE_STORAGE_LOW = "android.intent.action.DEVICE_STORAGE_LOW";//存储空间过低
18 | public final static String DEVICE_STORAGE_OK = "android.intent.action.DEVICE_STORAGE_OK";//存储空间恢复
19 | public final static String PACKAGE_ADDED = "android.intent.action.PACKAGE_ADDED";//安装了新的应用
20 | public final static String WIFI_STATE_CHANGE = "android.net.wifi.STATE_CHANGE";//WiFi 连接状态发生变化
21 | public final static String STATE_CHANGE = "android.net.wifi.WIFI_STATE_CHANGED";//WiFi 状态变为启用/关闭/正在启动/正在关闭/未知
22 | public final static String BATTERY_CHANGED = "android.intent.action.BATTERY_CHANGED"; //电池电量发生变化
23 | public final static String INPUT_METHOD_CHANGED ="android.intent.action.INPUT_METHOD_CHANGED";//系统输入法发生变化
24 | public final static String ACTION_POWER_CONNECTED = "android.intent.action.ACTION_POWER_CONNECTED";//外部电源连接
25 | public final static String ACTION_POWER_DISCONNECTED = "android.intent.action.ACTION_POWER_DISCONNECTED"; //外部电源断开连接
26 | public final static String DREAMING_STARTED = "android.intent.action.DREAMING_STARTED"; //系统开始休眠
27 | public final static String DREAMING_STOPPED = "android.intent.action.DREAMING_STOPPED"; //系统停止休眠
28 | public final static String WALLPAPER_CHANGED = "android.intent.action.WALLPAPER_CHANGED";//壁纸发生变化
29 | public final static String HEADSET_PLUG = "android.intent.action.HEADSET_PLUG";//插入耳机
30 | public final static String MEDIA_UNMOUNTED = "android.intent.action.MEDIA_UNMOUNTED";//卸载外部介质
31 | public final static String MEDIA_MOUNTED = "android.intent.action.MEDIA_MOUNTED";//挂载外部介质
32 | public final static String POWER_SAVE_MODE_CHANGED = "android.os.action.POWER_SAVE_MODE_CHANGED";//省电模式开启
33 |
34 | public Broadcast(Device context) {
35 | super(context);
36 | }
37 |
38 | private BroadcastCmd cmd = new BroadcastCmd();
39 |
40 | /**
41 | *
42 | * 发送广播
43 | * @param
44 | * @return
45 | */
46 | public boolean send(IContext.Intent intent) {
47 | try{
48 | String reply = context.exec(intent.cmd);
49 | System.out.println(reply);
50 | return !reply.toLowerCase().contains("error:");
51 | }catch (Exception e){
52 | e.printStackTrace();
53 | }
54 | return false;
55 | }
56 |
57 |
58 | /**
59 | *
60 | * 发送广播
61 | * @param
62 | * @return
63 | */
64 | public boolean send(String action){
65 | try {
66 | String reply = context.exec(cmd.send(action));
67 | return !reply.toLowerCase().contains("error:");
68 | } catch (IOException e) {
69 | e.printStackTrace();
70 | }
71 | return false;
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/ADBLib/src/com/adb/process/android/context/BroadcastIntentBuilder.java:
--------------------------------------------------------------------------------
1 | package com.adb.process.android.context;
2 |
3 | public class BroadcastIntentBuilder extends IContext{
4 |
5 | /**
6 | * 无差别广播
7 | * @param action
8 | */
9 | public BroadcastIntentBuilder(String action){
10 | builder.append("adb shell am broadcast -a ")
11 | .append(action).append(" ");
12 | }
13 |
14 | /**
15 | * 限定接收器的地址
16 | *
17 | * @param action 广播Action
18 | * @param packageName 接收器的包名
19 | * @param canonicalName 接收器的完整类路径
20 | */
21 | public BroadcastIntentBuilder(String action,String packageName, String canonicalName){
22 | this(action);
23 |
24 | builder.append("-n ").append(packageName).append("/").append(canonicalName);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/ADBLib/src/com/adb/process/android/context/IContext.java:
--------------------------------------------------------------------------------
1 | package com.adb.process.android.context;
2 |
3 | public abstract class IContext{
4 |
5 | protected StringBuilder builder = new StringBuilder();
6 |
7 | public IContext addExtra(String key, String value){
8 | builder.append("--es ");
9 | builder.append(key);
10 | builder.append(" ");
11 | builder.append(value);
12 | builder.append(" ");
13 | return this;
14 | }
15 |
16 | public IContext addExtra(String key, boolean value){
17 | builder.append("--ez ");
18 | builder.append(key);
19 | builder.append(" ");
20 | builder.append(value);
21 | builder.append(" ");
22 | return this;
23 | }
24 |
25 | public IContext addExtra(String key, int value){
26 | builder.append("--ei ");
27 | builder.append(key);
28 | builder.append(" ");
29 | builder.append(value);
30 | builder.append(" ");
31 |
32 | return this;
33 | }
34 |
35 | public IContext addExtra(String key, int[] value) {
36 | builder.append("--eia ");
37 | builder.append(key);
38 | builder.append(" ");
39 | for(int i = 0;i [path]
26 | *
27 | * (小米)Android 10测试无效
28 | *暂时没有找到无法正常执行的原因,替代方案:save2WindowFile2()
29 | * @param path
30 | */
31 | @Deprecated
32 | public void save2WindowFile(String path){
33 | try{
34 | context.exec(cmd.logcat2WindowFile(path));
35 | }catch (Exception e){
36 | e.printStackTrace();
37 | }
38 | }
39 |
40 | /**
41 | * 为了替代adb指令无法正常指令的方案。
42 | * @param isPrint 保存的同时是否打印输出
43 | * @param path 保存路径
44 | * @param grep 日志关键字过滤
45 | */
46 | public void save2WindowFile2(boolean isPrint,String path,String grep){
47 | try{
48 | context.execASave(cmd.logcat(grep),path,isPrint);
49 | } catch (IOException e) {
50 | e.printStackTrace();
51 | }
52 | }
53 |
54 | /**
55 | * 保存日志到Android设备
56 | * @param path 文件完整路径
57 | * @param tag 日志过滤的TAG
58 | */
59 | public boolean save2AndroidFile(String path,String tag){
60 | try {
61 | String reply = context.exec(cmd.logcat2AndroidFile(path, tag));
62 | return !reply.startsWith("error:");
63 | }catch (Exception e){
64 | e.printStackTrace();
65 | }
66 |
67 | return false;
68 | }
69 |
70 | /**
71 | * 打印日志
72 | * @param grep 过滤,为空时不过滤
73 | */
74 | public void print(String grep){
75 | try {
76 | context.execAPrint(cmd.logcat(grep));
77 | }catch (Exception e){
78 | e.printStackTrace();
79 | }
80 | }
81 |
82 | /**
83 | *
84 | * @param config 日志过滤的条件
85 | * @param callback 回调
86 | * @param isPrint 是否打印日志
87 | */
88 | public void listenLogcat(LogcatConfig config,IExecCallback callback,boolean isPrint){
89 | if (config == null){
90 | return;
91 | }
92 |
93 | if (config.packageName == null||config.packageName.trim().isEmpty()){
94 | context.exec(config.cmd,callback,config.grep,isPrint);
95 | }else{
96 | //监听进程,并每5秒检查一下当前进程ID是否有所变化
97 | new ProcessManager(context).startListenerOfProcess(config.packageName, new ProcessManager.IListenerOfProcess() {
98 | @Override
99 | public void onChange(ProcessInfo info) {
100 | fixedThreadPool.execute(() -> {
101 | context.exec(cmd.logcatByPid(info.pid), new IExecCallback() {
102 | @Override
103 | public void onCreatedProcess(Process process) {
104 | lastProcess = process;
105 | if (callback != null){
106 | callback.onCreatedProcess(process);
107 | }
108 | }
109 |
110 | @Override
111 | public void onReplyLine(String str) {
112 | if (callback!=null){
113 | callback.onReplyLine(str);
114 | }
115 | }
116 |
117 | @Override
118 | public void onErrorLine(String str) {
119 | if (callback!=null){
120 | callback.onErrorLine(str);
121 | }
122 | }
123 | },config.grep,isPrint);
124 | });
125 | }
126 |
127 |
128 | @Override
129 | public void onNoFoundPid() {
130 | if (lastProcess!= null){
131 | lastProcess.destroy();
132 | //判定进程已经被销毁,故而结果该Process,避免堵塞造成资源浪费
133 | lastProcess = null;
134 | }
135 | }
136 |
137 | @Override
138 | public void onError(String info) {
139 | callback.onErrorLine(info);
140 | }
141 | },5);
142 | }
143 | }
144 |
145 | /**
146 | * 根据PID打印日志和可以配合getPid使用
147 | * @param pid
148 | */
149 | public void printByPid(String pid){
150 |
151 | try {
152 | context.execAPrint(cmd.logcatByPid(pid));
153 | }catch (Exception e){
154 | e.printStackTrace();
155 | }
156 | }
157 |
158 | public void print(LogcatConfig config){
159 | listenLogcat(config,null,true);
160 | }
161 | }
162 |
--------------------------------------------------------------------------------
/ADBLib/src/com/adb/process/android/logcat/LogcatConfig.java:
--------------------------------------------------------------------------------
1 | package com.adb.process.android.logcat;
2 |
3 | public class LogcatConfig{
4 | public static final String LEVEL_V = "v";//Verbose:输出全部日志
5 | public static final String LEVEL_D = "d";//Debug
6 | public static final String LEVEL_I = "i";//Info
7 | public static final String LEVEL_W = "w";//Warning
8 | public static final String LEVEL_E = "e";//Error
9 | public static final String LEVEL_F = "f";//Fatal
10 | public static final String LEVEL_S = "s";//Silent:不输出任何日志
11 |
12 | public static final String FORMAT_BRIEF = "brief";///():
13 | public static final String FORMAT_PROCESS = "process";//()
14 | public static final String FORMAT_TAG = "tag";///:
15 | public static final String FORMAT_RAW = "raw";//
16 | public static final String FORMAT_TIME = "time";// /():
17 | public static final String FORMAT_LONG = "long";//[ : / ]
18 |
19 | public String cmd = "";
20 | public String grep = null;
21 | public String packageName = null;
22 |
23 | protected LogcatConfig(){}
24 |
25 | public LogcatConfig(String packageName,String tag,String level,String format,String grep){
26 |
27 | this.packageName = packageName;
28 |
29 | if (tag == null||tag.isEmpty()){
30 | tag = "*";
31 | }
32 |
33 | if (level == null||level.isEmpty()){
34 | level = LEVEL_I;
35 | }
36 |
37 | if (format == null||format.isEmpty()){
38 | format = FORMAT_TIME;
39 | }
40 |
41 | this.grep = grep;
42 |
43 | // if (grep == null||grep.isEmpty()){
44 | cmd = "adb shell logcat -v "+format+" -s "+tag+":"+level;
45 | // }else{
46 | // cmd = "adb shell logcat -v "+format+" -s "+tag+":"+level+"|grep \""+grep+"\"";
47 | // }
48 | }
49 | }
--------------------------------------------------------------------------------
/ADBLib/src/com/adb/process/android/logcat/LogcatConfigBuilder.java:
--------------------------------------------------------------------------------
1 | package com.adb.process.android.logcat;
2 |
3 | public class LogcatConfigBuilder {
4 |
5 | private String tag = null;
6 | private String level = null;
7 | private String format = null;
8 | private String filter = null;
9 | private String packageName = null;
10 |
11 | /**
12 | * 根据TAG过滤
13 | * @param tag
14 | * @return
15 | */
16 | public LogcatConfigBuilder filterTAG(String tag){
17 | this.tag = tag;
18 | return this;
19 | }
20 |
21 | /**
22 | * 根据日志Level过滤
23 | * @param level
24 | * @return
25 | */
26 | public LogcatConfigBuilder filterLevel(String level){
27 | this.level = level;
28 | return this;
29 | }
30 |
31 | /**
32 | * 设置日志输出的格式
33 | * @param format
34 | * @return
35 | */
36 | public LogcatConfigBuilder showFormat(String format){
37 | this.format = format;
38 | return this;
39 | }
40 |
41 | public LogcatConfigBuilder filterPackageName(String packageName){
42 | this.packageName =packageName;
43 | return this;
44 | }
45 |
46 | /**
47 | * 关键字过滤
48 | * @param grep
49 | * @return
50 | */
51 | public LogcatConfigBuilder filter(String grep){
52 | this.filter = grep;
53 | return this;
54 | }
55 |
56 | public LogcatConfig build(){
57 | return new LogcatConfig(packageName,tag,level,format,filter);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/ADBLib/src/com/adb/utils/FileUtils.java:
--------------------------------------------------------------------------------
1 | package com.adb.utils;
2 |
3 | import java.io.File;
4 | import java.io.UnsupportedEncodingException;
5 | import java.net.URLDecoder;
6 |
7 | public class FileUtils {
8 |
9 | /**
10 | * 返回当前项目的地址(如果为库,则为该库地址)
11 | *
12 | * 如果为jar包,则返回jar包的地址
13 | * 如果未编译为Jar包,则返回当前库(JBaseLib)的地址
14 | *
15 | */
16 | public static String getLocalPath(String chartsName){
17 |
18 | String path = FileUtils.class.getProtectionDomain().getCodeSource().getLocation().getPath();
19 | if (chartsName == null||chartsName.isEmpty()){
20 | chartsName = "UTF-8";
21 | }
22 | try {
23 | return URLDecoder.decode(path,chartsName);
24 | } catch (UnsupportedEncodingException e) {
25 | e.printStackTrace();
26 | }
27 |
28 | return path;
29 | }
30 |
31 | /**
32 | * 删除文件(夹)
33 | * @param path
34 | * @return
35 | */
36 | public static void delete(String path){
37 | File file = new File(path);
38 |
39 | if (file.exists()){
40 | if (file.isDirectory()){
41 |
42 | File[] list = file.listFiles();
43 | for (File f:list){
44 | delete(f.getAbsolutePath());
45 | }
46 | }
47 |
48 | file.delete();
49 | }
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/ADBLib/src/com/adb/utils/JarUtils.java:
--------------------------------------------------------------------------------
1 | package com.adb.utils;
2 |
3 | public class JarUtils {
4 |
5 | /**
6 | * 判断当前是否是作为一个jar包
7 | * @return
8 | */
9 | public static boolean isJar() {
10 | return JarUtils.class.getProtectionDomain().getCodeSource().getLocation().getPath().endsWith(".jar");
11 | }
12 |
13 | /**
14 | * 获取当前Jar包的绝对地址(如果当前不为jar包,则返回的地址为当前module的绝对地址)
15 | * @return
16 | */
17 | public static String getJarPath(){
18 | return JarUtils.class.getProtectionDomain().getCodeSource().getLocation().getPath();
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/ADBLib/src/com/adb/utils/StringUtils.java:
--------------------------------------------------------------------------------
1 | package com.adb.utils;
2 |
3 | import java.io.UnsupportedEncodingException;
4 | import java.net.URLDecoder;
5 |
6 | public class StringUtils {
7 |
8 | /**
9 | * 判断字符串是否为数字
10 | * @param str
11 | * @return
12 | */
13 | public static boolean isNumber(String str){
14 |
15 | if (str == null||str.trim().isEmpty()){
16 | return false;
17 | }
18 |
19 | for (int i = 0; i < str.length(); i++){
20 | if (!Character.isDigit(str.charAt(i))){
21 | return false;
22 | }
23 | }
24 |
25 | return true;
26 | }
27 |
28 | /**
29 | * 转化编码格式
30 | * @param str
31 | * @param charsetName
32 | * @return
33 | */
34 | public static String decode(String str,String charsetName){
35 | try {
36 | return URLDecoder.decode(str, charsetName);
37 | } catch (UnsupportedEncodingException e) {
38 | e.printStackTrace();
39 | }
40 |
41 | return null;
42 | }
43 |
44 | /**
45 | * 重复字符串
46 | * @param str 重复的字符串
47 | * @param count 重复的次数
48 | * @return
49 | */
50 | public static String repeat(String str,int count){
51 | return String.format("%0" + count + "d", 0).replace("0",str);
52 | }
53 |
54 | /**
55 | * 删除字符串前缀的所有 prefix,如deleteAllPrefix("aaaaaaaaBC","a"),返回值为:BC
56 | * @param str
57 | * @param prefix 前缀
58 | * @return 如果不存在该前缀,则原值返回
59 | */
60 | public static String deleteAllPrefix(String str,String prefix){
61 | return str.replaceAll("^("+prefix+"+)", "");
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/ADBLibSample.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ADBLib
2 |
3 | ## ADBLib
4 | 一个封装了adb常用指令的纯Java库(不依赖于其他第三方库),可以方便的进行一些Android设备控制脚本的编写。
5 |
6 |
7 | ## 环境
8 |
9 | - 适用于Window环境(其他系统环境未测试adb指令是否正常)
10 | - ADB环境(需提前下载好ADB工具,无需配置ADB的系统环境变量)
11 |
12 |
13 |
14 | ## 调用
15 |
16 | ### 基本应用
17 | ```java
18 | package com.adb.sample;
19 |
20 | import com.adb.process.ADBCtrl;
21 | import com.adb.process.Device;
22 | import com.adb.process.android.AndroidSystem;
23 | import com.adb.process.android.context.Activity;
24 |
25 | public class CommonSample {
26 | public static void main(String[] args) {
27 |
28 | //如果已经配置过ADB环境变量,则可以
29 | ADBCtrl adb = new ADBCtrl();
30 |
31 | //在未配置ADB环境变量的情况下可以通过调用
32 | ADBCtrl adb1 = new ADBCtrl("E:\\tool\\adbDir\\");
33 |
34 | adb.setCharset("GBK");//设置编码格式,默认为GBK,可不设置
35 | adb.isPrintCmd(true);//是否打印执行的命令
36 |
37 | //获取已连接的设备
38 | Device[] device = adb.listDevices();
39 |
40 | //如果我们确定连接的设备只有一个或者操作任一台设备均可,无需进行选择时,也可以直接调用
41 | Device device1 = adb.firstDevice();
42 |
43 | AndroidSystem system = device1.managerOfSystem();
44 | system.listProcess(null);//获取系统进程等
45 | //详情可看 com.adb.sample.AndroidSystemSample
46 |
47 | Activity activity = device1.managerOfActivity();
48 | activity.start("com.hxw.test");
49 | //详情可看 com.adb.sample.ActivitySample
50 |
51 | //其他API可阅其他Sample
52 | }
53 | }
54 | ```
55 |
56 | ### Event
57 | ```java
58 | package com.adb.sample;
59 |
60 | import com.adb.process.ADBCtrl;
61 | import com.adb.process.Device;
62 | import com.adb.process.android.event.AndroidEvent;
63 | import com.adb.process.android.event.ClickEventManager;
64 | import com.adb.process.android.event.KeyCode;
65 |
66 | public class EventSample {
67 | public static void main(String[] args) {
68 |
69 | Device device = new ADBCtrl().firstDevice();
70 | if (device == null){
71 | System.out.println("找不到连接的设备");
72 | }
73 |
74 | AndroidEvent androidEvent = device.managerOfEvent();
75 |
76 | //点击指定坐标
77 | androidEvent.click(230,449);
78 |
79 | //滑动
80 | androidEvent.swipe(230,449,200,440);
81 |
82 | androidEvent.inputKeyEvent(KeyCode.KEYCODE_BACK);//执行返回键
83 |
84 | //监听设备的点击/滑动/松开事件
85 | androidEvent.listenOfClickEvent(new ClickEventManager.IEventCallback() {
86 | @Override
87 | public void onCreateProcess(Process process) {
88 | //获取Process,并在需要的时候调用process结束任务
89 | }
90 |
91 | @Override
92 | public void onEventDown(int x, int y) {
93 | System.out.println("点击坐标:("+x+","+y+")");
94 |
95 | // androidEvent.click(x,y); //可以通过click点击同样位置,但不能在这个地方写,会导致死循环的
96 | }
97 |
98 | @Override
99 | public void onEventUp(int x, int y) {
100 | System.out.println("松开:("+x+","+y+")");
101 | }
102 |
103 | @Override
104 | public void onEventMove(int x, int y) {
105 | System.out.println("滑动坐标:("+x+","+y+")");
106 | }
107 |
108 | @Override
109 | public void onError(String msg) {
110 | //执行错误时,回调该方法
111 | }
112 | });
113 | }
114 | }
115 |
116 | ```
117 |
118 | ### Broadcast
119 | ```java
120 | package com.adb.sample;
121 |
122 | import com.adb.process.ADBCtrl;
123 | import com.adb.process.android.context.Broadcast;
124 | import com.adb.process.android.context.BroadcastIntentBuilder;
125 | import com.adb.process.android.context.IContext;
126 |
127 | public class BroadcastSample {
128 |
129 | public static void main(String[] args) {
130 |
131 | Broadcast broadcast = new Broadcast(new ADBCtrl().firstDevice());
132 |
133 | IContext.Intent intent =
134 | new BroadcastIntentBuilder("com.hxw.test")//ACTION
135 | .addExtra("数组",new int[]{1,2,3,4})
136 | .addExtra("KeyOfString","i am string")
137 | .addExtra("KeyOfBoolean",false)
138 | .addExtra("KeyOfLong",Long.valueOf("12433333399"))
139 | .build();
140 | broadcast.send(intent);//发送广播
141 |
142 | broadcast.send(Broadcast.BOOT_COMPLETED);//发送开机广播
143 |
144 | broadcast.send("com.hxw.hi");//发送指定Action的广播
145 | }
146 | }
147 | ```
148 |
149 |
150 | ### Activity
151 | ```java
152 | package com.adb.sample;
153 |
154 | import com.adb.process.ADBCtrl;
155 | import com.adb.process.Device;
156 | import com.adb.process.android.context.Activity;
157 | import com.adb.process.android.context.ActivityIntentBuilder;
158 | import com.adb.process.android.context.IContext;
159 |
160 | public class ActivitySample {
161 | public static void main(String[] args) {
162 | Device context = new ADBCtrl().firstDevice();
163 | Activity activity = new Activity(context);
164 |
165 | //根据包名启动应用(进入默认Activity)
166 | activity.start("com.huangxiaowei.annotationtest");
167 |
168 | //启动指定Activity
169 | activity.start("com.hxw.test","com.hxw.test.MainActivity");
170 |
171 | //带参数启动Activity
172 | IContext.Intent intent = new ActivityIntentBuilder("android.intent.action.TestActivity",
173 | "com.huangxiaowei.annotationtest",
174 | "com.huangxiaowei.annotationtest.TestActivity")
175 | .addExtra("KEY","这是一个Value")
176 | .build();
177 | activity.start(intent);
178 |
179 | }
180 | }
181 |
182 | ```
183 | ###
184 | ### Service
185 | ```java
186 | package com.adb.sample;
187 |
188 | import com.adb.process.ADBCtrl;
189 | import com.adb.process.android.context.IContext;
190 | import com.adb.process.android.context.Service;
191 | import com.adb.process.android.context.ServiceInentBuilder;
192 |
193 | public class ServiceSample {
194 |
195 | public static void main(String[] args) {
196 |
197 | Service service = new Service(new ADBCtrl().listDevices()[0]);
198 |
199 | service.getAllRunningService(null);//获取正在运行的服务,参数为指定应用的包名
200 |
201 | //带参数启动服务
202 | IContext.Intent intent = new ServiceInentBuilder("com.hxw.test","com.hxw.test.MainService")
203 | .addExtra("KEY","VALUE").build();
204 | service.startService(intent);
205 |
206 | //无参数启动服务
207 | service.startService("com.hxw.test","com.hxw.test.MainService");
208 |
209 | //停止服务
210 | service.stopService("com.hxw.test","com.hxw.test.MainService");
211 | }
212 | }
213 | ```
214 |
215 |
216 | ### Logcat
217 | ```java
218 | package com.adb.sample;
219 |
220 | import com.adb.process.ADBCtrl;
221 | import com.adb.process.Device;
222 | import com.adb.process.android.logcat.AndroidLogcat;
223 | import com.adb.process.android.logcat.LogcatConfig;
224 | import com.adb.process.android.logcat.LogcatConfigBuilder;
225 |
226 | public class LogcatSample {
227 | public static void main(String[] args) {
228 |
229 | Device android = new ADBCtrl().firstDevice();
230 | AndroidLogcat logcat = android.managerOfLogcat();
231 |
232 | //多参数日志过滤
233 | LogcatConfig config = new LogcatConfigBuilder()
234 | .filterTAG("BindView")//设置TAG
235 | .showFormat(LogcatConfig.FORMAT_BRIEF)//输出格式
236 | .filterLevel(LogcatConfig.LEVEL_W)//设置输出的日志等级
237 | .filter("3")//关键字过滤
238 | .build();
239 |
240 | logcat.print(config);
241 |
242 | logcat.listenLogcat(config, new ACtrl.IExecCallback() {
243 | @Override
244 | public void onCreatedProcess(Process process) {
245 |
246 | }
247 |
248 | @Override
249 | public void onReplyLine(String str) {
250 | //实时获取日志处理
251 | }
252 |
253 | @Override
254 | public void onErrorLine(String str) {
255 | //返回的错误信息
256 | }
257 | },false);//不打印日志,如果为true,则回调的同时打印输出日志
258 |
259 | }
260 | }
261 |
262 | ```
263 | ```java
264 | package com.adb.sample;
265 |
266 | import com.adb.process.ADBCtrl;
267 | import com.adb.process.Device;
268 | import com.adb.process.android.logcat.AndroidLogcat;
269 |
270 | public class LogcatSample {
271 | public static void main(String[] args) {
272 |
273 | Device android = new ADBCtrl().firstDevice();
274 | AndroidLogcat logcat = android.managerOfLogcat();
275 |
276 | String pid = android.managerOfApp().getPid("com.huangxiaowei.annotationtest");
277 |
278 | //将日志中TAG为"Test"的日志保存至设备
279 | logcat.save2AndroidFile("/mnt/sdcard/log.txt",pid);
280 |
281 | //将日志保存至window
282 | logcat.save2WindowFile2(true,"E:\\日志.log",pid);
283 | }
284 | }
285 | ```
286 |
287 |
288 | ### App
289 | ```java
290 | package com.adb.sample;
291 |
292 | import com.adb.process.ADBCtrl;
293 | import com.adb.process.Device;
294 | import com.adb.process.android.app.AndroidAPP;
295 |
296 | import java.io.IOException;
297 |
298 | public class APPSample {
299 | public static void main(String[] args) throws IOException {
300 |
301 | Device device = new ADBCtrl().firstDevice();
302 | if (device == null){
303 | System.out.println("找不到连接的设备");
304 | }
305 |
306 | AndroidAPP appCtrl = device.managerOfApp();
307 |
308 | //获取APP列表
309 | String list = appCtrl.listApp();
310 |
311 | System.out.println(list);
312 |
313 | //卸载应用
314 | boolean uninstallResult = appCtrl.uninstall("com.taobao.idlefish");
315 |
316 | //安装应用,非debug签名的apk,如果已经安装,则重新安装
317 | boolean installResult = appCtrl.install("E:\\BaiduNetdiskDownload\\FiddlerSetup.apk",false,true);
318 |
319 | //强制停止应用
320 | appCtrl.stopApp("com.taobao.idlefish");
321 |
322 | //读取应用的信息
323 | String msg = appCtrl.readAppInfo("com.xiaomi.youpin");
324 | System.out.println(msg);
325 |
326 | //如果应用正在运行,获取该进程的ID
327 | String pid = appCtrl.getPid("com.taobao.idlefish");
328 |
329 | //监听进程ID变化(一般发生进程崩溃/重启才会导致进程变化)
330 | ProcessManager process = new ProcessManager(device);
331 | process.startListenerOfProcess("com.huangxiaowei.joke", new ProcessManager.IListenerOfProcess() {
332 | @Override
333 | public void onChange(ProcessInfo info) {
334 | System.out.println("监听到进程变化,"+info.pid);
335 | }
336 |
337 | @Override
338 | public void onNoFoundPid() {
339 | System.out.println("找不到该进程");
340 | }
341 |
342 | @Override
343 | public void onError(String info) {
344 | System.out.println("Error:"+info);
345 | if (info.startsWith("error")){
346 | process.finish();//结束轮询
347 | }
348 |
349 | }
350 | },5);
351 |
352 |
353 |
354 | }
355 | }
356 |
357 |
358 | ```
359 | ### 其他可参考Sample
360 | https://github.com/zhixiaowei/ADBLib/tree/master/src/com/adb/sample
361 |
362 | ### 核心代码解析
363 |
364 |
365 | ### ADB指令部分参考
366 | https://github.com/mzlogin/awesome-adb
367 |
368 |
369 |
--------------------------------------------------------------------------------
/out/artifacts/ADBLib_jar/ADBLib.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhixiaowei/ADBLib/22fe0194eb7ca763beb33fe0d50cd1494ffe5261/out/artifacts/ADBLib_jar/ADBLib.jar
--------------------------------------------------------------------------------
/src/com/adb/sample/APPSample.java:
--------------------------------------------------------------------------------
1 | package com.adb.sample;
2 |
3 | import com.adb.process.ADBCtrl;
4 | import com.adb.process.Device;
5 | import com.adb.process.android.app.AndroidAPP;
6 | import com.adb.process.android.app.ProcessInfo;
7 | import com.adb.process.android.app.ProcessManager;
8 |
9 | import java.io.IOException;
10 |
11 | public class APPSample {
12 | public static void main(String[] args) throws IOException {
13 |
14 | Device device = new ADBCtrl().firstDevice();
15 | if (device == null){
16 | System.out.println("找不到连接的设备");
17 | }
18 |
19 | AndroidAPP appCtrl = device.managerOfApp();
20 |
21 | //获取APP列表
22 | String list = appCtrl.listApp();
23 |
24 | System.out.println(list);
25 |
26 | //卸载应用
27 | boolean uninstallResult = appCtrl.uninstall("com.taobao.idlefish");
28 |
29 | //安装应用,非debug签名的apk,如果已经安装,则重新安装
30 | boolean installResult = appCtrl.install("E:\\BaiduNetdiskDownload\\FiddlerSetup.apk",false,true);
31 |
32 | //强制停止应用
33 | appCtrl.stopApp("com.taobao.idlefish");
34 |
35 | //读取应用的信息
36 | String msg = appCtrl.readAppInfo("com.xiaomi.youpin");
37 | System.out.println(msg);
38 |
39 | //如果应用正在运行,获取该进程的ID
40 | String pid = appCtrl.getPid("com.taobao.idlefish");
41 |
42 | //监听进程ID变化(一般发生进程崩溃/重启才会导致进程变化)
43 | ProcessManager process = new ProcessManager(device);
44 | process.startListenerOfProcess("com.huangxiaowei.joke", new ProcessManager.IListenerOfProcess() {
45 | @Override
46 | public void onChange(ProcessInfo info) {
47 | System.out.println("监听到进程变化,"+info.pid);
48 | }
49 |
50 | @Override
51 | public void onNoFoundPid() {
52 | System.out.println("找不到该进程");
53 | }
54 |
55 | @Override
56 | public void onError(String info) {
57 | System.out.println("Error:"+info);
58 | if (info.startsWith("error")){
59 | process.finish();//结束轮询
60 | }
61 |
62 | }
63 | },5);
64 |
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/com/adb/sample/ActivitySample.java:
--------------------------------------------------------------------------------
1 | package com.adb.sample;
2 |
3 | import com.adb.process.ADBCtrl;
4 | import com.adb.process.Device;
5 | import com.adb.process.android.context.Activity;
6 | import com.adb.process.android.context.ActivityIntentBuilder;
7 | import com.adb.process.android.context.IContext;
8 |
9 | public class ActivitySample {
10 | public static void main(String[] args) {
11 | Device context = new ADBCtrl().firstDevice();
12 | Activity activity = new Activity(context);
13 |
14 | //根据包名启动应用(进入默认Activity)
15 | activity.start("com.huangxiaowei.annotationtest");
16 |
17 | //启动指定Activity
18 | activity.start("com.hxw.test","com.hxw.test.MainActivity");
19 |
20 | //带参数启动Activity
21 | IContext.Intent intent = new ActivityIntentBuilder("android.intent.action.TestActivity",
22 | "com.huangxiaowei.annotationtest",
23 | "com.huangxiaowei.annotationtest.TestActivity")
24 | .addExtra("KEY","这是一个Value")
25 | .build();
26 | activity.start(intent);
27 |
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/com/adb/sample/BroadcastSample.java:
--------------------------------------------------------------------------------
1 | package com.adb.sample;
2 |
3 | import com.adb.process.ADBCtrl;
4 | import com.adb.process.android.context.Broadcast;
5 | import com.adb.process.android.context.BroadcastIntentBuilder;
6 | import com.adb.process.android.context.IContext;
7 |
8 | public class BroadcastSample {
9 |
10 | public static void main(String[] args) {
11 |
12 | Broadcast broadcast = new Broadcast(new ADBCtrl().firstDevice());
13 |
14 | IContext.Intent intent =
15 | new BroadcastIntentBuilder("com.hxw.test")//ACTION
16 | .addExtra("数组",new int[]{1,2,3,4})
17 | .addExtra("KeyOfString","i am string")
18 | .addExtra("KeyOfBoolean",false)
19 | .addExtra("KeyOfLong",Long.valueOf("12433333399"))
20 | .build();
21 | broadcast.send(intent);//发送广播
22 |
23 | broadcast.send(Broadcast.BOOT_COMPLETED);//发送开机广播
24 |
25 | broadcast.send("com.hxw.hi");//发送指定Action的广播
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/com/adb/sample/CommonSample.java:
--------------------------------------------------------------------------------
1 | package com.adb.sample;
2 |
3 | import com.adb.process.ADBCtrl;
4 | import com.adb.process.Device;
5 | import com.adb.process.android.AndroidSystem;
6 | import com.adb.process.android.context.Activity;
7 |
8 | public class CommonSample {
9 | public static void main(String[] args) {
10 |
11 | //如果已经配置过ADB环境变量,则可以
12 | ADBCtrl adb = new ADBCtrl();
13 |
14 | //在未配置ADB环境变量的情况下可以通过调用
15 | ADBCtrl adb1 = new ADBCtrl("E:\\tool\\adbDir\\");
16 |
17 | adb.setCharset("GBK");//设置编码格式,默认为GBK,可不设置
18 | adb.isPrintCmd(true);//是否打印执行的命令
19 |
20 | //获取已连接的设备
21 | Device[] device = adb.listDevices();
22 |
23 | //如果我们确定连接的设备只有一个或者操作任一台设备均可,无需进行选择时,也可以直接调用
24 | Device device1 = adb.firstDevice();
25 |
26 | AndroidSystem system = device1.managerOfSystem();
27 | system.listProcess(null);//获取系统进程等
28 | //详情可看 com.adb.sample.AndroidSystemSample
29 |
30 | Activity activity = device1.managerOfActivity();
31 | activity.start("com.hxw.test");
32 | //详情可看 com.adb.sample.ActivitySample
33 |
34 | //其他API可阅其他Sample
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/com/adb/sample/EventSample.java:
--------------------------------------------------------------------------------
1 | package com.adb.sample;
2 |
3 | import com.adb.process.ADBCtrl;
4 | import com.adb.process.Device;
5 | import com.adb.process.android.event.AndroidEvent;
6 | import com.adb.process.android.event.ClickEventManager;
7 | import com.adb.process.android.event.KeyCode;
8 |
9 | public class EventSample {
10 | public static void main(String[] args) {
11 |
12 | Device device = new ADBCtrl().firstDevice();
13 | if (device == null){
14 | System.out.println("找不到连接的设备");
15 | }
16 |
17 | AndroidEvent androidEvent = device.managerOfEvent();
18 |
19 | // //点击指定坐标
20 | // androidEvent.click(230,449);
21 | //
22 | // //滑动
23 | // androidEvent.swipe(230,449,200,440);
24 | //
25 | // androidEvent.inputKeyEvent(KeyCode.KEYCODE_BACK);//执行返回键
26 |
27 | //监听设备的点击/滑动/松开事件
28 | androidEvent.listenOfClickEvent(new ClickEventManager.IEventCallback() {
29 | @Override
30 | public void onCreateProcess(Process process) {
31 | //获取Process,并在需要的时候调用process结束任务
32 | }
33 |
34 | @Override
35 | public void onEventDown(int x, int y) {
36 | System.out.println("点击坐标:("+x+","+y+")");
37 |
38 | // androidEvent.click(x,y); //可以通过click点击同样位置,但不能在这个地方写,会导致死循环的
39 | }
40 |
41 | @Override
42 | public void onEventUp(int x, int y) {
43 | System.out.println("松开:("+x+","+y+")");
44 | }
45 |
46 | @Override
47 | public void onEventMove(int x, int y) {
48 | System.out.println("滑动坐标:("+x+","+y+")");
49 | }
50 |
51 | @Override
52 | public void onError(String msg) {
53 | //执行错误时,回调该方法
54 | }
55 | });
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/com/adb/sample/FileSample.java:
--------------------------------------------------------------------------------
1 | package com.adb.sample;
2 |
3 | import com.adb.process.ADBCtrl;
4 | import com.adb.process.android.AndroidFile;
5 |
6 | /**
7 | * 文件操作
8 | */
9 | public class FileSample {
10 |
11 | public static void main(String[] args) {
12 | AndroidFile fileCtrl = new ADBCtrl().firstDevice().managerOfFile();
13 |
14 | //从Android拷贝文件到电脑
15 | fileCtrl.copyFileAndroid2Window("/mnt/sdcard/image.png","E:\\Download\\image.png");
16 |
17 | //从电脑端拷贝文件到Android
18 | fileCtrl.copyFileWindow2Android("/mnt/sdcard/image.png","E:\\Download\\image.png");
19 |
20 | //读取Android端的文件文件
21 | String text = fileCtrl.readTextFile("/mnt/sdcard/log.txt");
22 |
23 | //获取文件夹下的文件列表
24 | String list = fileCtrl.listDir("/mnt/sdcard/");
25 |
26 | //删除文件夹下以.xml 为结尾的文件
27 | fileCtrl.delDirFileBySuffix("/mnt/sdcard/",".xml");
28 |
29 | //删除文件夹及文件夹下的所有文件
30 | fileCtrl.deleteDir(true,"/mnt/sdcard/image/");
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/src/com/adb/sample/HardwareSample.java:
--------------------------------------------------------------------------------
1 | package com.adb.sample;
2 |
3 | import com.adb.process.ADBCtrl;
4 | import com.adb.process.android.AndroidHardware;
5 |
6 | public class HardwareSample {
7 |
8 | public static void main(String[] args) {
9 | AndroidHardware hardware = new ADBCtrl().firstDevice().managerOfHardware();
10 |
11 | hardware.screenDensity();//屏幕密度
12 | hardware.screenSize();//屏幕分辨率
13 | hardware.screenInfo();//屏幕详细信息
14 |
15 | hardware.getBatteryInfo();//电池信息(总量、余量等)
16 |
17 | hardware.getCPUInfo();//CPU信息
18 |
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/com/adb/sample/LogcatSample.java:
--------------------------------------------------------------------------------
1 | package com.adb.sample;
2 |
3 | import com.adb.process.ACtrl;
4 | import com.adb.process.ADBCtrl;
5 | import com.adb.process.Device;
6 | import com.adb.process.android.logcat.AndroidLogcat;
7 | import com.adb.process.android.logcat.LogcatConfig;
8 | import com.adb.process.android.logcat.LogcatConfigBuilder;
9 |
10 | public class LogcatSample {
11 | public static void main(String[] args) {
12 |
13 | Device android = new ADBCtrl().firstDevice();
14 | AndroidLogcat logcat = android.managerOfLogcat();
15 |
16 | String pid = android.managerOfApp().getPid("com.huangxiaowei.annotationtest");
17 |
18 | //将日志中TAG为"Test"的日志保存至设备
19 | logcat.save2AndroidFile("/mnt/sdcard/log.txt",pid);
20 |
21 | //将日志保存至window
22 | logcat.save2WindowFile2(true,"E:\\日志.log",pid);
23 |
24 | //输出日志,过滤字为"Test"
25 | logcat.print("Test");
26 |
27 | //配合进程ID过滤日志
28 | logcat.printByPid(pid);//将Pid作为过滤条件
29 |
30 | //多参数日志过滤
31 | android.isPrintCmd(true);
32 | LogcatConfig config = new LogcatConfigBuilder()
33 | .filterTAG("BindView")//设置TAG
34 | .filterPackageName("com.huangxiaowei.joke")//仅显示该应用(进程)的日志
35 | .showFormat(LogcatConfig.FORMAT_BRIEF)//输出格式
36 | .filterLevel(LogcatConfig.LEVEL_W)//设置输出的日志等级
37 | .filter("3")//关键字过滤
38 | .build();
39 |
40 | logcat.print(config);//直接
41 |
42 |
43 | logcat.listenLogcat(config, new ACtrl.IExecCallback() {
44 | @Override
45 | public void onCreatedProcess(Process process) {
46 |
47 | }
48 |
49 | @Override
50 | public void onReplyLine(String str) {
51 | //实时获取日志
52 | System.out.println(str);
53 | }
54 |
55 | @Override
56 | public void onErrorLine(String str) {
57 | System.out.println(str);
58 | }
59 | },false);
60 |
61 |
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/com/adb/sample/NetworkSample.java:
--------------------------------------------------------------------------------
1 | package com.adb.sample;
2 |
3 | import com.adb.process.ADBCtrl;
4 | import com.adb.process.android.AndroidNetwork;
5 |
6 | public class NetworkSample {
7 | public static void main(String[] args) {
8 | AndroidNetwork network = new AndroidNetwork(new ADBCtrl().firstDevice());
9 |
10 | network.ping("www.baidu.com",3,true);
11 |
12 | network.isPreferWifi(false);//当4G和WIFI同时打开,是否WIFI优先
13 |
14 | network.setNetSwitch(true);//打开4G网络
15 | network.setWifiSwitch(false);//关闭WIFI
16 |
17 | network.getLocalAddress();//获取本地IP地址
18 |
19 | System.out.println(network.connectivity());
20 |
21 | System.out.println(network.netPolicy());
22 |
23 | System.out.println(network.netStatus());
24 |
25 | System.out.println(network.networkManagement());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/com/adb/sample/ServiceSample.java:
--------------------------------------------------------------------------------
1 | package com.adb.sample;
2 |
3 | import com.adb.process.ADBCtrl;
4 | import com.adb.process.android.context.IContext;
5 | import com.adb.process.android.context.Service;
6 | import com.adb.process.android.context.ServiceInentBuilder;
7 |
8 | public class ServiceSample {
9 |
10 | public static void main(String[] args) {
11 |
12 | Service service = new Service(new ADBCtrl().listDevices()[0]);
13 |
14 | service.getAllRunningService(null);//获取正在运行的服务,参数为指定应用的包名
15 |
16 | //带参数启动服务
17 | IContext.Intent intent = new ServiceInentBuilder("com.hxw.test","com.hxw.test.MainService")
18 | .addExtra("KEY","VALUE").build();
19 | service.startService(intent);
20 |
21 | //无参数启动服务
22 | service.startService("com.hxw.test","com.hxw.test.MainService");
23 |
24 | //停止服务
25 | service.stopService("com.hxw.test","com.hxw.test.MainService");
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/com/adb/sample/SystemSample.java:
--------------------------------------------------------------------------------
1 | package com.adb.sample;
2 |
3 | import com.adb.process.ADBCtrl;
4 | import com.adb.process.Device;
5 | import com.adb.process.android.AndroidSystem;
6 |
7 | public class SystemSample {
8 |
9 | public static void main(String[] args) {
10 | Device context = new ADBCtrl().firstDevice();
11 | AndroidSystem system = new AndroidSystem(context);
12 |
13 | system.location();//位置信息
14 |
15 | system.date();//系统时间
16 |
17 | system.devBrand();//品牌
18 |
19 | system.devIMEI();//IMEI
20 |
21 | system.devModel();//型号
22 |
23 | system.SDKVersion();//SDK版本
24 |
25 | system.SystemVersion();//系统版本
26 |
27 | system.listProcess(null);//获取当前正在执行的进程
28 |
29 |
30 |
31 | }
32 | }
33 |
--------------------------------------------------------------------------------