Search in sources :

Example 11 with MqttData

use of org.flyve.mdm.agent.data.database.MqttData in project android-mdm-agent by flyve-mdm.

the class SplashActivity method onCreate.

/**
 * Called when the activity is starting
 * It shows the UI with the Splash screen
 * @param savedInstanceState if the activity is being re-initialized, it contains the data it most recently supplied
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    MqttData cache = new MqttData(SplashActivity.this);
    // if broker is on cache open the main activity
    String broker = cache.getBroker();
    if (!broker.isEmpty()) {
        // if user is enrolled show landing screen
        FlyveLog.d(cache.getSessionToken());
        setContentView(R.layout.activity_splash_enrolled);
        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                openMain();
            }
        }, TIME);
        return;
    }
    // if user is not enrolled show help
    setContentView(R.layout.activity_splash);
    setupUI();
    FloatingActionButton btnScan = findViewById(R.id.btnScan);
    btnScan.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            SplashActivity.this.startActivityForResult(new Intent(SplashActivity.this, ScanActivity.class), REQUEST_CODE_SCAN);
        }
    });
    TextView txtVersion = findViewById(R.id.txtVersion);
    txtVersion.setText(MDMAgent.getCompleteVersion());
}
Also used : MqttData(org.flyve.mdm.agent.data.database.MqttData) Handler(android.os.Handler) FloatingActionButton(android.support.design.widget.FloatingActionButton) Intent(android.content.Intent) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View)

Example 12 with MqttData

use of org.flyve.mdm.agent.data.database.MqttData in project android-mdm-agent by flyve-mdm.

the class Inventory method getJSONInventory.

public void getJSONInventory(Context context, InventoryTask.OnTaskCompleted callback) {
    InventoryTask inventoryTask = new InventoryTask(context, APP_VERSION, true);
    MqttData cache = new MqttData(context);
    String invitationToken = cache.getInvitationToken();
    if (!invitationToken.isEmpty()) {
        String tag = "invitation_" + invitationToken;
        FlyveLog.i(tag);
        inventoryTask.setTag(tag);
    }
    inventoryTask.getJSON(callback);
}
Also used : MqttData(org.flyve.mdm.agent.data.database.MqttData) InventoryTask(org.flyve.inventory.InventoryTask)

Example 13 with MqttData

use of org.flyve.mdm.agent.data.database.MqttData in project android-mdm-agent by flyve-mdm.

the class Inventory method getXMLInventory.

public void getXMLInventory(Context context, InventoryTask.OnTaskCompleted callback) {
    InventoryTask inventoryTask = new InventoryTask(context, APP_VERSION, true);
    MqttData cache = new MqttData(context);
    String invitationToken = cache.getInvitationToken();
    if (!invitationToken.isEmpty()) {
        String tag = "invitation_" + invitationToken;
        FlyveLog.i(tag);
        inventoryTask.setTag(tag);
    }
    inventoryTask.getXML(callback);
}
Also used : MqttData(org.flyve.mdm.agent.data.database.MqttData) InventoryTask(org.flyve.inventory.InventoryTask)

Example 14 with MqttData

use of org.flyve.mdm.agent.data.database.MqttData in project android-mdm-agent by flyve-mdm.

the class ConnectionHTTP method killSession.

public static void killSession(final Context context, final String sessionToken) {
    Thread t = new Thread(new Runnable() {

        public void run() {
            try {
                Routes routes = new Routes(context);
                MqttData cache = new MqttData(context);
                String url = routes.pluginFlyvemdmAgent(cache.getAgentId());
                URL dataURL = new URL(url);
                HttpURLConnection conn = (HttpURLConnection) dataURL.openConnection();
                conn.setRequestMethod("GET");
                conn.setConnectTimeout(timeout);
                conn.setReadTimeout(readtimeout);
                HashMap<String, String> header = new HashMap();
                header.put("Accept", "application/octet-stream");
                header.put("Content-Type", "application/json");
                header.put("Session-Token", sessionToken);
                StringBuilder logHeader = new StringBuilder();
                if (header != null) {
                    for (Map.Entry<String, String> entry : header.entrySet()) {
                        logHeader.append("- " + entry.getKey() + " : " + entry.getValue() + "\n");
                        conn.setRequestProperty(entry.getKey(), entry.getValue());
                    }
                } else {
                    logHeader.append("Empty");
                }
                if (conn.getResponseCode() >= 400) {
                    InputStream is = conn.getErrorStream();
                    String result = inputStreamToString(is);
                    Log(result);
                    return;
                }
                InputStream is = conn.getInputStream();
                final String requestResponse = inputStreamToString(is);
                String response = "\n URL:\n" + url + "\n\n Method:\n" + conn.getRequestMethod() + "\n\n Code:\n" + conn.getResponseCode() + " " + conn.getResponseMessage() + "\n\n Header:\n" + logHeader + "\n\n Response:\n" + requestResponse + "\n\n";
                LogDebug(response);
            } catch (final Exception ex) {
                ConnectionHTTP.runOnUI(new Runnable() {

                    public void run() {
                        FlyveLog.e(ConnectionHTTP.class.getClass().getName() + ", getWebData", ex.getClass() + " : " + ex.getMessage());
                    }
                });
            }
        }
    });
    t.start();
}
Also used : MqttData(org.flyve.mdm.agent.data.database.MqttData) HttpURLConnection(java.net.HttpURLConnection) HashMap(java.util.HashMap) InputStream(java.io.InputStream) Routes(org.flyve.mdm.agent.core.Routes) URL(java.net.URL) IOException(java.io.IOException)

Aggregations

MqttData (org.flyve.mdm.agent.data.database.MqttData)14 JSONObject (org.json.JSONObject)5 View (android.view.View)4 Routes (org.flyve.mdm.agent.core.Routes)4 Intent (android.content.Intent)3 InventoryTask (org.flyve.inventory.InventoryTask)3 FloatingActionButton (android.support.design.widget.FloatingActionButton)2 TextView (android.widget.TextView)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 HttpURLConnection (java.net.HttpURLConnection)2 URL (java.net.URL)2 HashMap (java.util.HashMap)2 Hardware (org.flyve.inventory.categories.Hardware)2 UserData (org.flyve.mdm.agent.data.localstorage.UserData)2 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 Location (android.location.Location)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1