| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.telecom; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.annotation.Nullable; |
| 21 |
import android.annotation.SystemApi; |
| 22 |
import android.compat.annotation.UnsupportedAppUsage; |
| 23 |
import android.os.Build; |
| 24 |
import android.os.Parcel; |
| 25 |
import android.os.Parcelable; |
| 26 |
|
| 27 |
import java.util.Locale; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
@Deprecated |
| 36 |
@SystemApi |
| 37 |
public class AudioState implements Parcelable { |
| 38 |
|
| 39 |
public static final int ROUTE_EARPIECE = 0x00000001; |
| 40 |
|
| 41 |
|
| 42 |
public static final int ROUTE_BLUETOOTH = 0x00000002; |
| 43 |
|
| 44 |
|
| 45 |
public static final int ROUTE_WIRED_HEADSET = 0x00000004; |
| 46 |
|
| 47 |
|
| 48 |
public static final int ROUTE_SPEAKER = 0x00000008; |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
public static final int ROUTE_WIRED_OR_EARPIECE = ROUTE_EARPIECE | ROUTE_WIRED_HEADSET; |
| 55 |
|
| 56 |
|
| 57 |
private static final int ROUTE_ALL = ROUTE_EARPIECE | ROUTE_BLUETOOTH | ROUTE_WIRED_HEADSET | |
| 58 |
ROUTE_SPEAKER; |
| 59 |
|
| 60 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 127403196) |
| 61 |
private final boolean isMuted; |
| 62 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 127403196) |
| 63 |
private final int route; |
| 64 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 127403196) |
| 65 |
private final int supportedRouteMask; |
| 66 |
|
| 67 |
public AudioState(boolean muted, int route, int supportedRouteMask) { |
| 68 |
this.isMuted = muted; |
| 69 |
this.route = route; |
| 70 |
this.supportedRouteMask = supportedRouteMask; |
| 71 |
} |
| 72 |
|
| 73 |
public AudioState(AudioState state) { |
| 74 |
isMuted = state.isMuted(); |
| 75 |
route = state.getRoute(); |
| 76 |
supportedRouteMask = state.getSupportedRouteMask(); |
| 77 |
} |
| 78 |
|
| 79 |
public AudioState(CallAudioState state) { |
| 80 |
isMuted = state.isMuted(); |
| 81 |
route = state.getRoute(); |
| 82 |
supportedRouteMask = state.getSupportedRouteMask(); |
| 83 |
} |
| 84 |
|
| 85 |
@Override |
| 86 |
public boolean equals(@Nullable Object obj) { |
| 87 |
if (obj == null) { |
| 88 |
return false; |
| 89 |
} |
| 90 |
if (!(obj instanceof AudioState)) { |
| 91 |
return false; |
| 92 |
} |
| 93 |
AudioState state = (AudioState) obj; |
| 94 |
return isMuted() == state.isMuted() && getRoute() == state.getRoute() && |
| 95 |
getSupportedRouteMask() == state.getSupportedRouteMask(); |
| 96 |
} |
| 97 |
|
| 98 |
@NonNull |
| 99 |
@Override |
| 100 |
public String toString() { |
| 101 |
return String.format(Locale.US, |
| 102 |
"[AudioState isMuted: %b, route: %s, supportedRouteMask: %s]", |
| 103 |
isMuted, |
| 104 |
audioRouteToString(route), |
| 105 |
audioRouteToString(supportedRouteMask)); |
| 106 |
} |
| 107 |
|
| 108 |
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 |
|
| 138 |
|
| 139 |
|
| 140 |
public static final @android.annotation.NonNull Parcelable.Creator<AudioState> CREATOR = |
| 141 |
new Parcelable.Creator<AudioState> () { |
| 142 |
|
| 143 |
@Override |
| 144 |
public AudioState createFromParcel(Parcel source) { |
| 145 |
boolean isMuted = source.readByte() == 0 ? false : true; |
| 146 |
int route = source.readInt(); |
| 147 |
int supportedRouteMask = source.readInt(); |
| 148 |
return new AudioState(isMuted, route, supportedRouteMask); |
| 149 |
} |
| 150 |
|
| 151 |
@Override |
| 152 |
public AudioState[] newArray(int size) { |
| 153 |
return new AudioState[size]; |
| 154 |
} |
| 155 |
}; |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
@Override |
| 161 |
public int describeContents() { |
| 162 |
return 0; |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 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 |
} |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
public boolean isMuted() { |
| 179 |
return isMuted; |
| 180 |
} |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
public int getRoute() { |
| 186 |
return route; |
| 187 |
} |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
public int getSupportedRouteMask() { |
| 193 |
return supportedRouteMask; |
| 194 |
} |
| 195 |
} |