3
3
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
4
4
*/
5
5
6
- import java .io .*;
6
+ import java .io .BufferedReader ;
7
+ import java .io .IOException ;
8
+ import java .io .InputStreamReader ;
7
9
import java .util .*;
10
+ import java .util .regex .Matcher ;
11
+ import java .util .regex .Pattern ;
8
12
9
13
/**
10
14
*
13
17
public class Scrcpy_GUI {
14
18
15
19
/**
16
- * Method to list devices connected to the computer,
17
- * this method execute {@code adb devices} command using ProcessBuilder.
18
- *
20
+ * Method to list devices connected to the computer, this method execute
21
+ * {@code adb devices} command using ProcessBuilder.
22
+ *
19
23
* @return {@code List<String> output}
20
24
* @author opelooo
21
25
*/
@@ -44,12 +48,13 @@ public static List<String> adb_devices() {
44
48
45
49
return output ;
46
50
}
47
-
51
+
48
52
/**
49
- * Method to run scrcpy,
50
- * this method execute {@code scrcpy -s device_code -m 1024 -b 2M} command using ProcessBuilder.
51
- *
53
+ * Method to run scrcpy, this method execute
54
+ * {@code scrcpy -s device_code -m 1024 -b 2M} command using ProcessBuilder.
55
+ *
52
56
* @param device_code device ID from adb devices list
57
+ *
53
58
* @author opelooo
54
59
*/
55
60
public static void run_scrcpy (String device_code ) {
@@ -68,20 +73,67 @@ public static void run_scrcpy(String device_code) {
68
73
}
69
74
}).start (); // Start the new thread
70
75
}
71
-
76
+
77
+ /**
78
+ * Method to customize run scrcpy, this method execute
79
+ * {@code scrcpy -s device_code -m 1024 -b 2M} command using ProcessBuilder.
80
+ *
81
+ * @param device_code device ID from adb devices list
82
+ * @param maxSize maximum size of mirroring panel
83
+ * @param bitRate bit rate transfer for mirroring
84
+ * @param videoOn toggle mirror the video
85
+ * @param screenOn toggle phone screen on or off
86
+ * @param stayAwake toggle option to stay awake mode
87
+ *
88
+ * @author opelooo
89
+ */
90
+ public static void custom_run_scrcpy (
91
+ String device_code , String maxSize , String bitRate ,
92
+ boolean videoOn , boolean screenOn , boolean stayAwake ) {
93
+ new Thread (() -> {
94
+ try {
95
+ // creating list of process
96
+ List <String > list = new ArrayList <>();
97
+ list .add ("scrcpy" );
98
+ list .add ("-s" );
99
+ list .add (device_code );
100
+ list .add (String .format ("-m %s" , maxSize ));
101
+ list .add (String .format ("-b %s" , bitRate ));
102
+
103
+ if (!videoOn ) {
104
+ list .add ("--no-video" );
105
+ }
106
+ if (!screenOn ) {
107
+ list .add ("--turn-screen-off" );
108
+ }
109
+ if (stayAwake ) {
110
+ list .add ("--stay-awake" );
111
+ }
112
+
113
+ // Create a process
114
+ ProcessBuilder pb = new ProcessBuilder (list );
115
+
116
+ pb .start ();
117
+ // Optionally, monitor the process if needed
118
+ } catch (IOException e ) {
119
+ e .printStackTrace (); // Handle exceptions properly
120
+ }
121
+ }).start (); // Start the new thread
122
+ }
123
+
72
124
/**
73
- * Method to get device info product manufaturer,
74
- * this method execute
75
- * {@code adb -s device_code shell getprop ro.product.manufacturer} command using ProcessBuilder.
76
- *
125
+ * Method to get device info product manufaturer, this method execute
126
+ * {@code adb -s device_code shell getprop ro.product.manufacturer} command
127
+ * using ProcessBuilder.
128
+ *
77
129
* @param device_code device ID from adb devices list
78
- * @return {@code String output}
130
+ * @return {@code String output}
79
131
* @author opelooo
80
132
*/
81
133
public static String adb_device_info (String device_code ) {
82
134
String output = new String ();
83
135
try {
84
- // Create a process to execute 'adb devices'
136
+ // Create a process
85
137
ProcessBuilder pb
86
138
= new ProcessBuilder (
87
139
"adb" , "-s" , device_code , "shell" ,
@@ -107,9 +159,54 @@ public static String adb_device_info(String device_code) {
107
159
108
160
return output ;
109
161
}
162
+
163
+ /**
164
+ * Method to get device info IP Address, this method execute
165
+ * {@code adb -s device_code shell ip route} command
166
+ * using ProcessBuilder. After that, the output filtered using regex.
167
+ *
168
+ * @param device_code device ID from adb devices list
169
+ * @return {@code String device_ip_addr}
170
+ * @author opelooo
171
+ */
172
+ public static String adb_get_device_ip (String device_code ) {
173
+ String device_ip_addr = new String ();
174
+ try {
175
+ // Create a process to execute 'adb devices'
176
+ ProcessBuilder pb
177
+ = new ProcessBuilder (
178
+ "adb" , "-s" , device_code , "shell" ,
179
+ "ip" , "route"
180
+ );
181
+ Process process = pb .start ();
110
182
111
- public static void adb_connect_tcpip () {
183
+ String regex = "src (\\ b(?:\\ d{1,3}\\ .){3}\\ d{1,3}\\ b)" ;
184
+
185
+ BufferedReader reader = new BufferedReader (new InputStreamReader (process .getInputStream ()));
186
+ String line ;
187
+
188
+ while ((line = reader .readLine ()) != null ) {
189
+ // Compile the pattern and create a matcher
190
+ Pattern pattern = Pattern .compile (regex );
191
+ Matcher matcher = pattern .matcher (line .trim ());
192
+
193
+ // If an IP address is found, assign it to device_ip_addr
194
+ if (line .contains ("wlan" ) && matcher .find ()) {
195
+ device_ip_addr = matcher .group (1 );
196
+ }
197
+ }
198
+
199
+ // Wait for the process to complete
200
+ process .waitFor ();
201
+ } catch (IOException | InterruptedException e ) {
202
+ e .printStackTrace (); // Handle exceptions properly
203
+ }
204
+
205
+ return device_ip_addr ;
206
+ }
112
207
208
+ public static void adb_connect_tcpip (String device_code ) {
209
+
113
210
}
114
211
115
212
}
0 commit comments