WakeLockStateMachinepublic 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_MESSAGENew message to process. | protected static final int | EVENT_BROADCAST_COMPLETEResult receiver called for current cell broadcast. | static final int | EVENT_RELEASE_WAKE_LOCKRelease 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_TIMEOUTWakelock release delay when returning to idle state. | private final DefaultState | mDefaultState | private final IdleState | mIdleState | private final WaitingState | mWaitingState | protected final android.content.BroadcastReceiver | mReceiverBroadcastReceiver 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 void | dispatchSmsMessage(java.lang.Object obj)Send a message with the specified object for {@link #handleSmsMessage}.
sendMessage(EVENT_NEW_SMS_MESSAGE, obj);
| public final void | dispose()Tell the state machine to quit after processing all messages.
quit();
| protected abstract boolean | handleSmsMessage(android.os.Message message)Implemented by subclass to handle messages in {@link IdleState}.
| protected void | log(java.lang.String s)Log with debug level.
Rlog.d(getName(), s);
| protected void | loge(java.lang.String s)Log with error level.
Rlog.e(getName(), s);
| protected void | loge(java.lang.String s, java.lang.Throwable e)Log with error level.
Rlog.e(getName(), s, e);
| protected void | onQuitting()
// fully release the wakelock
while (mWakeLock.isHeld()) {
mWakeLock.release();
}
| public void | updatePhoneObject(PhoneBase phone)
sendMessage(EVENT_UPDATE_PHONE_OBJECT, phone);
|
|