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

Commit 93c001b8 authored by Thomas Nguyen's avatar Thomas Nguyen
Browse files

Change return type of isSatelliteSupported from Boolean to boolean

Bug: 274136093
Test: Emergency/normal call, SMS, MMS with live network.
atest com.android.internal.telephony.satellite.SatelliteSOSMessageRecommenderTest
atest com.android.internal.telephony.satellite.SatelliteSessionControllerTest
atest android.telephony.cts.SatelliteManagerTest

Change-Id: I78aa245b0656cf994b21c449ba0e4e7f5058364b
parent cb2ee091
Loading
Loading
Loading
Loading
+48 −38
Original line number Diff line number Diff line
@@ -185,7 +185,7 @@ public class SatelliteController extends Handler {
     * @param looper The looper for the handler. It does not run on main thread.
     */
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    protected SatelliteController(@NonNull Context context, @NonNull Looper looper) {
    public SatelliteController(@NonNull Context context, @NonNull Looper looper) {
        super(looper);

        mContext = context;
@@ -512,6 +512,8 @@ public class SatelliteController extends Handler {
                        bundle.putBoolean(SatelliteManager.KEY_SATELLITE_ENABLED, enabled);
                        updateSatelliteEnabledState(enabled, "EVENT_IS_SATELLITE_ENABLED_DONE");
                    }
                } else if (error == SatelliteManager.SATELLITE_REQUEST_NOT_SUPPORTED) {
                    updateSatelliteSupportedState(false);
                }
                ((ResultReceiver) request.argument).send(error, bundle);
                break;
@@ -829,7 +831,7 @@ public class SatelliteController extends Handler {
    public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
            @NonNull IIntegerConsumer callback) {
        Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
        Boolean satelliteSupported = isSatelliteSupported();
        Boolean satelliteSupported = isSatelliteSupportedInternal();
        if (satelliteSupported == null) {
            result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
            return;
@@ -862,7 +864,7 @@ public class SatelliteController extends Handler {
     *               if the request is successful or an error code if the request failed.
     */
    public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
        Boolean satelliteSupported = isSatelliteSupported();
        Boolean satelliteSupported = isSatelliteSupportedInternal();
        if (satelliteSupported == null) {
            result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
            return;
@@ -894,7 +896,7 @@ public class SatelliteController extends Handler {
     *               if the request is successful or an error code if the request failed.
     */
    public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
        Boolean satelliteSupported = isSatelliteSupported();
        Boolean satelliteSupported = isSatelliteSupportedInternal();
        if (satelliteSupported == null) {
            result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
            return;
@@ -948,7 +950,7 @@ public class SatelliteController extends Handler {
     *               if the request is successful or an error code if the request failed.
     */
    public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
        Boolean satelliteSupported = isSatelliteSupported();
        Boolean satelliteSupported = isSatelliteSupportedInternal();
        if (satelliteSupported == null) {
            result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
            return;
@@ -984,7 +986,7 @@ public class SatelliteController extends Handler {
            @NonNull IIntegerConsumer errorCallback,
            @NonNull ISatelliteTransmissionUpdateCallback callback) {
        Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(errorCallback::accept);
        Boolean satelliteSupported = isSatelliteSupported();
        Boolean satelliteSupported = isSatelliteSupportedInternal();
        if (satelliteSupported == null) {
            result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
            return;
@@ -1023,7 +1025,7 @@ public class SatelliteController extends Handler {
    public void stopSatelliteTransmissionUpdates(int subId, @NonNull IIntegerConsumer errorCallback,
            @NonNull ISatelliteTransmissionUpdateCallback callback) {
        Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(errorCallback::accept);
        Boolean satelliteSupported = isSatelliteSupported();
        Boolean satelliteSupported = isSatelliteSupportedInternal();
        if (satelliteSupported == null) {
            result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
            return;
@@ -1070,7 +1072,7 @@ public class SatelliteController extends Handler {
    @Nullable public ICancellationSignal provisionSatelliteService(int subId,
            @NonNull String token, @NonNull String regionId, @NonNull IIntegerConsumer callback) {
        Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
        Boolean satelliteSupported = isSatelliteSupported();
        Boolean satelliteSupported = isSatelliteSupportedInternal();
        if (satelliteSupported == null) {
            result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
            return null;
@@ -1120,7 +1122,7 @@ public class SatelliteController extends Handler {
    public void deprovisionSatelliteService(int subId,
            @NonNull String token, @NonNull IIntegerConsumer callback) {
        Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
        Boolean satelliteSupported = isSatelliteSupported();
        Boolean satelliteSupported = isSatelliteSupportedInternal();
        if (satelliteSupported == null) {
            result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
            return;
@@ -1156,7 +1158,7 @@ public class SatelliteController extends Handler {
     */
    @SatelliteManager.SatelliteError public int registerForSatelliteProvisionStateChanged(int subId,
            @NonNull ISatelliteProvisionStateCallback callback) {
        Boolean satelliteSupported = isSatelliteSupported();
        Boolean satelliteSupported = isSatelliteSupportedInternal();
        if (satelliteSupported == null) {
            return SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE;
        }
@@ -1190,7 +1192,7 @@ public class SatelliteController extends Handler {
     *               request failed.
     */
    public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
        Boolean satelliteSupported = isSatelliteSupported();
        Boolean satelliteSupported = isSatelliteSupportedInternal();
        if (satelliteSupported == null) {
            result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
            return;
@@ -1359,7 +1361,7 @@ public class SatelliteController extends Handler {
     */
    public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId,
            @NonNull ResultReceiver result) {
        Boolean satelliteSupported = isSatelliteSupported();
        Boolean satelliteSupported = isSatelliteSupportedInternal();
        if (satelliteSupported == null) {
            result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
            return;
@@ -1381,7 +1383,7 @@ public class SatelliteController extends Handler {
     *               be visible if the request is successful or an error code if the request failed.
     */
    public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
        Boolean satelliteSupported = isSatelliteSupported();
        Boolean satelliteSupported = isSatelliteSupportedInternal();
        if (satelliteSupported == null) {
            result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
            return;
@@ -1405,31 +1407,6 @@ public class SatelliteController extends Handler {
        sendRequestAsync(CMD_GET_TIME_SATELLITE_NEXT_VISIBLE, result, phone);
    }

    /**
     * If we have not successfully queried the satellite modem for its satellite service support,
     * we will retry the query one more time. Otherwise, we will return the cached result.
     */
    public Boolean isSatelliteSupported() {
        synchronized (mIsSatelliteSupportedLock) {
            if (mIsSatelliteSupported != null) {
                /* We have already successfully queried the satellite modem. */
                return mIsSatelliteSupported;
            }
        }
        /**
         * We have not successfully checked whether the modem supports satellite service.
         * Thus, we need to retry it now.
         */
        requestIsSatelliteSupported(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
                new ResultReceiver(this) {
                    @Override
                    protected void onReceiveResult(int resultCode, Bundle resultData) {
                        logd("requestIsSatelliteSupported: resultCode=" + resultCode);
                    }
                });
        return null;
    }

    /**
     * This function is used by {@link SatelliteModemInterface} to notify
     * {@link SatelliteController} that the satellite vendor service was just connected.
@@ -1460,6 +1437,39 @@ public class SatelliteController extends Handler {
        }
    }

    /**
     * @return {@code true} is satellite is supported on the device, {@code  false} otherwise.
     */
    public boolean isSatelliteSupported() {
        Boolean supported = isSatelliteSupportedInternal();
        return (supported != null ? supported : false);
    }

    /**
     * If we have not successfully queried the satellite modem for its satellite service support,
     * we will retry the query one more time. Otherwise, we will return the cached result.
     */
    private Boolean isSatelliteSupportedInternal() {
        synchronized (mIsSatelliteSupportedLock) {
            if (mIsSatelliteSupported != null) {
                /* We have already successfully queried the satellite modem. */
                return mIsSatelliteSupported;
            }
        }
        /**
         * We have not successfully checked whether the modem supports satellite service.
         * Thus, we need to retry it now.
         */
        requestIsSatelliteSupported(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
                new ResultReceiver(this) {
                    @Override
                    protected void onReceiveResult(int resultCode, Bundle resultData) {
                        logd("requestIsSatelliteSupported: resultCode=" + resultCode);
                    }
                });
        return null;
    }

    private void handleEventProvisionSatelliteServiceDone(
            @NonNull ProvisionSatelliteServiceArgument arg,
            @SatelliteManager.SatelliteError int result) {
+2 −1
Original line number Diff line number Diff line
@@ -578,7 +578,8 @@ public class SatelliteModemInterface {
            }
        } else {
            loge("requestIsSatelliteSupported: Satellite service is unavailable.");
            sendMessageWithResult(message, null, SatelliteManager.SATELLITE_REQUEST_NOT_SUPPORTED);
            sendMessageWithResult(
                    message, null, SatelliteManager.SATELLITE_RADIO_NOT_AVAILABLE);
        }
    }

+9 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.os.Looper;
import android.os.Message;
import android.os.RemoteException;
import android.provider.DeviceConfig;
import android.telephony.Rlog;
import android.telephony.satellite.ISatelliteStateCallback;
import android.telephony.satellite.SatelliteManager;
import android.util.Log;
@@ -92,6 +93,7 @@ public class SatelliteSessionController extends StateMachine {
    private final long mSatelliteStayAtListeningFromReceivingMillis;
    private final ConcurrentHashMap<IBinder, ISatelliteStateCallback> mListeners;
    @SatelliteManager.SatelliteModemState private int mCurrentState;
    final boolean mIsSatelliteSupported;

    /**
     * @return The singleton instance of SatelliteSessionController.
@@ -118,6 +120,12 @@ public class SatelliteSessionController extends StateMachine {
                    SatelliteModemInterface.getInstance(),
                    getSatelliteStayAtListeningFromSendingMillis(),
                    getSatelliteStayAtListeningFromReceivingMillis());
        } else {
            if (isSatelliteSupported != sInstance.mIsSatelliteSupported) {
                Rlog.e(TAG, "New satellite support state " + isSatelliteSupported
                        + " is different from existing state " + sInstance.mIsSatelliteSupported
                        + ". Ignore the new state.");
            }
        }
        return sInstance;
    }
@@ -149,6 +157,7 @@ public class SatelliteSessionController extends StateMachine {
        mListeners = new ConcurrentHashMap<>();
        mIsSendingTriggeredDuringTransferringState = new AtomicBoolean(false);
        mCurrentState = SatelliteManager.SATELLITE_MODEM_STATE_UNKNOWN;
        mIsSatelliteSupported = isSatelliteSupported;

        addState(mUnavailableState);
        addState(mPowerOffState);
+16 −2
Original line number Diff line number Diff line
@@ -72,7 +72,6 @@ import java.util.concurrent.Executor;
public class SatelliteSOSMessageRecommenderTest extends TelephonyTest {
    private static final String TAG = "SatelliteSOSMessageRecommenderTest";
    private static final long TEST_EMERGENCY_CALL_TO_SOS_MSG_HYSTERESIS_TIMEOUT_MILLIS = 500;
    private static final long EVENT_PROCESSING_TIME_MILLIS = 100;
    private static final int PHONE_ID = 0;
    private static final String CALL_ID = "CALL_ID";
    private static final String WRONG_CALL_ID = "WRONG_CALL_ID";
@@ -314,6 +313,21 @@ public class SatelliteSOSMessageRecommenderTest extends TelephonyTest {
        assertUnregisterForStateChangedEventsTriggered(mPhone, 1, 1, 1);
    }

    @Test
    public void testOnEmergencyCallStarted() {
        SatelliteController satelliteController = new SatelliteController(
                mMockContext, Looper.myLooper());
        TestSOSMessageRecommender testSOSMessageRecommender = new TestSOSMessageRecommender(
                Looper.myLooper(),
                satelliteController, mTestImsManager,
                TEST_EMERGENCY_CALL_TO_SOS_MSG_HYSTERESIS_TIMEOUT_MILLIS);
        testSOSMessageRecommender.onEmergencyCallStarted(mTestConnection, mPhone);
        processAllMessages();

        assertFalse(testSOSMessageRecommender.isTimerStarted());
        assertEquals(0, testSOSMessageRecommender.getCountOfTimerStarted());
    }

    private void testStopTrackingCallBeforeTimeout(
            @Connection.ConnectionState int connectionState) {
        mTestSOSMessageRecommender.onEmergencyCallStarted(mTestConnection, mPhone);
@@ -409,7 +423,7 @@ public class SatelliteSOSMessageRecommenderTest extends TelephonyTest {
        }

        @Override
        public Boolean isSatelliteSupported() {
        public boolean isSatelliteSupported() {
            return true;
        }