use of org.flyve.mdm.agent.policies.PoliciesAsyncTask in project android-mdm-agent by flyve-mdm.
the class MessagePolicies method messageArrived.
public void messageArrived(final Context context, String topic, String message) {
// Delete policy information if message contains default
if (message.contains("default")) {
try {
String taskId = new JSONObject(message).getString("taskId");
new PoliciesData(context).removeValue(taskId);
FlyveLog.i("Deleting policy " + message + " - " + topic);
} catch (Exception ex) {
FlyveLog.e("fcm", "error deleting policy " + message + " - " + topic, ex.getMessage());
}
return;
}
// Command/Policies
new PoliciesAsyncTask().execute(context, PoliciesAsyncTask.POLICIES, topic, message);
// Command/Ping
if (topic.toLowerCase().contains("ping")) {
new PoliciesAsyncTask().execute(context, PoliciesAsyncTask.PING, topic, message);
}
// Command/Geolocate
if (topic.toLowerCase().contains("geolocate")) {
new PoliciesAsyncTask().execute(context, PoliciesAsyncTask.GEOLOCATE, topic, message);
}
// Command/Inventory
if (topic.toLowerCase().contains("inventory")) {
new PoliciesAsyncTask().execute(context, PoliciesAsyncTask.INVENTORY, topic, message);
}
// Command/Wipe
if (topic.toLowerCase().contains("wipe")) {
new PoliciesAsyncTask().execute(context, PoliciesAsyncTask.WIPE, topic, message);
}
// Command/Lock
if (topic.toLowerCase().contains("lock")) {
new PoliciesAsyncTask().execute(context, PoliciesAsyncTask.LOCK, topic, message);
}
// Command/Unenroll
if (topic.toLowerCase().contains("unenroll")) {
new PoliciesAsyncTask().execute(context, PoliciesAsyncTask.UNENROLL, topic, message);
}
}
use of org.flyve.mdm.agent.policies.PoliciesAsyncTask in project android-mdm-agent by flyve-mdm.
the class MqttModel method messageArrived.
public void messageArrived(Context context, String topic, MqttMessage message) {
int priority = topic.contains("fleet") ? 0 : 1;
String messageBody = new String(message.getPayload());
MqttController mqttController = new MqttController(context, getMqttClient());
if (topic.isEmpty()) {
// exit if the topic if empty
return;
}
// Delete policy information
if (messageBody.contains("default")) {
try {
String taskId = new JSONObject(messageBody).getString("taskId");
new PoliciesData(context).removeValue(taskId);
FlyveLog.i("Deleting policy " + message + " - " + topic);
} catch (Exception ex) {
FlyveLog.e("fcm", "error deleting policy " + message + " - " + topic, ex.getMessage());
}
return;
}
// Command/Policies
new PoliciesAsyncTask().execute(context, PoliciesAsyncTask.POLICIES, topic, messageBody, this.client);
// Command/Ping
if (topic.toLowerCase().contains("ping")) {
new PoliciesAsyncTask().execute(context, PoliciesAsyncTask.PING, topic, messageBody, this.client);
}
// Command/Geolocate
if (topic.toLowerCase().contains("geolocate")) {
new PoliciesAsyncTask().execute(context, PoliciesAsyncTask.GEOLOCATE, topic, messageBody, this.client);
}
// Command/Inventory
if (topic.toLowerCase().contains("inventory")) {
new PoliciesAsyncTask().execute(context, PoliciesAsyncTask.INVENTORY, topic, messageBody, this.client);
}
// Command/Wipe
if (topic.toLowerCase().contains("wipe")) {
new PoliciesAsyncTask().execute(context, PoliciesAsyncTask.WIPE, topic, messageBody);
}
// Command/Unenroll
if (topic.toLowerCase().contains("unenroll")) {
new PoliciesAsyncTask().execute(context, PoliciesAsyncTask.UNENROLL, topic, messageBody);
}
// Command/Lock
if (topic.toLowerCase().contains("lock")) {
new PoliciesAsyncTask().execute(context, PoliciesAsyncTask.LOCK, topic, messageBody);
}
// Command/Subscribe
if (topic.toLowerCase().contains("subscribe")) {
try {
JSONObject jsonObj = new JSONObject(messageBody);
if (jsonObj.has("subscribe")) {
JSONArray jsonTopics = jsonObj.getJSONArray("subscribe");
for (int i = 0; i < jsonTopics.length(); i++) {
JSONObject jsonTopic = jsonTopics.getJSONObject(i);
String channel = jsonTopic.getString("topic") + "/#";
if (channel == null || channel.contains("null")) {
mqttController.unsubscribe();
} else {
mqttController.subscribe(channel);
}
}
}
} catch (Exception ex) {
showDetailError(context, CommonErrorType.MQTT_SUBSCRIBE, ex.getMessage());
}
}
}
Aggregations