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

Commit c045df60 authored by Hall Liu's avatar Hall Liu
Browse files

Add the addServiceAnnouncement API for EMBMS

Add addServiceAnnouncement to MbmsDownloadSession, allowing apps to add
service announcements from group call servers and receive information
about available files via the MbmsDownloadSession API surface.

Fixes: 144368478
Test: CTS
Change-Id: I760400f56219879fe71d0115042a3be2f83cef90
parent 5842f3ec
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -47567,12 +47567,14 @@ package android.telephony {
  public class MbmsDownloadSession implements java.lang.AutoCloseable {
    method public void addProgressListener(@NonNull android.telephony.mbms.DownloadRequest, @NonNull java.util.concurrent.Executor, @NonNull android.telephony.mbms.DownloadProgressListener);
    method public void addServiceAnnouncementFile(@NonNull byte[]);
    method public void addStatusListener(@NonNull android.telephony.mbms.DownloadRequest, @NonNull java.util.concurrent.Executor, @NonNull android.telephony.mbms.DownloadStatusListener);
    method public void cancelDownload(@NonNull android.telephony.mbms.DownloadRequest);
    method public void close();
    method public static android.telephony.MbmsDownloadSession create(@NonNull android.content.Context, @NonNull java.util.concurrent.Executor, @NonNull android.telephony.mbms.MbmsDownloadSessionCallback);
    method @Nullable public static android.telephony.MbmsDownloadSession create(@NonNull android.content.Context, @NonNull java.util.concurrent.Executor, int, @NonNull android.telephony.mbms.MbmsDownloadSessionCallback);
    method public void download(@NonNull android.telephony.mbms.DownloadRequest);
    method public static int getMaximumServiceAnnouncementFileSize();
    method @Nullable public java.io.File getTempFileRootDirectory();
    method @NonNull public java.util.List<android.telephony.mbms.DownloadRequest> listPendingDownloads();
    method public void removeProgressListener(@NonNull android.telephony.mbms.DownloadRequest, @NonNull android.telephony.mbms.DownloadProgressListener);
@@ -49184,6 +49186,7 @@ package android.telephony.mbms {
  public static class MbmsErrors.DownloadErrors {
    field public static final int ERROR_CANNOT_CHANGE_TEMP_FILE_ROOT = 401; // 0x191
    field public static final int ERROR_MALFORMED_SERVICE_ANNOUNCEMENT_FILE = 404; // 0x194
    field public static final int ERROR_UNKNOWN_DOWNLOAD_REQUEST = 402; // 0x192
    field public static final int ERROR_UNKNOWN_FILE_INFO = 403; // 0x193
  }
+1 −0
Original line number Diff line number Diff line
@@ -12442,6 +12442,7 @@ package android.telephony.mbms.vendor {
  public class MbmsDownloadServiceBase extends android.os.Binder implements android.os.IInterface {
    ctor public MbmsDownloadServiceBase();
    method public int addProgressListener(android.telephony.mbms.DownloadRequest, android.telephony.mbms.DownloadProgressListener) throws android.os.RemoteException;
    method public int addServiceAnnouncementFile(int, @NonNull byte[]);
    method public int addStatusListener(android.telephony.mbms.DownloadRequest, android.telephony.mbms.DownloadStatusListener) throws android.os.RemoteException;
    method public android.os.IBinder asBinder();
    method public int cancelDownload(android.telephony.mbms.DownloadRequest) throws android.os.RemoteException;
+1 −0
Original line number Diff line number Diff line
@@ -4670,6 +4670,7 @@ package android.telephony.mbms.vendor {
  public class MbmsDownloadServiceBase extends android.os.Binder implements android.os.IInterface {
    ctor public MbmsDownloadServiceBase();
    method public int addProgressListener(android.telephony.mbms.DownloadRequest, android.telephony.mbms.DownloadProgressListener) throws android.os.RemoteException;
    method public int addServiceAnnouncementFile(int, @NonNull byte[]);
    method public int addStatusListener(android.telephony.mbms.DownloadRequest, android.telephony.mbms.DownloadStatusListener) throws android.os.RemoteException;
    method public android.os.IBinder asBinder();
    method public int cancelDownload(android.telephony.mbms.DownloadRequest) throws android.os.RemoteException;
+1 −0
Original line number Diff line number Diff line
@@ -1929,6 +1929,7 @@ package android.telephony.mbms.vendor {
  public class MbmsDownloadServiceBase extends android.os.Binder implements android.os.IInterface {
    ctor public MbmsDownloadServiceBase();
    method public int addProgressListener(android.telephony.mbms.DownloadRequest, android.telephony.mbms.DownloadProgressListener) throws android.os.RemoteException;
    method public int addServiceAnnouncementFile(int, @NonNull byte[]);
    method public int addStatusListener(android.telephony.mbms.DownloadRequest, android.telephony.mbms.DownloadStatusListener) throws android.os.RemoteException;
    method public android.os.IBinder asBinder();
    method public int cancelDownload(android.telephony.mbms.DownloadRequest) throws android.os.RemoteException;
+66 −0
Original line number Diff line number Diff line
@@ -231,6 +231,8 @@ public class MbmsDownloadSession implements AutoCloseable {

    private static final String DESTINATION_SANITY_CHECK_FILE_NAME = "destinationSanityCheckFile";

    private static final int MAX_SERVICE_ANNOUNCEMENT_FILE_SIZE = 10 * 1024; // 10KB

    private static AtomicBoolean sIsInitialized = new AtomicBoolean(false);

    private final Context mContext;
@@ -318,6 +320,16 @@ public class MbmsDownloadSession implements AutoCloseable {
        return session;
    }

    /**
     * Returns the maximum size of the service announcement file that can be provided via
     * {@link #addServiceAnnouncementFile}
     * @return The maximum length of the byte array passed as an argument to
     *         {@link #addServiceAnnouncementFile}.
     */
    public static int getMaximumServiceAnnouncementFileSize() {
        return MAX_SERVICE_ANNOUNCEMENT_FILE_SIZE;
    }

    private int bindAndInitialize() {
        mServiceConnection = new ServiceConnection() {
            @Override
@@ -423,6 +435,60 @@ public class MbmsDownloadSession implements AutoCloseable {
        }
    }

    /**
     * Inform the middleware of a service announcement file received from a group communication
     * server.
     *
     * When participating in a group call via the {@link MbmsGroupCallSession} API, applications may
     * receive a service announcement file from the group call server that informs them of
     * files that may be relevant to users communicating on the group call.
     *
     * After supplying the service announcement file received from the server to the middleware via
     * this API, applications will receive information on the available files via
     * {@link MbmsDownloadSessionCallback#onFileServicesUpdated}, and the available files will be
     * downloadable via {@link MbmsDownloadSession#download} like other files published via
     * {@link MbmsDownloadSessionCallback#onFileServicesUpdated}.
     *
     * Asynchronous error codes via the {@link MbmsDownloadSessionCallback#onError(int, String)}
     * callback may include any of the errors that are not specific to the streaming use-case.
     *
     * May throw an {@link IllegalStateException} when the middleware has not yet been bound,
     * or an {@link IllegalArgumentException} if the file is too large.
     *
     * @param fileContents The contents of the service announcement file received from the group
     *                     call server. If the size of this array is greater than the value of
     *                     {@link #getMaximumServiceAnnouncementFileSize()}, an
     *                     {@link IllegalArgumentException} will be thrown.
     */
    public void addServiceAnnouncementFile(@NonNull byte[] fileContents) {
        IMbmsDownloadService downloadService = mService.get();
        if (downloadService == null) {
            throw new IllegalStateException("Middleware not yet bound");
        }

        if (fileContents.length > MAX_SERVICE_ANNOUNCEMENT_FILE_SIZE) {
            throw new IllegalArgumentException("File too large");
        }

        try {
            int returnCode = downloadService.addServiceAnnouncementFile(
                    mSubscriptionId, fileContents);
            if (returnCode == MbmsErrors.UNKNOWN) {
                // Unbind and throw an obvious error
                close();
                throw new IllegalStateException("Middleware must not return an unknown error code");
            }
            if (returnCode != MbmsErrors.SUCCESS) {
                sendErrorToApp(returnCode, null);
            }
        } catch (RemoteException e) {
            Log.w(LOG_TAG, "Remote process died");
            mService.set(null);
            sIsInitialized.set(false);
            sendErrorToApp(MbmsErrors.ERROR_MIDDLEWARE_LOST, null);
        }
    }

    /**
     * Sets the temp file root for downloads.
     * All temp files created for the middleware to write to will be contained in the specified
Loading