Skip to content

Commit

Permalink
Work account: Fix NewApi lint failure
Browse files Browse the repository at this point in the history
  • Loading branch information
fynngodau committed Sep 2, 2024
1 parent cbdab68 commit edd5a2f
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down

0 comments on commit edd5a2f

Please sign in to comment.