diff --git a/app/src/main/assets/about.properties b/app/src/main/assets/about.properties index 1c902ed440..b4c9834d28 100644 --- a/app/src/main/assets/about.properties +++ b/app/src/main/assets/about.properties @@ -1,6 +1,6 @@ about.version=2.0.0-rc.5 about.build=3067 -about.date=Thu Dec 13 20:17:23 2018 +about.date=Thu Dec 13 20:30:44 2018 about.commit= about.commitFull= about.github=https://github.com/flyve-mdm/flyve-mdm-android-agent diff --git a/app/src/mqtt/java/org/flyve/mdm/agent/core/enrollment/EnrollmentHelper.java b/app/src/mqtt/java/org/flyve/mdm/agent/core/enrollment/EnrollmentHelper.java index cb2323637b..cac43e6121 100644 --- a/app/src/mqtt/java/org/flyve/mdm/agent/core/enrollment/EnrollmentHelper.java +++ b/app/src/mqtt/java/org/flyve/mdm/agent/core/enrollment/EnrollmentHelper.java @@ -353,6 +353,7 @@ public void run() { FlyveLog.d("Id: " + mId); int mEntitiesId = jsonObject.getInt("entities_id"); int mFleetId = jsonObject.getInt("plugin_flyvemdm_fleets_id"); + String mApiToken = jsonObject.getString("api_token"); cache.setAgentId(agentId); cache.setBroker(mbroker); @@ -366,6 +367,7 @@ public void run() { cache.setComputersId(String.valueOf(mComputersId)); cache.setEntitiesId(String.valueOf(mEntitiesId)); cache.setPluginFlyvemdmFleetsId(String.valueOf(mFleetId)); + cache.setApiToken(mApiToken); } catch (final Exception ex) { EnrollmentHelper.runOnUI(new Runnable() { diff --git a/app/src/mqtt/java/org/flyve/mdm/agent/core/mqtt/MqttModel.java b/app/src/mqtt/java/org/flyve/mdm/agent/core/mqtt/MqttModel.java index 044b65e1aa..2aaa79ed1b 100644 --- a/app/src/mqtt/java/org/flyve/mdm/agent/core/mqtt/MqttModel.java +++ b/app/src/mqtt/java/org/flyve/mdm/agent/core/mqtt/MqttModel.java @@ -25,6 +25,7 @@ import android.content.Context; import android.content.Intent; +import android.os.SystemClock; import android.util.Log; import org.eclipse.paho.android.service.MqttAndroidClient; @@ -37,7 +38,9 @@ import org.eclipse.paho.client.mqttv3.MqttMessage; import org.flyve.mdm.agent.R; import org.flyve.mdm.agent.core.CommonErrorType; +import org.flyve.mdm.agent.data.database.ApplicationData; import org.flyve.mdm.agent.data.database.MqttData; +import org.flyve.mdm.agent.data.database.entity.Application; import org.flyve.mdm.agent.data.localstorage.AppData; import org.flyve.mdm.agent.policies.AirplaneModePolicy; import org.flyve.mdm.agent.policies.BasePolicies; @@ -78,7 +81,6 @@ import org.flyve.mdm.agent.services.MQTTService; import org.flyve.mdm.agent.ui.MDMAgent; import org.flyve.mdm.agent.ui.MainActivity; -import org.flyve.mdm.agent.utils.AppThreadManager; import org.flyve.mdm.agent.utils.FlyveLog; import org.flyve.mdm.agent.utils.Helpers; import org.json.JSONArray; @@ -608,17 +610,34 @@ public void messageArrived(Context context, String topic, MqttMessage message) { String DEPLOY_APP = "deployApp"; if(topic.toLowerCase().contains(DEPLOY_APP.toLowerCase())) { MDMAgent.setMqttClient(getMqttClient()); - AppThreadManager manager = MDMAgent.getAppThreadManager(); try { JSONObject jsonObj = new JSONObject(messageBody); if(jsonObj.has(DEPLOY_APP)) { - manager.add(context, jsonObj); + + String deployApp = jsonObj.getString("deployApp"); + String id = jsonObj.getString("id"); + String versionCode = jsonObj.getString("versionCode"); + String taskId = jsonObj.getString("taskId"); + + ApplicationData apps = new ApplicationData(context); + Application[] appsArray = apps.getApplicationsById(id); + + // check if the app exists with same version or older + Boolean bDownload = true; + if(appsArray.length>0 && Integer.parseInt(versionCode) >= Integer.parseInt(appsArray[0].appVersionCode)) { + bDownload = false; + } + + if(bDownload) { + // execute the policy + mqttPoliciesController.installPackage(deployApp, id, versionCode, taskId); + SystemClock.sleep(2000); + } } } catch (Exception ex) { showDetailError(context, CommonErrorType.MQTT_DEPLOYAPP, ex.getMessage()); - manager.finishProcess(context); } }