use of org.flyve.mdm.agent.data.database.entity.Application in project android-mdm-agent by flyve-mdm.
the class AppReceiver method onRemoveApp.
public void onRemoveApp(String mPackage, Context context) {
String taskId = "0";
AppDataBase dataBase = AppDataBase.getAppDatabase(context);
// retrieve taskId from applicationDAO
Application[] appsArray = dataBase.applicationDao().getApplicationByPackageName(mPackage);
// app installed by agent
if (appsArray.length == 1) {
taskId = appsArray[0].taskId;
FlyveLog.d("Retrieve TaskId -> " + appsArray[0].taskId);
// remove file from DB
FlyveLog.d("Remove File from DB -> " + mPackage);
dataBase.FileDao().deleteByName(mPackage + ".apk");
dataBase.FileDao().deleteByName(mPackage + ".upk");
// remove app from DB
FlyveLog.d("Remove App from DB -> " + mPackage);
dataBase.applicationDao().deleteByPackageName(mPackage);
// try to remove Package from device
String filePath = "";
try {
filePath = new StorageFolder(context).getApkDir();
filePath = filePath + mPackage + ".apk";
// validating if file exists
File fileApk = new File(filePath);
if (!fileApk.exists()) {
filePath = filePath + mPackage + ".upk";
}
// remove package from device
String realPath = new StorageFolder(context).convertPath(filePath);
File file = new File(realPath);
if (file.delete()) {
FlyveLog.d("Successful removal of package : " + filePath);
} else {
FlyveLog.d("Can't remove Package : " + filePath);
}
} catch (Exception ex) {
FlyveLog.e(this.getClass().getName() + ", removeApk", ex.getMessage());
}
BasePolicies.sendTaskStatusbyHttp(context, BasePolicies.FEEDBACK_DONE, taskId);
}
}
use of org.flyve.mdm.agent.data.database.entity.Application in project android-mdm-agent by flyve-mdm.
the class PoliciesFiles method removeApk.
/**
* Uninstall the Android Package
* @param mPackage to uninstall
* @return int if it succeed 1, otherwise 0
*/
public void removeApk(String mPackage, final String taskId) {
this.taskId = taskId;
this.status = BasePolicies.FEEDBACK_WAITING;
// update taskID from DAO app
AppDataBase dataBase = AppDataBase.getAppDatabase(context);
Application[] appsArray = dataBase.applicationDao().getApplicationByPackageName(mPackage);
// app installed by agent
if (appsArray.length == 1) {
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;
Helpers.uninstallApk(context, mPackage);
}
BasePolicies.sendTaskStatusbyHttp(this.context, this.status, this.taskId);
}
use of org.flyve.mdm.agent.data.database.entity.Application in project android-mdm-agent by flyve-mdm.
the class Helpers method uninstallApk.
public static Boolean uninstallApk(Context context, String mPackage) {
// check if the app is installed
AppDataBase dataBase = AppDataBase.getAppDatabase(context);
Application[] appsArray = dataBase.applicationDao().getApplicationByPackageName(mPackage);
if (appsArray.length == 0 || !Helpers.isPackageInstalled(context, appsArray[0].appPackage)) {
FlyveLog.d("This app is already uninstalled: " + appsArray[0].appName);
return true;
} else {
// add notification
Helpers.sendToNotificationBar(context, appsArray[0].id, context.getString(R.string.app_need_to_be_uninstall), appsArray[0].appName, true, MainActivity.class, "RemoveApp");
return false;
}
}
use of org.flyve.mdm.agent.data.database.entity.Application in project android-mdm-agent by flyve-mdm.
the class InstallAppActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_install_app);
Bundle extras = getIntent().getExtras();
if (extras != null) {
id = extras.getString("APP_ID");
appPath = extras.getString("APP_PATH");
appData = new ApplicationData(InstallAppActivity.this);
// check if the app is installed
Application[] apps = appData.getApplicationsById(id);
if (apps.length > 0 && Helpers.isPackageInstalled(InstallAppActivity.this, apps[0].appPackage)) {
PackageManager pm = getPackageManager();
// 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();
} else {
installApk(appPath);
}
} catch (Exception ex) {
FlyveLog.e(this.getClass().getName() + ", onCreate", ex.getMessage());
finish();
}
} else {
try {
installApk(appPath);
} catch (Exception ex) {
FlyveLog.e(this.getClass().getName() + ", onCreate", ex.getMessage());
}
}
} else {
finish();
}
}
use of org.flyve.mdm.agent.data.database.entity.Application in project android-mdm-agent by flyve-mdm.
the class AppReceiver method onInstallApp.
public void onInstallApp(String mPackage, Context context) {
// retrieve data from applicationDAO
AppDataBase dataBase = AppDataBase.getAppDatabase(context);
Application[] appsArray = dataBase.applicationDao().getApplicationByPackageName(mPackage);
// app installed by agent update internal status and send status to flyveMDM
if (appsArray.length == 1) {
dataBase.applicationDao().updateStatus(Integer.toString(appsArray[0].id), "2");
BasePolicies.sendTaskStatusbyHttp(context, BasePolicies.FEEDBACK_DONE, appsArray[0].taskId);
}
}
Aggregations