|
|
@ -323,6 +323,7 @@ public class AndroidDeviceUtils {
|
|
|
|
JsonArray appListArray = appListElement.getAsJsonArray();
|
|
|
|
JsonArray appListArray = appListElement.getAsJsonArray();
|
|
|
|
|
|
|
|
|
|
|
|
// Find if there are Apps with Work profile configurations
|
|
|
|
// Find if there are Apps with Work profile configurations
|
|
|
|
|
|
|
|
boolean alreadySendToGoogle = false;
|
|
|
|
for (JsonElement appElement : appListArray) {
|
|
|
|
for (JsonElement appElement : appListArray) {
|
|
|
|
JsonElement googlePolicyPayload = appElement.getAsJsonObject().
|
|
|
|
JsonElement googlePolicyPayload = appElement.getAsJsonObject().
|
|
|
|
get(AndroidConstants.ApplicationInstall.GOOGLE_POLICY_PAYLOAD);
|
|
|
|
get(AndroidConstants.ApplicationInstall.GOOGLE_POLICY_PAYLOAD);
|
|
|
@ -332,12 +333,16 @@ public class AndroidDeviceUtils {
|
|
|
|
containsGoogleAppPolicy = true;// breaking out of outer for loop
|
|
|
|
containsGoogleAppPolicy = true;// breaking out of outer for loop
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
uuid = uuid.replace("\"", "");
|
|
|
|
uuid = uuid.replace("\"", "");
|
|
|
|
sendPayloadToGoogle(uuid, payload, deviceIdentifier);
|
|
|
|
if (alreadySendToGoogle) {
|
|
|
|
|
|
|
|
sendPayloadToGoogle(uuid, payload, deviceIdentifier, false);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
sendPayloadToGoogle(uuid, payload, deviceIdentifier, true);
|
|
|
|
|
|
|
|
alreadySendToGoogle = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch (org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException e) {
|
|
|
|
} catch (org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException e) {
|
|
|
|
String errorMessage = "App install failed for device " + deviceIdentifier.getId();
|
|
|
|
String errorMessage = "App install failed for device " + deviceIdentifier.getId();
|
|
|
|
log.error(errorMessage, e);
|
|
|
|
log.error(errorMessage, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -352,8 +357,8 @@ public class AndroidDeviceUtils {
|
|
|
|
* @param payload policy profile
|
|
|
|
* @param payload policy profile
|
|
|
|
* @param deviceIdentifier device to apply policy
|
|
|
|
* @param deviceIdentifier device to apply policy
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private static void sendPayloadToGoogle(String uuid, String payload, DeviceIdentifier deviceIdentifier)
|
|
|
|
private static void sendPayloadToGoogle(String uuid, String payload, DeviceIdentifier deviceIdentifier,
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
boolean requireSendingToGoogle) throws ApplicationManagementException {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigsFromGoogle();
|
|
|
|
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigsFromGoogle();
|
|
|
|
if (enterpriseConfigs.getErrorResponse() == null) {
|
|
|
|
if (enterpriseConfigs.getErrorResponse() == null) {
|
|
|
@ -369,12 +374,12 @@ public class AndroidDeviceUtils {
|
|
|
|
for (EnterpriseApp enterpriseApp : enterpriseInstallPolicy.getApps()) {
|
|
|
|
for (EnterpriseApp enterpriseApp : enterpriseInstallPolicy.getApps()) {
|
|
|
|
apps.add(enterpriseApp.getProductId());
|
|
|
|
apps.add(enterpriseApp.getProductId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
googleAPIInvoker
|
|
|
|
if (requireSendingToGoogle) {
|
|
|
|
.approveAppsForUser(enterpriseConfigs.getEnterpriseId(), userDetail.getGoogleUserId(), apps,
|
|
|
|
googleAPIInvoker.approveAppsForUser(enterpriseConfigs.getEnterpriseId(), userDetail
|
|
|
|
enterpriseInstallPolicy.getProductSetBehavior());
|
|
|
|
.getGoogleUserId(), apps, enterpriseInstallPolicy.getProductSetBehavior());
|
|
|
|
googleAPIInvoker
|
|
|
|
googleAPIInvoker.updateAppsForUser(enterpriseConfigs.getEnterpriseId(), userDetail.getGoogleUserId(),
|
|
|
|
.updateAppsForUser(enterpriseConfigs.getEnterpriseId(), userDetail.getGoogleUserId(),
|
|
|
|
|
|
|
|
AndroidEnterpriseUtils.convertToDeviceInstance(enterpriseInstallPolicy));
|
|
|
|
AndroidEnterpriseUtils.convertToDeviceInstance(enterpriseInstallPolicy));
|
|
|
|
|
|
|
|
}
|
|
|
|
AndroidEnterpriseUtils.getAppSubscriptionService().performEntAppSubscription(uuid,
|
|
|
|
AndroidEnterpriseUtils.getAppSubscriptionService().performEntAppSubscription(uuid,
|
|
|
|
Arrays.asList(CarbonContext.getThreadLocalCarbonContext().getUsername()),
|
|
|
|
Arrays.asList(CarbonContext.getThreadLocalCarbonContext().getUsername()),
|
|
|
|
SubscriptionType.USER.toString(), SubAction.INSTALL.toString(), false);
|
|
|
|
SubscriptionType.USER.toString(), SubAction.INSTALL.toString(), false);
|
|
|
@ -697,6 +702,10 @@ public class AndroidDeviceUtils {
|
|
|
|
StringEntity requestEntity = new StringEntity(payload.toString(), ContentType.APPLICATION_JSON);
|
|
|
|
StringEntity requestEntity = new StringEntity(payload.toString(), ContentType.APPLICATION_JSON);
|
|
|
|
JsonArray appListArray = appListElement.getAsJsonArray();
|
|
|
|
JsonArray appListArray = appListElement.getAsJsonArray();
|
|
|
|
for (JsonElement appElement : appListArray) {
|
|
|
|
for (JsonElement appElement : appListArray) {
|
|
|
|
|
|
|
|
JsonElement googlePolicyPayload = appElement.getAsJsonObject().
|
|
|
|
|
|
|
|
get(AndroidConstants.ApplicationInstall.GOOGLE_POLICY_PAYLOAD);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (googlePolicyPayload == null) {
|
|
|
|
uuid = appElement.getAsJsonObject().
|
|
|
|
uuid = appElement.getAsJsonObject().
|
|
|
|
get(AndroidConstants.ApplicationInstall.ENROLLMENT_APP_INSTALL_UUID).getAsString();
|
|
|
|
get(AndroidConstants.ApplicationInstall.ENROLLMENT_APP_INSTALL_UUID).getAsString();
|
|
|
|
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
|
|
|
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
|
|
@ -707,6 +716,8 @@ public class AndroidDeviceUtils {
|
|
|
|
postRequest.setEntity(requestEntity);
|
|
|
|
postRequest.setEntity(requestEntity);
|
|
|
|
httpClient.execute(postRequest);
|
|
|
|
httpClient.execute(postRequest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
String msg = "Error while accessing user store for user with Android device id: " +
|
|
|
|
String msg = "Error while accessing user store for user with Android device id: " +
|
|
|
|