summaryrefslogtreecommitdiffstats
path: root/media/lib/java/com/android/media/remotedisplay/RemoteDisplay.java
blob: c2461e6f445006cab864bf1204f4f901488ac3f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
 * Copyright (C) 2013 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.media.remotedisplay;

import com.android.internal.util.Objects;

import android.media.RemoteDisplayState.RemoteDisplayInfo;
import android.text.TextUtils;

/**
 * Represents a remote display that has been discovered.
 */
public class RemoteDisplay {
    private final RemoteDisplayInfo mMutableInfo;
    private RemoteDisplayInfo mImmutableInfo;

    /**
     * Status code: Indicates that the remote display is not available.
     */
    public static final int STATUS_NOT_AVAILABLE = RemoteDisplayInfo.STATUS_NOT_AVAILABLE;

    /**
     * Status code: Indicates that the remote display is in use by someone else.
     */
    public static final int STATUS_IN_USE = RemoteDisplayInfo.STATUS_IN_USE;

    /**
     * Status code: Indicates that the remote display is available for new connections.
     */
    public static final int STATUS_AVAILABLE = RemoteDisplayInfo.STATUS_AVAILABLE;

    /**
     * Status code: Indicates that the remote display is current connecting.
     */
    public static final int STATUS_CONNECTING = RemoteDisplayInfo.STATUS_CONNECTING;

    /**
     * Status code: Indicates that the remote display is connected and is mirroring
     * display contents.
     */
    public static final int STATUS_CONNECTED = RemoteDisplayInfo.STATUS_CONNECTED;

    /**
     * Volume handling: Output volume can be changed.
     */
    public static final int PLAYBACK_VOLUME_VARIABLE =
            RemoteDisplayInfo.PLAYBACK_VOLUME_VARIABLE;

    /**
     * Volume handling: Output volume is fixed.
     */
    public static final int PLAYBACK_VOLUME_FIXED =
            RemoteDisplayInfo.PLAYBACK_VOLUME_FIXED;

    /**
     * Creates a remote display with the specified name and id.
     */
    public RemoteDisplay(String id, String name) {
        if (TextUtils.isEmpty(id)) {
            throw new IllegalArgumentException("id must not be null or empty");
        }
        mMutableInfo = new RemoteDisplayInfo(id);
        setName(name);
    }

    public String getId() {
        return mMutableInfo.id;
    }

    public String getName() {
        return mMutableInfo.name;
    }

    public void setName(String name) {
        if (!Objects.equal(mMutableInfo.name, name)) {
            mMutableInfo.name = name;
            mImmutableInfo = null;
        }
    }

    public String getDescription() {
        return mMutableInfo.description;
    }

    public void setDescription(String description) {
        if (!Objects.equal(mMutableInfo.description, description)) {
            mMutableInfo.description = description;
            mImmutableInfo = null;
        }
    }

    public int getStatus() {
        return mMutableInfo.status;
    }

    public void setStatus(int status) {
        if (mMutableInfo.status != status) {
            mMutableInfo.status = status;
            mImmutableInfo = null;
        }
    }

    public int getVolume() {
        return mMutableInfo.volume;
    }

    public void setVolume(int volume) {
        if (mMutableInfo.volume != volume) {
            mMutableInfo.volume = volume;
            mImmutableInfo = null;
        }
    }

    public int getVolumeMax() {
        return mMutableInfo.volumeMax;
    }

    public void setVolumeMax(int volumeMax) {
        if (mMutableInfo.volumeMax != volumeMax) {
            mMutableInfo.volumeMax = volumeMax;
            mImmutableInfo = null;
        }
    }

    public int getVolumeHandling() {
        return mMutableInfo.volumeHandling;
    }

    public void setVolumeHandling(int volumeHandling) {
        if (mMutableInfo.volumeHandling != volumeHandling) {
            mMutableInfo.volumeHandling = volumeHandling;
            mImmutableInfo = null;
        }
    }

    public int getPresentationDisplayId() {
        return mMutableInfo.presentationDisplayId;
    }

    public void setPresentationDisplayId(int presentationDisplayId) {
        if (mMutableInfo.presentationDisplayId != presentationDisplayId) {
            mMutableInfo.presentationDisplayId = presentationDisplayId;
            mImmutableInfo = null;
        }
    }

    @Override
    public String toString() {
        return "RemoteDisplay{" + mMutableInfo.toString() + "}";
    }

    RemoteDisplayInfo getInfo() {
        if (mImmutableInfo == null) {
            mImmutableInfo = new RemoteDisplayInfo(mMutableInfo);
        }
        return mImmutableInfo;
    }
}