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

Commit dfc58e75 authored by Aishwarya Mallampati's avatar Aishwarya Mallampati
Browse files

Check if ar.result is boolean before calling cast

Bug: 405485612
Test: atest SatelliteControllerTest
Flag: EXEMPT bugfix
Change-Id: I4f07455f1a5842f5d26308db9c596da316524cce
parent cd57af52
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -1307,7 +1307,8 @@ public class SatelliteController extends Handler {
        }
    }

    private static final class SatelliteControllerHandlerRequest {
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    public static final class SatelliteControllerHandlerRequest {
        /** The argument to use for the request */
        public @NonNull Object argument;
        /** The caller needs to specify the phone to be used for the request */
@@ -1315,7 +1316,7 @@ public class SatelliteController extends Handler {
        /** The result of the request that is run on the main thread */
        public @Nullable Object result;

        SatelliteControllerHandlerRequest(Object argument, Phone phone) {
        public SatelliteControllerHandlerRequest(Object argument, Phone phone) {
            this.argument = argument;
            this.phone = phone;
        }
@@ -2302,7 +2303,7 @@ public class SatelliteController extends Handler {
                    int subId = (int) ar.userObj;
                    int error = SatelliteServiceUtils.getSatelliteError(
                            ar, "isSatelliteEnabledForCarrier");
                    boolean satelliteEnabled = (boolean) ar.result;
                    boolean satelliteEnabled = (Boolean) ar.result;
                    plogd("EVENT_GET_SATELLITE_ENABLED_FOR_CARRIER_DONE: subId=" + subId
                            + " error=" + error + " satelliteEnabled=" + satelliteEnabled);

@@ -6129,7 +6130,8 @@ public class SatelliteController extends Handler {
     * @param subId subscription ID
     * @return {@code true} if satellite modem is enabled, {@code false} otherwise.
     */
    private boolean isSatelliteEnabledForCarrierAtModem(int subId) {
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    public boolean isSatelliteEnabledForCarrierAtModem(int subId) {
        synchronized (mIsSatelliteEnabledLock) {
            return mIsSatelliteAttachEnabledForCarrierArrayPerSub.getOrDefault(subId, false);
        }
+2 −6
Original line number Diff line number Diff line
@@ -1160,13 +1160,9 @@ public class SatelliteModemInterface {
                        }, new IBooleanConsumer.Stub() {
                            @Override
                            public void accept(boolean result) {
                                // Convert for compatibility with SatelliteResponse
                                // TODO: This should just report result instead.
                                int[] enabled = new int[] {result ? 1 : 0};
                                plogd("requestIsSatelliteEnabledForCarrier: "
                                        + Arrays.toString(enabled));
                                plogd("requestIsSatelliteEnabledForCarrier: " + result);
                                Binder.withCleanCallingIdentity(() -> sendMessageWithResult(
                                        message, enabled,
                                        message, result,
                                        SatelliteManager.SATELLITE_RESULT_SUCCESS));
                            }
                        });
+39 −0
Original line number Diff line number Diff line
@@ -5693,6 +5693,22 @@ public class SatelliteControllerTest extends TelephonyTest {
                61 /* CMD_EVALUATE_CARRIER_ROAMING_NTN_ELIGIBILITY_CHANGE */).sendToTarget();
    }

    private void sendCmdGetSatelliteEnabledForCarrier(Phone phone) {
        SatelliteController.SatelliteControllerHandlerRequest request =
                new SatelliteController.SatelliteControllerHandlerRequest(null, phone);
        Message msg = mSatelliteControllerUT.obtainMessage(
                64 /* CMD_GET_SATELLITE_ENABLED_FOR_CARRIER */, request);
        msg.sendToTarget();
    }

    private void sendEventGetSatelliteEnabledForCarrierDone(int subId, Boolean result,
            Throwable exception) {
        Message msg = mSatelliteControllerUT.obtainMessage(
                65 /* EVENT_GET_SATELLITE_ENABLED_FOR_CARRIER_DONE */, subId);
        msg.obj = new AsyncResult(subId, result, exception);
        msg.sendToTarget();
    }

    private void setRadioPower(boolean on) {
        mSimulatedCommands.setRadioPower(on, false, false, null);
    }
@@ -7009,4 +7025,27 @@ public class SatelliteControllerTest extends TelephonyTest {

        verify(mPhone, times(1)).notifyCarrierRoamingNtnEligibleStateChanged(eq(true));
    }

    @Test
    public void testGetSatelliteEnabledForCarrier() {
        reset(mPhone);
        sendCmdGetSatelliteEnabledForCarrier(mPhone);
        processAllMessages();
        verify(mPhone, times(1)).isSatelliteEnabledForCarrier(anyInt(), any());
        reset(mPhone);

        sendEventGetSatelliteEnabledForCarrierDone(mPhone.getSubId(), false,
                new SatelliteException(SATELLITE_RESULT_ERROR));
        processAllMessages();
        assertFalse(mSatelliteControllerUT.isSatelliteEnabledForCarrierAtModem(mPhone.getSubId()));

        sendEventGetSatelliteEnabledForCarrierDone(mPhone.getSubId(), true, null);
        processAllMessages();
        assertTrue(mSatelliteControllerUT.isSatelliteEnabledForCarrierAtModem(mPhone.getSubId()));

        sendEventGetSatelliteEnabledForCarrierDone(mPhone.getSubId(), false, null);
        processAllMessages();
        assertFalse(mSatelliteControllerUT.isSatelliteEnabledForCarrierAtModem(mPhone.getSubId()));
    }

}