diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementServiceImpl.java index 8b5b49738..a595bdba7 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementServiceImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementServiceImpl.java @@ -455,6 +455,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { if (permanentDelete) { result = AndroidAPIUtils.getDeviceManagementService().deleteDevice(deviceIdentifier); } else { + AndroidDeviceUtils.updateDisEnrollOperationStatus(deviceIdentifier); result = AndroidAPIUtils.getDeviceManagementService().disenrollDevice(deviceIdentifier); } if (result) { diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidDeviceUtils.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidDeviceUtils.java index 0e6319f9a..a6c949957 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidDeviceUtils.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidDeviceUtils.java @@ -572,4 +572,25 @@ public class AndroidDeviceUtils { } } + /** + * Update status of pending operations to error when a dis-enroll operation is triggered. + * + * @param deviceIdentifier Identifier of the device + * @throws DeviceManagementException + */ + public static void updateDisEnrollOperationStatus(DeviceIdentifier deviceIdentifier) + throws DeviceManagementException { + try { + List pendingOperations = getPendingOperations(deviceIdentifier); + for (Operation operation : pendingOperations) { + operation.setStatus(Operation.Status.ERROR); + AndroidAPIUtils.getDeviceManagementService().updateOperation(deviceIdentifier, operation); + } + } catch (OperationManagementException e) { + String msg = "Error occurred while retrieving pending operations to update operation statuses of " + + "device to be dis-enrolled"; + log.error(msg); + throw new DeviceManagementException(msg, e); + } + } }