use of org.flyve.mdm.agent.data.database.ApplicationData in project android-mdm-agent by flyve-mdm.
the class FragmentAppList method loadData.
private void loadData() {
pb.setVisibility(View.VISIBLE);
apps = new ApplicationData(FragmentAppList.this.getContext()).getAllApplications();
if (apps.length > 0) {
ApplicationsAdapter mAdapter = new ApplicationsAdapter(this.getActivity(), apps, getContext());
lst.setAdapter(mAdapter);
txtNoData.setVisibility(View.GONE);
} else {
txtNoData.setVisibility(View.VISIBLE);
}
pb.setVisibility(View.GONE);
}
use of org.flyve.mdm.agent.data.database.ApplicationData in project android-mdm-agent by flyve-mdm.
the class InstallAppActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_install_app);
Bundle extras = getIntent().getExtras();
if (extras != null) {
id = extras.getString("APP_ID");
appPath = extras.getString("APP_PATH");
appData = new ApplicationData(InstallAppActivity.this);
// check if the app is installed
Application[] apps = appData.getApplicationsById(id);
if (apps.length > 0 && Helpers.isPackageInstalled(InstallAppActivity.this, apps[0].appPackage)) {
PackageManager pm = getPackageManager();
// check if is a new version or newest
try {
PackageInfo packageInfo = pm.getPackageInfo(apps[0].appPackage, 0);
if (Integer.parseInt(apps[0].appVersionCode) <= packageInfo.versionCode) {
// is the same version of the app or older
finish();
} else {
installApk(appPath);
}
} catch (Exception ex) {
FlyveLog.e(this.getClass().getName() + ", onCreate", ex.getMessage());
finish();
}
} else {
try {
installApk(appPath);
} catch (Exception ex) {
FlyveLog.e(this.getClass().getName() + ", onCreate", ex.getMessage());
}
}
} else {
finish();
}
}
use of org.flyve.mdm.agent.data.database.ApplicationData 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;
}
}
use of org.flyve.mdm.agent.data.database.ApplicationData in project android-mdm-agent by flyve-mdm.
the class PoliciesAsyncTask method doInBackground.
protected Boolean doInBackground(Object... object) {
final Context context = (Context) object[0];
final Integer action = (Integer) object[1];
final String topic = (String) object[2];
final String message = (String) object[3];
mHandler.post(new Runnable() {
public void run() {
switch(action) {
case LOCK:
{
if (!MDMAgent.isSecureVersion()) {
try {
JSONObject jsonObj = new JSONObject(message);
if (jsonObj.has("lock")) {
String lock = jsonObj.getString("lock");
AndroidPolicies androidPolicies = new AndroidPolicies(context, FlyveAdminReceiver.class);
if (lock.equalsIgnoreCase("now")) {
// lock screen
androidPolicies.lockScreen(LockActivity.class, context);
// lock device
androidPolicies.lockDevice();
} else {
// unlock screen
if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M && Settings.canDrawOverlays(context)) {
try {
MDMAgent mainActivity = ((MDMAgent) context);
mainActivity.getLockActivity().unlockScreen();
} catch (Exception e) {
}
}
// unlock device
androidPolicies.unlockDevice();
Helpers.sendBroadcast("unlock", "org.flyvemdm.finishlock", context);
}
}
} catch (Exception ex) {
FlyveLog.e(this.getClass().getName() + ", LOCK ", ex.getMessage());
}
}
}
case PING:
{
String data = "{\"input\":{\"_pong\":\"!\"}}";
Routes routes = new Routes(context);
MqttData cache = new MqttData(context);
String url = routes.pluginFlyvemdmAgent(cache.getAgentId());
pluginHttpResponse(context, url, data);
}
break;
case WIPE:
{
if (!MDMAgent.isSecureVersion()) {
try {
JSONObject jsonObj = new JSONObject(message);
if (jsonObj.has("wipe") && "NOW".equalsIgnoreCase(jsonObj.getString("wipe"))) {
sendStatusbyHttp(context, false);
new AndroidPolicies(context, FlyveAdminReceiver.class).wipe();
}
} catch (Exception ex) {
FlyveLog.e(this.getClass().getName() + ", WIPE ", ex.getMessage());
}
}
}
break;
case UNENROLL:
{
// set offline
sendStatusbyHttp(context, false);
// Remove all the information
new ApplicationData(context).deleteAll();
new FileData(context).deleteAll();
new MqttData(context).deleteAll();
new PoliciesData(context).deleteAll();
}
break;
case GEOLOCATE:
{
FastLocationProvider fastLocationProvider = new FastLocationProvider();
Routes routes = new Routes(context);
final String url = routes.pluginFlyvemdmGeolocation();
boolean isAvailable = fastLocationProvider.getLocation(context, new FastLocationProvider.LocationResult() {
@Override
public void gotLocation(Location location) {
if (location == null) {
FlyveLog.e(this.getClass().getName() + ", sendGPS", "without location yet...");
try {
JSONObject jsonPayload = new JSONObject();
jsonPayload.put("_datetime", Helpers.getUnixTime(context));
jsonPayload.put("_agents_id", new MqttData(context).getAgentId());
jsonPayload.put("computers_id", new MqttData(context).getComputersId());
jsonPayload.put("_gps", "off");
JSONObject jsonInput = new JSONObject();
jsonInput.put("input", jsonPayload);
String payload = jsonInput.toString();
pluginHttpResponse(context, url, payload);
} catch (Exception ex) {
Helpers.storeLog("fcm", "Error on GPS location", ex.getMessage());
}
} else {
try {
String latitude = String.valueOf(location.getLatitude());
String longitude = String.valueOf(location.getLongitude());
// "{"input":{"_agents_id":":id","_datetime":":string","latitude":":float","longitude":":float"}}"
JSONObject jsonGPS = new JSONObject();
jsonGPS.put("latitude", latitude);
jsonGPS.put("longitude", longitude);
jsonGPS.put("_datetime", Helpers.getUnixTime(context));
jsonGPS.put("_agents_id", new MqttData(context).getAgentId());
jsonGPS.put("computers_id", new MqttData(context).getComputersId());
JSONObject jsonInput = new JSONObject();
jsonInput.put("input", jsonGPS);
String payload = jsonInput.toString();
pluginHttpResponse(context, url, payload);
} catch (Exception ex) {
FlyveLog.e(this.getClass().getName() + ", sendGPS", ex.getMessage());
Helpers.storeLog("fcm", "Error on GPS location", ex.getMessage());
}
}
}
});
if (!isAvailable) {
try {
JSONObject jsonPayload = new JSONObject();
jsonPayload.put("_datetime", Helpers.getUnixTime(context));
jsonPayload.put("_agents_id", new MqttData(context).getAgentId());
jsonPayload.put("_gps", "off");
jsonPayload.put("computers_id", new MqttData(context).getComputersId());
JSONObject jsonInput = new JSONObject();
jsonInput.put("input", jsonPayload);
String payload = jsonInput.toString();
pluginHttpResponse(context, url, payload);
} catch (Exception ex) {
Helpers.storeLog("fcm", "Error on GPS location", ex.getMessage());
}
}
}
break;
case INVENTORY:
{
Inventory inventory = new Inventory();
inventory.getXMLInventory(context, new InventoryTask.OnTaskCompleted() {
@Override
public void onTaskSuccess(String s) {
Routes routes = new Routes(context);
MqttData cache = new MqttData(context);
String url = routes.pluginFlyvemdmAgent(cache.getAgentId());
try {
JSONObject jsonPayload = new JSONObject();
jsonPayload.put("_inventory", Helpers.base64encode(s));
JSONObject jsonInput = new JSONObject();
jsonInput.put("input", jsonPayload);
String payload = jsonInput.toString();
pluginHttpResponse(context, url, payload);
Helpers.storeLog("fcm", "Inventory", "Inventory Send");
} catch (Exception ex) {
Helpers.storeLog("fcm", "Error on json createInventory", ex.getMessage());
}
}
@Override
public void onTaskError(Throwable throwable) {
Helpers.storeLog("fcm", "Error on createInventory", throwable.getMessage());
}
});
}
case POLICIES:
{
// Policy/passwordEnabled
callPolicy(context, PasswordEnablePolicy.class, PasswordEnablePolicy.POLICY_NAME, priority, topic, message);
// Policy/passwordQuality
callPolicy(context, PasswordQualityPolicy.class, PasswordQualityPolicy.POLICY_NAME, priority, topic, message);
// Policy/passwordMinLength
callPolicy(context, PasswordMinLengthPolicy.class, PasswordMinLengthPolicy.POLICY_NAME, priority, topic, message);
// Policy/passwordMinLowerCase
callPolicy(context, PasswordMinLowerCasePolicy.class, PasswordMinLowerCasePolicy.POLICY_NAME, priority, topic, message);
// Policy/passwordMinUpperCase
callPolicy(context, PasswordMinUpperCasePolicy.class, PasswordMinUpperCasePolicy.POLICY_NAME, priority, topic, message);
// Policy/passwordMinNonLetter
callPolicy(context, PasswordMinNonLetterPolicy.class, PasswordMinNonLetterPolicy.POLICY_NAME, priority, topic, message);
// Policy/passwordMinLetters
callPolicy(context, PasswordMinLetterPolicy.class, PasswordMinLetterPolicy.POLICY_NAME, priority, topic, message);
// Policy/passwordMinNumeric
callPolicy(context, PasswordMinNumericPolicy.class, PasswordMinNumericPolicy.POLICY_NAME, priority, topic, message);
// Policy/passwordMinSymbols
callPolicy(context, PasswordMinSymbolsPolicy.class, PasswordMinSymbolsPolicy.POLICY_NAME, priority, topic, message);
// Policy/MaximumFailedPasswordsForWipe
callPolicy(context, MaximumFailedPasswordForWipePolicy.class, MaximumFailedPasswordForWipePolicy.POLICY_NAME, priority, topic, message);
// Policy/MaximumTimeToLock
callPolicy(context, MaximumTimeToLockPolicy.class, MaximumTimeToLockPolicy.POLICY_NAME, priority, topic, message);
// Policy/storageEncryption
callPolicy(context, StorageEncryptionPolicy.class, StorageEncryptionPolicy.POLICY_NAME, priority, topic, message);
// Policy/disableCamera
callPolicy(context, CameraPolicy.class, CameraPolicy.POLICY_NAME, priority, topic, message);
// Policy/disableBluetooth
callPolicy(context, BluetoothPolicy.class, BluetoothPolicy.POLICY_NAME, priority, topic, message);
// Policy/disableHostpotTethering
callPolicy(context, HostpotTetheringPolicy.class, HostpotTetheringPolicy.POLICY_NAME, priority, topic, message);
// Policy/disableRoaming
callPolicy(context, RoamingPolicy.class, RoamingPolicy.POLICY_NAME, priority, topic, message);
// Policy/disableWifi
callPolicy(context, WifiPolicy.class, WifiPolicy.POLICY_NAME, priority, topic, message);
// Policy/disableSpeakerphone
callPolicy(context, SpeakerphonePolicy.class, SpeakerphonePolicy.POLICY_NAME, priority, topic, message);
// Policy/disableCreateVpnProfiles
callPolicy(context, VPNPolicy.class, VPNPolicy.POLICY_NAME, priority, topic, message);
// Policy/disableStreamMusic
callPolicy(context, StreamMusicPolicy.class, StreamMusicPolicy.POLICY_NAME, priority, topic, message);
// Policy/disableStreamRing
callPolicy(context, StreamRingPolicy.class, StreamRingPolicy.POLICY_NAME, priority, topic, message);
// Policy/disableStreamAlarm
callPolicy(context, StreamAlarmPolicy.class, StreamAlarmPolicy.POLICY_NAME, priority, topic, message);
// Policy/disableStreamNotification
callPolicy(context, StreamNotificationPolicy.class, StreamNotificationPolicy.POLICY_NAME, priority, topic, message);
// Policy/disableStreamAccessibility
callPolicy(context, StreamAccessibilityPolicy.class, StreamAccessibilityPolicy.POLICY_NAME, priority, topic, message);
// Policy/disableStreamVoiceCall
callPolicy(context, StreamVoiceCallPolicy.class, StreamVoiceCallPolicy.POLICY_NAME, priority, topic, message);
// Policy/disableStreamDTMF
callPolicy(context, StreamVoiceCallPolicy.class, StreamVoiceCallPolicy.POLICY_NAME, priority, topic, message);
// Policy/disableScreenCapture
// ROOT REQUIRED
callPolicy(context, ScreenCapturePolicy.class, ScreenCapturePolicy.POLICY_NAME, priority, topic, message);
// Policy/disableAirplaneMode
// ROOT REQUIRED
callPolicy(context, AirplaneModePolicy.class, AirplaneModePolicy.POLICY_NAME, priority, topic, message);
// Policy/disableGPS
// ROOT REQUIRED
callPolicy(context, GPSPolicy.class, GPSPolicy.POLICY_NAME, priority, topic, message);
// Policy/disableMobileLine
// ROOT
callPolicy(context, MobileLinePolicy.class, MobileLinePolicy.POLICY_NAME, priority, topic, message);
// Policy/disableNfc
// ROOT
callPolicy(context, NFCPolicy.class, NFCPolicy.POLICY_NAME, priority, topic, message);
// Policy/disableStatusBar
// ROOT
callPolicy(context, StatusBarPolicy.class, StatusBarPolicy.POLICY_NAME, priority, topic, message);
// Policy/disableUsbMtp
// ROOT
callPolicy(context, UsbMtpPolicy.class, UsbMtpPolicy.POLICY_NAME, priority, topic, message);
// Policy/disableUsbPtp
// ROOT
callPolicy(context, UsbPtpPolicy.class, UsbPtpPolicy.POLICY_NAME, priority, topic, message);
// Policy/disableUsbAdb
// ROOT
callPolicy(context, UsbAdbPolicy.class, UsbAdbPolicy.POLICY_NAME, priority, topic, message);
// Policy/deployApp
// ROOT
callPolicy(context, DeployAppPolicy.class, DeployAppPolicy.POLICY_NAME, priority, topic, message);
// Policy/removeApp
// ROOT
callPolicy(context, RemoveAppPolicy.class, RemoveAppPolicy.POLICY_NAME, priority, topic, message);
// Policy/deployFile
// ROOT
callPolicy(context, DeployFilePolicy.class, DeployFilePolicy.POLICY_NAME, priority, topic, message);
// Policy/removeFile
// ROOT
callPolicy(context, RemoveFilePolicy.class, RemoveFilePolicy.POLICY_NAME, priority, topic, message);
}
break;
default:
}
}
});
return true;
}
use of org.flyve.mdm.agent.data.database.ApplicationData 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;
}
}
Aggregations