Loading telephony/java/android/telephony/MbmsDownloadSession.java +3 −3 Original line number Diff line number Diff line Loading @@ -523,8 +523,7 @@ public class MbmsDownloadSession implements AutoCloseable { * @param handler The {@link Handler} on which calls to {@code callback} should be enqueued on. */ public void registerStateCallback(@NonNull DownloadRequest request, @NonNull DownloadStateCallback callback, @NonNull Handler handler) { @NonNull DownloadStateCallback callback, @NonNull Handler handler) { IMbmsDownloadService downloadService = mService.get(); if (downloadService == null) { throw new IllegalStateException("Middleware not yet bound"); Loading @@ -534,7 +533,8 @@ public class MbmsDownloadSession implements AutoCloseable { new InternalDownloadStateCallback(callback, handler); try { int result = downloadService.registerStateCallback(request, internalCallback); int result = downloadService.registerStateCallback(request, internalCallback, callback.getCallbackFilterFlags()); if (result != MbmsErrors.SUCCESS) { if (result == MbmsErrors.DownloadErrors.ERROR_UNKNOWN_DOWNLOAD_REQUEST) { throw new IllegalArgumentException("Unknown download request."); Loading telephony/java/android/telephony/mbms/DownloadStateCallback.java +69 −0 Original line number Diff line number Diff line Loading @@ -16,8 +16,12 @@ package android.telephony.mbms; import android.annotation.IntDef; import android.telephony.MbmsDownloadSession; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; /** * A optional listener class used by download clients to track progress. Apps should extend this * class and pass an instance into Loading @@ -29,6 +33,71 @@ import android.telephony.MbmsDownloadSession; */ public class DownloadStateCallback { /** * Bitmask flags used for filtering out callback methods. Used when constructing the * DownloadStateCallback as an optional parameter. * @hide */ @Retention(RetentionPolicy.SOURCE) @IntDef({ALL_UPDATES, PROGRESS_UPDATES, STATE_UPDATES}) public @interface FilterFlag {} /** * Receive all callbacks. * Default value. */ public static final int ALL_UPDATES = 0x00; /** * Receive callbacks for {@link #onProgressUpdated}. */ public static final int PROGRESS_UPDATES = 0x01; /** * Receive callbacks for {@link #onStateUpdated}. */ public static final int STATE_UPDATES = 0x02; private final int mCallbackFilterFlags; /** * Creates a DownloadStateCallback that will receive all callbacks. */ public DownloadStateCallback() { mCallbackFilterFlags = ALL_UPDATES; } /** * Creates a DownloadStateCallback that will only receive callbacks for the methods specified * via the filterFlags parameter. * @param filterFlags A bitmask of filter flags that will specify which callback this instance * is interested in. */ public DownloadStateCallback(int filterFlags) { mCallbackFilterFlags = filterFlags; } /** * Return the currently set filter flags. * @return An integer containing the bitmask of flags that this instance is interested in. * @hide */ public int getCallbackFilterFlags() { return mCallbackFilterFlags; } /** * Returns true if a filter flag is set for a particular callback method. If the flag is set, * the callback will be delivered to the listening process. * @param flag A filter flag specifying whether or not a callback method is registered to * receive callbacks. * @return true if registered to receive callbacks in the listening process, false if not. */ public final boolean isFilterFlagSet(@FilterFlag int flag) { if (mCallbackFilterFlags == ALL_UPDATES) { return true; } return (mCallbackFilterFlags & flag) > 0; } /** * Called when the middleware wants to report progress for a file in a {@link DownloadRequest}. * Loading telephony/java/android/telephony/mbms/vendor/IMbmsDownloadService.aidl +2 −1 Original line number Diff line number Diff line Loading @@ -36,7 +36,8 @@ interface IMbmsDownloadService int download(in DownloadRequest downloadRequest); int registerStateCallback(in DownloadRequest downloadRequest, IDownloadStateCallback listener); int registerStateCallback(in DownloadRequest downloadRequest, IDownloadStateCallback listener, int flags); int unregisterStateCallback(in DownloadRequest downloadRequest, IDownloadStateCallback listener); Loading telephony/java/android/telephony/mbms/vendor/MbmsDownloadServiceBase.java +46 −24 Original line number Diff line number Diff line Loading @@ -46,6 +46,47 @@ public class MbmsDownloadServiceBase extends IMbmsDownloadService.Stub { private final Map<IBinder, DownloadStateCallback> mDownloadCallbackBinderMap = new HashMap<>(); private final Map<IBinder, DeathRecipient> mDownloadCallbackDeathRecipients = new HashMap<>(); // Filters the DownloadStateCallbacks by its configuration from the app. private abstract static class FilteredDownloadStateCallback extends DownloadStateCallback { private final IDownloadStateCallback mCallback; public FilteredDownloadStateCallback(IDownloadStateCallback callback, int callbackFlags) { super(callbackFlags); mCallback = callback; } @Override public void onProgressUpdated(DownloadRequest request, FileInfo fileInfo, int currentDownloadSize, int fullDownloadSize, int currentDecodedSize, int fullDecodedSize) { if (!isFilterFlagSet(PROGRESS_UPDATES)) { return; } try { mCallback.onProgressUpdated(request, fileInfo, currentDownloadSize, fullDownloadSize, currentDecodedSize, fullDecodedSize); } catch (RemoteException e) { onRemoteException(e); } } @Override public void onStateUpdated(DownloadRequest request, FileInfo fileInfo, @MbmsDownloadSession.DownloadStatus int state) { if (!isFilterFlagSet(STATE_UPDATES)) { return; } try { mCallback.onStateUpdated(request, fileInfo, state); } catch (RemoteException e) { onRemoteException(e); } } protected abstract void onRemoteException(RemoteException e); } /** * Initialize the download service for this app and subId, registering the listener. * Loading Loading @@ -196,9 +237,8 @@ public class MbmsDownloadServiceBase extends IMbmsDownloadService.Stub { * @hide */ @Override public final int registerStateCallback( final DownloadRequest downloadRequest, final IDownloadStateCallback callback) throws RemoteException { public final int registerStateCallback(final DownloadRequest downloadRequest, final IDownloadStateCallback callback, int flags) throws RemoteException { final int uid = Binder.getCallingUid(); DeathRecipient deathRecipient = new DeathRecipient() { @Override Loading @@ -211,29 +251,11 @@ public class MbmsDownloadServiceBase extends IMbmsDownloadService.Stub { mDownloadCallbackDeathRecipients.put(callback.asBinder(), deathRecipient); callback.asBinder().linkToDeath(deathRecipient, 0); DownloadStateCallback exposedCallback = new DownloadStateCallback() { @Override public void onProgressUpdated(DownloadRequest request, FileInfo fileInfo, int currentDownloadSize, int fullDownloadSize, int currentDecodedSize, int fullDecodedSize) { try { callback.onProgressUpdated(request, fileInfo, currentDownloadSize, fullDownloadSize, currentDecodedSize, fullDecodedSize); } catch (RemoteException e) { onAppCallbackDied(uid, downloadRequest.getSubscriptionId()); } } DownloadStateCallback exposedCallback = new FilteredDownloadStateCallback(callback, flags) { @Override public void onStateUpdated(DownloadRequest request, FileInfo fileInfo, @MbmsDownloadSession.DownloadStatus int state) { try { callback.onStateUpdated(request, fileInfo, state); } catch (RemoteException e) { protected void onRemoteException(RemoteException e) { onAppCallbackDied(uid, downloadRequest.getSubscriptionId()); } } }; mDownloadCallbackBinderMap.put(callback.asBinder(), exposedCallback); Loading Loading
telephony/java/android/telephony/MbmsDownloadSession.java +3 −3 Original line number Diff line number Diff line Loading @@ -523,8 +523,7 @@ public class MbmsDownloadSession implements AutoCloseable { * @param handler The {@link Handler} on which calls to {@code callback} should be enqueued on. */ public void registerStateCallback(@NonNull DownloadRequest request, @NonNull DownloadStateCallback callback, @NonNull Handler handler) { @NonNull DownloadStateCallback callback, @NonNull Handler handler) { IMbmsDownloadService downloadService = mService.get(); if (downloadService == null) { throw new IllegalStateException("Middleware not yet bound"); Loading @@ -534,7 +533,8 @@ public class MbmsDownloadSession implements AutoCloseable { new InternalDownloadStateCallback(callback, handler); try { int result = downloadService.registerStateCallback(request, internalCallback); int result = downloadService.registerStateCallback(request, internalCallback, callback.getCallbackFilterFlags()); if (result != MbmsErrors.SUCCESS) { if (result == MbmsErrors.DownloadErrors.ERROR_UNKNOWN_DOWNLOAD_REQUEST) { throw new IllegalArgumentException("Unknown download request."); Loading
telephony/java/android/telephony/mbms/DownloadStateCallback.java +69 −0 Original line number Diff line number Diff line Loading @@ -16,8 +16,12 @@ package android.telephony.mbms; import android.annotation.IntDef; import android.telephony.MbmsDownloadSession; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; /** * A optional listener class used by download clients to track progress. Apps should extend this * class and pass an instance into Loading @@ -29,6 +33,71 @@ import android.telephony.MbmsDownloadSession; */ public class DownloadStateCallback { /** * Bitmask flags used for filtering out callback methods. Used when constructing the * DownloadStateCallback as an optional parameter. * @hide */ @Retention(RetentionPolicy.SOURCE) @IntDef({ALL_UPDATES, PROGRESS_UPDATES, STATE_UPDATES}) public @interface FilterFlag {} /** * Receive all callbacks. * Default value. */ public static final int ALL_UPDATES = 0x00; /** * Receive callbacks for {@link #onProgressUpdated}. */ public static final int PROGRESS_UPDATES = 0x01; /** * Receive callbacks for {@link #onStateUpdated}. */ public static final int STATE_UPDATES = 0x02; private final int mCallbackFilterFlags; /** * Creates a DownloadStateCallback that will receive all callbacks. */ public DownloadStateCallback() { mCallbackFilterFlags = ALL_UPDATES; } /** * Creates a DownloadStateCallback that will only receive callbacks for the methods specified * via the filterFlags parameter. * @param filterFlags A bitmask of filter flags that will specify which callback this instance * is interested in. */ public DownloadStateCallback(int filterFlags) { mCallbackFilterFlags = filterFlags; } /** * Return the currently set filter flags. * @return An integer containing the bitmask of flags that this instance is interested in. * @hide */ public int getCallbackFilterFlags() { return mCallbackFilterFlags; } /** * Returns true if a filter flag is set for a particular callback method. If the flag is set, * the callback will be delivered to the listening process. * @param flag A filter flag specifying whether or not a callback method is registered to * receive callbacks. * @return true if registered to receive callbacks in the listening process, false if not. */ public final boolean isFilterFlagSet(@FilterFlag int flag) { if (mCallbackFilterFlags == ALL_UPDATES) { return true; } return (mCallbackFilterFlags & flag) > 0; } /** * Called when the middleware wants to report progress for a file in a {@link DownloadRequest}. * Loading
telephony/java/android/telephony/mbms/vendor/IMbmsDownloadService.aidl +2 −1 Original line number Diff line number Diff line Loading @@ -36,7 +36,8 @@ interface IMbmsDownloadService int download(in DownloadRequest downloadRequest); int registerStateCallback(in DownloadRequest downloadRequest, IDownloadStateCallback listener); int registerStateCallback(in DownloadRequest downloadRequest, IDownloadStateCallback listener, int flags); int unregisterStateCallback(in DownloadRequest downloadRequest, IDownloadStateCallback listener); Loading
telephony/java/android/telephony/mbms/vendor/MbmsDownloadServiceBase.java +46 −24 Original line number Diff line number Diff line Loading @@ -46,6 +46,47 @@ public class MbmsDownloadServiceBase extends IMbmsDownloadService.Stub { private final Map<IBinder, DownloadStateCallback> mDownloadCallbackBinderMap = new HashMap<>(); private final Map<IBinder, DeathRecipient> mDownloadCallbackDeathRecipients = new HashMap<>(); // Filters the DownloadStateCallbacks by its configuration from the app. private abstract static class FilteredDownloadStateCallback extends DownloadStateCallback { private final IDownloadStateCallback mCallback; public FilteredDownloadStateCallback(IDownloadStateCallback callback, int callbackFlags) { super(callbackFlags); mCallback = callback; } @Override public void onProgressUpdated(DownloadRequest request, FileInfo fileInfo, int currentDownloadSize, int fullDownloadSize, int currentDecodedSize, int fullDecodedSize) { if (!isFilterFlagSet(PROGRESS_UPDATES)) { return; } try { mCallback.onProgressUpdated(request, fileInfo, currentDownloadSize, fullDownloadSize, currentDecodedSize, fullDecodedSize); } catch (RemoteException e) { onRemoteException(e); } } @Override public void onStateUpdated(DownloadRequest request, FileInfo fileInfo, @MbmsDownloadSession.DownloadStatus int state) { if (!isFilterFlagSet(STATE_UPDATES)) { return; } try { mCallback.onStateUpdated(request, fileInfo, state); } catch (RemoteException e) { onRemoteException(e); } } protected abstract void onRemoteException(RemoteException e); } /** * Initialize the download service for this app and subId, registering the listener. * Loading Loading @@ -196,9 +237,8 @@ public class MbmsDownloadServiceBase extends IMbmsDownloadService.Stub { * @hide */ @Override public final int registerStateCallback( final DownloadRequest downloadRequest, final IDownloadStateCallback callback) throws RemoteException { public final int registerStateCallback(final DownloadRequest downloadRequest, final IDownloadStateCallback callback, int flags) throws RemoteException { final int uid = Binder.getCallingUid(); DeathRecipient deathRecipient = new DeathRecipient() { @Override Loading @@ -211,29 +251,11 @@ public class MbmsDownloadServiceBase extends IMbmsDownloadService.Stub { mDownloadCallbackDeathRecipients.put(callback.asBinder(), deathRecipient); callback.asBinder().linkToDeath(deathRecipient, 0); DownloadStateCallback exposedCallback = new DownloadStateCallback() { @Override public void onProgressUpdated(DownloadRequest request, FileInfo fileInfo, int currentDownloadSize, int fullDownloadSize, int currentDecodedSize, int fullDecodedSize) { try { callback.onProgressUpdated(request, fileInfo, currentDownloadSize, fullDownloadSize, currentDecodedSize, fullDecodedSize); } catch (RemoteException e) { onAppCallbackDied(uid, downloadRequest.getSubscriptionId()); } } DownloadStateCallback exposedCallback = new FilteredDownloadStateCallback(callback, flags) { @Override public void onStateUpdated(DownloadRequest request, FileInfo fileInfo, @MbmsDownloadSession.DownloadStatus int state) { try { callback.onStateUpdated(request, fileInfo, state); } catch (RemoteException e) { protected void onRemoteException(RemoteException e) { onAppCallbackDied(uid, downloadRequest.getSubscriptionId()); } } }; mDownloadCallbackBinderMap.put(callback.asBinder(), exposedCallback); Loading