diff --git a/app/src/main/java/com/stand/standapp/LoginActivity.kt b/app/src/main/java/com/stand/standapp/LoginActivity.kt index f0ef2b3..3300508 100644 --- a/app/src/main/java/com/stand/standapp/LoginActivity.kt +++ b/app/src/main/java/com/stand/standapp/LoginActivity.kt @@ -65,30 +65,9 @@ class LoginActivity : AppCompatActivity() { // 4. 退出按钮 btnExit.setOnClickListener { -// fullCleanup() -// finishAffinity() -// android.os.Process.killProcess(android.os.Process.myPid()) - try { -// com.example.kingway.ptt.MyApplication.init(this@LoginActivity) -// Thread.sleep(500) -// com.example.kingway.ptt.SendAtUtil.toCancelLogin() -// com.example.kingway.ptt.SendAtUtil.toLogout() - } catch (e: Exception) { - Timber.tag("PTT").e(e, "PTT init error") - } - Thread { - try { - Thread.sleep(500) - runOnUiThread { - Toast.makeText(this@LoginActivity, "PTT初始化中", Toast.LENGTH_SHORT).show() - } - Thread.sleep(3000) - com.example.kingway.ptt.SendAtUtil.toLogin("gzz22222", "1111", "61.243.1.123", 1, 1) -// com.example.kingway.ptt.SendAtUtil.toLogin("gzzdweb01", "123456", "61.243.1.123", 1, 1) - } catch (e: Exception) { - Timber.tag("PTT").e(e, "PTT login error") - } - }.start() + fullCleanup() + finishAffinity() + android.os.Process.killProcess(android.os.Process.myPid()) } // 5. 彩蛋:点击底部版权 10 次进入开发者模式 diff --git a/app/src/main/java/com/stand/standapp/MainActivity.kt b/app/src/main/java/com/stand/standapp/MainActivity.kt index 8969fb7..0e625f2 100644 --- a/app/src/main/java/com/stand/standapp/MainActivity.kt +++ b/app/src/main/java/com/stand/standapp/MainActivity.kt @@ -61,15 +61,15 @@ class MainActivity : AppCompatActivity() { .setMessage("您的 PTT 账号已在其他设备登录,当前设备已被迫下线。\n请点击确认退出并重新登录。") .setCancelable(false) .setPositiveButton("确认") { _, _ -> -// try { -// com.example.kingway.ptt.SendAtUtil.toLogout() + try { + com.example.kingway.ptt.SendAtUtil.toLogout() // com.example.kingway.ptt.MyApplication.destroy() -// com.stand.standapp.utils.GpioManager.stopListening() -// } catch (_: Exception) {} -// val pm = ctx.packageManager -// val intent = pm.getLaunchIntentForPackage(ctx.packageName) -// intent?.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK) -// ctx.startActivity(intent) + com.stand.standapp.utils.GpioManager.stopListening() + } catch (_: Exception) {} + val pm = ctx.packageManager + val intent = pm.getLaunchIntentForPackage(ctx.packageName) + intent?.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK) + ctx.startActivity(intent) android.os.Process.killProcess(android.os.Process.myPid()) } .show() @@ -263,7 +263,7 @@ class MainActivity : AppCompatActivity() { .setTitle("提示") .setMessage("确定要退出应用吗?") .setPositiveButton("确定") { _, _ -> -// pttLogoutAndDestroy() + pttLogoutAndDestroy() finishAffinity() android.os.Process.killProcess(android.os.Process.myPid()) } @@ -271,47 +271,47 @@ class MainActivity : AppCompatActivity() { .show() } -// private fun pttLogoutAndDestroy() { -// try { -// com.example.kingway.ptt.SendAtUtil.toCancelLogin() -// } catch (e: Exception) { -// Timber.tag("LoginActivity").e(e, "PTT cancel failed") -// } -// try { -// com.example.kingway.ptt.SendAtUtil.toLogout() -// Timber.tag("LoginActivity").i("PTT logout sent") -// } catch (e: Exception) { -// Timber.tag("LoginActivity").e(e, "PTT logout failed") -// } -// try { -// com.stand.standapp.utils.GpioManager.stopListening() -// } catch (e: Exception) { -// Timber.tag("MainActivity").e(e, "GPIO stop failed") -// } -// try { -// com.stand.standapp.utils.GpioManager.stopListening() -// } catch (e: Exception) { -// Timber.tag("LoginActivity").e(e, "GPIO stop failed") -// } -// try { + private fun pttLogoutAndDestroy() { + try { + com.example.kingway.ptt.SendAtUtil.toCancelLogin() + } catch (e: Exception) { + Timber.tag("LoginActivity").e(e, "PTT cancel failed") + } + try { + com.example.kingway.ptt.SendAtUtil.toLogout() + Timber.tag("LoginActivity").i("PTT logout sent") + } catch (e: Exception) { + Timber.tag("LoginActivity").e(e, "PTT logout failed") + } + try { + com.stand.standapp.utils.GpioManager.stopListening() + } catch (e: Exception) { + Timber.tag("MainActivity").e(e, "GPIO stop failed") + } + try { + com.stand.standapp.utils.GpioManager.stopListening() + } catch (e: Exception) { + Timber.tag("LoginActivity").e(e, "GPIO stop failed") + } + try { // com.example.kingway.ptt.MyApplication.destroy() -// Timber.tag("LoginActivity").i("PTT native destroyed") -// } catch (e: Exception) { -// 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") -// } -// } + Timber.tag("LoginActivity").i("PTT native destroyed") + } catch (e: Exception) { + 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") + } + } override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean { if (keyCode == KeyEvent.KEYCODE_BACK) { diff --git a/app/src/main/java/com/stand/standapp/MyApplication.kt b/app/src/main/java/com/stand/standapp/MyApplication.kt index 2c4b595..5d48c58 100644 --- a/app/src/main/java/com/stand/standapp/MyApplication.kt +++ b/app/src/main/java/com/stand/standapp/MyApplication.kt @@ -8,36 +8,6 @@ import timber.log.Timber class MyApplication : Application() { -// companion object { -// private var instance: MyApplication? = null -// fun getAppInstance(): MyApplication = instance ?: error("MyApplication not yet initialized") -// } - -// override fun onCreate() { -// super.onCreate() -// instance = this -// // 第一步:初始化日志 -// LogManager.init(this) -// -// // 初始化 xCrash 以捕获 Native (SO) 崩溃 -// xcrash.XCrash.init(this, xcrash.XCrash.InitParameters().apply { -// setAppVersion(packageManager.getPackageInfo(packageName, 0).versionName) -// setLogDir(getExternalFilesDir("tombstones")?.absolutePath) -// setNativeDumpAllThreads(true) -// -// setJavaCallback { logPath, emergency -> -// LogManager.onCrashDetected(logPath, "Java-xCrash", null) -// } -// -// setNativeCallback { logPath, emergency -> -// LogManager.onCrashDetected(logPath, "Native-xCrash", null) -// android.util.Log.e("MyApplication", "NATIVE CRASH DETECTED at: $logPath") -// } -// }) -// -// Timber.tag("MyApplication").i("=== Application Starting ===") -// } - // 单例实例 companion object { private lateinit var mApp: MyApplication