diff --git a/telephony/java/android/telephony/satellite/SatelliteManager.java b/telephony/java/android/telephony/satellite/SatelliteManager.java index 5dff8b078f363..d0154271fce2a 100644 --- a/telephony/java/android/telephony/satellite/SatelliteManager.java +++ b/telephony/java/android/telephony/satellite/SatelliteManager.java @@ -25,19 +25,23 @@ import android.annotation.RequiresFeature; import android.annotation.RequiresPermission; import android.content.Context; import android.content.pm.PackageManager; +import android.os.Binder; import android.os.RemoteException; import android.telephony.SubscriptionManager; import android.telephony.TelephonyFrameworkInitializer; import android.util.ArrayMap; +import com.android.internal.telephony.IIntegerConsumer; import com.android.internal.telephony.ITelephony; import com.android.telephony.Rlog; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.Map; +import java.util.Objects; import java.util.concurrent.Executor; import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Consumer; /** * Manages satellite operations such as provisioning, pointing, messaging, location sharing, etc. @@ -116,9 +120,9 @@ public class SatelliteManager { */ public static final int SATELLITE_SERVICE_SERVER_ERROR = 2; /** - * Internal error received from the satellite service + * Unexpected telephony internal error. */ - public static final int SATELLITE_SERVICE_INTERNAL_ERROR = 3; + public static final int SATELLITE_SERVICE_TELEPHONY_INTERNAL_ERROR = 3; /** * Modem error received from the satellite service. */ @@ -176,12 +180,17 @@ public class SatelliteManager { */ public static final int SATELLITE_SERVICE_ERROR = 17; + /** + * Satellite service is disabled on the requested subscription. + */ + public static final int SATELLITE_SERVICE_DISABLED = 18; + /** @hide */ @IntDef(prefix = {"SATELLITE_SERVICE_"}, value = { SATELLITE_SERVICE_SUCCESS, SATELLITE_SERVICE_SERVER_NOT_REACHABLE, SATELLITE_SERVICE_SERVER_ERROR, - SATELLITE_SERVICE_INTERNAL_ERROR, + SATELLITE_SERVICE_TELEPHONY_INTERNAL_ERROR, SATELLITE_SERVICE_MODEM_ERROR, SATELLITE_SERVICE_SYSTEM_ERROR, SATELLITE_SERVICE_INVALID_ARGUMENTS, @@ -195,7 +204,8 @@ public class SatelliteManager { SATELLITE_SERVICE_NO_RESOURCES, SATELLITE_SERVICE_REQUEST_FAILED, SATELLITE_SERVICE_INVALID_SUBSCRIPTION_ID, - SATELLITE_SERVICE_ERROR + SATELLITE_SERVICE_ERROR, + SATELLITE_SERVICE_DISABLED }) @Retention(RetentionPolicy.SOURCE) public @interface SatelliteServiceResult {} @@ -345,6 +355,46 @@ public class SatelliteManager { return SATELLITE_SERVICE_REQUEST_FAILED; } + /** + * Get maximum number of characters per text message on satellite. + * @param executor - The executor on which the result listener will be called. + * @param resultListener - Listener that will be called when the operation is successful. + * If this method returns {@link #SATELLITE_SERVICE_SUCCESS}, listener + * will be called with maximum characters limit. + * + * @throws SecurityException if the caller doesn't have required permission. + * + * @return The result of the operation + */ + @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION) + @SatelliteServiceResult + public int getMaxCharactersPerSatelliteTextMessage(@NonNull @CallbackExecutor Executor executor, + @NonNull Consumer resultListener) { + 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))); + } + }; + + return telephony.getMaxCharactersPerSatelliteTextMessage(mSubId, internalCallback); + } else { + throw new IllegalStateException("telephony service is null."); + } + } catch (RemoteException ex) { + loge("getMaxCharactersPerSatelliteTextMessage() RemoteException:" + ex); + ex.rethrowFromSystemServer(); + } + return SATELLITE_SERVICE_REQUEST_FAILED; + } + private static ITelephony getITelephony() { ITelephony binder = ITelephony.Stub.asInterface(TelephonyFrameworkInitializer .getTelephonyServiceManager() diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl index 933043ec29c16..54863653d0b33 100644 --- a/telephony/java/com/android/internal/telephony/ITelephony.aidl +++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl @@ -2709,4 +2709,9 @@ interface ITelephony { * Stop receiving satellite pointing updates. */ int stopSatellitePositionUpdates(int subId, int callbackId); -} + + /** + * Get maximum number of characters per text message on satellite. + */ + int getMaxCharactersPerSatelliteTextMessage(int subId, IIntegerConsumer internalCallback); +} \ No newline at end of file