Skip to content

Commit

Permalink
更新V1.4.5
Browse files Browse the repository at this point in the history
- 修复激活检测的Bug
- 支持关闭剪切板同步
- 支持自定义服务端口
- 修复部分bug
  • Loading branch information
mingzhixian committed Apr 10, 2024
1 parent 558904a commit 38325d0
Show file tree
Hide file tree
Showing 28 changed files with 365 additions and 173 deletions.
4 changes: 2 additions & 2 deletions easycontrol/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "top.saymzx.easycontrol.app"
minSdk 21
targetSdk 34
versionCode 10403
versionName "1.4.3"
versionCode 10405
versionName "1.4.5"
ndk {
abiFilters "arm64-v8a", "armeabi-v7a", "x86", "x86_64"
}
Expand Down
3 changes: 1 addition & 2 deletions easycontrol/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTask">
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ private void drawUI() {
// 预填写参数
activityDeviceDetailBinding.name.setText(device.name);
activityDeviceDetailBinding.address.setText(device.address);
activityDeviceDetailBinding.startApp.setText(device.startApp);
activityDeviceDetailBinding.adbPort.setText(String.valueOf(device.adbPort));
activityDeviceDetailBinding.serverPort.setText(String.valueOf(device.serverPort));
activityDeviceDetailBinding.customResolution.setVisibility(device.customResolutionOnConnect ? View.VISIBLE : View.GONE);
activityDeviceDetailBinding.customResolutionWidth.setText(String.valueOf(device.customResolutionWidth));
activityDeviceDetailBinding.customResolutionHeight.setText(String.valueOf(device.customResolutionHeight));
Expand All @@ -74,6 +77,7 @@ private void drawUI() {
activityDeviceDetailBinding.layoutOnConnectSub.addView(ViewTools.createSwitchCard(this, getString(R.string.device_change_to_full_on_connect), getString(R.string.device_change_to_full_on_connect_detail), device.changeToFullOnConnect, isChecked -> device.changeToFullOnConnect = isChecked).getRoot());
// 运行时操作
activityDeviceDetailBinding.layoutOnRunning.setOnClickListener(v -> activityDeviceDetailBinding.layoutOnRunningSub.setVisibility(activityDeviceDetailBinding.layoutOnRunningSub.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE));
activityDeviceDetailBinding.layoutOnRunningSub.addView(ViewTools.createSwitchCard(this, getString(R.string.device_listen_clip_on_running), getString(R.string.device_listen_clip_on_running_detail), device.listenClip, isChecked -> device.listenClip = isChecked).getRoot());
activityDeviceDetailBinding.layoutOnRunningSub.addView(ViewTools.createSwitchCard(this, getString(R.string.device_keep_wake_on_running), getString(R.string.device_keep_wake_on_running_detail), device.keepWakeOnRunning, isChecked -> device.keepWakeOnRunning = isChecked).getRoot());
activityDeviceDetailBinding.layoutOnRunningSub.addView(ViewTools.createSwitchCard(this, getString(R.string.device_change_resolution_on_running), getString(R.string.device_change_resolution_on_running_detail), device.changeResolutionOnRunning, isChecked -> device.changeResolutionOnRunning = isChecked).getRoot());
activityDeviceDetailBinding.layoutOnRunningSub.addView(ViewTools.createSwitchCard(this, getString(R.string.device_small_to_mini_on_running), getString(R.string.device_small_to_mini_on_running_detail), device.smallToMiniOnRunning, isChecked -> device.smallToMiniOnRunning = isChecked).getRoot());
Expand Down Expand Up @@ -110,7 +114,10 @@ private void setListener() {
return;
}
device.name = name;
device.address = device.isLinkDevice() ? device.uuid + (address.contains("#") ? ("#" + address.split("#")[1]) : "") : address;
device.address = device.isLinkDevice() ? device.uuid : address;
device.startApp = String.valueOf(activityDeviceDetailBinding.startApp.getText());
device.adbPort = Integer.parseInt(String.valueOf(activityDeviceDetailBinding.adbPort.getText()));
device.serverPort = Integer.parseInt(String.valueOf(activityDeviceDetailBinding.serverPort.getText()));
// 自定义分辨率
String width = String.valueOf(activityDeviceDetailBinding.customResolutionWidth.getText());
String height = String.valueOf(activityDeviceDetailBinding.customResolutionHeight.getText());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void onCreate(Bundle savedInstanceState) {

private void drawUi() {
// 添加IP
Pair<ArrayList<String>, ArrayList<String>> listPair = PublicTools.getIp();
Pair<ArrayList<String>, ArrayList<String>> listPair = PublicTools.getLocalIp();
for (String i : listPair.first) {
ItemTextBinding text = ViewTools.createTextCard(this, i, () -> {
AppData.clipBoard.setPrimaryClip(ClipData.newPlainText(ClipDescription.MIMETYPE_TEXT_PLAIN, i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,19 @@

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.content.ContentResolver;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.OpenableColumns;
import android.provider.Settings;
import android.view.LayoutInflater;

import java.io.IOException;
import java.io.InputStream;

import top.saymzx.easycontrol.app.client.Client;
import top.saymzx.easycontrol.app.client.tools.AdbTools;
import top.saymzx.easycontrol.app.databinding.ActivityMainBinding;
import top.saymzx.easycontrol.app.databinding.ItemRequestPermissionBinding;
import top.saymzx.easycontrol.app.entity.AppData;
import top.saymzx.easycontrol.app.entity.Device;
import top.saymzx.easycontrol.app.helper.DeviceListAdapter;
Expand All @@ -43,19 +38,6 @@ public void onCreate(Bundle savedInstanceState) {
ViewTools.setLocale(this);
activityMainBinding = ActivityMainBinding.inflate(this.getLayoutInflater());
setContentView(activityMainBinding.getRoot());
// 检测权限
if (!checkPermission()) createAlert();
else startApp();
}

@Override
protected void onDestroy() {
myBroadcastReceiver.unRegister(this);
super.onDestroy();
}

// 启动步骤
private void startApp() {
// 检测激活
checkActive();
// 设置设备列表适配器
Expand All @@ -74,47 +56,17 @@ private void startApp() {
}, 2000);
}

@Override
protected void onDestroy() {
myBroadcastReceiver.unRegister(this);
super.onDestroy();
}

// 检测激活
private void checkActive() {
if (!AppData.setting.getIsActive()) startActivity(new Intent(this, ActiveActivity.class));
}

// 检查权限
private boolean checkPermission() {
// 检查悬浮窗权限,防止某些设备如鸿蒙不兼容
try {
return Build.VERSION.SDK_INT < Build.VERSION_CODES.M || Settings.canDrawOverlays(this);
} catch (Exception ignored) {
return true;
}
}

// 创建Client加载框
private void createAlert() {
ItemRequestPermissionBinding requestPermissionView = ItemRequestPermissionBinding.inflate(LayoutInflater.from(this));
requestPermissionView.buttonGoToSet.setOnClickListener(v -> {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
intent.setData(Uri.parse("package:$packageName"));
startActivity(intent);
}
});
Dialog dialog = ViewTools.createDialog(this, false, requestPermissionView.getRoot());
dialog.show();
checkPermissionDelay(dialog);
}

// 定时检查
private void checkPermissionDelay(Dialog dialog) {
// 因为某些设备可能会无法进入设置或其他问题,导致不会有返回结果,为了减少不确定性,使用定时检测的方法
AppData.uiHandler.postDelayed(() -> {
if (checkPermission()) {
dialog.cancel();
startApp();
} else checkPermissionDelay(dialog);
}, 1000);
}

// 设置按钮监听
private void setButtonListener() {
activityMainBinding.buttonAdd.setOnClickListener(v -> startActivity(new Intent(this, DeviceDetailActivity.class)));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
package top.saymzx.easycontrol.app;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;

import top.saymzx.easycontrol.app.entity.AppData;
import top.saymzx.easycontrol.app.helper.MyBroadcastReceiver;

public class UsbActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent();
intent.setAction(MyBroadcastReceiver.ACTION_UPDATE_USB);
sendBroadcast(intent);
startActivity(new Intent(this, MainActivity.class));
SharedPreferences sharedPreferences = this.getSharedPreferences("setting", Context.MODE_PRIVATE);
if (sharedPreferences.getBoolean("isActive", false)) {
Intent intent = new Intent();
intent.setAction(MyBroadcastReceiver.ACTION_UPDATE_USB);
sendBroadcast(intent);
if (AppData.mainActivity == null) startActivity(new Intent(this, MainActivity.class));
}
finish();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public class Adb {

private final Thread handleInThread = new Thread(this::handleIn);

public Adb(Pair<String, Integer> address, AdbKeyPair keyPair) throws Exception {
channel = new TcpChannel(address.first, address.second);
public Adb(String address,int port, AdbKeyPair keyPair) throws Exception {
channel = new TcpChannel(address, port);
connect(keyPair);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package top.saymzx.easycontrol.app.client.tools;

import android.hardware.usb.UsbDevice;
import android.util.Log;

import java.io.InputStream;
import java.util.ArrayList;
Expand All @@ -22,14 +21,12 @@ public class AdbTools {

// 连接ADB
public static Adb connectADB(Device device) throws Exception {
String address = device.address;
// 如果包含应用名,则需要要分割出地址
if (address.contains("#")) address = address.split("#")[0];
Adb adb = allAdbConnect.get(address);
String addressId = device.isLinkDevice() ? device.uuid : device.address + ":" + device.adbPort;
Adb adb = allAdbConnect.get(addressId);
if (adb == null || adb.isClosed()) {
if (device.isLinkDevice()) adb = new Adb(usbDevicesList.get(address), AppData.keyPair);
else adb = new Adb(PublicTools.getIpAndPort(address), AppData.keyPair);
allAdbConnect.put(address, adb);
if (device.isLinkDevice()) adb = new Adb(usbDevicesList.get(addressId), AppData.keyPair);
else adb = new Adb(PublicTools.getIp(device.address), device.adbPort, AppData.keyPair);
allAdbConnect.put(addressId, adb);
}
return adb;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import android.content.ClipData;
import android.content.Intent;
import android.graphics.SurfaceTexture;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
import android.provider.Settings;
import android.util.Pair;
import android.view.Display;
import android.view.MotionEvent;
Expand Down Expand Up @@ -168,14 +170,34 @@ private synchronized void changeToFull() {

private synchronized void changeToSmall() {
hide();
if (smallView == null) smallView = new SmallView(device.uuid);
AppData.uiHandler.post(smallView::show);
if (noFloatPermission()) {
PublicTools.logToast("controller", AppData.applicationContext.getString(R.string.toast_float_per), true);
changeToFull();
} else {
if (smallView == null) smallView = new SmallView(device.uuid);
AppData.uiHandler.post(smallView::show);
}
}

private synchronized void changeToMini(ByteBuffer byteBuffer) {
hide();
if (miniView == null) miniView = new MiniView(device.uuid);
AppData.uiHandler.post(() -> miniView.show(byteBuffer));
if (noFloatPermission()) {
PublicTools.logToast("controller", AppData.applicationContext.getString(R.string.toast_float_per), true);
changeToFull();
} else {
if (miniView == null) miniView = new MiniView(device.uuid);
AppData.uiHandler.post(() -> miniView.show(byteBuffer));
}
}

// 检查悬浮窗权限
private boolean noFloatPermission() {
// 检查悬浮窗权限,防止某些设备如鸿蒙不兼容
try {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(AppData.applicationContext);
} catch (Exception ignored) {
return false;
}
}

private synchronized void changeToApp() throws Exception {
Expand All @@ -187,7 +209,7 @@ private synchronized void changeToApp() throws Exception {
if (matcher.find()) {
Device tempDevice = device.clone(String.valueOf(UUID.randomUUID()));
tempDevice.name = "----";
tempDevice.address = tempDevice.address + "#" + matcher.group(1);
tempDevice.startApp = matcher.group(1);
// 为了错开界面
tempDevice.smallX += 200;
tempDevice.smallY += 200;
Expand Down Expand Up @@ -290,6 +312,7 @@ private void createTouchPacket(MotionEvent event, int action, int i) {
private String nowClipboardText = "";

private void checkClipBoard() {
if (!device.listenClip) return;
ClipData clipBoard = AppData.clipBoard.getPrimaryClip();
if (clipBoard != null && clipBoard.getItemCount() > 0) {
String newClipBoardText = String.valueOf(clipBoard.getItemAt(0).getText());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,17 @@ private void startServer(Device device) throws Exception {
adb.pushFile(AppData.applicationContext.getResources().openRawResource(R.raw.easycontrol_server), serverName, null);
}
shell = adb.getShell();
String startApp = device.address.contains("#") ? device.address.split("#")[1] : "";
shell.write(ByteBuffer.wrap(("app_process -Djava.class.path=" + serverName + " / top.saymzx.easycontrol.server.Server"
+ " serverPort=" + device.serverPort
+ " listenClip=" + (device.listenClip ? 1 : 0)
+ " isAudio=" + (device.isAudio ? 1 : 0)
+ " maxSize=" + device.maxSize
+ " maxFps=" + device.maxFps
+ " maxVideoBit=" + device.maxVideoBit
+ " keepAwake=" + (device.keepWakeOnRunning ? 1 : 0)
+ " supportH265=" + ((device.useH265 && supportH265) ? 1 : 0)
+ " supportOpus=" + (supportOpus ? 1 : 0)
+ " startApp=" + startApp + " \n").getBytes()));
+ " startApp=" + device.startApp + " \n").getBytes()));
}

// 连接Server
Expand All @@ -89,19 +90,16 @@ private void connectServer(Device device) throws Exception {
if (!device.isLinkDevice()) {
long startTime = System.currentTimeMillis();
boolean mainConn = false;
String address = device.address;
// 如果包含应用名,则需要要分割出地址
if (address.contains("#")) address = address.split("#")[0];
InetSocketAddress inetSocketAddress = new InetSocketAddress(PublicTools.getIpAndPort(address).first, 25166);
InetSocketAddress inetSocketAddress = new InetSocketAddress(PublicTools.getIp(device.address), device.serverPort);
for (int i = 0; i < reTry; i++) {
try {
if (!mainConn) {
mainSocket = new Socket();
mainSocket.connect(inetSocketAddress, 1000);
mainSocket.connect(inetSocketAddress, 5000);
mainConn = true;
}
videoSocket = new Socket();
videoSocket.connect(inetSocketAddress, 1000);
videoSocket.connect(inetSocketAddress, 3000);
mainOutputStream = mainSocket.getOutputStream();
mainDataInputStream = new DataInputStream(mainSocket.getInputStream());
videoDataInputStream = new DataInputStream(videoSocket.getInputStream());
Expand All @@ -111,17 +109,17 @@ private void connectServer(Device device) throws Exception {
if (mainSocket != null) mainSocket.close();
if (videoSocket != null) videoSocket.close();
// 如果超时,直接跳出循环
if (System.currentTimeMillis() - startTime >= 5000) i = reTry;
if (System.currentTimeMillis() - startTime >= 4000) i = reTry;
else Thread.sleep(50);
}
}
}
// 直连失败尝试ADB中转
for (int i = 0; i < reTry; i++) {
try {
if (mainBufferStream == null) mainBufferStream = adb.tcpForward(25166);
if (mainBufferStream == null) mainBufferStream = adb.tcpForward(device.serverPort);
// 为了减少adb同步阻塞的问题,此处分开音视频流
if (videoBufferStream == null) videoBufferStream = adb.tcpForward(25166);
if (videoBufferStream == null) videoBufferStream = adb.tcpForward(device.serverPort);
return;
} catch (Exception ignored) {
Thread.sleep(50);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.view.View;

import java.nio.ByteBuffer;
import java.util.Objects;

import top.saymzx.easycontrol.app.R;
import top.saymzx.easycontrol.app.client.Client;
Expand All @@ -35,6 +36,7 @@ public class FullActivity extends Activity implements SensorEventListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ViewTools.setStatusAndNavBar(this);
ViewTools.setFullScreen(this);
activityFullBinding = ActivityFullBinding.inflate(this.getLayoutInflater());
setContentView(activityFullBinding.getRoot());
Expand All @@ -48,7 +50,7 @@ protected void onCreate(Bundle savedInstanceState) {
setNavBarHide(device.showNavBarOnConnect);
autoRotate = AppData.setting.getAutoRotate();
activityFullBinding.buttonAutoRotate.setImageResource(autoRotate ? R.drawable.un_auto : R.drawable.auto);
if (device.address.contains("#")) {
if (!Objects.equals(device.startApp, "")) {
activityFullBinding.buttonHome.setVisibility(View.GONE);
activityFullBinding.buttonSwitch.setVisibility(View.GONE);
activityFullBinding.buttonApp.setVisibility(View.GONE);
Expand Down
Loading

0 comments on commit 38325d0

Please sign in to comment.