diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/policy/PolicyConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/policy/PolicyConfiguration.java index 2f419755c44..73d3517d837 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/policy/PolicyConfiguration.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/policy/PolicyConfiguration.java @@ -19,7 +19,9 @@ package org.wso2.carbon.device.mgt.core.config.policy; import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; +import java.util.List; @XmlRootElement(name = "PolicyConfiguration") public class PolicyConfiguration { @@ -30,6 +32,7 @@ public class PolicyConfiguration { private int maxRetries; private int minRetriesToMarkUnreachable; private int minRetriesToMarkInactive; + private List platforms; @XmlElement(name = "MonitoringClass", required = true) public String getMonitoringClass() { @@ -85,4 +88,14 @@ public class PolicyConfiguration { this.monitoringFrequency = monitoringFrequency; } + @XmlElementWrapper(name = "Platforms", required = true) + @XmlElement(name = "Platform", required = true) + public List getPlatforms() { + return platforms; + } + + public void setPlatforms(List platforms) { + this.platforms = platforms; + } + } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/MonitoringTask.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/MonitoringTask.java index 6e3f8408bd6..17b314865ec 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/MonitoringTask.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/MonitoringTask.java @@ -23,6 +23,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; +import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; +import org.wso2.carbon.device.mgt.core.config.policy.PolicyConfiguration; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.ntask.core.Task; import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException; @@ -59,8 +61,14 @@ public class MonitoringTask implements Task { MonitoringManager monitoringManager = PolicyManagementDataHolder.getInstance().getMonitoringManager(); List deviceTypes = new ArrayList<>(); + List configDeviceTypes = new ArrayList<>(); try { deviceTypes = monitoringManager.getDeviceTypes(); + for (String deviceType : deviceTypes) { + if (isPlatformExist(deviceType)) { + configDeviceTypes.add(deviceType); + } + } } catch (PolicyComplianceException e) { log.error("Error occurred while getting the device types."); } @@ -68,7 +76,7 @@ public class MonitoringTask implements Task { try { DeviceManagementProviderService deviceManagementProviderService = PolicyManagementDataHolder.getInstance().getDeviceManagementService(); - for (String deviceType : deviceTypes) { + for (String deviceType : configDeviceTypes) { if (log.isDebugEnabled()) { log.debug("Running task for device type : " + deviceType); } @@ -82,6 +90,7 @@ public class MonitoringTask implements Task { deviceType); } for (Device device : devices) { + EnrolmentInfo.Status status = device.getEnrolmentInfo().getStatus(); if (status.equals(EnrolmentInfo.Status.BLOCKED) || status.equals(EnrolmentInfo.Status.REMOVED) || @@ -116,4 +125,18 @@ public class MonitoringTask implements Task { } } + + /** + * Check whether Device platform (ex: android) is exist in the cdm-config.xml file before adding a + * Monitoring operation to a specific device type. + * + * @param deviceType available device types. + * @return return platform is exist(true) or not (false). + */ + + private boolean isPlatformExist(String deviceType) { + PolicyConfiguration policyConfiguration = + DeviceConfigurationManager.getInstance().getDeviceManagementConfig().getPolicyConfiguration(); + return (policyConfiguration.getPlatforms().contains(deviceType)); + } } diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml index fdd4a427103..6fe961cc36b 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml @@ -42,6 +42,11 @@ 5 8 20 + + android + ios + windows + true