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; |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 20 | import android.os.Parcel; |
| 21 | import android.os.Parcelable; |
| 22 | |
| 23 | import java.util.Locale; |
| 24 | |
| 25 | /** |
Santos Cordon | d9e614f | 2014-10-28 13:10:36 -0700 | [diff] [blame] | 26 | * Encapsulates the telecom audio state, including the current audio routing, supported audio |
| 27 | * routing and mute. |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 28 | * @deprecated - use {@link CallAudioState} instead. |
| 29 | * @hide |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 30 | */ |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 31 | @Deprecated |
| 32 | @SystemApi |
| 33 | public class AudioState implements Parcelable { |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 34 | /** Direct the audio stream through the device's earpiece. */ |
Yorke Lee | 1426048 | 2014-08-20 16:16:26 -0700 | [diff] [blame] | 35 | public static final int ROUTE_EARPIECE = 0x00000001; |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 36 | |
| 37 | /** Direct the audio stream through Bluetooth. */ |
Yorke Lee | 1426048 | 2014-08-20 16:16:26 -0700 | [diff] [blame] | 38 | public static final int ROUTE_BLUETOOTH = 0x00000002; |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 39 | |
| 40 | /** Direct the audio stream through a wired headset. */ |
Yorke Lee | 1426048 | 2014-08-20 16:16:26 -0700 | [diff] [blame] | 41 | public static final int ROUTE_WIRED_HEADSET = 0x00000004; |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 42 | |
Nancy Chen | ea38cca | 2014-09-05 16:38:49 -0700 | [diff] [blame] | 43 | /** Direct the audio stream through the device's speakerphone. */ |
Yorke Lee | 1426048 | 2014-08-20 16:16:26 -0700 | [diff] [blame] | 44 | public static final int ROUTE_SPEAKER = 0x00000008; |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 45 | |
| 46 | /** |
| 47 | * Direct the audio stream through the device's earpiece or wired headset if one is |
| 48 | * connected. |
| 49 | */ |
Yorke Lee | 1426048 | 2014-08-20 16:16:26 -0700 | [diff] [blame] | 50 | 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] | 51 | |
Jay Shrauner | 55b9752 | 2015-04-09 15:15:43 -0700 | [diff] [blame] | 52 | /** Bit mask of all possible audio routes. */ |
| 53 | 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] | 54 | ROUTE_SPEAKER; |
| 55 | |
Jay Shrauner | 164a0ac | 2015-04-14 18:16:10 -0700 | [diff] [blame] | 56 | private final boolean isMuted; |
| 57 | private final int route; |
| 58 | private final int supportedRouteMask; |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 59 | |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 60 | public AudioState(boolean muted, int route, int supportedRouteMask) { |
| 61 | this.isMuted = muted; |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 62 | this.route = route; |
| 63 | this.supportedRouteMask = supportedRouteMask; |
| 64 | } |
| 65 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 66 | public AudioState(AudioState state) { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 67 | isMuted = state.isMuted(); |
| 68 | route = state.getRoute(); |
| 69 | supportedRouteMask = state.getSupportedRouteMask(); |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 72 | public AudioState(CallAudioState state) { |
| 73 | isMuted = state.isMuted(); |
| 74 | route = state.getRoute(); |
| 75 | supportedRouteMask = state.getSupportedRouteMask(); |
| 76 | } |
| 77 | |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 78 | @Override |
| 79 | public boolean equals(Object obj) { |
| 80 | if (obj == null) { |
| 81 | return false; |
| 82 | } |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 83 | if (!(obj instanceof AudioState)) { |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 84 | return false; |
| 85 | } |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 86 | AudioState state = (AudioState) obj; |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 87 | return isMuted() == state.isMuted() && getRoute() == state.getRoute() && |
| 88 | getSupportedRouteMask() == state.getSupportedRouteMask(); |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | @Override |
| 92 | public String toString() { |
| 93 | return String.format(Locale.US, |
Nancy Chen | ddf15a1 | 2014-12-02 15:59:35 -0800 | [diff] [blame] | 94 | "[AudioState isMuted: %b, route: %s, supportedRouteMask: %s]", |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 95 | isMuted, |
| 96 | audioRouteToString(route), |
| 97 | audioRouteToString(supportedRouteMask)); |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 100 | public static String audioRouteToString(int route) { |
| 101 | if (route == 0 || (route & ~ROUTE_ALL) != 0x0) { |
| 102 | return "UNKNOWN"; |
| 103 | } |
| 104 | |
| 105 | StringBuffer buffer = new StringBuffer(); |
| 106 | if ((route & ROUTE_EARPIECE) == ROUTE_EARPIECE) { |
| 107 | listAppend(buffer, "EARPIECE"); |
| 108 | } |
| 109 | if ((route & ROUTE_BLUETOOTH) == ROUTE_BLUETOOTH) { |
| 110 | listAppend(buffer, "BLUETOOTH"); |
| 111 | } |
| 112 | if ((route & ROUTE_WIRED_HEADSET) == ROUTE_WIRED_HEADSET) { |
| 113 | listAppend(buffer, "WIRED_HEADSET"); |
| 114 | } |
| 115 | if ((route & ROUTE_SPEAKER) == ROUTE_SPEAKER) { |
| 116 | listAppend(buffer, "SPEAKER"); |
| 117 | } |
| 118 | |
| 119 | return buffer.toString(); |
| 120 | } |
| 121 | |
| 122 | private static void listAppend(StringBuffer buffer, String str) { |
| 123 | if (buffer.length() > 0) { |
| 124 | buffer.append(", "); |
| 125 | } |
| 126 | buffer.append(str); |
| 127 | } |
| 128 | |
| 129 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 130 | * Responsible for creating AudioState objects for deserialized Parcels. |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 131 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 132 | public static final Parcelable.Creator<AudioState> CREATOR = |
| 133 | new Parcelable.Creator<AudioState> () { |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 134 | |
| 135 | @Override |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 136 | public AudioState createFromParcel(Parcel source) { |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 137 | boolean isMuted = source.readByte() == 0 ? false : true; |
| 138 | int route = source.readInt(); |
| 139 | int supportedRouteMask = source.readInt(); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 140 | return new AudioState(isMuted, route, supportedRouteMask); |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | @Override |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 144 | public AudioState[] newArray(int size) { |
| 145 | return new AudioState[size]; |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 146 | } |
| 147 | }; |
| 148 | |
| 149 | /** |
| 150 | * {@inheritDoc} |
| 151 | */ |
| 152 | @Override |
| 153 | public int describeContents() { |
| 154 | return 0; |
| 155 | } |
| 156 | |
| 157 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 158 | * Writes AudioState object into a serializeable Parcel. |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 159 | */ |
| 160 | @Override |
| 161 | public void writeToParcel(Parcel destination, int flags) { |
| 162 | destination.writeByte((byte) (isMuted ? 1 : 0)); |
| 163 | destination.writeInt(route); |
| 164 | destination.writeInt(supportedRouteMask); |
| 165 | } |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 166 | |
| 167 | /** |
| 168 | * @return {@code true} if the call is muted, false otherwise. |
| 169 | */ |
| 170 | public boolean isMuted() { |
| 171 | return isMuted; |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * @return The current audio route being used. |
| 176 | */ |
| 177 | public int getRoute() { |
| 178 | return route; |
| 179 | } |
| 180 | |
| 181 | /** |
| 182 | * @return Bit mask of all routes supported by this call. |
| 183 | */ |
| 184 | public int getSupportedRouteMask() { |
| 185 | return supportedRouteMask; |
| 186 | } |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 187 | } |