blob: a9b75a391255847ea6db793e55214c991a36ea95 [file] [log] [blame]
Sailesh Nepal4cff3922014-03-19 10:15:37 -07001/*
2 * Copyright (C) 2014 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
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Sailesh Nepal4cff3922014-03-19 10:15:37 -070018
Yorke Lee4af59352015-05-13 14:14:54 -070019import android.annotation.SystemApi;
Mathew Inwood42346d12018-08-01 11:33:05 +010020import android.annotation.UnsupportedAppUsage;
Tyler Gunn17933eb2019-03-05 13:58:45 -080021import android.os.Build;
Sailesh Nepal4cff3922014-03-19 10:15:37 -070022import android.os.Parcel;
23import android.os.Parcelable;
24
25import java.util.Locale;
26
27/**
Santos Cordond9e614f2014-10-28 13:10:36 -070028 * Encapsulates the telecom audio state, including the current audio routing, supported audio
29 * routing and mute.
Yorke Lee4af59352015-05-13 14:14:54 -070030 * @deprecated - use {@link CallAudioState} instead.
31 * @hide
Sailesh Nepal4cff3922014-03-19 10:15:37 -070032 */
Yorke Lee4af59352015-05-13 14:14:54 -070033@Deprecated
34@SystemApi
35public class AudioState implements Parcelable {
Sailesh Nepal4cff3922014-03-19 10:15:37 -070036 /** Direct the audio stream through the device's earpiece. */
Yorke Lee14260482014-08-20 16:16:26 -070037 public static final int ROUTE_EARPIECE = 0x00000001;
Sailesh Nepal4cff3922014-03-19 10:15:37 -070038
39 /** Direct the audio stream through Bluetooth. */
Yorke Lee14260482014-08-20 16:16:26 -070040 public static final int ROUTE_BLUETOOTH = 0x00000002;
Sailesh Nepal4cff3922014-03-19 10:15:37 -070041
42 /** Direct the audio stream through a wired headset. */
Yorke Lee14260482014-08-20 16:16:26 -070043 public static final int ROUTE_WIRED_HEADSET = 0x00000004;
Sailesh Nepal4cff3922014-03-19 10:15:37 -070044
Nancy Chenea38cca2014-09-05 16:38:49 -070045 /** Direct the audio stream through the device's speakerphone. */
Yorke Lee14260482014-08-20 16:16:26 -070046 public static final int ROUTE_SPEAKER = 0x00000008;
Sailesh Nepal4cff3922014-03-19 10:15:37 -070047
48 /**
49 * Direct the audio stream through the device's earpiece or wired headset if one is
50 * connected.
51 */
Yorke Lee14260482014-08-20 16:16:26 -070052 public static final int ROUTE_WIRED_OR_EARPIECE = ROUTE_EARPIECE | ROUTE_WIRED_HEADSET;
Sailesh Nepal4cff3922014-03-19 10:15:37 -070053
Jay Shrauner55b97522015-04-09 15:15:43 -070054 /** Bit mask of all possible audio routes. */
55 private static final int ROUTE_ALL = ROUTE_EARPIECE | ROUTE_BLUETOOTH | ROUTE_WIRED_HEADSET |
Sailesh Nepal4cff3922014-03-19 10:15:37 -070056 ROUTE_SPEAKER;
57
Tyler Gunn17933eb2019-03-05 13:58:45 -080058 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 127403196)
Jay Shrauner164a0ac2015-04-14 18:16:10 -070059 private final boolean isMuted;
Tyler Gunn17933eb2019-03-05 13:58:45 -080060 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 127403196)
Jay Shrauner164a0ac2015-04-14 18:16:10 -070061 private final int route;
Tyler Gunn17933eb2019-03-05 13:58:45 -080062 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 127403196)
Jay Shrauner164a0ac2015-04-14 18:16:10 -070063 private final int supportedRouteMask;
Sailesh Nepal4cff3922014-03-19 10:15:37 -070064
Ihab Awad5c9c86e2014-11-12 13:41:16 -080065 public AudioState(boolean muted, int route, int supportedRouteMask) {
66 this.isMuted = muted;
Sailesh Nepal4cff3922014-03-19 10:15:37 -070067 this.route = route;
68 this.supportedRouteMask = supportedRouteMask;
69 }
70
Ihab Awadb19a0bc2014-08-07 19:46:01 -070071 public AudioState(AudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -080072 isMuted = state.isMuted();
73 route = state.getRoute();
74 supportedRouteMask = state.getSupportedRouteMask();
Sailesh Nepal4cff3922014-03-19 10:15:37 -070075 }
76
Yorke Lee4af59352015-05-13 14:14:54 -070077 public AudioState(CallAudioState state) {
78 isMuted = state.isMuted();
79 route = state.getRoute();
80 supportedRouteMask = state.getSupportedRouteMask();
81 }
82
Sailesh Nepal4cff3922014-03-19 10:15:37 -070083 @Override
84 public boolean equals(Object obj) {
85 if (obj == null) {
86 return false;
87 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -070088 if (!(obj instanceof AudioState)) {
Sailesh Nepal4cff3922014-03-19 10:15:37 -070089 return false;
90 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -070091 AudioState state = (AudioState) obj;
Ihab Awad5c9c86e2014-11-12 13:41:16 -080092 return isMuted() == state.isMuted() && getRoute() == state.getRoute() &&
93 getSupportedRouteMask() == state.getSupportedRouteMask();
Sailesh Nepal4cff3922014-03-19 10:15:37 -070094 }
95
96 @Override
97 public String toString() {
98 return String.format(Locale.US,
Nancy Chenddf15a12014-12-02 15:59:35 -080099 "[AudioState isMuted: %b, route: %s, supportedRouteMask: %s]",
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800100 isMuted,
101 audioRouteToString(route),
102 audioRouteToString(supportedRouteMask));
Sailesh Nepal4cff3922014-03-19 10:15:37 -0700103 }
104
Sailesh Nepal4cff3922014-03-19 10:15:37 -0700105 public static String audioRouteToString(int route) {
106 if (route == 0 || (route & ~ROUTE_ALL) != 0x0) {
107 return "UNKNOWN";
108 }
109
110 StringBuffer buffer = new StringBuffer();
111 if ((route & ROUTE_EARPIECE) == ROUTE_EARPIECE) {
112 listAppend(buffer, "EARPIECE");
113 }
114 if ((route & ROUTE_BLUETOOTH) == ROUTE_BLUETOOTH) {
115 listAppend(buffer, "BLUETOOTH");
116 }
117 if ((route & ROUTE_WIRED_HEADSET) == ROUTE_WIRED_HEADSET) {
118 listAppend(buffer, "WIRED_HEADSET");
119 }
120 if ((route & ROUTE_SPEAKER) == ROUTE_SPEAKER) {
121 listAppend(buffer, "SPEAKER");
122 }
123
124 return buffer.toString();
125 }
126
127 private static void listAppend(StringBuffer buffer, String str) {
128 if (buffer.length() > 0) {
129 buffer.append(", ");
130 }
131 buffer.append(str);
132 }
133
134 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700135 * Responsible for creating AudioState objects for deserialized Parcels.
Sailesh Nepal4cff3922014-03-19 10:15:37 -0700136 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700137 public static final Parcelable.Creator<AudioState> CREATOR =
138 new Parcelable.Creator<AudioState> () {
Sailesh Nepal4cff3922014-03-19 10:15:37 -0700139
140 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700141 public AudioState createFromParcel(Parcel source) {
Sailesh Nepal4cff3922014-03-19 10:15:37 -0700142 boolean isMuted = source.readByte() == 0 ? false : true;
143 int route = source.readInt();
144 int supportedRouteMask = source.readInt();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700145 return new AudioState(isMuted, route, supportedRouteMask);
Sailesh Nepal4cff3922014-03-19 10:15:37 -0700146 }
147
148 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700149 public AudioState[] newArray(int size) {
150 return new AudioState[size];
Sailesh Nepal4cff3922014-03-19 10:15:37 -0700151 }
152 };
153
154 /**
155 * {@inheritDoc}
156 */
157 @Override
158 public int describeContents() {
159 return 0;
160 }
161
162 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700163 * Writes AudioState object into a serializeable Parcel.
Sailesh Nepal4cff3922014-03-19 10:15:37 -0700164 */
165 @Override
166 public void writeToParcel(Parcel destination, int flags) {
167 destination.writeByte((byte) (isMuted ? 1 : 0));
168 destination.writeInt(route);
169 destination.writeInt(supportedRouteMask);
170 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800171
172 /**
173 * @return {@code true} if the call is muted, false otherwise.
174 */
175 public boolean isMuted() {
176 return isMuted;
177 }
178
179 /**
180 * @return The current audio route being used.
181 */
182 public int getRoute() {
183 return route;
184 }
185
186 /**
187 * @return Bit mask of all routes supported by this call.
188 */
189 public int getSupportedRouteMask() {
190 return supportedRouteMask;
191 }
Sailesh Nepal4cff3922014-03-19 10:15:37 -0700192}