From 51f74d77449c68d152f1e126cf768f08de1515ae Mon Sep 17 00:00:00 2001 From: Saad Sahibjan Date: Thu, 29 Aug 2019 13:13:27 +0530 Subject: [PATCH] Modify enrollment app install android policy to support new app manager --- .../impl/DeviceManagementServiceImpl.java | 2 +- .../android/util/AndroidConstants.java | 4 +- .../android/util/AndroidDeviceUtils.java | 48 +++++++++++-------- .../public/templates/android-policy-edit.hbs | 2 +- .../templates/android-policy-operations.hbs | 2 +- 5 files changed, 32 insertions(+), 26 deletions(-) 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 839c86463..568d5e5fd 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 @@ -291,7 +291,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { for (ProfileFeature feature : effectiveProfileFeatures) { if (AndroidConstants.ApplicationInstall.ENROLLMENT_APP_INSTALL_FEATURE_CODE .equals(feature.getFeatureCode())) { - AndroidDeviceUtils.installEnrollmentApplications(feature, deviceIdentifier.getId()); + AndroidDeviceUtils.installEnrollmentApplications(feature, deviceIdentifier); break; } } 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 42712d987..b72367ddc 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 @@ -187,7 +187,7 @@ public final class AndroidConstants { public static final String DEFAULT_TOKEN_TYPE = "PRODUCTION"; public static final String DEFAULT_VALIDITY_PERIOD = "3600"; public static final String SUBSCRIPTION_SCOPE = "appm:subscribe"; - public static final String ENROLLMENT_APP_INSTALL_ID = "appId"; + public static final String ENROLLMENT_APP_INSTALL_UUID = "uuid"; public static final String ENROLLMENT_APP_INSTALL_CODE = "enrollmentAppInstall"; public static final String ENCODING = "UTF-8"; public static final String AT = "@"; @@ -195,7 +195,7 @@ public final class AndroidConstants { public static final String IOT_CORE_HOST = "iot.core.host"; public static final String IOT_CORE_PORT = "iot.core.https.port"; public static final String ENROLLMENT_APP_INSTALL_PROTOCOL = "https://"; - public static final String ENROLLMENT_APP_INSTALL_CONTEXT = "/api/appm/store/v1.1/apps/mobile/schedule-install"; + public static final String ENROLLMENT_APP_INSTALL_URL = "/api/application-mgt-store/v1.0/subscription/{uuid}/devices/install"; public static final String AUTHORIZATION = "Authorization"; public static final String AUTHORIZATION_HEADER_VALUE = "Bearer "; } 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 91dd56640..9bf0c2f94 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 @@ -559,11 +559,9 @@ public class AndroidDeviceUtils { return errorResponse; } - public static void installEnrollmentApplications(ProfileFeature feature, String deviceId) + public static void installEnrollmentApplications(ProfileFeature feature, DeviceIdentifier deviceIdentifier) throws PolicyManagementException { - String appId = ""; - String payload; - StringRequestEntity requestEntity; + String uuid = ""; HttpClient httpClient; PostMethod request; try { @@ -576,36 +574,44 @@ public class AndroidDeviceUtils { System.getProperty(AndroidConstants.ApplicationInstall.IOT_CORE_HOST) + AndroidConstants.ApplicationInstall.COLON + System.getProperty(AndroidConstants.ApplicationInstall.IOT_CORE_PORT) + - AndroidConstants.ApplicationInstall.ENROLLMENT_APP_INSTALL_CONTEXT; + AndroidConstants.ApplicationInstall.ENROLLMENT_APP_INSTALL_URL; JsonElement appListElement = new JsonParser().parse(feature.getContent().toString()).getAsJsonObject() .get(AndroidConstants.ApplicationInstall.ENROLLMENT_APP_INSTALL_CODE); + String payload = "[{\"id\":\"" + deviceIdentifier.getId() + "\", \"type\":\"" + + deviceIdentifier.getType() + "\"}]"; + StringRequestEntity requestEntity = new StringRequestEntity(payload, MediaType.APPLICATION_JSON + , AndroidConstants.ApplicationInstall.ENCODING); JsonArray appListArray = appListElement.getAsJsonArray(); for (JsonElement appElement : appListArray) { - appId = appElement.getAsJsonObject(). - get(AndroidConstants.ApplicationInstall.ENROLLMENT_APP_INSTALL_ID).getAsString(); - payload = "{\"appId\": \"" + appId + "\", \"scheduleTime\":\"2013-12-25T15:25:30-05:00\"," + - "\"deviceIds\": [\"{\\\"id\\\":\\\"" + deviceId + "\\\", \\\"type\\\":\\\"android\\\"}\"]}"; - requestEntity = new StringRequestEntity(payload, MediaType.APPLICATION_JSON, - AndroidConstants.ApplicationInstall.ENCODING); + uuid = appElement.getAsJsonObject(). + get(AndroidConstants.ApplicationInstall.ENROLLMENT_APP_INSTALL_UUID).getAsString(); + requestUrl = requestUrl.replace("{uuid}", uuid); httpClient = new HttpClient(); request = new PostMethod(requestUrl); - request.addRequestHeader(AndroidConstants.ApplicationInstall.AUTHORIZATION, - AndroidConstants.ApplicationInstall.AUTHORIZATION_HEADER_VALUE + tokenInfo.getAccessToken()); + request.addRequestHeader(AndroidConstants.ApplicationInstall.AUTHORIZATION + , AndroidConstants.ApplicationInstall.AUTHORIZATION_HEADER_VALUE + tokenInfo.getAccessToken()); request.setRequestEntity(requestEntity); httpClient.executeMethod(request); } } catch (UserStoreException e) { - throw new PolicyManagementException("Error while accessing user store for user with iOS device id: " + - deviceId, e); + String msg = "Error while accessing user store for user with Android device id: " + + deviceIdentifier.getId(); + log.error(msg, e); + throw new PolicyManagementException(msg, e); } catch (APIManagerException e) { - throw new PolicyManagementException("Error while retrieving access token for Android device id: " + - deviceId, e); + String msg = "Error while retrieving access token for Android device id: " + deviceIdentifier.getId(); + log.error(msg, e); + throw new PolicyManagementException(msg, e); } catch (HttpException e) { - throw new PolicyManagementException("Error while calling the app store to install enrollment app with " + - "id: " + appId + " on device with id: " + deviceId, e); + String msg = "Error while calling the app store to install enrollment app with uuid: " + uuid + + " on device with id: " + deviceIdentifier.getId(); + log.error(msg, e); + throw new PolicyManagementException(msg, e); } catch (IOException e) { - throw new PolicyManagementException("Error while installing the enrollment app with id: " + appId + - " on device with id: " + deviceId, e); + String msg = "Error while installing the enrollment with uuid: " + uuid + " on device with id: " + + deviceIdentifier.getId(); + log.error(msg, e); + throw new PolicyManagementException(msg, e); } } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-edit/public/templates/android-policy-edit.hbs b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-edit/public/templates/android-policy-edit.hbs index 319f06510..69e30efc1 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-edit/public/templates/android-policy-edit.hbs +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-edit/public/templates/android-policy-edit.hbs @@ -2999,7 +2999,7 @@ - + diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-wizard/public/templates/android-policy-operations.hbs b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-wizard/public/templates/android-policy-operations.hbs index 9ffd23e9a..42a02561f 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-wizard/public/templates/android-policy-operations.hbs +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-wizard/public/templates/android-policy-operations.hbs @@ -3020,7 +3020,7 @@ - +