package Ġcom . sh o un ak mul ay . tele phony Ċ Ċ import Ġandroid . app . Activity Ċ import Ġandroid . content . pm . PackageManager Ċ import Ġandroid . content . pm . PackageManager . PERMISSION _ GRAN TED Ċ import Ġandroid . os . Build Ċ import Ġandroidx . annotation . Requires Api Ċ import Ġcom . sh o un ak mul ay . tele phony . utils . Constants . PHONE _ PERMISSION S Ċ import Ġcom . sh o un ak mul ay . tele phony . utils . Constants . SERVICE _ STATE _ PERMISSION S Ċ import Ġcom . sh o un ak mul ay . tele phony . utils . Constants . SMS _ PERMISSION S Ċ Ċ object ĠPermissions Controller Ġ{ ĊĊĠ Ġprivate Ġlateinit Ġvar Ġactivity : ĠActivity ĊĠ Ġvar Ġis Request ing Permission : ĠBoolean Ġ= Ġfalse ĊĊĠ Ġfun Ġset Activity ( activity : ĠActivity ) Ġ{ ĊĠĠĠ ĠPermissions Controller . activity Ġ= Ġactivity ĊĠ Ġ} ĊĊĠ Ġfun Ġhas Required Permissions ( permissions : ĠList < String >): ĠBoolean Ġ{ ĊĠĠĠ Ġif Ġ( this :: activity . isInitialized ) Ġ{ ĊĠĠĠĠĠ Ġvar Ġhas Permissions Ġ= Ġtrue ĊĠĠĠĠĠ Ġfor Ġ( permission Ġin Ġpermissions ) Ġ{ ĊĠĠĠĠĠĠĠ Ġhas Permissions Ġ= Ġhas Permissions Ġ&& Ġcheck Permission ( permission ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġreturn Ġhas Permissions ĊĠĠĠ Ġ} ĊĠĠĠ Ġreturn Ġfalse ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġcheck Permission ( permission : ĠString ): ĠBoolean Ġ{ ĊĠĠĠ Ġreturn ĠBuild . VERSION . SDK _ INT Ġ< ĠBuild . VERSION _ CODES . M Ġ|| Ġactivity . check Self Permission ( permission ) Ġ== ĠPER MISSION _ GRAN TED ĊĠ Ġ} ĊĊĠ Ġ@ Requires Api ( Build . VERSION _ CODES . M ) ĊĠ Ġfun Ġrequest Permissions ( permissions : ĠList < String >, Ġrequest Code : ĠInt ) Ġ{ ĊĠĠĠ Ġif Ġ( this :: activity . isInitialized Ġ&& Ġ! is Request ing Permission ) Ġ{ ĊĠĠĠĠĠ Ġis Request ing Permission Ġ= Ġtrue ĊĠĠĠĠĠ Ġactivity . request Permissions ( permissions . to Typed Array (), Ġrequest Code ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġfun Ġget Sms Permissions (): ĠList < String > Ġ{ ĊĠĠĠ Ġval Ġpermissions Ġ= ĠgetList ed Permissions () ĊĠĠĠ Ġreturn Ġpermissions . filter Ġ{ Ġpermission Ġ-> ĠSMS _ PERMISSION S . contains ( permission ) Ġ} ĊĠ Ġ} ĊĊĠ Ġfun Ġget Phone Permissions (): ĠList < String > Ġ{ ĊĠĠĠ Ġval Ġpermissions Ġ= ĠgetList ed Permissions () ĊĠĠĠ Ġreturn Ġpermissions . filter Ġ{ Ġpermission Ġ-> ĠPH ONE _ PERMISSION S . contains ( permission ) Ġ} ĊĠ Ġ} ĊĊĠ Ġfun Ġget Service State Permissions (): ĠList < String > Ġ{ ĊĠĠĠ Ġval Ġpermissions Ġ= ĠgetList ed Permissions () ĊĠĠĠ Ġreturn Ġpermissions . filter Ġ{ Ġpermission Ġ-> ĠSERVICE _ STATE _ PERMISSION S . contains ( permission ) Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun ĠgetList ed Permissions (): ĠArray < out ĠString > Ġ{ ĊĠĠĠ Ġif Ġ( this :: activity . isInitialized ) Ġ{ ĊĠĠĠĠĠ Ġactivity . application Context . apply Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġinfo Ġ= Ġpackage Manager . get Package Info ( packageName , ĠPackage Manager . GET _ PERMISSION S ) ĊĠĠĠĠĠĠĠ Ġreturn Ġinfo . requested Permissions Ġ?: ĠarrayOf () ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠĠĠ Ġreturn ĠarrayOf () ĊĠ Ġ} Ċ }