diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/mdm/integration/common/Constants.java b/modules/integration/tests-integration/src/test/java/org/wso2/mdm/integration/common/Constants.java
index ed4bf73c0..543f52c38 100644
--- a/modules/integration/tests-integration/src/test/java/org/wso2/mdm/integration/common/Constants.java
+++ b/modules/integration/tests-integration/src/test/java/org/wso2/mdm/integration/common/Constants.java
@@ -289,8 +289,12 @@ public static final class RoleManagement {
public static final String ROLE_NAME = "administration";
public static final String UPDATED_ROLE_NAME = "manager";
public static final String ROLE_ENDPOINT = "/api/device-mgt/v1.0/roles";
+ public static final String ROLE_ENDPOINT_WITH_PAGINATION
+ = "/api/device-mgt/v1.0/roles?offset=0&limit=2";
public static final String SCOPE_ROLE_ENDPOINT = "/api/device-mgt/v1.0/roles/scopes";
public static final String ROLE_PAYLOAD_FILE_NAME = "role-payloads.json";
+ public static final String ROLE_RESPONSE_PAYLOAD
+ = "[{\"key\":\"role:view\",\"name\":\"View roles\",\"roles\":\"admin,manager\",\"description\":\"\"},{\"key\":\"role:manage\",\"name\":\"Add roles\",\"roles\":\"admin,manager\",\"description\":\"\"}]";
public static final String ROLE_RESPONSE_PAYLOAD_FILE_NAME = "role-response-payloads.json";
public static final String ROLE_ERRONEOUS_PAYLOAD_FILE_NAME = "role-erroneous-payloads.json";
public static final String ROLE_UPDATE_PAYLOAD_FILE_NAME = "role-update-payloads.json";
@@ -301,7 +305,7 @@ public static final class PolicyManagement {
private PolicyManagement() { throw new AssertionError();}
public static final String POLICY_MANAGEMENT_GROUP = "policy-mgt";
- public static final String ADD_POLICY_ENDPOINT= "/mdm-admin/policies/active-policy";
+ public static final String ADD_POLICY_ENDPOINT= "/api/device-mgt/v1.0/policies";
public static final String GET_ALL_POLICIES_ENDPOINT = "/mdm-admin/policies";
public static final String POLICY_PRIORITIES_ENDPOINT = "/mdm-admin/policies/priorities";
@@ -319,14 +323,16 @@ public static final class PolicyManagement {
public static final String POLICY_RESPONSE_PAYLOAD_FILE_NAME = "policy-response-payloads.json";
public static final String POLICY_PRIORITIES_RESPONSE_PAYLOAD_FILE_NAME = "policy-priories-response-payloads.json";
- public static final String UPDATE_ANDROID_POLICY_ENDPOINT = "/mdm-admin/policies/1";
+ public static final String UPDATE_ANDROID_POLICY_ENDPOINT = "/api/device-mgt/v1.0/policies/1";
public static String UPDATE_WINDOWS_POLICY_ENDPOINT = "";
+ public static final String UPDATE_POLICY_RESPONSE = "\"Policy has successfully been updated.\"";
- public static final String REMOVE_POLICY_ENDPOINT = "/mdm-admin/policies/bulk-remove";
+ public static final String REMOVE_POLICY_ENDPOINT = "/api/device-mgt/v1.0/policies/remove-policy";
public static final String REMOVE_ANDROID_POLICY_PAYLOAD_FILE_NAME = "[1]";
public static String REMOVE_WINDOWS_POLICY_PAYLOAD_FILE_NAME = "";
+ public static final String REMOVE_POLICY_RESPONSE = "\"Policies have been successfully deleted\"";
- public static final String VIEW_POLICY_LIST_ENDPOINT = "/mdm-admin/policies";
+ public static final String VIEW_POLICY_LIST_ENDPOINT = "/api/device-mgt/v1.0/policies";
}
public static final class FeatureManagement {
diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/mdm/integration/device/enrollment/AndroidEnrollment.java b/modules/integration/tests-integration/src/test/java/org/wso2/mdm/integration/device/enrollment/AndroidEnrollment.java
index b7e947b88..b37159959 100644
--- a/modules/integration/tests-integration/src/test/java/org/wso2/mdm/integration/device/enrollment/AndroidEnrollment.java
+++ b/modules/integration/tests-integration/src/test/java/org/wso2/mdm/integration/device/enrollment/AndroidEnrollment.java
@@ -46,7 +46,7 @@ public void testEnrollment() throws Exception {
enrollmentData.addProperty(Constants.DEVICE_IDENTIFIER_KEY, Constants.DEVICE_ID);
MDMResponse response = client.post(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT,
enrollmentData.toString());
- Assert.assertEquals(HttpStatus.SC_CREATED, response.getStatus());
+ Assert.assertEquals(HttpStatus.SC_OK, response.getStatus());
Assert.assertTrue(response.getBody().contains(Constants.AndroidEnrollment.ENROLLMENT_RESPONSE_PAYLOAD_FOR_POST));
}
diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/mdm/integration/operation/OperationManagement.java b/modules/integration/tests-integration/src/test/java/org/wso2/mdm/integration/operation/OperationManagement.java
index 53bbb74f2..4335ed79f 100644
--- a/modules/integration/tests-integration/src/test/java/org/wso2/mdm/integration/operation/OperationManagement.java
+++ b/modules/integration/tests-integration/src/test/java/org/wso2/mdm/integration/operation/OperationManagement.java
@@ -49,8 +49,7 @@ public void initTest() throws Exception {
@Test(description = "Add an Android device.")
public void enrollAndroidDevice() throws Exception {
JsonObject enrollmentData = PayloadGenerator.getJsonPayload(
- Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME,
- Constants.HTTP_METHOD_POST);
+ Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_POST);
enrollmentData.addProperty(Constants.DEVICE_IDENTIFIER_KEY, Constants.DEVICE_ID);
MDMResponse response = client.post(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT, enrollmentData.toString());
Assert.assertEquals(HttpStatus.SC_CREATED, response.getStatus());
@@ -59,7 +58,8 @@ public void enrollAndroidDevice() throws Exception {
Constants.HTTP_METHOD_POST).toString(), response.getBody(), true);
}
- @Test(dependsOnMethods = {"enrollAndroidDevice"}, description = "Install an app to enrolled android device")
+ @Test(dependsOnMethods = {
+ "enrollAndroidDevice" }, description = "Install an app to enrolled android device")
public void testInstallApps() throws Exception {
JsonObject operationData = PayloadGenerator.getJsonPayload(
Constants.AndroidOperations.OPERATION_PAYLOAD_FILE_NAME,
@@ -70,7 +70,7 @@ public void testInstallApps() throws Exception {
operationData.add(Constants.DEVICE_IDENTIFIERS_KEY, deviceIds);
HttpResponse response = rclient.post(Constants.AndroidOperations.INSTALL_APPS_ENDPOINT,
operationData.toString());
- Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode());
+ Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode());
}
@Test(dependsOnMethods = {"testInstallApps"}, description = "Test get device apps with wrong Device ID")
diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/mdm/integration/policy/AndroidPolicyManagement.java b/modules/integration/tests-integration/src/test/java/org/wso2/mdm/integration/policy/AndroidPolicyManagement.java
index 3b9dece63..afc4071e5 100644
--- a/modules/integration/tests-integration/src/test/java/org/wso2/mdm/integration/policy/AndroidPolicyManagement.java
+++ b/modules/integration/tests-integration/src/test/java/org/wso2/mdm/integration/policy/AndroidPolicyManagement.java
@@ -44,8 +44,6 @@ public void testAddPolicy() throws Exception {
PayloadGenerator.getJsonPayload(Constants.PolicyManagement.ANDROID_POLICY_PAYLOAD_FILE_NAME,
Constants.HTTP_METHOD_POST).toString());
Assert.assertEquals(HttpStatus.SC_CREATED, response.getStatus());
- Assert.assertEquals(PayloadGenerator.getJsonPayload(Constants.PolicyManagement.POLICY_RESPONSE_PAYLOAD_FILE_NAME,
- Constants.HTTP_METHOD_POST).toString(),response.getBody());
}
@Test(description = "Test add policy for work-profile")
@@ -54,8 +52,6 @@ public void testAddWorkProfilePolicy() throws Exception{
PayloadGenerator.getJsonPayload(Constants.PolicyManagement.ANDROID_POLICY_WORK_PROFILE_PAYLOAD_FILE_NAME,
Constants.HTTP_METHOD_POST).toString());
Assert.assertEquals(HttpStatus.SC_CREATED, response.getStatus());
- Assert.assertEquals(PayloadGenerator.getJsonPayload(Constants.PolicyManagement.POLICY_RESPONSE_PAYLOAD_FILE_NAME,
- Constants.HTTP_METHOD_POST).toString(),response.getBody());
}
@Test(description = "Test add policy with erroneous payload.")
@@ -65,11 +61,11 @@ public void testAddPolicyWithErroneousPayload() throws Exception {
Constants.HTTP_METHOD_POST).toString());
Assert.assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
}
+
@Test(description = "Test view policy list.", dependsOnMethods = { "testAddPolicy"})
public void testViewPolicyList() throws Exception {
MDMResponse response = client.get(Constants.PolicyManagement.VIEW_POLICY_LIST_ENDPOINT);
Assert.assertEquals(HttpStatus.SC_OK, response.getStatus());
-
}
@Test(description = "Test update policy.", dependsOnMethods = { "testViewPolicyList"})
@@ -79,32 +75,30 @@ public void testUpdatePolicy() throws Exception {
PayloadGenerator.getJsonPayload(
Constants.PolicyManagement.ANDROID_POLICY_PAYLOAD_FILE_NAME,
Constants.HTTP_METHOD_PUT).toString());
- Assert.assertEquals(HttpStatus.SC_CREATED, response.getStatus());
+ Assert.assertEquals(HttpStatus.SC_OK, response.getStatus());
+ Assert.assertEquals(Constants.PolicyManagement.UPDATE_POLICY_RESPONSE,response.getBody());
}
@Test(description = "Test update policy with erroneous payload.", dependsOnMethods = { "testAddPolicy"})
public void testUpdatePolicyWithErroneousPayload() throws Exception {
MDMResponse response = client.put(Constants.PolicyManagement.UPDATE_ANDROID_POLICY_ENDPOINT,
PayloadGenerator.getJsonPayload(Constants.PolicyManagement.ANDROID_POLICY_ERRONEOUS_PAYLOAD_FILE_NAME,
- Constants.HTTP_METHOD_POST).toString());
+ Constants.HTTP_METHOD_PUT).toString());
Assert.assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
}
@Test(description = "Test remove policy.", dependsOnMethods = { "testUpdatePolicy" })
public void testRemovePolicy() throws Exception {
-
MDMResponse response = client.post(Constants.PolicyManagement.REMOVE_POLICY_ENDPOINT,
Constants.PolicyManagement.REMOVE_ANDROID_POLICY_PAYLOAD_FILE_NAME);
Assert.assertEquals(HttpStatus.SC_OK, response.getStatus());
- Assert.assertEquals(PayloadGenerator.getJsonPayload(Constants.PolicyManagement.POLICY_RESPONSE_PAYLOAD_FILE_NAME,
- Constants.HTTP_METHOD_DELETE).toString(), response.getBody());
+ Assert.assertEquals(Constants.PolicyManagement.REMOVE_POLICY_RESPONSE, response.getBody());
}
@Test(description = "Test remove policy without a policies.", dependsOnMethods = { "testRemovePolicy" })
public void testRemovePolicyWithoutPolicies() throws Exception {
-
MDMResponse response = client.post(Constants.PolicyManagement.REMOVE_POLICY_ENDPOINT,
Constants.PolicyManagement.REMOVE_ANDROID_POLICY_PAYLOAD_FILE_NAME);
- Assert.assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
+ Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatus());
}
}
\ No newline at end of file
diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/mdm/integration/role/RoleManagement.java b/modules/integration/tests-integration/src/test/java/org/wso2/mdm/integration/role/RoleManagement.java
index 4d423efa4..73c85d6cd 100644
--- a/modules/integration/tests-integration/src/test/java/org/wso2/mdm/integration/role/RoleManagement.java
+++ b/modules/integration/tests-integration/src/test/java/org/wso2/mdm/integration/role/RoleManagement.java
@@ -49,7 +49,7 @@ public void testAddRole() throws Exception {
@Test(description = "Test view roles")
public void testViewRoles() throws Exception {
- MDMResponse response = client.get(Constants.RoleManagement.ROLE_ENDPOINT);
+ MDMResponse response = client.get(Constants.RoleManagement.ROLE_ENDPOINT_WITH_PAGINATION);
Assert.assertEquals(HttpStatus.SC_OK, response.getStatus());
AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload(Constants.RoleManagement.
ROLE_RESPONSE_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_GET).toString(),
@@ -82,15 +82,14 @@ public void testUpdateRoleWithErroneousPayload() throws Exception {
Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatus());
}
- @Test(description = "Test update scopes to a role.", dependsOnMethods = { "testUpdateUser"})
+ /*@Test(description = "Test update scopes to a role.", dependsOnMethods = { "testUpdateUser"})
public void testUpdateRolePermission() throws Exception {
String url=GetURL(Constants.RoleManagement.SCOPE_ROLE_ENDPOINT, Constants.RoleManagement.UPDATED_ROLE_NAME);
- MDMResponse response = client.put(url,
- PayloadGenerator.getJsonPayload(Constants.RoleManagement.ROLE_PAYLOAD_FILE_NAME,
- Constants.HTTP_METHOD_PUT).toString());
- Assert.assertEquals(HttpStatus.SC_OK, response.getStatus());
- }
+ MDMResponse response = client.put(url, Constants.RoleManagement.ROLE_RESPONSE_PAYLOAD);
+ Assert.assertEquals(HttpStatus.SC_OK, response.getStatus());
+ }*/
+ /*TODO Role detele endpoint currently expecting a payload, this has to be changed
/*@Test(description = "Test remove role.", dependsOnMethods = { "testUpdateRolePermission" })
public void testRemoveRole() throws Exception {
String url=GetURL(Constants.RoleManagement.ROLE_ENDPOINT, Constants.RoleManagement.UPDATED_ROLE_NAME);
diff --git a/modules/integration/tests-integration/src/test/resources/payloads/android-policy-payloads.json b/modules/integration/tests-integration/src/test/resources/payloads/android-policy-payloads.json
index e7f27dafa..2c32e8f4a 100644
--- a/modules/integration/tests-integration/src/test/resources/payloads/android-policy-payloads.json
+++ b/modules/integration/tests-integration/src/test/resources/payloads/android-policy-payloads.json
@@ -4,23 +4,23 @@
"description": "Optional",
"compliance": "enforce",
"ownershipType": "ANY",
+ "active": false,
"profile": {
"profileName": "Camera",
- "deviceType": {
- "id": 1
- },
+ "deviceType": "android",
"profileFeaturesList": [
{
"featureCode": "CAMERA",
- "deviceTypeId": 1,
+ "deviceType": "android",
"content": {
- "enabled": true
+ "enabled": false
}
}
]
},
- "users": [],
- "roles": []
+ "roles": [
+ "ANY"
+ ]
},
"PUT": {
"policyName": "Camera",
@@ -29,26 +29,26 @@
"ownershipType": "ANY",
"profile": {
"profileName": "Camera",
- "deviceType": {
- "id": 1
- },
+ "deviceType": "android",
"profileFeaturesList": [
{
"featureCode": "CAMERA",
- "deviceTypeId": 1,
+ "deviceType": "android",
"content": {
- "enabled": true
+ "enabled": false
}
},
{
- "featureCode": "ENCRYPT_STORAGE",
- "deviceTypeId": 1,
+ "featureCode": "DISALLOW_ADJUST_VOLUME",
+ "deviceType": "android",
"content": {
- "encrypted": true
+ "enabled": true
}
}
]
},
+ "users": [
+ ],
"roles": [
"ANY"
]
diff --git a/modules/integration/tests-integration/src/test/resources/payloads/android-policy-work-profile-payload.json b/modules/integration/tests-integration/src/test/resources/payloads/android-policy-work-profile-payload.json
index 9dae9dc04..f7b4eca2e 100644
--- a/modules/integration/tests-integration/src/test/resources/payloads/android-policy-work-profile-payload.json
+++ b/modules/integration/tests-integration/src/test/resources/payloads/android-policy-work-profile-payload.json
@@ -1,26 +1,29 @@
-{"POST": {
- "policyName": "Work-Profile",
- "description": "",
- "compliance": "enforce",
- "ownershipType": "ANY",
- "profile": {
- "profileName": "Work-Profile",
- "deviceType": {
- "id": 1
+{
+ "POST": {
+ "policyName":"Work-Profile",
+ "description":"",
+ "compliance":"enforce",
+ "ownershipType":"ANY",
+ "active":false,
+ "profile":{
+ "profileName":"Work-Profile",
+ "deviceType":"android",
+ "profileFeaturesList":[
+ {
+ "featureCode":"WORK_PROFILE",
+ "deviceType":"android",
+ "content":{
+ "profileName":"Work-Profile",
+ "enableSystemApps":"com.google.android.apps.maps",
+ "hideSystemApps":"com.google.android.calculator",
+ "unhideSystemApps":null,
+ "enablePlaystoreApps":"com.google.android.whity"
+ }
+ }
+ ]
},
- "profileFeaturesList": [{
- "featureCode": "WORK_PROFILE",
- "deviceTypeId": 1,
- "content": {
- "DISALLOW_CROSS_PROFILE_COPY_PASTE": true,
- "profileName": "WSO2 Profile",
- "enableSystemApps": "com.google.android.apps.maps",
- "hideSystemApps": "com.google.android.calculator",
- "unhideSystemApps": null,
- "enablePlaystoreApps": "com.google.android.whity"
- }
- }]
- },
- "roles": ["ANY"]
-}
+ "roles":[
+ "ANY"
+ ]
+ }
}
\ No newline at end of file
diff --git a/modules/integration/tests-integration/src/test/resources/payloads/policy-erroneous-payloads.json b/modules/integration/tests-integration/src/test/resources/payloads/policy-erroneous-payloads.json
index 7f87a2074..a65e9a91c 100644
--- a/modules/integration/tests-integration/src/test/resources/payloads/policy-erroneous-payloads.json
+++ b/modules/integration/tests-integration/src/test/resources/payloads/policy-erroneous-payloads.json
@@ -14,5 +14,21 @@
},
"users": [],
"roles": []
+ },
+ "PUT" : {
+ "compliance": "enforce",
+ "ownershipType": "ANY",
+ "profile": {
+ "profileName": "Camera",
+ "profileFeaturesList": [
+ {
+ "content": {
+ "enabled": true
+ }
+ }
+ ]
+ },
+ "users": [],
+ "roles": []
}
}
\ No newline at end of file
diff --git a/modules/integration/tests-integration/src/test/resources/payloads/policy-response-payloads.json b/modules/integration/tests-integration/src/test/resources/payloads/policy-response-payloads.json
index 396a639c0..9d77f80aa 100644
--- a/modules/integration/tests-integration/src/test/resources/payloads/policy-response-payloads.json
+++ b/modules/integration/tests-integration/src/test/resources/payloads/policy-response-payloads.json
@@ -4,11 +4,11 @@
"messageFromServer": "Policy has been added successfully."
},
"PUT": {
- "statusCode": 201,
- "messageFromServer": "Policy has been updated successfully."
+ "statusCode": 200,
+ "messageFromServer": "Policy has successfully been updated."
},
"DELETE": {
"statusCode": 200,
- "messageFromServer": "Policies have been successfully deleted."
+ "messageFromServer": "Policies have been successfully deleted"
}
}
diff --git a/modules/integration/tests-integration/src/test/resources/testng.xml b/modules/integration/tests-integration/src/test/resources/testng.xml
index 570056a6a..2977e4296 100644
--- a/modules/integration/tests-integration/src/test/resources/testng.xml
+++ b/modules/integration/tests-integration/src/test/resources/testng.xml
@@ -91,16 +91,16 @@
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
@@ -121,11 +121,11 @@
-
-
-
-
-
+
+
+
+
+
diff --git a/modules/mobile-agents/android/client/build.gradle b/modules/mobile-agents/android/client/build.gradle
index a94985438..9760e80e5 100644
--- a/modules/mobile-agents/android/client/build.gradle
+++ b/modules/mobile-agents/android/client/build.gradle
@@ -22,7 +22,7 @@ buildscript {
dependencies {
- classpath 'com.android.tools.build:gradle:2.1.0'
+ classpath 'com.android.tools.build:gradle:2.1.3'
}
}
diff --git a/modules/mobile-agents/android/client/client/build.gradle b/modules/mobile-agents/android/client/client/build.gradle
index 2cb02b315..cae2f1686 100644
--- a/modules/mobile-agents/android/client/client/build.gradle
+++ b/modules/mobile-agents/android/client/client/build.gradle
@@ -29,7 +29,7 @@ android {
defaultConfig {
applicationId "org.wso2.emm.agent"
- minSdkVersion 16
+ minSdkVersion 17
targetSdkVersion 23
multiDexEnabled true
}
diff --git a/modules/mobile-agents/android/client/client/src/main/java/org/wso2/emm/agent/api/ApplicationManager.java b/modules/mobile-agents/android/client/client/src/main/java/org/wso2/emm/agent/api/ApplicationManager.java
index e9ed1c233..64fda6b2b 100644
--- a/modules/mobile-agents/android/client/client/src/main/java/org/wso2/emm/agent/api/ApplicationManager.java
+++ b/modules/mobile-agents/android/client/client/src/main/java/org/wso2/emm/agent/api/ApplicationManager.java
@@ -411,7 +411,7 @@ public void manageWebAppBookmark(String url, String title, String operationType)
bookmarkIntent.
setAction(resources.getString(R.string.application_package_launcher_install_action));
}
- context.sendBroadcast(bookmarkIntent);
+ context.sendBroadcastAsUser(bookmarkIntent, android.os.Process.myUserHandle());
}
public List getInstalledApplications() {
diff --git a/modules/mobile-agents/android/client/client/src/main/java/org/wso2/emm/agent/dao/NotificationDAO.java b/modules/mobile-agents/android/client/client/src/main/java/org/wso2/emm/agent/dao/NotificationDAO.java
index fb480a0a1..0f8441c5a 100644
--- a/modules/mobile-agents/android/client/client/src/main/java/org/wso2/emm/agent/dao/NotificationDAO.java
+++ b/modules/mobile-agents/android/client/client/src/main/java/org/wso2/emm/agent/dao/NotificationDAO.java
@@ -37,10 +37,12 @@
public class NotificationDAO {
private SQLiteDatabase db;
- private DatabaseHelper dbHelper;
+ private static DatabaseHelper dbHelper;
public NotificationDAO(Context context) {
- dbHelper = new DatabaseHelper(context);
+ if(dbHelper == null){
+ dbHelper = new DatabaseHelper(context);
+ }
}
public void open() throws SQLException {
diff --git a/modules/mobile-agents/android/client/client/src/main/java/org/wso2/emm/agent/services/ApplicationManagementService.java b/modules/mobile-agents/android/client/client/src/main/java/org/wso2/emm/agent/services/ApplicationManagementService.java
index 26c63bdaf..23109ecc4 100644
--- a/modules/mobile-agents/android/client/client/src/main/java/org/wso2/emm/agent/services/ApplicationManagementService.java
+++ b/modules/mobile-agents/android/client/client/src/main/java/org/wso2/emm/agent/services/ApplicationManagementService.java
@@ -171,7 +171,7 @@ public void doTask(String operation) {
getString(R.string.firmware_upgrade_retries));
boolean isFirmwareUpgradeAutoRetry = Preference.getBoolean(context, context
.getResources().getString(R.string.is_automatic_firmware_upgrade));
- if (retryCount <= Constants.FIRMWARE_UPGRADE_RETRY_COUNT && isFirmwareUpgradeAutoRetry) {
+ if (retryCount < Constants.FIRMWARE_UPGRADE_RETRY_COUNT && isFirmwareUpgradeAutoRetry) {
Preference.putInt(context, context.getResources().
getString(R.string.firmware_upgrade_retries), ++retryCount);
Preference.putBoolean(context, context.getResources().
@@ -243,7 +243,7 @@ private void sendBroadcast(String status, String payload) {
broadcastIntent.putExtra(INTENT_KEY_STATUS, status);
broadcastIntent.putExtra(INTENT_KEY_PAYLOAD, payload);
broadcastIntent.putExtra(INTENT_KEY_SERVER, utils.getAPIServerURL(context));
- sendBroadcast(broadcastIntent);
+ sendBroadcastAsUser(broadcastIntent, android.os.Process.myUserHandle());
}
@Override
diff --git a/modules/mobile-agents/android/client/client/src/main/java/org/wso2/emm/agent/services/NetworkConnectedReceiver.java b/modules/mobile-agents/android/client/client/src/main/java/org/wso2/emm/agent/services/NetworkConnectedReceiver.java
index b3c663578..142bb997a 100644
--- a/modules/mobile-agents/android/client/client/src/main/java/org/wso2/emm/agent/services/NetworkConnectedReceiver.java
+++ b/modules/mobile-agents/android/client/client/src/main/java/org/wso2/emm/agent/services/NetworkConnectedReceiver.java
@@ -39,7 +39,7 @@ public void onReceive(Context context, Intent intent) {
Intent autoEnrollIntent = new Intent(context, EnrollmentService.class);
autoEnrollIntent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
autoEnrollIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- context.startService(autoEnrollIntent);
+ context.startServiceAsUser(intent, android.os.Process.myUserHandle());
}
CommonUtils.callSystemAppInit(context);
}
diff --git a/modules/mobile-agents/android/client/client/src/main/java/org/wso2/emm/agent/utils/CommonUtils.java b/modules/mobile-agents/android/client/client/src/main/java/org/wso2/emm/agent/utils/CommonUtils.java
index a7e434bb5..755ec34b4 100644
--- a/modules/mobile-agents/android/client/client/src/main/java/org/wso2/emm/agent/utils/CommonUtils.java
+++ b/modules/mobile-agents/android/client/client/src/main/java/org/wso2/emm/agent/utils/CommonUtils.java
@@ -429,7 +429,7 @@ public static void callSystemApp(Context context, String operation, String comma
}
intent.putExtra("command", command);
}
- context.startService(intent);
+ context.startServiceAsUser(intent, android.os.Process.myUserHandle());
} else {
Log.e(TAG, "System app not enabled.");
}
@@ -442,8 +442,7 @@ public static void callSystemAppInit(Context context) {
if (explicitIntent != null) {
intent = explicitIntent;
}
-
- context.startService(intent);
+ context.startServiceAsUser(intent, android.os.Process.myUserHandle());
} else {
Log.e(TAG, "System app not enabled.");
}
diff --git a/modules/mobile-agents/android/client/gradle/wrapper/gradle-wrapper.properties b/modules/mobile-agents/android/client/gradle/wrapper/gradle-wrapper.properties
index f604b9cfa..83d992a11 100644
--- a/modules/mobile-agents/android/client/gradle/wrapper/gradle-wrapper.properties
+++ b/modules/mobile-agents/android/client/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Wed May 04 10:23:44 IST 2016
+#Wed Aug 24 10:34:34 IST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
diff --git a/modules/mobile-agents/android/client/volley/build.gradle b/modules/mobile-agents/android/client/volley/build.gradle
index 855d39aae..0e2b7fe2a 100644
--- a/modules/mobile-agents/android/client/volley/build.gradle
+++ b/modules/mobile-agents/android/client/volley/build.gradle
@@ -19,7 +19,7 @@ buildscript {
jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:1.3.1'
+ classpath 'com.android.tools.build:gradle:2.1.3'
}
}
diff --git a/modules/mobile-agents/android/system-service/app/src/main/java/org/wso2/emm/system/service/EMMSystemService.java b/modules/mobile-agents/android/system-service/app/src/main/java/org/wso2/emm/system/service/EMMSystemService.java
index 4eeb74991..2dfc22358 100755
--- a/modules/mobile-agents/android/system-service/app/src/main/java/org/wso2/emm/system/service/EMMSystemService.java
+++ b/modules/mobile-agents/android/system-service/app/src/main/java/org/wso2/emm/system/service/EMMSystemService.java
@@ -25,6 +25,8 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
@@ -154,23 +156,38 @@ protected void onHandleIntent(Intent intent) {
doTask(operationCode);
} else {
Log.d(TAG, "Received command from external application. operation code: " + operationCode + " command: " + command);
- switch(operationCode){
+ boolean isAutomaticRetry;
+ switch (operationCode) {
case Constants.Operation.FIRMWARE_UPGRADE_AUTOMATIC_RETRY:
+ isAutomaticRetry = !"false".equals(command);
Preference.putBoolean(context, context.getResources().
- getString(R.string.firmware_upgrade_automatic_retry), !"false".equals(command));
+ getString(R.string.firmware_upgrade_automatic_retry), isAutomaticRetry);
+ if (isAutomaticRetry) {
+ String status = Preference.getString(context, context.getResources().getString(R.string.upgrade_download_status));
+ if (Constants.Status.WIFI_OFF.equals(status) && !checkNetworkOnline()) {
+ Preference.putString(context, context.getResources().getString(R.string.upgrade_download_status), Constants.Status.FAILED);
+ } else if (Constants.Status.BATTERY_LEVEL_INSUFFICIENT_TO_DOWNLOAD.equals(status)) {
+ Preference.putString(context, context.getResources().getString(R.string.upgrade_download_status), Constants.Status.FAILED);
+ } else if (Constants.Status.BATTERY_LEVEL_INSUFFICIENT_TO_INSTALL.equals(Preference.getString(context, context.getResources().getString(R.string.upgrade_install_status)))) {
+ Preference.putString(context, context.getResources().getString(R.string.upgrade_install_status), Constants.Status.FAILED);
+ }
+ }
CommonUtils.callAgentApp(context, Constants.Operation.
FIRMWARE_UPGRADE_AUTOMATIC_RETRY, 0, command); //Sending command as the message
break;
case Constants.Operation.UPGRADE_FIRMWARE:
try {
JSONObject upgradeData = new JSONObject(command);
- boolean isAutomaticUpgrade = true;
+ isAutomaticRetry = (Preference.hasPreferenceKey(context, context.getResources()
+ .getString(R.string.firmware_upgrade_automatic_retry)) && Preference.getBoolean(context, context.getResources()
+ .getString(R.string.firmware_upgrade_automatic_retry))) || !Preference.hasPreferenceKey(context, context.getResources()
+ .getString(R.string.firmware_upgrade_automatic_retry));
if (!upgradeData.isNull(context.getResources().getString(R.string.firmware_upgrade_automatic_retry))) {
- isAutomaticUpgrade = upgradeData.getBoolean(context.getResources()
+ isAutomaticRetry = upgradeData.getBoolean(context.getResources()
.getString(R.string.firmware_upgrade_automatic_retry));
}
CommonUtils.callAgentApp(context, Constants.Operation.
- FIRMWARE_UPGRADE_AUTOMATIC_RETRY, 0, (isAutomaticUpgrade ? "true": "false"));
+ FIRMWARE_UPGRADE_AUTOMATIC_RETRY, 0, (isAutomaticRetry ? "true": "false"));
} catch (JSONException e) {
String error = "Failed to build JSON object form the request: " + command;
Log.e(TAG, error);
@@ -468,8 +485,8 @@ public void upgradeFirmware(final boolean isStatusCheck) {
boolean isAutomaticUpgrade = Preference.getBoolean(context, context.getResources()
.getString(R.string.firmware_upgrade_automatic_retry));
- if (Constants.Status.WIFI_OFF.equals(status) && isAutomaticUpgrade) {
- String msg = "Ignoring request from agent as service waiting for WiFi to start upgrade.";
+ if (Constants.Status.WIFI_OFF.equals(status) && isAutomaticUpgrade && !checkNetworkOnline()) {
+ String msg = "Ignoring request as service waiting for WiFi to start upgrade.";
Log.d(TAG, msg);
CommonUtils.sendBroadcast(context, Constants.Operation.UPGRADE_FIRMWARE, Constants.Code.PENDING,
Constants.Status.OTA_UPGRADE_PENDING, msg);
@@ -506,6 +523,17 @@ public void run() {
}
}
+ private boolean checkNetworkOnline() {
+ ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
+ NetworkInfo info = connectivityManager.getActiveNetworkInfo();
+ boolean status = false;
+ if (info != null && info.isConnectedOrConnecting()) {
+ status = true;
+ }
+
+ return status;
+ }
+
/**
* Rebooting the device.
*/
@@ -602,6 +630,12 @@ private void publishFirmwareDownloadProgress() {
.getString(R.string.firmware_upgrade_automatic_retry));
String statusCode = isAutomaticRetry ? Constants.Code.PENDING : Constants.Code.FAILURE;
+ if (status == null) {
+ CommonUtils.sendBroadcast(context, Constants.Operation.GET_FIRMWARE_UPGRADE_DOWNLOAD_PROGRESS,
+ Constants.Code.SUCCESS, Constants.Status.NO_HISTORY, "History not found");
+ return;
+ }
+
switch (status){
case Constants.Status.WIFI_OFF:
CommonUtils.sendBroadcast(context, Constants.Operation.GET_FIRMWARE_UPGRADE_DOWNLOAD_PROGRESS,
@@ -619,6 +653,14 @@ private void publishFirmwareDownloadProgress() {
CommonUtils.sendBroadcast(context, Constants.Operation.GET_FIRMWARE_UPGRADE_DOWNLOAD_PROGRESS,
Constants.Code.FAILURE, Constants.Status.LOW_DISK_SPACE, null);
break;
+ case Constants.Status.FILE_NOT_FOUND:
+ CommonUtils.sendBroadcast(context, Constants.Operation.GET_FIRMWARE_UPGRADE_DOWNLOAD_PROGRESS,
+ Constants.Code.FAILURE, Constants.Status.FILE_NOT_FOUND, null);
+ break;
+ case Constants.Status.CONNECTION_FAILED:
+ CommonUtils.sendBroadcast(context, Constants.Operation.GET_FIRMWARE_UPGRADE_DOWNLOAD_PROGRESS,
+ Constants.Code.FAILURE, Constants.Status.CONNECTION_FAILED, null);
+ break;
case Constants.Status.REQUEST_PLACED:
CommonUtils.sendBroadcast(context, Constants.Operation.GET_FIRMWARE_UPGRADE_DOWNLOAD_PROGRESS,
Constants.Code.PENDING, Constants.Status.REQUEST_PLACED, null);
diff --git a/modules/mobile-agents/android/system-service/app/src/main/java/org/wso2/emm/system/service/api/OTADownload.java b/modules/mobile-agents/android/system-service/app/src/main/java/org/wso2/emm/system/service/api/OTADownload.java
index dacdc3051..57fd67b16 100755
--- a/modules/mobile-agents/android/system-service/app/src/main/java/org/wso2/emm/system/service/api/OTADownload.java
+++ b/modules/mobile-agents/android/system-service/app/src/main/java/org/wso2/emm/system/service/api/OTADownload.java
@@ -96,6 +96,7 @@ public String byteCountToDisplaySize(long bytes, boolean isSI) {
}
public void startOTA() {
+ CommonUtils.sendBroadcast(context, Constants.Operation.UPGRADE_FIRMWARE, Constants.Code.SUCCESS, Constants.Status.REQUEST_PLACED, null);
//Check in the main service thread
otaServerManager.startCheckingVersion();
}
@@ -226,9 +227,12 @@ protected void onPostExecute(Long bytes) {
if (getBatteryLevel(context) >= Constants.REQUIRED_BATTERY_LEVEL_TO_FIRMWARE_UPGRADE) {
otaServerManager.startDownloadUpgradePackage(otaServerManager);
} else if (isAutomaticRetry) {
+ String message = "Upgrade download has been differed due to insufficient battery level.";
+ Log.w(TAG, message);
Preference.putString(context, context.getResources().getString(R.string.upgrade_download_status),
Constants.Status.BATTERY_LEVEL_INSUFFICIENT_TO_DOWNLOAD);
- Log.e(TAG, "Upgrade download has been differed due to insufficient battery level.");
+ CommonUtils.sendBroadcast(context, Constants.Operation.UPGRADE_FIRMWARE, Constants.Code.PENDING,
+ Constants.Status.BATTERY_LEVEL_INSUFFICIENT_TO_DOWNLOAD, message);
} else {
String message = "Upgrade download has been failed due to insufficient battery level.";
Preference.putString(context, context.getResources().getString(R.string.upgrade_download_status),
diff --git a/modules/mobile-agents/android/system-service/app/src/main/java/org/wso2/emm/system/service/api/OTAServerManager.java b/modules/mobile-agents/android/system-service/app/src/main/java/org/wso2/emm/system/service/api/OTAServerManager.java
index 9728dd8db..67dbba7e5 100755
--- a/modules/mobile-agents/android/system-service/app/src/main/java/org/wso2/emm/system/service/api/OTAServerManager.java
+++ b/modules/mobile-agents/android/system-service/app/src/main/java/org/wso2/emm/system/service/api/OTAServerManager.java
@@ -372,14 +372,14 @@ public void run() {
Preference.putString(context, context.getResources().getString(R.string.upgrade_download_status),
Constants.Status.CONNECTION_FAILED);
} catch (IOException e) {
- String message = "Connection failure when downloading update package.";
+ String message = "Unable to find firmware upgrade package " + serverConfig.getPackageURL().toString();
Log.e(TAG, message + e);
CommonUtils.sendBroadcast(context, Constants.Operation.UPGRADE_FIRMWARE, Constants.Code.FAILURE,
- Constants.Status.CONNECTION_FAILED, message);
+ Constants.Status.FILE_NOT_FOUND, message);
CommonUtils.callAgentApp(context, Constants.Operation.FAILED_FIRMWARE_UPGRADE_NOTIFICATION, 0, null);
reportDownloadError(OTAStateChangeListener.ERROR_WRITE_FILE_ERROR);
Preference.putString(context, context.getResources().getString(R.string.upgrade_download_status),
- Constants.Status.CONNECTION_FAILED);
+ Constants.Status.FILE_NOT_FOUND);
} finally {
wakeLock.release();
wakeLock.acquire(2);
@@ -594,9 +594,9 @@ protected Void doInBackground(Void... param) {
CommonUtils.sendBroadcast(context, operation, Constants.Code.FAILURE, Constants.Status.CONNECTION_FAILED, message);
CommonUtils.callAgentApp(context, Constants.Operation.FAILED_FIRMWARE_UPGRADE_NOTIFICATION, 0, null);
} catch (IOException e) {
- String message = "Property list (build.prop) download failed due to connection failure.";
+ String message = "Property list (build.prop) not found in the server.";
Log.e(TAG, message + e);
- CommonUtils.sendBroadcast(context, operation, Constants.Code.FAILURE, Constants.Status.CONNECTION_FAILED, message);
+ CommonUtils.sendBroadcast(context, operation, Constants.Code.FAILURE, Constants.Status.FILE_NOT_FOUND, message);
CommonUtils.callAgentApp(context, Constants.Operation.FAILED_FIRMWARE_UPGRADE_NOTIFICATION, 0, null);
} finally {
if (reader != null) {
diff --git a/modules/mobile-agents/android/system-service/app/src/main/java/org/wso2/emm/system/service/utils/Constants.java b/modules/mobile-agents/android/system-service/app/src/main/java/org/wso2/emm/system/service/utils/Constants.java
index 613d7ff89..c8d56b8a6 100644
--- a/modules/mobile-agents/android/system-service/app/src/main/java/org/wso2/emm/system/service/utils/Constants.java
+++ b/modules/mobile-agents/android/system-service/app/src/main/java/org/wso2/emm/system/service/utils/Constants.java
@@ -132,6 +132,7 @@ private Status(){
public static final String OTA_UPGRADE_ONGOING = "2001";
public static final String REQUEST_PLACED = "2002";
public static final String USER_CANCELED = "3000";
+ public static final String NO_HISTORY = "3001";
public static final String MALFORMED_REQUEST = "4000";
public static final String BATTERY_LEVEL_INSUFFICIENT_TO_DOWNLOAD = "4001";
public static final String WIFI_OFF = "4002";
@@ -146,6 +147,8 @@ private Status(){
public static final String BATTERY_LEVEL_INSUFFICIENT_TO_INSTALL = "4011";
public static final String OTA_IMAGE_VERIFICATION_FAILED = "4012";
public static final String CONNECTION_FAILED = "4013";
+ public static final String FILE_NOT_FOUND = "4014";
+ public static final String FAILED = "5000";
public static final String INTERNAL_ERROR = "5001";
}
diff --git a/modules/mobile-agents/android/system-service/build.gradle b/modules/mobile-agents/android/system-service/build.gradle
index fd910a3a3..e3a8c8bc1 100644
--- a/modules/mobile-agents/android/system-service/build.gradle
+++ b/modules/mobile-agents/android/system-service/build.gradle
@@ -21,7 +21,7 @@ buildscript {
jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:1.3.0'
+ classpath 'com.android.tools.build:gradle:2.1.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
diff --git a/modules/mobile-agents/android/system-service/gradle/wrapper/gradle-wrapper.properties b/modules/mobile-agents/android/system-service/gradle/wrapper/gradle-wrapper.properties
index e288073d9..1fd0ff1d8 100644
--- a/modules/mobile-agents/android/system-service/gradle/wrapper/gradle-wrapper.properties
+++ b/modules/mobile-agents/android/system-service/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Tue Jan 26 09:42:40 IST 2016
+#Wed Aug 24 10:36:36 IST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip