注销功能

This commit is contained in:
fengge 2026-06-18 16:09:53 +08:00
parent 9d5f4dc3a9
commit c531965106
4 changed files with 84 additions and 39 deletions

View File

@ -44,8 +44,12 @@ public class CallBackResolution {
} }
public static void resetPttLoginStatus() { public static void resetPttLoginStatus() {
loginState = false;
pttLoginStatus = "00"; pttLoginStatus = "00";
pttLoginId = ""; pttLoginId = "";
indexGroupId ="";
indexGroupName = "";
keepAliveExecutor.shutdownNow();
} }
public static String getCurrentGroupId() { public static String getCurrentGroupId() {

View File

@ -30,6 +30,7 @@ public class SendAtUtil {
*/ */
public static void toCancelLogin() { public static void toCancelLogin() {
send("050000\r\n"); send("050000\r\n");
send("05000000\r\n");
} }
/** /**
@ -37,6 +38,7 @@ public class SendAtUtil {
*/ */
public static void toLogout() { public static void toLogout() {
send("040000\r\n"); send("040000\r\n");
send("04000000\r\n");
} }
/** /**

View File

@ -86,6 +86,7 @@ class AndroidInterface(private val activity: MainActivity) {
"showJsonDialog" -> { showJsonDialog(args.optString(0, "")); "" } "showJsonDialog" -> { showJsonDialog(args.optString(0, "")); "" }
"getTempCallStatus" -> getTempCallStatus() "getTempCallStatus" -> getTempCallStatus()
"maximizeTempCall" -> { maximizeTempCall(); "" } "maximizeTempCall" -> { maximizeTempCall(); "" }
"logout" -> { logout(); "" }
else -> { else -> {
Timber.tag("Bridge").w("Unknown method: $method") Timber.tag("Bridge").w("Unknown method: $method")
"" ""
@ -502,4 +503,8 @@ class AndroidInterface(private val activity: MainActivity) {
} }
} }
} }
fun logout() {
activity.logout()
}
} }

View File

@ -5,6 +5,7 @@ import android.os.Bundle
import android.view.KeyEvent import android.view.KeyEvent
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import android.widget.FrameLayout import android.widget.FrameLayout
import com.example.kingway.ptt.CallBackResolution
import org.mozilla.geckoview.GeckoResult import org.mozilla.geckoview.GeckoResult
import org.mozilla.geckoview.GeckoRuntime import org.mozilla.geckoview.GeckoRuntime
import org.mozilla.geckoview.GeckoSession import org.mozilla.geckoview.GeckoSession
@ -419,45 +420,78 @@ class MainActivity : AppCompatActivity() {
.show() .show()
} }
private fun pttLogoutAndDestroy() { fun logout() {
try { runOnUiThread {
com.example.kingway.ptt.SendAtUtil.toCancelLogin() Timber.tag("MainActivity").i("用户注销,清理程序")
} catch (e: Exception) {
Timber.tag("LoginActivity").e(e, "PTT cancel failed") // 1. PTT Logout and cancel login
} try {
try { com.example.kingway.ptt.SendAtUtil.toCancelLogin()
com.example.kingway.ptt.SendAtUtil.toLogout() } catch (e: Exception) {
Timber.tag("LoginActivity").i("PTT logout sent") Timber.tag("MainActivity").e(e, "PTT cancel failed")
} catch (e: Exception) { }
Timber.tag("LoginActivity").e(e, "PTT logout failed") try {
} com.example.kingway.ptt.SendAtUtil.toLogout()
try { Timber.tag("MainActivity").i("PTT logout sent")
com.stand.standapp.utils.GpioManager.stopListening() } catch (e: Exception) {
} catch (e: Exception) { Timber.tag("MainActivity").e(e, "PTT logout failed")
Timber.tag("MainActivity").e(e, "GPIO stop failed") }
}
try { // 2. Stop GPIO listening
com.stand.standapp.utils.GpioManager.stopListening() try {
} catch (e: Exception) { com.stand.standapp.utils.GpioManager.stopListening()
Timber.tag("LoginActivity").e(e, "GPIO stop failed") Timber.tag("MainActivity").i("GPIO stop listening")
} } catch (e: Exception) {
try { Timber.tag("MainActivity").e(e, "GPIO stop failed")
// com.example.kingway.ptt.MyApplication.destroy() }
Timber.tag("LoginActivity").i("PTT native destroyed")
} catch (e: Exception) { // 3. Destroy/release AudioTrack in PTT Native
Timber.tag("LoginActivity").e(e, "PTT destroy failed") try {
} com.stand.standapp.MyApplication.pNative?.destory()
try { com.stand.standapp.MyApplication.pNative = null
// PrinterManager.shutdown() Timber.tag("MainActivity").i("PTT native AudioTrack destroyed")
Timber.tag("LoginActivity").i("Printer shut down") } catch (e: Exception) {
} catch (e: Exception) { Timber.tag("MainActivity").e(e, "PTT native destroy failed")
Timber.tag("LoginActivity").e(e, "Printer shutdown failed") }
}
try { // 4. Stop and destroy AudioRecord
com.stand.standapp.utils.LogManager.shutdown() try {
Timber.tag("LoginActivity").i("LogManager shut down") com.example.kingway.ptt.AudioRecordManager.getInstance().destroyAudio()
} catch (e: Exception) { Timber.tag("MainActivity").i("AudioRecordManager destroyed")
Timber.tag("LoginActivity").e(e, "LogManager shutdown failed") } catch (e: Exception) {
Timber.tag("MainActivity").e(e, "AudioRecordManager destroy failed")
}
// 5. Close printer connection
try {
com.stand.standapp.printer.PrinterManager.getFactory()?.ClosePort()
Timber.tag("MainActivity").i("Printer port closed")
} catch (e: Exception) {
Timber.tag("MainActivity").e(e, "Printer close failed")
}
// 6. Clear Access Token
try {
AppConfig.setAccessToken(this, "")
Timber.tag("MainActivity").i("Cleared access token")
} catch (e: Exception) {
Timber.tag("MainActivity").e(e, "Failed to clear access token")
}
// 7. Redirect back to LoginActivity and clear task stack
try {
val intent = Intent(this, LoginActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
startActivity(intent)
finish()
} catch (e: Exception) {
Timber.tag("MainActivity").e(e, "Failed to redirect to LoginActivity")
}
try {
CallBackResolution.resetPttLoginStatus();
}catch (e: Exception) {
Timber.tag("MainActivity").e(e, "Failed to clear public value")
}
} }
} }