Background location permission not granted in Android Q for Device Owner app through DevicePolicyManager at the time of device enrolment.

    coarseP = 
 mPolicyManager.setPermissionGrantState(mAdminComponent, 
  mContext.getPackageName(),
        Manifest.permission.ACCESS_COARSE_LOCATION, 
   DevicePolicyManager.PERMISSION_GRANT_STATE_GRANTED);
    fineP  = 
 mPolicyManager.setPermissionGrantState(mAdminComponent, 
  mContext.getPackageName(),
        Manifest.permission.ACCESS_FINE_LOCATION, 
  DevicePolicyManager.PERMISSION_GRANT_STATE_GRANTED);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
    {
        backgroundP = 
  mPolicyManager.setPermissionGrantState(mAdminComponent, 
   mContext.getPackageName(),
            Manifest.permission.ACCESS_BACKGROUND_LOCATION, 
    DevicePolicyManager.PERMISSION_GRANT_STATE_GRANTED);
    }

Result of all 3 API call (coarseP,fineP,backgroundP) is true but only foreground permission is granted.

Strangely when I add the same code in Broadcast receiver on app update then the background permission is granted in this case.

0

There are 0 answers