FileDocCategorySizeDatePackage
KeyguardTestActivity.javaAPI DocAndroid 5.1 API12548Thu Mar 12 22:22:42 GMT 2015com.android.keyguard.test

KeyguardTestActivity

public class KeyguardTestActivity extends android.app.Activity implements android.view.View.OnClickListener

Fields Summary
private static final String
KEYGUARD_PACKAGE
private static final String
KEYGUARD_CLASS
private static final String
TAG
private static final int
MODE_NONE
private static final int
MODE_PIN
private static final int
MODE_PASSWORD
private static final int
MODE_PATTERN
private static final int
MODE_SIM_PIN
private static final int
MODE_SIM_PUK
private static final String
SECURITY_MODE
android.os.Handler
mHandler
com.android.internal.policy.IKeyguardService
mService
KeyguardShowCallback
mKeyguardShowCallback
KeyguardExitCallback
mKeyguardExitCallback
RemoteServiceConnection
mConnection
private boolean
mSentSystemReady
public int
mSecurityModeMock
private boolean
mTestSimPin
private boolean
mTestSimPuk
private boolean
mLockPasswordEnabled
public boolean
mLockPatternEnabled
private int
mSecurityMode
Constructors Summary
Methods Summary
private voidbindService()

        if (mConnection == null) {
            mConnection = new RemoteServiceConnection();
            Intent intent = new Intent();
            intent.setClassName(KEYGUARD_PACKAGE, KEYGUARD_CLASS);
            Log.v(TAG, "BINDING SERVICE: " + KEYGUARD_CLASS);
            if (!bindService(intent, mConnection, Context.BIND_AUTO_CREATE)) {
                Log.v(TAG, "FAILED TO BIND TO KEYGUARD!");
            }
        } else {
            Log.v(TAG, "Service already bound");
        }
    
public voidonClick(android.view.View v)

        try {
            switch (v.getId()) {
            case R.id.on_screen_turned_on:
                mService.onScreenTurnedOn(mKeyguardShowCallback);
                break;
            case R.id.on_screen_turned_off:
                mService.onScreenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
                break;
            case R.id.do_keyguard:
                if (!mSentSystemReady) {
                    mSentSystemReady = true;
                    mService.onSystemReady();
                }
                mService.doKeyguardTimeout(null);
                break;
            case R.id.verify_unlock:
                mService.doKeyguardTimeout(null);
                // Wait for keyguard to lock and then try this...
                mHandler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            mService.verifyUnlock(mKeyguardExitCallback);
                        } catch (RemoteException e) {
                            Log.e(TAG, "Failed verifyUnlock()", e);
                        }
                    }
                }, 5000);
                break;
            }
        } catch (RemoteException e) {
            Log.e(TAG, "onClick(): Failed due to remote exeption", e);
        }
    
protected voidonCreate(android.os.Bundle savedInstanceState)

        super.onCreate(savedInstanceState);
        setContentView(R.layout.keyguard_test_activity);
        final int[] buttons = {
                R.id.on_screen_turned_off, R.id.on_screen_turned_on,
                R.id.do_keyguard, R.id.verify_unlock
        };
        for (int i = 0; i < buttons.length; i++) {
            findViewById(buttons[i]).setOnClickListener(this);
        }
        Log.v(TAG, "Binding service...");
        bindService();
    
public booleanonOptionsItemSelected(android.view.MenuItem item)

        // Handle item selection
        switch (item.getItemId()) {
            case R.id.none_menu_item:
                setMode(MODE_NONE);
                break;
            case R.id.pin_menu_item:
                setMode(MODE_PIN);
                break;
            case R.id.password_menu_item:
                setMode(MODE_PASSWORD);
                break;
            case R.id.pattern_menu_item:
                setMode(MODE_PATTERN);
                break;
            case R.id.sim_pin_menu_item:
                setMode(MODE_SIM_PIN);
                break;
            case R.id.sim_puk_menu_item:
                setMode(MODE_SIM_PUK);
                break;
            case R.id.add_widget_item:
                startWidgetPicker();
                break;
            default:
                return super.onOptionsItemSelected(item);
        }
        try {
            mService.doKeyguardTimeout(null);
        } catch (RemoteException e) {
            Log.e(TAG, "Remote service died");
            e.printStackTrace();
        }
        return true;
    
protected voidonPause()

        super.onPause();
        try {
            if (mService != null) {
                mService.setHidden(true);
            }
        } catch (RemoteException e) {
            Log.e(TAG, "Remote service died");
            e.printStackTrace();
        }
    
protected voidonRestoreInstanceState(android.os.Bundle savedInstanceState)

        super.onRestoreInstanceState(savedInstanceState);
        setMode(savedInstanceState.getInt(SECURITY_MODE));
    
protected voidonResume()

        super.onResume();
        try {
            if (mService != null) {
                mService.setHidden(false);
            }
        } catch (RemoteException e) {
            Log.e(TAG, "Remote service died");
            e.printStackTrace();
        }
    
protected voidonSaveInstanceState(android.os.Bundle outState)

        super.onSaveInstanceState(outState);
        outState.putInt(SECURITY_MODE, mSecurityMode);
    
private voidsetMode(int mode)

        mTestSimPin = false;
        mTestSimPuk = false;
        mLockPasswordEnabled = false;
        mLockPatternEnabled = false;
        switch(mode) {
            case MODE_NONE:
                mSecurityModeMock = DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
                break;
            case MODE_PIN:
                mSecurityModeMock = DevicePolicyManager.PASSWORD_QUALITY_NUMERIC;
                mLockPasswordEnabled = true;
                break;
            case MODE_PASSWORD:
                mSecurityModeMock = DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC;
                mLockPasswordEnabled = true;
                break;
            case MODE_PATTERN:
                mSecurityModeMock = DevicePolicyManager.PASSWORD_QUALITY_SOMETHING;
                mLockPatternEnabled = true;
                break;
            case MODE_SIM_PIN:
                mTestSimPin = true;
                break;
            case MODE_SIM_PUK:
                mTestSimPuk = true;
                break;
        }
        mSecurityMode = mode;
    
private voidstartWidgetPicker()

        startActivity(new Intent(Settings.ACTION_SECURITY_SETTINGS));