diff --git a/app/src/main/java/org/flyve/mdm/agent/ui/InstallAppActivity.java b/app/src/main/java/org/flyve/mdm/agent/ui/InstallAppActivity.java index c1a78877ea..dcdef30fa5 100644 --- a/app/src/main/java/org/flyve/mdm/agent/ui/InstallAppActivity.java +++ b/app/src/main/java/org/flyve/mdm/agent/ui/InstallAppActivity.java @@ -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); diff --git a/app/src/main/java/org/flyve/mdm/agent/utils/AppThreadManager.java b/app/src/main/java/org/flyve/mdm/agent/utils/AppThreadManager.java index 7f6e5f4a43..9b606834bd 100644 --- a/app/src/main/java/org/flyve/mdm/agent/utils/AppThreadManager.java +++ b/app/src/main/java/org/flyve/mdm/agent/utils/AppThreadManager.java @@ -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; @@ -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()); } } }