diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml
index 0cbe258eff..e09280720f 100644
--- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml
+++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml
@@ -354,5 +354,10 @@
org.codehaus.jacksonjackson-core-asl
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.apimgt.application.extension
+ provided
+
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/bean/ApiRegistrationProfile.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ApiRegistrationProfile.java
new file mode 100644
index 0000000000..6b14c0d385
--- /dev/null
+++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ApiRegistrationProfile.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2018, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
+ *
+ * Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.carbon.mdm.services.android.bean;
+
+public class ApiRegistrationProfile {
+
+ private String applicationName;
+ private String tags[];
+ private boolean isAllowedToAllDomains;
+ private boolean isMappingAnExistingOAuthApp;
+
+ public String getApplicationName() {
+ return applicationName;
+ }
+
+ public void setApplicationName(String applicationName) {
+ this.applicationName = applicationName;
+ }
+
+ public String[] getTags() {
+ return tags;
+ }
+
+ public void setTags(String[] tags) {
+ this.tags = tags;
+ }
+
+ public boolean isAllowedToAllDomains() {
+ return isAllowedToAllDomains;
+ }
+
+ public void setAllowedToAllDomains(boolean allowedToAllDomains) {
+ isAllowedToAllDomains = allowedToAllDomains;
+ }
+
+ public boolean isMappingAnExistingOAuthApp() {
+ return isMappingAnExistingOAuthApp;
+ }
+
+ public void setMappingAnExistingOAuthApp(boolean mappingAnExistingOAuthApp) {
+ isMappingAnExistingOAuthApp = mappingAnExistingOAuthApp;
+ }
+}
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 9990421f70..0322bd5e05 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
@@ -15,6 +15,22 @@
* specific language governing permissions and limitations
* under the License.
*
+ *
+ * Copyright (c) 2018, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
+ *
+ * Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
package org.wso2.carbon.mdm.services.android.services.impl;
@@ -31,6 +47,8 @@ import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
+import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
+import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException;
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
@@ -263,7 +281,20 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
operation, deviceIdentifiers);
}
PolicyManagerService policyManagerService = AndroidAPIUtils.getPolicyManagerService();
- policyManagerService.getEffectivePolicy(new DeviceIdentifier(androidDevice.getDeviceIdentifier(), device.getType()));
+ Policy effectivePolicy = policyManagerService.
+ getEffectivePolicy(new DeviceIdentifier(androidDevice.getDeviceIdentifier(), device.getType()));
+
+ if (effectivePolicy != null) {
+ List effectiveProfileFeatures = effectivePolicy.getProfile().
+ getProfileFeaturesList();
+ for (ProfileFeature feature : effectiveProfileFeatures) {
+ if (AndroidConstants.ApplicationInstall.ENROLLMENT_APP_INSTALL_FEATURE_CODE
+ .equals(feature.getFeatureCode())) {
+ AndroidDeviceUtils.installEnrollmentApplications(feature, deviceIdentifier.getId());
+ break;
+ }
+ }
+ }
Message responseMessage = new Message();
responseMessage.setResponseCode(Response.Status.OK.toString());
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 d7491c916c..b33c6bb89d 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
@@ -14,6 +14,23 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
+ *
+ *
+ * Copyright (c) 2018, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
+ *
+ * Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
package org.wso2.carbon.mdm.services.android.util;
@@ -139,6 +156,29 @@ public final class AndroidConstants {
public static final String IS_ACTIVE = "isActive";
}
+ public final class ApplicationInstall {
+ private ApplicationInstall() {
+ throw new AssertionError();
+ }
+
+ public static final String APPLICATION_NAME = "device_type_android";
+ public static final String ENROLLMENT_APP_INSTALL_FEATURE_CODE = "ENROLLMENT_APP_INSTALL";
+ 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_CODE = "enrollmentAppInstall";
+ public static final String ENCODING = "UTF-8";
+ public static final String AT = "@";
+ public static final String COLON = ":";
+ 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 AUTHORIZATION = "Authorization";
+ public static final String AUTHORIZATION_HEADER_VALUE = "Bearer ";
+ }
+
public final class ErrorMessages {
private ErrorMessages () { throw new AssertionError(); }
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 ad5f65f8d3..0346f94698 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
@@ -14,6 +14,23 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
+ *
+ *
+ * Copyright (c) 2018, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
+ *
+ * Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
package org.wso2.carbon.mdm.services.android.util;
@@ -24,6 +41,10 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonNull;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.analytics.api.AnalyticsDataAPI;
@@ -32,6 +53,8 @@ import org.wso2.carbon.analytics.dataservice.commons.AnalyticsDataResponse;
import org.wso2.carbon.analytics.dataservice.commons.SearchResultEntry;
import org.wso2.carbon.analytics.datasource.commons.Record;
import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException;
+import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey;
+import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.Device;
@@ -47,17 +70,23 @@ import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
+import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException;
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
import org.wso2.carbon.device.mgt.core.search.mgt.impl.Utils;
+import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
import org.wso2.carbon.mdm.services.android.bean.DeviceState;
import org.wso2.carbon.mdm.services.android.bean.ErrorListItem;
import org.wso2.carbon.mdm.services.android.bean.ErrorResponse;
import org.wso2.carbon.mdm.services.android.exception.BadRequestException;
+import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
+import org.wso2.carbon.user.api.UserStoreException;
import javax.validation.ConstraintViolation;
+import javax.ws.rs.core.MediaType;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -460,4 +489,54 @@ public class AndroidDeviceUtils {
return errorResponse;
}
+ public static void installEnrollmentApplications(ProfileFeature feature, String deviceId)
+ throws PolicyManagementException {
+ String appId = "";
+ String payload;
+ StringRequestEntity requestEntity;
+ HttpClient httpClient;
+ PostMethod request;
+ try {
+ String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
+ ApiApplicationKey apiApplicationKey = OAuthUtils.getClientCredentials(tenantDomain);
+ String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm()
+ .getRealmConfiguration().getAdminUserName() + AndroidConstants.ApplicationInstall.AT + tenantDomain;
+ AccessTokenInfo tokenInfo = OAuthUtils.getOAuthCredentials(apiApplicationKey, username);
+ String requestUrl = AndroidConstants.ApplicationInstall.ENROLLMENT_APP_INSTALL_PROTOCOL +
+ System.getProperty(AndroidConstants.ApplicationInstall.IOT_CORE_HOST) +
+ AndroidConstants.ApplicationInstall.COLON +
+ System.getProperty(AndroidConstants.ApplicationInstall.IOT_CORE_PORT) +
+ AndroidConstants.ApplicationInstall.ENROLLMENT_APP_INSTALL_CONTEXT;
+ JsonElement appListElement = new JsonParser().parse(feature.getContent().toString()).getAsJsonObject()
+ .get(AndroidConstants.ApplicationInstall.ENROLLMENT_APP_INSTALL_CODE);
+ 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);
+ httpClient = new HttpClient();
+ request = new PostMethod(requestUrl);
+ 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);
+ } catch (APIManagerException e) {
+ throw new PolicyManagementException("Error while retrieving access token for Android device id: " +
+ deviceId, 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);
+ } catch (IOException e) {
+ throw new PolicyManagementException("Error while installing the enrollment app with id: " + appId +
+ " on device with id: " + deviceId, e);
+ }
+ }
+
}
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/OAuthUtils.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/OAuthUtils.java
new file mode 100644
index 0000000000..53e0832c39
--- /dev/null
+++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/OAuthUtils.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2018, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
+ *
+ * Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.carbon.mdm.services.android.util;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService;
+import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey;
+import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException;
+import org.wso2.carbon.context.PrivilegedCarbonContext;
+import org.wso2.carbon.mdm.services.android.bean.ApiRegistrationProfile;
+import org.wso2.carbon.identity.jwt.client.extension.JWTClient;
+import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
+import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
+import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService;
+import org.wso2.carbon.user.api.UserStoreException;
+import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
+
+public class OAuthUtils {
+
+ private static final Log log = LogFactory.getLog(OAuthUtils.class);
+
+ public static ApiApplicationKey getClientCredentials(String tenantDomain)
+ throws UserStoreException, APIManagerException {
+ ApiRegistrationProfile registrationProfile = new ApiRegistrationProfile();
+ registrationProfile.setApplicationName(AndroidConstants.ApplicationInstall.APPLICATION_NAME);
+ registrationProfile.setTags(new String[]{AndroidConstants.DEVICE_TYPE_ANDROID});
+ registrationProfile.setAllowedToAllDomains(false);
+ registrationProfile.setMappingAnExistingOAuthApp(false);
+ return getCredentials(registrationProfile, tenantDomain);
+ }
+
+ public static ApiApplicationKey getCredentials(ApiRegistrationProfile registrationProfile, String tenantDomain)
+ throws UserStoreException, APIManagerException {
+ ApiApplicationKey apiApplicationKeyInfo;
+ if (tenantDomain == null || tenantDomain.isEmpty()) {
+ tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
+ }
+ try {
+ PrivilegedCarbonContext.startTenantFlow();
+ PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
+ PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(PrivilegedCarbonContext.
+ getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration().getAdminUserName());
+ PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
+ APIManagementProviderService apiManagementProviderService = (APIManagementProviderService) ctx.
+ getOSGiService(APIManagementProviderService.class, null);
+ apiApplicationKeyInfo = apiManagementProviderService.
+ generateAndRetrieveApplicationKeys(registrationProfile.getApplicationName(),
+ registrationProfile.getTags(), AndroidConstants.ApplicationInstall.DEFAULT_TOKEN_TYPE,
+ registrationProfile.getApplicationName(), registrationProfile.isAllowedToAllDomains(),
+ AndroidConstants.ApplicationInstall.DEFAULT_VALIDITY_PERIOD);
+ } finally {
+ PrivilegedCarbonContext.endTenantFlow();
+ }
+ return apiApplicationKeyInfo;
+ }
+
+ public static AccessTokenInfo getOAuthCredentials(ApiApplicationKey apiApplicationKey, String username)
+ throws APIManagerException {
+ try {
+ PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
+ JWTClientManagerService jwtClientManagerService = (JWTClientManagerService) ctx.
+ getOSGiService(JWTClientManagerService.class, null);
+ JWTClient jwtClient = jwtClientManagerService.getJWTClient();
+ return jwtClient.getAccessToken(apiApplicationKey.getConsumerKey(), apiApplicationKey.getConsumerSecret(),
+ username, AndroidConstants.ApplicationInstall.SUBSCRIPTION_SCOPE);
+ } catch (JWTClientException e) {
+ String errorMsg = "Error while generating an OAuth token for user " + username;
+ log.error(errorMsg, e);
+ throw new APIManagerException(errorMsg, 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.operation-mod/public/js/operation-mod.js 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.operation-mod/public/js/operation-mod.js
index c8a9ce6ee6..4b510a3040 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.operation-mod/public/js/operation-mod.js
+++ 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.operation-mod/public/js/operation-mod.js
@@ -14,6 +14,23 @@
* either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
+ *
+ *
+ * Copyright (c) 2018, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
+ *
+ * Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
var androidOperationModule = function () {
@@ -79,7 +96,9 @@ var androidOperationModule = function () {
"RUNTIME_PERMISSION_POLICY_OPERATION": "runtime-permission-policy",
"RUNTIME_PERMISSION_POLICY_OPERATION_CODE": "RUNTIME_PERMISSION_POLICY",
"COSU_PROFILE_CONFIGURATION_OPERATION": "cosu-profile-configuration",
- "COSU_PROFILE_CONFIGURATION_OPERATION_CODE": "COSU_PROFILE"
+ "COSU_PROFILE_CONFIGURATION_OPERATION_CODE": "COSU_PROFILE",
+ "ENROLLMENT_APP_INSTALL": "enrollment-app-install",
+ "ENROLLMENT_APP_INSTALL_CODE": "ENROLLMENT_APP_INSTALL"
};
/**
@@ -177,6 +196,11 @@ var androidOperationModule = function () {
"cosuWhitelistedApplications": operationPayload["whitelistedApplications"]
};
break;
+ case androidOperationConstants["ENROLLMENT_APP_INSTALL_CODE"]:
+ payload = {
+ "enrollmentAppInstall": operationPayload["enrollmentAppInstall"]
+ };
+ break;
}
return payload;
};
@@ -384,6 +408,14 @@ var androidOperationModule = function () {
}
};
break;
+ case androidOperationConstants["ENROLLMENT_APP_INSTALL_CODE"]:
+ operationType = operationTypeConstants["PROFILE"];
+ payload = {
+ "operation": {
+ "enrollmentAppInstall": operationData["enrollmentAppInstall"]
+ }
+ };
+ break;
default:
// If the operation is neither of above, it is a command operation
operationType = operationTypeConstants["COMMAND"];
@@ -708,34 +740,56 @@ var androidOperationModule = function () {
} else if (operationDataObj.hasClass("multi-column-key-value-pair-array")) {
// generating input fields to populate complex value
if (value) {
- for (i = 0; i < value.length; ++i) {
- operationDataObj.parent().find("a").filterByData("click-event", "add-form").click();
- }
- columnCount = operationDataObj.data("column-count");
- var multiColumnKeyValuePairArrayIndex = 0;
- // traversing through each child input
- $(".child-input", this).each(function () {
- childInput = $(this);
- var multiColumnKeyValuePair = value[multiColumnKeyValuePairArrayIndex];
- var childInputKey = childInput.data("child-key");
- var childInputValue = multiColumnKeyValuePair[childInputKey];
- // populating extracted value in the UI according to the input type
- if (childInput.is(":text") ||
- childInput.is("textarea") ||
- childInput.is(":password") ||
- childInput.is("input[type=hidden]") ||
- childInput.is("select")) {
- childInput.val(childInputValue);
- } else if (childInput.is(":checkbox")) {
- operationDataObj.prop("checked", childInputValue);
+ if (operationDataObj.hasClass("specific-enrollment-app-install")) {
+ if ($(".enrollment-app-install-input", this).length > 0) {
+ for (i=0; i
'
+ + value[i].version + '
';
+ $('[data-add-form-container="#enrollment-app-install-grid"]').append(content);
+ }
}
- // incrementing multiColumnKeyValuePairArrayIndex for the next row of inputs
- if ((childInputIndex % columnCount) == (columnCount - 1)) {
- multiColumnKeyValuePairArrayIndex++;
+ } else {
+ for (i = 0; i < value.length; ++i) {
+ operationDataObj.parent().find("a").filterByData("click-event", "add-form").click();
}
- // incrementing childInputIndex
- childInputIndex++;
- });
+ columnCount = operationDataObj.data("column-count");
+ var multiColumnKeyValuePairArrayIndex = 0;
+ // traversing through each child input
+ $(".child-input", this).each(function () {
+ childInput = $(this);
+ var multiColumnKeyValuePair = value[multiColumnKeyValuePairArrayIndex];
+ var childInputKey = childInput.data("child-key");
+ var childInputValue = multiColumnKeyValuePair[childInputKey];
+ // populating extracted value in the UI according to the input type
+ if (childInput.is(":text") ||
+ childInput.is("textarea") ||
+ childInput.is(":password") ||
+ childInput.is("input[type=hidden]") ||
+ childInput.is("select")) {
+ childInput.val(childInputValue);
+ } else if (childInput.is(":checkbox")) {
+ operationDataObj.prop("checked", childInputValue);
+ }
+ // incrementing multiColumnKeyValuePairArrayIndex for the next row of inputs
+ if ((childInputIndex % columnCount) == (columnCount - 1)) {
+ multiColumnKeyValuePairArrayIndex++;
+ }
+ // incrementing childInputIndex
+ childInputIndex++;
+ });
+ }
}
}
}
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/js/android-policy-edit.js 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/js/android-policy-edit.js
index c18f204d7c..cc151761f9 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/js/android-policy-edit.js
+++ 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/js/android-policy-edit.js
@@ -14,6 +14,23 @@
* either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
+ *
+ *
+ * Copyright (c) 2018, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
+ *
+ * Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
var configuredOperations = [];
@@ -37,7 +54,9 @@ var androidOperationConstants = {
"RUNTIME_PERMISSION_POLICY_OPERATION_CODE": "RUNTIME_PERMISSION_POLICY",
"RUNTIME_PERMISSION_POLICY_OPERATION": "runtime-permission-policy",
"COSU_PROFILE_CONFIGURATION_OPERATION": "cosu-profile-configuration",
- "COSU_PROFILE_CONFIGURATION_OPERATION_CODE": "COSU_PROFILE"
+ "COSU_PROFILE_CONFIGURATION_OPERATION_CODE": "COSU_PROFILE",
+ "ENROLLMENT_APP_INSTALL": "enrollment-app-install",
+ "ENROLLMENT_APP_INSTALL_CODE": "ENROLLMENT_APP_INSTALL"
};
/**
@@ -537,6 +556,24 @@ var validatePolicyProfile = function () {
// Updating validationStatusArray with validationStatus
validationStatusArray.push(validationStatus);
}
+ if ($.inArray(androidOperationConstants["ENROLLMENT_APP_INSTALL_CODE"], configuredOperations) != -1) {
+ //If enrollment app install configured
+ operation = androidOperationConstants["ENROLLMENT_APP_INSTALL"];
+ var enrollmentAppInstallAppList = "div#install-app-enrollment .child-input";
+ if($(enrollmentAppInstallAppList).length == 0) {
+ validationStatus = {
+ "error": true,
+ "subErrorMsg": "Applications are not selected to be installed during device enrollment.",
+ "erroneousFeature": operation
+ };
+ } else {
+ validationStatus = {
+ "error": false,
+ "okFeature": operation
+ };
+ }
+ validationStatusArray.push(validationStatus);
+ }
}
// ending validation process
@@ -771,6 +808,13 @@ var showHideHelpText = function (addFormContainer) {
}
};
+var applyDataTable = function() {
+ $("#enrollment-app-install-table").datatables_extended({
+ ordering: false,
+ lengthMenu: [5, 10, 25, 50, 100]
+ });
+};
+
$(document).ready(function () {
// Maintains an array of configured features of the profile
var advanceOperations = ".wr-advance-operations";
@@ -945,4 +989,22 @@ $(document).ready(function () {
setId(addFormContainer);
showHideHelpText(addFormContainer);
});
+
+ // add app entry for enrollment-app-install
+ $(advanceOperations).on("click", "[data-click-event=add-enrollment-app]", function () {
+ $(this).attr("hidden", true);
+ $(this).siblings("a").removeAttr("hidden");
+ $(this).parent().parent().find("input").each(function () {
+ $(this).addClass("child-input");
+ });
+ });
+
+ // remove app entry for enrollment-app-install
+ $(advanceOperations).on("click", "[data-click-event=remove-enrollment-app]", function () {
+ $(this).attr("hidden", true);
+ $(this).siblings("a").removeAttr("hidden");
+ $(this).parent().parent().find("input").each(function () {
+ $(this).removeClass("child-input");
+ });
+ });
});
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 58f1b9fcb4..82f09727be 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
@@ -132,6 +132,16 @@
class="fw fw-error">
{{/unless}}
+
+
+
+
+ Enrollment Application Install
+
+
+
+
@@ -1799,5 +1809,90 @@
+
+
+
+
+
+ Enrollment Application Install
+
+
+
+ This configuration can be used to install applications during Android device enrollment.
+
+
+ This configuration will be applied only during Android device enrollment.
+
+ This configuration can be used to install applications during Android device enrollment.
+
+
+ This configuration will be applied only during Android device enrollment.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Application Name
+
Version
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
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/js/android-policy-operations.js 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/js/android-policy-operations.js
index b6e08e785e..fa185f050c 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/js/android-policy-operations.js
+++ 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/js/android-policy-operations.js
@@ -14,6 +14,23 @@
* either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
+ *
+ *
+ * Copyright (c) 2018, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
+ *
+ * Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
var configuredOperations = [];
@@ -32,7 +49,9 @@ var androidOperationConstants = {
"APPLICATION_OPERATION": "app-restriction",
"APPLICATION_OPERATION_CODE": "APP-RESTRICTION",
"KIOSK_APPS_CODE": "KIOSK_APPS",
- "KIOSK_APPS": "cosu-whitelisted-applications"
+ "KIOSK_APPS": "cosu-whitelisted-applications",
+ "ENROLLMENT_APP_INSTALL": "enrollment-app-install",
+ "ENROLLMENT_APP_INSTALL_CODE": "ENROLLMENT_APP_INSTALL"
};
/**
@@ -456,6 +475,24 @@ var validatePolicyProfile = function () {
// Updating validationStatusArray with validationStatus
validationStatusArray.push(validationStatus);
}
+ if ($.inArray(androidOperationConstants["ENROLLMENT_APP_INSTALL_CODE"], configuredOperations) != -1) {
+ //If enrollment app install configured
+ operation = androidOperationConstants["ENROLLMENT_APP_INSTALL"];
+ var enrollmentAppInstallAppList = "div#install-app-enrollment .child-input";
+ if($(enrollmentAppInstallAppList).length == 0) {
+ validationStatus = {
+ "error": true,
+ "subErrorMsg": "Applications are not selected to be installed during device enrollment.",
+ "erroneousFeature": operation
+ };
+ } else {
+ validationStatus = {
+ "error": false,
+ "okFeature": operation
+ };
+ }
+ validationStatusArray.push(validationStatus);
+ }
}
// ending validation process
@@ -733,6 +770,13 @@ var showHideHelpText = function (addFormContainer) {
}
};
+var applyDataTable = function() {
+ $("#enrollment-app-install-table").datatables_extended({
+ ordering: false,
+ lengthMenu: [5, 10, 25, 50, 100]
+ });
+};
+
$(document).ready(function () {
// Maintains an array of configured features of the profile
var advanceOperations = ".wr-advance-operations";
@@ -907,4 +951,22 @@ $(document).ready(function () {
setId(addFormContainer);
showHideHelpText(addFormContainer);
});
+
+ // add app entry for enrollment-app-install
+ $(advanceOperations).on("click", "[data-click-event=add-enrollment-app]", function () {
+ $(this).attr("hidden", true);
+ $(this).siblings("a").removeAttr("hidden");
+ $(this).parent().parent().find("input").each(function () {
+ $(this).addClass("child-input");
+ });
+ });
+
+ // remove app entry for enrollment-app-install
+ $(advanceOperations).on("click", "[data-click-event=remove-enrollment-app]", function () {
+ $(this).attr("hidden", true);
+ $(this).siblings("a").removeAttr("hidden");
+ $(this).parent().parent().find("input").each(function () {
+ $(this).removeClass("child-input");
+ });
+ });
});
\ No newline at end of file
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 ed561045a4..5632744c41 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
@@ -140,6 +140,16 @@
class="fw fw-error">
{{/unless}}
+
+
+
+
+ Enrollment Application Install
+
+
+
+
@@ -1827,5 +1837,91 @@
+
+
+
+
+
+
+ Enrollment Application Install
+
+
+
+ Enforce applications to be installed during Android device enrollment.
+
+
+ This configuration will be applied only during Android device enrollment.
+