Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

Commit

Permalink
fix(apps): add thread manager
Browse files Browse the repository at this point in the history
Signed-off-by: Rafa Hernandez <[email protected]>
  • Loading branch information
rafaelje authored and Hector Rondon committed Sep 21, 2018
1 parent 136ae0c commit c526ea7
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions app/src/main/java/org/flyve/mdm/agent/utils/AppThreadManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package org.flyve.mdm.agent.utils;

/*
* Copyright © 2018 Teclib. All rights reserved.
*
* This file is part of flyve-mdm-android
*
* flyve-mdm-android is a subproject of Flyve MDM. Flyve MDM is a mobile
* device management software.
*
* Flyve MDM is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* Flyve MDM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* ------------------------------------------------------------------------------
* @author Rafael Hernandez
* @date 19/9/18
* @copyright Copyright © 2018 Teclib. All rights reserved.
* @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
* @link https://github.com/flyve-mdm/flyve-mdm-android
* @link https://flyve-mdm.com
* ------------------------------------------------------------------------------
*/

import android.content.Context;

import org.eclipse.paho.android.service.MqttAndroidClient;
import org.flyve.mdm.agent.services.PoliciesController;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class AppThreadManager {

private static AppThreadManager singleton;
private int index;
private MqttAndroidClient client;
private Boolean lock;

private List<JSONObject> item;

public static AppThreadManager getAppThreadManager(MqttAndroidClient client) {
if(singleton==null) {
singleton = new AppThreadManager(client);
}
return singleton;
}

private AppThreadManager(MqttAndroidClient client) {
this.item = new ArrayList<>();
this.index = 0;
this.client = client;
this.lock = false;
}

public void add(Context context, JSONObject jsonObj) {
item.add(jsonObj);
process(context);
}

public void finishProcess(Context context) {
if(!item.isEmpty()) {
item.remove(0);
}
this.lock = false;

FlyveLog.i("Finish Processing");
process(context);

}

public void process(Context context) {
if(!item.isEmpty() && !lock) {
this.lock = true;

FlyveLog.i("Processing item 0 from item size -> " + item.size());
JSONObject jsonObj = item.get(0);

try {
String deployApp = jsonObj.getString("deployApp");
String id = jsonObj.getString("id");
String versionCode = jsonObj.getString("versionCode");
String taskId = jsonObj.getString("taskId");

// execute the policy
PoliciesController policiesController = new PoliciesController(context, this.client);
policiesController.installPackage(deployApp, id, versionCode, taskId);
} catch (Exception ex) {
FlyveLog.e("");
}
}
}
}

0 comments on commit c526ea7

Please sign in to comment.