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