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

Commit 06dd990e authored by Chen Xu's avatar Chen Xu Committed by Gerrit Code Review
Browse files

Merge "Optimize power for incoming SMS"

parents 4dbf14ac b6655ffd
Loading
Loading
Loading
Loading
+29 −3
Original line number Diff line number Diff line
@@ -145,7 +145,7 @@ public abstract class InboundSmsHandler extends StateMachine {
    /** Sent on exit from {@link WaitingState} to return to idle after sending all broadcasts. */
    private static final int EVENT_RETURN_TO_IDLE = 4;

    /** Release wakelock after a short timeout when returning to idle state. */
    /** Release wakelock after {@link mWakeLockTimeout} when returning to idle state. */
    private static final int EVENT_RELEASE_WAKELOCK = 5;

    /** Sent by {@link SmsBroadcastUndelivered} after cleaning the raw table. */
@@ -215,6 +215,9 @@ public abstract class InboundSmsHandler extends StateMachine {
    private static String ACTION_OPEN_SMS_APP =
        "com.android.internal.telephony.OPEN_DEFAULT_SMS_APP";

    /** Timeout for releasing wakelock */
    private int mWakeLockTimeout;

    /**
     * Create a new SMS broadcast helper.
     * @param name the class name for logging
@@ -323,6 +326,14 @@ public abstract class InboundSmsHandler extends StateMachine {
     * notify the state machine to broadcast any complete PDUs that might not have been broadcast.
     */
    private class StartupState extends State {
        @Override
        public void enter() {
            if (DBG) log("entering Startup state");
            // Set wakelock timeout to 0 during startup, this will ensure that the wakelock is not
            // held if there are no pending messages to be handled.
            setWakeLockTimeout(0);
        }

        @Override
        public boolean processMessage(Message msg) {
            log("StartupState.processMessage:" + msg.what);
@@ -355,7 +366,7 @@ public abstract class InboundSmsHandler extends StateMachine {
        @Override
        public void enter() {
            if (DBG) log("entering Idle state");
            sendMessageDelayed(EVENT_RELEASE_WAKELOCK, WAKELOCK_TIMEOUT);
            sendMessageDelayed(EVENT_RELEASE_WAKELOCK, getWakeLockTimeout());
        }

        @Override
@@ -481,6 +492,14 @@ public abstract class InboundSmsHandler extends StateMachine {
     * {@link IdleState} after any deferred {@link #EVENT_BROADCAST_SMS} messages are handled.
     */
    private class WaitingState extends State {
        @Override
        public void exit() {
            if (DBG) log("exiting Waiting state");
            // Before moving to idle state, set wakelock timeout to WAKE_LOCK_TIMEOUT milliseconds
            // to give any receivers time to take their own wake locks
            setWakeLockTimeout(WAKELOCK_TIMEOUT);
        }

        @Override
        public boolean processMessage(Message msg) {
            log("WaitingState.processMessage:" + msg.what);
@@ -1500,7 +1519,14 @@ public abstract class InboundSmsHandler extends StateMachine {

    @VisibleForTesting
    public int getWakeLockTimeout() {
        return WAKELOCK_TIMEOUT;
        return mWakeLockTimeout;
    }

    /**
    * Sets the wakelock timeout to {@link timeOut} milliseconds
    */
    private void setWakeLockTimeout(int timeOut) {
        mWakeLockTimeout = timeOut;
    }

    /**