Merge "Make changes to MBMS Streaming APIs per recommendations"

am: 1bbf287859

Change-Id: I76662fd9822dcde781cdecafb45239e1da6337d9
This commit is contained in:
Hall Liu
2017-09-14 19:45:04 +00:00
committed by android-build-merger
18 changed files with 274 additions and 251 deletions

View File

@@ -505,7 +505,7 @@ LOCAL_SRC_FILES += \
telecomm/java/com/android/internal/telecom/ITelecomService.aidl \ telecomm/java/com/android/internal/telecom/ITelecomService.aidl \
telecomm/java/com/android/internal/telecom/RemoteServiceCallback.aidl \ telecomm/java/com/android/internal/telecom/RemoteServiceCallback.aidl \
telephony/java/android/telephony/mbms/IMbmsDownloadManagerCallback.aidl \ telephony/java/android/telephony/mbms/IMbmsDownloadManagerCallback.aidl \
telephony/java/android/telephony/mbms/IMbmsStreamingManagerCallback.aidl \ telephony/java/android/telephony/mbms/IMbmsStreamingSessionCallback.aidl \
telephony/java/android/telephony/mbms/IDownloadStateCallback.aidl \ telephony/java/android/telephony/mbms/IDownloadStateCallback.aidl \
telephony/java/android/telephony/mbms/IStreamingServiceCallback.aidl \ telephony/java/android/telephony/mbms/IStreamingServiceCallback.aidl \
telephony/java/android/telephony/mbms/vendor/IMbmsDownloadService.aidl \ telephony/java/android/telephony/mbms/vendor/IMbmsDownloadService.aidl \

View File

@@ -39746,13 +39746,12 @@ package android.telephony {
field public static final int STATUS_UNKNOWN = 0; // 0x0 field public static final int STATUS_UNKNOWN = 0; // 0x0
} }
public class MbmsStreamingManager { public class MbmsStreamingSession implements java.lang.AutoCloseable {
method public static android.telephony.MbmsStreamingManager create(android.content.Context, android.telephony.mbms.MbmsStreamingManagerCallback, int, android.os.Handler) throws android.telephony.mbms.MbmsException; method public void close();
method public static android.telephony.MbmsStreamingManager create(android.content.Context, android.telephony.mbms.MbmsStreamingManagerCallback, android.os.Handler) throws android.telephony.mbms.MbmsException; method public static android.telephony.MbmsStreamingSession create(android.content.Context, android.telephony.mbms.MbmsStreamingSessionCallback, int, android.os.Handler);
method public static android.telephony.MbmsStreamingManager create(android.content.Context, android.telephony.mbms.MbmsStreamingManagerCallback) throws android.telephony.mbms.MbmsException; method public static android.telephony.MbmsStreamingSession create(android.content.Context, android.telephony.mbms.MbmsStreamingSessionCallback, android.os.Handler);
method public void dispose(); method public void requestUpdateStreamingServices(java.util.List<java.lang.String>);
method public void getStreamingServices(java.util.List<java.lang.String>) throws android.telephony.mbms.MbmsException; method public android.telephony.mbms.StreamingService startStreaming(android.telephony.mbms.StreamingServiceInfo, android.telephony.mbms.StreamingServiceCallback, android.os.Handler);
method public android.telephony.mbms.StreamingService startStreaming(android.telephony.mbms.StreamingServiceInfo, android.telephony.mbms.StreamingServiceCallback, android.os.Handler) throws android.telephony.mbms.MbmsException;
} }
public class NeighboringCellInfo implements android.os.Parcelable { public class NeighboringCellInfo implements android.os.Parcelable {
@@ -40476,27 +40475,26 @@ package android.telephony.mbms {
field public static final int ERROR_UNABLE_TO_START_SERVICE = 302; // 0x12e field public static final int ERROR_UNABLE_TO_START_SERVICE = 302; // 0x12e
} }
public class MbmsStreamingManagerCallback { public class MbmsStreamingSessionCallback {
ctor public MbmsStreamingManagerCallback(); ctor public MbmsStreamingSessionCallback();
method public void onError(int, java.lang.String); method public void onError(int, java.lang.String);
method public void onMiddlewareReady(); method public void onMiddlewareReady();
method public void onStreamingServicesUpdated(java.util.List<android.telephony.mbms.StreamingServiceInfo>); method public void onStreamingServicesUpdated(java.util.List<android.telephony.mbms.StreamingServiceInfo>);
} }
public class ServiceInfo { public class ServiceInfo {
method public java.lang.String getClassName();
method public java.util.List<java.util.Locale> getLocales(); method public java.util.List<java.util.Locale> getLocales();
method public java.util.Map<java.util.Locale, java.lang.String> getNames(); method public java.util.Map<java.util.Locale, java.lang.String> getNames();
method public java.lang.String getServiceClassName();
method public java.lang.String getServiceId(); method public java.lang.String getServiceId();
method public java.util.Date getSessionEndTime(); method public java.util.Date getSessionEndTime();
method public java.util.Date getSessionStartTime(); method public java.util.Date getSessionStartTime();
} }
public class StreamingService { public class StreamingService {
method public void dispose() throws android.telephony.mbms.MbmsException;
method public android.telephony.mbms.StreamingServiceInfo getInfo(); method public android.telephony.mbms.StreamingServiceInfo getInfo();
method public android.net.Uri getPlaybackUri() throws android.telephony.mbms.MbmsException; method public android.net.Uri getPlaybackUri();
method public void stopStreaming() throws android.telephony.mbms.MbmsException; method public void stopStreaming();
field public static final int BROADCAST_METHOD = 1; // 0x1 field public static final int BROADCAST_METHOD = 1; // 0x1
field public static final int REASON_BY_USER_REQUEST = 1; // 0x1 field public static final int REASON_BY_USER_REQUEST = 1; // 0x1
field public static final int REASON_END_OF_SESSION = 2; // 0x2 field public static final int REASON_END_OF_SESSION = 2; // 0x2

View File

@@ -43176,13 +43176,12 @@ package android.telephony {
field public static final int STATUS_UNKNOWN = 0; // 0x0 field public static final int STATUS_UNKNOWN = 0; // 0x0
} }
public class MbmsStreamingManager { public class MbmsStreamingSession implements java.lang.AutoCloseable {
method public static android.telephony.MbmsStreamingManager create(android.content.Context, android.telephony.mbms.MbmsStreamingManagerCallback, int, android.os.Handler) throws android.telephony.mbms.MbmsException; method public void close();
method public static android.telephony.MbmsStreamingManager create(android.content.Context, android.telephony.mbms.MbmsStreamingManagerCallback, android.os.Handler) throws android.telephony.mbms.MbmsException; method public static android.telephony.MbmsStreamingSession create(android.content.Context, android.telephony.mbms.MbmsStreamingSessionCallback, int, android.os.Handler);
method public static android.telephony.MbmsStreamingManager create(android.content.Context, android.telephony.mbms.MbmsStreamingManagerCallback) throws android.telephony.mbms.MbmsException; method public static android.telephony.MbmsStreamingSession create(android.content.Context, android.telephony.mbms.MbmsStreamingSessionCallback, android.os.Handler);
method public void dispose(); method public void requestUpdateStreamingServices(java.util.List<java.lang.String>);
method public void getStreamingServices(java.util.List<java.lang.String>) throws android.telephony.mbms.MbmsException; method public android.telephony.mbms.StreamingService startStreaming(android.telephony.mbms.StreamingServiceInfo, android.telephony.mbms.StreamingServiceCallback, android.os.Handler);
method public android.telephony.mbms.StreamingService startStreaming(android.telephony.mbms.StreamingServiceInfo, android.telephony.mbms.StreamingServiceCallback, android.os.Handler) throws android.telephony.mbms.MbmsException;
field public static final java.lang.String MBMS_STREAMING_SERVICE_ACTION = "android.telephony.action.EmbmsStreaming"; field public static final java.lang.String MBMS_STREAMING_SERVICE_ACTION = "android.telephony.action.EmbmsStreaming";
} }
@@ -44001,27 +44000,26 @@ package android.telephony.mbms {
field public static final int ERROR_UNABLE_TO_START_SERVICE = 302; // 0x12e field public static final int ERROR_UNABLE_TO_START_SERVICE = 302; // 0x12e
} }
public class MbmsStreamingManagerCallback { public class MbmsStreamingSessionCallback {
ctor public MbmsStreamingManagerCallback(); ctor public MbmsStreamingSessionCallback();
method public void onError(int, java.lang.String); method public void onError(int, java.lang.String);
method public void onMiddlewareReady(); method public void onMiddlewareReady();
method public void onStreamingServicesUpdated(java.util.List<android.telephony.mbms.StreamingServiceInfo>); method public void onStreamingServicesUpdated(java.util.List<android.telephony.mbms.StreamingServiceInfo>);
} }
public class ServiceInfo { public class ServiceInfo {
method public java.lang.String getClassName();
method public java.util.List<java.util.Locale> getLocales(); method public java.util.List<java.util.Locale> getLocales();
method public java.util.Map<java.util.Locale, java.lang.String> getNames(); method public java.util.Map<java.util.Locale, java.lang.String> getNames();
method public java.lang.String getServiceClassName();
method public java.lang.String getServiceId(); method public java.lang.String getServiceId();
method public java.util.Date getSessionEndTime(); method public java.util.Date getSessionEndTime();
method public java.util.Date getSessionStartTime(); method public java.util.Date getSessionStartTime();
} }
public class StreamingService { public class StreamingService {
method public void dispose() throws android.telephony.mbms.MbmsException;
method public android.telephony.mbms.StreamingServiceInfo getInfo(); method public android.telephony.mbms.StreamingServiceInfo getInfo();
method public android.net.Uri getPlaybackUri() throws android.telephony.mbms.MbmsException; method public android.net.Uri getPlaybackUri();
method public void stopStreaming() throws android.telephony.mbms.MbmsException; method public void stopStreaming();
field public static final int BROADCAST_METHOD = 1; // 0x1 field public static final int BROADCAST_METHOD = 1; // 0x1
field public static final int REASON_BY_USER_REQUEST = 1; // 0x1 field public static final int REASON_BY_USER_REQUEST = 1; // 0x1
field public static final int REASON_END_OF_SESSION = 2; // 0x2 field public static final int REASON_END_OF_SESSION = 2; // 0x2
@@ -44082,11 +44080,10 @@ package android.telephony.mbms.vendor {
public class MbmsStreamingServiceBase extends android.os.Binder { public class MbmsStreamingServiceBase extends android.os.Binder {
ctor public MbmsStreamingServiceBase(); ctor public MbmsStreamingServiceBase();
method public void dispose(int) throws android.os.RemoteException; method public void dispose(int) throws android.os.RemoteException;
method public void disposeStream(int, java.lang.String) throws android.os.RemoteException;
method public android.net.Uri getPlaybackUri(int, java.lang.String) throws android.os.RemoteException; method public android.net.Uri getPlaybackUri(int, java.lang.String) throws android.os.RemoteException;
method public int getStreamingServices(int, java.util.List<java.lang.String>) throws android.os.RemoteException; method public int initialize(android.telephony.mbms.MbmsStreamingSessionCallback, int) throws android.os.RemoteException;
method public int initialize(android.telephony.mbms.MbmsStreamingManagerCallback, int) throws android.os.RemoteException;
method public void onAppCallbackDied(int, int); method public void onAppCallbackDied(int, int);
method public int requestUpdateStreamingServices(int, java.util.List<java.lang.String>) throws android.os.RemoteException;
method public int startStreaming(int, java.lang.String, android.telephony.mbms.StreamingServiceCallback) throws android.os.RemoteException; method public int startStreaming(int, java.lang.String, android.telephony.mbms.StreamingServiceCallback) throws android.os.RemoteException;
method public void stopStreaming(int, java.lang.String) throws android.os.RemoteException; method public void stopStreaming(int, java.lang.String) throws android.os.RemoteException;
} }

View File

@@ -39970,13 +39970,12 @@ package android.telephony {
field public static final int STATUS_UNKNOWN = 0; // 0x0 field public static final int STATUS_UNKNOWN = 0; // 0x0
} }
public class MbmsStreamingManager { public class MbmsStreamingSession implements java.lang.AutoCloseable {
method public static android.telephony.MbmsStreamingManager create(android.content.Context, android.telephony.mbms.MbmsStreamingManagerCallback, int, android.os.Handler) throws android.telephony.mbms.MbmsException; method public void close();
method public static android.telephony.MbmsStreamingManager create(android.content.Context, android.telephony.mbms.MbmsStreamingManagerCallback, android.os.Handler) throws android.telephony.mbms.MbmsException; method public static android.telephony.MbmsStreamingSession create(android.content.Context, android.telephony.mbms.MbmsStreamingSessionCallback, int, android.os.Handler);
method public static android.telephony.MbmsStreamingManager create(android.content.Context, android.telephony.mbms.MbmsStreamingManagerCallback) throws android.telephony.mbms.MbmsException; method public static android.telephony.MbmsStreamingSession create(android.content.Context, android.telephony.mbms.MbmsStreamingSessionCallback, android.os.Handler);
method public void dispose(); method public void requestUpdateStreamingServices(java.util.List<java.lang.String>);
method public void getStreamingServices(java.util.List<java.lang.String>) throws android.telephony.mbms.MbmsException; method public android.telephony.mbms.StreamingService startStreaming(android.telephony.mbms.StreamingServiceInfo, android.telephony.mbms.StreamingServiceCallback, android.os.Handler);
method public android.telephony.mbms.StreamingService startStreaming(android.telephony.mbms.StreamingServiceInfo, android.telephony.mbms.StreamingServiceCallback, android.os.Handler) throws android.telephony.mbms.MbmsException;
} }
public class NeighboringCellInfo implements android.os.Parcelable { public class NeighboringCellInfo implements android.os.Parcelable {
@@ -40700,27 +40699,26 @@ package android.telephony.mbms {
field public static final int ERROR_UNABLE_TO_START_SERVICE = 302; // 0x12e field public static final int ERROR_UNABLE_TO_START_SERVICE = 302; // 0x12e
} }
public class MbmsStreamingManagerCallback { public class MbmsStreamingSessionCallback {
ctor public MbmsStreamingManagerCallback(); ctor public MbmsStreamingSessionCallback();
method public void onError(int, java.lang.String); method public void onError(int, java.lang.String);
method public void onMiddlewareReady(); method public void onMiddlewareReady();
method public void onStreamingServicesUpdated(java.util.List<android.telephony.mbms.StreamingServiceInfo>); method public void onStreamingServicesUpdated(java.util.List<android.telephony.mbms.StreamingServiceInfo>);
} }
public class ServiceInfo { public class ServiceInfo {
method public java.lang.String getClassName();
method public java.util.List<java.util.Locale> getLocales(); method public java.util.List<java.util.Locale> getLocales();
method public java.util.Map<java.util.Locale, java.lang.String> getNames(); method public java.util.Map<java.util.Locale, java.lang.String> getNames();
method public java.lang.String getServiceClassName();
method public java.lang.String getServiceId(); method public java.lang.String getServiceId();
method public java.util.Date getSessionEndTime(); method public java.util.Date getSessionEndTime();
method public java.util.Date getSessionStartTime(); method public java.util.Date getSessionStartTime();
} }
public class StreamingService { public class StreamingService {
method public void dispose() throws android.telephony.mbms.MbmsException;
method public android.telephony.mbms.StreamingServiceInfo getInfo(); method public android.telephony.mbms.StreamingServiceInfo getInfo();
method public android.net.Uri getPlaybackUri() throws android.telephony.mbms.MbmsException; method public android.net.Uri getPlaybackUri();
method public void stopStreaming() throws android.telephony.mbms.MbmsException; method public void stopStreaming();
field public static final int BROADCAST_METHOD = 1; // 0x1 field public static final int BROADCAST_METHOD = 1; // 0x1
field public static final int REASON_BY_USER_REQUEST = 1; // 0x1 field public static final int REASON_BY_USER_REQUEST = 1; // 0x1
field public static final int REASON_END_OF_SESSION = 2; // 0x2 field public static final int REASON_END_OF_SESSION = 2; // 0x2

View File

@@ -16,6 +16,8 @@
package android.telephony; package android.telephony;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SdkConstant; import android.annotation.SdkConstant;
import android.annotation.SystemApi; import android.annotation.SystemApi;
import android.content.ComponentName; import android.content.ComponentName;
@@ -25,18 +27,20 @@ import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
import android.os.Looper; import android.os.Looper;
import android.os.RemoteException; import android.os.RemoteException;
import android.telephony.mbms.InternalStreamingManagerCallback; import android.telephony.mbms.InternalStreamingSessionCallback;
import android.telephony.mbms.InternalStreamingServiceCallback; import android.telephony.mbms.InternalStreamingServiceCallback;
import android.telephony.mbms.MbmsException; import android.telephony.mbms.MbmsException;
import android.telephony.mbms.MbmsStreamingManagerCallback; import android.telephony.mbms.MbmsStreamingSessionCallback;
import android.telephony.mbms.MbmsUtils; import android.telephony.mbms.MbmsUtils;
import android.telephony.mbms.StreamingService; import android.telephony.mbms.StreamingService;
import android.telephony.mbms.StreamingServiceCallback; import android.telephony.mbms.StreamingServiceCallback;
import android.telephony.mbms.StreamingServiceInfo; import android.telephony.mbms.StreamingServiceInfo;
import android.telephony.mbms.vendor.IMbmsStreamingService; import android.telephony.mbms.vendor.IMbmsStreamingService;
import android.util.ArraySet;
import android.util.Log; import android.util.Log;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
@@ -45,8 +49,8 @@ import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
/** /**
* This class provides functionality for streaming media over MBMS. * This class provides functionality for streaming media over MBMS.
*/ */
public class MbmsStreamingManager { public class MbmsStreamingSession implements AutoCloseable {
private static final String LOG_TAG = "MbmsStreamingManager"; private static final String LOG_TAG = "MbmsStreamingSession";
/** /**
* Service action which must be handled by the middleware implementing the MBMS streaming * Service action which must be handled by the middleware implementing the MBMS streaming
@@ -69,94 +73,94 @@ public class MbmsStreamingManager {
} }
}; };
private InternalStreamingManagerCallback mInternalCallback; private InternalStreamingSessionCallback mInternalCallback;
private Set<StreamingService> mKnownActiveStreamingServices = new ArraySet<>();
private final Context mContext; private final Context mContext;
private int mSubscriptionId = INVALID_SUBSCRIPTION_ID; private int mSubscriptionId = INVALID_SUBSCRIPTION_ID;
/** @hide */ /** @hide */
private MbmsStreamingManager(Context context, MbmsStreamingManagerCallback callback, private MbmsStreamingSession(Context context, MbmsStreamingSessionCallback callback,
int subscriptionId, Handler handler) { int subscriptionId, Handler handler) {
mContext = context; mContext = context;
mSubscriptionId = subscriptionId; mSubscriptionId = subscriptionId;
if (handler == null) { if (handler == null) {
handler = new Handler(Looper.getMainLooper()); handler = new Handler(Looper.getMainLooper());
} }
mInternalCallback = new InternalStreamingManagerCallback(callback, handler); mInternalCallback = new InternalStreamingSessionCallback(callback, handler);
} }
/** /**
* Create a new MbmsStreamingManager using the given subscription ID. * Create a new {@link MbmsStreamingSession} using the given subscription ID.
* *
* Note that this call will bind a remote service. You may not call this method on your app's * Note that this call will bind a remote service. You may not call this method on your app's
* main thread. This may throw an {@link MbmsException}, indicating errors that may happen * main thread.
* during the initialization or binding process.
* *
* * You may only have one instance of {@link MbmsStreamingSession} per UID. If you call this
* You may only have one instance of {@link MbmsStreamingManager} per UID. If you call this * method while there is an active instance of {@link MbmsStreamingSession} in your process
* method while there is an active instance of {@link MbmsStreamingManager} in your process * (in other words, one that has not had {@link #close()} called on it), this method will
* (in other words, one that has not had {@link #dispose()} called on it), this method will * throw an {@link IllegalStateException}. If you call this method in a different process
* throw an {@link MbmsException}. If you call this method in a different process
* running under the same UID, an error will be indicated via * running under the same UID, an error will be indicated via
* {@link MbmsStreamingManagerCallback#onError(int, String)}. * {@link MbmsStreamingSessionCallback#onError(int, String)}.
* *
* Note that initialization may fail asynchronously. If you wish to try again after you * Note that initialization may fail asynchronously. If you wish to try again after you
* receive such an asynchronous error, you must call dispose() on the instance of * receive such an asynchronous error, you must call {@link #close()} on the instance of
* {@link MbmsStreamingManager} that you received before calling this method again. * {@link MbmsStreamingSession} that you received before calling this method again.
* *
* @param context The {@link Context} to use. * @param context The {@link Context} to use.
* @param callback A callback object on which you wish to receive results of asynchronous * @param callback A callback object on which you wish to receive results of asynchronous
* operations. * operations.
* @param subscriptionId The subscription ID to use. * @param subscriptionId The subscription ID to use.
* @param handler The handler you wish to receive callbacks on. If null, callbacks will be * @param handler The handler you wish to receive callbacks on.
* processed on the main looper (in other words, the looper returned from * @return An instance of {@link MbmsStreamingSession}, or null if an error occurred.
* {@link Looper#getMainLooper()}).
*/ */
public static MbmsStreamingManager create(Context context, public static @Nullable MbmsStreamingSession create(@NonNull Context context,
MbmsStreamingManagerCallback callback, int subscriptionId, Handler handler) @NonNull MbmsStreamingSessionCallback callback, int subscriptionId,
throws MbmsException { @NonNull Handler handler) {
if (!sIsInitialized.compareAndSet(false, true)) { if (!sIsInitialized.compareAndSet(false, true)) {
throw new MbmsException(MbmsException.InitializationErrors.ERROR_DUPLICATE_INITIALIZE); throw new IllegalStateException("Cannot create two instances of MbmsStreamingSession");
} }
MbmsStreamingManager manager = new MbmsStreamingManager(context, callback, MbmsStreamingSession session = new MbmsStreamingSession(context, callback,
subscriptionId, handler); subscriptionId, handler);
try {
manager.bindAndInitialize(); int result = session.bindAndInitialize();
} catch (MbmsException e) { if (result != MbmsException.SUCCESS) {
sIsInitialized.set(false); sIsInitialized.set(false);
throw e; handler.post(new Runnable() {
@Override
public void run() {
callback.onError(result, null);
} }
return manager; });
return null;
}
return session;
} }
/** /**
* Create a new MbmsStreamingManager using the system default data subscription ID. * Create a new {@link MbmsStreamingSession} using the system default data subscription ID.
* See {@link #create(Context, MbmsStreamingManagerCallback, int, Handler)}. * See {@link #create(Context, MbmsStreamingSessionCallback, int, Handler)}.
*/ */
public static MbmsStreamingManager create(Context context, public static MbmsStreamingSession create(@NonNull Context context,
MbmsStreamingManagerCallback callback, Handler handler) @NonNull MbmsStreamingSessionCallback callback, @NonNull Handler handler) {
throws MbmsException {
return create(context, callback, SubscriptionManager.getDefaultSubscriptionId(), handler); return create(context, callback, SubscriptionManager.getDefaultSubscriptionId(), handler);
} }
/** /**
* Create a new MbmsStreamingManager using the system default data subscription ID and * Terminates this instance. Also terminates
* default {@link Handler}. * any streaming services spawned from this instance as if
* See {@link #create(Context, MbmsStreamingManagerCallback, int, Handler)}. * {@link StreamingService#stopStreaming()} had been called on them. After this method returns,
*/ * no further callbacks originating from the middleware will be enqueued on the provided
public static MbmsStreamingManager create(Context context, * instance of {@link MbmsStreamingSessionCallback}, but callbacks that have already been
MbmsStreamingManagerCallback callback) * enqueued will still be delivered.
throws MbmsException { *
return create(context, callback, SubscriptionManager.getDefaultSubscriptionId(), null); * It is safe to call {@link #create(Context, MbmsStreamingSessionCallback, int, Handler)} to
} * obtain another instance of {@link MbmsStreamingSession} immediately after this method
* returns.
/**
* Terminates this instance, ending calls to the registered listener. Also terminates
* any streaming services spawned from this instance.
* *
* May throw an {@link IllegalStateException} * May throw an {@link IllegalStateException}
*/ */
public void dispose() { public void close() {
try { try {
IMbmsStreamingService streamingService = mService.get(); IMbmsStreamingService streamingService = mService.get();
if (streamingService == null) { if (streamingService == null) {
@@ -164,47 +168,49 @@ public class MbmsStreamingManager {
return; return;
} }
streamingService.dispose(mSubscriptionId); streamingService.dispose(mSubscriptionId);
for (StreamingService s : mKnownActiveStreamingServices) {
s.getCallback().stop();
}
mKnownActiveStreamingServices.clear();
} catch (RemoteException e) { } catch (RemoteException e) {
// Ignore for now // Ignore for now
} finally { } finally {
mService.set(null); mService.set(null);
sIsInitialized.set(false); sIsInitialized.set(false);
mInternalCallback.stop();
} }
} }
/** /**
* An inspection API to retrieve the list of streaming media currently be advertised. * An inspection API to retrieve the list of streaming media currently be advertised.
* The results are returned asynchronously through the previously registered callback. * The results are returned asynchronously via
* serviceClasses lets the app filter on types of programming and is opaque data between * {@link MbmsStreamingSessionCallback#onStreamingServicesUpdated(List)} on the callback
* the app and the carrier. * provided upon creation.
* *
* Multiple calls replace the list of serviceClasses of interest. * Multiple calls replace the list of service classes of interest.
* *
* This may throw an {@link MbmsException} containing any error in * May throw an {@link IllegalArgumentException} or an {@link IllegalStateException}.
* {@link android.telephony.mbms.MbmsException.GeneralErrors},
* {@link MbmsException#ERROR_MIDDLEWARE_NOT_BOUND}, or
* {@link MbmsException#ERROR_MIDDLEWARE_LOST}.
* *
* May also throw an unchecked {@link IllegalArgumentException} or an * @param serviceClassList A list of streaming service classes that the app would like updates
* {@link IllegalStateException} * on. The exact names of these classes should be negotiated with the
* * wireless carrier separately.
* @param classList A list of streaming service classes that the app would like updates on.
*/ */
public void getStreamingServices(List<String> classList) throws MbmsException { public void requestUpdateStreamingServices(List<String> serviceClassList) {
IMbmsStreamingService streamingService = mService.get(); IMbmsStreamingService streamingService = mService.get();
if (streamingService == null) { if (streamingService == null) {
throw new MbmsException(MbmsException.ERROR_MIDDLEWARE_NOT_BOUND); throw new IllegalStateException("Middleware not yet bound");
} }
try { try {
int returnCode = streamingService.getStreamingServices(mSubscriptionId, classList); int returnCode = streamingService.requestUpdateStreamingServices(
mSubscriptionId, serviceClassList);
if (returnCode != MbmsException.SUCCESS) { if (returnCode != MbmsException.SUCCESS) {
throw new MbmsException(returnCode); sendErrorToApp(returnCode, null);
} }
} catch (RemoteException e) { } catch (RemoteException e) {
Log.w(LOG_TAG, "Remote process died"); Log.w(LOG_TAG, "Remote process died");
mService.set(null); mService.set(null);
sIsInitialized.set(false); sIsInitialized.set(false);
throw new MbmsException(MbmsException.ERROR_MIDDLEWARE_LOST); sendErrorToApp(MbmsException.ERROR_MIDDLEWARE_LOST, null);
} }
} }
@@ -215,13 +221,7 @@ public class MbmsStreamingManager {
* reported via * reported via
* {@link android.telephony.mbms.StreamingServiceCallback#onStreamStateUpdated(int, int)} * {@link android.telephony.mbms.StreamingServiceCallback#onStreamStateUpdated(int, int)}
* *
* May throw an * May throw an {@link IllegalArgumentException} or an {@link IllegalStateException}
* {@link MbmsException} containing any of the error codes in
* {@link android.telephony.mbms.MbmsException.GeneralErrors},
* {@link MbmsException#ERROR_MIDDLEWARE_NOT_BOUND}, or
* {@link MbmsException#ERROR_MIDDLEWARE_LOST}.
*
* May also throw an {@link IllegalArgumentException} or an {@link IllegalStateException}
* *
* Asynchronous errors through the callback include any of the errors in * Asynchronous errors through the callback include any of the errors in
* {@link android.telephony.mbms.MbmsException.GeneralErrors} or * {@link android.telephony.mbms.MbmsException.GeneralErrors} or
@@ -229,42 +229,49 @@ public class MbmsStreamingManager {
* *
* @param serviceInfo The information about the service to stream. * @param serviceInfo The information about the service to stream.
* @param callback A callback that'll be called when something about the stream changes. * @param callback A callback that'll be called when something about the stream changes.
* @param handler A handler that calls to {@code callback} should be called on. If null, * @param handler A handler that calls to {@code callback} should be called on.
* defaults to the handler provided via
* {@link #create(Context, MbmsStreamingManagerCallback, int, Handler)}.
* @return An instance of {@link StreamingService} through which the stream can be controlled. * @return An instance of {@link StreamingService} through which the stream can be controlled.
* May be {@code null} if an error occurred.
*/ */
public StreamingService startStreaming(StreamingServiceInfo serviceInfo, public @Nullable StreamingService startStreaming(StreamingServiceInfo serviceInfo,
StreamingServiceCallback callback, Handler handler) throws MbmsException { StreamingServiceCallback callback, @NonNull Handler handler) {
IMbmsStreamingService streamingService = mService.get(); IMbmsStreamingService streamingService = mService.get();
if (streamingService == null) { if (streamingService == null) {
throw new MbmsException(MbmsException.ERROR_MIDDLEWARE_NOT_BOUND); throw new IllegalStateException("Middleware not yet bound");
} }
InternalStreamingServiceCallback serviceCallback = new InternalStreamingServiceCallback( InternalStreamingServiceCallback serviceCallback = new InternalStreamingServiceCallback(
callback, handler == null ? mInternalCallback.getHandler() : handler); callback, handler);
StreamingService serviceForApp = new StreamingService( StreamingService serviceForApp = new StreamingService(
mSubscriptionId, streamingService, serviceInfo, serviceCallback); mSubscriptionId, streamingService, this, serviceInfo, serviceCallback);
mKnownActiveStreamingServices.add(serviceForApp);
try { try {
int returnCode = streamingService.startStreaming( int returnCode = streamingService.startStreaming(
mSubscriptionId, serviceInfo.getServiceId(), serviceCallback); mSubscriptionId, serviceInfo.getServiceId(), serviceCallback);
if (returnCode != MbmsException.SUCCESS) { if (returnCode != MbmsException.SUCCESS) {
throw new MbmsException(returnCode); sendErrorToApp(returnCode, null);
return null;
} }
} catch (RemoteException e) { } catch (RemoteException e) {
Log.w(LOG_TAG, "Remote process died"); Log.w(LOG_TAG, "Remote process died");
mService.set(null); mService.set(null);
sIsInitialized.set(false); sIsInitialized.set(false);
throw new MbmsException(MbmsException.ERROR_MIDDLEWARE_LOST); sendErrorToApp(MbmsException.ERROR_MIDDLEWARE_LOST, null);
return null;
} }
return serviceForApp; return serviceForApp;
} }
private void bindAndInitialize() throws MbmsException { /** @hide */
MbmsUtils.startBinding(mContext, MBMS_STREAMING_SERVICE_ACTION, public void onStreamingServiceStopped(StreamingService service) {
mKnownActiveStreamingServices.remove(service);
}
private int bindAndInitialize() {
return MbmsUtils.startBinding(mContext, MBMS_STREAMING_SERVICE_ACTION,
new ServiceConnection() { new ServiceConnection() {
@Override @Override
public void onServiceConnected(ComponentName name, IBinder service) { public void onServiceConnected(ComponentName name, IBinder service) {
@@ -315,7 +322,7 @@ public class MbmsStreamingManager {
private void sendErrorToApp(int errorCode, String message) { private void sendErrorToApp(int errorCode, String message) {
try { try {
mInternalCallback.error(errorCode, message); mInternalCallback.onError(errorCode, message);
} catch (RemoteException e) { } catch (RemoteException e) {
// Ignore, should not happen locally. // Ignore, should not happen locally.
} }

View File

@@ -58,7 +58,7 @@ public final class FileServiceInfo extends ServiceInfo implements Parcelable {
FileServiceInfo(Parcel in) { FileServiceInfo(Parcel in) {
super(in); super(in);
files = new ArrayList<FileInfo>(); files = new ArrayList<FileInfo>();
in.readList(files, null); in.readList(files, FileInfo.class.getClassLoader());
} }
@Override @Override

View File

@@ -24,11 +24,11 @@ import java.util.List;
* The interface the clients top-level streaming listener will satisfy. * The interface the clients top-level streaming listener will satisfy.
* @hide * @hide
*/ */
oneway interface IMbmsStreamingManagerCallback oneway interface IMbmsStreamingSessionCallback
{ {
void error(int errorCode, String message); void onError(int errorCode, String message);
void streamingServicesUpdated(in List<StreamingServiceInfo> services); void onStreamingServicesUpdated(in List<StreamingServiceInfo> services);
void middlewareReady(); void onMiddlewareReady();
} }

View File

@@ -20,9 +20,9 @@ package android.telephony.mbms;
* @hide * @hide
*/ */
oneway interface IStreamingServiceCallback { oneway interface IStreamingServiceCallback {
void error(int errorCode, String message); void onError(int errorCode, String message);
void streamStateUpdated(int state, int reason); void onStreamStateUpdated(int state, int reason);
void mediaDescriptionUpdated(); void onMediaDescriptionUpdated();
void broadcastSignalStrengthUpdated(int signalStrength); void onBroadcastSignalStrengthUpdated(int signalStrength);
void streamMethodUpdated(int methodType); void onStreamMethodUpdated(int methodType);
} }

View File

@@ -23,6 +23,7 @@ import android.os.RemoteException;
public class InternalStreamingServiceCallback extends IStreamingServiceCallback.Stub { public class InternalStreamingServiceCallback extends IStreamingServiceCallback.Stub {
private final StreamingServiceCallback mAppCallback; private final StreamingServiceCallback mAppCallback;
private final Handler mHandler; private final Handler mHandler;
private volatile boolean mIsStopped = false;
public InternalStreamingServiceCallback(StreamingServiceCallback appCallback, Handler handler) { public InternalStreamingServiceCallback(StreamingServiceCallback appCallback, Handler handler) {
mAppCallback = appCallback; mAppCallback = appCallback;
@@ -30,7 +31,11 @@ public class InternalStreamingServiceCallback extends IStreamingServiceCallback.
} }
@Override @Override
public void error(int errorCode, String message) throws RemoteException { public void onError(int errorCode, String message) throws RemoteException {
if (mIsStopped) {
return;
}
mHandler.post(new Runnable() { mHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
@@ -40,7 +45,11 @@ public class InternalStreamingServiceCallback extends IStreamingServiceCallback.
} }
@Override @Override
public void streamStateUpdated(int state, int reason) throws RemoteException { public void onStreamStateUpdated(int state, int reason) throws RemoteException {
if (mIsStopped) {
return;
}
mHandler.post(new Runnable() { mHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
@@ -50,7 +59,11 @@ public class InternalStreamingServiceCallback extends IStreamingServiceCallback.
} }
@Override @Override
public void mediaDescriptionUpdated() throws RemoteException { public void onMediaDescriptionUpdated() throws RemoteException {
if (mIsStopped) {
return;
}
mHandler.post(new Runnable() { mHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
@@ -60,7 +73,11 @@ public class InternalStreamingServiceCallback extends IStreamingServiceCallback.
} }
@Override @Override
public void broadcastSignalStrengthUpdated(int signalStrength) throws RemoteException { public void onBroadcastSignalStrengthUpdated(int signalStrength) throws RemoteException {
if (mIsStopped) {
return;
}
mHandler.post(new Runnable() { mHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
@@ -70,7 +87,11 @@ public class InternalStreamingServiceCallback extends IStreamingServiceCallback.
} }
@Override @Override
public void streamMethodUpdated(int methodType) throws RemoteException { public void onStreamMethodUpdated(int methodType) throws RemoteException {
if (mIsStopped) {
return;
}
mHandler.post(new Runnable() { mHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
@@ -78,4 +99,8 @@ public class InternalStreamingServiceCallback extends IStreamingServiceCallback.
} }
}); });
} }
public void stop() {
mIsStopped = true;
}
} }

View File

@@ -18,25 +18,27 @@ package android.telephony.mbms;
import android.os.Handler; import android.os.Handler;
import android.os.RemoteException; import android.os.RemoteException;
import android.telephony.mbms.IMbmsStreamingManagerCallback;
import android.telephony.mbms.MbmsStreamingManagerCallback;
import android.telephony.mbms.StreamingServiceInfo;
import java.util.List; import java.util.List;
/** @hide */ /** @hide */
public class InternalStreamingManagerCallback extends IMbmsStreamingManagerCallback.Stub { public class InternalStreamingSessionCallback extends IMbmsStreamingSessionCallback.Stub {
private final Handler mHandler; private final Handler mHandler;
private final MbmsStreamingManagerCallback mAppCallback; private final MbmsStreamingSessionCallback mAppCallback;
private volatile boolean mIsStopped = false;
public InternalStreamingManagerCallback(MbmsStreamingManagerCallback appCallback, public InternalStreamingSessionCallback(MbmsStreamingSessionCallback appCallback,
Handler handler) { Handler handler) {
mAppCallback = appCallback; mAppCallback = appCallback;
mHandler = handler; mHandler = handler;
} }
@Override @Override
public void error(int errorCode, String message) throws RemoteException { public void onError(int errorCode, String message) throws RemoteException {
if (mIsStopped) {
return;
}
mHandler.post(new Runnable() { mHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
@@ -46,8 +48,12 @@ public class InternalStreamingManagerCallback extends IMbmsStreamingManagerCallb
} }
@Override @Override
public void streamingServicesUpdated(List<StreamingServiceInfo> services) public void onStreamingServicesUpdated(List<StreamingServiceInfo> services)
throws RemoteException { throws RemoteException {
if (mIsStopped) {
return;
}
mHandler.post(new Runnable() { mHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
@@ -57,7 +63,11 @@ public class InternalStreamingManagerCallback extends IMbmsStreamingManagerCallb
} }
@Override @Override
public void middlewareReady() throws RemoteException { public void onMiddlewareReady() throws RemoteException {
if (mIsStopped) {
return;
}
mHandler.post(new Runnable() { mHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
@@ -69,4 +79,8 @@ public class InternalStreamingManagerCallback extends IMbmsStreamingManagerCallb
public Handler getHandler() { public Handler getHandler() {
return mHandler; return mHandler;
} }
public void stop() {
mIsStopped = true;
}
} }

View File

@@ -16,6 +16,8 @@
package android.telephony.mbms; package android.telephony.mbms;
import android.telephony.MbmsStreamingSession;
public class MbmsException extends Exception { public class MbmsException extends Exception {
/** Indicates that the operation was successful. */ /** Indicates that the operation was successful. */
public static final int SUCCESS = 0; public static final int SUCCESS = 0;
@@ -31,7 +33,7 @@ public class MbmsException extends Exception {
/** /**
* Indicates that the app attempted to perform an operation on an instance of * Indicates that the app attempted to perform an operation on an instance of
* TODO link android.telephony.MbmsDownloadManager or * TODO link android.telephony.MbmsDownloadManager or
* {@link android.telephony.MbmsStreamingManager} without being bound to the middleware. * {@link MbmsStreamingSession} without being bound to the middleware.
*/ */
public static final int ERROR_MIDDLEWARE_NOT_BOUND = 2; public static final int ERROR_MIDDLEWARE_NOT_BOUND = 2;
@@ -46,7 +48,7 @@ public class MbmsException extends Exception {
private InitializationErrors() {} private InitializationErrors() {}
/** /**
* Indicates that the app tried to create more than one instance each of * Indicates that the app tried to create more than one instance each of
* {@link android.telephony.MbmsStreamingManager} or * {@link MbmsStreamingSession} or
* TODO link android.telephony.MbmsDownloadManager * TODO link android.telephony.MbmsDownloadManager
*/ */
public static final int ERROR_DUPLICATE_INITIALIZE = 101; public static final int ERROR_DUPLICATE_INITIALIZE = 101;
@@ -64,7 +66,7 @@ public class MbmsException extends Exception {
private GeneralErrors() {} private GeneralErrors() {}
/** /**
* Indicates that the app attempted to perform an operation before receiving notification * Indicates that the app attempted to perform an operation before receiving notification
* that the middleware is ready via {@link MbmsStreamingManagerCallback#onMiddlewareReady()} * that the middleware is ready via {@link MbmsStreamingSessionCallback#onMiddlewareReady()}
* or TODO: link MbmsDownloadManagerCallback#middlewareReady * or TODO: link MbmsDownloadManagerCallback#middlewareReady
*/ */
public static final int ERROR_MIDDLEWARE_NOT_YET_READY = 201; public static final int ERROR_MIDDLEWARE_NOT_YET_READY = 201;
@@ -107,7 +109,7 @@ public class MbmsException extends Exception {
/** /**
* Indicates that the app called * Indicates that the app called
* {@link android.telephony.MbmsStreamingManager#startStreaming( * {@link MbmsStreamingSession#startStreaming(
* StreamingServiceInfo, StreamingServiceCallback, android.os.Handler)} * StreamingServiceInfo, StreamingServiceCallback, android.os.Handler)}
* more than once for the same {@link StreamingServiceInfo}. * more than once for the same {@link StreamingServiceInfo}.
*/ */

View File

@@ -16,25 +16,26 @@
package android.telephony.mbms; package android.telephony.mbms;
import android.annotation.Nullable;
import android.content.Context; import android.content.Context;
import android.os.RemoteException; import android.os.Handler;
import android.telephony.MbmsStreamingManager; import android.telephony.MbmsStreamingSession;
import java.util.List; import java.util.List;
/** /**
* A callback class that is used to receive information from the middleware on MBMS streaming * A callback class that is used to receive information from the middleware on MBMS streaming
* services. An instance of this object should be passed into * services. An instance of this object should be passed into
* {@link android.telephony.MbmsStreamingManager#create(Context, MbmsStreamingManagerCallback)}. * {@link MbmsStreamingSession#create(Context, MbmsStreamingSessionCallback, int, Handler)}.
*/ */
public class MbmsStreamingManagerCallback { public class MbmsStreamingSessionCallback {
/** /**
* Called by the middleware when it has detected an error condition. The possible error codes * Called by the middleware when it has detected an error condition. The possible error codes
* are listed in {@link MbmsException}. * are listed in {@link MbmsException}.
* @param errorCode The error code. * @param errorCode The error code.
* @param message A human-readable message generated by the middleware for debugging purposes. * @param message A human-readable message generated by the middleware for debugging purposes.
*/ */
public void onError(int errorCode, String message) { public void onError(int errorCode, @Nullable String message) {
// default implementation empty // default implementation empty
} }
@@ -47,8 +48,7 @@ public class MbmsStreamingManagerCallback {
* call with the same service class list would return different * call with the same service class list would return different
* results. * results.
* *
* @param services a List of StreamingServiceInfos * @param services The list of available services.
*
*/ */
public void onStreamingServicesUpdated(List<StreamingServiceInfo> services) { public void onStreamingServicesUpdated(List<StreamingServiceInfo> services) {
// default implementation empty // default implementation empty
@@ -58,9 +58,9 @@ public class MbmsStreamingManagerCallback {
* Called to indicate that the middleware has been initialized and is ready. * Called to indicate that the middleware has been initialized and is ready.
* *
* Before this method is called, calling any method on an instance of * Before this method is called, calling any method on an instance of
* {@link android.telephony.MbmsStreamingManager} will result in an {@link MbmsException} * {@link MbmsStreamingSession} will result in an {@link IllegalStateException} or an error
* being thrown with error code {@link MbmsException#ERROR_MIDDLEWARE_NOT_BOUND} * delivered via {@link #onError(int, String)} with error code
* or {@link MbmsException.GeneralErrors#ERROR_MIDDLEWARE_NOT_YET_READY} * {@link MbmsException.GeneralErrors#ERROR_MIDDLEWARE_NOT_YET_READY}.
*/ */
public void onMiddlewareReady() { public void onMiddlewareReady() {
// default implementation empty // default implementation empty

View File

@@ -68,19 +68,20 @@ public class MbmsUtils {
return downloadServices.get(0).serviceInfo; return downloadServices.get(0).serviceInfo;
} }
public static void startBinding(Context context, String serviceAction, public static int startBinding(Context context, String serviceAction,
ServiceConnection serviceConnection) throws MbmsException { ServiceConnection serviceConnection) {
Intent bindIntent = new Intent(); Intent bindIntent = new Intent();
ServiceInfo mbmsServiceInfo = ServiceInfo mbmsServiceInfo =
MbmsUtils.getMiddlewareServiceInfo(context, serviceAction); MbmsUtils.getMiddlewareServiceInfo(context, serviceAction);
if (mbmsServiceInfo == null) { if (mbmsServiceInfo == null) {
throw new MbmsException(MbmsException.ERROR_NO_UNIQUE_MIDDLEWARE); return MbmsException.ERROR_NO_UNIQUE_MIDDLEWARE;
} }
bindIntent.setComponent(MbmsUtils.toComponentName(mbmsServiceInfo)); bindIntent.setComponent(MbmsUtils.toComponentName(mbmsServiceInfo));
context.bindService(bindIntent, serviceConnection, Context.BIND_AUTO_CREATE); context.bindService(bindIntent, serviceConnection, Context.BIND_AUTO_CREATE);
return MbmsException.SUCCESS;
} }
/** /**

View File

@@ -123,7 +123,7 @@ public class ServiceInfo {
/** /**
* The class name for this service - used to categorize and filter * The class name for this service - used to categorize and filter
*/ */
public String getClassName() { public String getServiceClassName() {
return className; return className;
} }

View File

@@ -17,8 +17,10 @@
package android.telephony.mbms; package android.telephony.mbms;
import android.annotation.IntDef; import android.annotation.IntDef;
import android.annotation.Nullable;
import android.net.Uri; import android.net.Uri;
import android.os.RemoteException; import android.os.RemoteException;
import android.telephony.MbmsStreamingSession;
import android.telephony.mbms.vendor.IMbmsStreamingService; import android.telephony.mbms.vendor.IMbmsStreamingService;
import android.util.Log; import android.util.Log;
@@ -27,7 +29,7 @@ import java.lang.annotation.RetentionPolicy;
/** /**
* Class used to represent a single MBMS stream. After a stream has been started with * Class used to represent a single MBMS stream. After a stream has been started with
* {@link android.telephony.MbmsStreamingManager#startStreaming(StreamingServiceInfo, * {@link MbmsStreamingSession#startStreaming(StreamingServiceInfo,
* StreamingServiceCallback, android.os.Handler)}, * StreamingServiceCallback, android.os.Handler)},
* this class is used to hold information about the stream and control it. * this class is used to hold information about the stream and control it.
*/ */
@@ -63,7 +65,7 @@ public class StreamingService {
/** /**
* State changed due to a call to {@link #stopStreaming()} or * State changed due to a call to {@link #stopStreaming()} or
* {@link android.telephony.MbmsStreamingManager#startStreaming(StreamingServiceInfo, * {@link MbmsStreamingSession#startStreaming(StreamingServiceInfo,
* StreamingServiceCallback, android.os.Handler)} * StreamingServiceCallback, android.os.Handler)}
*/ */
public static final int REASON_BY_USER_REQUEST = 1; public static final int REASON_BY_USER_REQUEST = 1;
@@ -101,6 +103,7 @@ public class StreamingService {
public final static int UNICAST_METHOD = 2; public final static int UNICAST_METHOD = 2;
private final int mSubscriptionId; private final int mSubscriptionId;
private final MbmsStreamingSession mParentSession;
private final StreamingServiceInfo mServiceInfo; private final StreamingServiceInfo mServiceInfo;
private final InternalStreamingServiceCallback mCallback; private final InternalStreamingServiceCallback mCallback;
@@ -111,25 +114,25 @@ public class StreamingService {
*/ */
public StreamingService(int subscriptionId, public StreamingService(int subscriptionId,
IMbmsStreamingService service, IMbmsStreamingService service,
MbmsStreamingSession session,
StreamingServiceInfo streamingServiceInfo, StreamingServiceInfo streamingServiceInfo,
InternalStreamingServiceCallback callback) { InternalStreamingServiceCallback callback) {
mSubscriptionId = subscriptionId; mSubscriptionId = subscriptionId;
mParentSession = session;
mService = service; mService = service;
mServiceInfo = streamingServiceInfo; mServiceInfo = streamingServiceInfo;
mCallback = callback; mCallback = callback;
} }
/** /**
* Retreive the Uri used to play this stream. * Retrieve the Uri used to play this stream.
* *
* This may throw a {@link MbmsException} with the error code * May throw an {@link IllegalArgumentException} or an {@link IllegalStateException}.
* {@link MbmsException#ERROR_MIDDLEWARE_LOST}
* *
* May also throw an {@link IllegalArgumentException} or an {@link IllegalStateException} * @return The {@link Uri} to pass to the streaming client, or {@code null} if an error
* * occurred.
* @return The {@link Uri} to pass to the streaming client.
*/ */
public Uri getPlaybackUri() throws MbmsException { public @Nullable Uri getPlaybackUri() {
if (mService == null) { if (mService == null) {
throw new IllegalStateException("No streaming service attached"); throw new IllegalStateException("No streaming service attached");
} }
@@ -139,25 +142,26 @@ public class StreamingService {
} catch (RemoteException e) { } catch (RemoteException e) {
Log.w(LOG_TAG, "Remote process died"); Log.w(LOG_TAG, "Remote process died");
mService = null; mService = null;
throw new MbmsException(MbmsException.ERROR_MIDDLEWARE_LOST); mParentSession.onStreamingServiceStopped(this);
sendErrorToApp(MbmsException.ERROR_MIDDLEWARE_LOST, null);
return null;
} }
} }
/** /**
* Retreive the info for this StreamingService. * Retrieve the {@link StreamingServiceInfo} corresponding to this stream.
*/ */
public StreamingServiceInfo getInfo() { public StreamingServiceInfo getInfo() {
return mServiceInfo; return mServiceInfo;
} }
/** /**
* Stop streaming this service. * Stop streaming this service. Further operations on this object will fail with an
* This may throw a {@link MbmsException} with the error code * {@link IllegalStateException}.
* {@link MbmsException#ERROR_MIDDLEWARE_LOST}
* *
* May also throw an {@link IllegalArgumentException} or an {@link IllegalStateException} * May throw an {@link IllegalArgumentException} or an {@link IllegalStateException}
*/ */
public void stopStreaming() throws MbmsException { public void stopStreaming() {
if (mService == null) { if (mService == null) {
throw new IllegalStateException("No streaming service attached"); throw new IllegalStateException("No streaming service attached");
} }
@@ -167,32 +171,22 @@ public class StreamingService {
} catch (RemoteException e) { } catch (RemoteException e) {
Log.w(LOG_TAG, "Remote process died"); Log.w(LOG_TAG, "Remote process died");
mService = null; mService = null;
throw new MbmsException(MbmsException.ERROR_MIDDLEWARE_LOST); sendErrorToApp(MbmsException.ERROR_MIDDLEWARE_LOST, null);
}
}
/**
* Disposes of this stream. Further operations on this object will fail with an
* {@link IllegalStateException}.
*
* This may throw a {@link MbmsException} with the error code
* {@link MbmsException#ERROR_MIDDLEWARE_LOST}
* May also throw an {@link IllegalStateException}
*/
public void dispose() throws MbmsException {
if (mService == null) {
throw new IllegalStateException("No streaming service attached");
}
try {
mService.disposeStream(mSubscriptionId, mServiceInfo.getServiceId());
} catch (RemoteException e) {
Log.w(LOG_TAG, "Remote process died");
throw new MbmsException(MbmsException.ERROR_MIDDLEWARE_LOST);
} catch (IllegalArgumentException e) {
throw new IllegalStateException("StreamingService state inconsistent with middleware");
} finally { } finally {
mService = null; mParentSession.onStreamingServiceStopped(this);
}
}
/** @hide */
public InternalStreamingServiceCallback getCallback() {
return mCallback;
}
private void sendErrorToApp(int errorCode, String message) {
try {
mCallback.onError(errorCode, message);
} catch (RemoteException e) {
// Ignore, should not happen locally.
} }
} }
} }

View File

@@ -16,6 +16,8 @@
package android.telephony.mbms; package android.telephony.mbms;
import android.annotation.Nullable;
/** /**
* A callback class for use when the application is actively streaming content. The middleware * A callback class for use when the application is actively streaming content. The middleware
* will provide updates on the status of the stream via this callback. * will provide updates on the status of the stream via this callback.
@@ -37,7 +39,7 @@ public class StreamingServiceCallback {
* @param errorCode The error code. * @param errorCode The error code.
* @param message A human-readable message generated by the middleware for debugging purposes. * @param message A human-readable message generated by the middleware for debugging purposes.
*/ */
public void onError(int errorCode, String message) { public void onError(int errorCode, @Nullable String message) {
// default implementation empty // default implementation empty
} }

View File

@@ -17,7 +17,7 @@
package android.telephony.mbms.vendor; package android.telephony.mbms.vendor;
import android.net.Uri; import android.net.Uri;
import android.telephony.mbms.IMbmsStreamingManagerCallback; import android.telephony.mbms.IMbmsStreamingSessionCallback;
import android.telephony.mbms.IStreamingServiceCallback; import android.telephony.mbms.IStreamingServiceCallback;
import android.telephony.mbms.StreamingServiceInfo; import android.telephony.mbms.StreamingServiceInfo;
@@ -26,18 +26,16 @@ import android.telephony.mbms.StreamingServiceInfo;
*/ */
interface IMbmsStreamingService interface IMbmsStreamingService
{ {
int initialize(IMbmsStreamingManagerCallback listener, int subId); int initialize(IMbmsStreamingSessionCallback callback, int subId);
int getStreamingServices(int subId, in List<String> serviceClasses); int requestUpdateStreamingServices(int subId, in List<String> serviceClasses);
int startStreaming(int subId, String serviceId, int startStreaming(int subId, String serviceId,
IStreamingServiceCallback listener); IStreamingServiceCallback callback);
Uri getPlaybackUri(int subId, String serviceId); Uri getPlaybackUri(int subId, String serviceId);
void stopStreaming(int subId, String serviceId); void stopStreaming(int subId, String serviceId);
void disposeStream(int subId, String serviceId);
void dispose(int subId); void dispose(int subId);
} }

View File

@@ -22,10 +22,10 @@ import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Binder; import android.os.Binder;
import android.os.RemoteException; import android.os.RemoteException;
import android.telephony.mbms.IMbmsStreamingManagerCallback; import android.telephony.mbms.IMbmsStreamingSessionCallback;
import android.telephony.mbms.IStreamingServiceCallback; import android.telephony.mbms.IStreamingServiceCallback;
import android.telephony.mbms.MbmsException; import android.telephony.mbms.MbmsException;
import android.telephony.mbms.MbmsStreamingManagerCallback; import android.telephony.mbms.MbmsStreamingSessionCallback;
import android.telephony.mbms.StreamingService; import android.telephony.mbms.StreamingService;
import android.telephony.mbms.StreamingServiceCallback; import android.telephony.mbms.StreamingServiceCallback;
import android.telephony.mbms.StreamingServiceInfo; import android.telephony.mbms.StreamingServiceInfo;
@@ -48,12 +48,12 @@ public class MbmsStreamingServiceBase extends IMbmsStreamingService.Stub {
* *
* May return any value from {@link android.telephony.mbms.MbmsException.InitializationErrors} * May return any value from {@link android.telephony.mbms.MbmsException.InitializationErrors}
* or {@link MbmsException#SUCCESS}. Non-successful error codes will be passed to the app via * or {@link MbmsException#SUCCESS}. Non-successful error codes will be passed to the app via
* {@link IMbmsStreamingManagerCallback#error(int, String)}. * {@link IMbmsStreamingSessionCallback#onError(int, String)}.
* *
* @param callback The callback to use to communicate with the app. * @param callback The callback to use to communicate with the app.
* @param subscriptionId The subscription ID to use. * @param subscriptionId The subscription ID to use.
*/ */
public int initialize(MbmsStreamingManagerCallback callback, int subscriptionId) public int initialize(MbmsStreamingSessionCallback callback, int subscriptionId)
throws RemoteException { throws RemoteException {
return 0; return 0;
} }
@@ -63,7 +63,7 @@ public class MbmsStreamingServiceBase extends IMbmsStreamingService.Stub {
* @hide * @hide
*/ */
@Override @Override
public final int initialize(final IMbmsStreamingManagerCallback callback, public final int initialize(final IMbmsStreamingSessionCallback callback,
final int subscriptionId) throws RemoteException { final int subscriptionId) throws RemoteException {
final int uid = Binder.getCallingUid(); final int uid = Binder.getCallingUid();
callback.asBinder().linkToDeath(new DeathRecipient() { callback.asBinder().linkToDeath(new DeathRecipient() {
@@ -73,11 +73,11 @@ public class MbmsStreamingServiceBase extends IMbmsStreamingService.Stub {
} }
}, 0); }, 0);
return initialize(new MbmsStreamingManagerCallback() { return initialize(new MbmsStreamingSessionCallback() {
@Override @Override
public void onError(int errorCode, String message) { public void onError(int errorCode, String message) {
try { try {
callback.error(errorCode, message); callback.onError(errorCode, message);
} catch (RemoteException e) { } catch (RemoteException e) {
onAppCallbackDied(uid, subscriptionId); onAppCallbackDied(uid, subscriptionId);
} }
@@ -86,7 +86,7 @@ public class MbmsStreamingServiceBase extends IMbmsStreamingService.Stub {
@Override @Override
public void onStreamingServicesUpdated(List<StreamingServiceInfo> services) { public void onStreamingServicesUpdated(List<StreamingServiceInfo> services) {
try { try {
callback.streamingServicesUpdated(services); callback.onStreamingServicesUpdated(services);
} catch (RemoteException e) { } catch (RemoteException e) {
onAppCallbackDied(uid, subscriptionId); onAppCallbackDied(uid, subscriptionId);
} }
@@ -95,7 +95,7 @@ public class MbmsStreamingServiceBase extends IMbmsStreamingService.Stub {
@Override @Override
public void onMiddlewareReady() { public void onMiddlewareReady() {
try { try {
callback.middlewareReady(); callback.onMiddlewareReady();
} catch (RemoteException e) { } catch (RemoteException e) {
onAppCallbackDied(uid, subscriptionId); onAppCallbackDied(uid, subscriptionId);
} }
@@ -107,7 +107,7 @@ public class MbmsStreamingServiceBase extends IMbmsStreamingService.Stub {
/** /**
* Registers serviceClasses of interest with the appName/subId key. * Registers serviceClasses of interest with the appName/subId key.
* Starts async fetching data on streaming services of matching classes to be reported * Starts async fetching data on streaming services of matching classes to be reported
* later via {@link IMbmsStreamingManagerCallback#streamingServicesUpdated(List)} * later via {@link IMbmsStreamingSessionCallback#onStreamingServicesUpdated(List)}
* *
* Note that subsequent calls with the same uid and subId will replace * Note that subsequent calls with the same uid and subId will replace
* the service class list. * the service class list.
@@ -122,7 +122,7 @@ public class MbmsStreamingServiceBase extends IMbmsStreamingService.Stub {
* {@link android.telephony.mbms.MbmsException.GeneralErrors} * {@link android.telephony.mbms.MbmsException.GeneralErrors}
*/ */
@Override @Override
public int getStreamingServices(int subscriptionId, public int requestUpdateStreamingServices(int subscriptionId,
List<String> serviceClasses) throws RemoteException { List<String> serviceClasses) throws RemoteException {
return 0; return 0;
} }
@@ -130,7 +130,7 @@ public class MbmsStreamingServiceBase extends IMbmsStreamingService.Stub {
/** /**
* Starts streaming on a particular service. This method may perform asynchronous work. When * Starts streaming on a particular service. This method may perform asynchronous work. When
* the middleware is ready to send bits to the frontend, it should inform the app via * the middleware is ready to send bits to the frontend, it should inform the app via
* {@link IStreamingServiceCallback#streamStateUpdated(int, int)}. * {@link IStreamingServiceCallback#onStreamStateUpdated(int, int)}.
* *
* May throw an {@link IllegalArgumentException} or an {@link IllegalStateException} * May throw an {@link IllegalArgumentException} or an {@link IllegalStateException}
* *
@@ -164,7 +164,7 @@ public class MbmsStreamingServiceBase extends IMbmsStreamingService.Stub {
@Override @Override
public void onError(int errorCode, String message) { public void onError(int errorCode, String message) {
try { try {
callback.error(errorCode, message); callback.onError(errorCode, message);
} catch (RemoteException e) { } catch (RemoteException e) {
onAppCallbackDied(uid, subscriptionId); onAppCallbackDied(uid, subscriptionId);
} }
@@ -174,7 +174,7 @@ public class MbmsStreamingServiceBase extends IMbmsStreamingService.Stub {
public void onStreamStateUpdated(@StreamingService.StreamingState int state, public void onStreamStateUpdated(@StreamingService.StreamingState int state,
@StreamingService.StreamingStateChangeReason int reason) { @StreamingService.StreamingStateChangeReason int reason) {
try { try {
callback.streamStateUpdated(state, reason); callback.onStreamStateUpdated(state, reason);
} catch (RemoteException e) { } catch (RemoteException e) {
onAppCallbackDied(uid, subscriptionId); onAppCallbackDied(uid, subscriptionId);
} }
@@ -183,7 +183,7 @@ public class MbmsStreamingServiceBase extends IMbmsStreamingService.Stub {
@Override @Override
public void onMediaDescriptionUpdated() { public void onMediaDescriptionUpdated() {
try { try {
callback.mediaDescriptionUpdated(); callback.onMediaDescriptionUpdated();
} catch (RemoteException e) { } catch (RemoteException e) {
onAppCallbackDied(uid, subscriptionId); onAppCallbackDied(uid, subscriptionId);
} }
@@ -192,7 +192,7 @@ public class MbmsStreamingServiceBase extends IMbmsStreamingService.Stub {
@Override @Override
public void onBroadcastSignalStrengthUpdated(int signalStrength) { public void onBroadcastSignalStrengthUpdated(int signalStrength) {
try { try {
callback.broadcastSignalStrengthUpdated(signalStrength); callback.onBroadcastSignalStrengthUpdated(signalStrength);
} catch (RemoteException e) { } catch (RemoteException e) {
onAppCallbackDied(uid, subscriptionId); onAppCallbackDied(uid, subscriptionId);
} }
@@ -201,7 +201,7 @@ public class MbmsStreamingServiceBase extends IMbmsStreamingService.Stub {
@Override @Override
public void onStreamMethodUpdated(int methodType) { public void onStreamMethodUpdated(int methodType) {
try { try {
callback.streamMethodUpdated(methodType); callback.onStreamMethodUpdated(methodType);
} catch (RemoteException e) { } catch (RemoteException e) {
onAppCallbackDied(uid, subscriptionId); onAppCallbackDied(uid, subscriptionId);
} }
@@ -228,7 +228,11 @@ public class MbmsStreamingServiceBase extends IMbmsStreamingService.Stub {
/** /**
* Stop streaming the stream identified by {@code serviceId}. Notification of the resulting * Stop streaming the stream identified by {@code serviceId}. Notification of the resulting
* stream state change should be reported to the app via * stream state change should be reported to the app via
* {@link IStreamingServiceCallback#streamStateUpdated(int, int)}. * {@link IStreamingServiceCallback#onStreamStateUpdated(int, int)}.
*
* In addition, the callback provided via
* {@link #startStreaming(int, String, IStreamingServiceCallback)} should no longer be
* used after this method has called by the app.
* *
* May throw an {@link IllegalArgumentException} or an {@link IllegalStateException} * May throw an {@link IllegalArgumentException} or an {@link IllegalStateException}
* *
@@ -240,28 +244,11 @@ public class MbmsStreamingServiceBase extends IMbmsStreamingService.Stub {
throws RemoteException { throws RemoteException {
} }
/**
* Dispose of the stream identified by {@code serviceId} for the app identified by the
* {@code appName} and {@code subscriptionId} arguments along with the caller's uid.
* No notification back to the app is required for this operation, and the callback provided via
* {@link #startStreaming(int, String, IStreamingServiceCallback)} should no longer be
* used after this method has called by the app.
*
* May throw an {@link IllegalArgumentException} or an {@link IllegalStateException}
*
* @param subscriptionId The subscription id to use.
* @param serviceId The ID of the streaming service that the app wishes to dispose of.
*/
@Override
public void disposeStream(int subscriptionId, String serviceId)
throws RemoteException {
}
/** /**
* Signals that the app wishes to dispose of the session identified by the * Signals that the app wishes to dispose of the session identified by the
* {@code subscriptionId} argument and the caller's uid. No notification back to the * {@code subscriptionId} argument and the caller's uid. No notification back to the
* app is required for this operation, and the corresponding callback provided via * app is required for this operation, and the corresponding callback provided via
* {@link #initialize(IMbmsStreamingManagerCallback, int)} should no longer be used * {@link #initialize(IMbmsStreamingSessionCallback, int)} should no longer be used
* after this method has been called by the app. * after this method has been called by the app.
* *
* May throw an {@link IllegalStateException} * May throw an {@link IllegalStateException}