Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

Commit

Permalink
refactor(enroll): set api token with mqtt
Browse files Browse the repository at this point in the history
Signed-off-by: Rafa Hernandez <[email protected]>
  • Loading branch information
rafaelje authored and Ivan Del Pino committed Dec 14, 2018
1 parent 1890ad9 commit 7339497
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/src/main/assets/about.properties
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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() {
Expand Down
27 changes: 23 additions & 4 deletions app/src/mqtt/java/org/flyve/mdm/agent/core/mqtt/MqttModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 7339497

Please sign in to comment.