Merge "Adjust testapps for download API changes"
am: 33aea1eaa2

Change-Id: Id355832afce78d3b5e0ff6f44386d73ef660f597
diff --git a/testapps/EmbmsServiceTestApp/src/com/android/phone/testapps/embmsmw/EmbmsSampleDownloadService.java b/testapps/EmbmsServiceTestApp/src/com/android/phone/testapps/embmsmw/EmbmsSampleDownloadService.java
index e7acf09..f73aec9 100644
--- a/testapps/EmbmsServiceTestApp/src/com/android/phone/testapps/embmsmw/EmbmsSampleDownloadService.java
+++ b/testapps/EmbmsServiceTestApp/src/com/android/phone/testapps/embmsmw/EmbmsSampleDownloadService.java
@@ -30,12 +30,11 @@
 import android.os.IBinder;
 import android.os.ParcelFileDescriptor;
 import android.os.RemoteException;
-import android.telephony.MbmsDownloadManager;
+import android.telephony.MbmsDownloadSession;
 import android.telephony.mbms.DownloadRequest;
-import android.telephony.mbms.DownloadStateCallback;
 import android.telephony.mbms.FileInfo;
 import android.telephony.mbms.FileServiceInfo;
-import android.telephony.mbms.MbmsDownloadManagerCallback;
+import android.telephony.mbms.MbmsDownloadSessionCallback;
 import android.telephony.mbms.MbmsException;
 import android.telephony.mbms.UriPathPair;
 import android.telephony.mbms.vendor.IMbmsDownloadService;
@@ -69,7 +68,7 @@
 
     private final IMbmsDownloadService mBinder = new MbmsDownloadServiceBase() {
         @Override
-        public int initialize(int subId, MbmsDownloadManagerCallback callback) {
+        public int initialize(int subId, MbmsDownloadSessionCallback callback) {
             int packageUid = Binder.getCallingUid();
             String[] packageNames = getPackageManager().getPackagesForUid(packageUid);
             if (packageNames == null) {
@@ -101,7 +100,7 @@
         }
 
         @Override
-        public int getFileServices(int subscriptionId,
+        public int requestUpdateFileServices(int subscriptionId,
                 List<String> serviceClasses) throws RemoteException {
             FrontendAppIdentifier appKey =
                     new FrontendAppIdentifier(Binder.getCallingUid(), subscriptionId);
@@ -112,7 +111,7 @@
                     .getFileServicesForClasses(serviceClasses);
 
             mHandler.postDelayed(() -> {
-                MbmsDownloadManagerCallback appCallback = mAppCallbacks.get(appKey);
+                MbmsDownloadSessionCallback appCallback = mAppCallbacks.get(appKey);
                 appCallback.onFileServicesUpdated(serviceInfos);
             }, SEND_FILE_SERVICE_INFO_DELAY);
             return MbmsException.SUCCESS;
@@ -133,7 +132,7 @@
         }
 
         @Override
-        public int download(DownloadRequest downloadRequest, DownloadStateCallback callback) {
+        public int download(DownloadRequest downloadRequest) {
             FrontendAppIdentifier appKey = new FrontendAppIdentifier(
                     Binder.getCallingUid(), downloadRequest.getSubscriptionId());
             checkInitialized(appKey);
@@ -167,7 +166,7 @@
 
     private static EmbmsSampleDownloadService sInstance = null;
 
-    private final Map<FrontendAppIdentifier, MbmsDownloadManagerCallback> mAppCallbacks =
+    private final Map<FrontendAppIdentifier, MbmsDownloadSessionCallback> mAppCallbacks =
             new HashMap<>();
     private final Map<FrontendAppIdentifier, ComponentName> mAppReceivers = new HashMap<>();
     private final Map<FrontendAppIdentifier, String> mAppTempFileRoots = new HashMap<>();
@@ -323,7 +322,7 @@
 
     private void downloadSingleFile(FrontendAppIdentifier appKey, DownloadRequest request,
             UriPathPair tempFile, FileInfo fileToDownload) {
-        int result = MbmsDownloadManager.RESULT_SUCCESSFUL;
+        int result = MbmsDownloadSession.RESULT_SUCCESSFUL;
         try {
             // Get the ParcelFileDescriptor for the single temp file we requested
             ParcelFileDescriptor tempFileFd = getContentResolver().openFileDescriptor(
@@ -345,7 +344,7 @@
             destinationStream.write(imageBuffer);
             destinationStream.flush();
         } catch (IOException e) {
-            result = MbmsDownloadManager.RESULT_CANCELLED;
+            result = MbmsDownloadSession.RESULT_CANCELLED;
         }
 
         // Take a round-trip through the download request serialization to exercise it
@@ -361,14 +360,14 @@
         downloadResultIntent.putExtra(VendorUtils.EXTRA_REQUEST, request1);
         downloadResultIntent.putExtra(VendorUtils.EXTRA_FINAL_URI,
                 tempFile.getFilePathUri());
-        downloadResultIntent.putExtra(MbmsDownloadManager.EXTRA_MBMS_FILE_INFO, fileToDownload);
+        downloadResultIntent.putExtra(MbmsDownloadSession.EXTRA_MBMS_FILE_INFO, fileToDownload);
         downloadResultIntent.putExtra(VendorUtils.EXTRA_TEMP_FILE_ROOT,
                 mAppTempFileRoots.get(appKey));
         ArrayList<Uri> tempFileList = new ArrayList<>(1);
         tempFileList.add(tempFile.getFilePathUri());
         downloadResultIntent.getExtras().putParcelableArrayList(
                 VendorUtils.EXTRA_TEMP_LIST, tempFileList);
-        downloadResultIntent.putExtra(MbmsDownloadManager.EXTRA_MBMS_DOWNLOAD_RESULT, result);
+        downloadResultIntent.putExtra(MbmsDownloadSession.EXTRA_MBMS_DOWNLOAD_RESULT, result);
         downloadResultIntent.setComponent(mAppReceivers.get(appKey));
 
         sendOrderedBroadcast(downloadResultIntent,
diff --git a/testapps/EmbmsTestDownloadApp/src/com/android/phone/testapps/embmsdownload/DownloadCompletionReceiver.java b/testapps/EmbmsTestDownloadApp/src/com/android/phone/testapps/embmsdownload/DownloadCompletionReceiver.java
index 0ecdb11..e434e9a 100644
--- a/testapps/EmbmsTestDownloadApp/src/com/android/phone/testapps/embmsdownload/DownloadCompletionReceiver.java
+++ b/testapps/EmbmsTestDownloadApp/src/com/android/phone/testapps/embmsdownload/DownloadCompletionReceiver.java
@@ -20,19 +20,19 @@
 import android.content.Context;
 import android.content.Intent;
 import android.net.Uri;
-import android.telephony.MbmsDownloadManager;
+import android.telephony.MbmsDownloadSession;
 
 public class DownloadCompletionReceiver extends BroadcastReceiver {
     @Override
     public void onReceive(Context context, Intent intent) {
         if (EmbmsTestDownloadApp.DOWNLOAD_DONE_ACTION.equals(intent.getAction())) {
-            int result = intent.getIntExtra(MbmsDownloadManager.EXTRA_MBMS_DOWNLOAD_RESULT,
-                    MbmsDownloadManager.RESULT_CANCELLED);
-            if (result != MbmsDownloadManager.RESULT_SUCCESSFUL) {
+            int result = intent.getIntExtra(MbmsDownloadSession.EXTRA_MBMS_DOWNLOAD_RESULT,
+                    MbmsDownloadSession.RESULT_CANCELLED);
+            if (result != MbmsDownloadSession.RESULT_SUCCESSFUL) {
                 EmbmsTestDownloadApp.getInstance().onDownloadFailed(result);
             }
             Uri completedFile = intent.getParcelableExtra(
-                    MbmsDownloadManager.EXTRA_MBMS_COMPLETED_FILE_URI);
+                    MbmsDownloadSession.EXTRA_MBMS_COMPLETED_FILE_URI);
             EmbmsTestDownloadApp.getInstance().onDownloadDone(completedFile);
         }
     }
diff --git a/testapps/EmbmsTestDownloadApp/src/com/android/phone/testapps/embmsdownload/EmbmsTestDownloadApp.java b/testapps/EmbmsTestDownloadApp/src/com/android/phone/testapps/embmsdownload/EmbmsTestDownloadApp.java
index f6dbe14..9611cca 100644
--- a/testapps/EmbmsTestDownloadApp/src/com/android/phone/testapps/embmsdownload/EmbmsTestDownloadApp.java
+++ b/testapps/EmbmsTestDownloadApp/src/com/android/phone/testapps/embmsdownload/EmbmsTestDownloadApp.java
@@ -25,12 +25,11 @@
 import android.os.HandlerThread;
 import android.support.v7.widget.LinearLayoutManager;
 import android.support.v7.widget.RecyclerView;
-import android.telephony.MbmsDownloadManager;
+import android.telephony.MbmsDownloadSession;
 import android.telephony.SubscriptionManager;
 import android.telephony.mbms.DownloadRequest;
 import android.telephony.mbms.FileServiceInfo;
-import android.telephony.mbms.MbmsDownloadManagerCallback;
-import android.telephony.mbms.MbmsException;
+import android.telephony.mbms.MbmsDownloadSessionCallback;
 import android.util.Log;
 import android.view.View;
 import android.view.ViewGroup;
@@ -108,7 +107,7 @@
         public View getView(int position, View convertView, ViewGroup parent) {
             FileServiceInfo info = getItem(position);
             TextView result = new TextView(EmbmsTestDownloadApp.this);
-            result.setText(info.getNames().get(info.getLocales().get(0)));
+            result.setText(info.getNameForLocale(info.getLocales().get(0)));
             return result;
         }
 
@@ -117,7 +116,7 @@
             FileServiceInfo info = getItem(position);
             TextView result = new TextView(EmbmsTestDownloadApp.this);
             String text = "name="
-                    + info.getNames().get(info.getLocales().get(0))
+                    + info.getNameForLocale(info.getLocales().get(0))
                     + ", "
                     + "numFiles="
                     + info.getFiles().size();
@@ -153,7 +152,7 @@
     }
 
 
-    private MbmsDownloadManagerCallback mCallback = new MbmsDownloadManagerCallback() {
+    private MbmsDownloadSessionCallback mCallback = new MbmsDownloadSessionCallback() {
         @Override
         public void onError(int errorCode, String message) {
             runOnUiThread(() -> Toast.makeText(EmbmsTestDownloadApp.this,
@@ -176,7 +175,7 @@
         }
     };
 
-    private MbmsDownloadManager mDownloadManager;
+    private MbmsDownloadSession mDownloadManager;
     private Handler mHandler;
     private HandlerThread mHandlerThread;
     private FileServiceInfoAdapter mFileServiceInfoAdapter;
@@ -203,12 +202,7 @@
 
         Button bindButton = (Button) findViewById(R.id.bind_button);
         bindButton.setOnClickListener((view) -> {
-            try {
-                mDownloadManager = MbmsDownloadManager.create(this, mCallback);
-            } catch (MbmsException e) {
-                Toast.makeText(EmbmsTestDownloadApp.this,
-                        "caught MbmsException: " + e.getErrorCode(), Toast.LENGTH_SHORT).show();
-            }
+            mDownloadManager = MbmsDownloadSession.create(this, mCallback, mHandler);
         });
 
         Button setTempFileRootButton = (Button) findViewById(R.id.set_temp_root_button);
@@ -216,24 +210,14 @@
             File downloadDir = new File(EmbmsTestDownloadApp.this.getFilesDir(),
                     CUSTOM_EMBMS_TEMP_FILE_LOCATION);
             downloadDir.mkdirs();
-            try {
-                mDownloadManager.setTempFileRootDirectory(downloadDir);
-                Toast.makeText(EmbmsTestDownloadApp.this,
-                        "temp file root set to " + downloadDir, Toast.LENGTH_SHORT).show();
-            } catch (MbmsException e) {
-                Toast.makeText(EmbmsTestDownloadApp.this,
-                        "caught MbmsException: " + e.getErrorCode(), Toast.LENGTH_SHORT).show();
-            }
+            mDownloadManager.setTempFileRootDirectory(downloadDir);
+            Toast.makeText(EmbmsTestDownloadApp.this,
+                    "temp file root set to " + downloadDir, Toast.LENGTH_SHORT).show();
         });
 
         Button getFileServicesButton = (Button) findViewById(R.id.get_file_services_button);
         getFileServicesButton.setOnClickListener((view) -> mHandler.post(() -> {
-            try {
-                mDownloadManager.getFileServices(Collections.singletonList("Class1"));
-            } catch (MbmsException e) {
-                runOnUiThread(() -> Toast.makeText(EmbmsTestDownloadApp.this,
-                        "caught MbmsException: " + e.getErrorCode(), Toast.LENGTH_SHORT).show());
-            }
+            mDownloadManager.requestUpdateFileServices(Collections.singletonList("Class1"));
         }));
 
         final Spinner serviceSelector = (Spinner) findViewById(R.id.available_file_services);
@@ -286,15 +270,10 @@
                         "No download service bound", Toast.LENGTH_SHORT).show();
                 return;
             }
-            try {
-                DownloadRequest request =
-                        (DownloadRequest) downloadRequestSpinner.getSelectedItem();
-                mDownloadManager.cancelDownload(request);
-                mDownloadRequestAdapter.remove(request);
-            } catch (MbmsException e) {
-                runOnUiThread(() -> Toast.makeText(EmbmsTestDownloadApp.this,
-                        "caught MbmsException: " + e.getErrorCode(), Toast.LENGTH_SHORT).show());
-            }
+            DownloadRequest request =
+                    (DownloadRequest) downloadRequestSpinner.getSelectedItem();
+            mDownloadManager.cancelDownload(request);
+            mDownloadRequestAdapter.remove(request);
         });
     }
 
@@ -361,13 +340,8 @@
                 .setSubscriptionId(SubscriptionManager.getDefaultSubscriptionId())
                 .build();
 
-        try {
-            mDownloadManager.download(request, null, null);
-            mDownloadRequestAdapter.add(request);
-        } catch (MbmsException e) {
-            Toast.makeText(EmbmsTestDownloadApp.this,
-                    "caught MbmsException: " + e.getErrorCode(), Toast.LENGTH_SHORT).show();
-        }
+        mDownloadManager.download(request);
+        mDownloadRequestAdapter.add(request);
     }
 
     private static void clearDirectory(File directory) {