diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/status/task/impl/DeviceStatusMonitoringTask.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/status/task/impl/DeviceStatusMonitoringTask.java index f2deae4810c..71cc06a6d12 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/status/task/impl/DeviceStatusMonitoringTask.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/status/task/impl/DeviceStatusMonitoringTask.java @@ -25,13 +25,16 @@ import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceStatusTaskPluginConfig; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException; import org.wso2.carbon.device.mgt.core.cache.impl.DeviceCacheManagerImpl; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; +import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationEnrolmentMapping; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.status.task.DeviceStatusTaskException; import org.wso2.carbon.ntask.core.Task; @@ -98,6 +101,19 @@ public class DeviceStatusMonitoringTask implements Task { enrolmentInfo.setId(mapping.getEnrolmentId()); enrolmentInfo.setStatus(newStatus); } else { + DeviceManagementProviderService dmps = DeviceManagementDataHolder.getInstance() + .getDeviceManagementProvider(); + try { + Device updatedDevice = dmps + .getDevice(device.getDeviceIdentifier(), device.getDeviceInfo().getUpdatedTime(), true); + if (updatedDevice != null) { + device = updatedDevice; + } + } catch (DeviceManagementException e) { + log.error( + "Error occurred while getting the updated device information which has device identifier: " + + device.getDeviceIdentifier()); + } enrolmentInfo = device.getEnrolmentInfo(); enrolmentInfo.setStatus(newStatus); device.setEnrolmentInfo(enrolmentInfo);