Add SDK compatibility code for new call states
Add code that translates the new call states to old call states for
in-call UIs that don't yet support background call screening.
Test: CTS
Bug: 140317205
Change-Id: I104f5f7ab3e3dc075e1d9ed5c64fcd924f9a977b
diff --git a/api/test-current.txt b/api/test-current.txt
index f1b00b2..620e931 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -2739,6 +2739,10 @@
method public void exitBackgroundAudioProcessing(boolean);
}
+ public static class Call.Details {
+ method public String getTelecomCallId();
+ }
+
public final class CallAudioState implements android.os.Parcelable {
ctor public CallAudioState(boolean, int, int, @Nullable android.bluetooth.BluetoothDevice, @NonNull java.util.Collection<android.bluetooth.BluetoothDevice>);
}
diff --git a/telecomm/java/android/telecom/Call.java b/telecomm/java/android/telecom/Call.java
index 5e71416..3f348a4 100644
--- a/telecomm/java/android/telecom/Call.java
+++ b/telecomm/java/android/telecom/Call.java
@@ -728,6 +728,7 @@
}
/** {@hide} */
+ @TestApi
public String getTelecomCallId() {
return mTelecomCallId;
}
@@ -2137,6 +2138,9 @@
}
int state = parcelableCall.getState();
+ if (mTargetSdkVersion < Phone.SDK_VERSION_R && state == Call.STATE_SIMULATED_RINGING) {
+ state = Call.STATE_RINGING;
+ }
boolean stateChanged = mState != state;
if (stateChanged) {
mState = state;
diff --git a/telecomm/java/android/telecom/CallScreeningService.java b/telecomm/java/android/telecom/CallScreeningService.java
index 0d97567..ef1c790 100644
--- a/telecomm/java/android/telecom/CallScreeningService.java
+++ b/telecomm/java/android/telecom/CallScreeningService.java
@@ -374,6 +374,8 @@
new ComponentName(getPackageName(), getClass().getName()));
} else if (response.getSilenceCall()) {
mCallScreeningAdapter.silenceCall(callDetails.getTelecomCallId());
+ } else if (response.getShouldScreenCallFurther()) {
+ mCallScreeningAdapter.screenCallFurther(callDetails.getTelecomCallId());
} else {
mCallScreeningAdapter.allowCall(callDetails.getTelecomCallId());
}
diff --git a/telecomm/java/android/telecom/Phone.java b/telecomm/java/android/telecom/Phone.java
index 0cc052e..2ecdb30 100644
--- a/telecomm/java/android/telecom/Phone.java
+++ b/telecomm/java/android/telecom/Phone.java
@@ -21,7 +21,6 @@
import android.bluetooth.BluetoothDevice;
import android.os.Build;
import android.os.Bundle;
-import android.os.RemoteException;
import android.util.ArrayMap;
import java.util.Collections;
@@ -111,6 +110,10 @@
public void onSilenceRinger(Phone phone) { }
}
+ // TODO: replace all usages of this with the actual R constant from Build.VERSION_CODES
+ /** @hide */
+ public static final int SDK_VERSION_R = 30;
+
// A Map allows us to track each Call by its Telecom-specified call ID
private final Map<String, Call> mCallByTelecomCallId = new ArrayMap<>();
@@ -143,6 +146,12 @@
}
final void internalAddCall(ParcelableCall parcelableCall) {
+ if (mTargetSdkVersion < SDK_VERSION_R
+ && parcelableCall.getState() == Call.STATE_AUDIO_PROCESSING) {
+ Log.i(this, "Skipping adding audio processing call for sdk compatibility");
+ return;
+ }
+
Call call = new Call(this, parcelableCall.getId(), mInCallAdapter,
parcelableCall.getState(), mCallingPackage, mTargetSdkVersion);
mCallByTelecomCallId.put(parcelableCall.getId(), call);
@@ -150,7 +159,7 @@
checkCallTree(parcelableCall);
call.internalUpdate(parcelableCall, mCallByTelecomCallId);
fireCallAdded(call);
- }
+ }
final void internalRemoveCall(Call call) {
mCallByTelecomCallId.remove(call.internalGetCallId());
@@ -164,12 +173,28 @@
}
final void internalUpdateCall(ParcelableCall parcelableCall) {
- Call call = mCallByTelecomCallId.get(parcelableCall.getId());
- if (call != null) {
- checkCallTree(parcelableCall);
- call.internalUpdate(parcelableCall, mCallByTelecomCallId);
- }
- }
+ if (mTargetSdkVersion < SDK_VERSION_R
+ && parcelableCall.getState() == Call.STATE_AUDIO_PROCESSING) {
+ Log.i(this, "removing audio processing call during update for sdk compatibility");
+ Call call = mCallByTelecomCallId.get(parcelableCall.getId());
+ if (call != null) {
+ internalRemoveCall(call);
+ }
+ return;
+ }
+
+ Call call = mCallByTelecomCallId.get(parcelableCall.getId());
+ if (call != null) {
+ checkCallTree(parcelableCall);
+ call.internalUpdate(parcelableCall, mCallByTelecomCallId);
+ } else {
+ // This call may have come out of audio processing. Try adding it if our target sdk
+ // version is low enough.
+ if (mTargetSdkVersion < SDK_VERSION_R) {
+ internalAddCall(parcelableCall);
+ }
+ }
+ }
final void internalSetPostDialWait(String telecomId, String remaining) {
Call call = mCallByTelecomCallId.get(telecomId);