v1.1.6 - 알람 볼륨 0 버그 수정 및 최초 설치 권한 모달 루프 버그 수정
This commit is contained in:
@@ -22,6 +22,15 @@ import kotlinx.coroutines.*
|
||||
object AlarmPermissionUtil {
|
||||
|
||||
private var monitorJob: Job? = null
|
||||
|
||||
/** 권한 플로우가 진행 중인지 추적하는 플래그 (onResume 루프 방지) */
|
||||
@Volatile
|
||||
var isPermissionFlowActive = false
|
||||
private set
|
||||
|
||||
/** 현재 권한 모달 다이얼로그가 표시 중인지 추적 */
|
||||
@Volatile
|
||||
private var isDialogShowing = false
|
||||
|
||||
/**
|
||||
* 시스템 설정 화면에서 사용자가 권한을 허용했을 때 뒤로가기를 누르지 않아도 앱으로 즉시 자동 복귀시킵니다.
|
||||
@@ -29,9 +38,9 @@ object AlarmPermissionUtil {
|
||||
fun monitorAndAutoReturn(activity: Activity, isGrantedCheck: () -> Boolean) {
|
||||
monitorJob?.cancel()
|
||||
monitorJob = CoroutineScope(Dispatchers.Main).launch {
|
||||
delay(1000) // 설정 화면 전환 시간 대기
|
||||
delay(1500) // 설정 화면 전환 시간 충분히 대기 (1.5초)
|
||||
var count = 0
|
||||
while (count < 150 && isActive) { // 최대 60초간 500ms 주기로 체크
|
||||
while (count < 120 && isActive) { // 최대 60초간 500ms 주기로 체크
|
||||
delay(500)
|
||||
count++
|
||||
if (isGrantedCheck()) {
|
||||
@@ -56,8 +65,12 @@ object AlarmPermissionUtil {
|
||||
|
||||
/**
|
||||
* 전체 권한 상태를 확인하고 필요한 경우 통합 안내 다이얼로그를 표시합니다.
|
||||
* 권한 플로우가 이미 진행 중이거나 다이얼로그가 표시 중이면 중복 호출을 방지합니다.
|
||||
*/
|
||||
fun checkAndRequestAllPermissions(activity: ComponentActivity) {
|
||||
// 이미 권한 플로우 진행 중이면 중복 호출 방지
|
||||
if (isPermissionFlowActive || isDialogShowing) return
|
||||
|
||||
val missingPermissions = mutableListOf<String>()
|
||||
|
||||
// 1. 알림 권한 (Android 13+)
|
||||
@@ -98,6 +111,9 @@ object AlarmPermissionUtil {
|
||||
|
||||
private fun showIntegratedPermissionDialog(activity: ComponentActivity, missing: List<String>) {
|
||||
if (activity.isFinishing || activity.isDestroyed) return
|
||||
if (isDialogShowing) return // 이미 모달이 떠있으면 중복 방지
|
||||
|
||||
isDialogShowing = true
|
||||
|
||||
val message = StringBuilder("안정적인 알람 작동을 위해 아래 권한들이 필요합니다:\n\n")
|
||||
missing.forEach { message.append("- $it\n") }
|
||||
@@ -108,16 +124,35 @@ object AlarmPermissionUtil {
|
||||
.setTitle("권한 설정 안내")
|
||||
.setMessage(message.toString())
|
||||
.setPositiveButton("확인") { _, _ ->
|
||||
isDialogShowing = false
|
||||
isPermissionFlowActive = true // 플로우 시작 - onResume 재호출 차단
|
||||
startPermissionFlow(activity)
|
||||
}
|
||||
.setNegativeButton("나중에", null)
|
||||
.setNegativeButton("나중에") { _, _ ->
|
||||
isDialogShowing = false
|
||||
// "나중에"를 누르면 이번 세션에서는 더 이상 묻지 않음
|
||||
isPermissionFlowActive = true
|
||||
}
|
||||
.setCancelable(false)
|
||||
.setOnDismissListener {
|
||||
// 어떤 이유로든 다이얼로그가 닫히면 플래그 해제
|
||||
isDialogShowing = false
|
||||
}
|
||||
.show()
|
||||
} catch (e: Exception) {
|
||||
isDialogShowing = false
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 권한 플로우 완료 후 플래그 리셋 (앱 재시작이나 설정에서 돌아올 때)
|
||||
*/
|
||||
fun resetPermissionFlowState() {
|
||||
isPermissionFlowActive = false
|
||||
isDialogShowing = false
|
||||
}
|
||||
|
||||
private fun startPermissionFlow(activity: ComponentActivity) {
|
||||
// 순차적으로 가장 중요한 것부터 요청
|
||||
|
||||
@@ -125,7 +160,7 @@ object AlarmPermissionUtil {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
if (ContextCompat.checkSelfPermission(activity, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(activity, arrayOf(Manifest.permission.POST_NOTIFICATIONS), 101)
|
||||
return // 알림 권한 결과 콜백 이후 다음으로 넘어가도록 유도 (혹은 그냥 연달아 띄움)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,8 +200,12 @@ object AlarmPermissionUtil {
|
||||
}
|
||||
activity.startActivity(intent)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 모든 권한이 허용된 경우 플로우 완료
|
||||
isPermissionFlowActive = false
|
||||
}
|
||||
|
||||
fun requestBatteryOptimization(context: Context) {
|
||||
|
||||
Reference in New Issue
Block a user