OSDN Git Service

Make EMBMS adjustments for 08/04
authorHall Liu <hallliu@google.com>
Sat, 5 Aug 2017 01:41:56 +0000 (18:41 -0700)
committerHall Liu <hallliu@google.com>
Wed, 13 Sep 2017 20:19:18 +0000 (13:19 -0700)
* 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
telephony/java/android/telephony/MbmsDownloadManager.java
telephony/java/android/telephony/mbms/DownloadStateCallback.java [moved from telephony/java/android/telephony/mbms/DownloadProgressListener.java with 65% similarity]
telephony/java/android/telephony/mbms/IDownloadStateCallback.aidl [moved from telephony/java/android/telephony/mbms/IDownloadProgressListener.aidl with 91% similarity]
telephony/java/android/telephony/mbms/MbmsDownloadReceiver.java
telephony/java/android/telephony/mbms/vendor/IMbmsDownloadService.aidl
telephony/java/android/telephony/mbms/vendor/MbmsDownloadServiceBase.java
telephony/java/android/telephony/mbms/vendor/VendorUtils.java

index 19bbc5f..ac72dc6 100644 (file)
@@ -504,7 +504,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 \
index 608f415..d76fca5 100644 (file)
@@ -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
      */
 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, DownloadProgressListener)}
+ * {@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 DownloadProgressListener extends IDownloadProgressListener.Stub {
+public class DownloadStateCallback extends IDownloadStateCallback.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.
+     * 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
@@ -47,4 +49,18 @@ public class DownloadProgressListener extends IDownloadProgressListener.Stub {
             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) {
+    }
 }
@@ -23,7 +23,7 @@ import android.telephony.mbms.FileInfo;
  * The optional interface used by download clients to track progress.
  * @hide
  */
-interface IDownloadProgressListener
+interface IDownloadStateCallback
 {
     /**
      * Gives progress callbacks for a given DownloadRequest.  Includes a FileInfo
@@ -31,4 +31,6 @@ interface IDownloadProgressListener
      */
     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);
 }
index 0c9b35a..8745d8e 100644 (file)
@@ -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<UriPathPair> freshTempFiles =
-                generateFreshTempFiles(context, serviceInfo, fdCount);
+                generateFreshTempFiles(context, serviceId, fdCount);
         ArrayList<UriPathPair> 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<UriPathPair> generateFreshTempFiles(Context context,
-            FileServiceInfo serviceInfo,
+    private ArrayList<UriPathPair> 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<UriPathPair> generateUrisForPausedFiles(Context context,
-            FileServiceInfo serviceInfo, List<Uri> pausedFiles) {
+            String serviceId, List<Uri> pausedFiles) {
         if (pausedFiles == null) {
             return new ArrayList<>(0);
         }
         ArrayList<UriPathPair> 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<Uri> filesInUse =
                 intent.getParcelableArrayListExtra(VendorUtils.EXTRA_TEMP_FILES_IN_USE);
         File[] filesToDelete = tempFileDir.listFiles(new FileFilter() {
index dfcc5f7..f29499d 100755 (executable)
@@ -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<DownloadRequest> listPendingDownloads(int subscriptionId);
 
index b6ed889..0baa375 100644 (file)
@@ -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}.
index bcae782..a01e57d 100644 (file)
@@ -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