FileDocCategorySizeDatePackage
EmergencyButton.javaAPI DocAndroid 5.1 API4831Thu Mar 12 22:22:42 GMT 2015com.android.keyguard

EmergencyButton

public class EmergencyButton extends android.widget.Button
This class implements a smart emergency button that updates itself based on telephony state. When the phone is idle, it is an emergency call button. When there's a call in progress, it presents an appropriate message and allows the user to return to the call.

Fields Summary
private static final String
ACTION_EMERGENCY_DIAL
KeyguardUpdateMonitorCallback
mInfoCallback
private com.android.internal.widget.LockPatternUtils
mLockPatternUtils
private android.os.PowerManager
mPowerManager
Constructors Summary
public EmergencyButton(android.content.Context context)


       
        this(context, null);
    
public EmergencyButton(android.content.Context context, android.util.AttributeSet attrs)

        super(context, attrs);
    
Methods Summary
protected voidonAttachedToWindow()

        super.onAttachedToWindow();
        KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mInfoCallback);
    
protected voidonDetachedFromWindow()

        super.onDetachedFromWindow();
        KeyguardUpdateMonitor.getInstance(mContext).removeCallback(mInfoCallback);
    
protected voidonFinishInflate()

        super.onFinishInflate();
        mLockPatternUtils = new LockPatternUtils(mContext);
        mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
        setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                takeEmergencyCallAction();
            }
        });
        updateEmergencyCallButton();
    
public voidtakeEmergencyCallAction()
Shows the emergency dialer or returns the user to the existing call.

        // TODO: implement a shorter timeout once new PowerManager API is ready.
        // should be the equivalent to the old userActivity(EMERGENCY_CALL_TIMEOUT)
        mPowerManager.userActivity(SystemClock.uptimeMillis(), true);
        if (mLockPatternUtils.isInCall()) {
            mLockPatternUtils.resumeCall();
        } else {
            final boolean bypassHandler = true;
            KeyguardUpdateMonitor.getInstance(mContext).reportEmergencyCallAction(bypassHandler);
            Intent intent = new Intent(ACTION_EMERGENCY_DIAL);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                    | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
            getContext().startActivityAsUser(intent,
                    new UserHandle(mLockPatternUtils.getCurrentUser()));
        }
    
private voidupdateEmergencyCallButton()

        boolean enabled = false;
        if (mLockPatternUtils.isInCall()) {
            enabled = true; // always show "return to call" if phone is off-hook
        } else if (mLockPatternUtils.isEmergencyCallCapable()) {
            final boolean simLocked = KeyguardUpdateMonitor.getInstance(mContext).isSimPinVoiceSecure();
            if (simLocked) {
                // Some countries can't handle emergency calls while SIM is locked.
                enabled = mLockPatternUtils.isEmergencyCallEnabledWhileSimLocked();
            } else {
                // True if we need to show a secure screen (pin/pattern/SIM pin/SIM puk);
                // hides emergency button on "Slide" screen if device is not secure.
                enabled = mLockPatternUtils.isSecure();
            }
        }
        mLockPatternUtils.updateEmergencyCallButtonState(this, enabled, false);