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

Commit ecd47095 authored by Hall Liu's avatar Hall Liu Committed by Android (Google) Code Review
Browse files

Merge "Split the DownloadStateCallback class into two" into pi-dev

parents 3aa86b42 79539971
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -500,7 +500,8 @@ java_library {
        "telephony/java/android/telephony/ims/aidl/IImsSmsListener.aidl",
        "telephony/java/android/telephony/mbms/IMbmsDownloadSessionCallback.aidl",
        "telephony/java/android/telephony/mbms/IMbmsStreamingSessionCallback.aidl",
        "telephony/java/android/telephony/mbms/IDownloadStateCallback.aidl",
        "telephony/java/android/telephony/mbms/IDownloadStatusListener.aidl",
        "telephony/java/android/telephony/mbms/IDownloadProgressListener.aidl",
        "telephony/java/android/telephony/mbms/IStreamingServiceCallback.aidl",
        "telephony/java/android/telephony/mbms/vendor/IMbmsDownloadService.aidl",
        "telephony/java/android/telephony/mbms/vendor/IMbmsStreamingService.aidl",
+12 −11
Original line number Diff line number Diff line
@@ -41867,6 +41867,8 @@ package android.telephony {
  }
  public class MbmsDownloadSession implements java.lang.AutoCloseable {
    method public int addProgressListener(android.telephony.mbms.DownloadRequest, java.util.concurrent.Executor, android.telephony.mbms.DownloadProgressListener);
    method public int addStatusListener(android.telephony.mbms.DownloadRequest, java.util.concurrent.Executor, android.telephony.mbms.DownloadStatusListener);
    method public int cancelDownload(android.telephony.mbms.DownloadRequest);
    method public void close();
    method public static android.telephony.MbmsDownloadSession create(android.content.Context, java.util.concurrent.Executor, android.telephony.mbms.MbmsDownloadSessionCallback);
@@ -41874,12 +41876,12 @@ package android.telephony {
    method public int download(android.telephony.mbms.DownloadRequest);
    method public java.io.File getTempFileRootDirectory();
    method public java.util.List<android.telephony.mbms.DownloadRequest> listPendingDownloads();
    method public int registerStateCallback(android.telephony.mbms.DownloadRequest, java.util.concurrent.Executor, android.telephony.mbms.DownloadStateCallback);
    method public int removeProgressListener(android.telephony.mbms.DownloadRequest, android.telephony.mbms.DownloadProgressListener);
    method public int removeStatusListener(android.telephony.mbms.DownloadRequest, android.telephony.mbms.DownloadStatusListener);
    method public void requestDownloadState(android.telephony.mbms.DownloadRequest, android.telephony.mbms.FileInfo);
    method public void requestUpdateFileServices(java.util.List<java.lang.String>);
    method public void resetDownloadKnowledge(android.telephony.mbms.DownloadRequest);
    method public void setTempFileRootDirectory(java.io.File);
    method public int unregisterStateCallback(android.telephony.mbms.DownloadRequest, android.telephony.mbms.DownloadStateCallback);
    field public static final java.lang.String DEFAULT_TOP_LEVEL_TEMP_DIRECTORY = "androidMbmsTempFileRoot";
    field public static final java.lang.String EXTRA_MBMS_COMPLETED_FILE_URI = "android.telephony.extra.MBMS_COMPLETED_FILE_URI";
    field public static final java.lang.String EXTRA_MBMS_DOWNLOAD_REQUEST = "android.telephony.extra.MBMS_DOWNLOAD_REQUEST";
@@ -42778,6 +42780,11 @@ package android.telephony.gsm {
package android.telephony.mbms {
  public class DownloadProgressListener {
    ctor public DownloadProgressListener();
    method public void onProgressUpdated(android.telephony.mbms.DownloadRequest, android.telephony.mbms.FileInfo, int, int, int, int);
  }
  public final class DownloadRequest implements android.os.Parcelable {
    method public int describeContents();
    method public android.net.Uri getDestinationUri();
@@ -42801,15 +42808,9 @@ package android.telephony.mbms {
    method public android.telephony.mbms.DownloadRequest.Builder setSubscriptionId(int);
  }
  public class DownloadStateCallback {
    ctor public DownloadStateCallback();
    ctor public DownloadStateCallback(int);
    method public final boolean isFilterFlagSet(int);
    method public void onProgressUpdated(android.telephony.mbms.DownloadRequest, android.telephony.mbms.FileInfo, int, int, int, int);
    method public void onStateUpdated(android.telephony.mbms.DownloadRequest, android.telephony.mbms.FileInfo, int);
    field public static final int ALL_UPDATES = 0; // 0x0
    field public static final int PROGRESS_UPDATES = 1; // 0x1
    field public static final int STATE_UPDATES = 2; // 0x2
  public class DownloadStatusListener {
    ctor public DownloadStatusListener();
    method public void onStatusUpdated(android.telephony.mbms.DownloadRequest, android.telephony.mbms.FileInfo, int);
  }
  public final class FileInfo implements android.os.Parcelable {
+4 −2
Original line number Diff line number Diff line
@@ -6311,18 +6311,20 @@ package android.telephony.mbms.vendor {

  public class MbmsDownloadServiceBase extends android.os.Binder {
    ctor public MbmsDownloadServiceBase();
    method public int addProgressListener(android.telephony.mbms.DownloadRequest, android.telephony.mbms.DownloadProgressListener) throws android.os.RemoteException;
    method public int addStatusListener(android.telephony.mbms.DownloadRequest, android.telephony.mbms.DownloadStatusListener) throws android.os.RemoteException;
    method public int cancelDownload(android.telephony.mbms.DownloadRequest) throws android.os.RemoteException;
    method public void dispose(int) throws android.os.RemoteException;
    method public int download(android.telephony.mbms.DownloadRequest) throws android.os.RemoteException;
    method public int initialize(int, android.telephony.mbms.MbmsDownloadSessionCallback) throws android.os.RemoteException;
    method public java.util.List<android.telephony.mbms.DownloadRequest> listPendingDownloads(int) throws android.os.RemoteException;
    method public void onAppCallbackDied(int, int);
    method public int registerStateCallback(android.telephony.mbms.DownloadRequest, android.telephony.mbms.DownloadStateCallback) throws android.os.RemoteException;
    method public int removeProgressListener(android.telephony.mbms.DownloadRequest, android.telephony.mbms.DownloadProgressListener) throws android.os.RemoteException;
    method public int removeStatusListener(android.telephony.mbms.DownloadRequest, android.telephony.mbms.DownloadStatusListener) throws android.os.RemoteException;
    method public int requestDownloadState(android.telephony.mbms.DownloadRequest, android.telephony.mbms.FileInfo) throws android.os.RemoteException;
    method public int requestUpdateFileServices(int, java.util.List<java.lang.String>) throws android.os.RemoteException;
    method public int resetDownloadKnowledge(android.telephony.mbms.DownloadRequest) throws android.os.RemoteException;
    method public int setTempFileRootDirectory(int, java.lang.String) throws android.os.RemoteException;
    method public int unregisterStateCallback(android.telephony.mbms.DownloadRequest, android.telephony.mbms.DownloadStateCallback) throws android.os.RemoteException;
  }

  public class MbmsStreamingServiceBase extends android.os.Binder {
+4 −2
Original line number Diff line number Diff line
@@ -802,18 +802,20 @@ package android.telephony.mbms.vendor {

  public class MbmsDownloadServiceBase extends android.os.Binder {
    ctor public MbmsDownloadServiceBase();
    method public int addProgressListener(android.telephony.mbms.DownloadRequest, android.telephony.mbms.DownloadProgressListener) throws android.os.RemoteException;
    method public int addStatusListener(android.telephony.mbms.DownloadRequest, android.telephony.mbms.DownloadStatusListener) throws android.os.RemoteException;
    method public int cancelDownload(android.telephony.mbms.DownloadRequest) throws android.os.RemoteException;
    method public void dispose(int) throws android.os.RemoteException;
    method public int download(android.telephony.mbms.DownloadRequest) throws android.os.RemoteException;
    method public int initialize(int, android.telephony.mbms.MbmsDownloadSessionCallback) throws android.os.RemoteException;
    method public java.util.List<android.telephony.mbms.DownloadRequest> listPendingDownloads(int) throws android.os.RemoteException;
    method public void onAppCallbackDied(int, int);
    method public int registerStateCallback(android.telephony.mbms.DownloadRequest, android.telephony.mbms.DownloadStateCallback) throws android.os.RemoteException;
    method public int removeProgressListener(android.telephony.mbms.DownloadRequest, android.telephony.mbms.DownloadProgressListener) throws android.os.RemoteException;
    method public int removeStatusListener(android.telephony.mbms.DownloadRequest, android.telephony.mbms.DownloadStatusListener) throws android.os.RemoteException;
    method public int requestDownloadState(android.telephony.mbms.DownloadRequest, android.telephony.mbms.FileInfo) throws android.os.RemoteException;
    method public int requestUpdateFileServices(int, java.util.List<java.lang.String>) throws android.os.RemoteException;
    method public int resetDownloadKnowledge(android.telephony.mbms.DownloadRequest) throws android.os.RemoteException;
    method public int setTempFileRootDirectory(int, java.lang.String) throws android.os.RemoteException;
    method public int unregisterStateCallback(android.telephony.mbms.DownloadRequest, android.telephony.mbms.DownloadStateCallback) throws android.os.RemoteException;
  }

  public class MbmsStreamingServiceBase extends android.os.Binder {
+128 −30
Original line number Diff line number Diff line
@@ -31,11 +31,13 @@ import android.net.Uri;
import android.os.Handler;
import android.os.IBinder;
import android.os.RemoteException;
import android.telephony.mbms.DownloadStateCallback;
import android.telephony.mbms.DownloadProgressListener;
import android.telephony.mbms.DownloadStatusListener;
import android.telephony.mbms.FileInfo;
import android.telephony.mbms.DownloadRequest;
import android.telephony.mbms.InternalDownloadProgressListener;
import android.telephony.mbms.InternalDownloadSessionCallback;
import android.telephony.mbms.InternalDownloadStateCallback;
import android.telephony.mbms.InternalDownloadStatusListener;
import android.telephony.mbms.MbmsDownloadSessionCallback;
import android.telephony.mbms.MbmsDownloadReceiver;
import android.telephony.mbms.MbmsErrors;
@@ -240,8 +242,10 @@ public class MbmsDownloadSession implements AutoCloseable {

    private AtomicReference<IMbmsDownloadService> mService = new AtomicReference<>(null);
    private final InternalDownloadSessionCallback mInternalCallback;
    private final Map<DownloadStateCallback, InternalDownloadStateCallback>
            mInternalDownloadCallbacks = new HashMap<>();
    private final Map<DownloadStatusListener, InternalDownloadStatusListener>
            mInternalDownloadStatusListeners = new HashMap<>();
    private final Map<DownloadProgressListener, InternalDownloadProgressListener>
            mInternalDownloadProgressListeners = new HashMap<>();

    private MbmsDownloadSession(Context context, Executor executor, int subscriptionId,
            MbmsDownloadSessionCallback callback) {
@@ -569,34 +573,33 @@ public class MbmsDownloadSession implements AutoCloseable {
    }

    /**
     * Registers a callback for a {@link DownloadRequest} previously requested via
     * Registers a download status listener for a {@link DownloadRequest} previously requested via
     * {@link #download(DownloadRequest)}. This callback will only be called as long as both this
     * app and the middleware are both running -- if either one stops, no further calls on the
     * provided {@link DownloadStateCallback} will be enqueued.
     * provided {@link DownloadStatusListener} will be enqueued.
     *
     * If the middleware is not aware of the specified download request,
     * this method will throw an {@link IllegalArgumentException}.
     *
     * @param request The {@link DownloadRequest} that you want updates on.
     * @param executor The {@link Executor} on which calls to {@code callback} should be executed.
     * @param callback The callback that should be called when the middleware has information to
     *                 share on the download.
     * @param executor The {@link Executor} on which calls to {@code listener } should be executed.
     * @param listener The listener that should be called when the middleware has information to
     *                 share on the status download.
     * @return {@link MbmsErrors#SUCCESS} if the operation did not encounter a synchronous error,
     * and some other error code otherwise.
     */
    public int registerStateCallback(@NonNull DownloadRequest request,
            @NonNull Executor executor, @NonNull DownloadStateCallback callback) {
    public int addStatusListener(@NonNull DownloadRequest request,
            @NonNull Executor executor, @NonNull DownloadStatusListener listener) {
        IMbmsDownloadService downloadService = mService.get();
        if (downloadService == null) {
            throw new IllegalStateException("Middleware not yet bound");
        }

        InternalDownloadStateCallback internalCallback =
                new InternalDownloadStateCallback(callback, executor);
        InternalDownloadStatusListener internalListener =
                new InternalDownloadStatusListener(listener, executor);

        try {
            int result = downloadService.registerStateCallback(request, internalCallback,
                    callback.getCallbackFilterFlags());
            int result = downloadService.addStatusListener(request, internalListener);
            if (result != MbmsErrors.SUCCESS) {
                if (result == MbmsErrors.DownloadErrors.ERROR_UNKNOWN_DOWNLOAD_REQUEST) {
                    throw new IllegalArgumentException("Unknown download request.");
@@ -608,13 +611,108 @@ public class MbmsDownloadSession implements AutoCloseable {
            sIsInitialized.set(false);
            return MbmsErrors.ERROR_MIDDLEWARE_LOST;
        }
        mInternalDownloadCallbacks.put(callback, internalCallback);
        mInternalDownloadStatusListeners.put(listener, internalListener);
        return MbmsErrors.SUCCESS;

    }

    /**
     * Un-register a listener previously registered via
     * {@link #addStatusListener(DownloadRequest, Executor, DownloadStatusListener)}. After
     * this method is called, no further calls will be enqueued on the {@link Executor}
     * provided upon registration, even if this method throws an exception.
     *
     * If the middleware is not aware of the specified download request,
     * this method will throw an {@link IllegalArgumentException}.
     *
     * @param request The {@link DownloadRequest} provided during registration
     * @param listener The listener provided during registration.
     * @return {@link MbmsErrors#SUCCESS} if the operation did not encounter a synchronous error,
     * and some other error code otherwise.
     */
    public int removeStatusListener(@NonNull DownloadRequest request,
            @NonNull DownloadStatusListener listener) {
        try {
            IMbmsDownloadService downloadService = mService.get();
            if (downloadService == null) {
                throw new IllegalStateException("Middleware not yet bound");
            }

            InternalDownloadStatusListener internalListener =
                    mInternalDownloadStatusListeners.get(listener);
            if (internalListener == null) {
                throw new IllegalArgumentException("Provided listener was never registered");
            }

            try {
                int result = downloadService.removeStatusListener(request, internalListener);
                if (result != MbmsErrors.SUCCESS) {
                    if (result == MbmsErrors.DownloadErrors.ERROR_UNKNOWN_DOWNLOAD_REQUEST) {
                        throw new IllegalArgumentException("Unknown download request.");
                    }
                    return result;
                }
            } catch (RemoteException e) {
                mService.set(null);
                sIsInitialized.set(false);
                return MbmsErrors.ERROR_MIDDLEWARE_LOST;
            }
        } finally {
            InternalDownloadStatusListener internalCallback =
                    mInternalDownloadStatusListeners.remove(listener);
            if (internalCallback != null) {
                internalCallback.stop();
            }
        }
        return MbmsErrors.SUCCESS;
    }

    /**
     * Registers a progress listener for a {@link DownloadRequest} previously requested via
     * {@link #download(DownloadRequest)}. This listener will only be called as long as both this
     * app and the middleware are both running -- if either one stops, no further calls on the
     * provided {@link DownloadProgressListener} will be enqueued.
     *
     * If the middleware is not aware of the specified download request,
     * this method will throw an {@link IllegalArgumentException}.
     *
     * @param request The {@link DownloadRequest} that you want updates on.
     * @param executor The {@link Executor} on which calls to {@code listener} should be executed.
     * @param listener The listener that should be called when the middleware has information to
     *                 share on the progress of the download.
     * @return {@link MbmsErrors#SUCCESS} if the operation did not encounter a synchronous error,
     * and some other error code otherwise.
     */
    public int addProgressListener(@NonNull DownloadRequest request,
            @NonNull Executor executor, @NonNull DownloadProgressListener listener) {
        IMbmsDownloadService downloadService = mService.get();
        if (downloadService == null) {
            throw new IllegalStateException("Middleware not yet bound");
        }

        InternalDownloadProgressListener internalListener =
                new InternalDownloadProgressListener(listener, executor);

        try {
            int result = downloadService.addProgressListener(request, internalListener);
            if (result != MbmsErrors.SUCCESS) {
                if (result == MbmsErrors.DownloadErrors.ERROR_UNKNOWN_DOWNLOAD_REQUEST) {
                    throw new IllegalArgumentException("Unknown download request.");
                }
                return result;
            }
        } catch (RemoteException e) {
            mService.set(null);
            sIsInitialized.set(false);
            return MbmsErrors.ERROR_MIDDLEWARE_LOST;
        }
        mInternalDownloadProgressListeners.put(listener, internalListener);
        return MbmsErrors.SUCCESS;
    }

    /**
     * Un-register a callback previously registered via
     * {@link #registerStateCallback(DownloadRequest, Executor, DownloadStateCallback)}. After
     * Un-register a listener previously registered via
     * {@link #addProgressListener(DownloadRequest, Executor, DownloadProgressListener)}. After
     * this method is called, no further callbacks will be enqueued on the {@link Handler}
     * provided upon registration, even if this method throws an exception.
     *
@@ -622,26 +720,26 @@ public class MbmsDownloadSession implements AutoCloseable {
     * this method will throw an {@link IllegalArgumentException}.
     *
     * @param request The {@link DownloadRequest} provided during registration
     * @param callback The callback provided during registration.
     * @param listener The listener provided during registration.
     * @return {@link MbmsErrors#SUCCESS} if the operation did not encounter a synchronous error,
     * and some other error code otherwise.
     */
    public int unregisterStateCallback(@NonNull DownloadRequest request,
            @NonNull DownloadStateCallback callback) {
    public int removeProgressListener(@NonNull DownloadRequest request,
            @NonNull DownloadProgressListener listener) {
        try {
            IMbmsDownloadService downloadService = mService.get();
            if (downloadService == null) {
                throw new IllegalStateException("Middleware not yet bound");
            }

            InternalDownloadStateCallback internalCallback =
                    mInternalDownloadCallbacks.get(callback);
            if (internalCallback == null) {
                throw new IllegalArgumentException("Provided callback was never registered");
            InternalDownloadProgressListener internalListener =
                    mInternalDownloadProgressListeners.get(listener);
            if (internalListener == null) {
                throw new IllegalArgumentException("Provided listener was never registered");
            }

            try {
                int result = downloadService.unregisterStateCallback(request, internalCallback);
                int result = downloadService.removeProgressListener(request, internalListener);
                if (result != MbmsErrors.SUCCESS) {
                    if (result == MbmsErrors.DownloadErrors.ERROR_UNKNOWN_DOWNLOAD_REQUEST) {
                        throw new IllegalArgumentException("Unknown download request.");
@@ -654,8 +752,8 @@ public class MbmsDownloadSession implements AutoCloseable {
                return MbmsErrors.ERROR_MIDDLEWARE_LOST;
            }
        } finally {
            InternalDownloadStateCallback internalCallback =
                    mInternalDownloadCallbacks.remove(callback);
            InternalDownloadProgressListener internalCallback =
                    mInternalDownloadProgressListeners.remove(listener);
            if (internalCallback != null) {
                internalCallback.stop();
            }
@@ -700,9 +798,9 @@ public class MbmsDownloadSession implements AutoCloseable {
     * Requests information about the state of a file pending download.
     *
     * The state will be delivered as a callback via
     * {@link DownloadStateCallback#onStateUpdated(DownloadRequest, FileInfo, int)}. If no such
     * {@link DownloadStatusListener#onStatusUpdated(DownloadRequest, FileInfo, int)}. If no such
     * callback has been registered via
     * {@link #registerStateCallback(DownloadRequest, Executor, DownloadStateCallback)}, this
     * {@link #addProgressListener(DownloadRequest, Executor, DownloadProgressListener)}, this
     * method will be a no-op.
     *
     * If the middleware has no record of the
Loading