MediaRouterClientState.java revision 69b07161bebdb2c726e3a826c2268866f1a94517
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
5369b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown    @Override
5469b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown    public int describeContents() {
5569b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        return 0;
5669b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown    }
5769b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown
5869b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown    @Override
5969b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown    public void writeToParcel(Parcel dest, int flags) {
6069b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        dest.writeTypedList(routes);
6169b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        dest.writeString(globallySelectedRouteId);
6269b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown    }
6369b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown
6469b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown    public static final Parcelable.Creator<MediaRouterClientState> CREATOR =
6569b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            new Parcelable.Creator<MediaRouterClientState>() {
6669b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        @Override
6769b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        public MediaRouterClientState createFromParcel(Parcel in) {
6869b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            return new MediaRouterClientState(in);
6969b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        }
7069b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown
7169b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        @Override
7269b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        public MediaRouterClientState[] newArray(int size) {
7369b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            return new MediaRouterClientState[size];
7469b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        }
7569b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown    };
7669b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown
7769b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown    public static final class RouteInfo implements Parcelable {
7869b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        public String id;
7969b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        public String name;
8069b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        public String description;
8169b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        public int supportedTypes;
8269b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        public boolean enabled;
8369b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        public int statusCode;
8469b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        public int playbackType;
8569b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        public int playbackStream;
8669b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        public int volume;
8769b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        public int volumeMax;
8869b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        public int volumeHandling;
8969b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        public int presentationDisplayId;
9069b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown
9169b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        public RouteInfo(String id) {
9269b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            this.id = id;
9369b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            enabled = true;
9469b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            statusCode = MediaRouter.RouteInfo.STATUS_NONE;
9569b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            playbackType = MediaRouter.RouteInfo.PLAYBACK_TYPE_REMOTE;
9669b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            playbackStream = -1;
9769b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            volumeHandling = MediaRouter.RouteInfo.PLAYBACK_VOLUME_FIXED;
9869b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            presentationDisplayId = -1;
9969b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        }
10069b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown
10169b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        public RouteInfo(RouteInfo other) {
10269b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            id = other.id;
10369b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            name = other.name;
10469b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            description = other.description;
10569b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            supportedTypes = other.supportedTypes;
10669b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            enabled = other.enabled;
10769b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            statusCode = other.statusCode;
10869b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            playbackType = other.playbackType;
10969b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            playbackStream = other.playbackStream;
11069b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            volume = other.volume;
11169b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            volumeMax = other.volumeMax;
11269b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            volumeHandling = other.volumeHandling;
11369b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            presentationDisplayId = other.presentationDisplayId;
11469b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        }
11569b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown
11669b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        RouteInfo(Parcel in) {
11769b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            id = in.readString();
11869b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            name = in.readString();
11969b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            description = in.readString();
12069b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            supportedTypes = in.readInt();
12169b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            enabled = in.readInt() != 0;
12269b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            statusCode = in.readInt();
12369b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            playbackType = in.readInt();
12469b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            playbackStream = in.readInt();
12569b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            volume = in.readInt();
12669b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            volumeMax = in.readInt();
12769b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            volumeHandling = in.readInt();
12869b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            presentationDisplayId = in.readInt();
12969b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        }
13069b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown
13169b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        @Override
13269b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        public int describeContents() {
13369b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            return 0;
13469b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        }
13569b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown
13669b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        @Override
13769b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        public void writeToParcel(Parcel dest, int flags) {
13869b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            dest.writeString(id);
13969b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            dest.writeString(name);
14069b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            dest.writeString(description);
14169b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            dest.writeInt(supportedTypes);
14269b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            dest.writeInt(enabled ? 1 : 0);
14369b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            dest.writeInt(statusCode);
14469b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            dest.writeInt(playbackType);
14569b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            dest.writeInt(playbackStream);
14669b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            dest.writeInt(volume);
14769b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            dest.writeInt(volumeMax);
14869b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            dest.writeInt(volumeHandling);
14969b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            dest.writeInt(presentationDisplayId);
15069b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        }
15169b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown
15269b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        @Override
15369b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        public String toString() {
15469b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            return "RouteInfo{ id=" + id
15569b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown                    + ", name=" + name
15669b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown                    + ", description=" + description
15769b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown                    + ", supportedTypes=0x" + Integer.toHexString(supportedTypes)
15869b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown                    + ", enabled=" + enabled
15969b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown                    + ", statusCode=" + statusCode
16069b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown                    + ", playbackType=" + playbackType
16169b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown                    + ", playbackStream=" + playbackStream
16269b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown                    + ", volume=" + volume
16369b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown                    + ", volumeMax=" + volumeMax
16469b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown                    + ", volumeHandling=" + volumeHandling
16569b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown                    + ", presentationDisplayId=" + presentationDisplayId
16669b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown                    + " }";
16769b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        }
16869b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown
16969b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        @SuppressWarnings("hiding")
17069b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        public static final Parcelable.Creator<RouteInfo> CREATOR =
17169b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown                new Parcelable.Creator<RouteInfo>() {
17269b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            @Override
17369b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            public RouteInfo createFromParcel(Parcel in) {
17469b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown                return new RouteInfo(in);
17569b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            }
17669b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown
17769b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            @Override
17869b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            public RouteInfo[] newArray(int size) {
17969b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown                return new RouteInfo[size];
18069b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown            }
18169b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        };
18269b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown    }
18369b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown}
184