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

Commit b2a83cfc authored by Brad Ebinger's avatar Brad Ebinger Committed by Mohamed
Browse files

SMS over IMS APIs revision

- Move from being a feature to being a capability
- Move format to the constructor and make final
- Initial hooking up of APIs provided by platform for ims providers.
- Add constants for send status result
- Rename SmsListener callbacks.
- Split acknowledgeSms for sms and sms reports.
- Add reason for onSendSmsResult
Bug: 69846044

Test: None
Change-Id: I861664264a117d5483e392d4aabff59bfaf4373e
parent 29f61c21
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -464,6 +464,7 @@ java_library {
        "telephony/java/android/telephony/ims/internal/aidl/IImsRegistrationCallback.aidl",
        "telephony/java/android/telephony/ims/internal/aidl/IImsServiceController.aidl",
        "telephony/java/android/telephony/ims/internal/aidl/IImsServiceControllerListener.aidl",
	"telephony/java/android/telephony/ims/internal/aidl/IImsSmsListener.aidl",
        "telephony/java/android/telephony/mbms/IMbmsDownloadSessionCallback.aidl",
        "telephony/java/android/telephony/mbms/IMbmsStreamingSessionCallback.aidl",
        "telephony/java/android/telephony/mbms/IDownloadStateCallback.aidl",
@@ -484,13 +485,11 @@ java_library {
        "telephony/java/com/android/ims/internal/IImsService.aidl",
        "telephony/java/com/android/ims/internal/IImsServiceController.aidl",
        "telephony/java/com/android/ims/internal/IImsServiceFeatureCallback.aidl",
        "telephony/java/com/android/ims/internal/IImsSmsFeature.aidl",
        "telephony/java/com/android/ims/internal/IImsStreamMediaSession.aidl",
        "telephony/java/com/android/ims/internal/IImsUt.aidl",
        "telephony/java/com/android/ims/internal/IImsUtListener.aidl",
        "telephony/java/com/android/ims/internal/IImsVideoCallCallback.aidl",
        "telephony/java/com/android/ims/internal/IImsVideoCallProvider.aidl",
        "telephony/java/com/android/ims/internal/ISmsListener.aidl",
        "telephony/java/com/android/ims/internal/uce/uceservice/IUceService.aidl",
        "telephony/java/com/android/ims/internal/uce/uceservice/IUceListener.aidl",
        "telephony/java/com/android/ims/internal/uce/options/IOptionsService.aidl",
+2 −0
Original line number Diff line number Diff line
@@ -1123,6 +1123,8 @@ public final class SmsManager {

    // SMS send failure result codes

    /** No error. {@hide}*/
    static public final int RESULT_ERROR_NONE    = 0;
    /** Generic failure cause */
    static public final int RESULT_ERROR_GENERIC_FAILURE    = 1;
    /** Failed because radio was explicitly turned off */
+260 −0
Original line number Diff line number Diff line
@@ -14,29 +14,37 @@
 * limitations under the License
 */

package android.telephony.ims.feature;
package android.telephony.ims.internal;

import android.annotation.IntDef;
import android.annotation.SystemApi;
import android.os.RemoteException;
import com.android.ims.internal.IImsSmsFeature;
import com.android.ims.internal.ISmsListener;
import android.telephony.SmsManager;
import android.telephony.SmsMessage;
import android.telephony.ims.internal.aidl.IImsSmsListener;
import android.telephony.ims.internal.feature.MmTelFeature;
import android.util.Log;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * Base implementation of SMS over IMS functionality.
 * Base implementation for SMS over IMS.
 *
 * Any service wishing to provide SMS over IMS should extend this class and implement all methods
 * that the service supports.
 * @hide
 */
public class SmsFeature extends ImsFeature {
  /**
   * SMS over IMS format is 3gpp.
   */
  public static final int IMS_SMS_FORMAT_3GPP = 1;

  /**
   * SMS over IMS format is 3gpp2.
   */
  public static final int IMS_SMS_FORMAT_3GPP2 = 2;
public class SmsImplBase {
  private static final String LOG_TAG = "SmsImplBase";

  @IntDef({
          SEND_STATUS_OK,
          SEND_STATUS_ERROR,
          SEND_STATUS_ERROR_RETRY,
          SEND_STATUS_ERROR_FALLBACK
      })
  @Retention(RetentionPolicy.SOURCE)
  public @interface SendStatusResult {}
  /**
   * Message was sent successfully.
   */
@@ -60,6 +68,12 @@ public class SmsFeature extends ImsFeature {
   */
  public static final int SEND_STATUS_ERROR_FALLBACK = 4;

  @IntDef({
          DELIVER_STATUS_OK,
          DELIVER_STATUS_ERROR
      })
  @Retention(RetentionPolicy.SOURCE)
  public @interface DeliverStatusResult {}
  /**
   * Message was delivered successfully.
   */
@@ -70,51 +84,38 @@ public class SmsFeature extends ImsFeature {
   */
  public static final int DELIVER_STATUS_ERROR = 2;

  // Lock for feature synchronization
  private final Object mLock = new Object();
  private ISmsListener mSmsListener;
  @IntDef({
          STATUS_REPORT_STATUS_OK,
          STATUS_REPORT_STATUS_ERROR
      })
  @Retention(RetentionPolicy.SOURCE)
  public @interface StatusReportResult {}

  private final IImsSmsFeature mIImsSmsBinder = new IImsSmsFeature.Stub() {
    @Override
    public void registerSmsListener(ISmsListener listener) {
      synchronized (mLock) {
        SmsFeature.this.registerSmsListener(listener);
      }
    }
  /**
   * Status Report was set successfully.
   */
  public static final int STATUS_REPORT_STATUS_OK = 1;

    @Override
    public void sendSms(int format, int messageRef, boolean retry, byte[] pdu) {
      synchronized (mLock) {
        SmsFeature.this.sendSms(format, messageRef, retry, pdu);
      }
    }
  /**
   * Error while setting status report.
   */
  public static final int STATUS_REPORT_STATUS_ERROR = 2;

    @Override
    public void acknowledgeSms(int messageRef, int result) {
      synchronized (mLock) {
        SmsFeature.this.acknowledgeSms(messageRef, result);
      }
    }

    @Override
    public int getSmsFormat() {
      synchronized (mLock) {
        return SmsFeature.this.getSmsFormat();
      }
    }
  };
  // Lock for feature synchronization
  private final Object mLock = new Object();
  private IImsSmsListener mListener;

  /**
   * Registers a listener responsible for handling tasks like delivering messages.

   *
   * @param listener listener to register.
   *
   * @hide
   */
  @SystemApi
  public final void registerSmsListener(ISmsListener listener) {
  public final void registerSmsListener(IImsSmsListener listener) {
    synchronized (mLock) {
      mSmsListener = listener;
      mListener = listener;
    }
  }

@@ -123,46 +124,71 @@ public class SmsFeature extends ImsFeature {
   * method should be implemented by the IMS providers to provide implementation of sending an SMS
   * over IMS.
   *
   * @param format the format of the message. One of {@link #IMS_SMS_FORMAT_3GPP} or
   *                {@link #IMS_SMS_FORMAT_3GPP2}
   * @param smsc the Short Message Service Center address.
   * @param format the format of the message. Valid values are {@link SmsMessage#FORMAT_3GPP} and
   * {@link SmsMessage#FORMAT_3GPP2}.
   * @param messageRef the message reference.
   * @param retry whether it is a retry of an already attempted message or not.
   * @param isRetry whether it is a retry of an already attempted message or not.
   * @param pdu PDUs representing the contents of the message.
   */
  public void sendSms(int format, int messageRef, boolean isRetry, byte[] pdu) {
  public void sendSms(int messageRef, String format, String smsc, boolean isRetry, byte[] pdu) {
    // Base implementation returns error. Should be overridden.
    try {
      onSendSmsResult(messageRef, SEND_STATUS_ERROR, SmsManager.RESULT_ERROR_GENERIC_FAILURE);
    } catch (RemoteException e) {
      Log.e(LOG_TAG, "Can not send sms: " + e.getMessage());
    }
  }

  /**
   * This method will be triggered by the platform after {@link #deliverSms(int, byte[])} has been
   * called to deliver the result to the IMS provider. It will also be triggered after
   * {@link #setSentSmsResult(int, int)} has been called to provide the result of the operation.
   * This method will be triggered by the platform after {@link #onSmsReceived(String, byte[])} has
   * been called to deliver the result to the IMS provider.
   *
   * @param result Should be {@link #DELIVER_STATUS_OK} if the message was delivered successfully,
   * {@link #DELIVER_STATUS_ERROR} otherwise.
   * @param messageRef the message reference.
   * @param result result of delivering the message. Valid values are defined in
   * {@link DeliverStatusResult}
   * @param messageRef the message reference or -1 of unavailable.
   */
  public void acknowledgeSms(int messageRef, int result) {
  public void acknowledgeSms(int messageRef, @DeliverStatusResult int result) {

  }

  /**
   * This method will be triggered by the platform after
   * {@link #onSmsStatusReportReceived(int, int, byte[])} has been called to provide the result to
   * the IMS provider.
   *
   * @param result result of delivering the message. Valid values are defined in
   * {@link StatusReportResult}
   * @param messageRef the message reference or -1 of unavailable.
   */
  public void acknowledgeSmsReport(int messageRef, @StatusReportResult int result) {

  }

  /**
   * This method should be triggered by the IMS providers when there is an incoming message. The
   * platform will deliver the message to the messages database and notify the IMS provider of the
   * result by calling {@link #acknowledgeSms(int)}.
   * result by calling {@link #acknowledgeSms(int, int)}.
   *
   * This method must not be called before {@link #onFeatureReady()} is called.
   * This method must not be called before {@link MmTelFeature#onFeatureReady()} is called.
   *
   * @param format the format of the message.One of {@link #IMS_SMS_FORMAT_3GPP} or
   *                {@link #IMS_SMS_FORMAT_3GPP2}
   * @param format the format of the message. Valid values are {@link SmsMessage#FORMAT_3GPP} and
   * {@link SmsMessage#FORMAT_3GPP2}.
   * @param pdu PDUs representing the contents of the message.
   * @throws IllegalStateException if called before {@link #onFeatureReady()}
   * @throws IllegalStateException if called before {@link MmTelFeature#onFeatureReady()}
   */
  public final void deliverSms(int format, byte[] pdu) throws IllegalStateException {
    // TODO: Guard against NPE/ Check if feature is ready and thrown an exception
    // otherwise.
  public final void onSmsReceived(String format, byte[] pdu) throws IllegalStateException {
    synchronized (mLock) {
      if (mListener == null) {
        throw new IllegalStateException("Feature not ready.");
      }
      try {
      mSmsListener.deliverSms(format, pdu);
        mListener.onSmsReceived(format, pdu);
        acknowledgeSms(-1, DELIVER_STATUS_OK);
      } catch (RemoteException e) {
        Log.e(LOG_TAG, "Can not deliver sms: " + e.getMessage());
        acknowledgeSms(-1, DELIVER_STATUS_ERROR);
      }
    }
  }

@@ -170,68 +196,65 @@ public class SmsFeature extends ImsFeature {
   * This method should be triggered by the IMS providers to pass the result of the sent message
   * to the platform.
   *
   * This method must not be called before {@link #onFeatureReady()} is called.
   * This method must not be called before {@link MmTelFeature#onFeatureReady()} is called.
   *
   * @param messageRef the message reference.
   * @param result One of {@link #SEND_STATUS_OK}, {@link #SEND_STATUS_ERROR},
   *                {@link #SEND_STATUS_ERROR_RETRY}, {@link #SEND_STATUS_ERROR_FALLBACK}
   * @throws IllegalStateException if called before {@link #onFeatureReady()}
   * @param messageRef the message reference. Should be between 0 and 255 per TS.123.040
   * @param status result of sending the SMS. Valid values are defined in {@link SendStatusResult}
   * @param reason reason in case status is failure. Valid values are:
   *  {@link SmsManager#RESULT_ERROR_NONE},
   *  {@link SmsManager#RESULT_ERROR_GENERIC_FAILURE},
   *  {@link SmsManager#RESULT_ERROR_RADIO_OFF},
   *  {@link SmsManager#RESULT_ERROR_NULL_PDU},
   *  {@link SmsManager#RESULT_ERROR_NO_SERVICE},
   *  {@link SmsManager#RESULT_ERROR_LIMIT_EXCEEDED},
   *  {@link SmsManager#RESULT_ERROR_SHORT_CODE_NOT_ALLOWED},
   *  {@link SmsManager#RESULT_ERROR_SHORT_CODE_NEVER_ALLOWED}
   * @throws IllegalStateException if called before {@link MmTelFeature#onFeatureReady()}
   * @throws RemoteException if the connection to the framework is not available. If this happens
   *  attempting to send the SMS should be aborted.
   */
  public final void setSentSmsResult(int messageRef, int result) throws IllegalStateException {
    // TODO: Guard against NPE/ Check if feature is ready and thrown an exception
    // otherwise.
    try {
      mSmsListener.setSentSmsResult(messageRef, result);
    } catch (RemoteException e) {
  public final void onSendSmsResult(int messageRef, @SendStatusResult int status, int reason)
      throws IllegalStateException, RemoteException {
    synchronized (mLock) {
      if (mListener == null) {
        throw new IllegalStateException("Feature not ready.");
      }
      mListener.onSendSmsResult(messageRef, status, reason);
    }
  }

  /**
   * Sets the status report of the sent message.
   *
   * @param format Should be {@link #IMS_SMS_FORMAT_3GPP} or {@link #IMS_SMS_FORMAT_3GPP2}
   * @param messageRef the message reference.
   * @param format the format of the message. Valid values are {@link SmsMessage#FORMAT_3GPP} and
   * {@link SmsMessage#FORMAT_3GPP2}.
   * @param pdu PDUs representing the content of the status report.
   * @throws IllegalStateException if called before {@link #onFeatureReady()}
   * @throws IllegalStateException if called before {@link MmTelFeature#onFeatureReady()}
   */
  public final void setSentSmsStatusReport(int format, byte[] pdu) {
    // TODO: Guard against NPE/ Check if feature is ready and thrown an exception
    // otherwise.
  public final void onSmsStatusReportReceived(int messageRef, String format, byte[] pdu) {
    synchronized (mLock) {
      if (mListener == null) {
        throw new IllegalStateException("Feature not ready.");
      }
      try {
      mSmsListener.setSentSmsStatusReport(format, pdu);
        mListener.onSmsStatusReportReceived(messageRef, format, pdu);
      } catch (RemoteException e) {
        Log.e(LOG_TAG, "Can not process sms status report: " + e.getMessage());
        acknowledgeSmsReport(messageRef, STATUS_REPORT_STATUS_ERROR);
      }
    }
  }

  /**
   * Returns the SMS format. Default is {@link #IMS_SMS_FORMAT_3GPP} unless overridden by IMS
   * Returns the SMS format. Default is {@link SmsMessage#FORMAT_3GPP} unless overridden by IMS
   * Provider.
   *
   * @return sms format.
   */
  public int getSmsFormat() {
    return IMS_SMS_FORMAT_3GPP;
  }

  /**
   * {@inheritDoc}
   * @return  the format of the message. Valid values are {@link SmsMessage#FORMAT_3GPP} and
   * {@link SmsMessage#FORMAT_3GPP2}.
   */
  public void onFeatureReady() {

  public String getSmsFormat() {
    return SmsMessage.FORMAT_3GPP;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public void onFeatureRemoved() {

  }

  /**
   * @hide
   */
  @Override
  public final IImsSmsFeature getBinder() {
    return mIImsSmsBinder;
  }
}
+8 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.telephony.ims.internal.aidl;

import android.os.Message;
import android.telephony.ims.internal.aidl.IImsMmTelListener;
import android.telephony.ims.internal.aidl.IImsSmsListener;
import android.telephony.ims.internal.aidl.IImsCapabilityCallback;
import android.telephony.ims.internal.aidl.IImsCallSessionListener;
import android.telephony.ims.internal.feature.CapabilityChangeRequest;
@@ -30,7 +31,7 @@ import com.android.ims.internal.IImsRegistrationListener;
import com.android.ims.internal.IImsUt;

/**
 * See MmTelFeature for more information.
 * See SmsImplBase for more information.
 * {@hide}
 */
interface IImsMmTelFeature {
@@ -49,4 +50,10 @@ interface IImsMmTelFeature {
            IImsCapabilityCallback c);
    oneway void queryCapabilityConfiguration(int capability, int radioTech,
            IImsCapabilityCallback c);
    // SMS APIs
    void setSmsListener(IImsSmsListener l);
    oneway void sendSms(int messageRef, String format, String smsc, boolean retry, in byte[] pdu);
    oneway void acknowledgeSms(int messageRef, int result);
    oneway void acknowledgeSmsReport(int messageRef, int result);
    String getSmsFormat();
}
+6 −6
Original line number Diff line number Diff line
@@ -14,14 +14,14 @@
 * limitations under the License.
 */

package com.android.ims.internal;
package android.telephony.ims.internal.aidl;

/**
 * See SmsFeature for more information.
 * See MMTelFeature for more information.
 * {@hide}
 */
interface ISmsListener {
    void setSentSmsResult(in int messageRef, in int result);
    void setSentSmsStatusReport(in int format, in byte[] pdu);
    void deliverSms(in int format, in byte[] pdu);
interface IImsSmsListener {
    void onSendSmsResult(in int messageRef, in int status, in int reason);
    void onSmsStatusReportReceived(in int messageRef, in String format, in byte[] pdu);
    void onSmsReceived(in String format, in byte[] pdu);
}
 No newline at end of file
Loading