Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 64e22af3 authored by Hall Liu's avatar Hall Liu
Browse files

EMBMS - Add TestApi and provide service override

Add @TestApi annotations to methods that CTS needs
Add a manifest meta-data key that allows client apps to specify the
exact component name of the MBMS service to bind to.

Bug: 68049452
Test: CTS
Change-Id: I50654c41da38696a25fad93d0a5e0b0c11fa0b42
parent 9009eabb
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -40025,6 +40025,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
@@ -40046,6 +40047,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<java.lang.String>);
    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 {
@@ -40821,6 +40823,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.util.Locale, java.lang.String>, java.lang.String, java.util.List<java.util.Locale>, 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<android.telephony.mbms.StreamingServiceInfo> CREATOR;
@@ -40828,6 +40831,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<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 void stopStreaming(int, java.lang.String) throws android.os.RemoteException;
  }
}
package android.test {
  public abstract deprecated class ActivityInstrumentationTestCase<T extends android.app.Activity> extends android.test.ActivityTestCase {
+9 −0
Original line number Diff line number Diff line
@@ -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)}
+9 −0
Original line number Diff line number Diff line
@@ -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<IMbmsStreamingService> mService = new AtomicReference<>(null);
+49 −7
Original line number Diff line number Diff line
@@ -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<ResolveInfo> downloadServices = packageManager.queryIntentServices(queryIntent,

        ComponentName overrideService = getOverrideServiceName(context, serviceAction);
        List<ResolveInfo> services;
        if (overrideService == null) {
            services = packageManager.queryIntentServices(queryIntent,
                    PackageManager.MATCH_SYSTEM_ONLY);
        } else {
            queryIntent.setComponent(overrideService);
            services = packageManager.queryIntentServices(queryIntent,
                    PackageManager.MATCH_ALL);
        }

        if (downloadServices == null || downloadServices.size() == 0) {
            Log.w(LOG_TAG, "No download services found, cannot get service info");
        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,
+2 −0
Original line number Diff line number Diff line
@@ -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<Locale, String> names, String className,
            List<Locale> locales, String serviceId, Date start, Date end) {
        super(names, className, locales, serviceId, start, end);
Loading