Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0c71404e authored by Brad Ebinger's avatar Brad Ebinger
Browse files

Add handler callbacks to StateMachine

Adds two callbacks to StateMachine that notify its user when (1) a message
is about to be processed in the StateMachine and (2) after the StateMachine
has successfully processed a message and has transitioned to a new
State.

Change-Id: I694793872a22f56b3092f5d8b39a116e385a64da
parent 62211c9b
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -778,6 +778,7 @@ public class StateMachine {
         */
        @Override
        public final void handleMessage(Message msg) {
            mSm.onPreHandleMessage(msg);
            if (!mHasQuit) {
                if (mDbg) mSm.log("handleMessage: E msg.what=" + msg.what);

@@ -803,6 +804,7 @@ public class StateMachine {
                // We need to check if mSm == null here as we could be quitting.
                if (mDbg && mSm != null) mSm.log("handleMessage: X");
            }
            mSm.onPostHandleMessage(msg);
        }

        /**
@@ -1273,6 +1275,21 @@ public class StateMachine {
        initStateMachine(name, handler.getLooper());
    }

    /**
     * Notifies subclass that the StateMachine handler is about to process the Message msg
     * @param msg The message that is being handled
     */
    protected void onPreHandleMessage(Message msg) {
    }

    /**
     * Notifies subclass that the StateMachine handler has finished processing the Message msg and
     * has possibly transitioned to a new state.
     * @param msg The message that is being handled
     */
    protected void onPostHandleMessage(Message msg) {
    }

    /**
     * Add a new state to the state machine
     * @param state the state to add