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/bean/Notification.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/Notification.java index e7cdb5788..7cc4d4627 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/Notification.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/Notification.java @@ -30,14 +30,25 @@ import java.io.Serializable; description = "Details related to notifications passed to device.") public class Notification extends AndroidOperation implements Serializable { - @ApiModelProperty(name = "message", value = "The message to be sent to the device.", required = true) - private String message; + @ApiModelProperty(name = "messageText", value = "The message text to be sent to the device.", required = true) + private String messageText; - public String getMessage() { - return message; + @ApiModelProperty(name = "messageTitle", value = "The message title to be sent to the device.", required = true) + private String messageTitle; + + public String getMessageText() { + return messageText; + } + + public void setMessageText(String messageText) { + this.messageText = messageText; + } + + public String getMessageTitle() { + return messageTitle; } - public void setMessage(String message) { - this.message = message; + public void setMessageTitle(String messageTitle) { + this.messageTitle = messageTitle; } } 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/bean/UpgradeFirmware.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/UpgradeFirmware.java index ae1dad869..1b2152325 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/UpgradeFirmware.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/UpgradeFirmware.java @@ -29,15 +29,31 @@ import java.io.Serializable; @ApiModel(value = "UpgradeFirmware", description = "This class carries all information related to UpgradeFirmware.") public class UpgradeFirmware extends AndroidOperation implements Serializable { + @ApiModelProperty(name = "schedule", value = "Schedule of the UpgradeFirmware.", required = true) private String schedule; + @ApiModelProperty(name = "server", value = "Firmware package server.") + private String server; + + @SuppressWarnings("unused") public String getSchedule() { return schedule; } + @SuppressWarnings("unused") public void setSchedule(String schedule) { this.schedule = schedule; } + @SuppressWarnings("unused") + public String getServer() { + return server; + } + + @SuppressWarnings("unused") + public void setServer(String server) { + this.server = server; + } + } 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/services/impl/DeviceManagementAdminServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementAdminServiceImpl.java index 82717aba2..bd09d30cc 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementAdminServiceImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementAdminServiceImpl.java @@ -543,8 +543,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe operation.setCode(AndroidConstants.OperationCodes.UPGRADE_FIRMWARE); operation.setType(Operation.Type.PROFILE); operation.setPayLoad(upgradeFirmware.toJSON()); - return AndroidAPIUtils.getOperationResponse(upgradeFirmwareBeanWrapper.getDeviceIDs(), - operation); + return AndroidAPIUtils.getOperationResponse(upgradeFirmwareBeanWrapper.getDeviceIDs(), operation); } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); 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/services/impl/DeviceManagementServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementServiceImpl.java index 746e61d77..f8c0980d7 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementServiceImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementServiceImpl.java @@ -74,8 +74,6 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { } } - - @PUT @Path("/{id}/pending-operations") @Override @@ -85,14 +83,14 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { if (id == null || id.isEmpty()) { String msg = "Device identifier is null or empty, hence returning device not found"; log.error(msg); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); try { if (!AndroidDeviceUtils.isValidDeviceIdentifier(deviceIdentifier)) { String msg = "Device not found for identifier '" + id + "'"; log.error(msg); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } if (log.isDebugEnabled()) { log.debug("Invoking Android pending operations:" + id); @@ -133,7 +131,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { } catch (OperationManagementException e) { String msg = "Issue in retrieving operation management service instance"; log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); } return Response.status(Response.Status.CREATED).entity(pendingOperations).build(); } 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/AndroidAPIUtils.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/AndroidAPIUtils.java index 98ab67adc..3635bae73 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/AndroidAPIUtils.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/AndroidAPIUtils.java @@ -36,6 +36,7 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; +import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo; import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation; import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService; import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; @@ -277,8 +278,7 @@ public class AndroidAPIUtils { try { Device device = new Gson().fromJson(operation.getOperationResponse(), Device.class); org.wso2.carbon.device.mgt.common.device.details.DeviceInfo deviceInfo = convertDeviceToInfo(device); - deviceInfo.setDeviceIdentifier(deviceIdentifier); - updateDeviceInfo(deviceInfo); + updateDeviceInfo(deviceIdentifier, deviceInfo); } catch (DeviceDetailsMgtException e) { throw new OperationManagementException("Error occurred while updating the device information.", e); } @@ -312,26 +312,31 @@ public class AndroidAPIUtils { private static void updateApplicationList(Operation operation, DeviceIdentifier deviceIdentifier) throws ApplicationManagementException { // Parsing json string to get applications list. - JsonElement jsonElement = new JsonParser().parse(operation.getOperationResponse()); - JsonArray jsonArray = jsonElement.getAsJsonArray(); - Application app; - List applications = new ArrayList(jsonArray.size()); - for (JsonElement element : jsonArray) { - app = new Application(); - app.setName(element.getAsJsonObject(). - get(AndroidConstants.ApplicationProperties.NAME).getAsString()); - app.setApplicationIdentifier(element.getAsJsonObject(). - get(AndroidConstants.ApplicationProperties.IDENTIFIER).getAsString()); - app.setPlatform(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - if (element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.USS) != null) { - app.setMemoryUsage(element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.USS).getAsInt()); - } - if (element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.VERSION) != null) { - app.setVersion(element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.VERSION).getAsString()); + if (operation.getOperationResponse() != null) { + JsonElement jsonElement = new JsonParser().parse(operation.getOperationResponse()); + JsonArray jsonArray = jsonElement.getAsJsonArray(); + Application app; + List applications = new ArrayList(jsonArray.size()); + for (JsonElement element : jsonArray) { + app = new Application(); + app.setName(element.getAsJsonObject(). + get(AndroidConstants.ApplicationProperties.NAME).getAsString()); + app.setApplicationIdentifier(element.getAsJsonObject(). + get(AndroidConstants.ApplicationProperties.IDENTIFIER).getAsString()); + app.setPlatform(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + if (element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.USS) != null) { + app.setMemoryUsage(element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.USS).getAsInt()); + } + if (element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.VERSION) != null) { + app.setVersion(element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.VERSION).getAsString()); + } + applications.add(app); } - applications.add(app); + getApplicationManagerService().updateApplicationListInstalledInDevice(deviceIdentifier, applications); + } else { + log.error("Operation Response is null."); } - getApplicationManagerService().updateApplicationListInstalledInDevice(deviceIdentifier, applications); + } @@ -344,14 +349,14 @@ public class AndroidAPIUtils { } - private static void updateDeviceInfo(org.wso2.carbon.device.mgt.common.device.details.DeviceInfo deviceInfo) + private static void updateDeviceInfo(DeviceIdentifier deviceId, DeviceInfo deviceInfo) throws DeviceDetailsMgtException { PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); DeviceInformationManager informationManager = (DeviceInformationManager) ctx.getOSGiService(DeviceInformationManager.class, null); - informationManager.addDeviceInfo(deviceInfo); + informationManager.addDeviceInfo(deviceId, deviceInfo); } 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/AndroidConstants.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/AndroidConstants.java index beb8c010b..7aad2f7b1 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/AndroidConstants.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/AndroidConstants.java @@ -51,7 +51,7 @@ public final class AndroidConstants { public static final String DEVICE_PROPERTIES_KEY = "properties"; public static final String DEVICE_FEATURES_KEY = "features"; public static final String DEVICE_DATA = "data"; - public static final String DEVICE_ID_NOT_FOUND = "Device Id not found for device found at %s"; + public static final String DEVICE_ID_NOT_FOUND = "Device not found for device id: %s"; public static final String DEVICE_ID_SERVICE_NOT_FOUND = "Issue in retrieving device management service instance for device found at %s"; } 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 f2ed96cdd..9c4c660a7 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 @@ -55,8 +55,8 @@ public class AndroidDeviceUtils { if (isValidDeviceIdentifier(deviceIdentifier)) { validDeviceIDList.add(deviceIdentifier); } else { - errorDeviceIdList.add(String.format(AndroidConstants.DeviceConstants.DEVICE_ID_NOT_FOUND, - deviceIDCounter)); + errorDeviceIdList.add(String.format(AndroidConstants.DeviceConstants. + DEVICE_ID_NOT_FOUND, deviceID)); } } catch (DeviceManagementException e) { errorDeviceIdList.add(String.format(AndroidConstants.DeviceConstants.DEVICE_ID_SERVICE_NOT_FOUND,