Merge "Cleanup Satellite Messaging APIs."

This commit is contained in:
Aishwarya Mallampati
2023-02-15 01:06:13 +00:00
committed by Android (Google) Code Review
4 changed files with 73 additions and 49 deletions

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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,44 +1064,21 @@ public class SatelliteManager {
/**
* Poll pending satellite datagrams over satellite.
*
* @return The 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() {
try {
ITelephony telephony = getITelephony();
if (telephony != null) {
return telephony.pollPendingSatelliteDatagrams(mSubId);
} else {
throw new IllegalStateException("telephony service is null.");
}
} catch (RemoteException ex) {
loge("pollPendingSatelliteDatagrams() RemoteException:" + ex);
ex.rethrowFromSystemServer();
}
return SATELLITE_REQUEST_FAILED;
}
/**
* Send datagram over satellite.
* 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 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.
* @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)
public void sendSatelliteDatagram(@DatagramType int datagramType,
@NonNull SatelliteDatagram datagram, @NonNull @CallbackExecutor Executor executor,
@SatelliteError @NonNull Consumer<Integer> errorCodeListener) {
Objects.requireNonNull(datagram);
public void pollPendingSatelliteDatagrams(@NonNull @CallbackExecutor Executor executor,
@SatelliteError @NonNull Consumer<Integer> resultListener) {
Objects.requireNonNull(executor);
Objects.requireNonNull(errorCodeListener);
Objects.requireNonNull(resultListener);
try {
ITelephony telephony = getITelephony();
@@ -1107,7 +1087,52 @@ public class SatelliteManager {
@Override
public void accept(int result) {
executor.execute(() -> Binder.withCleanCallingIdentity(
() -> errorCodeListener.accept(result)));
() -> resultListener.accept(result)));
}
};
telephony.pollPendingSatelliteDatagrams(mSubId, internalCallback);
} else {
throw new IllegalStateException("telephony service is null.");
}
} catch (RemoteException ex) {
loge("pollPendingSatelliteDatagrams() RemoteException:" + ex);
ex.rethrowFromSystemServer();
}
}
/**
* 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.
*
* @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.
*/
@RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
public void sendSatelliteDatagram(@DatagramType int datagramType,
@NonNull SatelliteDatagram datagram, @NonNull @CallbackExecutor Executor executor,
@SatelliteError @NonNull Consumer<Integer> resultListener) {
Objects.requireNonNull(datagram);
Objects.requireNonNull(executor);
Objects.requireNonNull(resultListener);
try {
ITelephony telephony = getITelephony();
if (telephony != null) {
IIntegerConsumer internalCallback = new IIntegerConsumer.Stub() {
@Override
public void accept(int result) {
executor.execute(() -> Binder.withCleanCallingIdentity(
() -> resultListener.accept(result)));
}
};
telephony.sendSatelliteDatagram(mSubId, datagramType, datagram, internalCallback);

View File

@@ -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);
+ "android.Manifest.permission.SATELLITE_COMMUNICATION)")
void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback);
/**
* Send datagram over satellite.