注销功能

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() {
runOnUiThread {
Timber.tag("MainActivity").i("用户注销,清理程序")
// 1. PTT Logout and cancel login
try { try {
com.example.kingway.ptt.SendAtUtil.toCancelLogin() com.example.kingway.ptt.SendAtUtil.toCancelLogin()
} catch (e: Exception) { } catch (e: Exception) {
Timber.tag("LoginActivity").e(e, "PTT cancel failed") Timber.tag("MainActivity").e(e, "PTT cancel failed")
} }
try { try {
com.example.kingway.ptt.SendAtUtil.toLogout() com.example.kingway.ptt.SendAtUtil.toLogout()
Timber.tag("LoginActivity").i("PTT logout sent") Timber.tag("MainActivity").i("PTT logout sent")
} catch (e: Exception) { } catch (e: Exception) {
Timber.tag("LoginActivity").e(e, "PTT logout failed") Timber.tag("MainActivity").e(e, "PTT logout failed")
} }
// 2. Stop GPIO listening
try { try {
com.stand.standapp.utils.GpioManager.stopListening() com.stand.standapp.utils.GpioManager.stopListening()
Timber.tag("MainActivity").i("GPIO stop listening")
} catch (e: Exception) { } catch (e: Exception) {
Timber.tag("MainActivity").e(e, "GPIO stop failed") Timber.tag("MainActivity").e(e, "GPIO stop failed")
} }
// 3. Destroy/release AudioTrack in PTT Native
try { try {
com.stand.standapp.utils.GpioManager.stopListening() com.stand.standapp.MyApplication.pNative?.destory()
com.stand.standapp.MyApplication.pNative = null
Timber.tag("MainActivity").i("PTT native AudioTrack destroyed")
} catch (e: Exception) { } catch (e: Exception) {
Timber.tag("LoginActivity").e(e, "GPIO stop failed") Timber.tag("MainActivity").e(e, "PTT native destroy failed")
}
// 4. Stop and destroy AudioRecord
try {
com.example.kingway.ptt.AudioRecordManager.getInstance().destroyAudio()
Timber.tag("MainActivity").i("AudioRecordManager destroyed")
} 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 { try {
// com.example.kingway.ptt.MyApplication.destroy() CallBackResolution.resetPttLoginStatus();
Timber.tag("LoginActivity").i("PTT native destroyed") }catch (e: Exception) {
} catch (e: Exception) { Timber.tag("MainActivity").e(e, "Failed to clear public value")
Timber.tag("LoginActivity").e(e, "PTT destroy failed")
} }
try {
// PrinterManager.shutdown()
Timber.tag("LoginActivity").i("Printer shut down")
} catch (e: Exception) {
Timber.tag("LoginActivity").e(e, "Printer shutdown failed")
}
try {
com.stand.standapp.utils.LogManager.shutdown()
Timber.tag("LoginActivity").i("LogManager shut down")
} catch (e: Exception) {
Timber.tag("LoginActivity").e(e, "LogManager shutdown failed")
} }
} }