This commit is contained in:
parent
cd09ed6429
commit
119252cb4b
|
|
@ -154,27 +154,12 @@ class LoginActivity : AppCompatActivity() {
|
|||
// 提取登录数据
|
||||
val data = json.optJSONObject("data")
|
||||
val loginData = data?.toString() ?: "{}"
|
||||
val accessToken = data?.optString("access_token", "") ?: ""
|
||||
|
||||
Toast.makeText(this@LoginActivity, "登录成功", Toast.LENGTH_SHORT).show()
|
||||
|
||||
// 1. PTT 引擎强制重置后登录 (销毁旧 session,确保干净状态)
|
||||
try {
|
||||
com.example.kingway.ptt.SendAtUtil.toCancelLogin()
|
||||
com.example.kingway.ptt.SendAtUtil.toLogout()
|
||||
} catch (e: Exception) {
|
||||
Timber.tag("PTT").e(e, "PTT init error")
|
||||
}
|
||||
|
||||
Toast.makeText(this@LoginActivity, "PTT初始化中...", Toast.LENGTH_SHORT).show()
|
||||
|
||||
// 使用 Handler 替代硬编码 Thread.sleep,避免阻塞或随意开辟线程
|
||||
android.os.Handler(android.os.Looper.getMainLooper()).postDelayed({
|
||||
try {
|
||||
com.example.kingway.ptt.SendAtUtil.toLogin(username, "123456", "220.154.131.231", 1, 1)
|
||||
} catch (e: Exception) {
|
||||
Timber.tag("PTT").e(e, "PTT login error")
|
||||
}
|
||||
}, 1500)
|
||||
// 获取独立的 PTT 账号并初始化
|
||||
initPttWithAccount(username, accessToken)
|
||||
|
||||
// 2. 启动硬件 GPIO 监听
|
||||
try {
|
||||
|
|
@ -302,8 +287,9 @@ class LoginActivity : AppCompatActivity() {
|
|||
val gname = group.optString("gname", "临时群组")
|
||||
Timber.tag("TempGroup").d("发现临时群组: $gname")
|
||||
// 打开临时呼叫页面
|
||||
val appCtx = com.stand.standapp.MyApplication.getAppInstance()
|
||||
val intent = android.content.Intent(
|
||||
this@LoginActivity,
|
||||
appCtx,
|
||||
TempCallActivity::class.java
|
||||
)
|
||||
intent.putExtra("group_name", gname)
|
||||
|
|
@ -312,7 +298,7 @@ class LoginActivity : AppCompatActivity() {
|
|||
android.content.Intent.FLAG_ACTIVITY_MULTIPLE_TASK or
|
||||
android.content.Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
|
||||
)
|
||||
startActivity(intent)
|
||||
appCtx.startActivity(intent)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
@ -322,4 +308,70 @@ class LoginActivity : AppCompatActivity() {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun initPttWithAccount(username: String, accessToken: String) {
|
||||
if (accessToken.isEmpty()) {
|
||||
doPttInit(username, "123456")
|
||||
return
|
||||
}
|
||||
|
||||
val serverUrl = AppConfig.getServerUrl(this)
|
||||
val url = "$serverUrl/api/poc-card/account/$username"
|
||||
|
||||
val request = Request.Builder()
|
||||
.url(url)
|
||||
.addHeader("Authorization", "Bearer $accessToken")
|
||||
.get()
|
||||
.build()
|
||||
|
||||
client.newCall(request).enqueue(object : Callback {
|
||||
override fun onFailure(call: Call, e: IOException) {
|
||||
Timber.tag("PTT").w(e, "获取 PTT 账号失败,使用默认账号")
|
||||
doPttInit(username, "123456")
|
||||
}
|
||||
|
||||
override fun onResponse(call: Call, response: Response) {
|
||||
try {
|
||||
val body = response.body?.string() ?: ""
|
||||
val json = JSONObject(body)
|
||||
if (json.optInt("code") == 0) {
|
||||
val data = json.optJSONObject("data")
|
||||
val pttUsername = data?.optString("cardNumber", username) ?: username
|
||||
val pttPassword = data?.optString("pocPassword", "123456") ?: "123456"
|
||||
doPttInit(pttUsername, pttPassword)
|
||||
} else {
|
||||
doPttInit(username, "123456")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Timber.tag("PTT").e(e, "解析 PTT 账号失败")
|
||||
doPttInit(username, "123456")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun doPttInit(pttUsername: String, pttPassword: String) {
|
||||
runOnUiThread {
|
||||
if (!isFinishing) {
|
||||
Toast.makeText(this@LoginActivity, "PTT初始化中...", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
|
||||
// 1. PTT 引擎强制重置后登录 (销毁旧 session,确保干净状态)
|
||||
try {
|
||||
com.example.kingway.ptt.SendAtUtil.toCancelLogin()
|
||||
com.example.kingway.ptt.SendAtUtil.toLogout()
|
||||
} catch (e: Exception) {
|
||||
Timber.tag("PTT").e(e, "PTT init error")
|
||||
}
|
||||
|
||||
// 使用 Handler 替代硬编码 Thread.sleep,避免阻塞或随意开辟线程
|
||||
android.os.Handler(android.os.Looper.getMainLooper()).postDelayed({
|
||||
try {
|
||||
com.example.kingway.ptt.SendAtUtil.toLogin(pttUsername, pttPassword, "220.154.131.231", 1, 1)
|
||||
} catch (e: Exception) {
|
||||
Timber.tag("PTT").e(e, "PTT login error")
|
||||
}
|
||||
}, 1500)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,27 +68,6 @@ class MyApplication : Application() {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录成功后将真实账号信息覆盖写入 cfg.dat
|
||||
*/
|
||||
@JvmStatic
|
||||
fun writeCfgDat(ip: String, account: String, password: String) {
|
||||
try {
|
||||
val cfgFile = File("/data/data/$pageName/cfg.dat")
|
||||
val data = ByteArray(240)
|
||||
ip.toByteArray().copyInto(data, 0)
|
||||
account.toByteArray().copyInto(data, 0x10)
|
||||
password.toByteArray().copyInto(data, 0x20)
|
||||
"GPSON".toByteArray().copyInto(data, 0x30)
|
||||
data[0xE1] = 0x01
|
||||
data[0xEA] = 0x3F
|
||||
data[0xEB] = 0x3F
|
||||
cfgFile.writeBytes(data)
|
||||
Timber.tag("PTT_INIT").i("writeCfgDat done: ip=$ip, account=$account")
|
||||
} catch (e: Exception) {
|
||||
Timber.tag("PTT_INIT").w(e, "writeCfgDat failed")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -62,8 +62,9 @@ class TempCallActivity : AppCompatActivity() {
|
|||
|
||||
@JvmStatic
|
||||
fun closeWithMessage(message: String) {
|
||||
val appCtx = com.stand.standapp.MyApplication.getAppInstance()
|
||||
instance?.runOnUiThread {
|
||||
Toast.makeText(instance, message, Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(appCtx, message, Toast.LENGTH_SHORT).show()
|
||||
instance?.finish()
|
||||
} ?: run {
|
||||
// Activity 已销毁但状态还在,清除状态
|
||||
|
|
|
|||
Loading…
Reference in New Issue