Search in sources :

Example 1 with EnrollmentHelper

use of org.flyve.mdm.agent.core.enrollment.EnrollmentHelper in project android-mdm-agent by flyve-mdm.

the class PoliciesController method installPackage.

/**
 * Application
 */
public void installPackage(final String deployApp, final String id, final String versionCode, final String taskId) {
    EnrollmentHelper sToken = new EnrollmentHelper(this.context);
    sToken.getActiveSessionToken(new EnrollmentHelper.EnrollCallBack() {

        @Override
        public void onSuccess(String sessionToken) {
            try {
                FlyveLog.d("Install package: " + deployApp + " id: " + id);
                PoliciesFiles policiesFiles = new PoliciesFiles(PoliciesController.this.context);
                policiesFiles.execute("package", deployApp, id, sessionToken);
                broadcastReceivedLog(Helpers.broadCastMessage(MQTT_SEND, "Install package", "name: " + deployApp + " id: " + id));
                // return the status of the task
                sendTaskStatus(taskId, FEEDBACK_RECEIVED);
            } catch (Exception ex) {
                FlyveLog.e(ex.getMessage());
                broadcastReceivedLog(Helpers.broadCastMessage(ERROR, "Error on getActiveSessionToken", ex.getMessage()));
                // return the status of the task
                sendTaskStatus(taskId, FEEDBACK_FAILED);
            }
        }

        @Override
        public void onError(String error) {
            FlyveLog.e(error);
            broadcastReceivedLog(Helpers.broadCastMessage(ERROR, ERROR, error));
            broadcastReceivedLog("Application fail: " + error);
            // return the status of the task
            sendTaskStatus(taskId, FEEDBACK_FAILED);
        }
    });
}
Also used : EnrollmentHelper(org.flyve.mdm.agent.core.enrollment.EnrollmentHelper)

Example 2 with EnrollmentHelper

use of org.flyve.mdm.agent.core.enrollment.EnrollmentHelper in project android-mdm-agent by flyve-mdm.

the class PermissionModel method generateInventory.

@Override
public void generateInventory(final Context context) {
    final ProgressDialog progress = ProgressDialog.show(context, context.getString(R.string.app_name), context.getString(R.string.creating_inventory), true);
    Inventory inventory = new Inventory();
    inventory.getJSONInventory(context, new InventoryTask.OnTaskCompleted() {

        @Override
        public void onTaskSuccess(String s) {
            FlyveLog.i(s);
        }

        @Override
        public void onTaskError(Throwable throwable) {
            FlyveLog.e(this.getClass().getName() + ", generateInventory", throwable.getMessage());
        }
    });
    inventory.getXMLInventory(context, new InventoryTask.OnTaskCompleted() {

        @Override
        public void onTaskSuccess(final String s) {
            progress.setMessage(context.getString(R.string.creating_session));
            EnrollmentHelper sessionToken = new EnrollmentHelper(context);
            sessionToken.getActiveSessionTokenEnrollment(new EnrollmentHelper.EnrollCallBack() {

                @Override
                public void onSuccess(String data) {
                    // Active EnrollmentHelper Token is stored on cache
                    progress.dismiss();
                    FlyveLog.d(s);
                    presenter.inventorySuccess(s);
                }

                @Override
                public void onError(int type, String error) {
                    progress.dismiss();
                    presenter.showSnackError(type, error);
                }
            });
        }

        @Override
        public void onTaskError(Throwable throwable) {
            progress.dismiss();
            presenter.showSnackError(CommonErrorType.PERMISSION_XML_INVENTORY, context.getString(R.string.inventory_fail) + throwable.getMessage());
        }
    });
}
Also used : InventoryTask(org.flyve.inventory.InventoryTask) EnrollmentHelper(org.flyve.mdm.agent.core.enrollment.EnrollmentHelper) ProgressDialog(android.app.ProgressDialog) Inventory(org.flyve.mdm.agent.utils.Inventory)

Example 3 with EnrollmentHelper

use of org.flyve.mdm.agent.core.enrollment.EnrollmentHelper in project android-mdm-agent by flyve-mdm.

the class PoliciesController method downloadFile.

/**
 * Files
 * {"file":[{"deployFile":"%SDCARD%/","id":"1","version":"1","taskId":"1"}]}
 */
public void downloadFile(final String deployFile, final String id, final String versionCode, final String taskId) {
    EnrollmentHelper sToken = new EnrollmentHelper(this.context);
    sToken.getActiveSessionToken(new EnrollmentHelper.EnrollCallBack() {

        @Override
        public void onSuccess(String sessionToken) {
            PoliciesFiles policiesFiles = new PoliciesFiles(PoliciesController.this.context);
            if ("true".equals(policiesFiles.execute("file", deployFile, id, sessionToken))) {
                FlyveLog.d("File was stored on: " + deployFile);
                broadcastReceivedLog(Helpers.broadCastMessage(MQTT_SEND, "File was stored on", deployFile));
                // return the status of the task
                sendTaskStatus(taskId, FEEDBACK_DONE);
            }
        }

        @Override
        public void onError(String error) {
            FlyveLog.e(error);
            broadcastReceivedLog(Helpers.broadCastMessage(ERROR, "Error on applicationOnDevices", error));
            // return the status of the task
            sendTaskStatus(taskId, FEEDBACK_FAILED);
        }
    });
}
Also used : EnrollmentHelper(org.flyve.mdm.agent.core.enrollment.EnrollmentHelper)

Example 4 with EnrollmentHelper

use of org.flyve.mdm.agent.core.enrollment.EnrollmentHelper in project android-mdm-agent by flyve-mdm.

the class PoliciesAsyncTask method pluginHttpResponse.

public static void pluginHttpResponse(final Context context, final String url, final String data) {
    Helpers.storeLog("fcm", "http response payload", data);
    EnrollmentHelper enrollmentHelper = new EnrollmentHelper(context);
    enrollmentHelper.getActiveSessionToken(new EnrollmentHelper.EnrollCallBack() {

        @Override
        public void onSuccess(String sessionToken) {
            ConnectionHTTP.sendHttpResponse(context, url, data, sessionToken, new ConnectionHTTP.DataCallback() {

                @Override
                public void callback(String data) {
                    Helpers.storeLog("fcm", "http response from url", data);
                }
            });
        }

        @Override
        public void onError(int type, String error) {
            Helpers.storeLog("fcm", "active session fail", data);
        }
    });
}
Also used : EnrollmentHelper(org.flyve.mdm.agent.core.enrollment.EnrollmentHelper)

Example 5 with EnrollmentHelper

use of org.flyve.mdm.agent.core.enrollment.EnrollmentHelper in project android-mdm-agent by flyve-mdm.

the class BasePolicies method sendTaskStatusbyHttp.

public static void sendTaskStatusbyHttp(final Context context, final String status, final String taskId) {
    EnrollmentHelper enrollmentHelper = new EnrollmentHelper(context);
    enrollmentHelper.getActiveSessionToken(new EnrollmentHelper.EnrollCallBack() {

        @Override
        public void onSuccess(String sessionToken) {
            Helpers.storeLog("fcm", "http response session token", sessionToken);
            String payload = "";
            try {
                JSONObject jsonPayload = new JSONObject();
                jsonPayload.put("status", status);
                JSONObject jsonInput = new JSONObject();
                jsonInput.put("input", jsonPayload);
                payload = jsonInput.toString();
            } catch (Exception ex) {
                Helpers.storeLog("fcm", "Error sending status http", ex.getMessage());
            }
            ConnectionHTTP.sendHttpResponsePolicies(context, taskId, payload, sessionToken, new ConnectionHTTP.DataCallback() {

                @Override
                public void callback(String data) {
                    Helpers.storeLog("fcm", "http response from policy", data);
                }
            });
        }

        @Override
        public void onError(int type, String error) {
            Helpers.storeLog("fcm", "problem with session token", error);
        }
    });
}
Also used : EnrollmentHelper(org.flyve.mdm.agent.core.enrollment.EnrollmentHelper) JSONObject(org.json.JSONObject)

Aggregations

EnrollmentHelper (org.flyve.mdm.agent.core.enrollment.EnrollmentHelper)8 JSONObject (org.json.JSONObject)3 ProgressDialog (android.app.ProgressDialog)1 InventoryTask (org.flyve.inventory.InventoryTask)1 ApplicationData (org.flyve.mdm.agent.data.database.ApplicationData)1 Application (org.flyve.mdm.agent.data.database.entity.Application)1 Inventory (org.flyve.mdm.agent.utils.Inventory)1