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));
}
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);
}
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;
}
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;
}
Aggregations