I recently started to move an Android App to Flutter. I enjoy the way Flutter Apps are coded. After 2 days the Flutter App had the same functionality as the Android App. The only feature missing is the lockdown. The Android App is running on corporate-owned devices and is device owner. The lockdown is achieved by the following methods:
private void setDefaultCosuPolicies(boolean active) {
// set user restrictions
setUserRestriction(UserManager.DISALLOW_SAFE_BOOT, active);
setUserRestriction(UserManager.DISALLOW_FACTORY_RESET, active);
setUserRestriction(UserManager.DISALLOW_ADD_USER, active);
setUserRestriction(UserManager.DISALLOW_MOUNT_PHYSICAL_MEDIA, active);
setUserRestriction(UserManager.DISALLOW_ADJUST_VOLUME, active);
// disable keyguard and status bar
mDevicePolicyManager.setKeyguardDisabled(mAdminName, active);
mDevicePolicyManager.setStatusBarDisabled(mAdminName, active);
// enable STAY_ON_WHILE_PLUGGED_IN
enableStayOnWhilePluggedIn(false);
// set this Activity as a lock task package
mDevicePolicyManager.setLockTaskPackages(mAdminName,
active ? new String[]{getPackageName()} : new String[]{});
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_MAIN);
intentFilter.addCategory(Intent.CATEGORY_HOME);
intentFilter.addCategory(Intent.CATEGORY_DEFAULT);
if (active) {
// set Cosu activity as home intent receiver so that it is started
// on reboot
mDevicePolicyManager.addPersistentPreferredActivity(
mAdminName, intentFilter, new ComponentName(
getPackageName(), MainActivity.class.getName()));
} else {
mDevicePolicyManager.clearPackagePersistentPreferredActivities(
mAdminName, getPackageName());
}
}
private void setUserRestriction(String restriction, boolean disallow) {
if (disallow) {
mDevicePolicyManager.addUserRestriction(mAdminName,
restriction);
} else {
mDevicePolicyManager.clearUserRestriction(mAdminName,
restriction);
}
}
private void enableStayOnWhilePluggedIn(boolean enabled) {
if (enabled) {
mDevicePolicyManager.setGlobalSetting(
mAdminName,
Settings.Global.STAY_ON_WHILE_PLUGGED_IN,
Battery_PLUGGED_ANY);
} else {
mDevicePolicyManager.setGlobalSetting(
mAdminName,
Settings.Global.STAY_ON_WHILE_PLUGGED_IN, DONT_STAY_ON);
}
}
In the MainActivitys onCreate function setDefaultCosuPolicies(true) was called. I copied these functions to the flutter app. Added the AdminReceiver and configured everything in the AndroidManifest. The first attempt didn't work so I tried to call the setDefaultCosuPolicies function through a MethodChannel. This also did not work.
Does anyone have any idea how to activate the kiosk functionality?
Thanks in advance