Skip to content

Commit

Permalink
修复错误
Browse files Browse the repository at this point in the history
1、修复Windows下apk安装目录中有空格失败的问题;
2、ADB设备新增一个Wifi连接操作。
  • Loading branch information
GangJust committed Feb 3, 2023
1 parent 05372fc commit 23a9134
Show file tree
Hide file tree
Showing 12 changed files with 305 additions and 160 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
.idea
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
9 changes: 6 additions & 3 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.*
import androidx.compose.material.Card
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.material.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.Alignment
Expand All @@ -23,8 +26,7 @@ import utils.ShellUtils
import java.io.File
import java.io.FileInputStream
import java.io.FileOutputStream
import java.lang.Exception
import java.util.Properties
import java.util.*


class AppLogic : AbstractLogic() {
Expand Down Expand Up @@ -135,6 +137,7 @@ class App(private var application: ApplicationScope) : AbstractView<AppState>()
value = adbDir,
hintText = "请输入可执行adb所在路径",
textStyle = TextStyleRes.bodyMedium,
fillMaxWidth = true,
onValueChange = { adbDir.value = it },
)
}
Expand Down
36 changes: 30 additions & 6 deletions src/main/kotlin/app/state/HomeState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import androidx.compose.ui.unit.dp
import app.logic.HomeLogic
import base.mvvm.AbstractState
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import res.IconRes
import utils.ShellUtils
import utils.formatAdbCommand
import java.lang.RuntimeException

class HomeState : AbstractState<HomeLogic>() {
override fun createLogic(): HomeLogic = HomeLogic()
Expand All @@ -25,7 +23,10 @@ class HomeState : AbstractState<HomeLogic>() {

val currentDevice = mutableStateOf("")
val devicesList = mutableStateListOf<String>()
val phoneApiMap = mutableStateMapOf<String, String>()
val phoneAbiMap = mutableStateMapOf<String, String>()
val phoneBrandMap = mutableStateMapOf<String, String>()

val showConnectWifiDeviceView = mutableStateOf(false)

init {
loadDevices()
Expand Down Expand Up @@ -56,11 +57,12 @@ class HomeState : AbstractState<HomeLogic>() {
val device = element.replace("device", "").trim()
devicesList.add(device)
//获取Abi系统架构
phoneApiMap[device] = getAbi(device)
phoneAbiMap[device] = getAbi(device)
phoneBrandMap[device] = getBrand(device)
}
}

if(currentDevice.value.isEmpty()){
if (currentDevice.value.isEmpty()) {
currentDevice.value = devicesList[0]
}
}
Expand All @@ -71,6 +73,28 @@ class HomeState : AbstractState<HomeLogic>() {
val command = "adb shell getprop ro.product.cpu.abi".formatAdbCommand(device)
val abi = ShellUtils.shell(command)
if (abi.isEmpty()) return "unknown"
return abi
return abi.trim()
}

/// 获取某个ADB设备的系统品牌
private suspend fun getBrand(device: String): String {
val command = "adb shell getprop ro.product.brand".formatAdbCommand(device)
val brand = ShellUtils.shell(command)
if (brand.isEmpty()) return "unknown"
return brand.trim()
}

/// 通过Wifi连接ADB设备
fun wifiConnect(ipAndPort: String, block: (Boolean) -> Unit) {
launch {
val command = "adb connect $ipAndPort".formatAdbCommand("")
ShellUtils.shell(command) { success, error ->
if (error.isNotBlank() || !success.contains("connected")) {
block.invoke(false)
return@shell
}
block.invoke(true)
}
}
}
}
2 changes: 1 addition & 1 deletion src/main/kotlin/app/state/pages/AppManagerState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ class AppManagerState : AbstractState<AppManagerLogic>() {

///安装Apk
fun installApk(path: String) {
val command = "adb install -r $path".formatAdbCommand(device)
val command = "adb install -r \"$path\"".formatAdbCommand(device)
apkInstallMessage.value = "正在安装, 请注意设备安装弹窗.."
launch {
ShellUtils.shell(command) { success, error ->
Expand Down
Loading

0 comments on commit 23a9134

Please sign in to comment.