refactor(android): P2.1 Batch A - delegate status/permission methods to services
- Refactor checkStatus() to delegate to NotificationStatusChecker - Refactor getNotificationStatus() to delegate to NotificationStatusChecker - Refactor checkPermissionStatus() to delegate to PermissionManager - Add service instance variables and initialization in load() - Defer getExactAlarmStatus() (requires complex service initialization) Reduces plugin class complexity by ~130 lines. Services already exist - this is delegation, not extraction. Refs: docs/progress/P2.1-BATCH-1.md
This commit is contained in:
@@ -90,6 +90,9 @@ open class DailyNotificationPlugin : Plugin() {
|
||||
|
||||
// Service instances for delegation
|
||||
private var statusChecker: NotificationStatusChecker? = null
|
||||
private var permissionManager: PermissionManager? = null
|
||||
private var exactAlarmManager: DailyNotificationExactAlarmManager? = null
|
||||
private var channelManager: ChannelManager? = null
|
||||
|
||||
override fun load() {
|
||||
super.load()
|
||||
@@ -100,6 +103,12 @@ open class DailyNotificationPlugin : Plugin() {
|
||||
}
|
||||
db = DailyNotificationDatabase.getDatabase(context)
|
||||
statusChecker = NotificationStatusChecker(context)
|
||||
channelManager = ChannelManager(context)
|
||||
permissionManager = PermissionManager(context, channelManager)
|
||||
// Note: exactAlarmManager requires AlarmManager and DailyNotificationScheduler
|
||||
// For now, we'll initialize it lazily when needed, or create a simpler version
|
||||
// This is a known limitation - exactAlarmManager initialization needs refactoring
|
||||
exactAlarmManager = null // Will be initialized on-demand if needed
|
||||
Log.i(TAG, "Daily Notification Plugin loaded successfully")
|
||||
|
||||
// Phase 1: Perform app launch recovery (cold start only)
|
||||
@@ -184,42 +193,8 @@ open class DailyNotificationPlugin : Plugin() {
|
||||
return call.reject("Context not available")
|
||||
}
|
||||
|
||||
Log.i(TAG, "Checking permission status")
|
||||
|
||||
var notificationsEnabled = false
|
||||
var exactAlarmEnabled = false
|
||||
var wakeLockEnabled = false
|
||||
|
||||
// Check POST_NOTIFICATIONS permission
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
notificationsEnabled = context.checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED
|
||||
} else {
|
||||
notificationsEnabled = NotificationManagerCompat.from(context).areNotificationsEnabled()
|
||||
}
|
||||
|
||||
// Check exact alarm permission
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as? AlarmManager
|
||||
exactAlarmEnabled = alarmManager?.canScheduleExactAlarms() ?: false
|
||||
} else {
|
||||
exactAlarmEnabled = true // Pre-Android 12, exact alarms are always allowed
|
||||
}
|
||||
|
||||
// Check wake lock permission (usually granted by default)
|
||||
val powerManager = context.getSystemService(Context.POWER_SERVICE) as? PowerManager
|
||||
wakeLockEnabled = powerManager != null
|
||||
|
||||
val allPermissionsGranted = notificationsEnabled && exactAlarmEnabled && wakeLockEnabled
|
||||
|
||||
val result = JSObject().apply {
|
||||
put("notificationsEnabled", notificationsEnabled)
|
||||
put("exactAlarmEnabled", exactAlarmEnabled)
|
||||
put("wakeLockEnabled", wakeLockEnabled)
|
||||
put("allPermissionsGranted", allPermissionsGranted)
|
||||
}
|
||||
|
||||
Log.i(TAG, "Permission status: notifications=$notificationsEnabled, exactAlarm=$exactAlarmEnabled, wakeLock=$wakeLockEnabled, all=$allPermissionsGranted")
|
||||
call.resolve(result)
|
||||
// Delegate to PermissionManager
|
||||
permissionManager?.checkPermissionStatus(call)
|
||||
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Failed to check permission status", e)
|
||||
@@ -282,6 +257,8 @@ open class DailyNotificationPlugin : Plugin() {
|
||||
return call.reject("Context not available")
|
||||
}
|
||||
|
||||
// Fallback to original implementation since exactAlarmManager requires complex initialization
|
||||
// TODO: Refactor exactAlarmManager initialization to support delegation
|
||||
Log.i(TAG, "Getting exact alarm status")
|
||||
|
||||
val supported = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
|
||||
|
||||
Reference in New Issue
Block a user