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

Commit 4d611342 authored by Hakjun Choi's avatar Hakjun Choi
Browse files

Modify error handling for registerForNtnSignalStrength

Return value of registerForNtnSignalStrengthChanged become void from int.
Throws RemoteException which wraps SatelliteException includes
SatelliteResult, when registration operation fails.

Bug: 306111250
Test: atest SatelliteControllerTest, SatelliteManagerTest, SatelliteManagerTestOnMockService
Change-Id: I2a7fa65204a102584e12622b8f92dedc68a384a8
parent 9feb3c43
Loading
Loading
Loading
Loading
+17 −10
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ import android.os.Message;
import android.os.PersistableBundle;
import android.os.RemoteException;
import android.os.ResultReceiver;
import android.os.ServiceSpecificException;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.provider.Settings;
@@ -2005,23 +2006,29 @@ public class SatelliteController extends Handler {
    }

    /**
     * Registers for NTN signal strength changed from satellite modem.
     * Registers for NTN signal strength changed from satellite modem. If the registration operation
     * is not successful, a {@link ServiceSpecificException} that contains
     * {@link SatelliteManager.SatelliteResult} will be thrown.
     *
     * @param subId The id of the subscription to request for.
     * @param callback The callback to handle the non-terrestrial network signal strength changed
     * event.
     * @param callback The callback to handle the NTN signal strength changed event. If the
     * operation is successful, {@link INtnSignalStrengthCallback#onNtnSignalStrengthChanged(
     * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
     * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
     * network has changed.
     *
     * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
     * @throws ServiceSpecificException If the callback registration operation fails.
     */
    @SatelliteManager.SatelliteResult public int registerForNtnSignalStrengthChanged(
            int subId, @NonNull INtnSignalStrengthCallback callback) {
    public void registerForNtnSignalStrengthChanged(int subId,
            @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
        if (DBG) logd("registerForNtnSignalStrengthChanged()");

        int error = evaluateOemSatelliteRequestAllowed(true);
        if (error != SATELLITE_RESULT_SUCCESS) return error;

        if (error == SATELLITE_RESULT_SUCCESS) {
            mNtnSignalStrengthChangedListeners.put(callback.asBinder(), callback);
        return SATELLITE_RESULT_SUCCESS;
        } else {
            throw new ServiceSpecificException(error);
        }
    }

    /**
+39 −21
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
@@ -91,7 +92,9 @@ import android.os.ICancellationSignal;
import android.os.Looper;
import android.os.Message;
import android.os.PersistableBundle;
import android.os.RemoteException;
import android.os.ResultReceiver;
import android.os.ServiceSpecificException;
import android.telephony.CarrierConfigManager;
import android.telephony.Rlog;
import android.telephony.ServiceState;
@@ -2156,16 +2159,16 @@ public class SatelliteControllerTest extends TelephonyTest {
                    }
                };

        int errorCode = mSatelliteControllerUT.registerForNtnSignalStrengthChanged(SUB_ID,
                callback);
        assertEquals(SATELLITE_RESULT_INVALID_TELEPHONY_STATE, errorCode);
        @NtnSignalStrength.NtnSignalStrengthLevel int expectedLevel = NTN_SIGNAL_STRENGTH_NONE;
        verifyRegisterForNtnSignalStrengthChanged(SUB_ID, callback,
                SATELLITE_RESULT_INVALID_TELEPHONY_STATE);

        setUpResponseForRequestIsSatelliteSupported(false,
                SATELLITE_RESULT_SUCCESS);
        verifySatelliteSupported(false, SATELLITE_RESULT_SUCCESS);
        errorCode = mSatelliteControllerUT.registerForNtnSignalStrengthChanged(SUB_ID, callback);
        assertEquals(SATELLITE_RESULT_NOT_SUPPORTED, errorCode);
        verifyRegisterForNtnSignalStrengthChanged(SUB_ID, callback,
                SATELLITE_RESULT_NOT_SUPPORTED);

        @NtnSignalStrength.NtnSignalStrengthLevel int expectedLevel = NTN_SIGNAL_STRENGTH_NONE;
        verifyRequestNtnSignalStrength(expectedLevel, SATELLITE_RESULT_NOT_SUPPORTED);

        resetSatelliteControllerUT();
@@ -2173,8 +2176,8 @@ public class SatelliteControllerTest extends TelephonyTest {
        setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS);
        setUpResponseForRequestNtnSignalStrength(expectedLevel, SATELLITE_RESULT_SUCCESS);
        verifySatelliteSupported(true, SATELLITE_RESULT_SUCCESS);
        errorCode = mSatelliteControllerUT.registerForNtnSignalStrengthChanged(SUB_ID, callback);
        assertEquals(SATELLITE_RESULT_SUCCESS, errorCode);
        verifyRegisterForNtnSignalStrengthChanged(SUB_ID, callback,
                SATELLITE_RESULT_SUCCESS);
        verifyRequestNtnSignalStrength(expectedLevel, SATELLITE_RESULT_SUCCESS);

        expectedLevel = NTN_SIGNAL_STRENGTH_GOOD;
@@ -2225,15 +2228,14 @@ public class SatelliteControllerTest extends TelephonyTest {
                    }
                };

        int errorCode = mSatelliteControllerUT.registerForNtnSignalStrengthChanged(SUB_ID,
                callback);
        assertEquals(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, errorCode);
        verifyRegisterForNtnSignalStrengthChanged(SUB_ID, callback,
                SATELLITE_RESULT_REQUEST_NOT_SUPPORTED);

        setUpResponseForRequestIsSatelliteSupported(false,
                SATELLITE_RESULT_SUCCESS);
        verifySatelliteSupported(false, SATELLITE_RESULT_NOT_SUPPORTED);
        errorCode = mSatelliteControllerUT.registerForNtnSignalStrengthChanged(SUB_ID, callback);
        assertEquals(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, errorCode);
        verifyRegisterForNtnSignalStrengthChanged(SUB_ID, callback,
                SATELLITE_RESULT_REQUEST_NOT_SUPPORTED);
        setUpResponseForRequestNtnSignalStrength(NTN_SIGNAL_STRENGTH_NONE,
                SATELLITE_RESULT_SUCCESS);
        verifyRequestNtnSignalStrength(NTN_SIGNAL_STRENGTH_NONE,
@@ -2242,8 +2244,8 @@ public class SatelliteControllerTest extends TelephonyTest {
        resetSatelliteControllerUT();
        setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS);
        verifySatelliteSupported(false, SATELLITE_RESULT_NOT_SUPPORTED);
        errorCode = mSatelliteControllerUT.registerForNtnSignalStrengthChanged(SUB_ID, callback);
        assertEquals(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, errorCode);
        verifyRegisterForNtnSignalStrengthChanged(SUB_ID, callback,
                SATELLITE_RESULT_REQUEST_NOT_SUPPORTED);
        verifyRequestNtnSignalStrength(NTN_SIGNAL_STRENGTH_NONE,
                SATELLITE_RESULT_REQUEST_NOT_SUPPORTED);

@@ -3101,6 +3103,22 @@ public class SatelliteControllerTest extends TelephonyTest {
        mSimulatedCommands.setRadioPower(on, false, false, null);
    }

    private void verifyRegisterForNtnSignalStrengthChanged(int subId,
            INtnSignalStrengthCallback callback, int expectedError) {
        if (expectedError == SATELLITE_RESULT_SUCCESS) {
            try {
                mSatelliteControllerUT.registerForNtnSignalStrengthChanged(subId, callback);
            } catch (RemoteException ex) {
                throw new AssertionError();
            }
        } else {
            ServiceSpecificException ex = assertThrows(ServiceSpecificException.class,
                    () -> mSatelliteControllerUT.registerForNtnSignalStrengthChanged(subId,
                            callback));
            assertEquals(expectedError, ex.errorCode);
        }
    }

    private static void loge(String message) {
        Rlog.e(TAG, message);
    }