fix(android): resolve compilation errors in DailyNotificationPlugin
Fix all compilation errors identified in production readiness build check. Fixes: - Missing imports: Added AlarmManager and NotificationManagerCompat imports - getExactAlarmStatus(): Fixed to use exactAlarmManager or fallback to PermissionManager - canRequestExactAlarmPermission(): Implemented inline logic (method doesn't exist in PermissionManager) - requestExactAlarmPermission(): Fixed call sites to use single-parameter signature - JSObject.put ambiguity: Added explicit type casts for all put() calls - enabledSchedules scope: Fixed variable scope issue in ReactivationManager.kt Errors Fixed: - Unresolved reference: AlarmManager (multiple locations) - Unresolved reference: NotificationManagerCompat - Unresolved reference: getExactAlarmStatus - Unresolved reference: canRequestExactAlarmPermission - Too many arguments for requestExactAlarmPermission - Overload resolution ambiguity for JSObject.put - Unresolved reference: enabledSchedules Verification: - Kotlin compilation: PASS - Full assembleDebug build: PASS - All compilation errors resolved
This commit is contained in:
@@ -2,6 +2,7 @@ package com.timesafari.dailynotification
|
||||
|
||||
import android.Manifest
|
||||
import android.app.Activity
|
||||
import android.app.AlarmManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
@@ -11,6 +12,7 @@ import android.os.Build
|
||||
import android.provider.Settings
|
||||
import android.util.Log
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.work.WorkManager
|
||||
import androidx.work.OneTimeWorkRequestBuilder
|
||||
@@ -321,11 +323,24 @@ open class DailyNotificationPlugin : Plugin() {
|
||||
permissionManager = PermissionManager(context, channelManager)
|
||||
}
|
||||
|
||||
// Delegate to PermissionManager.getExactAlarmStatus()
|
||||
val result = permissionManager!!.getExactAlarmStatus()
|
||||
|
||||
Log.i(TAG, "Exact alarm status retrieved: ${result.toString()}")
|
||||
call.resolve(result)
|
||||
// Delegate to DailyNotificationExactAlarmManager if available, otherwise use PermissionManager
|
||||
if (exactAlarmManager != null) {
|
||||
val status = exactAlarmManager!!.getExactAlarmStatus()
|
||||
val result = JSObject().apply {
|
||||
put("supported", status.supported)
|
||||
put("enabled", status.enabled)
|
||||
put("canSchedule", status.canSchedule)
|
||||
put("fallbackWindow", JSObject().apply {
|
||||
put("startMs", status.fallbackWindow.startMs)
|
||||
put("lengthMs", status.fallbackWindow.lengthMs)
|
||||
})
|
||||
}
|
||||
Log.i(TAG, "Exact alarm status retrieved: ${status.toString()}")
|
||||
call.resolve(result)
|
||||
} else {
|
||||
// Fallback: Use PermissionManager's checkExactAlarmPermission
|
||||
permissionManager!!.checkExactAlarmPermission(call)
|
||||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Failed to get exact alarm status", e)
|
||||
@@ -735,8 +750,32 @@ open class DailyNotificationPlugin : Plugin() {
|
||||
permissionManager = PermissionManager(context, channelManager)
|
||||
}
|
||||
|
||||
// Delegate to PermissionManager
|
||||
return permissionManager!!.canRequestExactAlarmPermission()
|
||||
// Delegate to PermissionManager.checkExactAlarmPermission and extract canRequest
|
||||
// Note: This is a synchronous check, so we need to check directly
|
||||
val canSchedule = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as? AlarmManager
|
||||
alarmManager?.canScheduleExactAlarms() ?: false
|
||||
} else {
|
||||
true // Android 11 and below don't need this permission
|
||||
}
|
||||
|
||||
// Check if permission can be requested (Android 13+)
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
// Try reflection to call Settings.canRequestScheduleExactAlarms()
|
||||
try {
|
||||
val method = Settings::class.java.getMethod("canRequestScheduleExactAlarms", Context::class.java)
|
||||
method.invoke(null, context) as Boolean
|
||||
} catch (e: Exception) {
|
||||
// Fallback heuristic: if exact alarms are not currently allowed, assume we can request them
|
||||
!canSchedule
|
||||
}
|
||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
// Android 12 (API 31-32) - permission can always be requested
|
||||
true
|
||||
} else {
|
||||
// Android 11 and below - permission not needed
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -880,11 +919,11 @@ open class DailyNotificationPlugin : Plugin() {
|
||||
|
||||
val result = JSObject().apply {
|
||||
// Channel is enabled if both app notifications are enabled AND channel importance is not NONE
|
||||
put("enabled", finalEnabled)
|
||||
put("channelId", channelId)
|
||||
put("importance", if (importance >= 0) importance else android.app.NotificationManager.IMPORTANCE_DEFAULT)
|
||||
put("appNotificationsEnabled", appNotificationsEnabled)
|
||||
put("channelBlocked", importance == android.app.NotificationManager.IMPORTANCE_NONE)
|
||||
put("enabled", finalEnabled as Boolean)
|
||||
put("channelId", channelId as String)
|
||||
put("importance", (if (importance >= 0) importance else android.app.NotificationManager.IMPORTANCE_DEFAULT) as Int)
|
||||
put("appNotificationsEnabled", appNotificationsEnabled as Boolean)
|
||||
put("channelBlocked", (importance == android.app.NotificationManager.IMPORTANCE_NONE) as Boolean)
|
||||
}
|
||||
call.resolve(result)
|
||||
} catch (e: Exception) {
|
||||
@@ -1285,7 +1324,7 @@ open class DailyNotificationPlugin : Plugin() {
|
||||
if (activity == null) {
|
||||
return call.reject("Activity not available")
|
||||
}
|
||||
permissionManager!!.requestExactAlarmPermission(call, activity)
|
||||
permissionManager!!.requestExactAlarmPermission(call)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1335,7 +1374,7 @@ open class DailyNotificationPlugin : Plugin() {
|
||||
if (activity == null) {
|
||||
return call.reject("Activity not available")
|
||||
}
|
||||
permissionManager!!.requestExactAlarmPermission(call, activity)
|
||||
permissionManager!!.requestExactAlarmPermission(call)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -74,13 +74,12 @@ class ReactivationManager(private val context: Context) {
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Failed to load schedules from DB", e)
|
||||
emptyList()
|
||||
} finally {
|
||||
val dbDuration = System.currentTimeMillis() - dbStartTime
|
||||
if (dbDuration > 100) {
|
||||
Log.w(TAG, "Database query slow: ${dbDuration}ms for getEnabled()")
|
||||
} else {
|
||||
Log.d(TAG, "Database query: ${dbDuration}ms, schedules=${enabledSchedules.size}")
|
||||
}
|
||||
}
|
||||
val dbDuration = System.currentTimeMillis() - dbStartTime
|
||||
if (dbDuration > 100) {
|
||||
Log.w(TAG, "Database query slow: ${dbDuration}ms for getEnabled()")
|
||||
} else {
|
||||
Log.d(TAG, "Database query: ${dbDuration}ms, schedules=${enabledSchedules.size}")
|
||||
}
|
||||
|
||||
if (enabledSchedules.isEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user