package Ġcom . oasis f eng . is land . installer Ċ Ċ import Ġandroid . app . Search Manager Ċ import Ġandroid . content . Component Name Ċ import Ġandroid . content . Intent Ċ import Ġandroid . content . Intent . ACTION _ SEARCH Ċ import Ġandroid . content . pm . Labeled Intent Ċ import Ġandroid . content . pm . PackageManager . MATCH _ DEFAULT _ ONLY Ċ import Ġandroid . content . pm . PackageManager . MATCH _ SYSTEM _ ONLY Ċ import Ġandroid . net . Uri Ċ import Ġandroid . os . Build . VERSION . SDK _ INT Ċ import Ġandroid . os . Build . VERSION _ CODES . O Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . os . User Handle Ċ import Ġandroid . provider . Settings Ċ import Ġandroid . text . TextUtils Ċ import Ġandroid . util . Log Ċ import Ġcom . oasis f eng . android . content . Intent Compat Ċ import Ġcom . oasis f eng . android . util . Apps Ċ import Ġcom . oasis f eng . is land . sh ut tle . Activity Shut tle Ċ import Ġcom . oasis f eng . is land . sh ut tle . Shut tle Ċ import Ġcom . oasis f eng . is land . util . Caller Aware Activity Ċ import Ġcom . oasis f eng . is land . util . Users Ċ import Ġjava . util .* Ċ Ċ /** Ċ Ġ* ĠCreated Ġby ĠO asis Ġon Ġ 2 0 1 8 - 1 1 - 1 6 . Ċ Ġ*/ Ċ class ĠApp Info For warder Activity Ġ: ĠCall er Aware Activity () Ġ{ ĊĊ ĉ override Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ Ċĉ ĉ super . onCreate ( savedInstanceState ) Ċĉ ĉ val Ġintent Ġ= Ġintent . set Component ( null ). set Package ( null ) Ċĉ ĉ val Ġuser : ĠUser Handle ? Ġ= Ġintent . get Parcelable Extra ( Intent . EXTRA _ USER ) Ċĉ ĉ if Ġ( user Ġ!= Ġnull Ġ&& Ġintent . action Ġ== ĠSettings . ACTION _ APPLICATION _ DETAILS _ SETTINGS ) Ġ{ Ġ Ġ// ĠFor Ġprofiles Ġother Ġthan Ġdefault Ċĉĉ ĉ intent . remove Extra ( Intent . EXTRA _ USER ) Ċĉĉ ĉ Shut tle ( this , Ġuser ). launch Ġ{ Ċĉĉĉ ĉ startActivity ( intent . add Flags ( Intent . FLAG _ ACTIVITY _ NEW _ TASK )) Ġ} Ċĉ ĉ } Ġelse Ġintent . getString Extra ( Intent Compat . EXTRA _ PACKAGE _ NAME )?. also Ġ{ Ġpkg Ġ-> Ċĉĉ ĉ startActivity ( build Target Intent ( pkg , Ġuser , Ġintent )) Ġ} Ċĉ ĉ finish () Ċ ĉ } ĊĊ ĉ private Ġfun Ġbuild Target Intent ( pkg : ĠString , Ġuser : ĠUser Handle ?, Ġtarget : ĠIntent ): ĠIntent Ġ{ Ċĉ ĉ val Ġcaller Ġ= Ġcalling Package ; Ġval Ġpm Ġ= Ġpackage Manager Ċĉ ĉ val Ġdetails Ġ= ĠIntent ( Settings . ACTION _ APPLICATION _ DETAILS _ SETTINGS , ĠUri . from Parts (" package ", Ġpkg , Ġnull )) Ċĉ ĉ val Ġdetails Activity Ġ= Ġtry Ġ{ Ġpm . query Intent Activities ( details , ĠMATCH _ SYSTEM _ ONLY ). get OrNull ( 0 )?. activity Info Ġ} Ċĉ ĉ catch Ġ( e : ĠNullPointerException ) Ġ{ Ġnull . also Ġ{ ĠLog . e ( TAG , Ġ" Error Ġquerying Ġapp Ġdetail Ġactivities : Ġ$ details ", Ġe ) Ġ}} ĠĠĠ Ġ// ĠHu awei - specific Ġissue , Ġonly Ġreported Ġon ĠAndroid Ġ 8 Ċĉ ĉ var Ġis Caller Not Settings Ġ= Ġtrue ĠĠĠĠĠ Ġ// ĠCall er Ġis Ġnot Ġsystem ĠSettings Ġapp Ċĉ ĉ val Ġtarget Res olves Ġby Ġlazy Ġ{ Ġpm . query Intent Activities ( target , ĠMATCH _ DEFAULT _ ONLY Ġ/* ĠEx cluding Ġthis Ġactivity Ġ*/) Ġ} ĊĊĉ ĉ if Ġ( details Activity Ġ!= Ġnull ) Ġ{ Ċĉĉ ĉ val Ġref errer Ġ= Ġref errer ?. take If Ġ{ Ġit . scheme Ġ== Ġ" android - app " Ġ} ?. authority Ċĉĉ ĉ is Caller Not Settings Ġ= Ġref errer Ġ!= ĠCALL ER _ PLACE HOLDER _ FOR _ SETTINGS Ġ&& Ġcaller Ġ!= Ġdetails Activity . packageName Ċĉĉ ĉ if Ġ( is Caller Not Settings Ġ&& Ġ! Ġis Caller Is land But Not For warder ( caller )) Ġ{ ĠĠĠ Ġ// ĠStarted Ġby Ġ 3 rd - party Ġapp Ġor Ġthis Ġfor warder Ġitself Ċĉĉĉ ĉ val Ġintent Ġ= ĠIntent ( ACTION _ SEARCH ). putExtra ( Search Manager . QUERY , Ġ" package :$ pkg "). set Package ( packageName ) Ċĉĉĉ ĉ if Ġ( user Ġ!= Ġnull ) Ġintent . putExtra ( Intent . EXTRA _ USER , Ġuser ) Ċĉĉĉ ĉ pm . resolve Activity ( intent , Ġ 0 )?. also Ġ{ Ċĉĉĉĉ ĉ return Ġintent . set ClassName ( this , Ġit . activity Info . name ) Ġ}} ĊĊĉĉ ĉ if Ġ( is Caller Not Settings Ġ&& Ġuser Ġ!= Ġnull Ġ&& Ġuser Ġ!= ĠUsers . current ()) Ġ{ Ċĉĉĉ ĉ if Ġ( user Ġ== ĠUsers . profile ) Ġdetails . component Ġ= ĠActivity Shut tle . get For warder ( this ) Ġ// ĠForward ing Ġadded Ġin ĠIsland Provisioning Ċĉĉĉ ĉ else Ġdetails . set Component ( component Name ). putExtra ( Intent . EXTRA _ USER , Ġuser ) Ċĉĉ ĉ } Ġelse ĠActivity Shut tle . force Never Forwarding ( pm , Ġdetails ) ĊĊĉĉ ĉ if Ġ( SDK _ INT Ġ< ĠO Ġ&& Ġis Caller Not Settings Ġ&& Ġtarget Res olves . all Ġ{ Ġit . activity Info . packageName Ġ== Ġ" android " Ġ}) Ċĉĉĉ ĉ return Ġdetails Ġ} Ġ// ĠNo Ġactual Ġtarget , Ġjust Ġsimulate ĠEX TRA _ AUTO _ LA UNCH _ SINGLE _ CHO ICE Ġon ĠAndroid Ġpre - O . ĊĊĉ ĉ val Ġtitle Ġ= ĠgetString ( R . string . app _ info _ for warder _ title , ĠApps . of ( this ). get AppName ( pkg ), Ġpkg ) Ċĉ ĉ val Ġcho oser Ġ= ĠIntent . create Chooser ( target , Ġtitle ). add Flags ( Intent . FLAG _ ACTIVITY _ FORWARD _ RESULT ) Ċĉ ĉ if Ġ( SDK _ INT Ġ>= ĠO ) Ġcho oser . putExtra ( Intent Compat . EXTRA _ AUTO _ LA UNCH _ SINGLE _ CHO ICE , Ġis Caller Not Settings ) Ċĉ ĉ val Ġinitial Intent s : ĠMutable List < Intent > Ġ= ĠArrayList () Ċĉ ĉ if Ġ( is Caller Not Settings Ġ&& Ġdetails Activity Ġ!= Ġnull ) Ġ{ Ċĉĉ ĉ if Ġ( user Ġ!= Ġnull Ġ&& Ġ! ĠUsers . is Owner ( user ) Ġ&& ĠUsers . is Profile Managed By Is land ( user )) Ġ{ ĠĠĠ Ġ// ĠUse Ġmain land Ġresolve Ġto Ġreplace Ġthe Ġmis leading Ġforwarding - resolved Ġ" Switch Ġto Ġwork Ġprofile ". Ċĉĉĉ ĉ val Ġlabel Res Ġ= Ġdetails Activity . run Ġ{ Ġif Ġ( label Res Ġ!= Ġ 0 ) Ġlabel Res Ġelse Ġapplication Info . label Res Ġ} Ċĉĉĉ ĉ initial Intent s . add ( Labeled Intent ( details , Ġdetails Activity . packageName , Ġlabel Res , Ġdetails Activity . icon Resource )) Ċĉĉ ĉ } Ġelse Ġinitial Intent s . add ( details ) Ġ} ĊĊĉ ĉ // ĠAlso Ġadd Ġapp Ġmark ets Ġto Ġthe Ġcho oser . ĠEX TRA _ ALTER N ATE _ INT ENTS Ġis Ġnot Ġused Ġhere Ġdue Ġto Ġin ability Ġof Ġde - dup . Ġ( e . g . ĠGoogle ĠPlay ĠStore ) Ċĉ ĉ val Ġmarket Intent Ġ= ĠIntent ( Intent . ACTION _ VIEW , ĠUri . parse (" market :// details ? id =$ pkg ")) Ċĉ ĉ val Ġexclude s Ġ= ĠArrayList < Component Name >() Ċĉ ĉ pm . query Intent Activities ( market Intent , Ġ 0 ). forEach Ġ{ Ġresolve Ġ-> Ġval Ġactivity Ġ= Ġresolve . activity Info Ċĉĉ ĉ if Ġ( activity . packageName Ġ== Ġcaller ) Ġreturn @ forEach Ċĉĉ ĉ initial Intent s . add ( Intent ( market Intent ). set ClassName ( activity . packageName , Ġactivity . name )) Ċĉĉ ĉ target Res olves . map Ġ{ Ġit . activity Info Ġ}. first OrNull Ġ{ Ġactivity . packageName Ġ== Ġit . packageName Ġ&& Ġactivity . label Res Ġ== Ġit . label Res Ċĉĉĉĉ ĉ && ĠText Utils . equals ( activity . non Localized Label , Ġit . non Localized Label ) Ġ} ?. also Ġ{ Ċĉĉĉ ĉ exclude s . add ( Component Name ( it . packageName , Ġit . name )) Ġ}} ĊĊĉ ĉ if Ġ( is Caller Not Settings Ġ&& Ġis Caller Is land But Not For warder ( caller )) Ċĉĉ ĉ exclude s . add ( Component Name ( this , ĠApp Info For warder Activity :: class . java )) ĊĊĉ ĉ return Ġcho oser . apply Ġ{ Ċĉĉ ĉ if Ġ( exclude s . isNotEmpty ()) Ġput Extra ( Intent . EXTRA _ EXCL UDE _ COMPONENTS , Ġexclude s . to Typed Array ()) Ċĉĉ ĉ if Ġ( initial Intent s . isNotEmpty ()) Ġput Extra ( Intent . EXTRA _ INITIAL _ INT ENTS , Ġinitial Intent s . to Typed Array ()) Ġ} Ċ ĉ } ĊĊ ĉ private Ġfun Ġis Caller Is land But Not For warder ( caller : ĠString ?): ĠBoolean Ġ{ Ċĉ ĉ return ĠpackageName Ġ== Ġcaller Ġ&& Ġintent . flags Ġand ĠIntent . FLAG _ ACTIVITY _ FORWARD _ RESULT Ġ== Ġ 0 Ċ ĉ } ĊĊ ĉ comp anion Ġobject Ġ{ Ċĉ ĉ fun Ġmark As La unched By Settings ( intent : ĠIntent ) Ġ= Ċĉĉĉ ĉ intent . putExtra ( Intent . EXTRA _ REF ERR ER , ĠUri . parse (" android - app :// $ CALL ER _ PLACE HOLDER _ FOR _ SETTINGS ")) Ċ ĉ } Ċ } Ċ Ċ private Ġconst Ġval ĠCALL ER _ PLACE HOLDER _ FOR _ SETTINGS Ġ= Ġ" settings " Ċ private Ġconst Ġval ĠTAG Ġ= Ġ" Is land . A IF " Ċ