Search in sources :

Example 6 with Application

use of org.flyve.mdm.agent.data.database.entity.Application in project android-mdm-agent by flyve-mdm.

the class FragmentAppList method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_app_list, container, false);
    pb = v.findViewById(R.id.progressBar);
    txtNoData = v.findViewById(R.id.txtNoData);
    final SwipeRefreshLayout swipeLayout = v.findViewById(R.id.swipe_container);
    swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            swipeLayout.setRefreshing(false);
            loadData();
        }
    });
    lst = v.findViewById(R.id.lst);
    lst.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            Application app = apps[i];
            Intent intent = new Intent(FragmentAppList.this.getContext(), InstallAppActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.putExtra("APP_ID", app.appId);
            intent.putExtra("APP_PATH", app.appPath);
            intent.putExtra("TASK_ID", app.taskId);
            FragmentAppList.this.getContext().startActivity(intent);
        }
    });
    loadData();
    return v;
}
Also used : AdapterView(android.widget.AdapterView) Intent(android.content.Intent) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) Application(org.flyve.mdm.agent.data.database.entity.Application)

Example 7 with Application

use of org.flyve.mdm.agent.data.database.entity.Application in project android-mdm-agent by flyve-mdm.

the class DeployAppPolicy method process.

@Override
protected boolean process() {
    try {
        JSONObject jsonObj = new JSONObject(message);
        final String deployApp = jsonObj.getString("deployApp");
        final String id = jsonObj.getString("id");
        final String versionCode = jsonObj.getString("versionCode");
        final String taskId = jsonObj.getString("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) {
            EnrollmentHelper sToken = new EnrollmentHelper(this.context);
            sToken.getActiveSessionToken(new EnrollmentHelper.EnrollCallBack() {

                @Override
                public void onSuccess(String sessionToken) {
                    try {
                        FlyveLog.d("Download package: " + deployApp + " id: " + id);
                        PoliciesFiles policiesFiles = new PoliciesFiles(context);
                        policiesFiles.execute("package", deployApp, id, sessionToken, taskId, versionCode);
                    } catch (Exception ex) {
                        FlyveLog.e(this.getClass().getName() + ", installPackage", ex.getMessage());
                    }
                }

                @Override
                public void onError(int type, String error) {
                    FlyveLog.e(this.getClass().getName() + ", installPackage", error);
                }
            });
        }
        return true;
    } catch (Exception ex) {
        FlyveLog.e(this.getClass().getName() + ", process", ex.getMessage());
        return false;
    }
}
Also used : EnrollmentHelper(org.flyve.mdm.agent.core.enrollment.EnrollmentHelper) JSONObject(org.json.JSONObject) ApplicationData(org.flyve.mdm.agent.data.database.ApplicationData) Application(org.flyve.mdm.agent.data.database.entity.Application)

Example 8 with Application

use of org.flyve.mdm.agent.data.database.entity.Application in project android-mdm-agent by flyve-mdm.

the class ApplicationsAdapter method getView.

/**
 * Get a View that displays the data at the specified position
 * @param position of the item within the adapter's data set of the item whose View we want
 * @param convertView the old View to reuse, if possible
 * @param parent the parent that this View will eventually be attached to
 * @return View a View corresponding to the data at the specified position
 */
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View vi = inflater.inflate(R.layout.list_item_application, null);
    final Application app;
    try {
        app = data[position];
    } catch (Exception ex) {
        FlyveLog.e(this.getClass().getName() + ", getView", ex.getMessage());
        return vi;
    }
    TextView txtStatus = vi.findViewById(R.id.txtStatus);
    ImageButton img_trash = vi.findViewById(R.id.btnUninstall);
    String status = "";
    if (Helpers.isPackageInstalled(parent.getContext(), app.appPackage)) {
        try {
            PackageManager pm = parent.getContext().getPackageManager();
            PackageInfo packageInfo = pm.getPackageInfo(app.appPackage, 0);
            if (Integer.parseInt(app.appVersionCode) > packageInfo.versionCode) {
                status = parent.getResources().getString(R.string.app_ready_to_update);
                img_trash.setVisibility(View.GONE);
            } else {
                status = parent.getResources().getString(R.string.app_installed);
                // for this app if we have removeApp policies
                Policies policies = new PoliciesData(this.context).getByTaskId(app.taskId);
                if (policies.policyName.equalsIgnoreCase("removeApp")) {
                    status = parent.getResources().getString(R.string.app_need_to_be_uninstall);
                    img_trash.setVisibility(View.VISIBLE);
                    // on click  start activity to uninstall app
                    img_trash.setOnClickListener(new ImageButton.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            Intent intent = new Intent();
                            String mPackage = app.appPackage;
                            if (Build.VERSION.SDK_INT < 14) {
                                intent.setAction(Intent.ACTION_DELETE);
                                // intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                intent.setDataAndType(Uri.parse("package:" + mPackage), "application/vnd.android.package-archive");
                            } else if (Build.VERSION.SDK_INT < 16) {
                                intent.setAction(Intent.ACTION_UNINSTALL_PACKAGE);
                                intent.setData(Uri.parse("package:" + mPackage));
                                // intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                intent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
                                intent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
                                intent.putExtra(Intent.EXTRA_ALLOW_REPLACE, true);
                            } else if (Build.VERSION.SDK_INT < 24) {
                                intent.setAction(Intent.ACTION_UNINSTALL_PACKAGE);
                                intent.setData(Uri.parse("package:" + mPackage));
                                // intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                intent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
                                intent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
                            } else {
                                // Android N
                                intent.setAction(Intent.ACTION_UNINSTALL_PACKAGE);
                                intent.setData(Uri.parse("package:" + mPackage));
                                // grant READ permission for this content Uri
                                // intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                                intent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
                                intent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
                            }
                            try {
                                v.getContext().startActivity(intent);
                            } catch (ActivityNotFoundException e) {
                                FlyveLog.e(this.getClass().getName() + ", un	installApk", e.getMessage());
                            }
                        }
                    });
                } else {
                    img_trash.setVisibility(View.GONE);
                }
            }
        } catch (Exception ex) {
            FlyveLog.e(this.getClass().getName() + ", getView", ex.getMessage());
        }
    } else {
        status = parent.getResources().getString(R.string.app_not_installed);
        Policies policies = new PoliciesData(this.context).getByTaskId(app.taskId);
        if (policies.policyName.equalsIgnoreCase("deployApp")) {
            status = parent.getResources().getString(R.string.app_pending_to_install);
        }
        img_trash.setVisibility(View.GONE);
    }
    txtStatus.setText(status);
    TextView txtAppName = vi.findViewById(R.id.txtAppName);
    txtAppName.setText(app.appName);
    TextView txtPackageName = vi.findViewById(R.id.txtPackageName);
    txtPackageName.setText(app.appPackage);
    TextView txtVersionCode = vi.findViewById(R.id.txtVersionCode);
    txtVersionCode.setText(parent.getContext().getString(R.string.version_code, app.appVersionCode));
    TextView txtVersionName = vi.findViewById(R.id.txtVersionName);
    txtVersionName.setText(parent.getContext().getString(R.string.version_name, app.appVersionName));
    ImageView imgApp = vi.findViewById(R.id.imgApp);
    imgApp.setImageDrawable(Helpers.getApplicationImage(parent.getContext(), app.appPackage));
    return vi;
}
Also used : Policies(org.flyve.mdm.agent.data.database.entity.Policies) FragmentPolicies(org.flyve.mdm.agent.ui.FragmentPolicies) PackageInfo(android.content.pm.PackageInfo) Intent(android.content.Intent) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) ActivityNotFoundException(android.content.ActivityNotFoundException) PoliciesData(org.flyve.mdm.agent.data.database.PoliciesData) ImageButton(android.widget.ImageButton) PackageManager(android.content.pm.PackageManager) ActivityNotFoundException(android.content.ActivityNotFoundException) TextView(android.widget.TextView) ImageView(android.widget.ImageView) Application(org.flyve.mdm.agent.data.database.entity.Application)

Example 9 with Application

use of org.flyve.mdm.agent.data.database.entity.Application in project android-mdm-agent by flyve-mdm.

the class Helpers method installApk.

public static Boolean installApk(Context context, String id, String appPath, String taskId, String versionCode) {
    // check if the app is installed
    ApplicationData apps = new ApplicationData(context);
    Application[] appsArray = apps.getApplicationsById(id);
    if (appsArray.length > 0 && Helpers.isPackageInstalled(context, appsArray[0].appPackage) && Integer.parseInt(versionCode) <= Integer.parseInt(appsArray[0].appVersionCode)) {
        FlyveLog.d("This app is installed: " + appsArray[0].appName);
        return true;
    } else {
        PackageManager packageManager = context.getPackageManager();
        String appName = "";
        String appPackage = "";
        String appVersionCode = "";
        String appVersionName = "";
        try {
            PackageInfo packageInfo = packageManager.getPackageArchiveInfo(appPath, 0);
            packageInfo.applicationInfo.sourceDir = appPath;
            packageInfo.applicationInfo.publicSourceDir = appPath;
            appName = packageManager.getApplicationLabel(packageInfo.applicationInfo).toString();
            appPackage = packageInfo.packageName;
            appVersionCode = String.valueOf(packageInfo.versionCode);
            appVersionName = String.valueOf(packageInfo.versionName);
        } catch (Exception ex) {
            FlyveLog.e(Helpers.class.getClass().getName() + ", installApk", ex.getMessage());
        }
        if (appsArray.length <= 0) {
            // add into the database
            Application appsData = new Application();
            appsData.appId = id;
            appsData.taskId = taskId;
            appsData.appName = appName;
            appsData.appPath = appPath;
            // 1 pending | 2 installed
            appsData.appStatus = "1";
            appsData.appPackage = appPackage;
            appsData.appVersionCode = appVersionCode;
            appsData.appVersionName = appVersionName;
            if (!appPackage.isEmpty()) {
                apps.create(appsData);
            }
            // update the array information
            appsArray = apps.getApplicationsById(id);
        } else {
            apps.updateStatus(id, "1");
            apps.updateVersionCode(id, appVersionCode);
        }
        if (appsArray.length > 0 && appsArray[0].appStatus.equalsIgnoreCase("1")) {
            // add notification
            Helpers.sendToNotificationBar(context, Integer.parseInt(id), context.getString(R.string.app_pending_to_install), appName, true, MainActivity.class, "DeployApp");
        }
        return false;
    }
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo) ApplicationData(org.flyve.mdm.agent.data.database.ApplicationData) Application(org.flyve.mdm.agent.data.database.entity.Application) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException)

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