169b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown/* 269b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown * Copyright (C) 2013 The Android Open Source Project 369b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown * 469b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown * Licensed under the Apache License, Version 2.0 (the "License"); 569b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown * you may not use this file except in compliance with the License. 669b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown * You may obtain a copy of the License at 769b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown * 869b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown * http://www.apache.org/licenses/LICENSE-2.0 969b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown * 1069b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown * Unless required by applicable law or agreed to in writing, software 1169b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown * distributed under the License is distributed on an "AS IS" BASIS, 1269b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1369b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown * See the License for the specific language governing permissions and 1469b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown * limitations under the License. 1569b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown */ 1669b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown 1769b07161bebdb2c726e3a826c2268866f1a94517Jeff Brownpackage android.media; 1869b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown 1969b07161bebdb2c726e3a826c2268866f1a94517Jeff Brownimport android.os.Parcel; 2069b07161bebdb2c726e3a826c2268866f1a94517Jeff Brownimport android.os.Parcelable; 2169b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown 2269b07161bebdb2c726e3a826c2268866f1a94517Jeff Brownimport java.util.ArrayList; 2369b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown 2469b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown/** 2569b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown * Information available from MediaRouterService about the state perceived by 2669b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown * a particular client and the routes that are available to it. 2769b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown * 2869b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown * Clients must not modify the contents of this object. 2969b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown * @hide 3069b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown */ 3169b07161bebdb2c726e3a826c2268866f1a94517Jeff Brownpublic final class MediaRouterClientState implements Parcelable { 3269b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown /** 3369b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown * A list of all known routes. 3469b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown */ 3569b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown public final ArrayList<RouteInfo> routes; 3669b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown 3769b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown /** 3869b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown * The id of the current globally selected route, or null if none. 3969b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown * Globally selected routes override any other route selections that applications 4069b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown * may have made. Used for remote displays. 4169b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown */ 4269b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown public String globallySelectedRouteId; 4369b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown 4469b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown public MediaRouterClientState() { 4569b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown routes = new ArrayList<RouteInfo>(); 4669b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown } 4769b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown 4869b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown MediaRouterClientState(Parcel src) { 4969b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown routes = src.createTypedArrayList(RouteInfo.CREATOR); 5069b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown globallySelectedRouteId = src.readString(); 5169b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown } 5269b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown 53af574183c274f51d04487a9c8355e9f34a1150f2Jeff Brown public RouteInfo getRoute(String id) { 54af574183c274f51d04487a9c8355e9f34a1150f2Jeff Brown final int count = routes.size(); 55af574183c274f51d04487a9c8355e9f34a1150f2Jeff Brown for (int i = 0; i < count; i++) { 56af574183c274f51d04487a9c8355e9f34a1150f2Jeff Brown final RouteInfo route = routes.get(i); 57af574183c274f51d04487a9c8355e9f34a1150f2Jeff Brown if (route.id.equals(id)) { 58af574183c274f51d04487a9c8355e9f34a1150f2Jeff Brown return route; 59af574183c274f51d04487a9c8355e9f34a1150f2Jeff Brown } 60af574183c274f51d04487a9c8355e9f34a1150f2Jeff Brown } 61af574183c274f51d04487a9c8355e9f34a1150f2Jeff Brown return null; 62af574183c274f51d04487a9c8355e9f34a1150f2Jeff Brown } 63af574183c274f51d04487a9c8355e9f34a1150f2Jeff Brown 6469b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown @Override 6569b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown public int describeContents() { 6669b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown return 0; 6769b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown } 6869b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown 6969b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown @Override 7069b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown public void writeToParcel(Parcel dest, int flags) { 7169b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown dest.writeTypedList(routes); 7269b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown dest.writeString(globallySelectedRouteId); 7369b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown } 7469b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown 75af574183c274f51d04487a9c8355e9f34a1150f2Jeff Brown @Override 76af574183c274f51d04487a9c8355e9f34a1150f2Jeff Brown public String toString() { 77af574183c274f51d04487a9c8355e9f34a1150f2Jeff Brown return "MediaRouterClientState{ globallySelectedRouteId=" 78af574183c274f51d04487a9c8355e9f34a1150f2Jeff Brown + globallySelectedRouteId + ", routes=" + routes.toString() + " }"; 79af574183c274f51d04487a9c8355e9f34a1150f2Jeff Brown } 80af574183c274f51d04487a9c8355e9f34a1150f2Jeff Brown 8169b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown public static final Parcelable.Creator<MediaRouterClientState> CREATOR = 8269b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown new Parcelable.Creator<MediaRouterClientState>() { 8369b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown @Override 8469b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown public MediaRouterClientState createFromParcel(Parcel in) { 8569b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown return new MediaRouterClientState(in); 8669b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown } 8769b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown 8869b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown @Override 8969b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown public MediaRouterClientState[] newArray(int size) { 9069b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown return new MediaRouterClientState[size]; 9169b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown } 9269b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown }; 9369b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown 9469b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown public static final class RouteInfo implements Parcelable { 9569b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown public String id; 9669b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown public String name; 9769b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown public String description; 9869b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown public int supportedTypes; 9969b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown public boolean enabled; 10069b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown public int statusCode; 10169b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown public int playbackType; 10269b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown public int playbackStream; 10369b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown public int volume; 10469b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown public int volumeMax; 10569b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown public int volumeHandling; 10669b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown public int presentationDisplayId; 10769b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown 10869b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown public RouteInfo(String id) { 10969b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown this.id = id; 11069b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown enabled = true; 11169b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown statusCode = MediaRouter.RouteInfo.STATUS_NONE; 11269b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown playbackType = MediaRouter.RouteInfo.PLAYBACK_TYPE_REMOTE; 11369b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown playbackStream = -1; 11469b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown volumeHandling = MediaRouter.RouteInfo.PLAYBACK_VOLUME_FIXED; 11569b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown presentationDisplayId = -1; 11669b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown } 11769b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown 11869b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown public RouteInfo(RouteInfo other) { 11969b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown id = other.id; 12069b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown name = other.name; 12169b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown description = other.description; 12269b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown supportedTypes = other.supportedTypes; 12369b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown enabled = other.enabled; 12469b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown statusCode = other.statusCode; 12569b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown playbackType = other.playbackType; 12669b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown playbackStream = other.playbackStream; 12769b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown volume = other.volume; 12869b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown volumeMax = other.volumeMax; 12969b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown volumeHandling = other.volumeHandling; 13069b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown presentationDisplayId = other.presentationDisplayId; 13169b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown } 13269b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown 13369b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown RouteInfo(Parcel in) { 13469b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown id = in.readString(); 13569b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown name = in.readString(); 13669b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown description = in.readString(); 13769b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown supportedTypes = in.readInt(); 13869b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown enabled = in.readInt() != 0; 13969b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown statusCode = in.readInt(); 14069b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown playbackType = in.readInt(); 14169b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown playbackStream = in.readInt(); 14269b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown volume = in.readInt(); 14369b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown volumeMax = in.readInt(); 14469b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown volumeHandling = in.readInt(); 14569b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown presentationDisplayId = in.readInt(); 14669b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown } 14769b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown 14869b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown @Override 14969b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown public int describeContents() { 15069b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown return 0; 15169b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown } 15269b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown 15369b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown @Override 15469b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown public void writeToParcel(Parcel dest, int flags) { 15569b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown dest.writeString(id); 15669b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown dest.writeString(name); 15769b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown dest.writeString(description); 15869b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown dest.writeInt(supportedTypes); 15969b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown dest.writeInt(enabled ? 1 : 0); 16069b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown dest.writeInt(statusCode); 16169b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown dest.writeInt(playbackType); 16269b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown dest.writeInt(playbackStream); 16369b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown dest.writeInt(volume); 16469b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown dest.writeInt(volumeMax); 16569b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown dest.writeInt(volumeHandling); 16669b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown dest.writeInt(presentationDisplayId); 16769b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown } 16869b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown 16969b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown @Override 17069b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown public String toString() { 17169b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown return "RouteInfo{ id=" + id 17269b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown + ", name=" + name 17369b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown + ", description=" + description 17469b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown + ", supportedTypes=0x" + Integer.toHexString(supportedTypes) 17569b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown + ", enabled=" + enabled 17669b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown + ", statusCode=" + statusCode 17769b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown + ", playbackType=" + playbackType 17869b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown + ", playbackStream=" + playbackStream 17969b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown + ", volume=" + volume 18069b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown + ", volumeMax=" + volumeMax 18169b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown + ", volumeHandling=" + volumeHandling 18269b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown + ", presentationDisplayId=" + presentationDisplayId 18369b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown + " }"; 18469b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown } 18569b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown 18669b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown @SuppressWarnings("hiding") 18769b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown public static final Parcelable.Creator<RouteInfo> CREATOR = 18869b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown new Parcelable.Creator<RouteInfo>() { 18969b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown @Override 19069b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown public RouteInfo createFromParcel(Parcel in) { 19169b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown return new RouteInfo(in); 19269b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown } 19369b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown 19469b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown @Override 19569b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown public RouteInfo[] newArray(int size) { 19669b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown return new RouteInfo[size]; 19769b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown } 19869b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown }; 19969b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown } 20069b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown} 201