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

Commit 5166d141 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add register/unregister callback for selected satellite subscription...

Merge "Add register/unregister callback for selected satellite subscription changed event in SatelliteController and SatelliteModemInterface." into main
parents be25e2b6 5ac2150a
Loading
Loading
Loading
Loading
+96 −0
Original line number Diff line number Diff line
@@ -134,6 +134,7 @@ import android.telephony.satellite.ISatelliteModemStateCallback;
import android.telephony.satellite.ISatelliteProvisionStateCallback;
import android.telephony.satellite.ISatelliteSupportedStateCallback;
import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
import android.telephony.satellite.ISelectedNbIotSatelliteSubscriptionCallback;
import android.telephony.satellite.NtnSignalStrength;
import android.telephony.satellite.SatelliteCapabilities;
import android.telephony.satellite.SatelliteDatagram;
@@ -303,6 +304,7 @@ public class SatelliteController extends Handler {
    private static final int EVENT_SIGNAL_STRENGTH_CHANGED = 57;
    private static final int CMD_UPDATE_SYSTEM_SELECTION_CHANNELS = 58;
    private static final int EVENT_UPDATE_SYSTEM_SELECTION_CHANNELS_DONE = 59;
    private static final int EVENT_SELECTED_NB_IOT_SATELLITE_SUBSCRIPTION_CHANGED = 60;

    @NonNull private static SatelliteController sInstance;
    @NonNull private final Context mContext;
@@ -427,6 +429,13 @@ public class SatelliteController extends Handler {
     */
    private final ConcurrentHashMap<IBinder, ISatelliteModemStateCallback>
            mTerrestrialNetworkAvailableChangedListeners = new ConcurrentHashMap<>();
    /**
     * Map key: binder of the callback, value: callback to receive selected NB IOT satellite
     * subscription changed
     */
    private final ConcurrentHashMap<IBinder, ISelectedNbIotSatelliteSubscriptionCallback>
            mSelectedNbIotSatelliteSubscriptionChangedListeners = new ConcurrentHashMap<>();

    private final Object mIsSatelliteSupportedLock = new Object();
    @GuardedBy("mIsSatelliteSupportedLock")
    private Boolean mIsSatelliteSupported = null;
@@ -2083,6 +2092,16 @@ public class SatelliteController extends Handler {
                break;
            }

            case EVENT_SELECTED_NB_IOT_SATELLITE_SUBSCRIPTION_CHANGED: {
                ar = (AsyncResult) msg.obj;
                if (ar.result == null) {
                    loge("EVENT_SELECTED_NB_IOT_SATELLITE_SUBSCRIPTION_CHANGED: result is null");
                } else {
                    handleEventSelectedNbIotSatelliteSubscriptionChanged((int) ar.result);
                }
                break;
            }

            default:
                Log.w(TAG, "SatelliteControllerHandler: unexpected message code: " +
                        msg.what);
@@ -3297,6 +3316,59 @@ public class SatelliteController extends Handler {
        mSatelliteSupportedStateChangedListeners.remove(callback.asBinder());
    }

    /**
     * Registers for selected satellite subscription changed event.
     *
     * @param callback The callback to handle the selected satellite subscription changed event.
     *
     * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
     */
    @SatelliteManager.SatelliteResult
    public int registerForSelectedNbIotSatelliteSubscriptionChanged(
            @NonNull ISelectedNbIotSatelliteSubscriptionCallback callback) {
        if (DBG) plogd("registerForSelectedNbIotSatelliteSubscriptionChanged()");

        if (!mFeatureFlags.carrierRoamingNbIotNtn()) {
            plogd("carrierRoamingNbIotNtn flag is disabled");
            return SatelliteManager.SATELLITE_RESULT_REQUEST_NOT_SUPPORTED;
        }

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

        mSelectedNbIotSatelliteSubscriptionChangedListeners.put(callback.asBinder(), callback);
        try {
            callback.onSelectedNbIotSatelliteSubscriptionChanged(getSelectedSatelliteSubId());
        } catch (RemoteException ex) {
            ploge("registerForSelectedNbIotSatelliteSubscriptionChanged: RemoteException ex="
                    + ex);
        }
        return SATELLITE_RESULT_SUCCESS;
    }

    /**
     * Unregisters for the selected satellite subscription changed event.
     * If callback was not registered before, the request will be ignored.
     *
     * @param callback The callback that was passed to {@link
     *     #registerForSelectedNbIotSatelliteSubscriptionChanged(
     *     ISelectedNbIotSatelliteSubscriptionCallback)}.
     */
    public void unregisterForSelectedNbIotSatelliteSubscriptionChanged(
            @NonNull ISelectedNbIotSatelliteSubscriptionCallback callback) {
        if (DBG) plogd("unregisterForSelectedNbIotSatelliteSubscriptionChanged()");

        if (!mFeatureFlags.carrierRoamingNbIotNtn()) {
            plogd("carrierRoamingNbIotNtn flag is disabled");
            return;
        }

        int error = evaluateOemSatelliteRequestAllowed(true);
        if (error == SATELLITE_RESULT_SUCCESS) {
            mSelectedNbIotSatelliteSubscriptionChangedListeners.remove(callback.asBinder());
        }
    }

    /**
     * This API can be used by only CTS to update satellite vendor service package name.
     *
@@ -4829,6 +4901,29 @@ public class SatelliteController extends Handler {
        }
    }

    private void handleEventSelectedNbIotSatelliteSubscriptionChanged(int selectedSubId) {
        if (!mFeatureFlags.carrierRoamingNbIotNtn()) {
            plogd("handleEventSelectedNbIotSatelliteSubscriptionChanged: "
                    + "carrierRoamingNbIotNtn flag is disabled");
            return;
        }

        plogd("handleEventSelectedNbIotSatelliteSubscriptionChanged: " + selectedSubId);

        List<ISelectedNbIotSatelliteSubscriptionCallback> deadCallersList = new ArrayList<>();
        mSelectedNbIotSatelliteSubscriptionChangedListeners.values().forEach(listener -> {
            try {
                listener.onSelectedNbIotSatelliteSubscriptionChanged(selectedSubId);
            } catch (RemoteException e) {
                logd("handleEventSelectedNbIotSatelliteSubscriptionChanged RemoteException: " + e);
                deadCallersList.add(listener);
            }
        });
        deadCallersList.forEach(listener -> {
            mSelectedNbIotSatelliteSubscriptionChangedListeners.remove(listener.asBinder());
        });
    }

    private void notifySatelliteSupportedStateChanged(boolean supported) {
        List<ISatelliteSupportedStateCallback> deadCallersList = new ArrayList<>();
        mSatelliteSupportedStateChangedListeners.values().forEach(listener -> {
@@ -7178,6 +7273,7 @@ public class SatelliteController extends Handler {
        }
        setSatellitePhone(selectedSubId);
        plogd("selectBindingSatelliteSubscription: SelectedSatelliteSubId=" + selectedSubId);
        handleEventSelectedNbIotSatelliteSubscriptionChanged(selectedSubId);
    }

    private int getSubIdFromSubscriberId(String subscriberId) {
+99 −0
Original line number Diff line number Diff line
@@ -157,6 +157,7 @@ import android.telephony.satellite.ISatelliteModemStateCallback;
import android.telephony.satellite.ISatelliteProvisionStateCallback;
import android.telephony.satellite.ISatelliteSupportedStateCallback;
import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
import android.telephony.satellite.ISelectedNbIotSatelliteSubscriptionCallback;
import android.telephony.satellite.NtnSignalStrength;
import android.telephony.satellite.SatelliteCapabilities;
import android.telephony.satellite.SatelliteDatagram;
@@ -3985,6 +3986,96 @@ public class SatelliteControllerTest extends TelephonyTest {
        assertEquals(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, errorCode);
    }

    @Test
    public void testRegisterForSelectedNbIotSatelliteSubscriptionChanged_WithFeatureFlagEnabled() {
        when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(true);

        Semaphore semaphore = new Semaphore(0);
        final int[] selectedSubIds = new int[1];
        ISelectedNbIotSatelliteSubscriptionCallback callback =
                new ISelectedNbIotSatelliteSubscriptionCallback.Stub() {
                    @Override
                    public void onSelectedNbIotSatelliteSubscriptionChanged(int selectedSubId) {
                        logd("onSelectedNbIotSatelliteSubscriptionChanged: selectedSubId="
                                + selectedSubId);
                        try {
                            selectedSubIds[0] = selectedSubId;
                            semaphore.release();
                        } catch (Exception ex) {
                            loge("onSelectedNbIotSatelliteSubscriptionChanged: Got exception in "
                                    + "releasing semaphore, ex=" + ex);
                        }
                    }
                };

        int errorCode = mSatelliteControllerUT.registerForSelectedNbIotSatelliteSubscriptionChanged(
                callback);
        assertEquals(SATELLITE_RESULT_INVALID_TELEPHONY_STATE, errorCode);

        setUpResponseForRequestIsSatelliteSupported(false, SATELLITE_RESULT_SUCCESS);
        verifySatelliteSupported(false, SATELLITE_RESULT_SUCCESS);
        errorCode = mSatelliteControllerUT.registerForSelectedNbIotSatelliteSubscriptionChanged(
                callback);
        assertEquals(SATELLITE_RESULT_NOT_SUPPORTED, errorCode);

        // Register the callback and verify that the event is reported.
        resetSatelliteControllerUT();
        setUpResponseForRequestIsSatelliteProvisioned(true,SATELLITE_RESULT_SUCCESS);
        setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS);
        verifySatelliteSupported(true, SATELLITE_RESULT_SUCCESS);
        errorCode = mSatelliteControllerUT.registerForSelectedNbIotSatelliteSubscriptionChanged(
                callback);
        assertEquals(SATELLITE_RESULT_SUCCESS, errorCode);
        int expectedSubId = 1;
        sendSelectedNbIotSatelliteSubscriptionChangedEvent(expectedSubId, null);
        processAllMessages();
        assertTrue(waitForForEvents(
                semaphore, 1, "testRegisterForSelectedNbIotSatelliteSubscriptionChanged"));
        assertEquals(expectedSubId, selectedSubIds[0]);

        // Unregister the callback and verify that the event is not reported.
        mSatelliteControllerUT.unregisterForSelectedNbIotSatelliteSubscriptionChanged(callback);
        sendSelectedNbIotSatelliteSubscriptionChangedEvent(2, null);
        processAllMessages();
        assertTrue(waitForForEvents(
                semaphore, 0, "testRegisterForSelectedNbIotSatelliteSubscriptionChanged"));
    }

    @Test
    public void testRegisterForSelectedNbIotSatelliteSubscriptionChanged_WithFeatureFlagDisabled() {
        when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(false);

        Semaphore semaphore = new Semaphore(0);
        final int[] selectedSubIds = new int[1];
        ISelectedNbIotSatelliteSubscriptionCallback callback =
                new ISelectedNbIotSatelliteSubscriptionCallback.Stub() {
                    @Override
                    public void onSelectedNbIotSatelliteSubscriptionChanged(int selectedSubId) {
                        logd("onSelectedNbIotSatelliteSubscriptionChanged: selectedSubId="
                                + selectedSubId);
                        try {
                            selectedSubIds[0] = selectedSubId;
                            semaphore.release();
                        } catch (Exception ex) {
                            loge("onSelectedNbIotSatelliteSubscriptionChanged: Got exception in "
                                    + "releasing semaphore, ex=" + ex);
                        }
                    }
                };

        int errorCode = mSatelliteControllerUT.registerForSelectedNbIotSatelliteSubscriptionChanged(
                callback);
        assertEquals(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, errorCode);

        // Verify that the event is not reported.
        sendSelectedNbIotSatelliteSubscriptionChangedEvent(1, null);
        processAllMessages();
        assertTrue(waitForForEvents(
                semaphore, 0, "testRegisterForSelectedNbIotSatelliteSubscriptionChanged"));


    }

    @Test
    public void testIsSatelliteEmergencyMessagingSupportedViaCarrier() {
        // Carrier-enabled flag is off
@@ -5591,6 +5682,14 @@ public class SatelliteControllerTest extends TelephonyTest {
        msg.sendToTarget();
    }

    private void sendSelectedNbIotSatelliteSubscriptionChangedEvent(int selectedSubId,
            Throwable exception) {
        Message msg = mSatelliteControllerUT.obtainMessage(
                60 /* EVENT_SELECTED_NB_IOT_SATELLITE_SUBSCRIPTION_CHANGED */);
        msg.obj = new AsyncResult(null, selectedSubId, exception);
        msg.sendToTarget();
    }

    private void setRadioPower(boolean on) {
        mSimulatedCommands.setRadioPower(on, false, false, null);
    }