package Ġcom . react n ativ ed p 3 ts dk Ċ Ċ import Ġandroid . annotation . Suppress Lint Ċ import Ġandroid . content . Broadcast Receiver Ċ import Ġandroid . content . Context Ċ import Ġandroid . content . Intent Ċ import Ġandroid . net . Uri Ċ import Ġandroid . os . Power Manager Ċ import Ġandroid . provider . Settings Ċ import Ġcom . facebook . react . bridge .* Ċ import Ġcom . facebook . react . modules . core . Device Event Manager Module . RCT Device EventEmitter Ċ import Ġorg . dpp pt . android . sdk . DP 3 T Ċ import Ġorg . dpp pt . android . sdk . In fection Status Ċ import Ġorg . dpp pt . android . sdk . Tracing Status Ċ import Ġorg . dpp pt . android . sdk . backend . Response Callback Ċ import Ġorg . dpp pt . android . sdk . backend . models . Application Info Ċ import Ġorg . dpp pt . android . sdk . backend . models . Ex po see Auth Method Authorization Ċ import Ġorg . dpp pt . android . sdk . backend . models . Ex po see Auth Method Json Ċ import Ġorg . dpp pt . android . sdk . internal . database . Database Ċ import Ġorg . dpp pt . android . sdk . util . Signature Util Ċ import Ġjava . util .* Ċ import Ġkotlin . concurrent . thread Ċ Ċ class ĠD p 3 t Module ( react Context : ĠReact ApplicationContext ) Ġ: ĠReact Context Base Java Module ( react Context ) Ġ{ ĊĠ Ġprivate Ġvar Ġupdate Intent Receiver Registered Ġ= Ġfalse ĊĠ Ġprivate Ġvar Ġinitialized Ġ= Ġfalse ĊĠ Ġprivate Ġvar Ġsync Thread : ĠThread ? Ġ= Ġnull ĊĊĠ Ġoverride Ġfun ĠgetName (): ĠString Ġ{ ĊĠĠĠ Ġreturn Ġ" Dp 3 t " ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġget Constants (): ĠMutable Map < String , ĠAny > Ġ{ ĊĠĠĠ Ġval Ġconstants : ĠMutable Map < String , ĠAny > Ġ= ĠHashMap () ĊĠĠĠ Ġval Ġerror States Ġ= ĠArguments . create Map (); ĊĠĠĠ ĠTr acing Status . Error State . values (). forEach Ġ{ ĊĠĠĠĠĠ Ġerror States . putString ( it . name , Ġit . name ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġconstants [" error States "] Ġ= Ġerror States ĊĠĠĠ Ġconstants [" Dp 3 t Status Updated "] Ġ= Ġ" Dp 3 t Status Updated " ĊĠĠĠ Ġreturn Ġconstants ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġto JS Status ( context : ĠContext , Ġstatus : ĠTr acing Status ): ĠWrit able Map Ġ{ ĊĠĠĠ Ġval Ġmap Ġ= ĠArguments . create Map () ĊĠĠĠ Ġval Ġdatabase Ġ= ĠDatabase ( context ) ĊĊĠĠĠ Ġval Ġtracing State Ġ= Ġif Ġ( status . is Re ceiving ) Ġ" started " Ġelse Ġif Ġ( status . errors . isNotEmpty ()) Ġ" error " Ġelse Ġ" stopped " ĊĠĠĠ Ġval Ġhealth Status Ġ= Ġif Ġ( status . in fection Status Ġ== ĠIn fection Status . EXPOSE D ) Ġ" ex posed " Ġelse Ġif Ġ( status . in fection Status Ġ== ĠIn fection Status . INF ECT ED ) Ġ" inf ected " Ġelse Ġ" healthy " ĊĊĠĠĠ Ġmap . putString (" tracing State ", Ġtracing State ) ĊĠĠĠ Ġmap . put Int (" numberOf Hand sh akes ", Ġdatabase . hand sh akes . size ) ĊĠĠĠ Ġmap . put Int (" numberOf Contacts ", Ġstatus . numberOf Contacts ) ĊĠĠĠ Ġmap . putString (" health Status ", Ġhealth Status ) ĊĊĠĠĠ Ġif Ġ( status . last Sync Date Ġ> Ġ 0 ) Ġ{ ĊĠĠĠĠĠ Ġmap . putString (" last Sync Date ", Ġstatus . last Sync Date . toString ( 1 0 )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġerrors Ġ= ĠArguments . create Array (); ĊĠĠĠ Ġval Ġnative Errors Ġ= ĠArguments . create Array () ĊĠĠĠ Ġstatus . errors . forEach Ġ{ ĊĠĠĠĠĠ Ġnative Errors . push String ( it . name ) ĊĠĠĠĠĠ Ġwhen Ġ( it ) Ġ{ ĊĠĠĠĠĠĠĠ ĠTr acing Status . Error State . BLE _ DISABLED Ġ-> Ġerrors . push String (" bluetooth Disabled ") ĊĠĠĠĠĠĠĠ ĠTr acing Status . Error State . MISSING _ LOCATION _ PERMISSION , ĠTr acing Status . Error State . B ATTER Y _ OPTIMI Z ER _ ENABLED Ġ-> Ġerrors . push String (" permission Missing ") ĊĠĠĠĠĠĠĠ ĠTr acing Status . Error State . SYNC _ ERROR _ SERVER , ĠTr acing Status . Error State . SYNC _ ERROR _ NETWORK , ĠTr acing Status . Error State . SYNC _ ERROR _ TIM ING , ĠTr acing Status . Error State . SYNC _ ERROR _ DATABASE , ĠTr acing Status . Error State . SYNC _ ERROR _ SIGNATURE Ġ-> Ġerrors . push String (" sync ") ĊĠĠĠĠĠĠĠ Ġelse Ġ-> Ġerrors . push String (" other ") ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠĠĠ Ġmap . put Array (" errors ", Ġerrors ) ĊĠĠĠ Ġmap . put Array (" native Errors ", Ġnative Errors ) ĊĊĠĠĠ Ġval Ġexposed Days Ġ= ĠArguments . create Array () ĊĠĠĠ Ġstatus . ex posure Days . forEach () Ġ{ ĊĠĠĠĠĠ Ġval Ġcontact Ġ= ĠArguments . create Map () ĊĠĠĠĠĠ Ġcontact . put Int (" id ", Ġit . id ) ĊĠĠĠĠĠ Ġcontact . putString (" ex posed Date ", Ġit . ex posed Date . start OfDay Timestamp . toString ( 1 0 )) Ġ// Ġy yyy - MM - dd ĊĠĠĠĠĠ Ġcontact . putString (" report Date ", Ġit . report Date . toString ( 1 0 )) ĊĠĠĠĠĠ Ġexposed Days . push Map ( contact ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġmap . put Array (" ex posed Days ", Ġexposed Days ) ĊĊĠĠĠ Ġreturn Ġmap ĊĠ Ġ} ĊĊĠ Ġ// ĠSee Ġhttps :// facebook . github . io / react - native / docs / native - modules - android ĊĠ Ġ@ React Method ĊĠ Ġfun Ġis Initialized ( promise : ĠPromise ) Ġ{ ĊĠĠĠ Ġpromise . resolve ( initialized ); ĊĠ Ġ} ĊĊĠ Ġ@ React Method ĊĠ Ġfun Ġinit With Discovery ( backend AppId : ĠString , ĠpublicKey Base 6 4 : ĠString , Ġdev : ĠBoolean , Ġpromise : ĠPromise ) Ġ{ ĊĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠ Ġregister Update Intent Receiver () ĊĠĠĠĠĠ ĠDP 3 T . init ( react ApplicationContext . application Context , Ġbackend AppId , Ġdev , ĠSignature Util . get PublicKey From Base 6 4 ( publicKey Base 6 4 )) ĊĊĠĠĠĠĠ Ġinitialized Ġ= Ġtrue ĊĠĠĠĠĠ Ġpromise . resolve ( null ) ĊĠĠĠ Ġ} Ġcatch Ġ( throwable : ĠThrowable ) Ġ{ ĊĠĠĠĠĠ Ġpromise . reject ( throwable ); ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ React Method ĊĠ Ġfun Ġinit Man ually ( backend AppId : ĠString , Ġreport BaseUrl : ĠString , Ġbucket BaseUrl : ĠString , ĠpublicKey Base 6 4 : ĠString , Ġpromise : ĠPromise ) Ġ{ ĊĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠ Ġregister Update Intent Receiver () ĊĠĠĠĠĠ ĠDP 3 T . init ( react ApplicationContext . application Context , ĠApplication Info ( backend AppId , Ġreport BaseUrl , Ġbucket BaseUrl ), ĠSignature Util . get PublicKey From Base 6 4 ( publicKey Base 6 4 )) ĊĊĠĠĠĠĠ Ġinitialized Ġ= Ġtrue ĊĠĠĠĠĠ Ġpromise . resolve ( null ) ĊĠĠĠ Ġ} Ġcatch Ġ( throwable : ĠThrowable ) Ġ{ ĊĠĠĠĠĠ Ġpromise . reject ( throwable ); ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ React Method ĊĠ Ġ@ Suppress Lint (" Battery Life ") Ġ// ĠReason Ġfor Ġusing Ġintent ĠSettings . ACTION _ REQUEST _ IGNORE _ B ATTER Y _ OPTIMI Z ATIONS Ġis Ġexplained Ġin Ġmodule 's ĠRead me ĊĠ Ġpublic Ġfun Ġcheck Battery Optimization De activated ( promise : ĠPromise ) Ġ{ ĊĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠ Ġval Ġpower Manager Ġ= Ġreact ApplicationContext . getSystem Service ( Context . POWER _ SERVICE ) Ġas ĠPower Manager ĊĠĠĠĠĠ Ġval Ġbattery Optimization De activated Ġ= Ġpower Manager . is Ign oring Battery Optim izations ( react ApplicationContext . packageName ) ĊĊĠĠĠĠĠ Ġif Ġ(! battery Optimization De activated ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġintent Ġ= ĠIntent ( Settings . ACTION _ REQUEST _ IGNORE _ B ATTER Y _ OPTIMI Z ATIONS , ĊĠĠĠĠĠĠĠĠĠ ĠUri . parse (" package :" Ġ+ Ġreact ApplicationContext . packageName )) ĊĠĠĠĠĠĠĠ Ġintent . add Flags ( Intent . FLAG _ ACTIVITY _ NEW _ TASK ) ĊĠĠĠĠĠĠĠ Ġreact ApplicationContext . startActivity ( intent ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġpromise . resolve ( null ) ĊĠĠĠ Ġ} Ġcatch Ġ( throwable : ĠThrowable ) Ġ{ ĊĠĠĠĠĠ Ġpromise . reject ( throwable ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġregister Update Intent Receiver () Ġ{ ĊĠĠĠ Ġif Ġ(! update Intent Receiver Registered ) Ġ{ ĊĠĠĠĠĠ Ġreact ApplicationContext . register Receiver ( object Ġ: ĠBroadcast Receiver () Ġ{ ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġon Receive ( context : ĠContext , Ġintent : ĠIntent ) Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġreact ApplicationContext ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. get JS Module ( RCT Device EventEmitter :: class . java ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. emit (" Dp 3 t Status Updated ", Ġto JS Status ( react ApplicationContext . application Context , ĠDP 3 T . getStatus ( react ApplicationContext . application Context ))) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ}, ĠDP 3 T . get Update Intent Filter ()) ĊĠĠĠĠĠ Ġupdate Intent Receiver Registered Ġ= Ġtrue ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ React Method ĊĠ Ġfun Ġstart ( promise : ĠPromise ) Ġ{ ĊĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠ ĠDP 3 T . start ( react ApplicationContext . application Context ) ĊĠĠĠĠĠ Ġpromise . resolve ( null ); ĊĠĠĠ Ġ} Ġcatch Ġ( throwable : ĠThrowable ) Ġ{ ĊĠĠĠĠĠ Ġpromise . reject ( throwable ); ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ React Method ĊĠ Ġfun Ġstop ( promise : ĠPromise ) Ġ{ ĊĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠ ĠDP 3 T . stop ( react ApplicationContext . application Context ) ĊĠĠĠĠĠ Ġpromise . resolve ( null ); ĊĠĠĠ Ġ} Ġcatch Ġ( throwable : ĠThrowable ) Ġ{ ĊĠĠĠĠĠ Ġpromise . reject ( throwable ); ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ React Method ĊĠ Ġfun Ġcurrent Tracing Status ( promise : ĠPromise ) Ġ{ ĊĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠ Ġval Ġstatus Ġ= ĠDP 3 T . getStatus ( react ApplicationContext . application Context ) ĊĊĠĠĠĠĠ Ġpromise . resolve ( to JS Status ( react ApplicationContext . application Context , Ġstatus )) ĊĠĠĠ Ġ} Ġcatch Ġ( throwable : ĠThrowable ) Ġ{ ĊĠĠĠĠĠ Ġpromise . reject ( throwable ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ React Method ĊĠ Ġfun Ġsend IA m Inf ected ( timestamp : ĠString , Ġauth : ĠRead able Map , Ġpromise : ĠPromise ) Ġ{ ĊĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠ Ġval Ġtimestamp Long Ġ= Ġtimestamp . to Long ( 1 0 ); ĊĠĠĠĠĠ Ġval Ġdate Ġ= ĠDate ( timestamp Long ) ĊĊĠĠĠĠĠ Ġval Ġex po see Auth Ġ= Ġwhen Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġauth . has Key (" authorization ") Ġ-> ĠEx po see Auth Method Authorization ( auth . getString (" authorization ")) ĊĠĠĠĠĠĠĠĠĠ Ġauth . has Key (" json ") Ġ-> ĠEx po see Auth Method Json ( auth . getString (" json ")) ĊĠĠĠĠĠĠĠĠĠ Ġelse Ġ-> Ġthrow ĠIllegalArgumentException (" Bad Ġauth Ġmethod ") ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ ĠDP 3 T . send IA m Inf ected ( react ApplicationContext , Ġdate , Ġex po see Auth , Ġobject Ġ: ĠResponse Callback < Void ?> Ġ{ ĊĠĠĠĠĠĠĠ Ġoverride Ġfun ĠonSuccess ( response : ĠVoid ?) Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġpromise . resolve ( null ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġoverride Ġfun ĠonError ( throwable : ĠThrowable ) Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġpromise . reject ( throwable ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ}) ĊĠĠĠ Ġ} Ġcatch Ġ( throwable : ĠThrowable ) Ġ{ ĊĠĠĠĠĠ Ġpromise . reject ( throwable ); ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ React Method ĊĠ Ġfun Ġsync ( promise : ĠPromise ) Ġ{ ĊĠĠĠ Ġif Ġ( sync Thread Ġ!= Ġnull ) Ġ{ ĊĠĠĠĠĠ Ġreturn Ġpromise . resolve ( false ); ĊĠĠĠ Ġ} ĊĠĠĠ Ġsync Thread Ġ= Ġthread Ġ{ ĊĠĠĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠĠĠ ĠDP 3 T . sync ( react ApplicationContext ); ĊĠĠĠĠĠĠĠ Ġpromise . resolve ( true ) ĊĠĠĠĠĠ Ġ} Ġcatch Ġ( throwable : ĠThrowable ) Ġ{ ĊĠĠĠĠĠĠĠ Ġpromise . reject ( throwable ); ĊĠĠĠĠĠ Ġ} Ġfinally Ġ{ ĊĠĠĠĠĠĠĠ Ġsync Thread Ġ= Ġnull ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ React Method ĊĠ Ġfun Ġclear Data ( promise : ĠPromise ) Ġ{ ĊĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠ ĠDP 3 T . clear Data ( react ApplicationContext ) Ġ{ Ġpromise . resolve ( null ) Ġ} ĊĠĠĠ Ġ} Ġcatch Ġ( throwable : ĠThrowable ) Ġ{ ĊĠĠĠĠĠ Ġpromise . reject ( throwable ) ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ } Ċ