Java Code Examples for android.app.admin.DevicePolicyManager#setKeyguardDisabled()

The following examples show how to use android.app.admin.DevicePolicyManager#setKeyguardDisabled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OBSystemsManager.java    From GLEXP-Team-onebillion with Apache License 2.0 6 votes vote down vote up
public void toggleKeyguardAndStatusBar(boolean status)
    {
        if (!MainActivity.isSDKCompatible())
        {
            MainActivity.log("OBSystemsManager:toggleKeyguardAndStatusBar: incompatible SDK version. exiting function");
            return;
        }
        DevicePolicyManager devicePolicyManager = (DevicePolicyManager) MainActivity.mainActivity.getSystemService(Context.DEVICE_POLICY_SERVICE);
        ComponentName adminReceiver = OBDeviceAdminReceiver.getComponentName(MainActivity.mainActivity);
        //
        if (devicePolicyManager.isDeviceOwnerApp(MainActivity.mainActivity.getPackageName()))
        {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
            {
                devicePolicyManager.setKeyguardDisabled(adminReceiver, !status);
            }
            MainActivity.log("OBSystemsManager.keyguard has been " + (status ? "enabled" : "disabled"));
            //
//            devicePolicyManager.setStatusBarDisabled(adminReceiver, !status);
//            MainActivity.log("OBSystemsManager.status bar has been " + (status ? "enabled" : "disabled"));
        }
    }
 
Example 2
Source File: OBSystemsManager.java    From GLEXP-Team-onebillion with Apache License 2.0 4 votes vote down vote up
public void disableAdministratorPrivileges()
    {
        if (!MainActivity.isSDKCompatible())
        {
            MainActivity.log("OBSystemsManager:disableAdministratorPrivileges: incompatible SDK version. exiting function");
            return;
        }
        MainActivity.log("OBSystemsManager.disableAdministratorPrivileges");
        DevicePolicyManager devicePolicyManager = (DevicePolicyManager) MainActivity.mainActivity.getSystemService(Context.DEVICE_POLICY_SERVICE);
        ComponentName adminReceiver = OBDeviceAdminReceiver.getComponentName(MainActivity.mainActivity);
        //
        if (devicePolicyManager.isDeviceOwnerApp(MainActivity.mainActivity.getPackageName()))
        {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
            {
                devicePolicyManager.setKeyguardDisabled(adminReceiver, false);
            }
            MainActivity.log("OBSystemsManager.keyguard restored");
            //
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
            {
                devicePolicyManager.setStatusBarDisabled(adminReceiver, false);
            }
            MainActivity.log("OBSystemsManager.status bar restored");
            //
            try
            {
                MainActivity.log("OBSystemsManager.disableAdministratorPrivileges: removing active admin");
                devicePolicyManager.removeActiveAdmin(adminReceiver);
                MainActivity.log("OBSystemsManager.disableAdministratorPrivileges: clearing device owner");
                devicePolicyManager.clearDeviceOwnerApp(MainActivity.mainActivity.getPackageName());
                MainActivity.log("OBSystemsManager.disableAdministratorPrivileges: done");
            } catch (Exception e)
            {
                MainActivity.log("OBSystemsManager.disableAdministratorPrivileges: exception caught");
//                e.printStackTrace();
                // App might not be the device owner at this point
            }
        }
        if (kioskModeActive)
        {
            MainActivity.mainActivity.stopLockTask();
            kioskModeActive = false;
        }
    }
 
Example 3
Source File: CosuConfig.java    From android-testdpc with Apache License 2.0 4 votes vote down vote up
@TargetApi(VERSION_CODES.M)
private void disableKeyGuardAndStatusBar(DevicePolicyManager dpm, ComponentName admin) {
    dpm.setStatusBarDisabled(admin, mDisableStatusBar);
    dpm.setKeyguardDisabled(admin, mDisableKeyguard);
}