Skip to content

Commit 705ab80

Browse files
committed
Add wireless display selection support to MediaRouter.
* Adds the new route type LIVE_VIDEO * Wireless displays support both LIVE_VIDEO and LIVE_AUDIO, making wireless display routes valid selections in when apps make selecting live audio routes available. * MediaRouter will only report/manipulate wireless displays that have already been paired at the system level. Bug 7177920 Change-Id: Ic221b8687d77b4c0df9801c396b74870e86206e9
1 parent 9dbbfcd commit 705ab80

File tree

7 files changed

+351
-50
lines changed

7 files changed

+351
-50
lines changed

api/current.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11750,6 +11750,7 @@ package android.media {
1175011750
method public void removeUserRoute(android.media.MediaRouter.UserRouteInfo);
1175111751
method public void selectRoute(int, android.media.MediaRouter.RouteInfo);
1175211752
field public static final int ROUTE_TYPE_LIVE_AUDIO = 1; // 0x1
11753+
field public static final int ROUTE_TYPE_LIVE_VIDEO = 2; // 0x2
1175311754
field public static final int ROUTE_TYPE_USER = 8388608; // 0x800000
1175411755
}
1175511756

@@ -11798,6 +11799,7 @@ package android.media {
1179811799
method public int getVolume();
1179911800
method public int getVolumeHandling();
1180011801
method public int getVolumeMax();
11802+
method public boolean isEnabled();
1180111803
method public void requestSetVolume(int);
1180211804
method public void requestUpdateVolume(int);
1180311805
method public void setTag(java.lang.Object);

core/java/android/app/MediaRouteButton.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,21 +221,28 @@ void updateRemoteIndicator() {
221221
void updateRouteCount() {
222222
final int N = mRouter.getRouteCount();
223223
int count = 0;
224+
boolean hasVideoRoutes = false;
224225
for (int i = 0; i < N; i++) {
225226
final RouteInfo route = mRouter.getRouteAt(i);
226-
if ((route.getSupportedTypes() & mRouteTypes) != 0) {
227+
final int routeTypes = route.getSupportedTypes();
228+
if ((routeTypes & mRouteTypes) != 0) {
227229
if (route instanceof RouteGroup) {
228230
count += ((RouteGroup) route).getRouteCount();
229231
} else {
230232
count++;
231233
}
234+
if ((routeTypes & MediaRouter.ROUTE_TYPE_LIVE_VIDEO) != 0) {
235+
hasVideoRoutes = true;
236+
}
232237
}
233238
}
234239

235240
setEnabled(count != 0);
236241

237-
// Only allow toggling if we have more than just user routes
238-
mToggleMode = count == 2 && (mRouteTypes & MediaRouter.ROUTE_TYPE_LIVE_AUDIO) != 0;
242+
// Only allow toggling if we have more than just user routes.
243+
// Don't toggle if we support video routes, we may have to let the dialog scan.
244+
mToggleMode = count == 2 && (mRouteTypes & MediaRouter.ROUTE_TYPE_LIVE_AUDIO) != 0 &&
245+
!hasVideoRoutes;
239246
}
240247

241248
@Override

core/java/com/android/internal/app/MediaRouteChooserDialogFragment.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import android.app.MediaRouteButton;
2626
import android.content.Context;
2727
import android.graphics.drawable.Drawable;
28-
import android.media.AudioManager;
28+
import android.hardware.display.DisplayManager;
2929
import android.media.MediaRouter;
3030
import android.media.MediaRouter.RouteCategory;
3131
import android.media.MediaRouter.RouteGroup;
@@ -70,6 +70,7 @@ public class MediaRouteChooserDialogFragment extends DialogFragment {
7070
};
7171

7272
MediaRouter mRouter;
73+
DisplayManager mDisplayService;
7374
private int mRouteTypes;
7475

7576
private LayoutInflater mInflater;
@@ -97,6 +98,7 @@ public void setLauncherListener(LauncherListener listener) {
9798
public void onAttach(Activity activity) {
9899
super.onAttach(activity);
99100
mRouter = (MediaRouter) activity.getSystemService(Context.MEDIA_ROUTER_SERVICE);
101+
mDisplayService = (DisplayManager) activity.getSystemService(Context.DISPLAY_SERVICE);
100102
}
101103

102104
@Override
@@ -119,6 +121,15 @@ public void setExtendedSettingsClickListener(View.OnClickListener listener) {
119121

120122
public void setRouteTypes(int types) {
121123
mRouteTypes = types;
124+
if ((mRouteTypes & MediaRouter.ROUTE_TYPE_LIVE_VIDEO) != 0 && mDisplayService == null) {
125+
final Context activity = getActivity();
126+
if (activity != null) {
127+
mDisplayService = (DisplayManager) activity.getSystemService(
128+
Context.DISPLAY_SERVICE);
129+
}
130+
} else {
131+
mDisplayService = null;
132+
}
122133
}
123134

124135
void updateVolume() {
@@ -194,6 +205,9 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
194205
@Override
195206
public void onResume() {
196207
super.onResume();
208+
if (mDisplayService != null) {
209+
mDisplayService.scanWifiDisplays();
210+
}
197211
}
198212

199213
private static class ViewHolder {
@@ -253,7 +267,9 @@ void update() {
253267
final RouteCategory cat = mRouter.getCategoryAt(i);
254268
routes = cat.getRoutes(mCatRouteList);
255269

256-
mItems.add(cat);
270+
if (!cat.isSystem()) {
271+
mItems.add(cat);
272+
}
257273

258274
if (cat == mCategoryEditingGroups) {
259275
addGroupEditingCategoryRoutes(routes);
@@ -370,6 +386,7 @@ public boolean areAllItemsEnabled() {
370386
public boolean isEnabled(int position) {
371387
switch (getItemViewType(position)) {
372388
case VIEW_ROUTE:
389+
return ((RouteInfo) mItems.get(position)).isEnabled();
373390
case VIEW_GROUPING_ROUTE:
374391
case VIEW_GROUPING_DONE:
375392
return true;
@@ -434,6 +451,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
434451
}
435452

436453
convertView.setActivated(position == mSelectedItemPosition);
454+
convertView.setEnabled(isEnabled(position));
437455

438456
return convertView;
439457
}

core/res/res/layout/media_route_list_item.xml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,33 @@
2424
android:layout_height="56dp"
2525
android:scaleType="center"
2626
android:id="@+id/icon"
27-
android:visibility="gone" />
27+
android:visibility="gone"
28+
android:duplicateParentState="true" />
2829

2930
<LinearLayout android:layout_width="0dp"
3031
android:layout_height="match_parent"
3132
android:layout_weight="1"
3233
android:orientation="vertical"
3334
android:gravity="start|center_vertical"
3435
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
35-
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
36+
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
37+
android:duplicateParentState="true">
3638

3739
<TextView android:id="@android:id/text1"
3840
android:layout_width="match_parent"
3941
android:layout_height="wrap_content"
4042
android:singleLine="true"
4143
android:ellipsize="marquee"
42-
android:textAppearance="?android:attr/textAppearanceMedium" />
44+
android:textAppearance="?android:attr/textAppearanceMedium"
45+
android:duplicateParentState="true" />
4346

4447
<TextView android:id="@android:id/text2"
4548
android:layout_width="match_parent"
4649
android:layout_height="wrap_content"
4750
android:singleLine="true"
4851
android:ellipsize="marquee"
49-
android:textAppearance="?android:attr/textAppearanceSmall" />
52+
android:textAppearance="?android:attr/textAppearanceSmall"
53+
android:duplicateParentState="true" />
5054
</LinearLayout>
5155

5256
<ImageButton
@@ -56,6 +60,7 @@
5660
android:background="?android:attr/selectableItemBackground"
5761
android:src="@drawable/ic_media_group_expand"
5862
android:scaleType="center"
59-
android:visibility="gone" />
63+
android:visibility="gone"
64+
android:duplicateParentState="true" />
6065

6166
</LinearLayout>

core/res/res/values/strings.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3783,6 +3783,18 @@
37833783
<!-- Content description of a MediaRouteButton for accessibility support -->
37843784
<string name="media_route_button_content_description">Media output</string>
37853785

3786+
<!-- Status message for remote routes attempting to scan/determine availability -->
3787+
<string name="media_route_status_scanning">Scanning...</string>
3788+
3789+
<!-- Status message for a remote route attempting to connect -->
3790+
<string name="media_route_status_connecting">Connecting...</string>
3791+
3792+
<!-- Status message for a remote route that is confirmed to be available for connection -->
3793+
<string name="media_route_status_available">Available</string>
3794+
3795+
<!-- Status message for remote routes that are not available for connection right now -->
3796+
<string name="media_route_status_not_available">Not available</string>
3797+
37863798
<!-- Display manager service -->
37873799

37883800
<!-- Name of the built-in display. [CHAR LIMIT=50] -->

core/res/res/values/symbols.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,10 @@
826826
<java-symbol type="string" name="default_audio_route_name_hdmi" />
827827
<java-symbol type="string" name="default_audio_route_category_name" />
828828
<java-symbol type="string" name="safe_media_volume_warning" />
829+
<java-symbol type="string" name="media_route_status_scanning" />
830+
<java-symbol type="string" name="media_route_status_connecting" />
831+
<java-symbol type="string" name="media_route_status_available" />
832+
<java-symbol type="string" name="media_route_status_not_available" />
829833

830834
<java-symbol type="plurals" name="abbrev_in_num_days" />
831835
<java-symbol type="plurals" name="abbrev_in_num_hours" />

0 commit comments

Comments
 (0)