adding DeviceInfo operation handler

revert-dabc3590
Hasunie 8 years ago
parent d82670fa94
commit 67e75ee38a

@ -226,13 +226,17 @@ public class WindowsAPIUtils {
}
}
private static void updateDeviceInfo(DeviceIdentifier deviceId, DeviceInfo deviceInfo)
/**
* This method is used to update Device Information.
* @param deviceId DeviceID to need to update.
* @param deviceInfo Device Info to be update/
* @throws DeviceDetailsMgtException Error occurs while updating Device Info.
*/
public static void updateDeviceInfo(DeviceIdentifier deviceId, DeviceInfo deviceInfo)
throws DeviceDetailsMgtException {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
DeviceInformationManager informationManager =
(DeviceInformationManager) ctx.getOSGiService(DeviceInformationManager.class, null);
informationManager.addDeviceInfo(deviceId, deviceInfo);
}
}

@ -24,6 +24,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService;
@ -165,7 +166,7 @@ public class OperationHandler {
}
}
/***
/**
* Update status of the ring operation.
*
* @param status Ring status of the device.
@ -193,7 +194,7 @@ public class OperationHandler {
}
}
/***
/**
* Update the status of the DataWipe operation.
*
* @param status Status of the data wipe.
@ -222,6 +223,23 @@ public class OperationHandler {
}
}
public void updateDeviceInfoStatus(DeviceIdentifier deviceIdentifier) throws OperationManagementException {
List<? extends Operation> pendingDeviceInfoOperations;
try {
pendingDeviceInfoOperations = WindowsAPIUtils.getPendingOperations(deviceIdentifier);
} catch (DeviceManagementException e) {
throw new OperationManagementException("Error occurred in getting pending operation.");
}
for (Operation operation : pendingDeviceInfoOperations) {
if (PluginConstants.OperationCodes.DEVICE_INFO.equals(operation.getCode())) {
operation.setStatus(Operation.Status.COMPLETED);
updateStatus(deviceIdentifier.getId(), pendingDeviceInfoOperations);
}
}
}
/**
* Get pending operations.
*
@ -231,13 +249,20 @@ public class OperationHandler {
*/
public List<? extends Operation> getPendingOperations(SyncmlDocument syncmlDocument)
throws OperationManagementException, WindowsOperationException {
SyncmlHeader syncmlHeader = syncmlDocument.getHeader();
SyncmlBody syncmlBody = syncmlDocument.getBody();
List<? extends Operation> pendingOperations;
DeviceIdentifier deviceIdentifier = convertToDeviceIdentifierObject(
syncmlDocument.getHeader().getSource().getLocURI());
DeviceIdentifier deviceIdentifier = convertToDeviceIdentifierObject(syncmlHeader.getSource().getLocURI());
int sessionId = syncmlHeader.getSessionId();
int msgId = syncmlHeader.getMsgID();
if (!(PluginConstants.SyncML.SYNCML_FIRST_MESSAGE_ID == msgId &&
PluginConstants.SyncML.SYNCML_FIRST_SESSION_ID == sessionId)) {
if ((syncmlBody.getResults() != null)) {
updateDeviceInfo(syncmlDocument);
}
}
UpdateUriOperations(syncmlDocument);
generateComplianceFeatureStatus(syncmlDocument);
pendingOperations = WindowsAPIUtils.getDeviceManagementService().getPendingOperations(deviceIdentifier);
return pendingOperations;
}
@ -486,4 +511,61 @@ public class OperationHandler {
}
}
public void updateDeviceInfo(SyncmlDocument syncmlDocument) throws WindowsOperationException {
String softwareVersion;
String imsi;
String imei;
String model;
String vendor;
String totalRAM;
String deviceID = null;
String totalStorage;
List<ItemTag> deviceInformations = syncmlDocument.getBody().getResults().getItem();
DeviceInfo deviceInfo = new DeviceInfo();
for (ItemTag item : deviceInformations) {
String source = item.getSource().getLocURI();
if (OperationCode.Info.SOFTWARE_VERSION.getCode().equals(source)) {
softwareVersion = item.getData();
deviceInfo.setOsVersion(softwareVersion);
}
if (OperationCode.Info.IMSI.getCode().equals(source)) {
imsi = item.getData();
deviceInfo.setIMSI(imsi);
}
if (OperationCode.Info.IMEI.getCode().equals(source)) {
imei = item.getData();
deviceInfo.setIMEI(imei);
}
if (OperationCode.Info.DEVICE_MODEL.getCode().equals(source)) {
model = item.getData();
deviceInfo.setDeviceModel(model);
}
if (OperationCode.Info.VENDOR.getCode().equals(source)) {
vendor = item.getData();
deviceInfo.setVendor(vendor);
}
if (OperationCode.Info.TOTAL_RAM.getCode().equals(source)) {
totalRAM = item.getData();
deviceInfo.setAvailableRAMMemory(Double.parseDouble(totalRAM));
}
if (OperationCode.Info.TOTAL_STORAGE.getCode().equals(source)) {
totalStorage = item.getData();
deviceInfo.setInternalAvailableMemory(Double.parseDouble(totalStorage));
}
if (OperationCode.Info.DEV_ID.getCode().equals(source)) {
deviceID = item.getData();
}
}
DeviceIdentifier deviceIdentifier = convertToDeviceIdentifierObject(deviceID);
try {
WindowsAPIUtils.updateDeviceInfo(deviceIdentifier, deviceInfo);
updateDeviceInfoStatus(deviceIdentifier);
} catch (org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException e) {
throw new WindowsOperationException("Error occurred while adding Device info.");
} catch (OperationManagementException e) {
throw new WindowsOperationException("Error occurred while updating Device info operation status.");
}
}
}

@ -247,9 +247,9 @@ public class OperationReply {
switch (type) {
case POLICY:
if (this.syncmlDocument.getBody().getAlert() != null) {
if ((Constants.INITIAL_ALERT_DATA.equals(this.syncmlDocument.getBody()
.getAlert().getData())) ||
Constants.INITIAL_WIN10_ALERT_DATA.equals(this.syncmlDocument.getBody()
if ((Constants.INITIAL_ALERT_DATA.equals(this.syncmlDocument.getBody().getAlert()
.getData())) || Constants.INITIAL_WIN10_ALERT_DATA.
equals(this.syncmlDocument.getBody()
.getAlert().getData())) {
SequenceTag policySequence = new SequenceTag();
policySequence = buildSequence(operation, policySequence);
@ -322,13 +322,19 @@ public class OperationReply {
}
}
if (PluginConstants.OperationCodes.DEVICE_INFO.equals(operation.getCode())) {
if (this.syncmlDocument.getBody().getAlert() != null) {
if ((Constants.INITIAL_ALERT_DATA.equals(this.syncmlDocument.getBody().getAlert()
.getData())) || Constants.INITIAL_WIN10_ALERT_DATA.
equals(this.syncmlDocument.getBody()
.getAlert().getData())) {
HeartBeatDeviceInfo heartBeatDeviceInfo = new HeartBeatDeviceInfo();
deviceInfoOperations = heartBeatDeviceInfo.getDeviceInfo();
for (int x = 0; x > deviceInfoOperations.size(); x++) {
ItemTag deviceInfo = appendGetInfo(operation);
for (Operation infoOperation : deviceInfoOperations) {
ItemTag deviceInfo = appendGetInfo(infoOperation);
getElements.add(deviceInfo);
}
}
}
break;
}
}
@ -350,6 +356,7 @@ public class OperationReply {
syncmlBody.setAtomicTag(atomicTagElement);
syncmlBody.setReplace(replaceElement);
}
}
private ItemTag appendExecInfo(Operation operation) {
ItemTag item = new ItemTag();

Loading…
Cancel
Save