From 571293ad96eae0a10d61fa2bd9e78f8cbb78803e Mon Sep 17 00:00:00 2001 From: Hall Liu Date: Fri, 4 Aug 2017 18:41:56 -0700 Subject: Make EMBMS adjustments for 08/04 * Add a download state callback to the callback formerly for progress * Rename EXTRA_SERVICE_INFO to EXTRA_SERVICE_ID, and specify that it should be a String rather than a ServiceInfo * Add documentation to clarify that the progress/state callback may be null Bug: 30981736 Test: manual Change-Id: Ie1ec99868f5b09a270b500dc97abeb9f819cfa56 --- Android.mk | 2 +- .../android/telephony/MbmsDownloadManager.java | 20 +++---- .../telephony/mbms/DownloadProgressListener.java | 50 ---------------- .../telephony/mbms/DownloadStateCallback.java | 66 ++++++++++++++++++++++ .../telephony/mbms/IDownloadProgressListener.aidl | 34 ----------- .../telephony/mbms/IDownloadStateCallback.aidl | 36 ++++++++++++ .../telephony/mbms/MbmsDownloadReceiver.java | 35 +++++------- .../mbms/vendor/IMbmsDownloadService.aidl | 4 +- .../mbms/vendor/MbmsDownloadServiceBase.java | 16 +++--- .../android/telephony/mbms/vendor/VendorUtils.java | 8 +-- 10 files changed, 140 insertions(+), 131 deletions(-) delete mode 100644 telephony/java/android/telephony/mbms/DownloadProgressListener.java create mode 100644 telephony/java/android/telephony/mbms/DownloadStateCallback.java delete mode 100755 telephony/java/android/telephony/mbms/IDownloadProgressListener.aidl create mode 100755 telephony/java/android/telephony/mbms/IDownloadStateCallback.aidl diff --git a/Android.mk b/Android.mk index 0e6642d70a28..bd32b55dfd51 100644 --- a/Android.mk +++ b/Android.mk @@ -488,7 +488,7 @@ LOCAL_SRC_FILES += \ telecomm/java/com/android/internal/telecom/RemoteServiceCallback.aidl \ telephony/java/android/telephony/mbms/IMbmsDownloadManagerCallback.aidl \ telephony/java/android/telephony/mbms/IMbmsStreamingManagerCallback.aidl \ - telephony/java/android/telephony/mbms/IDownloadProgressListener.aidl \ + telephony/java/android/telephony/mbms/IDownloadStateCallback.aidl \ telephony/java/android/telephony/mbms/IStreamingServiceCallback.aidl \ telephony/java/android/telephony/mbms/vendor/IMbmsDownloadService.aidl \ telephony/java/android/telephony/mbms/vendor/IMbmsStreamingService.aidl \ diff --git a/telephony/java/android/telephony/MbmsDownloadManager.java b/telephony/java/android/telephony/MbmsDownloadManager.java index 608f415b7a56..d76fca5f83ab 100644 --- a/telephony/java/android/telephony/MbmsDownloadManager.java +++ b/telephony/java/android/telephony/MbmsDownloadManager.java @@ -29,7 +29,7 @@ import android.content.SharedPreferences; import android.net.Uri; import android.os.IBinder; import android.os.RemoteException; -import android.telephony.mbms.DownloadProgressListener; +import android.telephony.mbms.DownloadStateCallback; import android.telephony.mbms.FileInfo; import android.telephony.mbms.DownloadRequest; import android.telephony.mbms.MbmsDownloadManagerCallback; @@ -99,7 +99,7 @@ public class MbmsDownloadManager { /** * The default directory name for all MBMS temp files. If you call - * {@link #download(DownloadRequest, DownloadProgressListener)} without first calling + * {@link #download(DownloadRequest, DownloadStateCallback)} without first calling * {@link #setTempFileRootDirectory(File)}, this directory will be created for you under the * path returned by {@link Context#getFilesDir()}. */ @@ -329,7 +329,7 @@ public class MbmsDownloadManager { * local instance of {@link android.content.SharedPreferences} and by the middleware. * * If this method is not called at least once before calling - * {@link #download(DownloadRequest, DownloadProgressListener)}, the framework + * {@link #download(DownloadRequest, DownloadStateCallback)}, the framework * will default to a directory formed by the concatenation of the app's files directory and * {@link MbmsDownloadManager#DEFAULT_TOP_LEVEL_TEMP_DIRECTORY}. * @@ -380,7 +380,7 @@ public class MbmsDownloadManager { /** * Retrieves the currently configured temp file root directory. Returns the file that was * configured via {@link #setTempFileRootDirectory(File)} or the default directory - * {@link #download(DownloadRequest, DownloadProgressListener)} was called without ever setting + * {@link #download(DownloadRequest, DownloadStateCallback)} was called without ever setting * the temp file root. If neither method has been called since the last time the app's shared * preferences were reset, returns null. * @@ -400,11 +400,6 @@ public class MbmsDownloadManager { /** * Requests a download of a file that is available via multicast. * - * downloadListener is an optional callback object which can be used to get progress reports - * of a currently occuring download. Note this can only run while the calling app - * is running, so future downloads will simply result in resultIntents being sent - * for completed or errored-out downloads. A NULL indicates no callbacks are needed. - * * May throw an {@link IllegalArgumentException} * * If {@link #setTempFileRootDirectory(File)} has not called after the app has been installed, @@ -416,9 +411,10 @@ public class MbmsDownloadManager { * * @param request The request that specifies what should be downloaded * @param progressListener Optional listener that will be provided progress updates - * if the app is running. + * if the app is running. If {@code null}, no callbacks will be + * provided. */ - public void download(DownloadRequest request, DownloadProgressListener progressListener) + public void download(DownloadRequest request, @Nullable DownloadStateCallback progressListener) throws MbmsException { IMbmsDownloadService downloadService = mService.get(); if (downloadService == null) { @@ -448,7 +444,7 @@ public class MbmsDownloadManager { /** * Returns a list of pending {@link DownloadRequest}s that originated from this application. * A pending request is one that was issued via - * {@link #download(DownloadRequest, DownloadProgressListener)} but not cancelled through + * {@link #download(DownloadRequest, DownloadStateCallback)} but not cancelled through * {@link #cancelDownload(DownloadRequest)}. * @return A list, possibly empty, of {@link DownloadRequest}s */ diff --git a/telephony/java/android/telephony/mbms/DownloadProgressListener.java b/telephony/java/android/telephony/mbms/DownloadProgressListener.java deleted file mode 100644 index 729c8fe8965e..000000000000 --- a/telephony/java/android/telephony/mbms/DownloadProgressListener.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.telephony.mbms; - -import android.os.RemoteException; - -/** - * A optional listener class used by download clients to track progress. Apps should extend this - * class and pass an instance into - * {@link android.telephony.MbmsDownloadManager#download(DownloadRequest, DownloadProgressListener)} - * @hide - */ -public class DownloadProgressListener extends IDownloadProgressListener.Stub { - /** - * Gives process callbacks for a given DownloadRequest. - * This is optionally specified when requesting a download and - * only lives while the app is running - it's unlikely to be useful for - * downloads far in the future. - * - * @param request a {@link DownloadRequest}, indicating which download is being referenced. - * @param fileInfo a {@link FileInfo} specifying the file to report progress on. Note that - * the request may result in many files being downloaded and the client - * may not have been able to get a list of them in advance. - * @param currentDownloadSize is the current amount downloaded. - * @param fullDownloadSize is the total number of bytes that make up the downloaded content. - * This may be different from the decoded final size, but is useful in gauging download - * progress. - * @param currentDecodedSize is the number of bytes that have been decoded. - * @param fullDecodedSize is the total number of bytes that make up the final decoded content. - */ - @Override - public void progress(DownloadRequest request, FileInfo fileInfo, - int currentDownloadSize, int fullDownloadSize, - int currentDecodedSize, int fullDecodedSize) throws RemoteException { - } -} diff --git a/telephony/java/android/telephony/mbms/DownloadStateCallback.java b/telephony/java/android/telephony/mbms/DownloadStateCallback.java new file mode 100644 index 000000000000..a144f3e89b11 --- /dev/null +++ b/telephony/java/android/telephony/mbms/DownloadStateCallback.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.telephony.mbms; + +import android.os.RemoteException; +import android.telephony.MbmsDownloadManager; + +/** + * A optional listener class used by download clients to track progress. Apps should extend this + * class and pass an instance into + * {@link android.telephony.MbmsDownloadManager#download(DownloadRequest, DownloadStateCallback)} + * + * This is optionally specified when requesting a download and will only be called while the app + * is running. + * @hide + */ +public class DownloadStateCallback extends IDownloadStateCallback.Stub { + + /** + * Called when the middleware wants to report progress for a file in a {@link DownloadRequest}. + * + * @param request a {@link DownloadRequest}, indicating which download is being referenced. + * @param fileInfo a {@link FileInfo} specifying the file to report progress on. Note that + * the request may result in many files being downloaded and the client + * may not have been able to get a list of them in advance. + * @param currentDownloadSize is the current amount downloaded. + * @param fullDownloadSize is the total number of bytes that make up the downloaded content. + * This may be different from the decoded final size, but is useful in gauging download + * progress. + * @param currentDecodedSize is the number of bytes that have been decoded. + * @param fullDecodedSize is the total number of bytes that make up the final decoded content. + */ + @Override + public void progress(DownloadRequest request, FileInfo fileInfo, + int currentDownloadSize, int fullDownloadSize, + int currentDecodedSize, int fullDecodedSize) throws RemoteException { + } + + /** + * Gives download state callbacks for a file in a {@link DownloadRequest}. + * + * @param request a {@link DownloadRequest}, indicating which download is being referenced. + * @param fileInfo a {@link FileInfo} specifying the file to report progress on. Note that + * the request may result in many files being downloaded and the client + * may not have been able to get a list of them in advance. + * @param state The current state of the download. + */ + @Override + public void state(DownloadRequest request, FileInfo fileInfo, + @MbmsDownloadManager.DownloadStatus int state) { + } +} diff --git a/telephony/java/android/telephony/mbms/IDownloadProgressListener.aidl b/telephony/java/android/telephony/mbms/IDownloadProgressListener.aidl deleted file mode 100755 index bb9dc6cfea9f..000000000000 --- a/telephony/java/android/telephony/mbms/IDownloadProgressListener.aidl +++ /dev/null @@ -1,34 +0,0 @@ -/* -** Copyright 2017, The Android Open Source Project -** -** Licensed under the Apache License, Version 2.0 (the "License"); -** you may not use this file except in compliance with the License. -** You may obtain a copy of the License at -** -** http://www.apache.org/licenses/LICENSE-2.0 -** -** Unless required by applicable law or agreed to in writing, software -** distributed under the License is distributed on an "AS IS" BASIS, -** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -** See the License for the specific language governing permissions and -** limitations under the License. -*/ - -package android.telephony.mbms; - -import android.telephony.mbms.DownloadRequest; -import android.telephony.mbms.FileInfo; - -/** - * The optional interface used by download clients to track progress. - * @hide - */ -interface IDownloadProgressListener -{ - /** - * Gives progress callbacks for a given DownloadRequest. Includes a FileInfo - * as the list of files may not have been known at request-time. - */ - void progress(in DownloadRequest request, in FileInfo fileInfo, int currentDownloadSize, - int fullDownloadSize, int currentDecodedSize, int fullDecodedSize); -} diff --git a/telephony/java/android/telephony/mbms/IDownloadStateCallback.aidl b/telephony/java/android/telephony/mbms/IDownloadStateCallback.aidl new file mode 100755 index 000000000000..d62247be127d --- /dev/null +++ b/telephony/java/android/telephony/mbms/IDownloadStateCallback.aidl @@ -0,0 +1,36 @@ +/* +** Copyright 2017, The Android Open Source Project +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ + +package android.telephony.mbms; + +import android.telephony.mbms.DownloadRequest; +import android.telephony.mbms.FileInfo; + +/** + * The optional interface used by download clients to track progress. + * @hide + */ +interface IDownloadStateCallback +{ + /** + * Gives progress callbacks for a given DownloadRequest. Includes a FileInfo + * as the list of files may not have been known at request-time. + */ + void progress(in DownloadRequest request, in FileInfo fileInfo, int currentDownloadSize, + int fullDownloadSize, int currentDecodedSize, int fullDecodedSize); + + void state(in DownloadRequest request, in FileInfo fileInfo, int state); +} diff --git a/telephony/java/android/telephony/mbms/MbmsDownloadReceiver.java b/telephony/java/android/telephony/mbms/MbmsDownloadReceiver.java index 0c9b35abad2b..8745d8e403b4 100644 --- a/telephony/java/android/telephony/mbms/MbmsDownloadReceiver.java +++ b/telephony/java/android/telephony/mbms/MbmsDownloadReceiver.java @@ -182,8 +182,8 @@ public class MbmsDownloadReceiver extends BroadcastReceiver { return false; } } else if (VendorUtils.ACTION_FILE_DESCRIPTOR_REQUEST.equals(intent.getAction())) { - if (!intent.hasExtra(VendorUtils.EXTRA_SERVICE_INFO)) { - Log.w(LOG_TAG, "Temp file request did not include the associated service info." + + if (!intent.hasExtra(VendorUtils.EXTRA_SERVICE_ID)) { + Log.w(LOG_TAG, "Temp file request did not include the associated service id." + " Ignoring."); return false; } @@ -192,8 +192,8 @@ public class MbmsDownloadReceiver extends BroadcastReceiver { return false; } } else if (VendorUtils.ACTION_CLEANUP.equals(intent.getAction())) { - if (!intent.hasExtra(VendorUtils.EXTRA_SERVICE_INFO)) { - Log.w(LOG_TAG, "Cleanup request did not include the associated service info." + + if (!intent.hasExtra(VendorUtils.EXTRA_SERVICE_ID)) { + Log.w(LOG_TAG, "Cleanup request did not include the associated service id." + " Ignoring."); return false; } @@ -270,10 +270,9 @@ public class MbmsDownloadReceiver extends BroadcastReceiver { } private void generateTempFiles(Context context, Intent intent) { - FileServiceInfo serviceInfo = - intent.getParcelableExtra(VendorUtils.EXTRA_SERVICE_INFO); - if (serviceInfo == null) { - Log.w(LOG_TAG, "Temp file request did not include the associated service info. " + + String serviceId = intent.getStringExtra(VendorUtils.EXTRA_SERVICE_ID); + if (serviceId == null) { + Log.w(LOG_TAG, "Temp file request did not include the associated service id. " + "Ignoring."); setResultCode(RESULT_MALFORMED_INTENT); return; @@ -289,9 +288,9 @@ public class MbmsDownloadReceiver extends BroadcastReceiver { } ArrayList freshTempFiles = - generateFreshTempFiles(context, serviceInfo, fdCount); + generateFreshTempFiles(context, serviceId, fdCount); ArrayList pausedFiles = - generateUrisForPausedFiles(context, serviceInfo, pausedList); + generateUrisForPausedFiles(context, serviceId, pausedList); Bundle result = new Bundle(); result.putParcelableArrayList(VendorUtils.EXTRA_FREE_URI_LIST, freshTempFiles); @@ -300,11 +299,9 @@ public class MbmsDownloadReceiver extends BroadcastReceiver { setResultExtras(result); } - private ArrayList generateFreshTempFiles(Context context, - FileServiceInfo serviceInfo, + private ArrayList generateFreshTempFiles(Context context, String serviceId, int freshFdCount) { - File tempFileDir = MbmsUtils.getEmbmsTempFileDirForService(context, - serviceInfo.getServiceId()); + File tempFileDir = MbmsUtils.getEmbmsTempFileDirForService(context, serviceId); if (!tempFileDir.exists()) { tempFileDir.mkdirs(); } @@ -348,14 +345,14 @@ public class MbmsDownloadReceiver extends BroadcastReceiver { } private ArrayList generateUrisForPausedFiles(Context context, - FileServiceInfo serviceInfo, List pausedFiles) { + String serviceId, List pausedFiles) { if (pausedFiles == null) { return new ArrayList<>(0); } ArrayList result = new ArrayList<>(pausedFiles.size()); for (Uri fileUri : pausedFiles) { - if (!verifyTempFilePath(context, serviceInfo.getServiceId(), fileUri)) { + if (!verifyTempFilePath(context, serviceId, fileUri)) { Log.w(LOG_TAG, "Supplied file " + fileUri + " is not a valid temp file to resume"); setResultCode(RESULT_TEMP_FILE_GENERATION_ERROR); continue; @@ -377,10 +374,8 @@ public class MbmsDownloadReceiver extends BroadcastReceiver { } private void cleanupTempFiles(Context context, Intent intent) { - FileServiceInfo serviceInfo = - intent.getParcelableExtra(VendorUtils.EXTRA_SERVICE_INFO); - File tempFileDir = MbmsUtils.getEmbmsTempFileDirForService(context, - serviceInfo.getServiceId()); + String serviceId = intent.getStringExtra(VendorUtils.EXTRA_SERVICE_ID); + File tempFileDir = MbmsUtils.getEmbmsTempFileDirForService(context, serviceId); final List filesInUse = intent.getParcelableArrayListExtra(VendorUtils.EXTRA_TEMP_FILES_IN_USE); File[] filesToDelete = tempFileDir.listFiles(new FileFilter() { diff --git a/telephony/java/android/telephony/mbms/vendor/IMbmsDownloadService.aidl b/telephony/java/android/telephony/mbms/vendor/IMbmsDownloadService.aidl index dfcc5f7c8793..f29499d9cb31 100755 --- a/telephony/java/android/telephony/mbms/vendor/IMbmsDownloadService.aidl +++ b/telephony/java/android/telephony/mbms/vendor/IMbmsDownloadService.aidl @@ -21,7 +21,7 @@ import android.net.Uri; import android.telephony.mbms.DownloadRequest; import android.telephony.mbms.FileInfo; import android.telephony.mbms.IMbmsDownloadManagerCallback; -import android.telephony.mbms.IDownloadProgressListener; +import android.telephony.mbms.IDownloadStateCallback; /** * @hide @@ -34,7 +34,7 @@ interface IMbmsDownloadService int setTempFileRootDirectory(int subId, String rootDirectoryPath); - int download(in DownloadRequest downloadRequest, IDownloadProgressListener listener); + int download(in DownloadRequest downloadRequest, IDownloadStateCallback listener); List listPendingDownloads(int subscriptionId); diff --git a/telephony/java/android/telephony/mbms/vendor/MbmsDownloadServiceBase.java b/telephony/java/android/telephony/mbms/vendor/MbmsDownloadServiceBase.java index b6ed889d69f1..0baa37564966 100644 --- a/telephony/java/android/telephony/mbms/vendor/MbmsDownloadServiceBase.java +++ b/telephony/java/android/telephony/mbms/vendor/MbmsDownloadServiceBase.java @@ -20,11 +20,11 @@ import android.annotation.NonNull; import android.annotation.SystemApi; import android.content.Intent; import android.os.RemoteException; -import android.telephony.mbms.DownloadProgressListener; +import android.telephony.mbms.DownloadStateCallback; import android.telephony.mbms.DownloadRequest; import android.telephony.mbms.FileInfo; import android.telephony.mbms.FileServiceInfo; -import android.telephony.mbms.IDownloadProgressListener; +import android.telephony.mbms.IDownloadStateCallback; import android.telephony.mbms.IMbmsDownloadManagerCallback; import android.telephony.mbms.MbmsDownloadManagerCallback; import android.telephony.mbms.MbmsException; @@ -134,12 +134,12 @@ public class MbmsDownloadServiceBase extends IMbmsDownloadService.Stub { * this is not the case, an {@link IllegalStateException} may be thrown. * * @param downloadRequest An object describing the set of files to be downloaded. - * @param listener A listener through which the middleware can provide progress updates to + * @param callback A callback through which the middleware can provide progress updates to * the app while both are still running. * @return Any error from {@link android.telephony.mbms.MbmsException.GeneralErrors} * or {@link MbmsException#SUCCESS} */ - public int download(DownloadRequest downloadRequest, DownloadProgressListener listener) { + public int download(DownloadRequest downloadRequest, DownloadStateCallback callback) { return 0; } @@ -148,14 +148,14 @@ public class MbmsDownloadServiceBase extends IMbmsDownloadService.Stub { * @hide */ @Override - public final int download(DownloadRequest downloadRequest, IDownloadProgressListener listener) + public final int download(DownloadRequest downloadRequest, IDownloadStateCallback callback) throws RemoteException { - return download(downloadRequest, new DownloadProgressListener() { + return download(downloadRequest, new DownloadStateCallback() { @Override public void progress(DownloadRequest request, FileInfo fileInfo, int currentDownloadSize, int fullDownloadSize, int currentDecodedSize, int fullDecodedSize) throws RemoteException { - listener.progress(request, fileInfo, currentDownloadSize, fullDownloadSize, + callback.progress(request, fileInfo, currentDownloadSize, fullDownloadSize, currentDecodedSize, fullDecodedSize); } }); @@ -165,7 +165,7 @@ public class MbmsDownloadServiceBase extends IMbmsDownloadService.Stub { /** * Returns a list of pending {@link DownloadRequest}s that originated from the calling * application, identified by its uid. A pending request is one that was issued via - * {@link #download(DownloadRequest, IDownloadProgressListener)} but not cancelled through + * {@link #download(DownloadRequest, DownloadStateCallback)} but not cancelled through * {@link #cancelDownload(DownloadRequest)}. * The middleware must return a non-null result synchronously or throw an exception * inheriting from {@link RuntimeException}. diff --git a/telephony/java/android/telephony/mbms/vendor/VendorUtils.java b/telephony/java/android/telephony/mbms/vendor/VendorUtils.java index bcae7822b475..a01e57dfdda1 100644 --- a/telephony/java/android/telephony/mbms/vendor/VendorUtils.java +++ b/telephony/java/android/telephony/mbms/vendor/VendorUtils.java @@ -52,7 +52,7 @@ public class VendorUtils { * The MBMS middleware should send this when it wishes to request {@code content://} URIs to * serve as temp files for downloads or when it wishes to resume paused downloads. Mandatory * extras are - * {@link #EXTRA_REQUEST} + * {@link #EXTRA_SERVICE_ID} * * Optional extras are * {@link #EXTRA_FD_COUNT} (0 if not present) @@ -133,12 +133,12 @@ public class VendorUtils { public static final String EXTRA_FINAL_URI = "android.telephony.mbms.extra.FINAL_URI"; /** - * Extra containing an instance of {@link android.telephony.mbms.ServiceInfo}, used by + * Extra containing a String representing a service ID, used by * file-descriptor requests and cleanup requests to specify which service they want to * request temp files or clean up temp files for, respectively. */ - public static final String EXTRA_SERVICE_INFO = - "android.telephony.mbms.extra.SERVICE_INFO"; + public static final String EXTRA_SERVICE_ID = + "android.telephony.mbms.extra.SERVICE_ID"; /** * Retrieves the {@link ComponentName} for the {@link android.content.BroadcastReceiver} that -- cgit v1.2.3-59-g8ed1b