use of org.flyve.mdm.agent.utils.StorageFolder in project android-mdm-agent by flyve-mdm.
the class PoliciesFiles method downloadApk.
/**
* Download, save and install app
* @param appName String package of the app
* @param id String Id from
* @param sessionToken
*/
public Boolean downloadApk(String appName, String id, String sessionToken) {
FlyveLog.d("Application name: " + appName);
// prevent CPU from going off if the user presses the power button during download
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName());
wl.acquire();
String filePath = "";
try {
filePath = new StorageFolder(context).getApkDir();
} catch (Exception ex) {
FlyveLog.e(ex.getMessage());
}
final String url = routes.pluginFlyvemdmPackage(id, sessionToken);
String completeFilePath = download(url, filePath);
if (completeFilePath.equalsIgnoreCase("")) {
return false;
} else {
if (Helpers.isSystemApp(context).equalsIgnoreCase("1")) {
// Silently for System apps
Helpers.installApkSilently(completeFilePath);
} else {
// Regular app
Helpers.installApk(context, id, completeFilePath);
}
return true;
}
}
use of org.flyve.mdm.agent.utils.StorageFolder in project android-mdm-agent by flyve-mdm.
the class FragmentTestPolicies method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_test_policies, container, false);
cache = new PoliciesData(FragmentTestPolicies.this.getContext());
mdm = new AndroidPolicies(FragmentTestPolicies.this.getContext(), FlyveAdminReceiver.class);
customPolicies = new CustomPolicies(FragmentTestPolicies.this.getContext());
Switch swGPS = v.findViewById(R.id.swGPS);
swGPS.setChecked(Boolean.parseBoolean(cache.getValue(GPSPolicy.POLICY_NAME).value));
swGPS.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
customPolicies.disableGps(isChecked);
}
}
});
Switch swAirplane = v.findViewById(R.id.swAirplane);
swAirplane.setChecked(Boolean.parseBoolean(cache.getValue(AirplaneModePolicy.POLICY_NAME).value));
swAirplane.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
customPolicies.disableAirplaneMode(isChecked);
}
});
Switch swBluetooth = v.findViewById(R.id.swBluetooth);
swBluetooth.setChecked(Boolean.parseBoolean(cache.getValue(BluetoothPolicy.POLICY_NAME).value));
swBluetooth.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
customPolicies.disableBluetooth(isChecked);
}
}
});
Switch swWifi = v.findViewById(R.id.swWifi);
swWifi.setChecked(Boolean.parseBoolean(cache.getValue(WifiPolicy.POLICY_NAME).value));
swWifi.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
customPolicies.disableWifi(isChecked);
}
}
});
Switch swNFC = v.findViewById(R.id.swNFC);
swNFC.setChecked(Boolean.parseBoolean(cache.getValue(NFCPolicy.POLICY_NAME).value));
swNFC.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
customPolicies.disableNFC(isChecked);
}
}
});
Switch swHostpot = v.findViewById(R.id.swHostpot);
swHostpot.setChecked(Boolean.parseBoolean(cache.getValue(HostpotTetheringPolicy.POLICY_NAME).value));
swHostpot.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
customPolicies.disableHostpotTethering(isChecked);
}
}
});
Switch swMobileLine = v.findViewById(R.id.swMobileLine);
swMobileLine.setChecked(Boolean.parseBoolean(cache.getValue(MobileLinePolicy.POLICY_NAME).value));
swMobileLine.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
customPolicies.disableMobileLine(isChecked);
}
}
});
Button btnLock = v.findViewById(R.id.btnLock);
btnLock.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mdm.lockScreen(LockActivity.class, getContext());
}
});
Switch swDisableCamera = v.findViewById(R.id.swDisableCamera);
swDisableCamera.setChecked(Boolean.parseBoolean(cache.getValue(CameraPolicy.POLICY_NAME).value));
swDisableCamera.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mdm.disableCamera(isChecked);
}
});
Switch swStorageEncryptionDevice = v.findViewById(R.id.swStorageEncryptionDevice);
swStorageEncryptionDevice.setChecked(Boolean.parseBoolean(cache.getValue(StorageEncryptionPolicy.POLICY_NAME).value));
swStorageEncryptionDevice.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mdm.storageEncryptionDevice(isChecked);
}
});
Button btnReboot = v.findViewById(R.id.btnReboot);
btnReboot.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mdm.reboot();
}
});
Button btnClearMQTT = v.findViewById(R.id.btnCleatMQTT);
btnClearMQTT.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
Helpers.deleteMQTTCache(FragmentTestPolicies.this.getContext());
} catch (Exception ex) {
FlyveLog.e(this.getClass().getName() + ", onCreateView", ex.getMessage());
}
}
});
final EditText edtPasswordLength = v.findViewById(R.id.edtPasswordLength);
final EditText edtPasswordMinimumLetters = v.findViewById(R.id.edtPasswordMinimumLetters);
final EditText edtPasswordMinimumLowerCase = v.findViewById(R.id.edtPasswordMinimumLowerCase);
final EditText edtPasswordMinimumUpperCase = v.findViewById(R.id.edtPasswordMinimumUpperCase);
final EditText edtPasswordMinimumNonLetter = v.findViewById(R.id.edtPasswordMinimumNonLetter);
final EditText edtPasswordMinimumNumeric = v.findViewById(R.id.edtPasswordMinimumNumeric);
final EditText edtPasswordMinimumSymbols = v.findViewById(R.id.edtPasswordMinimumSymbols);
final EditText edtMaximumFailedPasswordsForWipe = v.findViewById(R.id.edtMaximumFailedPasswordsForWipe);
final EditText edtMaximumTimeToLock = v.findViewById(R.id.edtMaximumTimeToLock);
Button btnPassword = v.findViewById(R.id.btnPassword);
btnPassword.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int minimumLength = Integer.parseInt(edtPasswordLength.getText().toString());
int minimumLetters = Integer.parseInt(edtPasswordMinimumLetters.getText().toString());
int minimumUpperCase = Integer.parseInt(edtPasswordMinimumUpperCase.getText().toString());
int minimumLowerCase = Integer.parseInt(edtPasswordMinimumLowerCase.getText().toString());
int minimumNonLetter = Integer.parseInt(edtPasswordMinimumNonLetter.getText().toString());
int minimumNumeric = Integer.parseInt(edtPasswordMinimumNumeric.getText().toString());
int minimumSymbols = Integer.parseInt(edtPasswordMinimumSymbols.getText().toString());
int maximumFailedPasswordsForWipe = Integer.parseInt(edtMaximumFailedPasswordsForWipe.getText().toString());
int maximumTimeToLock = Integer.parseInt(edtMaximumTimeToLock.getText().toString());
mdm.setPasswordLength(minimumLength);
mdm.setPasswordMinimumLetters(minimumLetters);
mdm.setPasswordMinimumUpperCase(minimumUpperCase);
mdm.setPasswordMinimumLowerCase(minimumLowerCase);
mdm.setPasswordMinimumNonLetter(minimumNonLetter);
mdm.setPasswordMinimumNumeric(minimumNumeric);
mdm.setPasswordMinimumSymbols(minimumSymbols);
mdm.setMaximumFailedPasswordsForWipe(maximumFailedPasswordsForWipe);
mdm.setMaximumTimeToLock(maximumTimeToLock);
}
});
Button btnPasswordEnable = v.findViewById(R.id.btnPasswordEnable);
btnPasswordEnable.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mdm.enablePassword(true, "", MainActivity.class);
}
});
Button btnDownloadFile = v.findViewById(R.id.btnDownloadFile);
btnDownloadFile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new Thread(new Runnable() {
public void run() {
//
String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath() + "/CHANGELOG.md";
FlyveLog.d(path);
ConnectionHTTP.getSyncFile("https://raw.githubusercontent.com/flyve-mdm/android-mdm-agent/develop/CHANGELOG.md", path, "", new ConnectionHTTP.ProgressCallback() {
@Override
public void progress(int value) {
}
});
}
}).start();
}
});
Button btnDownloadAPK = v.findViewById(R.id.btnDownloadAPK);
btnDownloadAPK.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String path = new StorageFolder(getContext()).getDocumentsDir() + "/flyve-apk.apk";
FlyveLog.d(path);
ConnectionHTTP.getSyncFile("https://f-droid.org/repo/org.flyve.inventory.agent_37960.apk", path, "", new ConnectionHTTP.ProgressCallback() {
@Override
public void progress(int value) {
}
});
}
});
Button btnEnablePassword = v.findViewById(R.id.btnEnablePassword);
btnEnablePassword.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Helpers.sendToNotificationBar(getContext(), 1009, "MDM Agent", "Please create a new password", true, MainActivity.class, "TestPolicies");
}
});
Button btnInstallSilently = v.findViewById(R.id.btnInstallSilently);
btnInstallSilently.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String path = new StorageFolder(FragmentTestPolicies.this.getContext()).getDownloadDir() + "/test.apk";
Helpers.installApkSilently(path);
}
});
return v;
}
use of org.flyve.mdm.agent.utils.StorageFolder in project android-mdm-agent by flyve-mdm.
the class PoliciesFiles method downloadApk.
/**
* Download, save and install app
* @param appName String package of the app
* @param id String Id from
* @param sessionToken
*/
public void downloadApk(String appName, String id, String sessionToken, String taskId, String versionCode) {
// prevent CPU from going off if the user presses the power button during download
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName());
wl.acquire();
String filePath = "";
try {
filePath = new StorageFolder(context).getApkDir();
} catch (Exception ex) {
FlyveLog.e(this.getClass().getName() + ", downloadApk", ex.getMessage());
this.status = BasePolicies.FEEDBACK_FAILED;
}
final String url = routes.pluginFlyvemdmPackage(id);
String completeFilePath = download(url, filePath, sessionToken, taskId);
if (completeFilePath.isEmpty()) {
this.status = BasePolicies.FEEDBACK_FAILED;
} else {
if (Helpers.isSystemApp(context).equalsIgnoreCase("1")) {
// Silently for System apps
this.status = BasePolicies.FEEDBACK_WAITING;
Helpers.installApkSilently(completeFilePath);
} else {
// Regular app
this.status = BasePolicies.FEEDBACK_WAITING;
Helpers.installApk(context, id, completeFilePath, taskId, versionCode);
}
}
}
use of org.flyve.mdm.agent.utils.StorageFolder in project android-mdm-agent by flyve-mdm.
the class PoliciesFiles method removeFile.
/**
* Remove the file according to the given path
* @param filePath
* @return boolean true if file deleted, false otherwise
*/
public void removeFile(String filePath, final String taskId) {
this.taskId = taskId;
try {
String realPath = new StorageFolder(context).convertPath(filePath);
File file = new File(realPath);
if (file.delete()) {
FlyveLog.d("Remove file: " + filePath);
// remove file from DB
AppDataBase dataBase = AppDataBase.getAppDatabase(context);
dataBase.FileDao().deleteByFilePath(file.getAbsolutePath());
this.status = BasePolicies.FEEDBACK_DONE;
} else {
this.status = BasePolicies.FEEDBACK_FAILED;
}
} catch (Exception ex) {
FlyveLog.e(this.getClass().getName() + ", removeFile", ex.getMessage() + "\n" + filePath);
this.status = BasePolicies.FEEDBACK_FAILED;
}
BasePolicies.sendTaskStatusbyHttp(this.context, this.status, this.taskId);
}
Aggregations