summaryrefslogtreecommitdiff
path: root/src/com/android/dialer
diff options
context:
space:
mode:
authorSailesh Nepal <sail@google.com>2016-02-21 13:43:45 -0800
committerSailesh Nepal <sail@google.com>2016-02-22 12:40:45 -0800
commite4be64852dac9e2c55ce8dd5b7063b0c21b9700e (patch)
treef45747e3fd824f97b8f8ccf9254b9533f5deb83d /src/com/android/dialer
parent68d86c656e5522dec1b04e85ebc0e0f78e436c3d (diff)
Remove CallAudioStateCompat
Now that we're no longer backwards compatible with Lollipop we don't need CallAudioStateCompat. See ag/870962 for more info. Bug: 26676586 Change-Id: I7c754d89a6c9e13bf5a004b7c5b15b88b9aff9ad
Diffstat (limited to 'src/com/android/dialer')
-rw-r--r--src/com/android/dialer/compat/CallAudioStateCompat.java331
-rw-r--r--src/com/android/dialer/voicemail/VoicemailAudioManager.java56
2 files changed, 27 insertions, 360 deletions
diff --git a/src/com/android/dialer/compat/CallAudioStateCompat.java b/src/com/android/dialer/compat/CallAudioStateCompat.java
deleted file mode 100644
index 51009d042..000000000
--- a/src/com/android/dialer/compat/CallAudioStateCompat.java
+++ /dev/null
@@ -1,331 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.dialer.compat;
-
-import android.os.Build;
-import android.os.Parcel;
-import android.os.Parcelable;
-import android.telecom.CallAudioState;
-
-import com.android.contacts.common.compat.SdkVersionOverride;
-
-import java.util.Locale;
-
-/**
- * Compatibility class for {@link CallAudioState}
- */
-public class CallAudioStateCompat {
-
- /**
- * Direct the audio stream through the device's earpiece.
- */
- public static final int ROUTE_EARPIECE = CallAudioState.ROUTE_EARPIECE;
-
- /**
- * Direct the audio stream through Bluetooth.
- */
- public static final int ROUTE_BLUETOOTH = CallAudioState.ROUTE_BLUETOOTH;
-
- /**
- * Direct the audio stream through a wired headset.
- */
- public static final int ROUTE_WIRED_HEADSET = CallAudioState.ROUTE_WIRED_HEADSET;
-
- /**
- * Direct the audio stream through the device's speakerphone.
- */
- public static final int ROUTE_SPEAKER = CallAudioState.ROUTE_SPEAKER;
-
- /**
- * Direct the audio stream through the device's earpiece or wired headset if one is connected.
- */
- public static final int ROUTE_WIRED_OR_EARPIECE = CallAudioState.ROUTE_WIRED_OR_EARPIECE;
-
- private final CallAudioStateImpl mCallAudioState;
-
- /**
- * Constructor for a {@link CallAudioStateCompat} object.
- *
- * @param muted {@code true} if the call is muted, {@code false} otherwise.
- * @param route The current audio route being used. Allowed values: {@link #ROUTE_EARPIECE}
- * {@link #ROUTE_BLUETOOTH} {@link #ROUTE_WIRED_HEADSET} {@link #ROUTE_SPEAKER}
- * @param supportedRouteMask Bit mask of all routes supported by this call. This should be a
- * bitwise combination of the following values: {@link #ROUTE_EARPIECE} {@link #ROUTE_BLUETOOTH}
- * {@link #ROUTE_WIRED_HEADSET} {@link #ROUTE_SPEAKER}
- */
- public CallAudioStateCompat(boolean muted, int route, int supportedRouteMask) {
- if (SdkVersionOverride.getSdkVersion(Build.VERSION_CODES.M)
- < Build.VERSION_CODES.M) {
- mCallAudioState = new CallAudioStateBase(muted, route, supportedRouteMask);
- } else {
- mCallAudioState = new CallAudioStateMarshmallow(muted, route, supportedRouteMask);
- }
- }
-
- /**
- * @return {@code true} if the call is muted, {@code false} otherwise.
- */
- public boolean isMuted() {
- return mCallAudioState.isMuted();
- }
-
- /**
- * @return The current audio route being used.
- */
- public int getRoute() {
- return mCallAudioState.getRoute();
- }
-
- /**
- * @return Bit mask of all routes supported by this call.
- */
- public int getSupportedRouteMask() {
- return mCallAudioState.getSupportedRouteMask();
- }
-
- /**
- * Converts the provided audio route into a human readable string representation.
- *
- * @param route to convert into a string.
- * @return String representation of the provided audio route.
- */
- public static String audioRouteToString(int route) {
- if (SdkVersionOverride.getSdkVersion(Build.VERSION_CODES.M)
- < Build.VERSION_CODES.M) {
- return CallAudioStateBase.audioRouteToString(route);
- }
- return CallAudioStateMarshmallow.audioRouteToString(route);
- }
-
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
-
- CallAudioStateCompat that = (CallAudioStateCompat) o;
-
- return mCallAudioState.equals(that.mCallAudioState);
-
- }
-
- @Override
- public int hashCode() {
- return mCallAudioState.hashCode();
- }
-
- @Override
- public String toString() {
- return mCallAudioState.toString();
- }
-
- private interface CallAudioStateImpl {
- boolean isMuted();
- int getRoute();
- int getSupportedRouteMask();
- }
-
- /**
- * CallAudioStateImpl to use if the Sdk version is lower than
- * {@link android.os.Build.VERSION_CODES.M}
- *
- * Coped from {@link android.telecom.CallAudioState}
- *
- * Encapsulates the telecom audio state, including the current audio routing, supported audio
- * routing and mute.
- */
- private static class CallAudioStateBase implements CallAudioStateImpl, Parcelable {
-
- /**
- * Bit mask of all possible audio routes.
- */
- private static final int ROUTE_ALL = ROUTE_EARPIECE | ROUTE_BLUETOOTH | ROUTE_WIRED_HEADSET
- | ROUTE_SPEAKER;
-
- private final boolean isMuted;
- private final int route;
- private final int supportedRouteMask;
-
- /**
- * Constructor for a {@link CallAudioStateBase} object.
- *
- * @param muted {@code true} if the call is muted, {@code false} otherwise.
- * @param route The current audio route being used. Allowed values: {@link #ROUTE_EARPIECE}
- * {@link #ROUTE_BLUETOOTH}, {@link #ROUTE_WIRED_HEADSET}, {@link #ROUTE_SPEAKER}
- * @param supportedRouteMask Bit mask of all routes supported by this call. This should be a
- * bitwise combination of the following values: {@link #ROUTE_EARPIECE},
- * {@link #ROUTE_BLUETOOTH}, {@link #ROUTE_WIRED_HEADSET}, {@link #ROUTE_SPEAKER}
- */
- public CallAudioStateBase(boolean muted, int route, int supportedRouteMask) {
- this.isMuted = muted;
- this.route = route;
- this.supportedRouteMask = supportedRouteMask;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof CallAudioStateBase)) {
- return false;
- }
- CallAudioStateBase state = (CallAudioStateBase) obj;
- return isMuted() == state.isMuted() && getRoute() == state.getRoute() &&
- getSupportedRouteMask() == state.getSupportedRouteMask();
- }
-
- @Override
- public String toString() {
- return String.format(Locale.US,
- "[AudioState isMuted: %b, route: %s, supportedRouteMask: %s]",
- isMuted,
- audioRouteToString(route),
- audioRouteToString(supportedRouteMask));
- }
-
- /**
- * @return {@code true} if the call is muted, {@code false} otherwise.
- */
- @Override
- public boolean isMuted() {
- return isMuted;
- }
-
- /**
- * @return The current audio route being used.
- */
- public int getRoute() {
- return route;
- }
-
- /**
- * @return Bit mask of all routes supported by this call.
- */
- public int getSupportedRouteMask() {
- return supportedRouteMask;
- }
-
- /**
- * Converts the provided audio route into a human readable string representation.
- *
- * @param route to convert into a string.
- * @return String representation of the provided audio route.
- */
- public static String audioRouteToString(int route) {
- if (route == 0 || (route & ~ROUTE_ALL) != 0x0) {
- return "UNKNOWN";
- }
-
- StringBuffer buffer = new StringBuffer();
- if ((route & ROUTE_EARPIECE) == ROUTE_EARPIECE) {
- listAppend(buffer, "EARPIECE");
- }
- if ((route & ROUTE_BLUETOOTH) == ROUTE_BLUETOOTH) {
- listAppend(buffer, "BLUETOOTH");
- }
- if ((route & ROUTE_WIRED_HEADSET) == ROUTE_WIRED_HEADSET) {
- listAppend(buffer, "WIRED_HEADSET");
- }
- if ((route & ROUTE_SPEAKER) == ROUTE_SPEAKER) {
- listAppend(buffer, "SPEAKER");
- }
-
- return buffer.toString();
- }
-
- /**
- * Responsible for creating AudioState objects for deserialized Parcels.
- */
- public static final Parcelable.Creator<CallAudioStateBase> CREATOR =
- new Parcelable.Creator<CallAudioStateBase>() {
-
- @Override
- public CallAudioStateBase createFromParcel(Parcel source) {
- boolean isMuted = source.readByte() == 0 ? false : true;
- int route = source.readInt();
- int supportedRouteMask = source.readInt();
- return new CallAudioStateBase(isMuted, route, supportedRouteMask);
- }
-
- @Override
- public CallAudioStateBase[] newArray(int size) {
- return new CallAudioStateBase[size];
- }
- };
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int describeContents() {
- return 0;
- }
-
- /**
- * Writes AudioState object into a serializeable Parcel.
- */
- @Override
- public void writeToParcel(Parcel destination, int flags) {
- destination.writeByte((byte) (isMuted ? 1 : 0));
- destination.writeInt(route);
- destination.writeInt(supportedRouteMask);
- }
-
- private static void listAppend(StringBuffer buffer, String str) {
- if (buffer.length() > 0) {
- buffer.append(", ");
- }
- buffer.append(str);
- }
- }
-
- /**
- * CallAudioStateImpl to use if the Sdk version is at least
- * {@link android.os.Build.VERSION_CODES.M}
- */
- private static class CallAudioStateMarshmallow implements CallAudioStateImpl {
-
- private final CallAudioState mCallAudioStateDelegate;
-
- public CallAudioStateMarshmallow(boolean muted, int route, int supportedRouteMask) {
- mCallAudioStateDelegate = new CallAudioState(muted, route, supportedRouteMask);
- }
-
- @Override
- public boolean isMuted() {
- return mCallAudioStateDelegate.isMuted();
- }
-
- @Override
- public int getRoute() {
- return mCallAudioStateDelegate.getRoute();
- }
-
- @Override
- public int getSupportedRouteMask() {
- return mCallAudioStateDelegate.getSupportedRouteMask();
- }
-
- public static String audioRouteToString(int route) {
- return CallAudioState.audioRouteToString(route);
- }
- }
-}
diff --git a/src/com/android/dialer/voicemail/VoicemailAudioManager.java b/src/com/android/dialer/voicemail/VoicemailAudioManager.java
index 712b20bf1..fe6cf5f45 100644
--- a/src/com/android/dialer/voicemail/VoicemailAudioManager.java
+++ b/src/com/android/dialer/voicemail/VoicemailAudioManager.java
@@ -19,10 +19,9 @@ package com.android.dialer.voicemail;
import android.content.Context;
import android.media.AudioManager;
import android.media.AudioManager.OnAudioFocusChangeListener;
+import android.telecom.CallAudioState;
import android.util.Log;
-import com.android.dialer.compat.CallAudioStateCompat;
-
import java.util.concurrent.RejectedExecutionException;
/**
@@ -38,7 +37,7 @@ final class VoicemailAudioManager implements OnAudioFocusChangeListener,
private VoicemailPlaybackPresenter mVoicemailPlaybackPresenter;
private WiredHeadsetManager mWiredHeadsetManager;
private boolean mWasSpeakerOn;
- private CallAudioStateCompat mCallAudioState;
+ private CallAudioState mCallAudioState;
public VoicemailAudioManager(Context context,
VoicemailPlaybackPresenter voicemailPlaybackPresenter) {
@@ -82,26 +81,25 @@ final class VoicemailAudioManager implements OnAudioFocusChangeListener,
int newRoute = mCallAudioState.getRoute(); // start out with existing route
if (newIsPluggedIn) {
- newRoute = CallAudioStateCompat.ROUTE_WIRED_HEADSET;
+ newRoute = CallAudioState.ROUTE_WIRED_HEADSET;
} else {
if (mWasSpeakerOn) {
- newRoute = CallAudioStateCompat.ROUTE_SPEAKER;
+ newRoute = CallAudioState.ROUTE_SPEAKER;
} else {
- newRoute = CallAudioStateCompat.ROUTE_EARPIECE;
+ newRoute = CallAudioState.ROUTE_EARPIECE;
}
}
- mVoicemailPlaybackPresenter.setSpeakerphoneOn(newRoute == CallAudioStateCompat.ROUTE_SPEAKER);
+ mVoicemailPlaybackPresenter.setSpeakerphoneOn(newRoute == CallAudioState.ROUTE_SPEAKER);
// We need to call this every time even if we do not change the route because the supported
// routes changed either to include or not include WIRED_HEADSET.
setSystemAudioState(
- new CallAudioStateCompat(false /* muted */, newRoute, calculateSupportedRoutes()));
+ new CallAudioState(false /* muted */, newRoute, calculateSupportedRoutes()));
}
public void setSpeakerphoneOn(boolean on) {
- setAudioRoute(on ? CallAudioStateCompat.ROUTE_SPEAKER
- : CallAudioStateCompat.ROUTE_WIRED_OR_EARPIECE);
+ setAudioRoute(on ? CallAudioState.ROUTE_SPEAKER : CallAudioState.ROUTE_WIRED_OR_EARPIECE);
}
public boolean isWiredHeadsetPluggedIn() {
@@ -120,10 +118,10 @@ final class VoicemailAudioManager implements OnAudioFocusChangeListener,
/**
* Change the audio route, for example from earpiece to speakerphone.
*
- * @param route The new audio route to use. See {@link CallAudioStateCompat}.
+ * @param route The new audio route to use. See {@link CallAudioState}.
*/
void setAudioRoute(int route) {
- Log.v(TAG, "setAudioRoute, route: " + CallAudioStateCompat.audioRouteToString(route));
+ Log.v(TAG, "setAudioRoute, route: " + CallAudioState.audioRouteToString(route));
// Change ROUTE_WIRED_OR_EARPIECE to a single entry.
int newRoute = selectWiredOrEarpiece(route, mCallAudioState.getSupportedRouteMask());
@@ -137,25 +135,25 @@ final class VoicemailAudioManager implements OnAudioFocusChangeListener,
if (mCallAudioState.getRoute() != newRoute) {
// Remember the new speaker state so it can be restored when the user plugs and unplugs
// a headset.
- mWasSpeakerOn = newRoute == CallAudioStateCompat.ROUTE_SPEAKER;
- setSystemAudioState(new CallAudioStateCompat(false /* muted */, newRoute,
+ mWasSpeakerOn = newRoute == CallAudioState.ROUTE_SPEAKER;
+ setSystemAudioState(new CallAudioState(false /* muted */, newRoute,
mCallAudioState.getSupportedRouteMask()));
}
}
- private CallAudioStateCompat getInitialAudioState() {
+ private CallAudioState getInitialAudioState() {
int supportedRouteMask = calculateSupportedRoutes();
- int route = selectWiredOrEarpiece(CallAudioStateCompat.ROUTE_WIRED_OR_EARPIECE,
+ int route = selectWiredOrEarpiece(CallAudioState.ROUTE_WIRED_OR_EARPIECE,
supportedRouteMask);
- return new CallAudioStateCompat(false /* muted */, route, supportedRouteMask);
+ return new CallAudioState(false /* muted */, route, supportedRouteMask);
}
private int calculateSupportedRoutes() {
- int routeMask = CallAudioStateCompat.ROUTE_SPEAKER;
+ int routeMask = CallAudioState.ROUTE_SPEAKER;
if (mWiredHeadsetManager.isPluggedIn()) {
- routeMask |= CallAudioStateCompat.ROUTE_WIRED_HEADSET;
+ routeMask |= CallAudioState.ROUTE_WIRED_HEADSET;
} else {
- routeMask |= CallAudioStateCompat.ROUTE_EARPIECE;
+ routeMask |= CallAudioState.ROUTE_EARPIECE;
}
return routeMask;
}
@@ -164,29 +162,29 @@ final class VoicemailAudioManager implements OnAudioFocusChangeListener,
// Since they are mutually exclusive and one is ALWAYS valid, we allow a special input of
// ROUTE_WIRED_OR_EARPIECE so that callers don't have to make a call to check which is
// supported before calling setAudioRoute.
- if (route == CallAudioStateCompat.ROUTE_WIRED_OR_EARPIECE) {
- route = CallAudioStateCompat.ROUTE_WIRED_OR_EARPIECE & supportedRouteMask;
+ if (route == CallAudioState.ROUTE_WIRED_OR_EARPIECE) {
+ route = CallAudioState.ROUTE_WIRED_OR_EARPIECE & supportedRouteMask;
if (route == 0) {
Log.wtf(TAG, "One of wired headset or earpiece should always be valid.");
// assume earpiece in this case.
- route = CallAudioStateCompat.ROUTE_EARPIECE;
+ route = CallAudioState.ROUTE_EARPIECE;
}
}
return route;
}
- private void setSystemAudioState(CallAudioStateCompat callAudioState) {
- CallAudioStateCompat oldAudioState = mCallAudioState;
+ private void setSystemAudioState(CallAudioState callAudioState) {
+ CallAudioState oldAudioState = mCallAudioState;
mCallAudioState = callAudioState;
Log.i(TAG, "setSystemAudioState: changing from " + oldAudioState + " to "
+ mCallAudioState);
// Audio route.
- if (mCallAudioState.getRoute() == CallAudioStateCompat.ROUTE_SPEAKER) {
+ if (mCallAudioState.getRoute() == CallAudioState.ROUTE_SPEAKER) {
turnOnSpeaker(true);
- } else if (mCallAudioState.getRoute() == CallAudioStateCompat.ROUTE_EARPIECE ||
- mCallAudioState.getRoute() == CallAudioStateCompat.ROUTE_WIRED_HEADSET) {
+ } else if (mCallAudioState.getRoute() == CallAudioState.ROUTE_EARPIECE ||
+ mCallAudioState.getRoute() == CallAudioState.ROUTE_WIRED_HEADSET) {
// Just handle turning off the speaker, the system will handle switching between wired
// headset and earpiece.
turnOnSpeaker(false);
@@ -199,4 +197,4 @@ final class VoicemailAudioManager implements OnAudioFocusChangeListener,
mAudioManager.setSpeakerphoneOn(on);
}
}
-} \ No newline at end of file
+}