/** * Checks if the app is already installed on the device. * * @param appIdentifier - App package name. * @return appInstalled - App installed status. */ private boolean isAppInstalled(String appIdentifier) { boolean appInstalled = false; ArrayList<DeviceAppInfo> apps = new ArrayList<>(appList.getInstalledApps().values()); for (DeviceAppInfo appInfo : apps) { if (appIdentifier.trim().equals(appInfo.getPackagename())) { appInstalled = true; } } return appInstalled; }
/** * Revokes install app policy on the device (Particular app in the policy should be removed). * * @param operation - Operation object. */ private void revokeInstallAppPolicy(org.wso2.emm.agent.beans.Operation operation) throws AndroidAgentException { String appIdentifier = null; try { JSONObject appData = new JSONObject(operation.getPayLoad().toString()); if (!appData.isNull(resources.getString(R.string.app_identifier))) { appIdentifier = appData.getString(resources.getString(R.string.app_identifier)); } if (isAppInstalled(appIdentifier)) { appList.uninstallApplication(appIdentifier); } } catch (JSONException e) { throw new AndroidAgentException("Invalid JSON format.", e); } }