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