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

Commit

Permalink
fix(application): download multiples apps
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelje authored and ajsb85 committed Nov 26, 2017
1 parent f66b919 commit fc9cddb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
9 changes: 2 additions & 7 deletions app/src/main/java/org/flyve/mdm/agent/utils/FilesHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,6 @@ private String getFile(JSONObject jsonObjDownload, String path, String url, Stri
String fileName = "";

try {

String id = jsonObjDownload.getString("id");

// Both has name
if (jsonObjDownload.has("name")) {
fileName = jsonObjDownload.getString("name");
Expand All @@ -283,8 +280,8 @@ private String getFile(JSONObject jsonObjDownload, String path, String url, Stri
FlyveLog.d("File exists");
return "";
}
String urlLocal = routes.pluginFlyvemdmPackage(id, sessionToken);
Boolean isSave = ConnectionHTTP.getSyncFile(urlLocal, filePath);

Boolean isSave = ConnectionHTTP.getSyncFile(url, filePath);
if (isSave) {
Helpers.sendToNotificationBar(context, context.getResources().getString(R.string.download_file_ready));
FlyveLog.d("Download ready");
Expand All @@ -298,8 +295,6 @@ private String getFile(JSONObject jsonObjDownload, String path, String url, Stri
FlyveLog.e(ex.getMessage());
return "";
}


}

/**
Expand Down
20 changes: 10 additions & 10 deletions app/src/main/java/org/flyve/mdm/agent/utils/MQTTHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ public void applicationOnDevices(final JSONObject json) {
@Override
public void onSuccess(String data) {
try {
JSONArray checkInstall = json.getJSONArray("application");
appWork(checkInstall, data);
JSONArray appsInstall = json.getJSONArray("application");
appWork(appsInstall, data);
} catch (Exception ex) {
FlyveLog.e(ex.getMessage());
broadcastReceivedLog(Helpers.broadCastMessage(ERROR, "Error on getActiveSessionToken", ex.getMessage()));
Expand All @@ -377,29 +377,29 @@ public void onError(String error) {

/**
* Check if the App is to be installed or uninstalled
* @param checkInstall if the object has remove or deploy app
* @param appsInstall if the object has remove or deploy app
* @param sessionToken the session token
*/
public void appWork(JSONArray checkInstall, String sessionToken) throws Exception {
public void appWork(JSONArray appsInstall, String sessionToken) throws Exception {
AppInfo appInfo = new AppInfo(this.context);
FilesHelper filesHelper = new FilesHelper(this.context);

for(int i=0; i<checkInstall.length(); i++) {
for(int i=0; i<appsInstall.length(); i++) {

if(checkInstall.getJSONObject(i).has(REMOVE_APP)){
if(appsInstall.getJSONObject(i).has(REMOVE_APP)){
FlyveLog.d("uninstall apps");

JSONObject jsonApp = checkInstall.getJSONObject(i);
JSONObject jsonApp = appsInstall.getJSONObject(i);
if(appInfo.isInstall(jsonApp.getString(REMOVE_APP))) {
FilesHelper.removeApk(this.context, jsonApp.getString(REMOVE_APP));
broadcastReceivedLog(Helpers.broadCastMessage(MQTT_SEND, "Remove app", "Package: " + jsonApp.getString(REMOVE_APP)));
}
}

if(checkInstall.getJSONObject(i).has("deployApp")){
if(appsInstall.getJSONObject(i).has("deployApp")){
FlyveLog.d("install apps");

JSONObject jsonApp = checkInstall.getJSONObject(i);
JSONObject jsonApp = appsInstall.getJSONObject(i);

String idlist;
String packageNamelist;
Expand All @@ -412,7 +412,7 @@ public void appWork(JSONArray checkInstall, String sessionToken) throws Exceptio
versionCode = jsonApp.getString("versionCode");

if(!appInfo.isInstall(packageNamelist,versionCode)){
filesHelper.downloadApk(packageNamelist, versionCode, sessionToken);
filesHelper.downloadApk(packageNamelist, idlist, sessionToken);
broadcastReceivedLog(Helpers.broadCastMessage(MQTT_SEND, "Download app", "Package: " + packageNamelist));
}
}
Expand Down

0 comments on commit fc9cddb

Please sign in to comment.