blob: 4e74395b54e2a8fa10cbc74bee1c3bb510422df4 [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 Inwoode5bfa3e2018-08-01 11:26:20 +010020import android.annotation.UnsupportedAppUsage;
Sailesh Nepal4cff3922014-03-19 10:15:37 -070021import android.os.Parcel;
22import android.os.Parcelable;
23
24import java.util.Locale;
25
26/**
Santos Cordond9e614f2014-10-28 13:10:36 -070027 * Encapsulates the telecom audio state, including the current audio routing, supported audio
28 * routing and mute.
Yorke Lee4af59352015-05-13 14:14:54 -070029 * @deprecated - use {@link CallAudioState} instead.
30 * @hide
Sailesh Nepal4cff3922014-03-19 10:15:37 -070031 */
Yorke Lee4af59352015-05-13 14:14:54 -070032@Deprecated
33@SystemApi
34public class AudioState implements Parcelable {
Sailesh Nepal4cff3922014-03-19 10:15:37 -070035 /** Direct the audio stream through the device's earpiece. */
Yorke Lee14260482014-08-20 16:16:26 -070036 public static final int ROUTE_EARPIECE = 0x00000001;
Sailesh Nepal4cff3922014-03-19 10:15:37 -070037
38 /** Direct the audio stream through Bluetooth. */
Yorke Lee14260482014-08-20 16:16:26 -070039 public static final int ROUTE_BLUETOOTH = 0x00000002;
Sailesh Nepal4cff3922014-03-19 10:15:37 -070040
41 /** Direct the audio stream through a wired headset. */
Yorke Lee14260482014-08-20 16:16:26 -070042 public static final int ROUTE_WIRED_HEADSET = 0x00000004;
Sailesh Nepal4cff3922014-03-19 10:15:37 -070043
Nancy Chenea38cca2014-09-05 16:38:49 -070044 /** Direct the audio stream through the device's speakerphone. */
Yorke Lee14260482014-08-20 16:16:26 -070045 public static final int ROUTE_SPEAKER = 0x00000008;
Sailesh Nepal4cff3922014-03-19 10:15:37 -070046
47 /**
48 * Direct the audio stream through the device's earpiece or wired headset if one is
49 * connected.
50 */
Yorke Lee14260482014-08-20 16:16:26 -070051 public static final int ROUTE_WIRED_OR_EARPIECE = ROUTE_EARPIECE | ROUTE_WIRED_HEADSET;
Sailesh Nepal4cff3922014-03-19 10:15:37 -070052
Jay Shrauner55b97522015-04-09 15:15:43 -070053 /** Bit mask of all possible audio routes. */
54 private static final int ROUTE_ALL = ROUTE_EARPIECE | ROUTE_BLUETOOTH | ROUTE_WIRED_HEADSET |
Sailesh Nepal4cff3922014-03-19 10:15:37 -070055 ROUTE_SPEAKER;
56
Mathew Inwoode5bfa3e2018-08-01 11:26:20 +010057 @UnsupportedAppUsage
Jay Shrauner164a0ac2015-04-14 18:16:10 -070058 private final boolean isMuted;
Mathew Inwoode5bfa3e2018-08-01 11:26:20 +010059 @UnsupportedAppUsage
Jay Shrauner164a0ac2015-04-14 18:16:10 -070060 private final int route;
Mathew Inwoode5bfa3e2018-08-01 11:26:20 +010061 @UnsupportedAppUsage
Jay Shrauner164a0ac2015-04-14 18:16:10 -070062 private final int supportedRouteMask;
Sailesh Nepal4cff3922014-03-19 10:15:37 -070063
Ihab Awad5c9c86e2014-11-12 13:41:16 -080064 public AudioState(boolean muted, int route, int supportedRouteMask) {
65 this.isMuted = muted;
Sailesh Nepal4cff3922014-03-19 10:15:37 -070066 this.route = route;
67 this.supportedRouteMask = supportedRouteMask;
68 }
69
Ihab Awadb19a0bc2014-08-07 19:46:01 -070070 public AudioState(AudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -080071 isMuted = state.isMuted();
72 route = state.getRoute();
73 supportedRouteMask = state.getSupportedRouteMask();
Sailesh Nepal4cff3922014-03-19 10:15:37 -070074 }
75
Yorke Lee4af59352015-05-13 14:14:54 -070076 public AudioState(CallAudioState state) {
77 isMuted = state.isMuted();
78 route = state.getRoute();
79 supportedRouteMask = state.getSupportedRouteMask();
80 }
81
Sailesh Nepal4cff3922014-03-19 10:15:37 -070082 @Override
83 public boolean equals(Object obj) {
84 if (obj == null) {
85 return false;
86 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -070087 if (!(obj instanceof AudioState)) {
Sailesh Nepal4cff3922014-03-19 10:15:37 -070088 return false;
89 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -070090 AudioState state = (AudioState) obj;
Ihab Awad5c9c86e2014-11-12 13:41:16 -080091 return isMuted() == state.isMuted() && getRoute() == state.getRoute() &&
92 getSupportedRouteMask() == state.getSupportedRouteMask();
Sailesh Nepal4cff3922014-03-19 10:15:37 -070093 }
94
95 @Override
96 public String toString() {
97 return String.format(Locale.US,
Nancy Chenddf15a12014-12-02 15:59:35 -080098 "[AudioState isMuted: %b, route: %s, supportedRouteMask: %s]",
Ihab Awad5c9c86e2014-11-12 13:41:16 -080099 isMuted,
100 audioRouteToString(route),
101 audioRouteToString(supportedRouteMask));
Sailesh Nepal4cff3922014-03-19 10:15:37 -0700102 }
103
Sailesh Nepal4cff3922014-03-19 10:15:37 -0700104 public static String audioRouteToString(int route) {
105 if (route == 0 || (route & ~ROUTE_ALL) != 0x0) {
106 return "UNKNOWN";
107 }
108
109 StringBuffer buffer = new StringBuffer();
110 if ((route & ROUTE_EARPIECE) == ROUTE_EARPIECE) {
111 listAppend(buffer, "EARPIECE");
112 }
113 if ((route & ROUTE_BLUETOOTH) == ROUTE_BLUETOOTH) {
114 listAppend(buffer, "BLUETOOTH");
115 }
116 if ((route & ROUTE_WIRED_HEADSET) == ROUTE_WIRED_HEADSET) {
117 listAppend(buffer, "WIRED_HEADSET");
118 }
119 if ((route & ROUTE_SPEAKER) == ROUTE_SPEAKER) {
120 listAppend(buffer, "SPEAKER");
121 }
122
123 return buffer.toString();
124 }
125
126 private static void listAppend(StringBuffer buffer, String str) {
127 if (buffer.length() > 0) {
128 buffer.append(", ");
129 }
130 buffer.append(str);
131 }
132
133 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700134 * Responsible for creating AudioState objects for deserialized Parcels.
Sailesh Nepal4cff3922014-03-19 10:15:37 -0700135 */
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700136 public static final @android.annotation.NonNull Parcelable.Creator<AudioState> CREATOR =
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700137 new Parcelable.Creator<AudioState> () {
Sailesh Nepal4cff3922014-03-19 10:15:37 -0700138
139 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700140 public AudioState createFromParcel(Parcel source) {
Sailesh Nepal4cff3922014-03-19 10:15:37 -0700141 boolean isMuted = source.readByte() == 0 ? false : true;
142 int route = source.readInt();
143 int supportedRouteMask = source.readInt();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700144 return new AudioState(isMuted, route, supportedRouteMask);
Sailesh Nepal4cff3922014-03-19 10:15:37 -0700145 }
146
147 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700148 public AudioState[] newArray(int size) {
149 return new AudioState[size];
Sailesh Nepal4cff3922014-03-19 10:15:37 -0700150 }
151 };
152
153 /**
154 * {@inheritDoc}
155 */
156 @Override
157 public int describeContents() {
158 return 0;
159 }
160
161 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700162 * Writes AudioState object into a serializeable Parcel.
Sailesh Nepal4cff3922014-03-19 10:15:37 -0700163 */
164 @Override
165 public void writeToParcel(Parcel destination, int flags) {
166 destination.writeByte((byte) (isMuted ? 1 : 0));
167 destination.writeInt(route);
168 destination.writeInt(supportedRouteMask);
169 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800170
171 /**
172 * @return {@code true} if the call is muted, false otherwise.
173 */
174 public boolean isMuted() {
175 return isMuted;
176 }
177
178 /**
179 * @return The current audio route being used.
180 */
181 public int getRoute() {
182 return route;
183 }
184
185 /**
186 * @return Bit mask of all routes supported by this call.
187 */
188 public int getSupportedRouteMask() {
189 return supportedRouteMask;
190 }
Sailesh Nepal4cff3922014-03-19 10:15:37 -0700191}