blob: ea641f866b98ebfcb160778df2dda5ee8e4cfd48 [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
Aurimas Liutikas00be9512019-08-28 13:01:05 -070019import android.annotation.NonNull;
20import android.annotation.Nullable;
Yorke Lee4af59352015-05-13 14:14:54 -070021import android.annotation.SystemApi;
Artur Satayev2ebb31c2020-01-08 12:24:36 +000022import android.compat.annotation.UnsupportedAppUsage;
Tyler Gunn17933eb2019-03-05 13:58:45 -080023import android.os.Build;
Sailesh Nepal4cff3922014-03-19 10:15:37 -070024import android.os.Parcel;
25import android.os.Parcelable;
26
27import java.util.Locale;
28
29/**
Santos Cordond9e614f2014-10-28 13:10:36 -070030 * Encapsulates the telecom audio state, including the current audio routing, supported audio
31 * routing and mute.
Yorke Lee4af59352015-05-13 14:14:54 -070032 * @deprecated - use {@link CallAudioState} instead.
33 * @hide
Sailesh Nepal4cff3922014-03-19 10:15:37 -070034 */
Yorke Lee4af59352015-05-13 14:14:54 -070035@Deprecated
36@SystemApi
37public class AudioState implements Parcelable {
Sailesh Nepal4cff3922014-03-19 10:15:37 -070038 /** Direct the audio stream through the device's earpiece. */
Yorke Lee14260482014-08-20 16:16:26 -070039 public static final int ROUTE_EARPIECE = 0x00000001;
Sailesh Nepal4cff3922014-03-19 10:15:37 -070040
41 /** Direct the audio stream through Bluetooth. */
Yorke Lee14260482014-08-20 16:16:26 -070042 public static final int ROUTE_BLUETOOTH = 0x00000002;
Sailesh Nepal4cff3922014-03-19 10:15:37 -070043
44 /** Direct the audio stream through a wired headset. */
Yorke Lee14260482014-08-20 16:16:26 -070045 public static final int ROUTE_WIRED_HEADSET = 0x00000004;
Sailesh Nepal4cff3922014-03-19 10:15:37 -070046
Nancy Chenea38cca2014-09-05 16:38:49 -070047 /** Direct the audio stream through the device's speakerphone. */
Yorke Lee14260482014-08-20 16:16:26 -070048 public static final int ROUTE_SPEAKER = 0x00000008;
Sailesh Nepal4cff3922014-03-19 10:15:37 -070049
50 /**
51 * Direct the audio stream through the device's earpiece or wired headset if one is
52 * connected.
53 */
Yorke Lee14260482014-08-20 16:16:26 -070054 public static final int ROUTE_WIRED_OR_EARPIECE = ROUTE_EARPIECE | ROUTE_WIRED_HEADSET;
Sailesh Nepal4cff3922014-03-19 10:15:37 -070055
Jay Shrauner55b97522015-04-09 15:15:43 -070056 /** Bit mask of all possible audio routes. */
57 private static final int ROUTE_ALL = ROUTE_EARPIECE | ROUTE_BLUETOOTH | ROUTE_WIRED_HEADSET |
Sailesh Nepal4cff3922014-03-19 10:15:37 -070058 ROUTE_SPEAKER;
59
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 boolean isMuted;
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 route;
Tyler Gunn17933eb2019-03-05 13:58:45 -080064 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 127403196)
Jay Shrauner164a0ac2015-04-14 18:16:10 -070065 private final int supportedRouteMask;
Sailesh Nepal4cff3922014-03-19 10:15:37 -070066
Ihab Awad5c9c86e2014-11-12 13:41:16 -080067 public AudioState(boolean muted, int route, int supportedRouteMask) {
68 this.isMuted = muted;
Sailesh Nepal4cff3922014-03-19 10:15:37 -070069 this.route = route;
70 this.supportedRouteMask = supportedRouteMask;
71 }
72
Ihab Awadb19a0bc2014-08-07 19:46:01 -070073 public AudioState(AudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -080074 isMuted = state.isMuted();
75 route = state.getRoute();
76 supportedRouteMask = state.getSupportedRouteMask();
Sailesh Nepal4cff3922014-03-19 10:15:37 -070077 }
78
Yorke Lee4af59352015-05-13 14:14:54 -070079 public AudioState(CallAudioState state) {
80 isMuted = state.isMuted();
81 route = state.getRoute();
82 supportedRouteMask = state.getSupportedRouteMask();
83 }
84
Sailesh Nepal4cff3922014-03-19 10:15:37 -070085 @Override
Aurimas Liutikas00be9512019-08-28 13:01:05 -070086 public boolean equals(@Nullable Object obj) {
Sailesh Nepal4cff3922014-03-19 10:15:37 -070087 if (obj == null) {
88 return false;
89 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -070090 if (!(obj instanceof AudioState)) {
Sailesh Nepal4cff3922014-03-19 10:15:37 -070091 return false;
92 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -070093 AudioState state = (AudioState) obj;
Ihab Awad5c9c86e2014-11-12 13:41:16 -080094 return isMuted() == state.isMuted() && getRoute() == state.getRoute() &&
95 getSupportedRouteMask() == state.getSupportedRouteMask();
Sailesh Nepal4cff3922014-03-19 10:15:37 -070096 }
97
Aurimas Liutikas00be9512019-08-28 13:01:05 -070098 @NonNull
Sailesh Nepal4cff3922014-03-19 10:15:37 -070099 @Override
100 public String toString() {
101 return String.format(Locale.US,
Nancy Chenddf15a12014-12-02 15:59:35 -0800102 "[AudioState isMuted: %b, route: %s, supportedRouteMask: %s]",
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800103 isMuted,
104 audioRouteToString(route),
105 audioRouteToString(supportedRouteMask));
Sailesh Nepal4cff3922014-03-19 10:15:37 -0700106 }
107
Sailesh Nepal4cff3922014-03-19 10:15:37 -0700108 public static String audioRouteToString(int route) {
109 if (route == 0 || (route & ~ROUTE_ALL) != 0x0) {
110 return "UNKNOWN";
111 }
112
113 StringBuffer buffer = new StringBuffer();
114 if ((route & ROUTE_EARPIECE) == ROUTE_EARPIECE) {
115 listAppend(buffer, "EARPIECE");
116 }
117 if ((route & ROUTE_BLUETOOTH) == ROUTE_BLUETOOTH) {
118 listAppend(buffer, "BLUETOOTH");
119 }
120 if ((route & ROUTE_WIRED_HEADSET) == ROUTE_WIRED_HEADSET) {
121 listAppend(buffer, "WIRED_HEADSET");
122 }
123 if ((route & ROUTE_SPEAKER) == ROUTE_SPEAKER) {
124 listAppend(buffer, "SPEAKER");
125 }
126
127 return buffer.toString();
128 }
129
130 private static void listAppend(StringBuffer buffer, String str) {
131 if (buffer.length() > 0) {
132 buffer.append(", ");
133 }
134 buffer.append(str);
135 }
136
137 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700138 * Responsible for creating AudioState objects for deserialized Parcels.
Sailesh Nepal4cff3922014-03-19 10:15:37 -0700139 */
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700140 public static final @android.annotation.NonNull Parcelable.Creator<AudioState> CREATOR =
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700141 new Parcelable.Creator<AudioState> () {
Sailesh Nepal4cff3922014-03-19 10:15:37 -0700142
143 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700144 public AudioState createFromParcel(Parcel source) {
Sailesh Nepal4cff3922014-03-19 10:15:37 -0700145 boolean isMuted = source.readByte() == 0 ? false : true;
146 int route = source.readInt();
147 int supportedRouteMask = source.readInt();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700148 return new AudioState(isMuted, route, supportedRouteMask);
Sailesh Nepal4cff3922014-03-19 10:15:37 -0700149 }
150
151 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700152 public AudioState[] newArray(int size) {
153 return new AudioState[size];
Sailesh Nepal4cff3922014-03-19 10:15:37 -0700154 }
155 };
156
157 /**
158 * {@inheritDoc}
159 */
160 @Override
161 public int describeContents() {
162 return 0;
163 }
164
165 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700166 * Writes AudioState object into a serializeable Parcel.
Sailesh Nepal4cff3922014-03-19 10:15:37 -0700167 */
168 @Override
169 public void writeToParcel(Parcel destination, int flags) {
170 destination.writeByte((byte) (isMuted ? 1 : 0));
171 destination.writeInt(route);
172 destination.writeInt(supportedRouteMask);
173 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800174
175 /**
176 * @return {@code true} if the call is muted, false otherwise.
177 */
178 public boolean isMuted() {
179 return isMuted;
180 }
181
182 /**
183 * @return The current audio route being used.
184 */
185 public int getRoute() {
186 return route;
187 }
188
189 /**
190 * @return Bit mask of all routes supported by this call.
191 */
192 public int getSupportedRouteMask() {
193 return supportedRouteMask;
194 }
Sailesh Nepal4cff3922014-03-19 10:15:37 -0700195}