FileDocCategorySizeDatePackage
WakeLockStateMachine.javaAPI DocAndroid 5.1 API8460Thu Mar 12 22:22:54 GMT 2015com.android.internal.telephony

WakeLockStateMachine

public abstract class WakeLockStateMachine extends com.android.internal.util.StateMachine
Generic state machine for handling messages and waiting for ordered broadcasts to complete. Subclasses implement {@link #handleSmsMessage}, which returns true to transition into waiting state, or false to remain in idle state. The wakelock is acquired on exit from idle state, and is released a few seconds after returning to idle state, or immediately upon calling {@link #quit}.

Fields Summary
protected static final boolean
DBG
private final PowerManager.WakeLock
mWakeLock
public static final int
EVENT_NEW_SMS_MESSAGE
New message to process.
protected static final int
EVENT_BROADCAST_COMPLETE
Result receiver called for current cell broadcast.
static final int
EVENT_RELEASE_WAKE_LOCK
Release wakelock after a short timeout when returning to idle state.
static final int
EVENT_UPDATE_PHONE_OBJECT
protected PhoneBase
mPhone
protected android.content.Context
mContext
private static final int
WAKE_LOCK_TIMEOUT
Wakelock release delay when returning to idle state.
private final DefaultState
mDefaultState
private final IdleState
mIdleState
private final WaitingState
mWaitingState
protected final android.content.BroadcastReceiver
mReceiver
BroadcastReceiver to send message to return to idle state.
Constructors Summary
protected WakeLockStateMachine(String debugTag, android.content.Context context, PhoneBase phone)


           
        super(debugTag);

        mContext = context;
        mPhone = phone;

        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, debugTag);
        mWakeLock.acquire();    // wake lock released after we enter idle state

        addState(mDefaultState);
        addState(mIdleState, mDefaultState);
        addState(mWaitingState, mDefaultState);
        setInitialState(mIdleState);
    
Methods Summary
public final voiddispatchSmsMessage(java.lang.Object obj)
Send a message with the specified object for {@link #handleSmsMessage}.

param
obj the object to pass in the msg.obj field

        sendMessage(EVENT_NEW_SMS_MESSAGE, obj);
    
public final voiddispose()
Tell the state machine to quit after processing all messages.

        quit();
    
protected abstract booleanhandleSmsMessage(android.os.Message message)
Implemented by subclass to handle messages in {@link IdleState}.

param
message the message to process
return
true to transition to {@link WaitingState}; false to stay in {@link IdleState}

protected voidlog(java.lang.String s)
Log with debug level.

param
s the string to log


                   
    
        
        Rlog.d(getName(), s);
    
protected voidloge(java.lang.String s)
Log with error level.

param
s the string to log

        Rlog.e(getName(), s);
    
protected voidloge(java.lang.String s, java.lang.Throwable e)
Log with error level.

param
s the string to log
param
e is a Throwable which logs additional information.

        Rlog.e(getName(), s, e);
    
protected voidonQuitting()

        // fully release the wakelock
        while (mWakeLock.isHeld()) {
            mWakeLock.release();
        }
    
public voidupdatePhoneObject(PhoneBase phone)

        sendMessage(EVENT_UPDATE_PHONE_OBJECT, phone);