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

WIP Improve apk managment #770

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/main/assets/about.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
about.version=
about.build=3789
about.date=mer. nov. 20 13:43:16 2019
about.date=jeu. nov. 21 08:51:49 2019
about.commit=
about.commitFull=
about.github=https://github.com/flyve-mdm/flyve-mdm-android-agent
39 changes: 20 additions & 19 deletions app/src/main/java/org/flyve/mdm/agent/policies/PoliciesFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.flyve.mdm.agent.core.Routes;
import org.flyve.mdm.agent.data.database.entity.Application;
import org.flyve.mdm.agent.data.database.setup.AppDataBase;
import org.flyve.mdm.agent.receivers.AppReceiver;
import org.flyve.mdm.agent.utils.ConnectionHTTP;
import org.flyve.mdm.agent.utils.FlyveLog;
import org.flyve.mdm.agent.utils.Helpers;
Expand Down Expand Up @@ -133,15 +134,17 @@ public void downloadFile(String path, String id, String sessionToken, String tas
/**
* Download, save and install app
* @param appName String package of the app
* @param id String Id from
* @param sessionToken
* @param id String Id of app
* @param sessionToken String token of user
* @param taskId string String Id of task
* @param versionCode string version code of app
*/
public void downloadApk(String appName, String id, String sessionToken, String taskId, String versionCode) {

//prevent CPU from going off if the user presses the power button during download
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName());
wl.acquire();
wl.acquire(10*60*1000L /*10 minutes*/);

String filePath = "";
try {
Expand All @@ -156,13 +159,12 @@ public void downloadApk(String appName, String id, String sessionToken, String
if(completeFilePath.isEmpty()) {
this.status = BasePolicies.FEEDBACK_FAILED;
} else {
if(Helpers.isSystemApp(context).equalsIgnoreCase("1")) {
// Silently for System apps
this.status = BasePolicies.FEEDBACK_WAITING;
Helpers.installApkSilently(completeFilePath);
} else {
// Regular app
this.status = BasePolicies.FEEDBACK_WAITING;
// Try install silently for System apps
this.status = BasePolicies.FEEDBACK_WAITING;
if(Helpers.installApkSilently(completeFilePath)){
new AppReceiver().onInstallApp(appName,context);
this.status = BasePolicies.FEEDBACK_DONE;
}else{
Helpers.installApk(context, id, completeFilePath, taskId, versionCode);
}
}
Expand All @@ -175,7 +177,7 @@ public void downloadApk(String appName, String id, String sessionToken, String
* @return String complete path with name of the file
*/
private String download(final String url, final String path, String sessionToken, String taskId) {
HashMap<String, String> header = new HashMap();
HashMap<String, String> header = new HashMap<>();
header.put("Session-Token", sessionToken);

String data = ConnectionHTTP.getSyncWebData(url, "GET",header);
Expand Down Expand Up @@ -333,16 +335,15 @@ public void removeApk(String mPackage, final String taskId){
dataBase.applicationDao().updateTaskId(mPackage, this.taskId);
}

//is priv app uninstall silently
if(Helpers.isSystemApp(context).equalsIgnoreCase("1")) {
// Silently for System apps
this.status = BasePolicies.FEEDBACK_WAITING;
Helpers.uninstallApkSilently(mPackage);
} else {
//use activity to install apk
this.status = BasePolicies.FEEDBACK_WAITING;
// Silently for System apps
this.status = BasePolicies.FEEDBACK_WAITING;
if(Helpers.uninstallApkSilently(mPackage)){
new AppReceiver().onRemoveApp(mPackage,context);
this.status = BasePolicies.FEEDBACK_DONE;
}else{
Helpers.uninstallApk(context,mPackage);
}

BasePolicies.sendTaskStatusbyHttp(this.context, this.status, this.taskId);
}

Expand Down