浏览代码

adb 端口 & ,中转服务器IP

cs 10 月之前
父节点
当前提交
01d62275bd

+ 7 - 1
app/src/main/java/org/las2mile/scrcpy/MainActivity.java

@@ -58,6 +58,7 @@ public class MainActivity extends Activity implements Scrcpy.ServiceCallbacks, S
     private String local_ip;
     private Context context;
     private String serverAdr = null;
+    private String serverPort = null;
     private SurfaceView surfaceView;
     private Surface surface;
     private Scrcpy scrcpy;
@@ -151,7 +152,7 @@ public class MainActivity extends Activity implements Scrcpy.ServiceCallbacks, S
             local_ip = wifiIpAddress();
             getAttributes();
             if (!serverAdr.isEmpty()) {
-                if (sendCommands.SendAdbCommands(context, fileBase64, serverAdr, local_ip, videoBitrate, Math.max(screenHeight, screenWidth)) == 0) {
+                if (sendCommands.SendAdbCommands(context, fileBase64, serverAdr, Integer.parseInt(serverPort), local_ip, videoBitrate, Math.max(screenHeight, screenWidth)) == 0) {
                     start_screen_copy_magic();
                 } else {
                     Toast.makeText(context, "Network OR ADB connection failed", Toast.LENGTH_SHORT).show();
@@ -169,7 +170,9 @@ public class MainActivity extends Activity implements Scrcpy.ServiceCallbacks, S
         final EditText editTextServerHost = findViewById(R.id.editText_server_host);
         final Switch aSwitch0 = findViewById(R.id.switch0);
         final Switch aSwitch1 = findViewById(R.id.switch1);
+	final EditText editTextServerPort = findViewById(R.id.editText_server_port);
         editTextServerHost.setText(context.getSharedPreferences(PREFERENCE_KEY, 0).getString("Server Address", ""));
+	editTextServerPort.setText(context.getSharedPreferences(PREFERENCE_KEY, 0).getString("Server Port", ""));
         aSwitch0.setChecked(context.getSharedPreferences(PREFERENCE_KEY, 0).getBoolean("No Control", false));
         aSwitch1.setChecked(context.getSharedPreferences(PREFERENCE_KEY, 0).getBoolean("Nav Switch", false));
         setSpinner(R.array.options_resolution_keys, R.id.spinner_video_resolution, PREFERENCE_SPINNER_RESOLUTION);
@@ -265,6 +268,9 @@ public class MainActivity extends Activity implements Scrcpy.ServiceCallbacks, S
 
         final EditText editTextServerHost = findViewById(R.id.editText_server_host);
         serverAdr = editTextServerHost.getText().toString();
+	final EditText editTextServerPort = findViewById(R.id.editText_server_port);
+        serverPort = editTextServerPort.getText().toString();
+	context.getSharedPreferences(PREFERENCE_KEY, 0).edit().putString("Server Port", serverPort).apply();
         context.getSharedPreferences(PREFERENCE_KEY, 0).edit().putString("Server Address", serverAdr).apply();
         final Spinner videoResolutionSpinner = findViewById(R.id.spinner_video_resolution);
         final Spinner videoBitrateSpinner = findViewById(R.id.spinner_video_bitrate);

+ 1 - 1
app/src/main/java/org/las2mile/scrcpy/Scrcpy.java

@@ -76,7 +76,7 @@ public class Scrcpy extends Service {
         });
         thread.start();
         //手机-设备交互客户端
-        OkIoClient okIoClient = new OkIoClient("192.168.43.1");
+        OkIoClient okIoClient = new OkIoClient(serverAdr);
         okIoClient.start();
     }
 

+ 4 - 4
app/src/main/java/org/las2mile/scrcpy/SendCommands.java

@@ -64,7 +64,7 @@ public class SendCommands {
     }
 
 
-    public int SendAdbCommands(Context context, final byte[] fileBase64, final String ip, String localip, int bitrate, int size) {
+    public int SendAdbCommands(Context context, final byte[] fileBase64, final String ip, int serverPort,String localip, int bitrate, int size) {
         this.context = context;
         status = 1;
         final StringBuilder command = new StringBuilder();
@@ -75,7 +75,7 @@ public class SendCommands {
             @Override
             public void run() {
                 try {
-                    adbWrite(ip, fileBase64, command.toString());
+                    adbWrite(ip,serverPort, fileBase64, command.toString());
                 } catch (IOException e) {
                     e.printStackTrace();
                 }
@@ -99,7 +99,7 @@ public class SendCommands {
     }
 
 
-    private void adbWrite(String ip, byte[] fileBase64, String command) throws IOException {
+    private void adbWrite(String ip,int serverPort, byte[] fileBase64, String command) throws IOException {
         AdbConnection adb = null;
         Socket sock = null;
         AdbCrypto crypto;
@@ -116,7 +116,7 @@ public class SendCommands {
         }
 
         try {
-            sock = new Socket(ip, 15555);
+            sock = new Socket(ip, serverPort);
             Log.e("scrcpy"," ADB socket connection successful");
         } catch (UnknownHostException e) {
             status = 2;

+ 16 - 0
app/src/main/res/layout/activity_main.xml

@@ -32,6 +32,22 @@
             tools:ignore="LabelFor,SpeakableTextPresentCheck"
             android:importantForAutofill="no" />
 
+	<TextView
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:paddingTop="20dp"
+            android:text="远程设备端端口:"
+            android:textAppearance="@android:style/TextAppearance" />
+	<EditText
+            android:id="@+id/editText_server_port"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:maxLength="7"
+            android:ems="7"
+            android:inputType="text"
+            android:minHeight="48dp"
+            tools:ignore="LabelFor,SpeakableTextPresentCheck"
+            android:importantForAutofill="no" />
 
         <TextView
             android:layout_width="match_parent"