diff --git a/telephony/java/android/telephony/satellite/ISatelliteDatagramCallback.aidl b/telephony/java/android/telephony/satellite/ISatelliteDatagramCallback.aidl index d6f8012201ab0..abf2b55de76a6 100644 --- a/telephony/java/android/telephony/satellite/ISatelliteDatagramCallback.aidl +++ b/telephony/java/android/telephony/satellite/ISatelliteDatagramCallback.aidl @@ -16,6 +16,7 @@ package android.telephony.satellite; +import android.telephony.satellite.ISatelliteDatagramReceiverAck; import android.telephony.satellite.SatelliteDatagram; /** @@ -24,8 +25,15 @@ import android.telephony.satellite.SatelliteDatagram; */ oneway interface ISatelliteDatagramCallback { /** - * Called when there are incoming datagrams to be received. - * @param datagrams Array of datagrams to be received over satellite. + * Called when datagrams are received from satellite. + * + * @param datagramId An id that uniquely identifies incoming datagram. + * @param datagram datagram received from satellite. + * @param pendingCount Number of datagrams yet to be received from satellite. + * @param callback This callback will be used by datagram receiver app to send ack back to + * Telephony. If the callback is not received within five minutes, + * Telephony will resend the datagrams. */ - void onSatelliteDatagrams(in SatelliteDatagram[] datagrams); + void onSatelliteDatagramReceived(long datagramId, in SatelliteDatagram datagram, + int pendingCount, ISatelliteDatagramReceiverAck callback); } diff --git a/telephony/java/android/telephony/satellite/ISatelliteDatagramReceiverAck.aidl b/telephony/java/android/telephony/satellite/ISatelliteDatagramReceiverAck.aidl new file mode 100644 index 0000000000000..eeb0ac56d6bfd --- /dev/null +++ b/telephony/java/android/telephony/satellite/ISatelliteDatagramReceiverAck.aidl @@ -0,0 +1,41 @@ +/* + * Copyright 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.telephony.satellite; + +import android.telephony.satellite.PointingInfo; +import android.telephony.satellite.SatelliteDatagram; + +/** + * Interface for satellite datagram receiver acknowledgement. + * @hide + */ +oneway interface ISatelliteDatagramReceiverAck { + /** + * This callback will be used by datagram receiver app to send ack back to + * Telephony. If the callback is not received within five minutes, + * then Telephony will resend the datagram again. + * + * @param datagramId An id that uniquely identifies datagram + * received by satellite datagram receiver app. + * This should match with datagramId passed in + * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived( + * long, SatelliteDatagram, int, ISatelliteDatagramReceiverAck)}. + * Upon receiving the ack, Telephony will remove the datagram from + * the persistent memory. + */ + void acknowledgeSatelliteDatagramReceived(in long datagramId); +} diff --git a/telephony/java/android/telephony/satellite/SatelliteDatagramCallback.java b/telephony/java/android/telephony/satellite/SatelliteDatagramCallback.java index 484b783e35e86..2c3884c81bfc0 100644 --- a/telephony/java/android/telephony/satellite/SatelliteDatagramCallback.java +++ b/telephony/java/android/telephony/satellite/SatelliteDatagramCallback.java @@ -38,10 +38,12 @@ public class SatelliteDatagramCallback { } @Override - public void onSatelliteDatagrams(SatelliteDatagram[] datagrams) { + public void onSatelliteDatagramReceived(long datagramId, SatelliteDatagram datagram, + int pendingCount, ISatelliteDatagramReceiverAck callback) { final long callingIdentity = Binder.clearCallingIdentity(); try { - mExecutor.execute(() -> mLocalCallback.onSatelliteDatagrams(datagrams)); + mExecutor.execute(() -> mLocalCallback.onSatelliteDatagramReceived(datagramId, + datagram, pendingCount, callback)); } finally { restoreCallingIdentity(callingIdentity); } @@ -54,9 +56,14 @@ public class SatelliteDatagramCallback { /** * Called when there are incoming datagrams to be received. - * @param datagrams Datagrams to be received over satellite. + * @param datagramId An id that uniquely identifies incoming datagram. + * @param datagram datagram to be received over satellite. + * @param pendingCount Number of datagrams yet to be received by the app. + * @param callback This callback will be used by datagram receiver app to send ack back to + * Telephony. */ - public void onSatelliteDatagrams(SatelliteDatagram[] datagrams) { + public void onSatelliteDatagramReceived(long datagramId, SatelliteDatagram datagram, + int pendingCount, ISatelliteDatagramReceiverAck callback) { // Base Implementation } diff --git a/telephony/java/android/telephony/satellite/SatelliteManager.java b/telephony/java/android/telephony/satellite/SatelliteManager.java index 8fbf640705345..dbc0ed9c5a246 100644 --- a/telephony/java/android/telephony/satellite/SatelliteManager.java +++ b/telephony/java/android/telephony/satellite/SatelliteManager.java @@ -130,7 +130,7 @@ public class SatelliteManager { /** * Bundle key to get the response from - * {@link #requestMaxCharactersPerSatelliteTextMessage(Executor, OutcomeReceiver)}. + * {@link #requestMaxSizePerSendingDatagram(Executor, OutcomeReceiver)} . * @hide */ public static final String KEY_MAX_CHARACTERS_PER_SATELLITE_TEXT = @@ -158,6 +158,13 @@ public class SatelliteManager { */ public static final String KEY_SATELLITE_NEXT_VISIBILITY = "satellite_next_visibility"; + /** + * Bundle key to get the respoonse from + * {@link #sendSatelliteDatagram(long, int, SatelliteDatagram, Executor, OutcomeReceiver)}. + * @hide + */ + public static final String KEY_SEND_SATELLITE_DATAGRAM = "send_satellite_datagram"; + /** * The request was successfully processed. */ @@ -541,8 +548,8 @@ public class SatelliteManager { @Retention(RetentionPolicy.SOURCE) public @interface SatelliteModemState {} - /** 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; + /** Datagram type indicating that the datagram to be sent or received is of type SOS message. */ + public static final int DATAGRAM_TYPE_SOS_MESSAGE = 0; /** Datagram type indicating that the datagram to be sent or received is of type * location sharing. */ @@ -551,7 +558,7 @@ public class SatelliteManager { @IntDef( prefix = "DATAGRAM_TYPE_", value = { - DATAGRAM_TYPE_SOS_SMS, + DATAGRAM_TYPE_SOS_MESSAGE, DATAGRAM_TYPE_LOCATION_SHARING, }) @Retention(RetentionPolicy.SOURCE) @@ -651,19 +658,20 @@ public class SatelliteManager { } /** - * Request to get the maximum number of characters per text message on satellite. + * Request to get the maximum number of bytes per datagram that can be sent to satellite. * * @param executor The executor on which the callback will be called. * @param callback The callback object to which the result will be delivered. * If the request is successful, {@link OutcomeReceiver#onResult(Object)} - * will return the maximum number of characters per text message on satellite. + * will return the maximum number of bytes per datagram that can be sent to + * satellite. * If the request is not successful, {@link OutcomeReceiver#onError(Throwable)} * * @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) - public void requestMaxCharactersPerSatelliteTextMessage( + public void requestMaxSizePerSendingDatagram( @NonNull @CallbackExecutor Executor executor, @NonNull OutcomeReceiver callback) { Objects.requireNonNull(executor); @@ -693,7 +701,7 @@ public class SatelliteManager { } } }; - telephony.requestMaxCharactersPerSatelliteTextMessage(mSubId, receiver); + telephony.requestMaxSizePerSendingDatagram(mSubId, receiver); } else { throw new IllegalStateException("telephony service is null."); } @@ -1039,7 +1047,8 @@ public class SatelliteManager { * * 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 SatelliteDatagramCallback#onSatelliteDatagrams(SatelliteDatagram[])})}. + * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, + * ISatelliteDatagramReceiverAck)} * * @param executor The executor on which the result listener will be called. * @param resultListener Listener for the {@link SatelliteError} result of the operation. @@ -1076,39 +1085,60 @@ public class SatelliteManager { /** * Send datagram over satellite. * - * 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. + * Gateway encodes SOS message 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 datagramId An id that uniquely identifies datagram requested to be sent. * @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. + * @param callback The callback object to which the result will be returned. + * If datagram is sent successfully, then + * {@link OutcomeReceiver#onResult(Object)} will return datagramId. + * If the request is not successful, {@link OutcomeReceiver#onError(Throwable)} + * will return a {@link SatelliteException} with the {@link SatelliteError}. * * @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) - public void sendSatelliteDatagram(@DatagramType int datagramType, + public void sendSatelliteDatagram(long datagramId, @DatagramType int datagramType, @NonNull SatelliteDatagram datagram, @NonNull @CallbackExecutor Executor executor, - @SatelliteError @NonNull Consumer resultListener) { + @NonNull OutcomeReceiver callback) { Objects.requireNonNull(datagram); Objects.requireNonNull(executor); - Objects.requireNonNull(resultListener); + Objects.requireNonNull(callback); try { ITelephony telephony = getITelephony(); if (telephony != null) { - IIntegerConsumer internalCallback = new IIntegerConsumer.Stub() { + ResultReceiver receiver = new ResultReceiver(null) { @Override - public void accept(int result) { - executor.execute(() -> Binder.withCleanCallingIdentity( - () -> resultListener.accept(result))); + protected void onReceiveResult(int resultCode, Bundle resultData) { + if (resultCode == SATELLITE_ERROR_NONE) { + if (resultData.containsKey(KEY_SEND_SATELLITE_DATAGRAM)) { + long resultDatagramId = resultData + .getLong(KEY_SEND_SATELLITE_DATAGRAM); + executor.execute(() -> Binder.withCleanCallingIdentity(() -> + callback.onResult(resultDatagramId))); + } else { + loge("KEY_SEND_SATELLITE_DATAGRAM does not exist."); + executor.execute(() -> Binder.withCleanCallingIdentity(() -> + callback.onError( + new SatelliteException(SATELLITE_REQUEST_FAILED)))); + } + + } else { + executor.execute(() -> Binder.withCleanCallingIdentity(() -> + callback.onError(new SatelliteException(resultCode)))); + } } }; - telephony.sendSatelliteDatagram(mSubId, datagramType, datagram, internalCallback); + telephony.sendSatelliteDatagram(mSubId, datagramId, datagramType, datagram, + receiver); } else { throw new IllegalStateException("telephony service is null."); } diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl index 62e087f3ca344..5bf55ef72bd05 100644 --- a/telephony/java/com/android/internal/telephony/ITelephony.aidl +++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl @@ -2772,15 +2772,15 @@ interface ITelephony { in ISatellitePositionUpdateCallback callback); /** - * Request to get the maximum number of characters per text message on satellite. + * Request to get the maximum number of bytes per datagram that can be sent to satellite. * * @param subId The subId of the subscription to get the maximum number of characters for. * @param receiver Result receiver to get the error code of the request and the requested - * maximum number of characters per text message on satellite. + * maximum number of bytes per datagram that can be sent to satellite. */ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(" + "android.Manifest.permission.SATELLITE_COMMUNICATION)") - void requestMaxCharactersPerSatelliteTextMessage(int subId, in ResultReceiver receiver); + void requestMaxSizePerSendingDatagram(int subId, in ResultReceiver receiver); /** * Register the subscription with a satellite provider. @@ -2912,14 +2912,16 @@ interface ITelephony { * Send datagram over satellite. * * @param subId The subId of the subscription to send satellite datagrams for. + * @param datagramId An id that uniquely identifies datagram requested to be sent. * @param datagramType Type of datagram. * @param datagram Datagram to send over satellite. - * @param callback The callback to get the error code of the request. + * @param receiver Result receiver to get the datagramId if datagram is sent successfully else + * error code of the request. */ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(" + "android.Manifest.permission.SATELLITE_COMMUNICATION)") - void sendSatelliteDatagram(int subId, int datagramType, in SatelliteDatagram datagram, - IIntegerConsumer callback); + void sendSatelliteDatagram(int subId, long datagramId, int datagramType, + in SatelliteDatagram datagram, in ResultReceiver receiver); /** * Request to get whether satellite communication is allowed for the current location.