Search in sources :

Example 1 with Application

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);
    }
}
Also used : AppDataBase(org.flyve.mdm.agent.data.database.setup.AppDataBase) Application(org.flyve.mdm.agent.data.database.entity.Application) File(java.io.File) StorageFolder(org.flyve.mdm.agent.utils.StorageFolder)

Example 2 with Application

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);
}
Also used : AppDataBase(org.flyve.mdm.agent.data.database.setup.AppDataBase) Application(org.flyve.mdm.agent.data.database.entity.Application)

Example 3 with Application

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;
    }
}
Also used : AppDataBase(org.flyve.mdm.agent.data.database.setup.AppDataBase) Application(org.flyve.mdm.agent.data.database.entity.Application)

Example 4 with Application

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();
    }
}
Also used : PackageManager(android.content.pm.PackageManager) Bundle(android.os.Bundle) PackageInfo(android.content.pm.PackageInfo) ApplicationData(org.flyve.mdm.agent.data.database.ApplicationData) Application(org.flyve.mdm.agent.data.database.entity.Application) ActivityNotFoundException(android.content.ActivityNotFoundException)

Example 5 with Application

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);
    }
}
Also used : AppDataBase(org.flyve.mdm.agent.data.database.setup.AppDataBase) Application(org.flyve.mdm.agent.data.database.entity.Application)

Aggregations

Application (org.flyve.mdm.agent.data.database.entity.Application)9 AppDataBase (org.flyve.mdm.agent.data.database.setup.AppDataBase)4 PackageInfo (android.content.pm.PackageInfo)3 PackageManager (android.content.pm.PackageManager)3 ApplicationData (org.flyve.mdm.agent.data.database.ApplicationData)3 ActivityNotFoundException (android.content.ActivityNotFoundException)2 Intent (android.content.Intent)2 View (android.view.View)2 TextView (android.widget.TextView)2 Bundle (android.os.Bundle)1 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 AdapterView (android.widget.AdapterView)1 ImageButton (android.widget.ImageButton)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 File (java.io.File)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 EnrollmentHelper (org.flyve.mdm.agent.core.enrollment.EnrollmentHelper)1 PoliciesData (org.flyve.mdm.agent.data.database.PoliciesData)1