diff --git a/play-services-auth-workaccount/core/src/main/kotlin/org/microg/gms/auth/workaccount/WorkAccountService.kt b/play-services-auth-workaccount/core/src/main/kotlin/org/microg/gms/auth/workaccount/WorkAccountService.kt index d5dc430b7..3f6145dce 100644 --- a/play-services-auth-workaccount/core/src/main/kotlin/org/microg/gms/auth/workaccount/WorkAccountService.kt +++ b/play-services-auth-workaccount/core/src/main/kotlin/org/microg/gms/auth/workaccount/WorkAccountService.kt @@ -38,7 +38,7 @@ class WorkAccountService : BaseService(TAG, GmsService.WORK_ACCOUNT) { ) { val packageName = PackageUtils.getAndCheckCallingPackage(this, request.packageName) val policyManager = getSystemService(Context.DEVICE_POLICY_SERVICE) as DevicePolicyManager - val authorized = policyManager.isDeviceOwnerApp(packageName) || policyManager.isProfileOwnerApp(packageName) + val authorized = policyManager.isDeviceAdminApp(packageName) if (authorized) { callback.onPostInitCompleteWithConnectionInfo( @@ -59,6 +59,15 @@ class WorkAccountService : BaseService(TAG, GmsService.WORK_ACCOUNT) { } } +private fun DevicePolicyManager.isDeviceAdminApp(packageName: String?): Boolean { + if (packageName == null) return false + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + isDeviceOwnerApp(packageName) || isProfileOwnerApp(packageName) + } else { + isDeviceOwnerApp(packageName) + } +} + class WorkAccountServiceImpl(context: Context) : IWorkAccountService.Stub() { val packageManager: PackageManager = context.packageManager