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

Commit 8b292d3d authored by Ling Ma's avatar Ling Ma
Browse files

Add signal strength callback

The existing telephonyCallback for signal strength is registered by sub Id, so the registrant cares about the phone id only, it will need to monitor the sub Id change on this phone slot. Adding a sub id agnostic callback solves this issue, which is the behavior that's consistent with DisplayInfoController.

Bug: 260928808
Test: phone call + internet browsing
Test: daily test P22 https://testtracker.googleplex.com/efforts/testplans/1498577 and P23 https://testtracker.googleplex.com/efforts/testplans/1498694
Change-Id: I1c8f1b6fec2674be62571e7354510085fda10e59
parent 764fccaf
Loading
Loading
Loading
Loading
+24 −1
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@ import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.PersistableBundle;
import android.os.Registrant;
import android.os.RegistrantList;
import android.os.RemoteException;
import android.telephony.AccessNetworkConstants;
import android.telephony.CarrierConfigManager;
@@ -102,7 +104,8 @@ public class SignalStrengthController extends Handler {
    private final Phone mPhone;
    @NonNull
    private final CommandsInterface mCi;

    @NonNull
    private final RegistrantList mSignalStrengthChangedRegistrants = new RegistrantList();
    @NonNull
    private SignalStrength mSignalStrength;
    private long mSignalStrengthUpdatedTime;
@@ -721,6 +724,7 @@ public class SignalStrengthController extends Handler {
        boolean notified = false;
        if (!mSignalStrength.equals(mLastSignalStrength)) {
            try {
                mSignalStrengthChangedRegistrants.notifyRegistrants();
                mPhone.notifySignalStrength();
                notified = true;
                mLastSignalStrength = mSignalStrength;
@@ -732,6 +736,25 @@ public class SignalStrengthController extends Handler {
        return notified;
    }

    /**
     * Register for SignalStrength changed.
     * @param h Handler to notify
     * @param what msg.what when the message is delivered
     * @param obj msg.obj when the message is delivered
     */
    public void registerForSignalStrengthChanged(Handler h, int what, Object obj) {
        Registrant r = new Registrant(h, what, obj);
        mSignalStrengthChangedRegistrants.add(r);
    }

    /**
     * Unregister for SignalStrength changed.
     * @param h Handler to notify
     */
    public void unregisterForSignalStrengthChanged(Handler h) {
        mSignalStrengthChangedRegistrants.remove(h);
    }

    /**
     * Print the SignalStrengthController states into the given stream.
     *
+13 −0
Original line number Diff line number Diff line
@@ -946,6 +946,19 @@ public class SignalStrengthControllerTest extends TelephonyTest {
                1 /*expectedNonEmptyThreshold*/);
    }

    @Test
    public void testSignalStrengthChangedCallback() {
        Handler mockRegistrant = Mockito.mock(Handler.class);
        int ssChangedEvent = 0;
        mSsc.registerForSignalStrengthChanged(mockRegistrant, ssChangedEvent, null);
        mSimulatedCommands.notifySignalStrength();
        processAllMessages();

        ArgumentCaptor<Message> msgCaptor = ArgumentCaptor.forClass(Message.class);
        verify(mockRegistrant).sendMessageDelayed(msgCaptor.capture(), Mockito.anyLong());
        assertThat(msgCaptor.getValue().what).isEqualTo(ssChangedEvent);
    }

    private void verifyAllEmptyThresholdAreDisabledWhenSetSignalStrengthReportingCriteria(
            int expectedNonEmptyThreshold) {
        ArgumentCaptor<List<SignalThresholdInfo>> signalThresholdInfoCaptor =