From c1184167df7facd5d878cf45392073016921b6d3 Mon Sep 17 00:00:00 2001 From: inoshperera Date: Thu, 8 Aug 2019 14:54:47 +0530 Subject: [PATCH] Fix https://gitlab.com/entgra/product-iots/issues/125 --- .../services/android/util/AndroidDeviceUtils.java | 14 ++++++++++++++ 1 file changed, 14 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/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 12ac7ef614..50c0c00f03 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 @@ -238,6 +238,20 @@ public class AndroidDeviceUtils { } } AndroidAPIUtils.getDeviceManagementService().updateOperation(deviceIdentifier, operation); + // This has to be bellow other if blocks, since updateOperation would fail if we execute against a disenrolled + // device. + if (!Operation.Status.ERROR.equals(operation.getStatus()) && AndroidConstants. + OperationCodes.WIPE_DATA.equals(operation.getCode())) { + if (log.isDebugEnabled()) { + log.debug("Received wipe data from device '" + deviceId + "'"); + } + try { + AndroidAPIUtils.getDeviceManagementService().disenrollDevice(deviceIdentifier); + } catch (DeviceManagementException e) { + throw new OperationManagementException("Error occurred while unenrolling the device.", e); + } + + } } public static List getPendingOperations