|
|
@ -321,21 +321,27 @@ 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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (googlePolicyPayload != null) {
|
|
|
|
if (googlePolicyPayload != null) {
|
|
|
|
String uuid = appElement.getAsJsonObject().get("uuid").toString();
|
|
|
|
String uuid = appElement.getAsJsonObject().get("uuid").toString();
|
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -349,8 +355,10 @@ public class AndroidDeviceUtils {
|
|
|
|
* Sends the app install policy to Google
|
|
|
|
* Sends the app install policy to Google
|
|
|
|
* @param payload policy profile
|
|
|
|
* @param payload policy profile
|
|
|
|
* @param deviceIdentifier device to apply policy
|
|
|
|
* @param deviceIdentifier device to apply policy
|
|
|
|
|
|
|
|
* @param requireSendingToGoogle
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private static void sendPayloadToGoogle(String uuid, String payload, DeviceIdentifier deviceIdentifier)
|
|
|
|
private static void sendPayloadToGoogle(String uuid, String payload, DeviceIdentifier deviceIdentifier,
|
|
|
|
|
|
|
|
boolean requireSendingToGoogle)
|
|
|
|
throws org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException {
|
|
|
|
throws org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigsFromGoogle();
|
|
|
|
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigsFromGoogle();
|
|
|
@ -370,10 +378,12 @@ public class AndroidDeviceUtils {
|
|
|
|
for (EnterpriseApp enterpriseApp : enterpriseInstallPolicy.getApps()) {
|
|
|
|
for (EnterpriseApp enterpriseApp : enterpriseInstallPolicy.getApps()) {
|
|
|
|
apps.add(enterpriseApp.getProductId());
|
|
|
|
apps.add(enterpriseApp.getProductId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (requireSendingToGoogle) {
|
|
|
|
googleAPIInvoker.approveAppsForUser(enterpriseConfigs.getEnterpriseId(), userDetail
|
|
|
|
googleAPIInvoker.approveAppsForUser(enterpriseConfigs.getEnterpriseId(), userDetail
|
|
|
|
.getGoogleUserId(), apps, enterpriseInstallPolicy.getProductSetBehavior());
|
|
|
|
.getGoogleUserId(), apps, enterpriseInstallPolicy.getProductSetBehavior());
|
|
|
|
googleAPIInvoker.updateAppsForUser(enterpriseConfigs.getEnterpriseId(), userDetail.getGoogleUserId(),
|
|
|
|
googleAPIInvoker.updateAppsForUser(enterpriseConfigs.getEnterpriseId(), userDetail.getGoogleUserId(),
|
|
|
|
AndroidEnterpriseUtils.convertToDeviceInstance(enterpriseInstallPolicy));
|
|
|
|
AndroidEnterpriseUtils.convertToDeviceInstance(enterpriseInstallPolicy));
|
|
|
|
|
|
|
|
}
|
|
|
|
AndroidEnterpriseUtils.getAppSubscriptionService()
|
|
|
|
AndroidEnterpriseUtils.getAppSubscriptionService()
|
|
|
|
.performEntAppSubscription(uuid,
|
|
|
|
.performEntAppSubscription(uuid,
|
|
|
|
Arrays.asList(CarbonContext.getThreadLocalCarbonContext().getUsername()),
|
|
|
|
Arrays.asList(CarbonContext.getThreadLocalCarbonContext().getUsername()),
|
|
|
@ -698,6 +708,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()) {
|
|
|
@ -709,6 +723,7 @@ public class AndroidDeviceUtils {
|
|
|
|
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: " +
|
|
|
|
deviceIdentifier.getId();
|
|
|
|
deviceIdentifier.getId();
|
|
|
|