fix: 修复SmartMediaProjectionManager权限死循环问题
- 重写onStop回调:添加isCreating()检查和Holder状态判断,避免误判权限丢失 - 重写attemptSilentRecovery():只从Holder获取已有对象,禁止重新创建MediaProjection - 重写checkAndRestoreExistingPermission():只从Holder获取,不再调用getMediaProjection - 重写createMediaProjectionSafely():通过safeGetOrCreateProjection统一创建入口 - 与Android15MediaProjectionManager/AccessibilityRemoteService/ScreenCaptureManager/RemoteControlForegroundService的修复配合,彻底消除死循环
This commit is contained in:
@@ -490,21 +490,18 @@ class SmartMediaProjectionManager(
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查并恢复现有权限
|
||||
* 检查并恢复现有权限 - 只从 Holder 获取已有对象
|
||||
*/
|
||||
private fun checkAndRestoreExistingPermission() {
|
||||
try {
|
||||
val permissionData = MediaProjectionHolder.getPermissionData()
|
||||
if (permissionData != null) {
|
||||
val (resultCode, resultData) = permissionData
|
||||
if (resultData != null) {
|
||||
Log.i(TAG, "📱 发现现有权限数据,尝试恢复")
|
||||
val projection = createMediaProjectionSafely(resultCode, resultData)
|
||||
if (projection != null) {
|
||||
Log.i(TAG, "✅ 现有权限恢复成功")
|
||||
notifyPermissionRecovered()
|
||||
}
|
||||
}
|
||||
// 只从 Holder 获取已有对象,不重新创建
|
||||
val existingProjection = MediaProjectionHolder.getMediaProjection()
|
||||
if (existingProjection != null) {
|
||||
Log.i(TAG, "✅ Holder中已有有效MediaProjection,直接复用")
|
||||
mediaProjection = existingProjection
|
||||
notifyPermissionRecovered()
|
||||
} else {
|
||||
Log.d(TAG, "📱 Holder中无有效MediaProjection,等待权限授予")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "❌ 检查现有权限失败", e)
|
||||
|
||||
Reference in New Issue
Block a user