package Ġde . mark us fis ch . android . binary eye . actions . wifi Ċ Ċ import Ġandroid . content . Context Ċ import Ġandroid . content . Context . WIFI _ SERVICE Ċ import Ġandroid . net . wifi . Wifi Configuration Ċ import Ġandroid . net . wifi . Wifi Manager Ċ import Ġandroid . widget . Toast Ċ import Ġde . mark us fis ch . android . binary eye . R Ċ import Ġde . mark us fis ch . android . binary eye . actions . I Action Ċ import Ġkotlinx . coroutines . Dispatch ers Ċ import Ġkotlinx . coroutines . delay Ċ import Ġkotlinx . coroutines . with Context Ċ import Ġkotlinx . coroutines . with Timeout OrNull Ċ Ċ object ĠW ifi Action Ġ: ĠI Action Ġ{ Ċ ĉ override Ġval Ġicon Res Id Ġ= ĠR . drawable . ic _ action _ wifi Ċ ĉ override Ġval Ġtitle Res Id Ġ= ĠR . string . connect _ to _ wifi ĊĊ ĉ override Ġfun Ġcan Execute On ( data : ĠByteArray ): ĠBoolean Ġ= Ċĉ ĉ Wifi Configuration Factory . parse ( String ( data )) Ġ!= Ġnull ĊĊ ĉ override Ġsuspend Ġfun Ġexecute ( context : ĠContext , Ġdata : ĠByteArray ) Ġ= Ġwith Context ( Dispatch ers . IO ) Ġ{ Ċĉ ĉ val Ġwifi Config Ġ= ĠW ifi Configuration Factory . parse ( Ċĉĉ ĉ String ( data ) Ċĉ ĉ ) Ġ?: Ġreturn @ with Context Ċĉ ĉ val Ġwifi Manager Ġ= Ġcontext . application Context . getSystem Service ( Ċĉĉ ĉ WIFI _ SERVICE Ċĉ ĉ ) Ġas ĠW ifi Manager ĊĊĉ ĉ wifi Manager . enable Wifi ( context ) Ċĉ ĉ wifi Manager . may Remove Old Network ( wifi Config ) Ċĉ ĉ wifi Manager . enable New Network ( wifi Config ) Ċĉ ĉ with Context ( Dispatch ers . Main ) Ġ{ Ċĉĉ ĉ Toast . makeText ( Ċĉĉĉ ĉ context , Ċĉĉĉ ĉ R . string . wifi _ added , Ċĉĉĉ ĉ Toast . LENGTH _ LONG Ċĉĉ ĉ ). show () Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġsuspend Ġfun ĠW ifi Manager . enable Wifi ( context : ĠContext ): ĠBoolean Ġ{ Ċĉ ĉ if Ġ(! is Wifi Enabled ) Ġ{ Ċĉĉ ĉ if Ġ(! set Wifi Enabled ( true )) Ġ{ Ċĉĉĉ ĉ with Context ( Dispatch ers . Main ) Ġ{ Ċĉĉĉĉ ĉ Toast . makeText ( Ċĉĉĉĉĉ ĉ context , Ċĉĉĉĉĉ ĉ R . string . wifi _ config _ failed , Ċĉĉĉĉĉ ĉ Toast . LENGTH _ LONG Ċĉĉĉĉ ĉ ). show () Ċĉĉĉ ĉ } Ċĉĉĉ ĉ return Ġfalse Ċĉĉ ĉ } Ċĉĉ ĉ // Ġwait Ġfor Ġwifi Ġto Ġreally Ġbe Ġenabled , Ġtakes Ġsome Ġtime Ċĉĉ ĉ with Timeout OrNull ( 1 0 0 0 0 ) Ġ{ Ċĉĉĉ ĉ while Ġ(! is Wifi Enabled ) Ġdelay ( 5 0 0 ) Ċĉĉ ĉ } Ġ?: Ġif Ġ(! is Wifi Enabled ) Ġ{ Ċĉĉĉ ĉ with Context ( Dispatch ers . Main ) Ġ{ Ċĉĉĉĉ ĉ Toast . makeText ( Ċĉĉĉĉĉ ĉ context , Ċĉĉĉĉĉ ĉ R . string . wifi _ config _ failed , Ċĉĉĉĉĉ ĉ Toast . LENGTH _ LONG Ċĉĉĉĉ ĉ ). show () Ċĉĉĉ ĉ } Ċĉĉĉ ĉ return Ġfalse Ċĉĉ ĉ } Ċĉ ĉ } Ċĉ ĉ return Ġtrue Ċ ĉ } ĊĊ ĉ private Ġsuspend Ġfun ĠW ifi Manager . may Remove Old Network ( Ċĉ ĉ wifi Config : ĠW ifi Configuration Ċ ĉ ) Ġ{ Ċĉ ĉ configured Networks ?. first OrNull Ġ{ Ċĉĉ ĉ it . SSID Ġ== Ġwifi Config . SSID Ġ&& Ċĉĉĉ ĉ it . allowed Key Management Ġ== Ġwifi Config . allowed Key Management Ċĉ ĉ } ?. network Id ?. also Ġ{ Ċĉĉ ĉ remove Network ( it ) Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġsuspend Ġfun ĠW ifi Manager . enable New Network ( Ċĉ ĉ wifi Config : ĠW ifi Configuration Ċ ĉ ) Ġ{ Ċĉ ĉ val Ġid Ġ= Ġadd Network ( wifi Config ) Ċĉ ĉ disconnect () Ċĉ ĉ enable Network ( id , Ġtrue ) Ċĉ ĉ reconnect () Ċ ĉ } Ċ } Ċ