diff options
Diffstat (limited to 'app/src/main/java/moe/yuuta/workmode/access/HostInfo.kt')
-rw-r--r-- | app/src/main/java/moe/yuuta/workmode/access/HostInfo.kt | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/app/src/main/java/moe/yuuta/workmode/access/HostInfo.kt b/app/src/main/java/moe/yuuta/workmode/access/HostInfo.kt new file mode 100644 index 0000000..05b1622 --- /dev/null +++ b/app/src/main/java/moe/yuuta/workmode/access/HostInfo.kt @@ -0,0 +1,25 @@ +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)) + } + } +}
\ No newline at end of file |