From ef281e1524fd1772a977ae9df16f97600b402387 Mon Sep 17 00:00:00 2001
From: Kasun Delgolla <kasun.mck@gmail.com>
Date: Wed, 15 Jun 2016 13:51:08 -0700
Subject: [PATCH] Fixing operation response ERROR state exception

---
 .../mdm/services/android/util/AndroidAPIUtils.java   | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

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/AndroidAPIUtils.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/AndroidAPIUtils.java
index 3635bae73..6c12740e3 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/AndroidAPIUtils.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/AndroidAPIUtils.java
@@ -262,18 +262,21 @@ public class AndroidAPIUtils {
         deviceIdentifier.setId(deviceId);
         deviceIdentifier.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
 
-        if (AndroidConstants.OperationCodes.MONITOR.equals(operation.getCode())) {
+        if (!Operation.Status.ERROR.equals(operation.getStatus()) &&
+            AndroidConstants.OperationCodes.MONITOR.equals(operation.getCode())) {
             if (log.isDebugEnabled()) {
                 log.info("Received compliance status from MONITOR operation ID: " + operation.getId());
             }
             getPolicyManagerService().checkPolicyCompliance(deviceIdentifier, operation.getPayLoad());
-        } else if (AndroidConstants.OperationCodes.APPLICATION_LIST.equals(operation.getCode())) {
+        } else if (!Operation.Status.ERROR.equals(operation.getStatus()) && AndroidConstants.
+                OperationCodes.APPLICATION_LIST.equals(operation.getCode())) {
             if (log.isDebugEnabled()) {
                 log.info("Received applications list from device '" + deviceId + "'");
             }
             updateApplicationList(operation, deviceIdentifier);
 
-        } else if (AndroidConstants.OperationCodes.DEVICE_INFO.equals(operation.getCode())) {
+        } else if (!Operation.Status.ERROR.equals(operation.getStatus()) && AndroidConstants.
+                OperationCodes.DEVICE_INFO.equals(operation.getCode())) {
 
             try {
                 Device device = new Gson().fromJson(operation.getOperationResponse(), Device.class);
@@ -284,7 +287,8 @@ public class AndroidAPIUtils {
             }
 
 
-        } else if (AndroidConstants.OperationCodes.DEVICE_LOCATION.equals(operation.getCode())) {
+        } else if (!Operation.Status.ERROR.equals(operation.getStatus()) &&
+                   AndroidConstants.OperationCodes.DEVICE_LOCATION.equals(operation.getCode())) {
             try {
                 DeviceLocation location = new Gson().fromJson(operation.getOperationResponse(), DeviceLocation.class);
                 // reason for checking "location.getLatitude() != null" because when device fails to provide