Code example for KeyguardManager

Methods: isKeyguardLocked, isKeyguardSecure

0
 
    private boolean isKeyguardLocked(boolean includeSlide) {
        // isKeyguardSecure() excludes "Slide" Lock 
        KeyguardManager kgm = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
        if (includeSlide) {
            return (null != kgm) && kgm.isKeyguardLocked();
        } else { 
            return (null != kgm) && kgm.isKeyguardLocked() && kgm.isKeyguardSecure();
        } 
    } 
 
    private boolean isTelephoneActive() { 
        TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        return (null != tm) && (TelephonyManager.CALL_STATE_IDLE != tm.getCallState());
    } 
 
    private void doLockScreen(Activity activity) {
        if (null != mDevicePolicyManager) {
            if (mDevicePolicyManager.isAdminActive(mAdminComponent)) {
                Log.d(TAG, "Doing LockScreen");
                mDevicePolicyManager.lockNow();