From b48c337d06aa1f23e10d56641aa2abb85e6fea8e Mon Sep 17 00:00:00 2001 From: charitha Date: Fri, 13 Oct 2017 17:37:08 +0530 Subject: [PATCH] Refactoring the code --- .../android/util/AndroidDeviceUtils.java | 215 +++++++++--------- .../DeviceManagementAdminServiceTests.java | 1 - .../NotificationManagementServiceMock.java | 18 ++ .../mocks/PolicyManagerServiceMock.java | 34 +-- .../mdm/services/android/utils/TestUtils.java | 61 ++++- 5 files changed, 203 insertions(+), 126 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/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 b560711212..ac99f20047 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 @@ -70,7 +70,7 @@ public class AndroidDeviceUtils { private static Log log = LogFactory.getLog(AndroidDeviceUtils.class); - private AndroidDeviceUtils(){ + private AndroidDeviceUtils() { throw new IllegalStateException("Utility class"); } @@ -78,9 +78,9 @@ public class AndroidDeviceUtils { Device device = AndroidAPIUtils.getDeviceManagementService(). getDevice(deviceIdentifier, false); return !(device == null || device.getDeviceIdentifier() == null || - device.getDeviceIdentifier().isEmpty() || - device.getEnrolmentInfo() == null || - EnrolmentInfo.Status.REMOVED.equals(device.getEnrolmentInfo().getStatus())); + device.getDeviceIdentifier().isEmpty() || + device.getEnrolmentInfo() == null || + EnrolmentInfo.Status.REMOVED.equals(device.getEnrolmentInfo().getStatus())); } public static DeviceIdentifier convertToDeviceIdentifierObject(String deviceId) { @@ -167,14 +167,14 @@ public class AndroidDeviceUtils { 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()); + log.debug("Received compliance status from MONITOR operation ID: " + operation.getId()); } AndroidAPIUtils.getPolicyManagerService().checkPolicyCompliance(deviceIdentifier, - getComplianceFeatures(operation.getPayLoad())); + getComplianceFeatures(operation.getPayLoad())); } 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 + "'"); + log.debug("Received applications list from device '" + deviceId + "'"); } updateApplicationList(operation, deviceIdentifier); @@ -182,7 +182,7 @@ public class AndroidDeviceUtils { OperationCodes.DEVICE_INFO.equals(operation.getCode())) { try { - if (log.isDebugEnabled()){ + if (log.isDebugEnabled()) { log.debug("Operation response: " + operation.getOperationResponse()); } Device device = new Gson().fromJson(operation.getOperationResponse(), Device.class); @@ -192,7 +192,6 @@ public class AndroidDeviceUtils { throw new OperationManagementException("Error occurred while updating the device information.", e); } - } else if (!Operation.Status.ERROR.equals(operation.getStatus()) && AndroidConstants.OperationCodes.DEVICE_LOCATION.equals(operation.getCode())) { try { @@ -247,7 +246,9 @@ public class AndroidDeviceUtils { } AndroidAPIUtils.getApplicationManagerService().updateApplicationListInstalledInDevice(deviceIdentifier, applications); } else { - log.error("Operation Response is null."); + if (log.isDebugEnabled()) { + log.debug("Operation Response is null."); + } } } @@ -277,108 +278,109 @@ public class AndroidDeviceUtils { for (Device.Property prop : props) { if (Utils.getDeviceDetailsColumnNames().containsValue(prop.getName())) { - if (prop.getName().equalsIgnoreCase("DEVICE_MODEL")) { - deviceInfo.setDeviceModel(prop.getValue()); - } else if (prop.getName().equalsIgnoreCase("VENDOR")) { - deviceInfo.setVendor(prop.getValue()); - } else if (prop.getName().equalsIgnoreCase("OS_VERSION")) { - deviceInfo.setOsVersion(prop.getValue()); - } else if (prop.getName().equalsIgnoreCase("IMEI")) { - deviceInfo.getDeviceDetailsMap().put("IMEI", prop.getValue()); - } else if (prop.getName().equalsIgnoreCase("IMSI")) { - deviceInfo.getDeviceDetailsMap().put("IMSI", prop.getValue()); - } else if (prop.getName().equalsIgnoreCase("MAC")) { - deviceInfo.getDeviceDetailsMap().put("mac", prop.getValue()); - } else if (prop.getName().equalsIgnoreCase("SERIAL")) { - deviceInfo.getDeviceDetailsMap().put("serial", prop.getValue()); - } else if (prop.getName().equalsIgnoreCase("OS_BUILD_DATE")) { - deviceInfo.setOsBuildDate(prop.getValue()); - } + extractDefinedProperties(deviceInfo, prop); } else { - if (prop.getName().equalsIgnoreCase("CPU_INFO")) { - deviceInfo.getDeviceDetailsMap().put("cpuUser", - getProperty(prop.getValue(), "User")); - deviceInfo.getDeviceDetailsMap().put("cpuSystem", - getProperty(prop.getValue(), "System")); - deviceInfo.getDeviceDetailsMap().put("IOW", - getProperty(prop.getValue(), "IOW")); - deviceInfo.getDeviceDetailsMap().put("IRQ", - getProperty(prop.getValue(), "IRQ")); - } else if (prop.getName().equalsIgnoreCase("RAM_INFO")) { - deviceInfo.setTotalRAMMemory(Double.parseDouble(getProperty(prop.getValue(), "TOTAL_MEMORY"))); - deviceInfo.setAvailableRAMMemory(Double.parseDouble(getProperty(prop.getValue(), "AVAILABLE_MEMORY"))); - - deviceInfo.getDeviceDetailsMap().put("ramThreshold", - getProperty(prop.getValue(), "THRESHOLD")); - deviceInfo.getDeviceDetailsMap().put("ramLowMemory", - getProperty(prop.getValue(), "LOW_MEMORY")); - } else if (prop.getName().equalsIgnoreCase("BATTERY_INFO")) { - deviceInfo.setPluggedIn(Boolean.parseBoolean(getProperty(prop.getValue(), "PLUGGED"))); - - deviceInfo.getDeviceDetailsMap().put("batteryLevel", - getProperty(prop.getValue(), "BATTERY_LEVEL")); - deviceInfo.getDeviceDetailsMap().put("batteryScale", - getProperty(prop.getValue(), "SCALE")); - deviceInfo.getDeviceDetailsMap().put("batteryVoltage", - getProperty(prop.getValue(), "BATTERY_VOLTAGE")); - deviceInfo.getDeviceDetailsMap().put("batteryTemperature", - getProperty(prop.getValue(), "TEMPERATURE")); - deviceInfo.getDeviceDetailsMap().put("batteryCurrentTemperature", - getProperty(prop.getValue(), "CURRENT_AVERAGE")); - deviceInfo.getDeviceDetailsMap().put("batteryTechnology", - getProperty(prop.getValue(), "TECHNOLOGY")); - deviceInfo.getDeviceDetailsMap().put("batteryHealth", - getProperty(prop.getValue(), "HEALTH")); - deviceInfo.getDeviceDetailsMap().put("batteryStatus", - getProperty(prop.getValue(), "STATUS")); - } else if (prop.getName().equalsIgnoreCase("NETWORK_INFO")) { - deviceInfo.setSsid(getProperty(prop.getValue(), "WIFI_SSID")); - deviceInfo.setConnectionType(getProperty(prop.getValue(), "CONNECTION_TYPE")); - - deviceInfo.getDeviceDetailsMap().put("mobileSignalStrength", - getProperty(prop.getValue(), "MOBILE_SIGNAL_STRENGTH")); - deviceInfo.getDeviceDetailsMap().put("wifiSignalStrength", - getProperty(prop.getValue(), "WIFI_SIGNAL_STRENGTH")); - } else if (prop.getName().equalsIgnoreCase("DEVICE_INFO")) { - deviceInfo.setBatteryLevel(Double.parseDouble( - getProperty(prop.getValue(), "BATTERY_LEVEL"))); - deviceInfo.setInternalTotalMemory(Double.parseDouble( - getProperty(prop.getValue(), "INTERNAL_TOTAL_MEMORY"))); - deviceInfo.setInternalAvailableMemory(Double.parseDouble( - getProperty(prop.getValue(), "INTERNAL_AVAILABLE_MEMORY"))); - deviceInfo.setExternalTotalMemory(Double.parseDouble( - getProperty(prop.getValue(), "EXTERNAL_TOTAL_MEMORY"))); - deviceInfo.setExternalAvailableMemory(Double.parseDouble( - getProperty(prop.getValue(), "EXTERNAL_AVAILABLE_MEMORY"))); - - deviceInfo.getDeviceDetailsMap().put("encryptionEnabled", - getProperty(prop.getValue(), "ENCRYPTION_ENABLED")); - deviceInfo.getDeviceDetailsMap().put("passcodeEnabled", - getProperty(prop.getValue(), "PASSCODE_ENABLED")); - deviceInfo.getDeviceDetailsMap().put("operator", - getProperty(prop.getValue(), "OPERATOR")); - deviceInfo.getDeviceDetailsMap().put("PhoneNumber", - getProperty(prop.getValue(), "PHONE_NUMBER")); - } + extractMapProperties(deviceInfo, prop); } } return deviceInfo; } - private static String getProperty(String a, String needed) { + private static void extractMapProperties(DeviceInfo deviceInfo, Device.Property prop) { + if (prop.getName().equalsIgnoreCase("CPU_INFO")) { + deviceInfo.getDeviceDetailsMap().put("cpuUser", getProperty(prop.getValue(), "User")); + deviceInfo.getDeviceDetailsMap().put("cpuSystem", getProperty(prop.getValue(), "System")); + deviceInfo.getDeviceDetailsMap().put("IOW", getProperty(prop.getValue(), "IOW")); + deviceInfo.getDeviceDetailsMap().put("IRQ", getProperty(prop.getValue(), "IRQ")); + } else if (prop.getName().equalsIgnoreCase("RAM_INFO")) { + deviceInfo.setTotalRAMMemory(Double.parseDouble(getProperty(prop.getValue(), "TOTAL_MEMORY"))); + deviceInfo.setAvailableRAMMemory(Double.parseDouble( + getProperty(prop.getValue(), "AVAILABLE_MEMORY"))); + deviceInfo.getDeviceDetailsMap().put("ramThreshold", getProperty(prop.getValue(), "THRESHOLD")); + deviceInfo.getDeviceDetailsMap().put("ramLowMemory", getProperty(prop.getValue(), "LOW_MEMORY")); + } else if (prop.getName().equalsIgnoreCase("BATTERY_INFO")) { + deviceInfo.setPluggedIn(Boolean.parseBoolean(getProperty(prop.getValue(), "PLUGGED"))); + + deviceInfo.getDeviceDetailsMap().put("batteryLevel", getProperty(prop.getValue(), "BATTERY_LEVEL")); + deviceInfo.getDeviceDetailsMap().put("batteryScale", getProperty(prop.getValue(), "SCALE")); + deviceInfo.getDeviceDetailsMap().put("batteryVoltage", + getProperty(prop.getValue(), "BATTERY_VOLTAGE")); + deviceInfo.getDeviceDetailsMap().put("batteryTemperature", + getProperty(prop.getValue(), "TEMPERATURE")); + deviceInfo.getDeviceDetailsMap().put("batteryCurrentTemperature", + getProperty(prop.getValue(), "CURRENT_AVERAGE")); + deviceInfo.getDeviceDetailsMap().put("batteryTechnology", + getProperty(prop.getValue(), "TECHNOLOGY")); + deviceInfo.getDeviceDetailsMap().put("batteryHealth", getProperty(prop.getValue(), "HEALTH")); + deviceInfo.getDeviceDetailsMap().put("batteryStatus", getProperty(prop.getValue(), "STATUS")); + } else if (prop.getName().equalsIgnoreCase("NETWORK_INFO")) { + deviceInfo.setSsid(getProperty(prop.getValue(), "WIFI_SSID")); + deviceInfo.setConnectionType(getProperty(prop.getValue(), "CONNECTION_TYPE")); + + deviceInfo.getDeviceDetailsMap().put("mobileSignalStrength", + getProperty(prop.getValue(), "MOBILE_SIGNAL_STRENGTH")); + deviceInfo.getDeviceDetailsMap().put("wifiSignalStrength", + getProperty(prop.getValue(), "WIFI_SIGNAL_STRENGTH")); + } else if (prop.getName().equalsIgnoreCase("DEVICE_INFO")) { + deviceInfo.setBatteryLevel(Double.parseDouble( + getProperty(prop.getValue(), "BATTERY_LEVEL"))); + deviceInfo.setInternalTotalMemory(Double.parseDouble( + getProperty(prop.getValue(), "INTERNAL_TOTAL_MEMORY"))); + deviceInfo.setInternalAvailableMemory(Double.parseDouble( + getProperty(prop.getValue(), "INTERNAL_AVAILABLE_MEMORY"))); + deviceInfo.setExternalTotalMemory(Double.parseDouble( + getProperty(prop.getValue(), "EXTERNAL_TOTAL_MEMORY"))); + deviceInfo.setExternalAvailableMemory(Double.parseDouble( + getProperty(prop.getValue(), "EXTERNAL_AVAILABLE_MEMORY"))); + + deviceInfo.getDeviceDetailsMap().put("encryptionEnabled", + getProperty(prop.getValue(), "ENCRYPTION_ENABLED")); + deviceInfo.getDeviceDetailsMap().put("passcodeEnabled", + getProperty(prop.getValue(), "PASSCODE_ENABLED")); + deviceInfo.getDeviceDetailsMap().put("operator", + getProperty(prop.getValue(), "OPERATOR")); + deviceInfo.getDeviceDetailsMap().put("PhoneNumber", + getProperty(prop.getValue(), "PHONE_NUMBER")); + } else if (prop.getName().equalsIgnoreCase("IMEI")) { + deviceInfo.getDeviceDetailsMap().put("IMEI", prop.getValue()); + } else if (prop.getName().equalsIgnoreCase("IMSI")) { + deviceInfo.getDeviceDetailsMap().put("IMSI", prop.getValue()); + } else if (prop.getName().equalsIgnoreCase("MAC")) { + deviceInfo.getDeviceDetailsMap().put("mac", prop.getValue()); + } else if (prop.getName().equalsIgnoreCase("SERIAL")) { + deviceInfo.getDeviceDetailsMap().put("serial", prop.getValue()); + } + } - JsonElement jsonElement = new JsonParser().parse(a); + private static void extractDefinedProperties(DeviceInfo deviceInfo, Device.Property prop) { + if (prop.getName().equalsIgnoreCase("DEVICE_MODEL")) { + deviceInfo.setDeviceModel(prop.getValue()); + } else if (prop.getName().equalsIgnoreCase("VENDOR")) { + deviceInfo.setVendor(prop.getValue()); + } else if (prop.getName().equalsIgnoreCase("OS_VERSION")) { + deviceInfo.setOsVersion(prop.getValue()); + } else if (prop.getName().equalsIgnoreCase("OS_BUILD_DATE")) { + deviceInfo.setOsBuildDate(prop.getValue()); + } + } + + private static String getProperty(String properties, String needed) { + // This is not a key value pair. value is the immediate element to its filed name. + // Ex: + // [{"name":"ENCRYPTION_ENABLED","value":"false"},{"name":"PASSCODE_ENABLED","value":"true"}, + // {"name":"BATTERY_LEVEL","value":"100"},{"name":"INTERNAL_TOTAL_MEMORY","value":"0.76"}] + JsonElement jsonElement = new JsonParser().parse(properties); JsonArray jsonArray = jsonElement.getAsJsonArray(); boolean exist = false; for (JsonElement element : jsonArray) { - for (Map.Entry ob : ((JsonObject) element).entrySet()) { - JsonElement val = ob.getValue(); - if (val != null && !val.isJsonNull()) { - if (exist) { - return val.getAsString().replace("%", ""); - } - if (val.getAsString().equalsIgnoreCase(needed)) { - exist = true; + if (element.isJsonObject()) { + JsonObject jsonObject = element.getAsJsonObject(); + if (jsonObject.has("name") + && jsonObject.get("name").getAsString().equalsIgnoreCase(needed)) { + if (jsonObject.has("value")) { + return jsonObject.get("value").getAsString().replace("%", ""); + } else { + return ""; } } } @@ -386,7 +388,8 @@ public class AndroidDeviceUtils { return ""; } - private static List getComplianceFeatures(Object compliancePayload) throws PolicyComplianceException { + private static List getComplianceFeatures(Object compliancePayload) + throws PolicyComplianceException { String compliancePayloadString = new Gson().toJson(compliancePayload); if (compliancePayload == null) { return null; @@ -419,15 +422,15 @@ public class AndroidDeviceUtils { */ public static BadRequestException buildBadRequestException(String description) { ErrorResponse errorResponse = getErrorResponse(AndroidConstants. - ErrorMessages.STATUS_BAD_REQUEST_MESSAGE_DEFAULT,400l, description); + ErrorMessages.STATUS_BAD_REQUEST_MESSAGE_DEFAULT, 400l, description); return new BadRequestException(errorResponse); } /** * Returns generic ErrorResponse. * - * @param message specific error message - * @param code error code + * @param message specific error message + * @param code error code * @param description error description * @return generic Response with error specific details. */ diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/DeviceManagementAdminServiceTests.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/DeviceManagementAdminServiceTests.java index 70934a86a7..c60de18bc9 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/DeviceManagementAdminServiceTests.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/DeviceManagementAdminServiceTests.java @@ -57,7 +57,6 @@ public class DeviceManagementAdminServiceTests { private void mockDeviceManagementService() throws DeviceManagementException, OperationManagementException, InvalidDeviceException { - PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getDeviceManagementService")) .toReturn(new DeviceManagementProviderServiceMock()); } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/NotificationManagementServiceMock.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/NotificationManagementServiceMock.java index 517ef61305..53b2106683 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/NotificationManagementServiceMock.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/NotificationManagementServiceMock.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.wso2.carbon.mdm.services.android.mocks; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/PolicyManagerServiceMock.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/PolicyManagerServiceMock.java index cdf618047c..a71dafebf8 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/PolicyManagerServiceMock.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/PolicyManagerServiceMock.java @@ -1,20 +1,3 @@ -package org.wso2.carbon.mdm.services.android.mocks; - -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.Feature; -import org.wso2.carbon.device.mgt.common.policy.mgt.Policy; -import org.wso2.carbon.device.mgt.common.policy.mgt.Profile; -import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature; -import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature; -import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData; -import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException; -import org.wso2.carbon.policy.mgt.common.FeatureManagementException; -import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint; -import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint; -import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint; -import org.wso2.carbon.policy.mgt.common.PolicyManagementException; -import org.wso2.carbon.policy.mgt.common.PolicyMonitoringTaskException; -import org.wso2.carbon.policy.mgt.core.PolicyManagerService; /* * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * @@ -32,6 +15,23 @@ import org.wso2.carbon.policy.mgt.core.PolicyManagerService; * specific language governing permissions and limitations * under the License. */ +package org.wso2.carbon.mdm.services.android.mocks; + +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.Feature; +import org.wso2.carbon.device.mgt.common.policy.mgt.Policy; +import org.wso2.carbon.device.mgt.common.policy.mgt.Profile; +import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature; +import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature; +import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData; +import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException; +import org.wso2.carbon.policy.mgt.common.FeatureManagementException; +import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint; +import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint; +import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint; +import org.wso2.carbon.policy.mgt.common.PolicyManagementException; +import org.wso2.carbon.policy.mgt.common.PolicyMonitoringTaskException; +import org.wso2.carbon.policy.mgt.core.PolicyManagerService; import org.wso2.carbon.policy.mgt.core.task.TaskScheduleService; import java.util.List; diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/utils/TestUtils.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/utils/TestUtils.java index 811ab24af1..cff3d8ca21 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/utils/TestUtils.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/utils/TestUtils.java @@ -276,7 +276,26 @@ public class TestUtils { operation.setActivityId(getActivity().getActivityId()); operation.setCode(AndroidConstants.OperationCodes.APPLICATION_LIST); operation.setId(1); - operation.setOperationResponse("[{\"name\":\"Widget%20Preview\",\"package\":\"com.android.widgetpreview\",\"version\":\"7.1.1\",\"isSystemApp\":false,\"isActive\":false},{\"name\":\"com.android.gesture.builder\",\"package\":\"com.android.gesture.builder\",\"version\":\"7.1.1\",\"isSystemApp\":false,\"isActive\":false},{\"name\":\"API%20Demos\",\"package\":\"com.example.android.apis\",\"version\":\"7.1.1\",\"isSystemApp\":false,\"isActive\":false},{\"name\":\"WSO2%20Device%20Management%20Agent\",\"package\":\"org.wso2.iot.agent\",\"version\":\"3.1.21\",\"isSystemApp\":false,\"isActive\":true},{\"name\":\"com.android.smoketest.tests\",\"package\":\"com.android.smoketest.tests\",\"version\":\"7.1.1\",\"isSystemApp\":false,\"isActive\":false},{\"name\":\"Sample%20Soft%20Keyboard\",\"package\":\"com.example.android.softkeyboard\",\"version\":\"7.1.1\",\"isSystemApp\":false,\"isActive\":false},{\"name\":\"Example%20Wallpapers\",\"package\":\"com.example.android.livecubes\",\"version\":\"7.1.1\",\"isSystemApp\":false,\"isActive\":false},{\"name\":\"com.android.smoketest\",\"package\":\"com.android.smoketest\",\"version\":\"7.1.1\",\"isSystemApp\":false,\"isActive\":false}]"); + operation.setOperationResponse("[{\"name\":\"Widget%20Preview\",\"package\":\"com.android.widgetpreview\"," + + "\"version\":\"7.1.1\",\"isSystemApp\":false,\"isActive\":false}," + + "{\"name\":\"com.android.gesture.builder\"," + + "\"package\":\"com.android.gesture.builder\",\"version\":\"7.1.1\"," + + "\"isSystemApp\":false,\"isActive\":false},{\"name\":\"API%20Demos\"," + + "\"package\":\"com.example.android.apis\",\"version\":\"7.1.1\"," + + "\"isSystemApp\":false,\"isActive\":false}," + + "{\"name\":\"WSO2%20Device%20Management%20Agent\"," + + "\"package\":\"org.wso2.iot.agent\",\"version\":\"3.1.21\"," + + "\"isSystemApp\":false,\"isActive\":true}," + + "{\"name\":\"com.android.smoketest.tests\"," + + "\"package\":\"com.android.smoketest.tests\",\"version\":\"7.1.1\"," + + "\"isSystemApp\":false,\"isActive\":false}," + + "{\"name\":\"Sample%20Soft%20Keyboard\"," + + "\"package\":\"com.example.android.softkeyboard\",\"version\":\"7.1.1\"," + + "\"isSystemApp\":false,\"isActive\":false},{\"name\":\"Example%20Wallpapers\"," + + "\"package\":\"com.example.android.livecubes\",\"version\":\"7.1.1\"," + + "\"isSystemApp\":false,\"isActive\":false},{\"name\":\"com.android.smoketest\"," + + "\"package\":\"com.android.smoketest\",\"version\":\"7.1.1\"," + + "\"isSystemApp\":false,\"isActive\":false}]"); operation.setStatus(Operation.Status.COMPLETED); operations.add(operation); return operations; @@ -288,7 +307,45 @@ public class TestUtils { operation.setActivityId(getActivity().getActivityId()); operation.setCode(AndroidConstants.OperationCodes.DEVICE_INFO); operation.setId(1); - operation.setOperationResponse("{\"description\":\"generic_x86\",\"deviceIdentifier\":\"1d9612def9d205f9\",\"enrolmentInfo\":null,\"name\":\"generic_x86\",\"properties\":[{\"name\":\"SERIAL\",\"value\":\"unknown\"},{\"name\":\"IMEI\",\"value\":null},{\"name\":\"IMSI\",\"value\":\"310260000000000\"},{\"name\":\"MAC\",\"value\":\"02:00:00:00:00:00\"},{\"name\":\"DEVICE_MODEL\",\"value\":\"Android SDK built for x86\"},{\"name\":\"VENDOR\",\"value\":\"unknown\"},{\"name\":\"OS_VERSION\",\"value\":\"7.1.1\"},{\"name\":\"OS_BUILD_DATE\",\"value\":\"1487782847000\"},{\"name\":\"DEVICE_NAME\",\"value\":\"generic_x86\"},{\"name\":\"LATITUDE\",\"value\":\"6.90988\"},{\"name\":\"LONGITUDE\",\"value\":\"79.85249999999999\"},{\"name\":\"NETWORK_INFO\",\"value\":\"[{\\\"name\\\":\\\"CONNECTION_TYPE\\\",\\\"value\\\":\\\"MOBILE\\\"},{\\\"name\\\":\\\"MOBILE_CONNECTION_TYPE\\\",\\\"value\\\":\\\"LTE\\\"},{\\\"name\\\":\\\"MOBILE_SIGNAL_STRENGTH\\\",\\\"value\\\":\\\"-89\\\"}]\"},{\"name\":\"CPU_INFO\",\"value\":\"[]\"},{\"name\":\"RAM_INFO\",\"value\":\"[{\\\"name\\\":\\\"TOTAL_MEMORY\\\",\\\"value\\\":\\\"1055113216\\\"},{\\\"name\\\":\\\"AVAILABLE_MEMORY\\\",\\\"value\\\":\\\"708997120\\\"},{\\\"name\\\":\\\"THRESHOLD\\\",\\\"value\\\":\\\"150994944\\\"},{\\\"name\\\":\\\"LOW_MEMORY\\\",\\\"value\\\":\\\"false\\\"}]\"},{\"name\":\"BATTERY_INFO\",\"value\":\"[{\\\"name\\\":\\\"BATTERY_LEVEL\\\",\\\"value\\\":\\\"100\\\"},{\\\"name\\\":\\\"SCALE\\\",\\\"value\\\":\\\"100\\\"},{\\\"name\\\":\\\"BATTERY_VOLTAGE\\\",\\\"value\\\":\\\"0\\\"},{\\\"name\\\":\\\"HEALTH\\\",\\\"value\\\":\\\"GOOD_CONDITION\\\"},{\\\"name\\\":\\\"STATUS\\\",\\\"value\\\":\\\"null\\\"},{\\\"name\\\":\\\"PLUGGED\\\",\\\"value\\\":\\\"AC\\\"}]\"},{\"name\":\"DEVICE_INFO\",\"value\":\"[{\\\"name\\\":\\\"ENCRYPTION_ENABLED\\\",\\\"value\\\":\\\"false\\\"},{\\\"name\\\":\\\"PASSCODE_ENABLED\\\",\\\"value\\\":\\\"true\\\"},{\\\"name\\\":\\\"BATTERY_LEVEL\\\",\\\"value\\\":\\\"100\\\"},{\\\"name\\\":\\\"INTERNAL_TOTAL_MEMORY\\\",\\\"value\\\":\\\"0.76\\\"},{\\\"name\\\":\\\"INTERNAL_AVAILABLE_MEMORY\\\",\\\"value\\\":\\\"0.67\\\"},{\\\"name\\\":\\\"EXTERNAL_TOTAL_MEMORY\\\",\\\"value\\\":\\\"0.1\\\"},{\\\"name\\\":\\\"EXTERNAL_AVAILABLE_MEMORY\\\",\\\"value\\\":\\\"0.1\\\"},{\\\"name\\\":\\\"OPERATOR\\\",\\\"value\\\":\\\"Android\\\"},{\\\"name\\\":\\\"PHONE_NUMBER\\\",\\\"value\\\":\\\"15555215554\\\"}]\"}]}"); + operation.setOperationResponse("{\"description\":\"generic_x86\",\"deviceIdentifier\":\"1d9612def9d205f9\"," + + "\"enrolmentInfo\":null,\"name\":\"generic_x86\",\"properties\":[" + + "{\"name\":\"SERIAL\",\"value\":\"unknown\"}," + + "{\"name\":\"IMEI\",\"value\":null}," + + "{\"name\":\"IMSI\",\"value\":\"310260000000000\"}," + + "{\"name\":\"MAC\",\"value\":\"02:00:00:00:00:00\"}," + + "{\"name\":\"DEVICE_MODEL\",\"value\":\"Android SDK built for x86\"}," + + "{\"name\":\"VENDOR\",\"value\":\"unknown\"}," + + "{\"name\":\"OS_VERSION\",\"value\":\"7.1.1\"}," + + "{\"name\":\"OS_BUILD_DATE\",\"value\":\"1487782847000\"}," + + "{\"name\":\"DEVICE_NAME\",\"value\":\"generic_x86\"}," + + "{\"name\":\"LATITUDE\",\"value\":\"6.90988\"}," + + "{\"name\":\"LONGITUDE\",\"value\":\"79.85249999999999\"}," + + "{\"name\":\"NETWORK_INFO\",\"value\":\"[" + + "{\\\"name\\\":\\\"CONNECTION_TYPE\\\",\\\"value\\\":\\\"MOBILE\\\"}," + + "{\\\"name\\\":\\\"MOBILE_CONNECTION_TYPE\\\",\\\"value\\\":\\\"LTE\\\"}," + + "{\\\"name\\\":\\\"MOBILE_SIGNAL_STRENGTH\\\",\\\"value\\\":\\\"-89\\\"}]\"}," + + "{\"name\":\"CPU_INFO\",\"value\":\"[]\"},{\"name\":\"RAM_INFO\",\"value\":\"[" + + "{\\\"name\\\":\\\"TOTAL_MEMORY\\\",\\\"value\\\":\\\"1055113216\\\"}," + + "{\\\"name\\\":\\\"AVAILABLE_MEMORY\\\",\\\"value\\\":\\\"708997120\\\"}," + + "{\\\"name\\\":\\\"THRESHOLD\\\",\\\"value\\\":\\\"150994944\\\"}," + + "{\\\"name\\\":\\\"LOW_MEMORY\\\",\\\"value\\\":\\\"false\\\"}]\"}," + + "{\"name\":\"BATTERY_INFO\",\"value\":\"[" + + "{\\\"name\\\":\\\"BATTERY_LEVEL\\\",\\\"value\\\":\\\"100\\\"}," + + "{\\\"name\\\":\\\"SCALE\\\",\\\"value\\\":\\\"100\\\"}," + + "{\\\"BATTERY_VOLTAGE\\\":\\\"0\\\"}," + + "{\\\"name\\\":\\\"HEALTH\\\",\\\"value\\\":\\\"GOOD_CONDITION\\\"}," + + "{\\\"name\\\":\\\"STATUS\\\"}," + + "{\\\"name\\\":\\\"PLUGGED\\\",\\\"value\\\":\\\"AC\\\"}]\"}," + + "{\"name\":\"DEVICE_INFO\",\"value\":\"[" + + "{\\\"name\\\":\\\"ENCRYPTION_ENABLED\\\",\\\"value\\\":\\\"false\\\"}," + + "{\\\"name\\\":\\\"PASSCODE_ENABLED\\\",\\\"value\\\":\\\"true\\\"}," + + "{\\\"name\\\":\\\"BATTERY_LEVEL\\\",\\\"value\\\":\\\"100\\\"}," + + "{\\\"name\\\":\\\"INTERNAL_TOTAL_MEMORY\\\",\\\"value\\\":\\\"0.76\\\"}," + + "{\\\"name\\\":\\\"INTERNAL_AVAILABLE_MEMORY\\\",\\\"value\\\":\\\"0.67\\\"}," + + "{\\\"name\\\":\\\"EXTERNAL_TOTAL_MEMORY\\\",\\\"value\\\":\\\"0.1\\\"}," + + "{\\\"name\\\":\\\"EXTERNAL_AVAILABLE_MEMORY\\\",\\\"value\\\":\\\"0.1\\\"}," + + "{\\\"name\\\":\\\"OPERATOR\\\",\\\"value\\\":\\\"Android\\\"}," + + "{\\\"name\\\":\\\"PHONE_NUMBER\\\",\\\"value\\\":\\\"15555215554\\\"}]\"}]}"); operation.setStatus(Operation.Status.COMPLETED); operations.add(operation); return operations;