Block Uninstall Policy Feature

(cherry picked from commit 556886daec)
4.x.x
Muhammad Rashad 3 years ago committed by Pahansith
parent 36f132d363
commit 5795db1360

@ -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.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationResult; 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.List;
import java.util.Properties;
/** /**
* This interface manages all the operations related with ApplicationDTO Subscription. * This interface manages all the operations related with ApplicationDTO Subscription.
@ -33,10 +35,9 @@ import java.util.List;
public interface SubscriptionManager { public interface SubscriptionManager {
/** /**
* Performs bulk subscription operation for a given application and a subscriber list. * 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 * @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 * to DEVICE or
* {@link String} if {@param subType} is USER, ROLE or GROUP * {@link String} if {@param subType} is USER, ROLE or GROUP
* @param subType subscription type. E.g. <code>DEVICE, USER, ROLE, GROUP</code> {@see { * @param subType subscription type. E.g. <code>DEVICE, USER, ROLE, GROUP</code> {@see {
@ -46,9 +47,10 @@ public interface SubscriptionManager {
* @throws ApplicationManagementException if error occurs when subscribing to the given application * @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.SubscriptionType}}
* @link org.wso2.carbon.device.application.mgt.common.SubAction}} * @link org.wso2.carbon.device.application.mgt.common.SubAction}}
* @param properties
*/ */
<T> ApplicationInstallResponse performBulkAppOperation(String applicationUUID, List<T> params, String subType, <T> ApplicationInstallResponse performBulkAppOperation(String applicationUUID, List<T> params, String subType,
String action) throws ApplicationManagementException; String action, Properties properties) throws ApplicationManagementException;
/** /**
* Create an entry related to the scheduled task in the database. * 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 * @throws ApplicationManagementException if error occurred while installing given applications into the given
* device * device
*/ */
void installAppsForDevice(DeviceIdentifier deviceIdentifier, List<String> releaseUUID) void installAppsForDevice(DeviceIdentifier deviceIdentifier, List<App> apps)
throws ApplicationManagementException; throws ApplicationManagementException;
/*** /***

@ -121,7 +121,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
@Override @Override
public <T> ApplicationInstallResponse performBulkAppOperation(String applicationUUID, List<T> params, public <T> ApplicationInstallResponse performBulkAppOperation(String applicationUUID, List<T> params,
String subType, String action) throws ApplicationManagementException { String subType, String action, Properties properties) throws ApplicationManagementException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Install application release which has UUID " + applicationUUID + " to " + params.size() log.debug("Install application release which has UUID " + applicationUUID + " to " + params.size()
+ " users."); + " users.");
@ -134,7 +134,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
params); params);
ApplicationInstallResponse applicationInstallResponse = performActionOnDevices( ApplicationInstallResponse applicationInstallResponse = performActionOnDevices(
applicationSubscriptionInfo.getAppSupportingDeviceTypeName(), applicationSubscriptionInfo.getDevices(), applicationSubscriptionInfo.getAppSupportingDeviceTypeName(), applicationSubscriptionInfo.getDevices(),
applicationDTO, subType, applicationSubscriptionInfo.getSubscribers(), action); applicationDTO, subType, applicationSubscriptionInfo.getSubscribers(), action, properties);
applicationInstallResponse.setErrorDeviceIdentifiers(applicationSubscriptionInfo.getErrorDeviceIdentifiers()); applicationInstallResponse.setErrorDeviceIdentifiers(applicationSubscriptionInfo.getErrorDeviceIdentifiers());
return applicationInstallResponse; return applicationInstallResponse;
@ -347,7 +347,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
} }
@Override @Override
public void installAppsForDevice(DeviceIdentifier deviceIdentifier, List<String> releaseUUIDs) public void installAppsForDevice(DeviceIdentifier deviceIdentifier, List<App> apps)
throws ApplicationManagementException { throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
@ -370,7 +370,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
List<DeviceIdentifier> appInstallingDevices = new ArrayList<>(); List<DeviceIdentifier> appInstallingDevices = new ArrayList<>();
for (String releaseUUID : releaseUUIDs) { for (App app : apps) {
String releaseUUID = app.getId();
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(releaseUUID, tenantId); ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(releaseUUID, tenantId);
@ -409,7 +410,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if (!appInstallingDevices.isEmpty()) { if (!appInstallingDevices.isEmpty()) {
performBulkAppOperation(releaseUUID, appInstallingDevices, SubscriptionType.DEVICE.toString(), performBulkAppOperation(releaseUUID, appInstallingDevices, SubscriptionType.DEVICE.toString(),
SubAction.INSTALL.toString()); SubAction.INSTALL.toString(), app.getProperties());
} }
} }
} }
@ -621,7 +622,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
* data. * data.
*/ */
private ApplicationInstallResponse performActionOnDevices(String deviceType, List<Device> devices, private ApplicationInstallResponse performActionOnDevices(String deviceType, List<Device> devices,
ApplicationDTO applicationDTO, String subType, List<String> subscribers, String action) ApplicationDTO applicationDTO, String subType, List<String> subscribers, String action, Properties properties)
throws ApplicationManagementException { throws ApplicationManagementException {
//Get app subscribing info of each device //Get app subscribing info of each device
@ -667,11 +668,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
} }
for (Map.Entry<String, List<DeviceIdentifier>> entry : deviceIdentifierMap.entrySet()) { for (Map.Entry<String, List<DeviceIdentifier>> entry : deviceIdentifierMap.entrySet()) {
Activity activity = addAppOperationOnDevices(applicationDTO, new ArrayList<>(entry.getValue()), Activity activity = addAppOperationOnDevices(applicationDTO, new ArrayList<>(entry.getValue()),
entry.getKey(), action); entry.getKey(), action, properties);
activityList.add(activity); activityList.add(activity);
} }
} else { } else {
Activity activity = addAppOperationOnDevices(applicationDTO, deviceIdentifiers, deviceType, action); Activity activity = addAppOperationOnDevices(applicationDTO, deviceIdentifiers, deviceType, action, properties);
activityList.add(activity); activityList.add(activity);
} }
@ -982,13 +983,13 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
* @throws ApplicationManagementException if found an invalid device. * @throws ApplicationManagementException if found an invalid device.
*/ */
private Activity addAppOperationOnDevices(ApplicationDTO applicationDTO, private Activity addAppOperationOnDevices(ApplicationDTO applicationDTO,
List<DeviceIdentifier> deviceIdentifierList, String deviceType, String action) List<DeviceIdentifier> deviceIdentifierList, String deviceType, String action, Properties properties)
throws ApplicationManagementException { throws ApplicationManagementException {
DeviceManagementProviderService deviceManagementProviderService = HelperUtil DeviceManagementProviderService deviceManagementProviderService = HelperUtil
.getDeviceManagementProviderService(); .getDeviceManagementProviderService();
try { try {
Application application = APIUtil.appDtoToAppResponse(applicationDTO); Application application = APIUtil.appDtoToAppResponse(applicationDTO);
Operation operation = generateOperationPayloadByDeviceType(deviceType, application, action); Operation operation = generateOperationPayloadByDeviceType(deviceType, application, action, properties);
return deviceManagementProviderService.addOperation(deviceType, operation, deviceIdentifierList); return deviceManagementProviderService.addOperation(deviceType, operation, deviceIdentifierList);
} catch (OperationManagementException e) { } catch (OperationManagementException e) {
String msg = "Error occurred while adding the application install operation to devices"; 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 * @throws ApplicationManagementException if unknown application type is found to generate operation payload or
* invalid action is found to generate operation payload. * 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 { throws ApplicationManagementException {
try { try {
if (ApplicationType.CUSTOM.toString().equalsIgnoreCase(application.getType())) { if (ApplicationType.CUSTOM.toString().equalsIgnoreCase(application.getType())) {
@ -1046,6 +1047,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
app.setLocation(application.getApplicationReleases().get(0).getInstallerPath()); app.setLocation(application.getApplicationReleases().get(0).getInstallerPath());
app.setIdentifier(application.getPackageName()); app.setIdentifier(application.getPackageName());
app.setName(application.getName()); app.setName(application.getName());
app.setProperties(properties);
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
return MDMAndroidOperationUtil.createInstallAppOperation(app); return MDMAndroidOperationUtil.createInstallAppOperation(app);
} else { } else {
@ -1067,7 +1069,6 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
app.setType(mobileAppType); app.setType(mobileAppType);
app.setLocation(plistDownloadEndpoint); app.setLocation(plistDownloadEndpoint);
app.setIconImage(application.getApplicationReleases().get(0).getIconPath()); app.setIconImage(application.getApplicationReleases().get(0).getIconPath());
Properties properties = new Properties();
properties.put(MDMAppConstants.IOSConstants.IS_PREVENT_BACKUP, true); properties.put(MDMAppConstants.IOSConstants.IS_PREVENT_BACKUP, true);
properties.put(MDMAppConstants.IOSConstants.IS_REMOVE_APP, true); properties.put(MDMAppConstants.IOSConstants.IS_REMOVE_APP, true);
properties.put(MDMAppConstants.IOSConstants.I_TUNES_ID, application.getPackageName()); properties.put(MDMAppConstants.IOSConstants.I_TUNES_ID, application.getPackageName());

@ -37,6 +37,7 @@ import org.wso2.carbon.device.mgt.core.task.impl.RandomlyAssignedScheduleTask;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -45,6 +46,7 @@ public class ScheduledAppSubscriptionTask extends RandomlyAssignedScheduleTask {
private static final String TASK_NAME = "SCHEDULE_APP_SUBSCRIPTION"; private static final String TASK_NAME = "SCHEDULE_APP_SUBSCRIPTION";
private SubscriptionManager subscriptionManager; private SubscriptionManager subscriptionManager;
private String payload;
private String subscribers; private String subscribers;
private String subscriptionType; private String subscriptionType;
private String application; private String application;
@ -57,6 +59,7 @@ public class ScheduledAppSubscriptionTask extends RandomlyAssignedScheduleTask {
@Override @Override
public void setProperties(Map<String, String> map) { public void setProperties(Map<String, String> map) {
this.subscribers = map.get(Constants.SUBSCRIBERS); this.subscribers = map.get(Constants.SUBSCRIBERS);
this.payload = map.get(Constants.PAYLOAD);
this.subscriptionType = map.get(Constants.SUB_TYPE); this.subscriptionType = map.get(Constants.SUB_TYPE);
this.application = map.get(Constants.APP_UUID); this.application = map.get(Constants.APP_UUID);
this.action = map.get(Constants.ACTION); this.action = map.get(Constants.ACTION);
@ -89,8 +92,9 @@ public class ScheduledAppSubscriptionTask extends RandomlyAssignedScheduleTask {
new TypeToken<List<DeviceIdentifier>>() { new TypeToken<List<DeviceIdentifier>>() {
}.getType()); }.getType());
try { try {
Properties properties = new Gson().fromJson(payload, Properties.class);
subscriptionManager.performBulkAppOperation(this.application, deviceIdentifiers, subscriptionManager.performBulkAppOperation(this.application, deviceIdentifiers,
this.subscriptionType, this.action); this.subscriptionType, this.action, properties);
subscriptionDTO.setStatus(ExecutionStatus.EXECUTED); subscriptionDTO.setStatus(ExecutionStatus.EXECUTED);
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
log.error( log.error(
@ -102,8 +106,9 @@ public class ScheduledAppSubscriptionTask extends RandomlyAssignedScheduleTask {
List<String> subscriberList = Pattern.compile(",").splitAsStream(this.subscribers).collect( List<String> subscriberList = Pattern.compile(",").splitAsStream(this.subscribers).collect(
Collectors.toList()); Collectors.toList());
try { try {
Properties properties = new Gson().fromJson(payload, Properties.class);
subscriptionManager.performBulkAppOperation(this.application, subscriberList, subscriptionManager.performBulkAppOperation(this.application, subscriberList,
this.subscriptionType, this.action); this.subscriptionType, this.action, properties);
subscriptionDTO.setStatus(ExecutionStatus.EXECUTED); subscriptionDTO.setStatus(ExecutionStatus.EXECUTED);
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
log.error( log.error(

@ -46,6 +46,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Properties;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class ScheduledAppSubscriptionTaskManager { public class ScheduledAppSubscriptionTaskManager {
@ -73,7 +74,7 @@ public class ScheduledAppSubscriptionTaskManager {
* @throws ApplicationOperationTaskException if error occurred while scheduling the subscription * @throws ApplicationOperationTaskException if error occurred while scheduling the subscription
*/ */
public void scheduleAppSubscriptionTask(String applicationUUID, List<?> subscribers, public void scheduleAppSubscriptionTask(String applicationUUID, List<?> subscribers,
SubscriptionType subscriptionType, SubAction action, long timestamp) SubscriptionType subscriptionType, SubAction action, long timestamp, Properties properties)
throws ApplicationOperationTaskException { throws ApplicationOperationTaskException {
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date(timestamp * 1000)); calendar.setTime(new Date(timestamp * 1000));
@ -106,7 +107,6 @@ public class ScheduledAppSubscriptionTaskManager {
taskProperties.put(Constants.APP_UUID, applicationUUID); taskProperties.put(Constants.APP_UUID, applicationUUID);
taskProperties.put(Constants.TENANT_DOMAIN, carbonContext.getTenantDomain(true)); taskProperties.put(Constants.TENANT_DOMAIN, carbonContext.getTenantDomain(true));
taskProperties.put(Constants.SUBSCRIBER, carbonContext.getUsername()); taskProperties.put(Constants.SUBSCRIBER, carbonContext.getUsername());
String subscribersString; String subscribersString;
if (SubscriptionType.DEVICE.equals(subscriptionType)) { if (SubscriptionType.DEVICE.equals(subscriptionType)) {
subscribersString = new Gson().toJson(subscribers); subscribersString = new Gson().toJson(subscribers);
@ -115,6 +115,10 @@ public class ScheduledAppSubscriptionTaskManager {
subscribersString = subscribers.stream().map(String.class::cast).collect(Collectors.joining(",")); subscribersString = subscribers.stream().map(String.class::cast).collect(Collectors.joining(","));
taskProperties.put(Constants.SUBSCRIBERS, subscribersString); taskProperties.put(Constants.SUBSCRIBERS, subscribersString);
} }
if(properties != null) {
String payload = new Gson().toJson(properties);
taskProperties.put(Constants.PAYLOAD, payload);
}
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Scheduling a task to " + action.toString() + " application: " + applicationUUID + log.debug("Scheduling a task to " + action.toString() + " application: " + applicationUUID +
" to/from the following " + subscriptionType.toString() + "S [" + subscribersString + "] at: " " to/from the following " + subscriptionType.toString() + "S [" + subscribersString + "] at: "

@ -58,6 +58,7 @@ public class Constants {
public static final String SUB_TYPE = "SUBSCRIPTION_TYPE"; public static final String SUB_TYPE = "SUBSCRIPTION_TYPE";
public static final String ACTION = "ACTION"; public static final String ACTION = "ACTION";
public static final String APP_UUID = "APP_UUID"; 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 SUBSCRIBER = "SUBSCRIBER";
public static final String TENANT_DOMAIN = "TENANT_DOMAIN"; public static final String TENANT_DOMAIN = "TENANT_DOMAIN";
public static final String TENANT_ID = "__TENANT_ID_PROP__"; public static final String TENANT_ID = "__TENANT_ID_PROP__";

@ -130,7 +130,12 @@ public interface SubscriptionManagementAPI {
name = "timestamp", name = "timestamp",
value = "Timestamp of scheduled install/uninstall operation" 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 @POST
@ -183,7 +188,12 @@ public interface SubscriptionManagementAPI {
name = "timestamp", name = "timestamp",
value = "Timestamp of scheduled install/uninstall operation" 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 @POST

@ -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.RoleList;
import org.wso2.carbon.device.application.mgt.common.DeviceGroupList; 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.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.BadRequestException;
import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException; import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException;
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException; 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.application.mgt.store.api.services.SubscriptionManagementAPI;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; 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.validation.Valid;
import javax.ws.rs.Path; import javax.ws.rs.Path;
@ -55,9 +56,8 @@ import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List; import java.util.List;
import java.util.Properties;
/** /**
* Implementation of Subscription Management related APIs. * Implementation of Subscription Management related APIs.
@ -75,16 +75,22 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{
@PathParam("uuid") String uuid, @PathParam("uuid") String uuid,
@PathParam("action") String action, @PathParam("action") String action,
@Valid List<DeviceIdentifier> deviceIdentifiers, @Valid List<DeviceIdentifier> 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 { try {
if (0 == timestamp) { if (0 == timestamp) {
SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager(); SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager();
ApplicationInstallResponse response = subscriptionManager 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(); return Response.status(Response.Status.OK).entity(response).build();
} else { } else {
return scheduleApplicationOperationTask(uuid, deviceIdentifiers, SubscriptionType.DEVICE, return scheduleApplicationOperationTask(uuid, deviceIdentifiers, SubscriptionType.DEVICE,
SubAction.valueOf(action.toUpperCase()), timestamp); SubAction.valueOf(action.toUpperCase()), timestamp, properties);
} }
} catch (NotFoundException e) { } catch (NotFoundException e) {
String msg = "Couldn't found an application release for UUI: " + uuid; 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("subType") String subType,
@PathParam("action") String action, @PathParam("action") String action,
@Valid List<String> subscribers, @Valid List<String> 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 { try {
if (0 == timestamp) { if (0 == timestamp) {
SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager(); SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager();
ApplicationInstallResponse response = subscriptionManager ApplicationInstallResponse response = subscriptionManager
.performBulkAppOperation(uuid, subscribers, subType, action); .performBulkAppOperation(uuid, subscribers, subType, action, properties);
return Response.status(Response.Status.OK).entity(response).build(); return Response.status(Response.Status.OK).entity(response).build();
} else { } else {
return scheduleApplicationOperationTask(uuid, subscribers, return scheduleApplicationOperationTask(uuid, subscribers,
SubscriptionType.valueOf(subType.toUpperCase()), SubAction.valueOf(action.toUpperCase()), SubscriptionType.valueOf(subType.toUpperCase()), SubAction.valueOf(action.toUpperCase()),
timestamp); timestamp, properties);
} }
} catch (NotFoundException e) { } catch (NotFoundException e) {
String msg = "Couldn't found an application release for UUID: " + uuid + ". Hence, verify the payload"; 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(); return Response.status(Response.Status.OK).entity(msg).build();
} else { } else {
return scheduleApplicationOperationTask(uuid, deviceIdentifiers, SubscriptionType.DEVICE, return scheduleApplicationOperationTask(uuid, deviceIdentifiers, SubscriptionType.DEVICE,
SubAction.valueOf(SubAction.INSTALL.toString().toUpperCase()), timestamp); SubAction.valueOf(SubAction.INSTALL.toString().toUpperCase()), timestamp, null);
} }
} catch (NotFoundException e) { } catch (NotFoundException e) {
String msg = "Couldn't found an application release for UUI: " + uuid + " to perform ent app installation " 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 { } else {
return scheduleApplicationOperationTask(uuid, subscribers, return scheduleApplicationOperationTask(uuid, subscribers,
SubscriptionType.valueOf(subType.toUpperCase()), SubscriptionType.valueOf(subType.toUpperCase()),
SubAction.valueOf(SubAction.INSTALL.toString().toUpperCase()), timestamp); SubAction.valueOf(SubAction.INSTALL.toString().toUpperCase()), timestamp, null);
} }
} catch (NotFoundException e) { } catch (NotFoundException e) {
String msg = "Couldn't found an application release for UUID: " + uuid + ". Hence, verify the payload"; 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 * @return {@link Response} of the operation
*/ */
private Response scheduleApplicationOperationTask(String applicationUUID, List<?> subscribers, private Response scheduleApplicationOperationTask(String applicationUUID, List<?> subscribers,
SubscriptionType subType, SubAction subAction, long timestamp) { SubscriptionType subType, SubAction subAction, long timestamp, Properties payload) {
try { try {
ScheduledAppSubscriptionTaskManager subscriptionTaskManager = new ScheduledAppSubscriptionTaskManager(); ScheduledAppSubscriptionTaskManager subscriptionTaskManager = new ScheduledAppSubscriptionTaskManager();
subscriptionTaskManager.scheduleAppSubscriptionTask(applicationUUID, subscribers, subType, subAction, subscriptionTaskManager.scheduleAppSubscriptionTask(applicationUUID, subscribers, subType, subAction,
timestamp); timestamp, payload);
} catch (ApplicationOperationTaskException e) { } catch (ApplicationOperationTaskException e) {
String msg = "Error occurred while scheduling the application install operation"; String msg = "Error occurred while scheduling the application install operation";
log.error(msg, e); log.error(msg, e);

@ -136,6 +136,7 @@ import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Properties;
@Path("/devices") @Path("/devices")
public class DeviceManagementServiceImpl implements DeviceManagementService { public class DeviceManagementServiceImpl implements DeviceManagementService {
@ -915,7 +916,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
if (UUID != null) { if (UUID != null) {
ApplicationInstallResponse response = subscriptionManager ApplicationInstallResponse response = subscriptionManager
.performBulkAppOperation(UUID, deviceIdentifiers, SubscriptionType.DEVICE.toString(), .performBulkAppOperation(UUID, deviceIdentifiers, SubscriptionType.DEVICE.toString(),
"uninstall"); "uninstall", new Properties());
return Response.status(Response.Status.OK).entity(response).build(); return Response.status(Response.Status.OK).entity(response).build();
//if the applications not installed via entgra store //if the applications not installed via entgra store
} else { } else {

@ -45,6 +45,7 @@ public class MDMAppConstants {
private AndroidConstants() { private AndroidConstants() {
throw new AssertionError(); 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_INSTALL_APPLICATION = "INSTALL_APPLICATION";
public static final String OPCODE_UNINSTALL_APPLICATION = "UNINSTALL_APPLICATION"; public static final String OPCODE_UNINSTALL_APPLICATION = "UNINSTALL_APPLICATION";
public static final String UNMANAGED_APP_UNINSTALL= "UNMANAGED_APP_UNINSTALL"; public static final String UNMANAGED_APP_UNINSTALL= "UNMANAGED_APP_UNINSTALL";

@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.common.app.mgt.android;
import com.google.gson.Gson; import com.google.gson.Gson;
import java.io.Serializable; import java.io.Serializable;
import java.util.Properties;
/** /**
* This class represents the Appstore AuthenticationImpl information. * This class represents the Appstore AuthenticationImpl information.
@ -29,6 +30,7 @@ public class AppStoreApplication implements Serializable {
private String type; private String type;
private String appIdentifier; private String appIdentifier;
private Properties properties;
public String getType() { public String getType() {
return type; return type;
@ -51,4 +53,11 @@ public class AppStoreApplication implements Serializable {
return gson.toJson(this); return gson.toJson(this);
} }
public Properties getProperties() {
return properties;
}
public void setProperties(Properties properties) {
this.properties = properties;
}
} }

@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.common.app.mgt.android;
import com.google.gson.Gson; import com.google.gson.Gson;
import java.io.Serializable; import java.io.Serializable;
import java.util.Properties;
/** /**
* This class represents the Enterprise AuthenticationImpl information. * This class represents the Enterprise AuthenticationImpl information.
@ -30,6 +31,7 @@ public class EnterpriseApplication implements Serializable {
private String type; private String type;
private String url; private String url;
private String appIdentifier; private String appIdentifier;
private Properties properties;
public String getAppIdentifier() { public String getAppIdentifier() {
return appIdentifier; return appIdentifier;
@ -60,4 +62,11 @@ public class EnterpriseApplication implements Serializable {
return gson.toJson(this); return gson.toJson(this);
} }
public Properties getProperties() {
return properties;
}
public void setProperties(Properties properties) {
this.properties = properties;
}
} }

@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.common.app.mgt.android;
import com.google.gson.Gson; import com.google.gson.Gson;
import java.io.Serializable; import java.io.Serializable;
import java.util.Properties;
/** /**
* This class represents the Web AuthenticationImpl information. * This class represents the Web AuthenticationImpl information.
@ -30,6 +31,7 @@ public class WebApplication implements Serializable {
private String name; private String name;
private String url; private String url;
private String type; private String type;
private Properties properties;
public String getName() { public String getName() {
return name; return name;
@ -60,4 +62,11 @@ public class WebApplication implements Serializable {
return gson.toJson(this); return gson.toJson(this);
} }
public Properties getProperties() {
return properties;
}
public void setProperties(Properties properties) {
this.properties = properties;
}
} }

@ -52,6 +52,7 @@ public class MDMAndroidOperationUtil {
enterpriseApplication.setType(application.getType().toString()); enterpriseApplication.setType(application.getType().toString());
enterpriseApplication.setUrl(application.getLocation()); enterpriseApplication.setUrl(application.getLocation());
enterpriseApplication.setAppIdentifier(application.getIdentifier()); enterpriseApplication.setAppIdentifier(application.getIdentifier());
enterpriseApplication.setProperties(application.getProperties());
operation.setPayLoad(enterpriseApplication.toJSON()); operation.setPayLoad(enterpriseApplication.toJSON());
break; break;
case PUBLIC: case PUBLIC:
@ -59,6 +60,7 @@ public class MDMAndroidOperationUtil {
new AppStoreApplication(); new AppStoreApplication();
appStoreApplication.setType(application.getType().toString()); appStoreApplication.setType(application.getType().toString());
appStoreApplication.setAppIdentifier(application.getIdentifier()); appStoreApplication.setAppIdentifier(application.getIdentifier());
appStoreApplication.setProperties(application.getProperties());
operation.setPayLoad(appStoreApplication.toJSON()); operation.setPayLoad(appStoreApplication.toJSON());
break; break;
case WEBAPP: case WEBAPP:
@ -67,6 +69,7 @@ public class MDMAndroidOperationUtil {
webApplication.setUrl(application.getLocation()); webApplication.setUrl(application.getLocation());
webApplication.setName(application.getName()); webApplication.setName(application.getName());
webApplication.setType(application.getType().toString()); webApplication.setType(application.getType().toString());
webApplication.setProperties(application.getProperties());
operation.setPayLoad(webApplication.toJSON()); operation.setPayLoad(webApplication.toJSON());
break; break;
default: default:
@ -93,6 +96,7 @@ public class MDMAndroidOperationUtil {
new EnterpriseApplication(); new EnterpriseApplication();
enterpriseApplication.setType(application.getType().toString()); enterpriseApplication.setType(application.getType().toString());
enterpriseApplication.setAppIdentifier(application.getIdentifier()); enterpriseApplication.setAppIdentifier(application.getIdentifier());
enterpriseApplication.setProperties(application.getProperties());
operation.setPayLoad(enterpriseApplication.toJSON()); operation.setPayLoad(enterpriseApplication.toJSON());
break; break;
case PUBLIC: case PUBLIC:

Loading…
Cancel
Save