Search in sources :

Example 6 with AppDataBase

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);
}
Also used : AppDataBase(org.flyve.mdm.agent.data.database.setup.AppDataBase) File(java.io.File)

Example 7 with AppDataBase

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);
}
Also used : AppDataBase(org.flyve.mdm.agent.data.database.setup.AppDataBase) File(java.io.File) StorageFolder(org.flyve.mdm.agent.utils.StorageFolder)

Example 8 with AppDataBase

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());
            }
        }
    }
}
Also used : IMqttActionListener(org.eclipse.paho.client.mqttv3.IMqttActionListener) Topics(org.flyve.mdm.agent.data.database.entity.Topics) AppDataBase(org.flyve.mdm.agent.data.database.setup.AppDataBase) IMqttToken(org.eclipse.paho.client.mqttv3.IMqttToken)

Aggregations

AppDataBase (org.flyve.mdm.agent.data.database.setup.AppDataBase)8 Application (org.flyve.mdm.agent.data.database.entity.Application)4 File (java.io.File)3 IMqttActionListener (org.eclipse.paho.client.mqttv3.IMqttActionListener)2 IMqttToken (org.eclipse.paho.client.mqttv3.IMqttToken)2 Topics (org.flyve.mdm.agent.data.database.entity.Topics)2 StorageFolder (org.flyve.mdm.agent.utils.StorageFolder)2 ArrayList (java.util.ArrayList)1 TopicsData (org.flyve.mdm.agent.data.database.TopicsData)1