/* Ċ Ġ* ĠCopyright Ġ 2 0 2 2 ĠGoogle ĠLLC Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* ĠĠĠĠĠ Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ Ċ package Ġcom . google . autom otive . comp anion Ċ Ċ import Ġandroid . app . Activity Manager Ċ import Ġandroid . app . Activity Manager . Running App Process Info . IMPORT ANCE _ FO REG ROUND Ċ import Ġandroid . app . Activity Manager . Running App Process Info . IMPORT ANCE _ VISIBLE Ċ import Ġandroid . content . Component Name Ċ import Ġandroid . content . Context Ċ import Ġandroid . content . Intent Ċ import Ġandroid . content . Service Connection Ċ import Ġandroid . os . IB inder Ċ import Ġandroidx . lifecycle . Default Lifecycle Observer Ċ import Ġandroidx . lifecycle . Lifecycle Ċ import Ġandroidx . lifecycle . Lifecycle Owner Ċ import Ġcom . google . android . libraries . car . communication . mess ag ings ync . Messaging Sync Manager Ċ import Ġcom . google . android . libraries . car . connection service . Feature Manager Service Binder Ċ import Ġcom . google . autom otive . comp anion . Messaging Sync Constants . DISABLE _ MESS AGING _ SYNC _ FEATURE Ċ import Ġcom . google . autom otive . comp anion . Messaging Sync Constants . ENABLE _ MESS AGING _ SYNC _ FEATURE Ċ import Ġcom . google . autom otive . comp anion . Messaging Sync Constants . IS _ MESS AGING _ SYNC _ FEATURE _ ENABLED Ċ import Ġcom . google . autom otive . comp anion . Messaging Sync Constants . ON _ FAILURE _ TO _ ENABLE _ MESS AGING _ SYNC _ ROUTE Ċ import Ġcom . google . autom otive . comp anion . Messaging Sync Constants . ON _ MESS AGING _ SYNC _ ENABLED _ ROUTE Ċ import Ġio . flutter . embedding . engine . dart . Dart Executor Ċ import Ġio . flutter . plugin . common . MethodCall Ċ import Ġio . flutter . plugin . common . Method Channel Ċ Ċ /** Ċ Ġ* Ġ ĠMessaging ĠSync ĠMethod ĠChannel Ġto Ġbridge ĠFlutter Ġapp Ġto Ġnative ĠAndroid Ġcode Ċ Ġ*/ Ċ class ĠMessaging Sync Method Channel ( ĊĠ Ġprivate Ġval Ġcontext : ĠContext , ĊĠ Ġlifecycle : ĠLifecycle , ĊĠ Ġdart Executor : ĠDart Executor Ċ ) Ġ: ĠMethod Channel . MethodCall Handler , ĠDefault Lifecycle Observer Ġ{ ĊĠ Ġprivate Ġval Ġmethod Channel Ġ= ĠMethod Channel ( dart Executor , ĠMessaging Sync Constants . CHANNEL ) ĊĠ Ġprivate Ġvar Ġmessaging Sync Manager : ĠMessaging Sync Manager ? Ġ= Ġnull ĊĊĠ Ġprivate Ġval Ġservice Connection Ġ= Ġobject Ġ: ĠService Connection Ġ{ ĊĠĠĠ Ġoverride Ġfun Ġon Service Connected ( name : ĠComponent Name , Ġservice : ĠI Binder ) Ġ{ ĊĠĠĠĠĠ Ġval Ġbinder Ġ= Ġservice Ġas ĠFeature Manager Service Binder ĊĠĠĠĠĠ Ġval Ġconnected Device Service Ġ= Ġbinder . getService () ĊĠĠĠĠĠ Ġmessaging Sync Manager Ġ= Ġconnected Device Service . get Feature Manager ( Messaging Sync Manager :: class . java ) ĊĠĠĠĠĠ Ġmessaging Sync Manager Ġ= Ġconnected Device Service . get Feature Manager ( Messaging Sync Manager :: class . java ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Service Disconnected ( name : ĠComponent Name ?) Ġ{ ĊĠĠĠĠĠ Ġmessaging Sync Manager Ġ= Ġnull ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġinit Ġ{ ĊĠĠĠ Ġlifecycle . add Observer ( this ) ĊĠĠĠ Ġmethod Channel . set MethodCall Handler ( this ) ĊĠĠĠ Ġcontext . bind Service ( ĊĠĠĠĠĠ ĠConnected Device Service . create Intent ( context ), ĊĠĠĠĠĠ Ġservice Connection , ĊĠĠĠĠĠ ĠContext . BIND _ AUTO _ CREATE ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġon Destroy ( owner : ĠLifecycle Owner ) Ġ{ ĊĠĠĠ Ġcontext . unbind Service ( service Connection ) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġon MethodCall ( call : ĠMethod Call , Ġresult : ĠMethod Channel . Result ) Ġ{ ĊĠĠĠ Ġwhen Ġ( call . method ) Ġ{ ĊĠĠĠĠĠ ĠIS _ MESS AGING _ SYNC _ FEATURE _ ENABLED Ġ-> Ġis Messaging Sync Feature Enabled ( call , Ġresult ) ĊĠĠĠĠĠ ĠENABLE _ MESS AGING _ SYNC _ FEATURE Ġ-> Ġenable Messaging Sync Feature ( call ) ĊĠĠĠĠĠ ĠDISABLE _ MESS AGING _ SYNC _ FEATURE Ġ-> Ġdisable Messaging Sync Feature ( call ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġis Messaging Sync Feature Enabled ( call : ĠMethod Call , Ġresult : ĠMethod Channel . Result ) Ġ{ ĊĠĠĠ Ġval Ġcar Id Ġ= Ġcall . arguments Ġas ? ĠString Ġ?: Ġreturn Ġresult . success ( false ) ĊĠĠĠ Ġresult . success ( messaging Sync Manager ?. is Messaging Sync Enabled ( car Id )) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġenable Messaging Sync Feature ( call : ĠMethod Call ) Ġ{ ĊĠĠĠ Ġval Ġcar Id Ġ= Ġcall . arguments Ġas ? ĠString Ġ?: Ġreturn ĊĠĠĠ Ġval ĠonSuccess Ġ= Ġ{ ĊĠĠĠĠĠ Ġmove To Foreground () ĊĠĠĠĠĠ Ġmethod Channel . invoke Method ( ON _ MESS AGING _ SYNC _ ENABLED _ ROUTE , Ġcar Id ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġon Failure Ġ= Ġ{ ĊĠĠĠĠĠ Ġmove To Foreground () ĊĠĠĠĠĠ Ġmethod Channel . invoke Method ( ON _ FAILURE _ TO _ ENABLE _ MESS AGING _ SYNC _ ROUTE , Ġcar Id ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġmessaging Sync Manager ?. enable Messaging Sync ( car Id , ĠonSuccess , Ġon Failure ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġdisable Messaging Sync Feature ( call : ĠMethod Call ) Ġ{ ĊĠĠĠ Ġval Ġcar Id Ġ= Ġcall . arguments Ġas ? ĠString Ġ?: Ġreturn ĊĠĠĠ Ġmessaging Sync Manager ?. disable Messaging Sync ( car Id ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġmove To Foreground () Ġ{ ĊĠĠĠ Ġif Ġ( is Foreground ()) Ġreturn ĊĠĠĠ Ġval Ġintent Ġ= ĠIntent ( context , ĠMainActivity :: class . java ). apply Ġ{ ĊĠĠĠĠĠ Ġflags Ġ= ĠIntent . FLAG _ ACTIVITY _ RE ORDER _ TO _ FRONT ĊĠĠĠ Ġ} ĊĠĠĠ Ġcontext . startActivity ( intent ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġis Foreground (): ĠBoolean Ġ{ ĊĠĠĠ Ġval Ġapp Process Info Ġ= ĠActivity Manager . Running App Process Info () ĊĠĠĠ ĠActivity Manager . get My Memory State ( app Process Info ) ĊĠĠĠ Ġreturn Ġapp Process Info . import ance Ġ== ĠIMPORT ANCE _ FO REG ROUND Ġ|| ĊĠĠĠĠĠĠĠĠĠĠ Ġapp Process Info . import ance Ġ== ĠIMPORT ANCE _ VISIBLE ĊĠ Ġ} Ċ } Ċ