package Ġcom . oval . sms _ receiver Ċ Ċ import Ġandroid . app . Activity Ċ import Ġandroid . content . Intent Filter Ċ import Ġandroid . util . Log Ċ import Ġandroidx . annotation . NonNull Ċ import Ġcom . google . android . gms . auth . api . phone . Sms Retriever Ċ import Ġio . flutter . embedding . engine . plugins . Flutter Plugin Ċ import Ġio . flutter . embedding . engine . plugins . activity . Activity Aware Ċ import Ġio . flutter . embedding . engine . plugins . activity . Activity Plugin Binding Ċ import Ġio . flutter . plugin . common . MethodCall Ċ import Ġio . flutter . plugin . common . Method Channel Ċ import Ġio . flutter . plugin . common . Method Channel . MethodCall Handler Ċ import Ġio . flutter . plugin . common . Method Channel . Result Ċ Ċ class ĠS ms Receiver Plugin : ĠFlutter Plugin , ĠMethod Call Handler , ĠActivity Aware Ġ{ ĊĊĠ Ġprivate Ġlateinit Ġvar Ġchannel Ġ: ĠMethod Channel ĊĠ Ġprivate Ġlateinit Ġvar Ġactivity : ĠActivity ĊĊĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠ Ġconst Ġval ĠTAG : ĠString Ġ= Ġ" FL UT TER - SMS - RECE IVER " ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġon Attached To Engine (@ NonNull Ġflutter Plugin Binding : ĠFlutter Plugin . Flutter Plugin Binding ) Ġ{ ĊĠĠĠ Ġchannel Ġ= ĠMethod Channel ( flutter Plugin Binding . binary Messenger , Ġ" com . oval . sms _ receiver ") ĊĠĠĠ Ġchannel . set MethodCall Handler ( this ) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġon Detached From Engine ( binding : ĠFlutter Plugin . Flutter Plugin Binding ) Ġ{ ĊĠ Ġ} ĊĊĠ Ġprivate Ġval Ġsms Broadcast Receiver Ġby Ġlazy Ġ{ ĠSMS Broadcast Receiver () Ġ} ĊĠ Ġprivate Ġvar Ġis Listening : ĠBoolean Ġ= Ġfalse ĊĊĊĠ Ġoverride Ġfun Ġon MethodCall ( call : ĠMethod Call , Ġresult : ĠResult ) Ġ{ ĊĠĠĠ ĠLog . d ( TAG , Ġ" calling Ġ${ call . method }") ĊĠĠĠ Ġwhen ( call . method ) Ġ{ ĊĠĠĠĠĠ Ġ" get Platform Version " Ġ-> Ġ{ ĊĠĠĠĠĠĠĠ Ġresult . success (" Android Ġ${ android . os . Build . VERSION . RELEASE }") ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ" start Listening " Ġ-> Ġ{ ĊĠĠĠĠĠĠĠ Ġsynchronized ( this ){ ĊĠĠĠĠĠĠĠĠĠ Ġif (! is Listening ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġis Listening Ġ= Ġtrue ĊĠĠĠĠĠĠĠĠĠĠĠ Ġstart Listening () ĊĠĠĠĠĠĠĠĠĠĠĠ ĠLog . d ( TAG , Ġ" SMS ĠReceiver ĠRegistered ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġresult . success ( true ) ĊĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠ Ġelse { ĊĠĠĠĠĠĠĠĠĠĠĠ ĠLog . d ( TAG , Ġ" Prevent ing Ġregister Ġmultiple ĠSMS Ġreceiver ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġresult . success ( false ) ĊĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ" stop Listening " Ġ-> Ġ{ ĊĠĠĠĠĠĠĠ Ġif ( is Listening ) Ġ{ ĊĠĠĠĠĠĠĠĠĠ ĠLog . d ( TAG , Ġ" SMS ĠReceiver Ġlistener Ġstopped Ġmanually ") ĊĠĠĠĠĠĠĠĠĠ Ġstop Listening () ĊĠĠĠĠĠĠĠĠĠ Ġresult . success ( false ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġelse Ġ-> Ġ{ ĊĠĠĠĠĠĠĠ Ġresult . not Implemented () ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġstart Listening () Ġ{ ĊĠĠĠ Ġval Ġclient Ġ= ĠS ms Retriever . getClient ( activity ) ĊĠĠĠ Ġval Ġretrie ver Ġ= Ġclient . start Sms Retriever () ĊĠĠĠ Ġretrie ver . add On Success Listener Ġ{ ĊĠĠĠĠĠ Ġval Ġlistener Ġ= Ġobject : SMS Broadcast Receiver . Listener Ġ{ ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġon SMS Received ( message : ĠString ) Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġchannel . invoke Method (" on Sms Received ", Ġmessage ) ĊĠĠĠĠĠĠĠĠĠ Ġstop Listening () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġon Timeout () Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġchannel . invoke Method (" on Timeout ", Ġnull ) ĊĠĠĠĠĠĠĠĠĠ Ġstop Listening () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġsms Broadcast Receiver . inject Listener ( listener ) ĊĠĠĠĠĠ Ġactivity . register Receiver ( sms Broadcast Receiver , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠIntent Filter ( Sms Retriever . SMS _ RE TR IE VED _ ACTION )) ĊĠĠĠ Ġ} ĊĠĠĠ Ġretrie ver . add On Failure Listener Ġ{ ĊĠĠĠĠĠ Ġchannel . invoke Method (" on Failure Listener ", Ġnull ) ĊĠĠĠĠĠ Ġstop Listening () ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġstop Listening () Ġ{ ĊĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠ Ġactivity . unregister Receiver ( sms Broadcast Receiver ) ĊĠĠĠ Ġ} Ġcatch Ġ( e : ĠException ) Ġ{ ĊĠĠĠĠĠ Ġ// ĠIgnore d ĊĠĠĠ Ġ} Ġfinally Ġ{ ĊĠĠĠĠĠ Ġis Listening Ġ= Ġfalse ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġon Attached To Activity ( binding : ĠActivity Plugin Binding ) Ġ{ ĊĠĠĠ Ġactivity Ġ= Ġbinding . activity ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġon Detached From Activity For Config Changes () Ġ{ ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġon Re attached To Activity For Config Changes ( binding : ĠActivity Plugin Binding ) Ġ{ ĊĠĠĠ Ġactivity Ġ= Ġbinding . activity ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġon Detached From Activity () Ġ{ ĊĠ Ġ} Ċ }