diff --git a/api/test-current.txt b/api/test-current.txt index 7959cd3d87065..4163faf39c25e 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -40042,6 +40042,7 @@ package android.telephony { field public static final java.lang.String EXTRA_MBMS_DOWNLOAD_REQUEST = "android.telephony.extra.MBMS_DOWNLOAD_REQUEST"; field public static final java.lang.String EXTRA_MBMS_DOWNLOAD_RESULT = "android.telephony.extra.MBMS_DOWNLOAD_RESULT"; field public static final java.lang.String EXTRA_MBMS_FILE_INFO = "android.telephony.extra.MBMS_FILE_INFO"; + field public static final java.lang.String MBMS_DOWNLOAD_SERVICE_OVERRIDE_METADATA = "mbms-download-service-override"; field public static final int RESULT_CANCELLED = 2; // 0x2 field public static final int RESULT_DOWNLOAD_FAILURE = 6; // 0x6 field public static final int RESULT_EXPIRED = 3; // 0x3 @@ -40063,6 +40064,7 @@ package android.telephony { method public static android.telephony.MbmsStreamingSession create(android.content.Context, android.telephony.mbms.MbmsStreamingSessionCallback, android.os.Handler); method public void requestUpdateStreamingServices(java.util.List); method public android.telephony.mbms.StreamingService startStreaming(android.telephony.mbms.StreamingServiceInfo, android.telephony.mbms.StreamingServiceCallback, android.os.Handler); + field public static final java.lang.String MBMS_STREAMING_SERVICE_OVERRIDE_METADATA = "mbms-streaming-service-override"; } public class NeighboringCellInfo implements android.os.Parcelable { @@ -40838,6 +40840,7 @@ package android.telephony.mbms { } public final class StreamingServiceInfo extends android.telephony.mbms.ServiceInfo implements android.os.Parcelable { + ctor public StreamingServiceInfo(java.util.Map, java.lang.String, java.util.List, java.lang.String, java.util.Date, java.util.Date); method public int describeContents(); method public void writeToParcel(android.os.Parcel, int); field public static final android.os.Parcelable.Creator CREATOR; @@ -40845,6 +40848,21 @@ package android.telephony.mbms { } +package android.telephony.mbms.vendor { + + public class MbmsStreamingServiceBase extends android.os.Binder { + ctor public MbmsStreamingServiceBase(); + method public void dispose(int) throws android.os.RemoteException; + method public android.net.Uri getPlaybackUri(int, java.lang.String) throws android.os.RemoteException; + method public int initialize(android.telephony.mbms.MbmsStreamingSessionCallback, int) throws android.os.RemoteException; + method public void onAppCallbackDied(int, int); + method public int requestUpdateStreamingServices(int, java.util.List) 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; + } + +} + package android.test { public abstract deprecated class ActivityInstrumentationTestCase extends android.test.ActivityTestCase { diff --git a/telephony/java/android/telephony/MbmsDownloadSession.java b/telephony/java/android/telephony/MbmsDownloadSession.java index 9a9877a885175..f392570ecb29b 100644 --- a/telephony/java/android/telephony/MbmsDownloadSession.java +++ b/telephony/java/android/telephony/MbmsDownloadSession.java @@ -21,6 +21,7 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SdkConstant; import android.annotation.SystemApi; +import android.annotation.TestApi; import android.content.ComponentName; import android.content.Context; import android.content.Intent; @@ -73,6 +74,14 @@ public class MbmsDownloadSession implements AutoCloseable { public static final String MBMS_DOWNLOAD_SERVICE_ACTION = "android.telephony.action.EmbmsDownload"; + /** + * Metadata key that specifies the component name of the service to bind to for file-download. + * @hide + */ + @TestApi + public static final String MBMS_DOWNLOAD_SERVICE_OVERRIDE_METADATA = + "mbms-download-service-override"; + /** * Integer extra that Android will attach to the intent supplied via * {@link android.telephony.mbms.DownloadRequest.Builder#setAppIntent(Intent)} diff --git a/telephony/java/android/telephony/MbmsStreamingSession.java b/telephony/java/android/telephony/MbmsStreamingSession.java index a8c46079148ce..fb2ff7b178b1c 100644 --- a/telephony/java/android/telephony/MbmsStreamingSession.java +++ b/telephony/java/android/telephony/MbmsStreamingSession.java @@ -20,6 +20,7 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SdkConstant; import android.annotation.SystemApi; +import android.annotation.TestApi; import android.content.ComponentName; import android.content.Context; import android.content.ServiceConnection; @@ -62,6 +63,14 @@ public class MbmsStreamingSession implements AutoCloseable { public static final String MBMS_STREAMING_SERVICE_ACTION = "android.telephony.action.EmbmsStreaming"; + /** + * Metadata key that specifies the component name of the service to bind to for file-download. + * @hide + */ + @TestApi + public static final String MBMS_STREAMING_SERVICE_OVERRIDE_METADATA = + "mbms-streaming-service-override"; + private static AtomicBoolean sIsInitialized = new AtomicBoolean(false); private AtomicReference mService = new AtomicReference<>(null); diff --git a/telephony/java/android/telephony/mbms/MbmsUtils.java b/telephony/java/android/telephony/mbms/MbmsUtils.java index d38d8a712c736..b4ad1d77760a3 100644 --- a/telephony/java/android/telephony/mbms/MbmsUtils.java +++ b/telephony/java/android/telephony/mbms/MbmsUtils.java @@ -22,6 +22,8 @@ import android.content.Intent; import android.content.ServiceConnection; import android.content.pm.*; import android.content.pm.ServiceInfo; +import android.telephony.MbmsDownloadSession; +import android.telephony.MbmsStreamingSession; import android.util.Log; import java.io.File; @@ -48,24 +50,64 @@ public class MbmsUtils { return new ComponentName(ci.packageName, ci.name); } + private static ComponentName getOverrideServiceName(Context context, String serviceAction) { + String metaDataKey = null; + switch (serviceAction) { + case MbmsDownloadSession.MBMS_DOWNLOAD_SERVICE_ACTION: + metaDataKey = MbmsDownloadSession.MBMS_DOWNLOAD_SERVICE_OVERRIDE_METADATA; + break; + case MbmsStreamingSession.MBMS_STREAMING_SERVICE_ACTION: + metaDataKey = MbmsStreamingSession.MBMS_STREAMING_SERVICE_OVERRIDE_METADATA; + break; + } + if (metaDataKey == null) { + return null; + } + + ApplicationInfo appInfo; + try { + appInfo = context.getPackageManager() + .getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); + } catch (PackageManager.NameNotFoundException e) { + return null; + } + if (appInfo.metaData == null) { + return null; + } + String serviceComponent = appInfo.metaData.getString(metaDataKey); + if (serviceComponent == null) { + return null; + } + return ComponentName.unflattenFromString(serviceComponent); + } + public static ServiceInfo getMiddlewareServiceInfo(Context context, String serviceAction) { // Query for the proper service PackageManager packageManager = context.getPackageManager(); Intent queryIntent = new Intent(); queryIntent.setAction(serviceAction); - List downloadServices = packageManager.queryIntentServices(queryIntent, - PackageManager.MATCH_SYSTEM_ONLY); - if (downloadServices == null || downloadServices.size() == 0) { - Log.w(LOG_TAG, "No download services found, cannot get service info"); + ComponentName overrideService = getOverrideServiceName(context, serviceAction); + List services; + if (overrideService == null) { + services = packageManager.queryIntentServices(queryIntent, + PackageManager.MATCH_SYSTEM_ONLY); + } else { + queryIntent.setComponent(overrideService); + services = packageManager.queryIntentServices(queryIntent, + PackageManager.MATCH_ALL); + } + + if (services == null || services.size() == 0) { + Log.w(LOG_TAG, "No MBMS services found, cannot get service info"); return null; } - if (downloadServices.size() > 1) { - Log.w(LOG_TAG, "More than one download service found, cannot get unique service"); + if (services.size() > 1) { + Log.w(LOG_TAG, "More than one MBMS service found, cannot get unique service"); return null; } - return downloadServices.get(0).serviceInfo; + return services.get(0).serviceInfo; } public static int startBinding(Context context, String serviceAction, diff --git a/telephony/java/android/telephony/mbms/StreamingServiceInfo.java b/telephony/java/android/telephony/mbms/StreamingServiceInfo.java index c704f346e311c..ef2a14aa26b35 100644 --- a/telephony/java/android/telephony/mbms/StreamingServiceInfo.java +++ b/telephony/java/android/telephony/mbms/StreamingServiceInfo.java @@ -17,6 +17,7 @@ package android.telephony.mbms; import android.annotation.SystemApi; +import android.annotation.TestApi; import android.os.Parcel; import android.os.Parcelable; @@ -41,6 +42,7 @@ public final class StreamingServiceInfo extends ServiceInfo implements Parcelabl * @hide */ @SystemApi + @TestApi public StreamingServiceInfo(Map names, String className, List locales, String serviceId, Date start, Date end) { super(names, className, locales, serviceId, start, end); diff --git a/telephony/java/android/telephony/mbms/vendor/MbmsStreamingServiceBase.java b/telephony/java/android/telephony/mbms/vendor/MbmsStreamingServiceBase.java index a2381536ac0c2..db177c0c77688 100644 --- a/telephony/java/android/telephony/mbms/vendor/MbmsStreamingServiceBase.java +++ b/telephony/java/android/telephony/mbms/vendor/MbmsStreamingServiceBase.java @@ -18,6 +18,7 @@ package android.telephony.mbms.vendor; import android.annotation.Nullable; import android.annotation.SystemApi; +import android.annotation.TestApi; import android.content.Intent; import android.net.Uri; import android.os.Binder; @@ -38,6 +39,7 @@ import java.util.List; * @hide */ @SystemApi +@TestApi public class MbmsStreamingServiceBase extends IMbmsStreamingService.Stub { /** * Initialize streaming service for this app and subId, registering the listener.