Disable AndroidDeviceOwnerApi for store builds

This commit is contained in:
Jonas Lochmann 2024-04-15 02:00:00 +02:00
parent 141c967b74
commit c0ea7962cd
No known key found for this signature in database
GPG key ID: 8B8C9AEE10FA5B36

View file

@ -71,6 +71,7 @@ class AndroidDeviceOwnerApi(
override val delegations: List<DeviceOwnerApi.DelegationScope> = delegationList.map { it.second }
override fun setDelegations(packageName: String, scopes: List<DeviceOwnerApi.DelegationScope>) {
if (BuildConfig.storeCompilant) throw IllegalStateException()
if (VERSION.SDK_INT <= VERSION_CODES.O) throw IllegalStateException()
val resolvedScopes = scopes.map { scope ->
@ -89,6 +90,7 @@ class AndroidDeviceOwnerApi(
}
override fun getDelegations(): Map<String, List<DeviceOwnerApi.DelegationScope>> {
if (BuildConfig.storeCompilant) return emptyMap()
if (VERSION.SDK_INT <= VERSION_CODES.O) throw IllegalStateException()
return delegationList.map { (scope, delegation) ->
@ -109,6 +111,7 @@ class AndroidDeviceOwnerApi(
}
override fun transferOwnership(packageName: String, dryRun: Boolean) {
if (BuildConfig.storeCompilant) throw IllegalStateException()
if (VERSION.SDK_INT < VERSION_CODES.P) throw IllegalStateException()
if (!devicePolicyManager.isDeviceOwnerApp(componentName.packageName)) throw SecurityException()
@ -127,6 +130,7 @@ class AndroidDeviceOwnerApi(
}
override fun grantLocationAccess(): Boolean {
if (BuildConfig.storeCompilant) return false
if (VERSION.SDK_INT < VERSION_CODES.LOLLIPOP) return false
if (!devicePolicyManager.isDeviceOwnerApp(componentName.packageName)) return false