Modify sample apps for API adjustments

Change-Id: I5dbe66ca14753b9156547d9f1c73cef79f21c828
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 5a92165..150460a 100644
--- a/testapps/EmbmsServiceTestApp/src/com/android/phone/testapps/embmsmw/EmbmsSampleDownloadService.java
+++ b/testapps/EmbmsServiceTestApp/src/com/android/phone/testapps/embmsmw/EmbmsSampleDownloadService.java
@@ -72,12 +72,25 @@
             int packageUid = Binder.getCallingUid();
             String[] packageNames = getPackageManager().getPackagesForUid(packageUid);
             if (packageNames == null) {
-                throw new SecurityException("No matching packages found for your UID");
+                try {
+                    listener.error(
+                            MbmsException.InitializationErrors.ERROR_APP_PERMISSIONS_NOT_GRANTED,
+                            "No matching packages found for your UID");
+                } catch (RemoteException e) {
+                    // ignore
+                }
+                return;
             }
             boolean isUidAllowed = Arrays.stream(packageNames).anyMatch(ALLOWED_PACKAGES::contains);
             if (!isUidAllowed) {
-                throw new SecurityException("No packages for your UID are allowed to use this " +
-                        "service");
+                try {
+                    listener.error(
+                            MbmsException.InitializationErrors.ERROR_APP_PERMISSIONS_NOT_GRANTED,
+                            "No packages for your UID are allowed to use this service.");
+                } catch (RemoteException e) {
+                    // ignore
+                }
+                return;
             }
 
             // Do initialization with a bit of a delay to simulate work being done.
@@ -90,7 +103,8 @@
                     mAppReceivers.put(appKey, appReceiver);
                 } else {
                     try {
-                        listener.error(MbmsException.ERROR_ALREADY_INITIALIZED, "");
+                        listener.error(
+                                MbmsException.InitializationErrors.ERROR_DUPLICATE_INITIALIZE, "");
                     } catch (RemoteException e) {
                         // ignore, it was an error anyway
                     }
@@ -134,7 +148,7 @@
             checkInitialized(appKey);
 
             if (mActiveDownloadRequests.getOrDefault(appKey, Collections.emptySet()).size() > 0) {
-                return MbmsException.ERROR_CANNOT_CHANGE_TEMP_FILE_ROOT;
+                return MbmsException.DownloadErrors.ERROR_CANNOT_CHANGE_TEMP_FILE_ROOT;
             }
             mAppTempFileRoots.put(appKey, rootDirectoryPath);
             return MbmsException.SUCCESS;
@@ -157,7 +171,7 @@
             checkInitialized(appKey);
             if (!mActiveDownloadRequests.getOrDefault(
                     appKey, Collections.emptySet()).contains(downloadRequest)) {
-                return MbmsException.ERROR_UNKNOWN_DOWNLOAD_REQUEST;
+                return MbmsException.DownloadErrors.ERROR_UNKNOWN_DOWNLOAD_REQUEST;
             }
             mActiveDownloadRequests.get(appKey).remove(downloadRequest);
             return MbmsException.SUCCESS;
diff --git a/testapps/EmbmsServiceTestApp/src/com/android/phone/testapps/embmsmw/EmbmsTestStreamingService.java b/testapps/EmbmsServiceTestApp/src/com/android/phone/testapps/embmsmw/EmbmsTestStreamingService.java
index 583aca4..0373597 100644
--- a/testapps/EmbmsServiceTestApp/src/com/android/phone/testapps/embmsmw/EmbmsTestStreamingService.java
+++ b/testapps/EmbmsServiceTestApp/src/com/android/phone/testapps/embmsmw/EmbmsTestStreamingService.java
@@ -81,16 +81,29 @@
 
     private final IMbmsStreamingService.Stub mBinder = new MbmsStreamingServiceBase() {
         @Override
-        public int initialize(IMbmsStreamingManagerCallback listener, int subId) {
+        public void initialize(IMbmsStreamingManagerCallback listener, int subId) {
             int packageUid = Binder.getCallingUid();
             String[] packageNames = getPackageManager().getPackagesForUid(packageUid);
             if (packageNames == null) {
-                throw new SecurityException("No matching packages found for your UID");
+                try {
+                    listener.error(
+                            MbmsException.InitializationErrors.ERROR_APP_PERMISSIONS_NOT_GRANTED,
+                            "No matching packages found for your UID");
+                } catch (RemoteException e) {
+                    // ignore
+                }
+                return;
             }
             boolean isUidAllowed = Arrays.stream(packageNames).anyMatch(ALLOWED_PACKAGES::contains);
             if (!isUidAllowed) {
-                throw new SecurityException("No packages for your UID are allowed to use this " +
-                        "service");
+                try {
+                    listener.error(
+                            MbmsException.InitializationErrors.ERROR_APP_PERMISSIONS_NOT_GRANTED,
+                            "No packages for your UID are allowed to use this service.");
+                } catch (RemoteException e) {
+                    // ignore
+                }
+                return;
             }
 
             mHandler.postDelayed(() -> {
@@ -99,7 +112,8 @@
                     mAppCallbacks.put(appKey, listener);
                 } else {
                     try {
-                        listener.error(MbmsException.ERROR_ALREADY_INITIALIZED, "");
+                        listener.error(
+                                MbmsException.InitializationErrors.ERROR_DUPLICATE_INITIALIZE, "");
                     } catch (RemoteException e) {
                         // ignore, it was an error anyway
                     }
@@ -112,7 +126,6 @@
                     mAppCallbacks.remove(appKey);
                 }
             }, INITIALIZATION_DELAY);
-            return 0;
         }
 
         @Override
@@ -145,7 +158,7 @@
 
             if (StreamStateTracker.getStreamingState(appKey, serviceId) ==
                     StreamingService.STATE_STARTED) {
-                return MbmsException.ERROR_STREAM_ALREADY_STARTED;
+                return MbmsException.StreamingErrors.ERROR_DUPLICATE_START_STREAM;
             }
 
             mHandler.postDelayed(