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 com.android.media.remotedisplay; 18 19import android.media.RemoteDisplayState.RemoteDisplayInfo; 20import android.text.TextUtils; 21 22import java.util.Objects; 23 24/** 25 * Represents a remote display that has been discovered. 26 */ 27public class RemoteDisplay { 28 private final RemoteDisplayInfo mMutableInfo; 29 private RemoteDisplayInfo mImmutableInfo; 30 31 /** 32 * Status code: Indicates that the remote display is not available. 33 */ 34 public static final int STATUS_NOT_AVAILABLE = RemoteDisplayInfo.STATUS_NOT_AVAILABLE; 35 36 /** 37 * Status code: Indicates that the remote display is in use by someone else. 38 */ 39 public static final int STATUS_IN_USE = RemoteDisplayInfo.STATUS_IN_USE; 40 41 /** 42 * Status code: Indicates that the remote display is available for new connections. 43 */ 44 public static final int STATUS_AVAILABLE = RemoteDisplayInfo.STATUS_AVAILABLE; 45 46 /** 47 * Status code: Indicates that the remote display is current connecting. 48 */ 49 public static final int STATUS_CONNECTING = RemoteDisplayInfo.STATUS_CONNECTING; 50 51 /** 52 * Status code: Indicates that the remote display is connected and is mirroring 53 * display contents. 54 */ 55 public static final int STATUS_CONNECTED = RemoteDisplayInfo.STATUS_CONNECTED; 56 57 /** 58 * Volume handling: Output volume can be changed. 59 */ 60 public static final int PLAYBACK_VOLUME_VARIABLE = 61 RemoteDisplayInfo.PLAYBACK_VOLUME_VARIABLE; 62 63 /** 64 * Volume handling: Output volume is fixed. 65 */ 66 public static final int PLAYBACK_VOLUME_FIXED = 67 RemoteDisplayInfo.PLAYBACK_VOLUME_FIXED; 68 69 /** 70 * Creates a remote display with the specified name and id. 71 */ 72 public RemoteDisplay(String id, String name) { 73 if (TextUtils.isEmpty(id)) { 74 throw new IllegalArgumentException("id must not be null or empty"); 75 } 76 mMutableInfo = new RemoteDisplayInfo(id); 77 setName(name); 78 } 79 80 public String getId() { 81 return mMutableInfo.id; 82 } 83 84 public String getName() { 85 return mMutableInfo.name; 86 } 87 88 public void setName(String name) { 89 if (!Objects.equals(mMutableInfo.name, name)) { 90 mMutableInfo.name = name; 91 mImmutableInfo = null; 92 } 93 } 94 95 public String getDescription() { 96 return mMutableInfo.description; 97 } 98 99 public void setDescription(String description) { 100 if (!Objects.equals(mMutableInfo.description, description)) { 101 mMutableInfo.description = description; 102 mImmutableInfo = null; 103 } 104 } 105 106 public int getStatus() { 107 return mMutableInfo.status; 108 } 109 110 public void setStatus(int status) { 111 if (mMutableInfo.status != status) { 112 mMutableInfo.status = status; 113 mImmutableInfo = null; 114 } 115 } 116 117 public int getVolume() { 118 return mMutableInfo.volume; 119 } 120 121 public void setVolume(int volume) { 122 if (mMutableInfo.volume != volume) { 123 mMutableInfo.volume = volume; 124 mImmutableInfo = null; 125 } 126 } 127 128 public int getVolumeMax() { 129 return mMutableInfo.volumeMax; 130 } 131 132 public void setVolumeMax(int volumeMax) { 133 if (mMutableInfo.volumeMax != volumeMax) { 134 mMutableInfo.volumeMax = volumeMax; 135 mImmutableInfo = null; 136 } 137 } 138 139 public int getVolumeHandling() { 140 return mMutableInfo.volumeHandling; 141 } 142 143 public void setVolumeHandling(int volumeHandling) { 144 if (mMutableInfo.volumeHandling != volumeHandling) { 145 mMutableInfo.volumeHandling = volumeHandling; 146 mImmutableInfo = null; 147 } 148 } 149 150 public int getPresentationDisplayId() { 151 return mMutableInfo.presentationDisplayId; 152 } 153 154 public void setPresentationDisplayId(int presentationDisplayId) { 155 if (mMutableInfo.presentationDisplayId != presentationDisplayId) { 156 mMutableInfo.presentationDisplayId = presentationDisplayId; 157 mImmutableInfo = null; 158 } 159 } 160 161 @Override 162 public String toString() { 163 return "RemoteDisplay{" + mMutableInfo.toString() + "}"; 164 } 165 166 RemoteDisplayInfo getInfo() { 167 if (mImmutableInfo == null) { 168 mImmutableInfo = new RemoteDisplayInfo(mMutableInfo); 169 } 170 return mImmutableInfo; 171 } 172} 173