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

Commit df20c630 authored by Sungsoo Lim's avatar Sungsoo Lim
Browse files

Make MediaRouter2Manager provide correct system routes info

System route info could be changed per different apps. For example,
when a BT headset is connected, if a media app call
MediaRouter.selectRoute(defaultRoute) via Jetpack lib, the app will use
the phone speaker while the other media apps use the BT headset.

System UI should be changed depends on this CL.

Bug: 156549746
Test: atest mediaroutertest
      atest CtsMediaTestCases:android.media.cts.SystemMediaRouter2Test
Ignore-AOSP-First: AOSP doesn't have SystemMediaRouter2Test
Change-Id: Ie24f97023b7113a2b59f0b55ab7b4230b394e9bd
parent 7066b46f
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -4319,6 +4319,9 @@
         doesn't support the work profile. [CHAR LIMIT=100] -->
    <string name="activity_resolver_work_profiles_support">%1$s doesn\'t support work profile</string>

    <!-- DO NOT TRANSLATE -->
    <string name="default_audio_route_id">default_audio_route</string>

    <!-- Name of the default audio route for tablets when nothing
         is connected to a headphone or other wired audio output jack. [CHAR LIMIT=50] -->
    <string name="default_audio_route_name" product="tablet">Tablet</string>
@@ -4347,6 +4350,9 @@
    <!-- Name of the default audio route category. [CHAR LIMIT=50] -->
    <string name="default_audio_route_category_name">System</string>

    <!-- DO NOT TRANSLATE -->
    <string name="bluetooth_a2dp_audio_route_id">bluetooth_a2dp_audio_route</string>

    <!-- Description of the bluetooth a2dp audio route. [CHAR LIMIT=50] -->
    <string name="bluetooth_a2dp_audio_route_name">Bluetooth audio</string>

+2 −0
Original line number Diff line number Diff line
@@ -1082,6 +1082,7 @@
  <java-symbol type="string" name="granularity_label_word" />
  <java-symbol type="string" name="granularity_label_link" />
  <java-symbol type="string" name="granularity_label_line" />
  <java-symbol type="string" name="default_audio_route_id" />
  <java-symbol type="string" name="default_audio_route_name" />
  <java-symbol type="string" name="default_audio_route_name_dock_speakers" />
  <java-symbol type="string" name="default_audio_route_name_hdmi" />
@@ -1663,6 +1664,7 @@
  <java-symbol type="string" name="media_route_chooser_title" />
  <java-symbol type="string" name="media_route_chooser_title_for_remote_display" />
  <java-symbol type="string" name="media_route_controller_disconnect" />
  <java-symbol type="string" name="bluetooth_a2dp_audio_route_id" />
  <java-symbol type="string" name="bluetooth_a2dp_audio_route_name" />

  <java-symbol type="dimen" name="config_minScalingSpan" />
+1 −0
Original line number Diff line number Diff line
@@ -486,6 +486,7 @@ applications that come with the platform
        <permission name="android.permission.SCHEDULE_PRIORITIZED_ALARM" />
        <!-- Permission required for CTS test - SystemMediaRouter2Test -->
        <permission name="android.permission.MEDIA_CONTENT_CONTROL"/>
        <permission name="android.permission.MODIFY_AUDIO_ROUTING"/>
        <!-- Permission required for CTS test - CtsPermission5TestCases -->
        <permission name="android.permission.RENOUNCE_PERMISSIONS" />
        <permission name="android.permission.WRITE_EMBEDDED_SUBSCRIPTIONS" />
+3 −1
Original line number Diff line number Diff line
@@ -69,7 +69,9 @@ interface IMediaRouterService {
    void releaseSessionWithRouter2(IMediaRouter2 router, String sessionId);

    // Methods for MediaRouter2Manager
    List<RoutingSessionInfo> getActiveSessions(IMediaRouter2Manager manager);
    List<RoutingSessionInfo> getRemoteSessions(IMediaRouter2Manager manager);
    RoutingSessionInfo getSystemSessionInfoForPackage(
            IMediaRouter2Manager manager, String packageName);
    void registerManager(IMediaRouter2Manager manager, String packageName);
    void unregisterManager(IMediaRouter2Manager manager);
    void setRouteVolumeWithManager(IMediaRouter2Manager manager, int requestId,
+23 −15
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import android.util.SparseIntArray;
import android.view.Display;
import android.view.DisplayAddress;

import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;

import java.lang.annotation.Retention;
@@ -148,7 +149,7 @@ public class MediaRouter {
                    ServiceManager.getService(Context.MEDIA_ROUTER_SERVICE));

            mSystemCategory = new RouteCategory(
                    com.android.internal.R.string.default_audio_route_category_name,
                    R.string.default_audio_route_category_name,
                    ROUTE_TYPE_LIVE_AUDIO | ROUTE_TYPE_LIVE_VIDEO, false);
            mSystemCategory.mIsSystem = true;

@@ -163,14 +164,15 @@ public class MediaRouter {
        // Called after sStatic is initialized
        void startMonitoringRoutes(Context appContext) {
            mDefaultAudioVideo = new RouteInfo(mSystemCategory);
            mDefaultAudioVideo.mNameResId = com.android.internal.R.string.default_audio_route_name;
            mDefaultAudioVideo.mNameResId = R.string.default_audio_route_name;
            mDefaultAudioVideo.mSupportedTypes = ROUTE_TYPE_LIVE_AUDIO | ROUTE_TYPE_LIVE_VIDEO;
            mDefaultAudioVideo.updatePresentationDisplay();
            if (((AudioManager) appContext.getSystemService(Context.AUDIO_SERVICE))
                    .isVolumeFixed()) {
                mDefaultAudioVideo.mVolumeHandling = RouteInfo.PLAYBACK_VOLUME_FIXED;
            }

            mDefaultAudioVideo.mGlobalRouteId = sStatic.mResources.getString(
                    R.string.default_audio_route_id);
            addRouteStatic(mDefaultAudioVideo);

            // This will select the active wifi display route if there is one.
@@ -215,15 +217,15 @@ public class MediaRouter {
                int name;
                if ((newRoutes.mainType & AudioRoutesInfo.MAIN_HEADPHONES) != 0
                        || (newRoutes.mainType & AudioRoutesInfo.MAIN_HEADSET) != 0) {
                    name = com.android.internal.R.string.default_audio_route_name_headphones;
                    name = R.string.default_audio_route_name_headphones;
                } else if ((newRoutes.mainType & AudioRoutesInfo.MAIN_DOCK_SPEAKERS) != 0) {
                    name = com.android.internal.R.string.default_audio_route_name_dock_speakers;
                    name = R.string.default_audio_route_name_dock_speakers;
                } else if ((newRoutes.mainType&AudioRoutesInfo.MAIN_HDMI) != 0) {
                    name = com.android.internal.R.string.default_audio_route_name_hdmi;
                    name = R.string.default_audio_route_name_hdmi;
                } else if ((newRoutes.mainType&AudioRoutesInfo.MAIN_USB) != 0) {
                    name = com.android.internal.R.string.default_audio_route_name_usb;
                    name = R.string.default_audio_route_name_usb;
                } else {
                    name = com.android.internal.R.string.default_audio_route_name;
                    name = R.string.default_audio_route_name;
                }
                mDefaultAudioVideo.mNameResId = name;
                dispatchRouteChanged(mDefaultAudioVideo);
@@ -243,9 +245,12 @@ public class MediaRouter {
                        final RouteInfo info = new RouteInfo(mSystemCategory);
                        info.mName = newRoutes.bluetoothName;
                        info.mDescription = mResources.getText(
                                com.android.internal.R.string.bluetooth_a2dp_audio_route_name);
                                R.string.bluetooth_a2dp_audio_route_name);
                        info.mSupportedTypes = ROUTE_TYPE_LIVE_AUDIO;
                        info.mDeviceType = RouteInfo.DEVICE_TYPE_BLUETOOTH;
                        info.mGlobalRouteId = sStatic.mResources.getString(
                                R.string.bluetooth_a2dp_audio_route_id);

                        mBluetoothA2dpRoute = info;
                        addRouteStatic(mBluetoothA2dpRoute);
                    } else {
@@ -508,6 +513,9 @@ public class MediaRouter {
            outer: for (int i = mRoutes.size(); i-- > 0; ) {
                final RouteInfo route = mRoutes.get(i);
                final String globalRouteId = route.mGlobalRouteId;
                if (route.isDefault() || route.isBluetooth()) {
                    continue;
                }
                if (globalRouteId != null) {
                    for (int j = 0; j < globalRouteCount; j++) {
                        MediaRouterClientState.RouteInfo globalRoute = globalRoutes.get(j);
@@ -1572,7 +1580,7 @@ public class MediaRouter {
        newRoute.mEnabled = isWifiDisplayEnabled(display, wfdStatus);
        newRoute.mName = display.getFriendlyDisplayName();
        newRoute.mDescription = sStatic.mResources.getText(
                com.android.internal.R.string.wireless_display_route_description);
                R.string.wireless_display_route_description);
        newRoute.updatePresentationDisplay();
        newRoute.mDeviceType = RouteInfo.DEVICE_TYPE_TV;
        return newRoute;
@@ -1867,19 +1875,19 @@ public class MediaRouter {
            int resId;
            switch (statusCode) {
                case STATUS_SCANNING:
                    resId = com.android.internal.R.string.media_route_status_scanning;
                    resId = R.string.media_route_status_scanning;
                    break;
                case STATUS_CONNECTING:
                    resId = com.android.internal.R.string.media_route_status_connecting;
                    resId = R.string.media_route_status_connecting;
                    break;
                case STATUS_AVAILABLE:
                    resId = com.android.internal.R.string.media_route_status_available;
                    resId = R.string.media_route_status_available;
                    break;
                case STATUS_NOT_AVAILABLE:
                    resId = com.android.internal.R.string.media_route_status_not_available;
                    resId = R.string.media_route_status_not_available;
                    break;
                case STATUS_IN_USE:
                    resId = com.android.internal.R.string.media_route_status_in_use;
                    resId = R.string.media_route_status_in_use;
                    break;
                case STATUS_CONNECTED:
                case STATUS_NONE:
Loading