From ade78959011ca628324fa351de2fb31e8602935a Mon Sep 17 00:00:00 2001 From: mharindu Date: Mon, 21 Sep 2015 16:26:10 +0530 Subject: [PATCH 1/2] Added data type check in android policy compliance --- .../impl/android/AndroidPolicyMonitoringService.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidPolicyMonitoringService.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidPolicyMonitoringService.java index 3c58c0c6e2..0300dea48c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidPolicyMonitoringService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidPolicyMonitoringService.java @@ -59,7 +59,12 @@ public class AndroidPolicyMonitoringService implements PolicyMonitoringService { List complianceFeatures = new ArrayList(); // Parsing json string to get compliance features. - JsonElement jsonElement = new JsonParser().parse((String) compliancePayload); + JsonElement jsonElement; + if (compliancePayload instanceof String) { + jsonElement = new JsonParser().parse((String) compliancePayload); + } else { + throw new PolicyComplianceException("Invalid policy compliance payload"); + } JsonArray jsonArray = jsonElement.getAsJsonArray(); Gson gson = new Gson(); ComplianceFeature complianceFeature; From 571b4deb4e32b37703b7d40f3940887bc02709a3 Mon Sep 17 00:00:00 2001 From: mharindu Date: Mon, 21 Sep 2015 16:37:14 +0530 Subject: [PATCH 2/2] Refactored android policy compliance --- .../mobile/impl/android/AndroidPolicyMonitoringService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidPolicyMonitoringService.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidPolicyMonitoringService.java index 0300dea48c..49ff0ab17d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidPolicyMonitoringService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidPolicyMonitoringService.java @@ -69,8 +69,8 @@ public class AndroidPolicyMonitoringService implements PolicyMonitoringService { Gson gson = new Gson(); ComplianceFeature complianceFeature; - for (int i = 0; i < jsonArray.size(); i++) { - complianceFeature = gson.fromJson(jsonArray.get(i), ComplianceFeature.class); + for (JsonElement element : jsonArray) { + complianceFeature = gson.fromJson(element, ComplianceFeature.class); complianceFeatures.add(complianceFeature); }