1/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.media;
18
19import android.os.Parcel;
20import android.os.Parcelable;
21import android.text.TextUtils;
22
23import java.util.ArrayList;
24
25/**
26 * Information available from IRemoteDisplayProvider about available remote displays.
27 *
28 * Clients must not modify the contents of this object.
29 * @hide
30 */
31public final class RemoteDisplayState implements Parcelable {
32    // Note: These constants are used by the remote display provider API.
33    // Do not change them!
34    public static final String SERVICE_INTERFACE =
35            "com.android.media.remotedisplay.RemoteDisplayProvider";
36    public static final int DISCOVERY_MODE_NONE = 0;
37    public static final int DISCOVERY_MODE_PASSIVE = 1;
38    public static final int DISCOVERY_MODE_ACTIVE = 2;
39
40    /**
41     * A list of all remote displays.
42     */
43    public final ArrayList<RemoteDisplayInfo> displays;
44
45    public RemoteDisplayState() {
46        displays = new ArrayList<RemoteDisplayInfo>();
47    }
48
49    RemoteDisplayState(Parcel src) {
50        displays = src.createTypedArrayList(RemoteDisplayInfo.CREATOR);
51    }
52
53    public boolean isValid() {
54        if (displays == null) {
55            return false;
56        }
57        final int count = displays.size();
58        for (int i = 0; i < count; i++) {
59            if (!displays.get(i).isValid()) {
60                return false;
61            }
62        }
63        return true;
64    }
65
66    @Override
67    public int describeContents() {
68        return 0;
69    }
70
71    @Override
72    public void writeToParcel(Parcel dest, int flags) {
73        dest.writeTypedList(displays);
74    }
75
76    public static final Parcelable.Creator<RemoteDisplayState> CREATOR =
77            new Parcelable.Creator<RemoteDisplayState>() {
78        @Override
79        public RemoteDisplayState createFromParcel(Parcel in) {
80            return new RemoteDisplayState(in);
81        }
82
83        @Override
84        public RemoteDisplayState[] newArray(int size) {
85            return new RemoteDisplayState[size];
86        }
87    };
88
89    public static final class RemoteDisplayInfo implements Parcelable {
90        // Note: These constants are used by the remote display provider API.
91        // Do not change them!
92        public static final int STATUS_NOT_AVAILABLE = 0;
93        public static final int STATUS_IN_USE = 1;
94        public static final int STATUS_AVAILABLE = 2;
95        public static final int STATUS_CONNECTING = 3;
96        public static final int STATUS_CONNECTED = 4;
97
98        public static final int PLAYBACK_VOLUME_VARIABLE =
99                MediaRouter.RouteInfo.PLAYBACK_VOLUME_VARIABLE;
100        public static final int PLAYBACK_VOLUME_FIXED =
101                MediaRouter.RouteInfo.PLAYBACK_VOLUME_FIXED;
102
103        public String id;
104        public String name;
105        public String description;
106        public int status;
107        public int volume;
108        public int volumeMax;
109        public int volumeHandling;
110        public int presentationDisplayId;
111
112        public RemoteDisplayInfo(String id) {
113            this.id = id;
114            status = STATUS_NOT_AVAILABLE;
115            volumeHandling = MediaRouter.RouteInfo.PLAYBACK_VOLUME_FIXED;
116            presentationDisplayId = -1;
117        }
118
119        public RemoteDisplayInfo(RemoteDisplayInfo other) {
120            id = other.id;
121            name = other.name;
122            description = other.description;
123            status = other.status;
124            volume = other.volume;
125            volumeMax = other.volumeMax;
126            volumeHandling = other.volumeHandling;
127            presentationDisplayId = other.presentationDisplayId;
128        }
129
130        RemoteDisplayInfo(Parcel in) {
131            id = in.readString();
132            name = in.readString();
133            description = in.readString();
134            status = in.readInt();
135            volume = in.readInt();
136            volumeMax = in.readInt();
137            volumeHandling = in.readInt();
138            presentationDisplayId = in.readInt();
139        }
140
141        public boolean isValid() {
142            return !TextUtils.isEmpty(id) && !TextUtils.isEmpty(name);
143        }
144
145        @Override
146        public int describeContents() {
147            return 0;
148        }
149
150        @Override
151        public void writeToParcel(Parcel dest, int flags) {
152            dest.writeString(id);
153            dest.writeString(name);
154            dest.writeString(description);
155            dest.writeInt(status);
156            dest.writeInt(volume);
157            dest.writeInt(volumeMax);
158            dest.writeInt(volumeHandling);
159            dest.writeInt(presentationDisplayId);
160        }
161
162        @Override
163        public String toString() {
164            return "RemoteDisplayInfo{ id=" + id
165                    + ", name=" + name
166                    + ", description=" + description
167                    + ", status=" + status
168                    + ", volume=" + volume
169                    + ", volumeMax=" + volumeMax
170                    + ", volumeHandling=" + volumeHandling
171                    + ", presentationDisplayId=" + presentationDisplayId
172                    + " }";
173        }
174
175        @SuppressWarnings("hiding")
176        public static final Parcelable.Creator<RemoteDisplayInfo> CREATOR =
177                new Parcelable.Creator<RemoteDisplayInfo>() {
178            @Override
179            public RemoteDisplayInfo createFromParcel(Parcel in) {
180                return new RemoteDisplayInfo(in);
181            }
182
183            @Override
184            public RemoteDisplayInfo[] newArray(int size) {
185                return new RemoteDisplayInfo[size];
186            }
187        };
188    }
189}
190