From 281e0a636e7c2243c92ca4fd317db9208d0db8da Mon Sep 17 00:00:00 2001 From: Saad Sahibjan Date: Tue, 25 Jun 2019 19:37:15 +0530 Subject: [PATCH] Update pending operations status of device to be disenrolled --- .../impl/DeviceManagementServiceImpl.java | 1 + .../android/util/AndroidDeviceUtils.java | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) 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 8b5b49738e..a595bdba7c 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 0e6319f9a5..a6c9499575 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); + } + } }