Skip to content

Commit

Permalink
更新V12.7.3
Browse files Browse the repository at this point in the history
优化兼容性问题,提高投屏成功率
优化占用
更改悬浮球样式,增加可视性
优化悬浮球长按识别率
  • Loading branch information
mingzhixian committed Jul 21, 2023
1 parent aa61a19 commit 6797232
Show file tree
Hide file tree
Showing 21 changed files with 262 additions and 342 deletions.
13 changes: 1 addition & 12 deletions scrcpy_android/.idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions scrcpy_android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "top.saymzx.scrcpy.android"
minSdk 23
targetSdk 33
versionCode 1260
versionName "12.6.0"
versionCode 1273
versionName "12.7.3"
resConfigs "zh"
resConfigs "xhdpi"
ndk {
Expand Down
50 changes: 29 additions & 21 deletions scrcpy_android/app/src/main/java/top/saymzx/scrcpy/adb/Adb.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
/*
* 本项目为适用于安卓的ADB库,本项目大量借鉴学习了开源ADB库:Dadb,在此对该项目表示感谢
*/

package top.saymzx.scrcpy.adb

import android.util.Log
import okhttp3.internal.notifyAll
import okhttp3.internal.wait
import okio.Buffer
Expand Down Expand Up @@ -43,7 +48,9 @@ class Adb(host: String, port: Int, keyPair: AdbKeyPair) {
// 最大承载长度
adbWriter.maxPayloadSize = message.arg1
// 开始读写线程
Thread { readAdb() }.start()
val thread = Thread { readAdbThread() }
thread.priority = Thread.MAX_PRIORITY
thread.start()
}

// 打开一个连接流
Expand All @@ -60,23 +67,26 @@ class Adb(host: String, port: Int, keyPair: AdbKeyPair) {
}

fun pushFile(file: InputStream, remotePath: String) {
val pushStream = open("sync:", true)
val remote = "$remotePath,${33206}"
pushStream.write(writePacket("SEND", remote.length))
pushStream.write(remote.toByteArray())
val byteArray = ByteArray(adbWriter.maxPayloadSize - 512)
while (true) {
val len = file.read(byteArray, 0, byteArray.size)
if (len == -1) break
pushStream.write(writePacket("DATA", len))
pushStream.write(byteArray.sliceArray(0..len))
val pushStream = open("sync:start a SYNC service", true)
val sendString = "$remotePath,33206"
pushStream.write(createSendPacket("SEND", sendString.length) + sendString.toByteArray())
val byteArray = ByteArray(60000)
var len = file.read(byteArray, 0, byteArray.size)
do {
var tmpByteArray = createSendPacket("DATA", len) + byteArray.sliceArray(0 until len)
if (len < byteArray.size) {
tmpByteArray += createSendPacket("DONE", System.currentTimeMillis().toInt())
}
pushStream.write(tmpByteArray)
len = file.read(byteArray, 0, byteArray.size)
} while (len > 0)
pushStream.write(createSendPacket("QUIT", 0))
synchronized(pushStream) {
pushStream.wait()
}
pushStream.write(writePacket("DONE", (System.currentTimeMillis() / 1000).toInt()))
pushStream.readByte()
pushStream.write(writePacket("QUIT", 0))
}

private fun writePacket(id: String, arg: Int): ByteArray {
private fun createSendPacket(id: String, arg: Int): ByteArray {
val tmpBuffer = Buffer()
tmpBuffer.clear()
tmpBuffer.writeString(id, StandardCharsets.UTF_8)
Expand Down Expand Up @@ -105,10 +115,11 @@ class Adb(host: String, port: Int, keyPair: AdbKeyPair) {

fun tcpForward(port: Int, isNeedSource: Boolean): AdbStream = open("tcp:$port", isNeedSource)

fun localSocketForward(socketName: String, isNeedSource: Boolean): AdbStream = open("localabstract:$socketName", isNeedSource)
fun localSocketForward(socketName: String, isNeedSource: Boolean): AdbStream =
open("localabstract:$socketName", isNeedSource)

// 读取线程
private fun readAdb() {
private fun readAdbThread() {
try {
while (true) {
val message = adbReader.readMessage()
Expand All @@ -123,10 +134,7 @@ class Adb(host: String, port: Int, keyPair: AdbKeyPair) {
stream.notifyAll()
}
}
// 可读写
synchronized(stream.canWrite) {
stream.canWrite.notify()
}
synchronized(stream.canWrite) { stream.canWrite.notify() }
}

Constants.CMD_WRTE -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/*
* Copyright (c) 2021 mobile.dev inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* 本项目为适用于安卓的ADB库,本项目大量借鉴学习了开源ADB库:Dadb,在此对该项目表示感谢
*/

package top.saymzx.scrcpy.adb
Expand All @@ -27,7 +14,6 @@ import java.security.PrivateKey
import java.security.interfaces.RSAPublicKey
import javax.crypto.Cipher


class AdbKeyPair(
private val privateKey: PrivateKey,
internal val publicKeyBytes: ByteArray
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/*
* Copyright (c) 2021 mobile.dev inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* 本项目为适用于安卓的ADB库,本项目大量借鉴学习了开源ADB库:Dadb,在此对该项目表示感谢
*/

package top.saymzx.scrcpy.adb
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/*
* Copyright (c) 2021 mobile.dev inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* 本项目为适用于安卓的ADB库,本项目大量借鉴学习了开源ADB库:Dadb,在此对该项目表示感谢
*/

package top.saymzx.scrcpy.adb
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
/*
* Copyright (c) 2021 mobile.dev inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* 本项目为适用于安卓的ADB库,本项目大量借鉴学习了开源ADB库:Dadb,在此对该项目表示感谢
*/

package top.saymzx.scrcpy.adb

import android.util.Log
import okhttp3.internal.notify
import okhttp3.internal.wait
import okio.Buffer
Expand Down Expand Up @@ -47,9 +35,7 @@ class AdbStream(

fun write(byteArray: ByteArray) {
if (status == -1) return
else if (status != 2) synchronized(canWrite) {
canWrite.wait()
}
else if (status != 2) synchronized(canWrite) { canWrite.wait() }
status = 1
adbWriter.writeWrite(localId, remoteId, byteArray, 0, byteArray.size)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/*
* Copyright (c) 2021 mobile.dev inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* 本项目为适用于安卓的ADB库,本项目大量借鉴学习了开源ADB库:Dadb,在此对该项目表示感谢
*/

package top.saymzx.scrcpy.adb
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/*
* Copyright (c) 2021 mobile.dev inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* 本项目为适用于安卓的ADB库,本项目大量借鉴学习了开源ADB库:Dadb,在此对该项目表示感谢
*/

package top.saymzx.scrcpy.adb
Expand Down
15 changes: 1 addition & 14 deletions scrcpy_android/app/src/main/java/top/saymzx/scrcpy/adb/PKCS8.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/*
* Copyright (c) 2021 mobile.dev inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* 本项目为适用于安卓的ADB库,本项目大量借鉴学习了开源ADB库:Dadb,在此对该项目表示感谢
*/

package top.saymzx.scrcpy.adb
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package top.saymzx.scrcpy.android
import android.app.Activity
import android.os.Bundle
import android.os.Handler
import android.os.Message
import android.widget.Toast
import top.saymzx.scrcpy.android.databinding.ActivityFullScreenBinding

Expand All @@ -28,10 +27,10 @@ class FullScreenActivity : Activity() {
val handler = Handler(this.mainLooper)
val runnable: Runnable = object : Runnable {
override fun run() {
if (appData.isFocus){
if (appData.isFocus) {
if (requestedOrientation != appData.fullScreenOrientation)
requestedOrientation = appData.fullScreenOrientation
}else{
} else {
finish()
}
handler.postDelayed(this, 200)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import top.saymzx.scrcpy.adb.Adb
import top.saymzx.scrcpy.adb.AdbKeyPair
import top.saymzx.scrcpy.android.databinding.ActivityMainBinding
import top.saymzx.scrcpy.android.databinding.AddDeviceBinding
import top.saymzx.scrcpy.android.databinding.EditPortBinding
Expand All @@ -45,6 +44,8 @@ class MainActivity : Activity(), ViewModelStoreOwner {
if (!appData.isInit) appData.init()
// 设置状态栏导航栏颜色沉浸
appData.publicTools.setStatusAndNavBar(this)
// 获取是否需要启动默认设备
startDefault = intent.getBooleanExtra("startDefault", true)
// 如果第一次使用进入软件展示页
if (appData.settings.getBoolean("FirstUse", true)) startActivityForResult(
Intent(
Expand All @@ -54,6 +55,20 @@ class MainActivity : Activity(), ViewModelStoreOwner {
else readMode()
}

// 进入页面
private var startDefault = true
override fun onResume() {
// 启动默认设备
if (startDefault) {
if (!appData.settings.getBoolean("FirstUse", true) && appData.setValue.appMode == 1) {
startDefault()
}
} else {
startDefault = true
}
super.onResume()
}

// 其他页面回调
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
// ShowApp页面回调
Expand All @@ -63,9 +78,9 @@ class MainActivity : Activity(), ViewModelStoreOwner {
super.onActivityResult(requestCode, resultCode, data)
}

// 选择模式
// 软件模式
private fun readMode() {
if (appData.setValue.appMode== 1) {
if (appData.setValue.appMode == 1) {
asMaster()
} else {
asSlave()
Expand All @@ -78,8 +93,6 @@ class MainActivity : Activity(), ViewModelStoreOwner {
private fun asMaster() {
// 检查权限
checkPermission()
// 启动默认设备
startDefault()
// 设置设备列表适配器
setDevicesList()
// 添加按钮监听
Expand Down Expand Up @@ -262,7 +275,7 @@ class MainActivity : Activity(), ViewModelStoreOwner {
val adb = Adb(
"127.0.0.1",
appData.setValue.slaveAdbPort,
AdbKeyPair.read(appData.privateKey, appData.publicKey)
appData.keyPair
)
adb.runAdbCmd(
"ps aux | grep scrcpy | grep -v grep | awk '{print \$2}' | xargs kill -9", false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,9 +653,9 @@ class FloatVideo(
MotionEvent.ACTION_MOVE -> {
val x = event.rawX.toInt()
val y = event.rawY.toInt()
// 取消手势识别,适配一些机器将点击视作小范围移动(小于3的圆内不做处理)
// 取消手势识别,适配一些机器将点击视作小范围移动(小于4的圆内不做处理)
if (xx != -1) {
if ((xx - x) * (xx - x) + (yy - y) * (yy - y) < 9) {
if ((xx - x) * (xx - x) + (yy - y) * (yy - y) < 16) {
return@setOnTouchListener true
}
xx = -1
Expand All @@ -673,7 +673,7 @@ class FloatVideo(
appData.mainScope.launch {
delay(2000)
withContext(Dispatchers.Main) {
floatNav.floatNavImage.alpha = 0.4f
floatNav.floatNavImage.alpha = 0.7f
}
}
return@setOnTouchListener true
Expand Down
Loading

0 comments on commit 6797232

Please sign in to comment.