Modify enrollment app install android policy to support new app manager

revert-dabc3590
Saad Sahibjan 5 years ago
parent b83c8806af
commit 51f74d7744

@ -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;
}
}

@ -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 ";
}

@ -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);
}
}

@ -2999,7 +2999,7 @@
<input class="enrollment-app-install-input" type="hidden" data-child-key="version" value="{{this.version}}"/>
</td>
<td data-title="enrollment-app-install-app-selection">
<input class="enrollment-app-install-input" type="hidden" data-child-key="packageName" value="{{this.packageName}}"/>
<input class="enrollment-app-install-input" type="hidden" data-child-key="uuid" value="{{this.uuid}}"/>
<input class="enrollment-app-install-input" type="hidden" data-child-key="appId" value="{{this.appId}}"/>
<a href="#enrollment-app-install-grid" data-click-event="add-enrollment-app">
<span>

@ -3020,7 +3020,7 @@
<input class="enrollment-app-install-input" type="hidden" data-child-key="version" value="{{this.version}}"/>
</td>
<td data-title="enrollment-app-install-app-selection">
<input class="enrollment-app-install-input" type="hidden" data-child-key="packageName" value="{{this.packageName}}"/>
<input class="enrollment-app-install-input" type="hidden" data-child-key="uuid" value="{{this.uuid}}"/>
<input class="enrollment-app-install-input" type="hidden" data-child-key="appId" value="{{this.appId}}"/>
<a href="#enrollment-app-install-grid" data-click-event="add-enrollment-app">
<span>

Loading…
Cancel
Save