revert-70aa11f8
kamidu 8 years ago
commit 959e3a63af

@ -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<String> 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<String> getPlatforms() {
return platforms;
}
public void setPlatforms(List<String> platforms) {
this.platforms = platforms;
}
}

@ -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<String> deviceTypes = new ArrayList<>();
List<String> 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));
}
}

@ -42,6 +42,11 @@
<MaxRetries>5</MaxRetries>
<MinRetriesToMarkUnreachable>8</MinRetriesToMarkUnreachable>
<MinRetriesToMarkInactive>20</MinRetriesToMarkInactive>
<Platforms>
<Platform>android</Platform>
<Platform>ios</Platform>
<Platform>windows</Platform>
</Platforms>
</PolicyConfiguration>
<TaskConfiguration>
<Enable>true</Enable>

Loading…
Cancel
Save