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

Commit e32fa017 authored by Sarah Chin's avatar Sarah Chin
Browse files

Update satellite implementation based on updated APIs

Test: atest SatelliteManagerTest
Bug: 261053569
Change-Id: Ia83a9304ad40dd124dafad3fbf34c9ea2b308c51
Merged-In: Ia83a9304ad40dd124dafad3fbf34c9ea2b308c51
parent ea427db1
Loading
Loading
Loading
Loading
+4 −8
Original line number Diff line number Diff line
@@ -86,16 +86,13 @@ public class DatagramController {
     * Register to receive incoming datagrams over satellite.
     *
     * @param subId The subId of the subscription to register for incoming satellite datagrams.
     * @param datagramType datagram type indicating whether the datagram is of type
     *                     SOS_SMS or LOCATION_SHARING.
     * @param callback The callback to handle incoming datagrams over satellite.
     *
     * @return The {@link SatelliteManager.SatelliteError} result of the operation.
     */
    @SatelliteManager.SatelliteError public int registerForSatelliteDatagram(int subId,
            @SatelliteManager.DatagramType int datagramType,
            @NonNull ISatelliteDatagramCallback callback) {
        return mDatagramReceiver.registerForSatelliteDatagram(subId, datagramType, callback);
        return mDatagramReceiver.registerForSatelliteDatagram(subId, callback);
    }

    /**
@@ -104,7 +101,7 @@ public class DatagramController {
     *
     * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
     * @param callback The callback that was passed to
     *                 {@link #registerForSatelliteDatagram(int, int, ISatelliteDatagramCallback)}.
     *                 {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}.
     */
    public void unregisterForSatelliteDatagram(int subId,
            @NonNull ISatelliteDatagramCallback callback) {
@@ -138,15 +135,14 @@ public class DatagramController {
     *                 Datagram will be passed down to modem without any encoding or encryption.
     * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
     *                                 full screen mode.
     * @param isSatelliteDemoModeEnabled True if satellite demo mode is enabled
     * @param callback The callback to get {@link SatelliteManager.SatelliteError} of the request.
     */
    public void sendSatelliteDatagram(@SatelliteManager.DatagramType int datagramType,
            @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
            boolean isSatelliteDemoModeEnabled, @NonNull Consumer<Integer> callback) {
            @NonNull Consumer<Integer> callback) {
        // TODO: set modemTransferState = SATELLITE_DATAGRAM_TRANSFER_STATE_SENDING
        mDatagramDispatcher.sendSatelliteDatagram(datagramType, datagram,
                needFullScreenPointingUI, isSatelliteDemoModeEnabled, callback);
                needFullScreenPointingUI, callback);
    }

    private static void logd(@NonNull String log) {
+4 −9
Original line number Diff line number Diff line
@@ -117,18 +117,16 @@ public class DatagramDispatcher extends Handler {
        public @SatelliteManager.DatagramType int datagramType;
        public @NonNull SatelliteDatagram datagram;
        public boolean needFullScreenPointingUI;
        public boolean isSatelliteDemoModeEnabled;
        public @NonNull Consumer<Integer> callback;

        SendSatelliteDatagramArgument(long datagramId,
                @SatelliteManager.DatagramType int datagramType,
                @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
                boolean isSatelliteDemoModeEnabled, @NonNull Consumer<Integer> callback) {
                @NonNull Consumer<Integer> callback) {
            this.datagramId = datagramId;
            this.datagramType = datagramType;
            this.datagram = datagram;
            this.needFullScreenPointingUI = needFullScreenPointingUI;
            this.isSatelliteDemoModeEnabled = isSatelliteDemoModeEnabled;
            this.callback = callback;
        }
    }
@@ -148,8 +146,7 @@ public class DatagramDispatcher extends Handler {
                if (SatelliteModemInterface.getInstance().isSatelliteServiceSupported()) {
                    SatelliteModemInterface.getInstance().sendSatelliteDatagram(argument.datagram,
                            argument.datagramType == SatelliteManager.DATAGRAM_TYPE_SOS_MESSAGE,
                            argument.needFullScreenPointingUI, argument.isSatelliteDemoModeEnabled,
                            onCompleted);
                            argument.needFullScreenPointingUI, onCompleted);
                    break;
                }
                Phone phone = request.phone;
@@ -216,19 +213,17 @@ public class DatagramDispatcher extends Handler {
     *                 Datagram will be passed down to modem without any encoding or encryption.
     * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
     *                                 full screen mode.
     * @param isSatelliteDemoModeEnabled True if satellite demo mode is enabled
     * @param callback The callback to get {@link SatelliteManager.SatelliteError} of the request.
     */
    public void sendSatelliteDatagram(@SatelliteManager.DatagramType int datagramType,
            @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
            boolean isSatelliteDemoModeEnabled, @NonNull Consumer<Integer> callback) {
            @NonNull Consumer<Integer> callback) {
        Phone phone = SatelliteServiceUtils.getPhone();

        long datagramId = mNextDatagramId.getAndUpdate(
                n -> ((n + 1) % DatagramController.MAX_DATAGRAM_ID));
        SendSatelliteDatagramArgument datagramArgs = new SendSatelliteDatagramArgument(datagramId,
                datagramType, datagram, needFullScreenPointingUI, isSatelliteDemoModeEnabled,
                callback);
                datagramType, datagram, needFullScreenPointingUI, callback);

        synchronized (mLock) {
            if (datagramType == SatelliteManager.DATAGRAM_TYPE_SOS_MESSAGE) {
+1 −4
Original line number Diff line number Diff line
@@ -323,14 +323,11 @@ public class DatagramReceiver {
     * Register to receive incoming datagrams over satellite.
     *
     * @param subId The subId of the subscription to register for incoming satellite datagrams.
     * @param datagramType datagram type indicating whether the datagram is of type
     *                     SOS_SMS or LOCATION_SHARING.
     * @param callback The callback to handle incoming datagrams over satellite.
     *
     * @return The {@link SatelliteManager.SatelliteError} result of the operation.
     */
    @SatelliteManager.SatelliteError public int registerForSatelliteDatagram(int subId,
            @SatelliteManager.DatagramType int datagramType,
            @NonNull ISatelliteDatagramCallback callback) {
        if (!SatelliteController.getInstance().isSatelliteSupported()) {
            return SatelliteManager.SATELLITE_NOT_SUPPORTED;
@@ -366,7 +363,7 @@ public class DatagramReceiver {
     *
     * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
     * @param callback The callback that was passed to
     *                 {@link #registerForSatelliteDatagram(int, int, ISatelliteDatagramCallback)}.
     *                 {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}.
     */
    public void unregisterForSatelliteDatagram(int subId,
            @NonNull ISatelliteDatagramCallback callback) {
+54 −49
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ import android.os.Looper;
import android.os.Message;
import android.os.RemoteException;
import android.telephony.Rlog;
import android.telephony.satellite.ISatellitePositionUpdateCallback;
import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
import android.telephony.satellite.PointingInfo;
import android.telephony.satellite.SatelliteManager;
import android.text.TextUtils;
@@ -46,13 +46,13 @@ public class PointingAppController {
    @NonNull
    private static PointingAppController sInstance;
    @NonNull private final Context mContext;
    private boolean mStartedSatellitePositionUpdates;
    private boolean mStartedSatelliteTransmissionUpdates;

    /**
     * Map key: subId, value: SatellitePositionUpdateHandler to notify registrants.
     * Map key: subId, value: SatelliteTransmissionUpdateHandler to notify registrants.
     */
    private final ConcurrentHashMap<Integer, SatellitePositionUpdateHandler>
            mSatellitePositionUpdateHandlers = new ConcurrentHashMap<>();
    private final ConcurrentHashMap<Integer, SatelliteTransmissionUpdateHandler>
            mSatelliteTransmissionUpdateHandlers = new ConcurrentHashMap<>();

    /**
     * @return The singleton instance of PointingAppController.
@@ -83,33 +83,34 @@ public class PointingAppController {
     */
    private PointingAppController(@NonNull Context context) {
        mContext = context;
        mStartedSatellitePositionUpdates = false;
        mStartedSatelliteTransmissionUpdates = false;
    }

    /**
     * set the flag mStartedSatellitePositionUpdates to true or false based on the state of
     * position updates
     * @param startedSatellitePositionUpdates boolean to set the flag
     * Set the flag mStartedSatelliteTransmissionUpdates to true or false based on the state of
     * transmission updates
     * @param startedSatelliteTransmissionUpdates boolean to set the flag
     */
    public void setStartedSatellitePositionUpdates(boolean startedSatellitePositionUpdates) {
        mStartedSatellitePositionUpdates = startedSatellitePositionUpdates;
    public void setStartedSatelliteTransmissionUpdates(
            boolean startedSatelliteTransmissionUpdates) {
        mStartedSatelliteTransmissionUpdates = startedSatelliteTransmissionUpdates;
    }

    private static final class SatellitePositionUpdateHandler extends Handler {
    private static final class SatelliteTransmissionUpdateHandler extends Handler {
        public static final int EVENT_POSITION_INFO_CHANGED = 1;
        public static final int EVENT_DATAGRAM_TRANSFER_STATE_CHANGED = 2;

        private final ConcurrentHashMap<IBinder, ISatellitePositionUpdateCallback> mListeners;
        SatellitePositionUpdateHandler(Looper looper) {
        private final ConcurrentHashMap<IBinder, ISatelliteTransmissionUpdateCallback> mListeners;
        SatelliteTransmissionUpdateHandler(Looper looper) {
            super(looper);
            mListeners = new ConcurrentHashMap<>();
        }

        public void addListener(ISatellitePositionUpdateCallback listener) {
        public void addListener(ISatelliteTransmissionUpdateCallback listener) {
            mListeners.put(listener.asBinder(), listener);
        }

        public void removeListener(ISatellitePositionUpdateCallback listener) {
        public void removeListener(ISatelliteTransmissionUpdateCallback listener) {
            mListeners.remove(listener.asBinder());
        }

@@ -146,30 +147,32 @@ public class PointingAppController {
                    break;
                }
                default:
                    loge("SatellitePositionUpdateHandler unknown event: " + msg.what);
                    loge("SatelliteTransmissionUpdateHandler unknown event: " + msg.what);
            }
        }
    }

    /**
     * register to start receiving Updates on Satellite Position and Datagram transfer state
     * Register to start receiving updates for satellite position and datagram transfer state
     * @param subId The subId of the subscription to register for receiving the updates.
     * @param callback The callback to notify of changes in satellite position.
     * @param phone The Phone Object to unregister for receiving the updates
     * @param callback The callback to notify of satellite transmission updates.
     * @param phone The Phone object to unregister for receiving the updates.
     */
    public void registerForSatellitePositionUpdates(int subId,
            ISatellitePositionUpdateCallback callback, Phone phone) {
        SatellitePositionUpdateHandler handler = mSatellitePositionUpdateHandlers.get(subId);
    public void registerForSatelliteTransmissionUpdates(int subId,
            ISatelliteTransmissionUpdateCallback callback, Phone phone) {
        SatelliteTransmissionUpdateHandler handler =
                mSatelliteTransmissionUpdateHandlers.get(subId);
        if (handler != null) {
            handler.addListener(callback);
            return;
        } else {
            handler = new SatellitePositionUpdateHandler(Looper.getMainLooper());
            handler = new SatelliteTransmissionUpdateHandler(Looper.getMainLooper());
            handler.addListener(callback);
            mSatellitePositionUpdateHandlers.put(subId, handler);
            mSatelliteTransmissionUpdateHandlers.put(subId, handler);
            if (SatelliteModemInterface.getInstance().isSatelliteServiceSupported()) {
                SatelliteModemInterface.getInstance().registerForSatellitePositionInfoChanged(
                        handler, SatellitePositionUpdateHandler.EVENT_POSITION_INFO_CHANGED, null);
                        handler, SatelliteTransmissionUpdateHandler.EVENT_POSITION_INFO_CHANGED,
                        null);
                /**
                 * TODO: Need to remove this call, Datagram transfer state should come from the
                 * DatagramController based upon Transfer state.
@@ -177,27 +180,29 @@ public class PointingAppController {
                 */
                SatelliteModemInterface.getInstance().registerForDatagramTransferStateChanged(
                        handler,
                        SatellitePositionUpdateHandler.EVENT_DATAGRAM_TRANSFER_STATE_CHANGED, null);
                        SatelliteTransmissionUpdateHandler.EVENT_DATAGRAM_TRANSFER_STATE_CHANGED,
                        null);
            } else {
                phone.registerForSatellitePositionInfoChanged(handler,
                        SatellitePositionUpdateHandler.EVENT_POSITION_INFO_CHANGED, null);
                        SatelliteTransmissionUpdateHandler.EVENT_POSITION_INFO_CHANGED, null);
                // TODO: registerForDatagramTransferStateChanged through SatelliteController
            }
        }
    }

    /**
     * Unregister to stop receiving Updates on Satellite Position and Datagram transfer state
     * Unregister to stop receiving updates on satellite position and datagram transfer state
     * If the callback was not registered before, it is ignored
     * @param subId The subId of the subscription to unregister for receiving the updates.
     * @param result The callback to get the error code in case of failure
     * @param callback The callback that was passed to
     * * {@link registerForSatellitePositionUpdateEvents}
     * @param phone The Phone Object to unregister for receiving the updates
     * @param callback The callback that was passed to {@link
     * #registerForSatelliteTransmissionUpdates(int, ISatelliteTransmissionUpdateCallback, Phone)}.
     * @param phone The Phone object to unregister for receiving the updates
     */
    public void unregisterForSatellitePositionUpdates(int subId, Consumer<Integer> result,
            ISatellitePositionUpdateCallback callback, Phone phone) {
        SatellitePositionUpdateHandler handler = mSatellitePositionUpdateHandlers.get(subId);
    public void unregisterForSatelliteTransmissionUpdates(int subId, Consumer<Integer> result,
            ISatelliteTransmissionUpdateCallback callback, Phone phone) {
        SatelliteTransmissionUpdateHandler handler =
                mSatelliteTransmissionUpdateHandlers.get(subId);
        if (handler != null) {
            handler.removeListener(callback);

@@ -213,7 +218,7 @@ public class PointingAppController {
                return;
            }

            mSatellitePositionUpdateHandlers.remove(subId);
            mSatelliteTransmissionUpdateHandlers.remove(subId);
            if (SatelliteModemInterface.getInstance().isSatelliteServiceSupported()) {
                SatelliteModemInterface.getInstance().unregisterForSatellitePositionInfoChanged(
                        handler);
@@ -231,28 +236,28 @@ public class PointingAppController {
    }

    /**
     * Start receiving satellite position updates.
     * Start receiving satellite trasmission updates.
     * This can be called by the pointing UI when the user starts pointing to the satellite.
     * Modem should continue to report the pointing input as the device or satellite moves.
     * The Position updates will be received via
     * {@link android.telephony.satellite.SatellitePositionUpdateCallback#onSatellitePositionChanged(
     * pointingInfo)}
     * The transmission updates will be received via
     * {@link android.telephony.satellite.SatelliteTransmissionUpdateCallback
     * #onSatellitePositionChanged(pointingInfo)}.
     */
    public void startSatellitePositionUpdates(@NonNull Message message, @Nullable Phone phone) {
        if (mStartedSatellitePositionUpdates) {
            logd("startSatellitePositionUpdates: already started");
    public void startSatelliteTransmissionUpdates(@NonNull Message message, @Nullable Phone phone) {
        if (mStartedSatelliteTransmissionUpdates) {
            logd("startSatelliteTransmissionUpdates: already started");
            return;
        }
        if (SatelliteModemInterface.getInstance().isSatelliteServiceSupported()) {
            SatelliteModemInterface.getInstance().startSendingSatellitePointingInfo(message);
            mStartedSatellitePositionUpdates = true;
            mStartedSatelliteTransmissionUpdates = true;
            return;
        }
        if (phone != null) {
            phone.startSatellitePositionUpdates(message);
            mStartedSatellitePositionUpdates = true;
            mStartedSatelliteTransmissionUpdates = true;
        } else {
            loge("startSatellitePositionUpdates: No phone object");
            loge("startSatelliteTransmissionUpdates: No phone object");
            AsyncResult.forMessage(message, null, new SatelliteManager.SatelliteException(
                    SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE));
            message.sendToTarget();
@@ -260,10 +265,10 @@ public class PointingAppController {
    }

    /**
     * Stop receiving satellite position updates.
     * Stop receiving satellite transmission updates.
     * This can be called by the pointing UI when the user stops pointing to the satellite.
     */
    public void stopSatellitePositionUpdates(@NonNull Message message, @Nullable Phone phone) {
    public void stopSatelliteTransmissionUpdates(@NonNull Message message, @Nullable Phone phone) {
        if (SatelliteModemInterface.getInstance().isSatelliteServiceSupported()) {
            SatelliteModemInterface.getInstance().stopSendingSatellitePointingInfo(message);
            return;
@@ -271,7 +276,7 @@ public class PointingAppController {
        if (phone != null) {
            phone.stopSatellitePositionUpdates(message);
        } else {
            loge("startSatellitePositionUpdates: No phone object");
            loge("startSatelliteTransmissionUpdates: No phone object");
            AsyncResult.forMessage(message, null, new SatelliteManager.SatelliteException(
                    SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE));
            message.sendToTarget();
+107 −215

File changed.

Preview size limit exceeded, changes collapsed.

Loading