From 556886daec3eddb082b1a362c6f0a4dc9e30fd3f Mon Sep 17 00:00:00 2001 From: Muhammad Rashad Date: Mon, 2 Aug 2021 05:09:51 +0000 Subject: [PATCH] Block Uninstall Policy Feature --- .../common/services/SubscriptionManager.java | 24 +++++----- .../core/impl/SubscriptionManagerImpl.java | 25 +++++----- .../task/ScheduledAppSubscriptionTask.java | 9 +++- .../ScheduledAppSubscriptionTaskManager.java | 8 +++- .../application/mgt/core/util/Constants.java | 1 + .../services/SubscriptionManagementAPI.java | 14 +++++- .../impl/SubscriptionManagementAPIImpl.java | 48 ++++++++++++------- .../impl/DeviceManagementServiceImpl.java | 3 +- .../device/mgt/common/MDMAppConstants.java | 1 + .../app/mgt/android/AppStoreApplication.java | 9 ++++ .../mgt/android/EnterpriseApplication.java | 9 ++++ .../app/mgt/android/WebApplication.java | 9 ++++ .../core/util/MDMAndroidOperationUtil.java | 4 ++ 13 files changed, 116 insertions(+), 48 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/SubscriptionManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/SubscriptionManager.java index 600da94b4f..bc2eaabc47 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/SubscriptionManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/SubscriptionManager.java @@ -24,8 +24,10 @@ import org.wso2.carbon.device.application.mgt.common.exception.SubscriptionManag import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; +import org.wso2.carbon.device.mgt.common.app.mgt.App; import java.util.List; +import java.util.Properties; /** * This interface manages all the operations related with ApplicationDTO Subscription. @@ -33,22 +35,22 @@ import java.util.List; public interface SubscriptionManager { /** * Performs bulk subscription operation for a given application and a subscriber list. - * - * @param applicationUUID UUID of the application to subscribe/unsubscribe + * @param applicationUUID UUID of the application to subscribe/unsubscribe * @param params list of subscribers. This list can be of either - * {@link org.wso2.carbon.device.mgt.common.DeviceIdentifier} if {@param subType} is equal + * {@link DeviceIdentifier} if {@param subType} is equal * to DEVICE or * {@link String} if {@param subType} is USER, ROLE or GROUP * @param subType subscription type. E.g. DEVICE, USER, ROLE, GROUP {@see { - * @param action subscription action. E.g. INSTALL/UNINSTALL {@see { - * @param generic type of the method. - * @return {@link ApplicationInstallResponse} - * @throws ApplicationManagementException if error occurs when subscribing to the given application - * @link org.wso2.carbon.device.application.mgt.common.SubscriptionType}} - * @link org.wso2.carbon.device.application.mgt.common.SubAction}} + * @param action subscription action. E.g. INSTALL/UNINSTALL {@see { + * @param generic type of the method. + * @return {@link ApplicationInstallResponse} + * @throws ApplicationManagementException if error occurs when subscribing to the given application + * @link org.wso2.carbon.device.application.mgt.common.SubscriptionType}} + * @link org.wso2.carbon.device.application.mgt.common.SubAction}} + * @param properties */ ApplicationInstallResponse performBulkAppOperation(String applicationUUID, List params, String subType, - String action) throws ApplicationManagementException; + String action, Properties properties) throws ApplicationManagementException; /** * Create an entry related to the scheduled task in the database. @@ -121,7 +123,7 @@ public interface SubscriptionManager { * @throws ApplicationManagementException if error occurred while installing given applications into the given * device */ - void installAppsForDevice(DeviceIdentifier deviceIdentifier, List releaseUUID) + void installAppsForDevice(DeviceIdentifier deviceIdentifier, List apps) throws ApplicationManagementException; /*** diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java index 8219dbb4e7..2de1094c1f 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java @@ -121,7 +121,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { @Override public ApplicationInstallResponse performBulkAppOperation(String applicationUUID, List params, - String subType, String action) throws ApplicationManagementException { + String subType, String action, Properties properties) throws ApplicationManagementException { if (log.isDebugEnabled()) { log.debug("Install application release which has UUID " + applicationUUID + " to " + params.size() + " users."); @@ -134,7 +134,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { params); ApplicationInstallResponse applicationInstallResponse = performActionOnDevices( applicationSubscriptionInfo.getAppSupportingDeviceTypeName(), applicationSubscriptionInfo.getDevices(), - applicationDTO, subType, applicationSubscriptionInfo.getSubscribers(), action); + applicationDTO, subType, applicationSubscriptionInfo.getSubscribers(), action, properties); applicationInstallResponse.setErrorDeviceIdentifiers(applicationSubscriptionInfo.getErrorDeviceIdentifiers()); return applicationInstallResponse; @@ -347,7 +347,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } @Override - public void installAppsForDevice(DeviceIdentifier deviceIdentifier, List releaseUUIDs) + public void installAppsForDevice(DeviceIdentifier deviceIdentifier, List apps) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); @@ -370,7 +370,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager { List appInstallingDevices = new ArrayList<>(); - for (String releaseUUID : releaseUUIDs) { + for (App app : apps) { + String releaseUUID = app.getId(); try { ConnectionManagerUtil.openDBConnection(); ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(releaseUUID, tenantId); @@ -409,7 +410,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { if (!appInstallingDevices.isEmpty()) { performBulkAppOperation(releaseUUID, appInstallingDevices, SubscriptionType.DEVICE.toString(), - SubAction.INSTALL.toString()); + SubAction.INSTALL.toString(), app.getProperties()); } } } @@ -621,7 +622,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { * data. */ private ApplicationInstallResponse performActionOnDevices(String deviceType, List devices, - ApplicationDTO applicationDTO, String subType, List subscribers, String action) + ApplicationDTO applicationDTO, String subType, List subscribers, String action, Properties properties) throws ApplicationManagementException { //Get app subscribing info of each device @@ -667,11 +668,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } for (Map.Entry> entry : deviceIdentifierMap.entrySet()) { Activity activity = addAppOperationOnDevices(applicationDTO, new ArrayList<>(entry.getValue()), - entry.getKey(), action); + entry.getKey(), action, properties); activityList.add(activity); } } else { - Activity activity = addAppOperationOnDevices(applicationDTO, deviceIdentifiers, deviceType, action); + Activity activity = addAppOperationOnDevices(applicationDTO, deviceIdentifiers, deviceType, action, properties); activityList.add(activity); } @@ -982,13 +983,13 @@ public class SubscriptionManagerImpl implements SubscriptionManager { * @throws ApplicationManagementException if found an invalid device. */ private Activity addAppOperationOnDevices(ApplicationDTO applicationDTO, - List deviceIdentifierList, String deviceType, String action) + List deviceIdentifierList, String deviceType, String action, Properties properties) throws ApplicationManagementException { DeviceManagementProviderService deviceManagementProviderService = HelperUtil .getDeviceManagementProviderService(); try { Application application = APIUtil.appDtoToAppResponse(applicationDTO); - Operation operation = generateOperationPayloadByDeviceType(deviceType, application, action); + Operation operation = generateOperationPayloadByDeviceType(deviceType, application, action, properties); return deviceManagementProviderService.addOperation(deviceType, operation, deviceIdentifierList); } catch (OperationManagementException e) { String msg = "Error occurred while adding the application install operation to devices"; @@ -1010,7 +1011,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { * @throws ApplicationManagementException if unknown application type is found to generate operation payload or * invalid action is found to generate operation payload. */ - private Operation generateOperationPayloadByDeviceType(String deviceType, Application application, String action) + private Operation generateOperationPayloadByDeviceType(String deviceType, Application application, String action, Properties properties) throws ApplicationManagementException { try { if (ApplicationType.CUSTOM.toString().equalsIgnoreCase(application.getType())) { @@ -1046,6 +1047,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { app.setLocation(application.getApplicationReleases().get(0).getInstallerPath()); app.setIdentifier(application.getPackageName()); app.setName(application.getName()); + app.setProperties(properties); if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { return MDMAndroidOperationUtil.createInstallAppOperation(app); } else { @@ -1067,7 +1069,6 @@ public class SubscriptionManagerImpl implements SubscriptionManager { app.setType(mobileAppType); app.setLocation(plistDownloadEndpoint); app.setIconImage(application.getApplicationReleases().get(0).getIconPath()); - Properties properties = new Properties(); properties.put(MDMAppConstants.IOSConstants.IS_PREVENT_BACKUP, true); properties.put(MDMAppConstants.IOSConstants.IS_REMOVE_APP, true); properties.put(MDMAppConstants.IOSConstants.I_TUNES_ID, application.getPackageName()); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/task/ScheduledAppSubscriptionTask.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/task/ScheduledAppSubscriptionTask.java index 8a95efc0aa..d8f491e37d 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/task/ScheduledAppSubscriptionTask.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/task/ScheduledAppSubscriptionTask.java @@ -37,6 +37,7 @@ import org.wso2.carbon.device.mgt.core.task.impl.RandomlyAssignedScheduleTask; import java.util.List; import java.util.Map; +import java.util.Properties; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -45,6 +46,7 @@ public class ScheduledAppSubscriptionTask extends RandomlyAssignedScheduleTask { private static final String TASK_NAME = "SCHEDULE_APP_SUBSCRIPTION"; private SubscriptionManager subscriptionManager; + private String payload; private String subscribers; private String subscriptionType; private String application; @@ -57,6 +59,7 @@ public class ScheduledAppSubscriptionTask extends RandomlyAssignedScheduleTask { @Override public void setProperties(Map map) { this.subscribers = map.get(Constants.SUBSCRIBERS); + this.payload = map.get(Constants.PAYLOAD); this.subscriptionType = map.get(Constants.SUB_TYPE); this.application = map.get(Constants.APP_UUID); this.action = map.get(Constants.ACTION); @@ -89,8 +92,9 @@ public class ScheduledAppSubscriptionTask extends RandomlyAssignedScheduleTask { new TypeToken>() { }.getType()); try { + Properties properties = new Gson().fromJson(payload, Properties.class); subscriptionManager.performBulkAppOperation(this.application, deviceIdentifiers, - this.subscriptionType, this.action); + this.subscriptionType, this.action, properties); subscriptionDTO.setStatus(ExecutionStatus.EXECUTED); } catch (ApplicationManagementException e) { log.error( @@ -102,8 +106,9 @@ public class ScheduledAppSubscriptionTask extends RandomlyAssignedScheduleTask { List subscriberList = Pattern.compile(",").splitAsStream(this.subscribers).collect( Collectors.toList()); try { + Properties properties = new Gson().fromJson(payload, Properties.class); subscriptionManager.performBulkAppOperation(this.application, subscriberList, - this.subscriptionType, this.action); + this.subscriptionType, this.action, properties); subscriptionDTO.setStatus(ExecutionStatus.EXECUTED); } catch (ApplicationManagementException e) { log.error( diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/task/ScheduledAppSubscriptionTaskManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/task/ScheduledAppSubscriptionTaskManager.java index 326a358e1b..b274b1850f 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/task/ScheduledAppSubscriptionTaskManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/task/ScheduledAppSubscriptionTaskManager.java @@ -46,6 +46,7 @@ import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Properties; import java.util.stream.Collectors; public class ScheduledAppSubscriptionTaskManager { @@ -73,7 +74,7 @@ public class ScheduledAppSubscriptionTaskManager { * @throws ApplicationOperationTaskException if error occurred while scheduling the subscription */ public void scheduleAppSubscriptionTask(String applicationUUID, List subscribers, - SubscriptionType subscriptionType, SubAction action, long timestamp) + SubscriptionType subscriptionType, SubAction action, long timestamp, Properties properties) throws ApplicationOperationTaskException { Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date(timestamp * 1000)); @@ -106,7 +107,6 @@ public class ScheduledAppSubscriptionTaskManager { taskProperties.put(Constants.APP_UUID, applicationUUID); taskProperties.put(Constants.TENANT_DOMAIN, carbonContext.getTenantDomain(true)); taskProperties.put(Constants.SUBSCRIBER, carbonContext.getUsername()); - String subscribersString; if (SubscriptionType.DEVICE.equals(subscriptionType)) { subscribersString = new Gson().toJson(subscribers); @@ -115,6 +115,10 @@ public class ScheduledAppSubscriptionTaskManager { subscribersString = subscribers.stream().map(String.class::cast).collect(Collectors.joining(",")); taskProperties.put(Constants.SUBSCRIBERS, subscribersString); } + if(properties != null) { + String payload = new Gson().toJson(properties); + taskProperties.put(Constants.PAYLOAD, payload); + } if (log.isDebugEnabled()) { log.debug("Scheduling a task to " + action.toString() + " application: " + applicationUUID + " to/from the following " + subscriptionType.toString() + "S [" + subscribersString + "] at: " diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/Constants.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/Constants.java index 866fbdd524..27498f77bb 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/Constants.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/Constants.java @@ -58,6 +58,7 @@ public class Constants { public static final String SUB_TYPE = "SUBSCRIPTION_TYPE"; public static final String ACTION = "ACTION"; public static final String APP_UUID = "APP_UUID"; + public static final String APP_PROPERTIES = "APP_PROPERTIES"; public static final String SUBSCRIBER = "SUBSCRIBER"; public static final String TENANT_DOMAIN = "TENANT_DOMAIN"; public static final String TENANT_ID = "__TENANT_ID_PROP__"; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/SubscriptionManagementAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/SubscriptionManagementAPI.java index 2c8811358d..174b6921ee 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/SubscriptionManagementAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/SubscriptionManagementAPI.java @@ -130,7 +130,12 @@ public interface SubscriptionManagementAPI { name = "timestamp", value = "Timestamp of scheduled install/uninstall operation" ) - @QueryParam("timestamp") long timestamp + @QueryParam("timestamp") long timestamp, + @ApiParam( + name = "block-uninstall", + value = "App removal status of the install operation" + ) + @QueryParam("block-uninstall") Boolean isUninstallBlocked ); @POST @@ -183,7 +188,12 @@ public interface SubscriptionManagementAPI { name = "timestamp", value = "Timestamp of scheduled install/uninstall operation" ) - @QueryParam("timestamp") long timestamp + @QueryParam("timestamp") long timestamp, + @ApiParam( + name = "block-uninstall", + value = "App removal status of the install operation" + ) + @QueryParam("block-uninstall") Boolean isUninstallBlocked ); @POST diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/SubscriptionManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/SubscriptionManagementAPIImpl.java index a6324c8fdb..4a51353997 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/SubscriptionManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/SubscriptionManagementAPIImpl.java @@ -34,8 +34,6 @@ import org.wso2.carbon.device.application.mgt.common.BasicUserInfoList; import org.wso2.carbon.device.application.mgt.common.RoleList; import org.wso2.carbon.device.application.mgt.common.DeviceGroupList; import org.wso2.carbon.device.application.mgt.store.api.services.impl.util.RequestValidationUtil; -import org.wso2.carbon.device.mgt.common.PaginationRequest; -import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException; import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException; import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException; @@ -44,6 +42,9 @@ import org.wso2.carbon.device.application.mgt.core.util.APIUtil; import org.wso2.carbon.device.application.mgt.store.api.services.SubscriptionManagementAPI; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.MDMAppConstants; +import org.wso2.carbon.device.mgt.common.PaginationRequest; +import org.wso2.carbon.device.mgt.common.PaginationResult; import javax.validation.Valid; import javax.ws.rs.Path; @@ -55,9 +56,8 @@ import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.core.Response; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; import java.util.List; +import java.util.Properties; /** * Implementation of Subscription Management related APIs. @@ -75,16 +75,22 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ @PathParam("uuid") String uuid, @PathParam("action") String action, @Valid List deviceIdentifiers, - @QueryParam("timestamp") long timestamp) { + @QueryParam("timestamp") long timestamp, + @QueryParam("block-uninstall") Boolean isUninstallBlocked + ) { + Properties properties = new Properties(); + if(isUninstallBlocked != null) { + properties.put(MDMAppConstants.AndroidConstants.IS_BLOCK_UNINSTALL, isUninstallBlocked); + } try { if (0 == timestamp) { SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager(); ApplicationInstallResponse response = subscriptionManager - .performBulkAppOperation(uuid, deviceIdentifiers, SubscriptionType.DEVICE.toString(), action); + .performBulkAppOperation(uuid, deviceIdentifiers, SubscriptionType.DEVICE.toString(), action, properties); return Response.status(Response.Status.OK).entity(response).build(); } else { return scheduleApplicationOperationTask(uuid, deviceIdentifiers, SubscriptionType.DEVICE, - SubAction.valueOf(action.toUpperCase()), timestamp); + SubAction.valueOf(action.toUpperCase()), timestamp, properties); } } catch (NotFoundException e) { String msg = "Couldn't found an application release for UUI: " + uuid; @@ -116,17 +122,23 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ @PathParam("subType") String subType, @PathParam("action") String action, @Valid List subscribers, - @QueryParam("timestamp") long timestamp) { + @QueryParam("timestamp") long timestamp, + @QueryParam("block-uninstall") Boolean isUninstallBlocked + ) { + Properties properties = new Properties(); + if(isUninstallBlocked != null) { + properties.put(MDMAppConstants.AndroidConstants.IS_BLOCK_UNINSTALL, isUninstallBlocked); + } try { if (0 == timestamp) { SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager(); ApplicationInstallResponse response = subscriptionManager - .performBulkAppOperation(uuid, subscribers, subType, action); + .performBulkAppOperation(uuid, subscribers, subType, action, properties); return Response.status(Response.Status.OK).entity(response).build(); } else { return scheduleApplicationOperationTask(uuid, subscribers, SubscriptionType.valueOf(subType.toUpperCase()), SubAction.valueOf(action.toUpperCase()), - timestamp); + timestamp, properties); } } catch (NotFoundException e) { String msg = "Couldn't found an application release for UUID: " + uuid + ". Hence, verify the payload"; @@ -170,7 +182,7 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ return Response.status(Response.Status.OK).entity(msg).build(); } else { return scheduleApplicationOperationTask(uuid, deviceIdentifiers, SubscriptionType.DEVICE, - SubAction.valueOf(SubAction.INSTALL.toString().toUpperCase()), timestamp); + SubAction.valueOf(SubAction.INSTALL.toString().toUpperCase()), timestamp, null); } } catch (NotFoundException e) { String msg = "Couldn't found an application release for UUI: " + uuid + " to perform ent app installation " @@ -216,7 +228,7 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ } else { return scheduleApplicationOperationTask(uuid, subscribers, SubscriptionType.valueOf(subType.toUpperCase()), - SubAction.valueOf(SubAction.INSTALL.toString().toUpperCase()), timestamp); + SubAction.valueOf(SubAction.INSTALL.toString().toUpperCase()), timestamp, null); } } catch (NotFoundException e) { String msg = "Couldn't found an application release for UUID: " + uuid + ". Hence, verify the payload"; @@ -255,11 +267,11 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ * @return {@link Response} of the operation */ private Response scheduleApplicationOperationTask(String applicationUUID, List subscribers, - SubscriptionType subType, SubAction subAction, long timestamp) { + SubscriptionType subType, SubAction subAction, long timestamp, Properties payload) { try { ScheduledAppSubscriptionTaskManager subscriptionTaskManager = new ScheduledAppSubscriptionTaskManager(); subscriptionTaskManager.scheduleAppSubscriptionTask(applicationUUID, subscribers, subType, subAction, - timestamp); + timestamp, payload); } catch (ApplicationOperationTaskException e) { String msg = "Error occurred while scheduling the application install operation"; log.error(msg, e); @@ -330,7 +342,7 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ return Response.status(Response.Status.FORBIDDEN).entity(msg).build(); } catch (ApplicationManagementException e) { String msg = "Error occurred while getting application with the application release uuid: " - + uuid; + + uuid; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } @@ -385,17 +397,17 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } catch (BadRequestException e) { String msg = "Found invalid payload for getting application which has UUID: " + uuid - + ". Hence verify the payload"; + + ". Hence verify the payload"; log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (ForbiddenException e) { String msg = "Application release is not in the installable state." - + "Hence you are not permitted to get the devices details."; + + "Hence you are not permitted to get the devices details."; log.error(msg, e); return Response.status(Response.Status.FORBIDDEN).entity(msg).build(); } catch (ApplicationManagementException e) { String msg = "Error occurred while getting application with the application " + - "release uuid: " + uuid; + "release uuid: " + uuid; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java index 7648a102b8..c0a5a4a6b4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java @@ -136,6 +136,7 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.ArrayList; +import java.util.Properties; @Path("/devices") public class DeviceManagementServiceImpl implements DeviceManagementService { @@ -915,7 +916,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { if (UUID != null) { ApplicationInstallResponse response = subscriptionManager .performBulkAppOperation(UUID, deviceIdentifiers, SubscriptionType.DEVICE.toString(), - "uninstall"); + "uninstall", new Properties()); return Response.status(Response.Status.OK).entity(response).build(); //if the applications not installed via entgra store } else { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/MDMAppConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/MDMAppConstants.java index e7f8f17df7..40b647d6ea 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/MDMAppConstants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/MDMAppConstants.java @@ -45,6 +45,7 @@ public class MDMAppConstants { private AndroidConstants() { throw new AssertionError(); } + public static final String IS_BLOCK_UNINSTALL = "isBlockUninstall"; public static final String OPCODE_INSTALL_APPLICATION = "INSTALL_APPLICATION"; public static final String OPCODE_UNINSTALL_APPLICATION = "UNINSTALL_APPLICATION"; public static final String UNMANAGED_APP_UNINSTALL= "UNMANAGED_APP_UNINSTALL"; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/android/AppStoreApplication.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/android/AppStoreApplication.java index 50126814ca..71464070b7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/android/AppStoreApplication.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/android/AppStoreApplication.java @@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.common.app.mgt.android; import com.google.gson.Gson; import java.io.Serializable; +import java.util.Properties; /** * This class represents the Appstore AuthenticationImpl information. @@ -29,6 +30,7 @@ public class AppStoreApplication implements Serializable { private String type; private String appIdentifier; + private Properties properties; public String getType() { return type; @@ -51,4 +53,11 @@ public class AppStoreApplication implements Serializable { return gson.toJson(this); } + public Properties getProperties() { + return properties; + } + + public void setProperties(Properties properties) { + this.properties = properties; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/android/EnterpriseApplication.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/android/EnterpriseApplication.java index f087013a18..0e9bdb47da 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/android/EnterpriseApplication.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/android/EnterpriseApplication.java @@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.common.app.mgt.android; import com.google.gson.Gson; import java.io.Serializable; +import java.util.Properties; /** * This class represents the Enterprise AuthenticationImpl information. @@ -30,6 +31,7 @@ public class EnterpriseApplication implements Serializable { private String type; private String url; private String appIdentifier; + private Properties properties; public String getAppIdentifier() { return appIdentifier; @@ -60,4 +62,11 @@ public class EnterpriseApplication implements Serializable { return gson.toJson(this); } + public Properties getProperties() { + return properties; + } + + public void setProperties(Properties properties) { + this.properties = properties; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/android/WebApplication.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/android/WebApplication.java index 3257429269..70797dc8d9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/android/WebApplication.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/android/WebApplication.java @@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.common.app.mgt.android; import com.google.gson.Gson; import java.io.Serializable; +import java.util.Properties; /** * This class represents the Web AuthenticationImpl information. @@ -30,6 +31,7 @@ public class WebApplication implements Serializable { private String name; private String url; private String type; + private Properties properties; public String getName() { return name; @@ -60,4 +62,11 @@ public class WebApplication implements Serializable { return gson.toJson(this); } + public Properties getProperties() { + return properties; + } + + public void setProperties(Properties properties) { + this.properties = properties; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/MDMAndroidOperationUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/MDMAndroidOperationUtil.java index 14dbaea9ed..99cacfd950 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/MDMAndroidOperationUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/MDMAndroidOperationUtil.java @@ -52,6 +52,7 @@ public class MDMAndroidOperationUtil { enterpriseApplication.setType(application.getType().toString()); enterpriseApplication.setUrl(application.getLocation()); enterpriseApplication.setAppIdentifier(application.getIdentifier()); + enterpriseApplication.setProperties(application.getProperties()); operation.setPayLoad(enterpriseApplication.toJSON()); break; case PUBLIC: @@ -59,6 +60,7 @@ public class MDMAndroidOperationUtil { new AppStoreApplication(); appStoreApplication.setType(application.getType().toString()); appStoreApplication.setAppIdentifier(application.getIdentifier()); + appStoreApplication.setProperties(application.getProperties()); operation.setPayLoad(appStoreApplication.toJSON()); break; case WEBAPP: @@ -67,6 +69,7 @@ public class MDMAndroidOperationUtil { webApplication.setUrl(application.getLocation()); webApplication.setName(application.getName()); webApplication.setType(application.getType().toString()); + webApplication.setProperties(application.getProperties()); operation.setPayLoad(webApplication.toJSON()); break; default: @@ -93,6 +96,7 @@ public class MDMAndroidOperationUtil { new EnterpriseApplication(); enterpriseApplication.setType(application.getType().toString()); enterpriseApplication.setAppIdentifier(application.getIdentifier()); + enterpriseApplication.setProperties(application.getProperties()); operation.setPayLoad(enterpriseApplication.toJSON()); break; case PUBLIC: