use of org.flyve.mdm.agent.data.database.setup.AppDataBase in project android-mdm-agent by flyve-mdm.
the class PoliciesFiles method addFile.
private void addFile(File file, String fileName, String taskId) {
org.flyve.mdm.agent.data.database.entity.File dataFile = new org.flyve.mdm.agent.data.database.entity.File();
dataFile.fileName = fileName;
dataFile.filePath = file.getAbsolutePath();
dataFile.taskid = taskId;
AppDataBase dataBase = AppDataBase.getAppDatabase(context);
dataBase.FileDao().deleteByName(fileName);
dataBase.FileDao().insert(dataFile);
}
use of org.flyve.mdm.agent.data.database.setup.AppDataBase in project android-mdm-agent by flyve-mdm.
the class PoliciesFiles method removeFile.
/**
* Remove the file according to the given path
* @param filePath
* @return boolean true if file deleted, false otherwise
*/
public void removeFile(String filePath, final String taskId) {
this.taskId = taskId;
try {
String realPath = new StorageFolder(context).convertPath(filePath);
File file = new File(realPath);
if (file.delete()) {
FlyveLog.d("Remove file: " + filePath);
// remove file from DB
AppDataBase dataBase = AppDataBase.getAppDatabase(context);
dataBase.FileDao().deleteByFilePath(file.getAbsolutePath());
this.status = BasePolicies.FEEDBACK_DONE;
} else {
this.status = BasePolicies.FEEDBACK_FAILED;
}
} catch (Exception ex) {
FlyveLog.e(this.getClass().getName() + ", removeFile", ex.getMessage() + "\n" + filePath);
this.status = BasePolicies.FEEDBACK_FAILED;
}
BasePolicies.sendTaskStatusbyHttp(this.context, this.status, this.taskId);
}
use of org.flyve.mdm.agent.data.database.setup.AppDataBase in project android-mdm-agent by flyve-mdm.
the class MqttController method unsubscribe.
/**
* Unsubscribe to the topic
* When come from MQTT has a format like this {"subscribe":[{"topic":null}]}
*/
public void unsubscribe() {
final AppDataBase dataBase = AppDataBase.getAppDatabase(context);
List<Topics> topics = dataBase.TopicsDao().getFleets();
if (!topics.isEmpty()) {
for (int i = 0; i < topics.size(); i++) {
final Topics topicToUnsubscribe = topics.get(i);
try {
IMqttToken subToken = client.unsubscribe(topicToUnsubscribe.topic);
subToken.setActionCallback(new IMqttActionListener() {
@Override
public void onSuccess(IMqttToken asyncActionToken) {
FlyveLog.d("Unsubscribe from fleet " + topicToUnsubscribe.topic);
dataBase.TopicsDao().delete(topicToUnsubscribe);
}
@Override
public void onFailure(IMqttToken asyncActionToken, Throwable exception) {
// The unsubscription could not be performed, maybe the user was not
// authorized to subscribe on the specified topic e.g. using wildcards
String errorMessage = " unknown";
if (exception != null) {
errorMessage = exception.getMessage();
Log.d("Unsubscribe", "Error", exception);
}
FlyveLog.e(this.getClass().getName() + ", unsubscribe", "ERROR on unsubscribe: " + errorMessage);
broadcastReceivedLog(ERROR, "Error on unsubscribe", errorMessage);
}
});
} catch (Exception ex) {
FlyveLog.e(this.getClass().getName() + ", unsubscribe", ex.getMessage());
}
}
}
}
Aggregations