package Ġcom . car ter chen 2 4 7 . alarm scheduler . receiver Ċ Ċ import Ġandroid . content . Broadcast Receiver Ċ import Ġandroid . content . Context Ċ import Ġandroid . content . Intent Ċ import Ġcom . car ter chen 2 4 7 . alarm scheduler . Alarm Scheduler Ċ import Ġcom . car ter chen 2 4 7 . alarm scheduler . constant . Constant Ċ import Ġcom . car ter chen 2 4 7 . alarm scheduler . error . ErrorHandler Ċ import Ġcom . car ter chen 2 4 7 . alarm scheduler . logger . Logger Ċ import Ġcom . car ter chen 2 4 7 . alarm scheduler . model . Data Payload Ċ import Ġcom . car ter chen 2 4 7 . alarm scheduler . storage . Alarm State Repository Ċ import Ġkotlinx . coroutines . Coroutine ExceptionHandler Ċ import Ġkotlinx . coroutines . launch Ċ Ċ internal Ġclass ĠAlarm Trigger Receiver Ġ: ĠBroadcast Receiver () Ġ{ ĊĠĠĠ Ġoverride Ġfun Ġon Receive ( context : ĠContext , Ġintent : ĠIntent ) Ġ{ ĊĠĠĠĠĠĠĠ ĠLogger . d (" Alarm Trigger Receiver . on Receive ") ĊĠĠĠĠĠĠĠ Ġval Ġalarm Type Ġ= Ġintent . getInt Extra ( Constant . ALARM _ TYPE , ĠConstant . VALUE _ NOT _ ASSIGN ) ĊĠĠĠĠĠĠĠ Ġval Ġalarm Id Ġ= Ġintent . getInt Extra ( Constant . ALARM _ ID , ĠConstant . VALUE _ NOT _ ASSIGN ) ĊĠĠĠĠĠĠĠ Ġval Ġbundle Ġ= Ġintent . get Bundle Extra ( Constant . ALARM _ CUSTOM _ DATA ) ĊĠĠĠĠĠĠĠ ĠLogger . d (" Alarm Trigger Receiver . on Receive Ġalarm Type =$ alarm Type Ġalarm Id =$ alarm Id Ġbundle =$ bundle ") ĊĠĠĠĠĠĠĠ Ġif Ġ( alarm Type Ġ== ĠConstant . VALUE _ NOT _ ASSIGN Ġ|| Ġalarm Id Ġ== ĠConstant . VALUE _ NOT _ ASSIGN ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġalarm Task Factory Ġ= ĠAlarm Scheduler . get Impl (). get Alarm Task Factory () ĊĠĠĠĠĠĠĠ Ġif Ġ( alarm Task Factory Ġ== Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠError Handler . onError ( IllegalStateException (" Failed Ġcreating ĠAlarm Task , Ġalarm Task Factory Ġis Ġnull ")) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ ĠLogger . d (" Creating ĠAlarm Task . Ġalarm Type =$ alarm Type Ġalarm Id =$ alarm Id ") ĊĠĠĠĠĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġalarm Task Ġ= Ġalarm Task Factory . create Alarm Task ( alarm Type ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġalarm Task . on Alarm F ires ( alarm Id , ĠData Payload . create ( bundle )) ĊĠĠĠĠĠĠĠ Ġ} Ġcatch Ġ( throwable : ĠThrowable ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠError Handler . onError ( IllegalStateException (" Failed Ġcreating ĠAlarm Task ", Ġthrowable )) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ ĠAlarm Scheduler . get Impl (). coroutine Scope . launch ( Coroutine ExceptionHandler Ġ{ Ġ_, Ġthrowable Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ ĠError Handler . onError ( IllegalStateException (" Failed Ġremoving Ġfired Ġalarm Id ", Ġthrowable )) ĊĠĠĠĠĠĠĠ Ġ}) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAlarm State Repository . getInstance ( context ). remove Immediate ly ( alarm Id ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ }