FileDocCategorySizeDatePackage
KeyguardManager.javaAPI DocAndroid 5.1 API10834Thu Mar 12 22:22:10 GMT 2015android.app

KeyguardManager

public class KeyguardManager extends Object
Class that can be used to lock and unlock the keyboard. Get an instance of this class by calling {@link android.content.Context#getSystemService(java.lang.String)} with argument {@link android.content.Context#KEYGUARD_SERVICE}. The actual class to control the keyboard locking is {@link android.app.KeyguardManager.KeyguardLock}.

Fields Summary
private android.view.IWindowManager
mWM
private android.app.trust.ITrustManager
mTrustManager
public static final String
ACTION_CONFIRM_DEVICE_CREDENTIAL
Intent used to prompt user for device credentials.
public static final String
EXTRA_TITLE
A CharSequence dialog title to show to the user when used with a {@link #ACTION_CONFIRM_DEVICE_CREDENTIAL}.
public static final String
EXTRA_DESCRIPTION
A CharSequence description to show to the user when used with {@link #ACTION_CONFIRM_DEVICE_CREDENTIAL}.
Constructors Summary
KeyguardManager()

        mWM = WindowManagerGlobal.getWindowManagerService();
        mTrustManager = ITrustManager.Stub.asInterface(
                ServiceManager.getService(Context.TRUST_SERVICE));
    
Methods Summary
public android.content.IntentcreateConfirmDeviceCredentialIntent(java.lang.CharSequence title, java.lang.CharSequence description)
Get an intent to prompt the user to confirm credentials (pin, pattern or password) for the current user of the device. The caller is expected to launch this activity using {@link android.app.Activity#startActivityForResult(Intent, int)} and check for {@link android.app.Activity#RESULT_OK} if the user successfully completes the challenge.

return
the intent for launching the activity or null if no password is required.


                                                                    
          
        if (!isKeyguardSecure()) return null;
        Intent intent = new Intent(ACTION_CONFIRM_DEVICE_CREDENTIAL);
        intent.putExtra(EXTRA_TITLE, title);
        intent.putExtra(EXTRA_DESCRIPTION, description);
        // For security reasons, only allow this to come from system settings.
        intent.setPackage("com.android.settings");
        return intent;
    
public voidexitKeyguardSecurely(android.app.KeyguardManager$OnKeyguardExitResult callback)

deprecated
Use {@link android.view.WindowManager.LayoutParams#FLAG_DISMISS_KEYGUARD} and/or {@link android.view.WindowManager.LayoutParams#FLAG_SHOW_WHEN_LOCKED} instead; this allows you to seamlessly hide the keyguard as your application moves in and out of the foreground and does not require that any special permissions be requested. Exit the keyguard securely. The use case for this api is that, after disabling the keyguard, your app, which was granted permission to disable the keyguard and show a limited amount of information deemed safe without the user getting past the keyguard, needs to navigate to something that is not safe to view without getting past the keyguard. This will, if the keyguard is secure, bring up the unlock screen of the keyguard.

This method requires the caller to hold the permission {@link android.Manifest.permission#DISABLE_KEYGUARD}.

param
callback Let's you know whether the operation was succesful and it is safe to launch anything that would normally be considered safe once the user has gotten past the keyguard.

        try {
            mWM.exitKeyguardSecurely(new IOnKeyguardExitResult.Stub() {
                public void onKeyguardExitResult(boolean success) throws RemoteException {
                    if (callback != null) {
                        callback.onKeyguardExitResult(success);
                    }
                }
            });
        } catch (RemoteException e) {

        }
    
public booleaninKeyguardRestrictedInputMode()
If keyguard screen is showing or in restricted key input mode (i.e. in keyguard password emergency screen). When in such mode, certain keys, such as the Home key and the right soft keys, don't work.

return
true if in keyguard restricted input mode.
see
android.view.WindowManagerPolicy#inKeyguardRestrictedKeyInputMode

        try {
            return mWM.inKeyguardRestrictedInputMode();
        } catch (RemoteException ex) {
            return false;
        }
    
public booleanisDeviceLocked()
Returns whether the device is currently locked and requires a PIN, pattern or password to unlock.

return
true if unlocking the device currently requires a PIN, pattern or password.

        return isDeviceLocked(UserHandle.getCallingUserId());
    
public booleanisDeviceLocked(int userId)
Returns whether the device is currently locked and requires a PIN, pattern or password to unlock.

param
userId the user for which the locked state should be reported.
return
true if unlocking the device currently requires a PIN, pattern or password.
hide

        try {
            return mTrustManager.isDeviceLocked(userId);
        } catch (RemoteException e) {
            return false;
        }
    
public booleanisKeyguardLocked()
Return whether the keyguard is currently locked.

return
true if keyguard is locked.

        try {
            return mWM.isKeyguardLocked();
        } catch (RemoteException ex) {
            return false;
        }
    
public booleanisKeyguardSecure()
Return whether the keyguard requires a password to unlock.

return
true if keyguard is secure.

        try {
            return mWM.isKeyguardSecure();
        } catch (RemoteException ex) {
            return false;
        }
    
public android.app.KeyguardManager$KeyguardLocknewKeyguardLock(java.lang.String tag)

deprecated
Use {@link android.view.WindowManager.LayoutParams#FLAG_DISMISS_KEYGUARD} and/or {@link android.view.WindowManager.LayoutParams#FLAG_SHOW_WHEN_LOCKED} instead; this allows you to seamlessly hide the keyguard as your application moves in and out of the foreground and does not require that any special permissions be requested. Enables you to lock or unlock the keyboard. Get an instance of this class by calling {@link android.content.Context#getSystemService(java.lang.String) Context.getSystemService()}. This class is wrapped by {@link android.app.KeyguardManager KeyguardManager}.
param
tag A tag that informally identifies who you are (for debugging who is disabling he keyguard).
return
A {@link KeyguardLock} handle to use to disable and reenable the keyguard.

        return new KeyguardLock(tag);