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

Commit e7636e47 authored by Lorenzo Colitti's avatar Lorenzo Colitti
Browse files

Make it easier to test code that uses WakeupMessage.

Code that uses WakeupMessage uses the AlarmManager. Testing such
code is slow because AlarmManager.MIN_FUTURITY ensures that
alarms must wait at least 5 seconds before firing.

This change makes WakeupMessage's fields protected so that test
code can subclass from it and override schedule() and cancel()
with implementations that do not use AlarmManager, for example
by making schedule() call sendEmptyMessageDelayed and making
cancel() call removeMessages.

Change-Id: I51096b182d9eb87cc7bd46c3c91906f18356b354
parent 5b30f0df
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import android.content.Context;
import android.os.Handler;
import android.os.Message;

import com.android.internal.annotations.VisibleForTesting;

 /**
 * An AlarmListener that sends the specified message to a Handler and keeps the system awake until
 * the message is processed.
@@ -36,9 +38,13 @@ import android.os.Message;
 */
public class WakeupMessage implements AlarmManager.OnAlarmListener {
    private final AlarmManager mAlarmManager;
    private final Handler mHandler;
    private final String mCmdName;
    private final int mCmd, mArg1, mArg2;

    @VisibleForTesting
    protected final Handler mHandler;
    @VisibleForTesting
    protected final String mCmdName;
    @VisibleForTesting
    protected final int mCmd, mArg1, mArg2;
    private boolean mScheduled;

    public WakeupMessage(Context context, Handler handler,