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

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

Cleanup Satellite Messaging APIs.

Bug: 260896985
Test: atest SatelliteManagerTest
Change-Id: Id55b6b1d6b2394d722752c6d21a89b2720acba8f
parent 9871076e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -29,6 +29,6 @@ oneway interface ISatelliteStateListener {
    void onMessageTransferStateUpdate(in int state, in int sendPendingCount,
            in int receivePendingCount, in int errorCode);
    void onSatelliteModemStateChange(in int state);
    void onPendingMessageCount(in int count);
    void onPendingDatagramCount(in int count);
    void onSatelliteDatagrams(in SatelliteDatagram[] datagrams);
}
+7 −7
Original line number Diff line number Diff line
@@ -98,15 +98,15 @@ public class SatelliteCallback {
    public interface SatelliteStateListener {
        /**
         * Called when satellite state changes.
         * @param state The new satellite state.
         * @param state The new satellite modem state.
         */
        void onSatelliteModemStateChange(@SatelliteManager.SatelliteModemState int state);

        /**
         * Called when there are pending messages to be received from satellite.
         * @param count Pending message count.
         * Called when there are pending datagrams to be received from satellite.
         * @param count pending datagram count.
         */
        void onPendingMessageCount(int count);
        void onPendingDatagramCount(int count);
    }

    /**
@@ -115,7 +115,7 @@ public class SatelliteCallback {
    public interface SatelliteDatagramListener {
        /**
         * Called when there are incoming datagrams to be received.
         * @param datagrams Datagrams to be received over satellite.
         * @param datagrams array of datagrams to be received over satellite.
         */
        void onSatelliteDatagrams(SatelliteDatagram[] datagrams);
    }
@@ -171,13 +171,13 @@ public class SatelliteCallback {
        }

        @Override
        public void onPendingMessageCount(int count) {
        public void onPendingDatagramCount(int count) {
            SatelliteStateListener listener =
                    (SatelliteStateListener) mSatelliteCallbackWeakRef.get();
            if (listener == null) return;

            Binder.withCleanCallingIdentity(() -> mExecutor.execute(
                    () -> listener.onPendingMessageCount(count)));
                    () -> listener.onPendingDatagramCount(count)));
        }

        @Override
+40 −15
Original line number Diff line number Diff line
@@ -540,10 +540,11 @@ public class SatelliteManager {
    @Retention(RetentionPolicy.SOURCE)
    public @interface SatelliteModemState {}

    /** SOS SMS */
    /** Datagram type indicating that the datagram to be sent or received is of type SOS SMS. */
    public static final int DATAGRAM_TYPE_SOS_SMS = 0;

    /** Location sharing message */
    /** Datagram type indicating that the datagram to be sent or received is of type
     * location sharing. */
    public static final int DATAGRAM_TYPE_LOCATION_SHARING = 3;

    @IntDef(
@@ -921,7 +922,7 @@ public class SatelliteManager {
     * Register for listening to satellite modem state changes.
     *
     * @param executor The executor on which the callback will be called.
     * @param callback The callback to handle the satellite state change event.
     * @param callback The callback to handle the satellite modem state change event.
     *                 This SatelliteCallback should implement the interface
     *                 {@link SatelliteCallback.SatelliteStateListener}.
     *
@@ -991,9 +992,11 @@ public class SatelliteManager {
    /**
     * Register to receive incoming datagrams over satellite.
     *
     * @param datagramType Type of datagram.
     * @param datagramType datagram type indicating whether the datagram is of type
     *                     SOS_SMS or LOCATION_SHARING.
     * @param executor The executor on which the callback will be called.
     * @param callback The callback to handle incoming datagrams over satellite.
     *                 This callback with be invoked when a new datagram is received from satellite.
     *                 This SatelliteCallback should implement the interface
     *                 {@link SatelliteCallback.SatelliteDatagramListener}.
     *
@@ -1061,16 +1064,33 @@ public class SatelliteManager {
    /**
     * Poll pending satellite datagrams over satellite.
     *
     * @return The result of the operation.
     * This method requests modem to check if there are any pending datagrams to be received over
     * satellite. If there are any incoming datagrams, they will be received via
     * {@link SatelliteCallback.SatelliteDatagramListener#onSatelliteDatagrams(SatelliteDatagram[])}
     *
     * @param executor The executor on which the result listener will be called.
     * @param resultListener Listener for the {@link SatelliteError} result of the operation.
     *
     * @throws SecurityException if the caller doesn't have required permission.
     * @throws IllegalStateException if the Telephony process is not currently available.
     */
    @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
    @SatelliteError public int pollPendingSatelliteDatagrams() {
    public void pollPendingSatelliteDatagrams(@NonNull @CallbackExecutor Executor executor,
            @SatelliteError @NonNull Consumer<Integer> resultListener) {
        Objects.requireNonNull(executor);
        Objects.requireNonNull(resultListener);

        try {
            ITelephony telephony = getITelephony();
            if (telephony != null) {
                return telephony.pollPendingSatelliteDatagrams(mSubId);
                IIntegerConsumer internalCallback = new IIntegerConsumer.Stub() {
                    @Override
                    public void accept(int result) {
                        executor.execute(() -> Binder.withCleanCallingIdentity(
                                () -> resultListener.accept(result)));
                    }
                };
                telephony.pollPendingSatelliteDatagrams(mSubId, internalCallback);
            } else {
                throw new IllegalStateException("telephony service is null.");
            }
@@ -1078,16 +1098,21 @@ public class SatelliteManager {
            loge("pollPendingSatelliteDatagrams() RemoteException:" + ex);
            ex.rethrowFromSystemServer();
        }
        return SATELLITE_REQUEST_FAILED;
    }

    /**
     * Send datagram over satellite.
     *
     * @param datagramType Type of datagram.
     * @param datagram Datagram to send over satellite.
     * @param executor The executor on which the error code listener will be called.
     * @param errorCodeListener Listener for the {@link SatelliteError} result of the operation.
     * Gateway encodes SOS SMS or location sharing message into a datagram and passes it as input to
     * this method. Datagram received here will be passed down to modem without any encoding or
     * encryption.
     *
     * @param datagramType datagram type indicating whether the datagram is of type
     *                     SOS_SMS or LOCATION_SHARING.
     * @param datagram encoded gateway datagram which is encrypted by the caller.
     *                 Datagram will be passed down to modem without any encoding or encryption.
     * @param executor The executor on which the result listener will be called.
     * @param resultListener Listener for the {@link SatelliteError} result of the operation.
     *
     * @throws SecurityException if the caller doesn't have required permission.
     * @throws IllegalStateException if the Telephony process is not currently available.
@@ -1095,10 +1120,10 @@ public class SatelliteManager {
    @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
    public void sendSatelliteDatagram(@DatagramType int datagramType,
            @NonNull SatelliteDatagram datagram, @NonNull @CallbackExecutor Executor executor,
            @SatelliteError @NonNull Consumer<Integer> errorCodeListener) {
            @SatelliteError @NonNull Consumer<Integer> resultListener) {
        Objects.requireNonNull(datagram);
        Objects.requireNonNull(executor);
        Objects.requireNonNull(errorCodeListener);
        Objects.requireNonNull(resultListener);

        try {
            ITelephony telephony = getITelephony();
@@ -1107,7 +1132,7 @@ public class SatelliteManager {
                    @Override
                    public void accept(int result) {
                        executor.execute(() -> Binder.withCleanCallingIdentity(
                                () -> errorCodeListener.accept(result)));
                                () -> resultListener.accept(result)));
                    }
                };
                telephony.sendSatelliteDatagram(mSubId, datagramType, datagram, internalCallback);
+4 −5
Original line number Diff line number Diff line
@@ -2898,13 +2898,12 @@ interface ITelephony {
   /**
    * Poll pending satellite datagrams over satellite.
    *
    * @param subId The subId of the subscription to poll pending satellite datagrams for.
    *
    * @return The {@link SatelliteError} result of the operation.
    * @param subId The subId of the subscription used for receiving datagrams.
    * @param callback The callback to get the error code of the request.
    */
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission("
                + "android.Manifest.permission.SATELLITE_COMMUNICATION)")
    int pollPendingSatelliteDatagrams(int subId);
    void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback);

   /**
    * Send datagram over satellite.