package moe.yuuta.workmode.access import android.content.Context import android.os.Binder import moe.yuuta.workmode.BuildConfig import moe.yuuta.workmode.Manifest internal data class HostInfo( val userId: Int, val hostContext: Context ) { companion object { /** * Generate the HostInfo from API caller. If it is NOT an authorized host, throw a SecurityException. */ @Throws(SecurityException::class) internal fun getHostInfoFromCaller(systemContext: Context): HostInfo { val user = Binder.getCallingUserHandle() systemContext.enforceCallingPermission(Manifest.permission.ACCESS, null) return HostInfo(user.hashCode(), systemContext.createPackageContextAsUser(BuildConfig.APPLICATION_ID, 0, user)) } } }