Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 1 | /* |
| 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 Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 17 | package android.telecom; |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 18 | |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 19 | import android.annotation.SystemApi; |
Mathew Inwood | e5bfa3e | 2018-08-01 11:26:20 +0100 | [diff] [blame] | 20 | import android.annotation.UnsupportedAppUsage; |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 21 | import android.os.Parcel; |
| 22 | import android.os.Parcelable; |
| 23 | |
| 24 | import java.util.Locale; |
| 25 | |
| 26 | /** |
Santos Cordon | d9e614f | 2014-10-28 13:10:36 -0700 | [diff] [blame] | 27 | * Encapsulates the telecom audio state, including the current audio routing, supported audio |
| 28 | * routing and mute. |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 29 | * @deprecated - use {@link CallAudioState} instead. |
| 30 | * @hide |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 31 | */ |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 32 | @Deprecated |
| 33 | @SystemApi |
| 34 | public class AudioState implements Parcelable { |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 35 | /** Direct the audio stream through the device's earpiece. */ |
Yorke Lee | 1426048 | 2014-08-20 16:16:26 -0700 | [diff] [blame] | 36 | public static final int ROUTE_EARPIECE = 0x00000001; |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 37 | |
| 38 | /** Direct the audio stream through Bluetooth. */ |
Yorke Lee | 1426048 | 2014-08-20 16:16:26 -0700 | [diff] [blame] | 39 | public static final int ROUTE_BLUETOOTH = 0x00000002; |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 40 | |
| 41 | /** Direct the audio stream through a wired headset. */ |
Yorke Lee | 1426048 | 2014-08-20 16:16:26 -0700 | [diff] [blame] | 42 | public static final int ROUTE_WIRED_HEADSET = 0x00000004; |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 43 | |
Nancy Chen | ea38cca | 2014-09-05 16:38:49 -0700 | [diff] [blame] | 44 | /** Direct the audio stream through the device's speakerphone. */ |
Yorke Lee | 1426048 | 2014-08-20 16:16:26 -0700 | [diff] [blame] | 45 | public static final int ROUTE_SPEAKER = 0x00000008; |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 46 | |
| 47 | /** |
| 48 | * Direct the audio stream through the device's earpiece or wired headset if one is |
| 49 | * connected. |
| 50 | */ |
Yorke Lee | 1426048 | 2014-08-20 16:16:26 -0700 | [diff] [blame] | 51 | public static final int ROUTE_WIRED_OR_EARPIECE = ROUTE_EARPIECE | ROUTE_WIRED_HEADSET; |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 52 | |
Jay Shrauner | 55b9752 | 2015-04-09 15:15:43 -0700 | [diff] [blame] | 53 | /** Bit mask of all possible audio routes. */ |
| 54 | private static final int ROUTE_ALL = ROUTE_EARPIECE | ROUTE_BLUETOOTH | ROUTE_WIRED_HEADSET | |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 55 | ROUTE_SPEAKER; |
| 56 | |
Mathew Inwood | e5bfa3e | 2018-08-01 11:26:20 +0100 | [diff] [blame] | 57 | @UnsupportedAppUsage |
Jay Shrauner | 164a0ac | 2015-04-14 18:16:10 -0700 | [diff] [blame] | 58 | private final boolean isMuted; |
Mathew Inwood | e5bfa3e | 2018-08-01 11:26:20 +0100 | [diff] [blame] | 59 | @UnsupportedAppUsage |
Jay Shrauner | 164a0ac | 2015-04-14 18:16:10 -0700 | [diff] [blame] | 60 | private final int route; |
Mathew Inwood | e5bfa3e | 2018-08-01 11:26:20 +0100 | [diff] [blame] | 61 | @UnsupportedAppUsage |
Jay Shrauner | 164a0ac | 2015-04-14 18:16:10 -0700 | [diff] [blame] | 62 | private final int supportedRouteMask; |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 63 | |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 64 | public AudioState(boolean muted, int route, int supportedRouteMask) { |
| 65 | this.isMuted = muted; |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 66 | this.route = route; |
| 67 | this.supportedRouteMask = supportedRouteMask; |
| 68 | } |
| 69 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 70 | public AudioState(AudioState state) { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 71 | isMuted = state.isMuted(); |
| 72 | route = state.getRoute(); |
| 73 | supportedRouteMask = state.getSupportedRouteMask(); |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 74 | } |
| 75 | |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 76 | public AudioState(CallAudioState state) { |
| 77 | isMuted = state.isMuted(); |
| 78 | route = state.getRoute(); |
| 79 | supportedRouteMask = state.getSupportedRouteMask(); |
| 80 | } |
| 81 | |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 82 | @Override |
| 83 | public boolean equals(Object obj) { |
| 84 | if (obj == null) { |
| 85 | return false; |
| 86 | } |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 87 | if (!(obj instanceof AudioState)) { |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 88 | return false; |
| 89 | } |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 90 | AudioState state = (AudioState) obj; |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 91 | return isMuted() == state.isMuted() && getRoute() == state.getRoute() && |
| 92 | getSupportedRouteMask() == state.getSupportedRouteMask(); |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public String toString() { |
| 97 | return String.format(Locale.US, |
Nancy Chen | ddf15a1 | 2014-12-02 15:59:35 -0800 | [diff] [blame] | 98 | "[AudioState isMuted: %b, route: %s, supportedRouteMask: %s]", |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 99 | isMuted, |
| 100 | audioRouteToString(route), |
| 101 | audioRouteToString(supportedRouteMask)); |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 104 | 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 Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 134 | * Responsible for creating AudioState objects for deserialized Parcels. |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 135 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 136 | public static final Parcelable.Creator<AudioState> CREATOR = |
| 137 | new Parcelable.Creator<AudioState> () { |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 138 | |
| 139 | @Override |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 140 | public AudioState createFromParcel(Parcel source) { |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 141 | boolean isMuted = source.readByte() == 0 ? false : true; |
| 142 | int route = source.readInt(); |
| 143 | int supportedRouteMask = source.readInt(); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 144 | return new AudioState(isMuted, route, supportedRouteMask); |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | @Override |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 148 | public AudioState[] newArray(int size) { |
| 149 | return new AudioState[size]; |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 150 | } |
| 151 | }; |
| 152 | |
| 153 | /** |
| 154 | * {@inheritDoc} |
| 155 | */ |
| 156 | @Override |
| 157 | public int describeContents() { |
| 158 | return 0; |
| 159 | } |
| 160 | |
| 161 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 162 | * Writes AudioState object into a serializeable Parcel. |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 163 | */ |
| 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 Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 170 | |
| 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 Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 191 | } |