Compare commits

..

10 Commits
main ... opti

8 changed files with 69 additions and 26 deletions

16
.codegraph/.gitignore vendored Normal file
View File

@ -0,0 +1,16 @@
# CodeGraph data files
# These are local to each machine and should not be committed
# Database
*.db
*.db-wal
*.db-shm
# Cache
cache/
# Logs
*.log
# Hook markers
.dirty

View File

@ -23,7 +23,8 @@
android:supportsRtl="true" android:supportsRtl="true"
android:usesCleartextTraffic="true" android:usesCleartextTraffic="true"
android:networkSecurityConfig="@xml/network_security_config" android:networkSecurityConfig="@xml/network_security_config"
android:theme="@style/Theme.StandAPP"> android:theme="@style/Theme.StandAPP"
android:hardwareAccelerated="true">
<activity <activity
android:name=".SplashActivity" android:name=".SplashActivity"

View File

@ -20,7 +20,7 @@
' setInterval(function() {', ' setInterval(function() {',
' var code = prompt("bridge:_poll", "");', ' var code = prompt("bridge:_poll", "");',
' if (code) { try { eval(code); } catch(e) {} }', ' if (code) { try { eval(code); } catch(e) {} }',
' }, 500);', ' }, 2000);',
'})();' '})();'
].join('\n'); ].join('\n');

View File

@ -28,6 +28,7 @@ public class CallBackResolution {
private static boolean loginState = false; private static boolean loginState = false;
private static String pttLoginStatus = "00"; // 00-未登录 01-登录中 02-已登录 private static String pttLoginStatus = "00"; // 00-未登录 01-登录中 02-已登录
private static String pttLoginId = ""; private static String pttLoginId = "";
private static ScheduledExecutorService keepAliveExecutor = null;
public static String getPttLoginStatus() { public static String getPttLoginStatus() {
return pttLoginStatus; return pttLoginStatus;
@ -543,13 +544,16 @@ public class CallBackResolution {
if (tempTxt.contains("已登录")) { if (tempTxt.contains("已登录")) {
String showName = tempTxt.substring(3, tempTxt.length()); String showName = tempTxt.substring(3, tempTxt.length());
CallBackUtil.callBackLogin(true, showName); CallBackUtil.callBackLogin(true, showName);
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); if (keepAliveExecutor != null && !keepAliveExecutor.isShutdown()) {
keepAliveExecutor.shutdownNow();
}
keepAliveExecutor = Executors.newSingleThreadScheduledExecutor();
Runnable task = () -> { Runnable task = () -> {
Timber.tag(TAG).d( "callBackLogin send tcp and udp"); Timber.tag(TAG).d( "callBackLogin send tcp and udp");
SendAtUtil.sendUDP(); SendAtUtil.sendUDP();
SendAtUtil.sendTCP(); SendAtUtil.sendTCP();
}; };
executor.scheduleAtFixedRate(task, 0, 40, TimeUnit.SECONDS); keepAliveExecutor.scheduleAtFixedRate(task, 0, 40, TimeUnit.SECONDS);
} else if (tempTxt.contains("账号已更新")) { } else if (tempTxt.contains("账号已更新")) {
Timber.tag(TAG).w("TTS reports account updated: '%s'", tempTxt); Timber.tag(TAG).w("TTS reports account updated: '%s'", tempTxt);
} else if (tempTxt.contains("账号或密码错误")) { } else if (tempTxt.contains("账号或密码错误")) {

View File

@ -31,10 +31,12 @@ class MainActivity : AppCompatActivity() {
@Volatile @Volatile
private var pendingJsCode: String? = null private var pendingJsCode: String? = null
private val jsLock = Any()
@JvmStatic @JvmStatic
fun executeJs(script: String) { fun executeJs(script: String) {
Timber.tag("ExecuteJs").d(script) Timber.tag("ExecuteJs").d(script)
synchronized(pendingJsCode ?: Any()) { synchronized(jsLock) {
// 合并多次调用(用换行分隔) // 合并多次调用(用换行分隔)
pendingJsCode = if (pendingJsCode != null) "$pendingJsCode;$script" else script pendingJsCode = if (pendingJsCode != null) "$pendingJsCode;$script" else script
} }
@ -119,7 +121,7 @@ class MainActivity : AppCompatActivity() {
// 获取并清除待执行的 JS 代码(由 bridge.js 轮询) // 获取并清除待执行的 JS 代码(由 bridge.js 轮询)
@JvmStatic @JvmStatic
fun pollPendingJs(): String { fun pollPendingJs(): String {
synchronized(pendingJsCode ?: Any()) { synchronized(jsLock) {
val code = pendingJsCode ?: "" val code = pendingJsCode ?: ""
pendingJsCode = null pendingJsCode = null
return code return code
@ -472,6 +474,16 @@ class MainActivity : AppCompatActivity() {
return super.onKeyDown(keyCode, event) return super.onKeyDown(keyCode, event)
} }
override fun onPause() {
super.onPause()
geckoSession?.setActive(false)
}
override fun onResume() {
super.onResume()
geckoSession?.setActive(true)
}
override fun onDestroy() { override fun onDestroy() {
cancelTimeoutTimer() cancelTimeoutTimer()
geckoView.releaseSession() geckoView.releaseSession()

View File

@ -7,14 +7,37 @@ import android.os.Looper
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
class SplashActivity : AppCompatActivity() { class SplashActivity : AppCompatActivity() {
private val handler = Handler(Looper.getMainLooper())
private var checkCount = 0
private val maxChecks = 20 // 最多检查20次(2秒)
private val checkInitRunnable = object : Runnable {
override fun run() {
if (MyApplication.pNative != null || checkCount >= maxChecks) {
navigateToLogin()
} else {
checkCount++
handler.postDelayed(this, 100)
}
}
}
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_splash) setContentView(R.layout.activity_splash)
// 延迟 2 秒进入登录界面 // 异步检查PTT JNI初始化状态避免硬等待2秒
Handler(Looper.getMainLooper()).postDelayed({ handler.post(checkInitRunnable)
startActivity(Intent(this, LoginActivity::class.java)) }
finish()
}, 2000) private fun navigateToLogin() {
if (isFinishing || isDestroyed) return
startActivity(Intent(this, LoginActivity::class.java))
finish()
}
override fun onDestroy() {
handler.removeCallbacks(checkInitRunnable)
super.onDestroy()
} }
} }

View File

@ -35,8 +35,8 @@ object GpioManager {
Timber.tag("GPIO").i("Start GPIO listening thread") Timber.tag("GPIO").i("Start GPIO listening thread")
while (mIsRunning) { while (mIsRunning) {
try { try {
// 硬件轮询频率优化:50ms 既能保证响应速度,又能降低 CPU 消耗 // 硬件轮询频率优化:150ms 既能保证响应速度,又能降低 CPU 消耗
Thread.sleep(50) Thread.sleep(150)
val manager = mZysjSystemManager ?: continue val manager = mZysjSystemManager ?: continue
// 获取 GPIO 1 的值 (0 按下, 1 松开) // 获取 GPIO 1 的值 (0 按下, 1 松开)

View File

@ -98,19 +98,6 @@ object LogManager {
onCrashDetected(null, thread.name, throwable) onCrashDetected(null, thread.name, throwable)
defaultHandler?.uncaughtException(thread, throwable) ?: exitProcess(1) defaultHandler?.uncaughtException(thread, throwable) ?: exitProcess(1)
} }
// 2. 捕获主线程 Looper
android.os.Handler(android.os.Looper.getMainLooper()).post {
while (true) {
try {
android.os.Looper.loop()
} catch (e: Throwable) {
onCrashDetected(null, "MainLooper", e)
// 如果是 UnsatisfiedLinkError这种错误无法恢复必须抛出让系统处理
throw e
}
}
}
} }
private fun cleanOldLogs(dir: File) { private fun cleanOldLogs(dir: File) {