Search in sources :

Example 1 with Policies

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

the class FragmentPolicies method loadData.

private void loadData(ListView lst) {
    List<Policies> arrPolicies = new PoliciesData(FragmentPolicies.this.getContext()).getAllPolicies();
    ArrayList arr = new ArrayList<HashMap<String, Boolean>>();
    if (arrPolicies.isEmpty()) {
        HashMap<String, String> map = new HashMap<>();
        map.put("description", "0 policies");
        map.put("value", "");
        map.put("taskId", "");
        arr.add(map);
    } else {
        for (int i = 0; i < arrPolicies.size(); i++) {
            HashMap<String, String> map = new HashMap<>();
            map.put("description", Helpers.splitCapitalized(arrPolicies.get(i).policyName));
            map.put("value", String.valueOf(arrPolicies.get(i).value));
            map.put("taskId", String.valueOf(arrPolicies.get(i).taskId));
            arr.add(map);
        }
    }
    lst.setAdapter(new PoliciesAdapter(FragmentPolicies.this.getActivity(), arr));
}
Also used : PoliciesData(org.flyve.mdm.agent.data.database.PoliciesData) Policies(org.flyve.mdm.agent.data.database.entity.Policies) PoliciesAdapter(org.flyve.mdm.agent.adapter.PoliciesAdapter) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 2 with Policies

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

the class PoliciesData method removeValue.

public void removeValue(String taskId) {
    Policies policies = dataBase.PoliciesDao().getPolicyByTaskId(taskId).get(0);
    dataBase.PoliciesDao().delete(policies);
}
Also used : Policies(org.flyve.mdm.agent.data.database.entity.Policies)

Example 3 with Policies

use of org.flyve.mdm.agent.data.database.entity.Policies 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 4 with Policies

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

the class PoliciesData method setValue.

public Object setValue(String policyName, String taskId, String value, int priority) {
    if (dataBase.PoliciesDao().getPolicyByTaskId(taskId).isEmpty()) {
        Policies policies = new Policies();
        policies.policyName = policyName;
        policies.taskId = taskId;
        policies.value = value;
        policies.priority = priority;
        dataBase.PoliciesDao().insert(policies);
    } else {
        Policies policies = dataBase.PoliciesDao().getPolicyByTaskId(taskId).get(0);
        policies.value = value;
        dataBase.PoliciesDao().update(policies);
    }
    // Return the priority value
    Policies policies = dataBase.PoliciesDao().getPolicyByTaskId(taskId).get(0);
    return policies.value;
}
Also used : Policies(org.flyve.mdm.agent.data.database.entity.Policies)

Aggregations

Policies (org.flyve.mdm.agent.data.database.entity.Policies)4 PoliciesData (org.flyve.mdm.agent.data.database.PoliciesData)2 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Intent (android.content.Intent)1 PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 View (android.view.View)1 ImageButton (android.widget.ImageButton)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 PoliciesAdapter (org.flyve.mdm.agent.adapter.PoliciesAdapter)1 Application (org.flyve.mdm.agent.data.database.entity.Application)1 FragmentPolicies (org.flyve.mdm.agent.ui.FragmentPolicies)1