Aurimas Liutikas | 93554f2 | 2022-04-19 16:51:35 -0700 | [diff] [blame] | 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 | |
| 17 | package android.media; |
| 18 | |
| 19 | import android.compat.annotation.UnsupportedAppUsage; |
| 20 | import android.os.Build; |
| 21 | import android.os.Parcel; |
| 22 | import android.os.Parcelable; |
| 23 | import android.text.TextUtils; |
| 24 | |
| 25 | import java.util.ArrayList; |
| 26 | |
| 27 | /** |
| 28 | * Information available from IRemoteDisplayProvider about available remote displays. |
| 29 | * |
| 30 | * Clients must not modify the contents of this object. |
| 31 | * @hide |
| 32 | */ |
| 33 | public final class RemoteDisplayState implements Parcelable { |
| 34 | // Note: These constants are used by the remote display provider API. |
| 35 | // Do not change them! |
| 36 | public static final String SERVICE_INTERFACE = |
| 37 | "com.android.media.remotedisplay.RemoteDisplayProvider"; |
| 38 | public static final int DISCOVERY_MODE_NONE = 0; |
| 39 | public static final int DISCOVERY_MODE_PASSIVE = 1; |
| 40 | public static final int DISCOVERY_MODE_ACTIVE = 2; |
| 41 | |
| 42 | /** |
| 43 | * A list of all remote displays. |
| 44 | */ |
| 45 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 46 | public final ArrayList<RemoteDisplayInfo> displays; |
| 47 | |
| 48 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 49 | public RemoteDisplayState() { |
| 50 | displays = new ArrayList<RemoteDisplayInfo>(); |
| 51 | } |
| 52 | |
| 53 | RemoteDisplayState(Parcel src) { |
| 54 | displays = src.createTypedArrayList(RemoteDisplayInfo.CREATOR); |
| 55 | } |
| 56 | |
| 57 | public boolean isValid() { |
| 58 | if (displays == null) { |
| 59 | return false; |
| 60 | } |
| 61 | final int count = displays.size(); |
| 62 | for (int i = 0; i < count; i++) { |
| 63 | if (!displays.get(i).isValid()) { |
| 64 | return false; |
| 65 | } |
| 66 | } |
| 67 | return true; |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public int describeContents() { |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public void writeToParcel(Parcel dest, int flags) { |
| 77 | dest.writeTypedList(displays); |
| 78 | } |
| 79 | |
| 80 | public static final @android.annotation.NonNull Parcelable.Creator<RemoteDisplayState> CREATOR = |
| 81 | new Parcelable.Creator<RemoteDisplayState>() { |
| 82 | @Override |
| 83 | public RemoteDisplayState createFromParcel(Parcel in) { |
| 84 | return new RemoteDisplayState(in); |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public RemoteDisplayState[] newArray(int size) { |
| 89 | return new RemoteDisplayState[size]; |
| 90 | } |
| 91 | }; |
| 92 | |
| 93 | public static final class RemoteDisplayInfo implements Parcelable { |
| 94 | // Note: These constants are used by the remote display provider API. |
| 95 | // Do not change them! |
| 96 | public static final int STATUS_NOT_AVAILABLE = 0; |
| 97 | public static final int STATUS_IN_USE = 1; |
| 98 | public static final int STATUS_AVAILABLE = 2; |
| 99 | public static final int STATUS_CONNECTING = 3; |
| 100 | public static final int STATUS_CONNECTED = 4; |
| 101 | |
| 102 | public static final int PLAYBACK_VOLUME_VARIABLE = |
| 103 | MediaRouter.RouteInfo.PLAYBACK_VOLUME_VARIABLE; |
| 104 | public static final int PLAYBACK_VOLUME_FIXED = |
| 105 | MediaRouter.RouteInfo.PLAYBACK_VOLUME_FIXED; |
| 106 | |
| 107 | public String id; |
| 108 | public String name; |
| 109 | public String description; |
| 110 | public int status; |
| 111 | public int volume; |
| 112 | public int volumeMax; |
| 113 | public int volumeHandling; |
| 114 | public int presentationDisplayId; |
| 115 | |
| 116 | public RemoteDisplayInfo(String id) { |
| 117 | this.id = id; |
| 118 | status = STATUS_NOT_AVAILABLE; |
| 119 | volumeHandling = MediaRouter.RouteInfo.PLAYBACK_VOLUME_FIXED; |
| 120 | presentationDisplayId = -1; |
| 121 | } |
| 122 | |
| 123 | public RemoteDisplayInfo(RemoteDisplayInfo other) { |
| 124 | id = other.id; |
| 125 | name = other.name; |
| 126 | description = other.description; |
| 127 | status = other.status; |
| 128 | volume = other.volume; |
| 129 | volumeMax = other.volumeMax; |
| 130 | volumeHandling = other.volumeHandling; |
| 131 | presentationDisplayId = other.presentationDisplayId; |
| 132 | } |
| 133 | |
| 134 | RemoteDisplayInfo(Parcel in) { |
| 135 | id = in.readString(); |
| 136 | name = in.readString(); |
| 137 | description = in.readString(); |
| 138 | status = in.readInt(); |
| 139 | volume = in.readInt(); |
| 140 | volumeMax = in.readInt(); |
| 141 | volumeHandling = in.readInt(); |
| 142 | presentationDisplayId = in.readInt(); |
| 143 | } |
| 144 | |
| 145 | public boolean isValid() { |
| 146 | return !TextUtils.isEmpty(id) && !TextUtils.isEmpty(name); |
| 147 | } |
| 148 | |
| 149 | @Override |
| 150 | public int describeContents() { |
| 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | @Override |
| 155 | public void writeToParcel(Parcel dest, int flags) { |
| 156 | dest.writeString(id); |
| 157 | dest.writeString(name); |
| 158 | dest.writeString(description); |
| 159 | dest.writeInt(status); |
| 160 | dest.writeInt(volume); |
| 161 | dest.writeInt(volumeMax); |
| 162 | dest.writeInt(volumeHandling); |
| 163 | dest.writeInt(presentationDisplayId); |
| 164 | } |
| 165 | |
| 166 | @Override |
| 167 | public String toString() { |
| 168 | return "RemoteDisplayInfo{ id=" + id |
| 169 | + ", name=" + name |
| 170 | + ", description=" + description |
| 171 | + ", status=" + status |
| 172 | + ", volume=" + volume |
| 173 | + ", volumeMax=" + volumeMax |
| 174 | + ", volumeHandling=" + volumeHandling |
| 175 | + ", presentationDisplayId=" + presentationDisplayId |
| 176 | + " }"; |
| 177 | } |
| 178 | |
| 179 | @SuppressWarnings("hiding") |
| 180 | public static final @android.annotation.NonNull Parcelable.Creator<RemoteDisplayInfo> CREATOR = |
| 181 | new Parcelable.Creator<RemoteDisplayInfo>() { |
| 182 | @Override |
| 183 | public RemoteDisplayInfo createFromParcel(Parcel in) { |
| 184 | return new RemoteDisplayInfo(in); |
| 185 | } |
| 186 | |
| 187 | @Override |
| 188 | public RemoteDisplayInfo[] newArray(int size) { |
| 189 | return new RemoteDisplayInfo[size]; |
| 190 | } |
| 191 | }; |
| 192 | } |
| 193 | } |