package Ġio . j erry c 0 5 . hello _ ssr Ċ Ċ import Ġandroid . app .* Ċ import Ġandroid . content .* Ċ import Ġandroid . os .* Ċ import Ġandroidx . core . app .* Ċ import Ġandroidx . core . content .* Ċ import Ġio . j erry c 0 5 . hello _ ssr . aid l .* Ċ import Ġio . j erry c 0 5 . hello _ ssr . utils .* Ċ import Ġjava . util .* Ċ Ċ class ĠShadow socks Notification Ġconstructor ( private Ġval Ġservice : ĠService , Ġprivate Ġval Ġprofile Name : ĠString , Ġprivate Ġval Ġvisible : ĠBoolean Ġ= Ġfalse ) Ċ { Ċ ĉ private Ġval Ġcallback Ġby Ġlazy Ġ{ Ċĉ ĉ object Ġ: ĠI Shadow socks Service Callback . Stub () Ċĉ ĉ { Ċĉĉ ĉ override Ġfun Ġstate Changed ( state : ĠInt , Ġprofile Name : ĠString , Ġmsg : ĠString ) Ċĉĉ ĉ { Ċĉĉ ĉ } ĊĊĉĉ ĉ override Ġfun Ġtraffic Updated ( tx Rate : ĠLong , Ġrx Rate : ĠLong , Ġtx Total : ĠLong , Ġrx Total : ĠLong ) Ċĉĉ ĉ { Ċĉĉĉ ĉ val Ġtx r Ġ= ĠTraffic Monitor . format Traffic ( tx Rate ) Ċĉĉĉ ĉ val Ġrx r Ġ= ĠTraffic Monitor . format Traffic ( rx Rate ) Ċĉĉĉ ĉ builder . setContent Text ( String . format ( Locale . EN GL ISH , Ġservice . getString ( R . string . traffic _ summary ), Ġtx r , Ġrx r )) ĊĊĉĉĉ ĉ style . big Text ( String . format ( Locale . EN GL ISH , Ċĉĉĉĉĉĉĉĉĉĉ ĉ service . getString ( R . string . stat _ summary ), Ċĉĉĉĉĉĉĉĉĉĉ ĉ tx r , Ċĉĉĉĉĉĉĉĉĉĉ ĉ rx r , Ċĉĉĉĉĉĉĉĉĉĉ ĉ Traffic Monitor . format Traffic ( tx Total ), Ċĉĉĉĉĉĉĉĉĉĉ ĉ Traffic Monitor . format Traffic ( rx Total ))) Ċĉĉĉ ĉ show () Ċĉĉ ĉ } Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġval Ġpm : ĠPower Manager Ġ= Ġservice . getSystem Service ( Context . POWER _ SERVICE ) Ġas ĠPower Manager Ċ ĉ private Ġval Ġkey Guard : ĠKey guard Manager Ġ= Ġservice . getSystem Service ( Context . KEY GU ARD _ SERVICE ) Ġas ĠKey guard Manager Ċ ĉ private Ġval Ġnm : ĠNotification Manager Ġ= Ġservice . getSystem Service ( Context . NOTIFICATION _ SERVICE ) Ġas ĠNotification Manager Ċ ĉ private Ġvar Ġcallback Registered : ĠBoolean Ġ= Ġfalse Ċ ĉ private Ġlateinit Ġvar Ġbuilder : ĠNotification Compat . Builder Ċ ĉ private Ġval Ġstyle : ĠNotification Compat . Big TextStyle Ċ ĉ private Ġvar Ġis Visible Ġ= Ġtrue ĊĊ ĉ private Ġvar Ġlock Receiver : ĠBroadcast Receiver ? Ġ= Ġobject Ġ: ĠBroadcast Receiver () Ċ ĉ { Ċĉ ĉ override Ġfun Ġon Receive ( context : ĠContext , Ġintent : ĠIntent ) Ċĉ ĉ { Ċĉĉ ĉ update ( intent . action ) Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġval Ġservice State : ĠInt Ċĉ ĉ get () Ċĉ ĉ { Ċĉĉ ĉ var Ġstate Ġ= Ġ 0 Ċĉĉ ĉ if Ġ( service Ġis ĠBase Vpn Service ) Ċĉĉ ĉ { Ċĉĉĉ ĉ state Ġ= Ġservice . currentState Ċĉĉ ĉ } Ċĉĉ ĉ else Ġif Ġ( service Ġis ĠBase Service ) Ċĉĉ ĉ { Ċĉĉĉ ĉ state Ġ= Ġservice . currentState Ċĉĉ ĉ } Ċĉĉ ĉ return Ġstate Ċĉ ĉ } ĊĊ ĉ init Ċ ĉ { Ċĉ ĉ // Ġinit Ġnotification Ġbuilder Ċĉ ĉ init Notification Builder () Ċĉ ĉ style Ġ= ĠNotification Compat . Big TextStyle ( builder ) ĊĊĉ ĉ // Ġinit Ġwith Ġupdate Ġaction Ċĉ ĉ initWith Update Action () ĊĊĉ ĉ // Ġregister Ġlock Ġreceiver Ċĉ ĉ register Lock Receiver ( service , Ġvisible ) Ċ ĉ } ĊĊ ĉ private Ġfun Ġupdate ( action : ĠString ?, Ġforce Show : ĠBoolean Ġ= Ġfalse ) Ċ ĉ { Ċĉ ĉ if Ġ( force Show Ġ|| Ġservice State Ġ== ĠConstants . State . CONNECTED ) Ċĉ ĉ { Ċĉĉ ĉ when Ġ( action ) Ċĉĉ ĉ { Ċĉĉĉ ĉ Intent . ACTION _ SCREEN _ OFF Ġ-> Ċĉĉĉ ĉ { Ċĉĉĉĉ ĉ setVisible ( visible Ġ&& Ġ! Utils . is L ol lip op Or Above , Ġforce Show ) Ċĉĉĉĉ ĉ // Ġunregister Ġcallback Ġto Ġsave Ġbattery Ċĉĉĉĉ ĉ unregister Callback () Ċĉĉĉ ĉ } Ċĉĉĉ ĉ Intent . ACTION _ SCREEN _ ON Ġ-> Ċĉĉĉ ĉ { Ċĉĉĉĉ ĉ setVisible ( visible Ġ&& ĠUtils . is L ol lip op Or Above Ġ&& Ġ! key Guard . is Key guard Locked , Ġforce Show ) Ċĉĉĉĉ ĉ try Ċĉĉĉĉ ĉ { Ċĉĉĉĉĉ ĉ register Service Callback ( callback ) Ċĉĉĉĉ ĉ } Ċĉĉĉĉ ĉ catch Ġ( e : ĠRemoteException ) Ċĉĉĉĉ ĉ { Ċĉĉĉĉĉ ĉ // ĠIgnore d Ċĉĉĉĉ ĉ } Ċĉĉĉĉ ĉ callback Registered Ġ= Ġtrue Ċĉĉĉ ĉ } Ċĉĉĉ ĉ Intent . ACTION _ USER _ PRESENT Ġ-> Ġset Visible ( true , Ġforce Show ) Ċĉĉ ĉ } Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ fun Ġdestroy () Ċ ĉ { Ċĉ ĉ if Ġ( lock Receiver Ġ!= Ġnull ) Ċĉ ĉ { Ċĉĉ ĉ service . unregister Receiver ( lock Receiver ) Ċĉĉ ĉ lock Receiver Ġ= Ġnull Ċĉ ĉ } Ċĉ ĉ unregister Callback () Ċĉ ĉ service . stop Foreground ( true ) Ċĉ ĉ nm . cancel ( 1 ) Ċ ĉ } ĊĊ ĉ private Ġfun Ġset Visible ( visible : ĠBoolean , Ġforce Show : ĠBoolean ) Ċ ĉ { Ċĉ ĉ if Ġ( isVisible Ġ!= Ġvisible ) Ċĉ ĉ { Ċĉĉ ĉ isVisible Ġ= Ġvisible Ċĉĉ ĉ builder . priority Ġ= Ġif Ġ( visible ) ĠNotification Compat . PRIORITY _ LOW Ġelse ĠNotification Compat . PRIORITY _ MIN Ċĉĉ ĉ show () Ċĉ ĉ } Ċĉ ĉ else Ġif Ġ( force Show ) Ċĉ ĉ { Ċĉĉ ĉ show () Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ fun Ġshow () Ċ ĉ { Ċĉ ĉ service . start Foreground ( 1 , Ġbuilder . build ()) Ċ ĉ } ĊĊ ĉ private Ġfun Ġunregister Callback () Ċ ĉ { Ċĉ ĉ if Ġ( callback Registered ) Ċĉ ĉ { Ċĉĉ ĉ try Ċĉĉ ĉ { Ċĉĉĉ ĉ unregister Service Callback ( callback ) Ċĉĉ ĉ } Ċĉĉ ĉ catch Ġ( e : ĠRemoteException ) Ċĉĉ ĉ { Ċĉĉĉ ĉ e . printStackTrace () Ċĉĉ ĉ } ĊĊĉĉ ĉ callback Registered Ġ= Ġfalse Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġfun Ġregister Lock Receiver ( service : ĠService , Ġvisible : ĠBoolean ) Ċ ĉ { Ċĉ ĉ val Ġscreen Filter Ġ= ĠIntent Filter () Ċĉ ĉ screen Filter . addAction ( Intent . ACTION _ SCREEN _ ON ) Ċĉ ĉ screen Filter . addAction ( Intent . ACTION _ SCREEN _ OFF ) Ċĉ ĉ if Ġ( visible Ġ&& ĠUtils . is L ol lip op Or Above ) Ċĉ ĉ { Ċĉĉ ĉ screen Filter . addAction ( Intent . ACTION _ USER _ PRESENT ) Ċĉ ĉ } Ċĉ ĉ service . register Receiver ( lock Receiver , Ġscreen Filter ) Ċ ĉ } ĊĊ ĉ private Ġfun Ġinit With Update Action () Ċ ĉ { Ċĉ ĉ val Ġaction Ġ= Ġif Ġ( pm . is Interactive ) ĠIntent . ACTION _ SCREEN _ ON Ġelse ĠIntent . ACTION _ SCREEN _ OFF Ċĉ ĉ update ( action , Ġtrue ) Ċ ĉ } ĊĊ ĉ private Ġfun Ġinit Notification Builder () Ċ ĉ { Ċĉ ĉ val Ġchannel Id Ġ= Ġ" net _ speed " Ċĉ ĉ if Ġ( Build . VERSION . SDK _ INT Ġ>= ĠBuild . VERSION _ CODES . O ) Ċĉ ĉ { Ċĉĉ ĉ val Ġchannel Ġ= ĠNotification Channel ( channelId , Ġ" Net Speed ", ĠNotification Manager . IMPORT ANCE _ MIN ) Ċĉĉ ĉ channel . set Sound ( null , Ġnull ) Ċĉĉ ĉ nm . create Notification Channel ( channel ) Ċĉ ĉ } Ċĉ ĉ builder Ġ= ĠNotification Compat . Builder ( service , Ġchannel Id ) Ċĉĉ ĉ . set When ( 0 ) Ċĉĉ ĉ . setColor ( Context Compat . getColor ( service , ĠR . color . material _ accent _ 5 0 0 )) Ċĉĉ ĉ . set Ticker ( service . getString ( R . string . forward _ success )) Ċĉĉ ĉ . setContent Title ( profile Name ) Ċĉĉ ĉ . setContent Intent ( Pending Intent . getActivity ( service , Ġ 0 , ĠIntent ( service , ĠShadow socks :: class . java ) Ċĉĉĉ ĉ . set Flags ( Intent . FLAG _ ACTIVITY _ RE ORDER _ TO _ FRONT ), Ġ 0 )) Ċĉĉ ĉ . set Small Icon ( R . drawable . ic _ stat _ shadow socks ) Ċĉ ĉ builder . addAction ( R . drawable . ic _ navigation _ close , ĊĉĉĉĉĉĉĠ Ġservice . getString ( R . string . stop ), ĊĉĉĉĉĉĉĠ ĠPending Intent . get Broadcast ( service , Ġ 0 , ĠIntent ( Constants . Action . CLOSE ), Ġ 0 )) ĊĊĉ ĉ val Ġprofiles Ġ= ĠShadow socks Application . app . profile Manager . all Profiles Ċĉ ĉ if Ġ( profiles . isNotEmpty ()) Ċĉ ĉ { Ċĉĉ ĉ builder . addAction ( R . drawable . ic _ action _ settings , Ġservice . getString ( R . string . quick _ switch ), ĊĉĉĉĉĉĉĉĠ ĠPending Intent . getActivity ( service , Ġ 0 , ĠIntent ( Constants . Action . QU ICK _ SWITCH ), Ġ 0 )) Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġfun Ġregister Service Callback ( callback : ĠI Shadow socks Service Callback ) Ċ ĉ { Ċĉ ĉ var Ġbinder : ĠI Shadow socks Service . Stub ? Ġ= Ġnull Ċĉ ĉ if Ġ( service Ġis ĠBase Vpn Service ) Ċĉ ĉ { Ċĉĉ ĉ binder Ġ= Ġservice . binder Ċĉ ĉ } Ċĉ ĉ else Ġif Ġ( service Ġis ĠBase Service ) Ċĉ ĉ { Ċĉĉ ĉ binder Ġ= Ġservice . binder Ċĉ ĉ } Ċĉ ĉ binder ?. register Callback ( callback ) Ċ ĉ } ĊĊ ĉ private Ġfun Ġunregister Service Callback ( callback : ĠI Shadow socks Service Callback ) Ċ ĉ { Ċĉ ĉ var Ġbinder : ĠI Shadow socks Service . Stub ? Ġ= Ġnull Ċĉ ĉ if Ġ( service Ġis ĠBase Vpn Service ) Ċĉ ĉ { Ċĉĉ ĉ binder Ġ= Ġservice . binder Ċĉ ĉ } Ċĉ ĉ else Ġif Ġ( service Ġis ĠBase Service ) Ċĉ ĉ { Ċĉĉ ĉ binder Ġ= Ġservice . binder Ċĉ ĉ } Ċĉ ĉ binder ?. unregister Callback ( callback ) Ċ ĉ } Ċ } Ċ