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

Commit

Permalink
fix(app): validate information of the app
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 8f2c6a5 commit 887cce5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
14 changes: 13 additions & 1 deletion app/src/main/java/org/flyve/mdm/agent/ui/InstallAppActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,20 @@ protected void onCreate(Bundle savedInstanceState) {
Application[] apps = appData.getApplicationsById(id);

if(apps.length > 0 && Helpers.isPackageInstalled(InstallAppActivity.this, apps[0].appPackage)) {
PackageManager pm = getPackageManager();
FlyveLog.d(apps[0].appPackage + " " + apps[0].appId);
finish();

// check if is a new version or newest
try {
PackageInfo packageInfo = pm.getPackageInfo(apps[0].appPackage, 0);
if (Integer.parseInt(apps[0].appVersionCode) <= packageInfo.versionCode) {
// is the same version of the app or older
finish();
}
} catch (Exception ex) {
FlyveLog.e(ex.getMessage());
finish();
}
} else {
try {
installApk(appPath);
Expand Down
21 changes: 17 additions & 4 deletions app/src/main/java/org/flyve/mdm/agent/utils/AppThreadManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import android.content.Context;

import org.eclipse.paho.android.service.MqttAndroidClient;
import org.flyve.mdm.agent.data.database.ApplicationData;
import org.flyve.mdm.agent.data.database.entity.Application;
import org.flyve.mdm.agent.services.PoliciesController;
import org.json.JSONObject;

Expand Down Expand Up @@ -88,11 +90,22 @@ public void process(Context context) {
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);
ApplicationData apps = new ApplicationData(context);
Application[] appsArray = apps.getApplicationsById(id);

// check if the app exists with same version or older
Boolean bDownload = true;
if(appsArray.length>0 && Integer.parseInt(versionCode) > Integer.parseInt(appsArray[0].appVersionCode)) {
bDownload = false;
}

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

0 comments on commit 887cce5

Please sign in to comment.