Merge "Revert "Gen. anamoly report when Telecom & Telephony default out are diff"" into main
diff --git a/Android.bp b/Android.bp
index 501b438..5a3561e 100644
--- a/Android.bp
+++ b/Android.bp
@@ -28,6 +28,7 @@
static_libs: [
"androidx.annotation_annotation",
"androidx.core_core",
+ "telecom_flags-lib",
],
libs: [
"services",
@@ -50,6 +51,7 @@
name: "TelecomUnitTests",
static_libs: [
"android-ex-camera2",
+ "flag-junit",
"guava",
"mockito-target-extended",
"androidx.test.rules",
@@ -60,6 +62,7 @@
"androidx.fragment_fragment",
"androidx.test.ext.junit",
"platform-compat-test-rules",
+ "telecom_flags-lib",
],
srcs: [
"tests/src/**/*.java",
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index ab067d9..28c85e1 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -28,7 +28,6 @@
<!-- Prevents the activity manager from delaying any activity-start
requests by this package, including requests immediately after
the user presses "home". -->
- <uses-permission android:name="android.permission.BIND_CONNECTION_SERVICE"/>
<uses-permission android:name="android.permission.BIND_INCALL_SERVICE"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
diff --git a/OWNERS b/OWNERS
index 97cc81f..7e68aea 100644
--- a/OWNERS
+++ b/OWNERS
@@ -1,7 +1,6 @@
breadley@google.com
tgunn@google.com
xiaotonj@google.com
-chinmayd@google.com
tjstuart@google.com
rgreenwalt@google.com
pmadapurmath@google.com
diff --git a/flags/Android.bp b/flags/Android.bp
new file mode 100644
index 0000000..402826a
--- /dev/null
+++ b/flags/Android.bp
@@ -0,0 +1,36 @@
+//
+// Copyright (C) 2023 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 {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+aconfig_declarations {
+ name: "telecom_flags",
+ package: "com.android.server.telecom.flags",
+ srcs: [
+ "telecom_broadcast_flags.aconfig",
+ "telecom_ringer_flag_declarations.aconfig",
+ "telecom_api_flags.aconfig",
+ "telecom_call_filtering_flags.aconfig",
+ "telecom_incallservice_flags.aconfig"
+ ],
+}
+
+java_aconfig_library {
+ name: "telecom_flags-lib",
+ aconfig_declarations: "telecom_flags"
+}
\ No newline at end of file
diff --git a/flags/telecom_api_flags.aconfig b/flags/telecom_api_flags.aconfig
new file mode 100644
index 0000000..e956a38
--- /dev/null
+++ b/flags/telecom_api_flags.aconfig
@@ -0,0 +1,8 @@
+package: "com.android.server.telecom.flags"
+
+flag {
+ name: "voip_app_actions_support"
+ namespace: "telecom"
+ description: "When set, Telecom support for additional VOIP application actions is active."
+ bug: "296934278"
+}
\ No newline at end of file
diff --git a/flags/telecom_broadcast_flags.aconfig b/flags/telecom_broadcast_flags.aconfig
new file mode 100644
index 0000000..348d574
--- /dev/null
+++ b/flags/telecom_broadcast_flags.aconfig
@@ -0,0 +1,8 @@
+package: "com.android.server.telecom.flags"
+
+flag {
+ name: "is_new_outgoing_call_broadcast_unblocking"
+ namespace: "telecom"
+ description: "When set, the ACTION_NEW_OUTGOING_CALL broadcast is unblocking."
+ bug: "224550864"
+}
\ No newline at end of file
diff --git a/flags/telecom_call_filtering_flags.aconfig b/flags/telecom_call_filtering_flags.aconfig
new file mode 100644
index 0000000..95e74ce
--- /dev/null
+++ b/flags/telecom_call_filtering_flags.aconfig
@@ -0,0 +1,8 @@
+package: "com.android.server.telecom.flags"
+
+flag {
+ name: "skip_filter_phone_account_perform_dnd_filter"
+ namespace: "telecom"
+ description: "Gates whether to still perform Dnd filter when phone account has skip_filter call extra."
+ bug: "222333869"
+}
\ No newline at end of file
diff --git a/flags/telecom_incallservice_flags.aconfig b/flags/telecom_incallservice_flags.aconfig
new file mode 100644
index 0000000..d70b9cc
--- /dev/null
+++ b/flags/telecom_incallservice_flags.aconfig
@@ -0,0 +1,8 @@
+package: "com.android.server.telecom.flags"
+
+flag {
+ name: "early_binding_to_incall_service"
+ namespace: "telecom"
+ description: "Binds to InCallServices when call requires no call filtering on watch"
+ bug: "282113261"
+}
\ No newline at end of file
diff --git a/flags/telecom_ringer_flag_declarations.aconfig b/flags/telecom_ringer_flag_declarations.aconfig
new file mode 100644
index 0000000..54748d0
--- /dev/null
+++ b/flags/telecom_ringer_flag_declarations.aconfig
@@ -0,0 +1,8 @@
+package: "com.android.server.telecom.flags"
+
+flag {
+ name: "use_device_provided_serialized_ringer_vibration"
+ namespace: "telecom"
+ description: "Gates whether to use a serialized, device-specific ring vibration."
+ bug: "282113261"
+}
\ No newline at end of file
diff --git a/proguard.flags b/proguard.flags
index 635eba6..7c71a15 100644
--- a/proguard.flags
+++ b/proguard.flags
@@ -9,17 +9,3 @@
-keep class android.telecom.Log {
*;
}
-
-# Keep classes, annotations and members used by Lifecycle. Remove this once aapt2 is enabled
--keepattributes *Annotation*
-
--keep class * implements android.arch.lifecycle.LifecycleObserver {
-}
-
--keep class * implements android.arch.lifecycle.GeneratedAdapter {
- <init>(...);
-}
-
--keepclassmembers class ** {
- @android.arch.lifecycle.OnLifecycleEvent *;
-}
diff --git a/res/values-el/strings.xml b/res/values-el/strings.xml
index 2cf961d..6b58863 100644
--- a/res/values-el/strings.xml
+++ b/res/values-el/strings.xml
@@ -101,7 +101,7 @@
<string name="notification_channel_disconnected_calls" msgid="8228636543997645757">"Αποσυνδεδεμένες κλήσεις"</string>
<string name="notification_channel_in_call_service_crash" msgid="7313237519166984267">"Εφαρμογές τηλεφώνου που αντιμετώπισαν σφάλμα λειτουργίας"</string>
<string name="notification_channel_call_streaming" msgid="5100510699787538991">"Ροή κλήσης"</string>
- <string name="alert_outgoing_call" msgid="5319895109298927431">"Εάν πραγματοποιήσετε αυτήν την κλήση, η κλήση σας μέσω <xliff:g id="OTHER_APP">%1$s</xliff:g> θα τερματιστεί."</string>
+ <string name="alert_outgoing_call" msgid="5319895109298927431">"Εάν πραγματοποιήσετε αυτή την κλήση, η κλήση σας μέσω <xliff:g id="OTHER_APP">%1$s</xliff:g> θα τερματιστεί."</string>
<string name="alert_redirect_outgoing_call_or_not" msgid="665409645789521636">"Επιλέξτε πώς θα πραγματοποιήσετε την κλήση"</string>
<string name="alert_place_outgoing_call_with_redirection" msgid="5221065030959024121">"Ανακατεύθυνση της κλήσης μέσω <xliff:g id="OTHER_APP">%1$s</xliff:g>"</string>
<string name="alert_place_unredirect_outgoing_call" msgid="2467608535225764006">"Κλήση μέσω του αριθμού τηλεφώνου μου"</string>
diff --git a/res/values-zh-rCN/strings.xml b/res/values-zh-rCN/strings.xml
index 071289e..1ef0a55 100644
--- a/res/values-zh-rCN/strings.xml
+++ b/res/values-zh-rCN/strings.xml
@@ -45,7 +45,7 @@
<string name="respond_via_sms_edittext_dialog_title" msgid="6579353156073272157">"快速回复"</string>
<string name="respond_via_sms_confirmation_format" msgid="2932395476561267842">"讯息已发送至 <xliff:g id="PHONE_NUMBER">%s</xliff:g>。"</string>
<string name="respond_via_sms_failure_format" msgid="5198680980054596391">"未能将信息发送到 <xliff:g id="PHONE_NUMBER">%s</xliff:g>。"</string>
- <string name="enable_account_preference_title" msgid="6949224486748457976">"通话帐号"</string>
+ <string name="enable_account_preference_title" msgid="6949224486748457976">"通话账号"</string>
<string name="outgoing_call_not_allowed_user_restriction" msgid="3424338207838851646">"只能拨打紧急呼救电话。"</string>
<string name="outgoing_call_not_allowed_no_permission" msgid="8590468836581488679">"此应用没有电话权限,无法拨出电话。"</string>
<string name="outgoing_call_error_no_phone_number_supplied" msgid="7665135102566099778">"要拨打电话,请输入有效的电话号码。"</string>
@@ -90,7 +90,7 @@
<string name="answering_ends_other_managed_video_call" msgid="1988508241432031327">"如果接听此来电,您当前的视频通话会中断。"</string>
<string name="answer_incoming_call" msgid="2045888814782215326">"接听"</string>
<string name="decline_incoming_call" msgid="922147089348451310">"拒接"</string>
- <string name="cant_call_due_to_no_supported_service" msgid="1635626384149947077">"无法拨出电话,因为没有通话帐号支持拨打这类电话。"</string>
+ <string name="cant_call_due_to_no_supported_service" msgid="1635626384149947077">"无法拨出电话,因为没有通话账号支持拨打这类电话。"</string>
<string name="cant_call_due_to_ongoing_call" msgid="8004235328451385493">"由于当前正在进行 <xliff:g id="OTHER_CALL">%1$s</xliff:g> 通话,因此无法拨打电话。"</string>
<string name="cant_call_due_to_ongoing_calls" msgid="6379163795277824868">"由于当前正在进行 <xliff:g id="OTHER_CALL">%1$s</xliff:g> 通话,因此无法拨打电话。"</string>
<string name="cant_call_due_to_ongoing_unknown_call" msgid="8243532328969433172">"由于当前正在通过其他应用通话,因此无法拨打电话。"</string>
diff --git a/res/values/config.xml b/res/values/config.xml
index 15f765b..c38a6ec 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -49,8 +49,10 @@
<bool name="grant_location_permission_enabled">false</bool>
<!-- When true, a simple full intensity on/off vibration pattern will be used when calls ring.
- When false, a fancy vibration pattern which ramps up and down will be used.
- Devices should overlay this value based on the type of vibration hardware they employ. -->
+
+ When false, the vibration effect serialized in the raw `default_ringtone_vibration_effect`
+ resource (under `frameworks/base/core/res/res/raw/`) is used. Devices should overlay this
+ value based on the type of vibration hardware they employ. -->
<bool name="use_simple_vibration_pattern">false</bool>
<!-- Threshold for the X+Y component of gravity needed for the device orientation to be
diff --git a/res/xml/activity_blocked_numbers.xml b/res/xml/activity_blocked_numbers.xml
index e77184d..b6298e9 100644
--- a/res/xml/activity_blocked_numbers.xml
+++ b/res/xml/activity_blocked_numbers.xml
@@ -41,8 +41,8 @@
android:layout_height="wrap_content"
android:text="@string/non_primary_user"
android:paddingTop="@dimen/blocked_numbers_large_padding"
- android:paddingLeft="@dimen/blocked_numbers_large_padding"
- android:paddingRight="@dimen/blocked_numbers_large_padding"
+ android:paddingStart="@dimen/blocked_numbers_large_padding"
+ android:paddingEnd="@dimen/blocked_numbers_large_padding"
style="@style/BlockedNumbersTextPrimary2"
android:visibility="gone" />
@@ -62,8 +62,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/blocked_numbers_large_padding"
- android:paddingLeft="@dimen/blocked_numbers_large_padding"
- android:paddingRight="@dimen/blocked_numbers_large_padding">
+ android:paddingStart="@dimen/blocked_numbers_large_padding"
+ android:paddingEnd="@dimen/blocked_numbers_large_padding">
<TextView
android:layout_width="wrap_content"
diff --git a/res/xml/blocking_suppressed_butterbar.xml b/res/xml/blocking_suppressed_butterbar.xml
index 8b941b9..2947340 100644
--- a/res/xml/blocking_suppressed_butterbar.xml
+++ b/res/xml/blocking_suppressed_butterbar.xml
@@ -25,19 +25,19 @@
android:id="@+id/icon"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
- android:layout_alignParentLeft="true"
+ android:layout_alignParentStart="true"
android:paddingTop="@dimen/blocked_numbers_large_padding"
- android:paddingRight="@dimen/blocked_numbers_large_padding"
- android:paddingLeft="@dimen/blocked_numbers_large_padding"
+ android:paddingEnd="@dimen/blocked_numbers_large_padding"
+ android:paddingStart="@dimen/blocked_numbers_large_padding"
android:src="@drawable/ic_status_blocked_orange_40dp"/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_toRightOf="@id/icon"
+ android:layout_toEndOf="@id/icon"
android:paddingTop="@dimen/blocked_numbers_large_padding"
- android:paddingRight="@dimen/blocked_numbers_large_padding"
+ android:paddingEnd="@dimen/blocked_numbers_large_padding"
android:text="@string/blocked_numbers_butter_bar_title"
style="@style/BlockedNumbersTextPrimary2" />
@@ -45,11 +45,11 @@
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_toRightOf="@id/icon"
+ android:layout_toEndOf="@id/icon"
android:layout_below="@id/title"
android:paddingTop="@dimen/blocked_numbers_large_padding"
android:paddingBottom="@dimen/blocked_numbers_large_padding"
- android:paddingRight="@dimen/blocked_numbers_large_padding"
+ android:paddingEnd="@dimen/blocked_numbers_large_padding"
android:text="@string/blocked_numbers_butter_bar_body"
style="@style/BlockedNumbersTextSecondary" />
@@ -57,9 +57,9 @@
android:id="@+id/reenable_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_toRightOf="@id/icon"
+ android:layout_toEndOf="@id/icon"
android:layout_below="@id/description"
- android:paddingRight="@dimen/blocked_numbers_large_padding"
+ android:paddingEnd="@dimen/blocked_numbers_large_padding"
android:text="@string/blocked_numbers_butter_bar_button"
style="@style/BlockedNumbersButton"
android:background="?android:attr/selectableItemBackgroundBorderless" />
diff --git a/src/com/android/server/telecom/Call.java b/src/com/android/server/telecom/Call.java
index c32d2bf..d095522 100644
--- a/src/com/android/server/telecom/Call.java
+++ b/src/com/android/server/telecom/Call.java
@@ -17,7 +17,7 @@
package com.android.server.telecom;
import static android.provider.CallLog.Calls.MISSED_REASON_NOT_MISSED;
-import static android.telecom.Call.EVENT_DISPLAY_SOS_MESSAGE;
+import static android.telephony.TelephonyManager.EVENT_DISPLAY_SOS_MESSAGE;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -30,6 +30,7 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
+import android.os.OutcomeReceiver;
import android.os.ParcelFileDescriptor;
import android.os.Parcelable;
import android.os.RemoteException;
@@ -43,6 +44,7 @@
import android.telecom.CallAudioState;
import android.telecom.CallDiagnosticService;
import android.telecom.CallDiagnostics;
+import android.telecom.CallException;
import android.telecom.CallerInfo;
import android.telecom.Conference;
import android.telecom.Connection;
@@ -73,6 +75,9 @@
import com.android.server.telecom.stats.CallFailureCause;
import com.android.server.telecom.stats.CallStateChangedAtomWriter;
import com.android.server.telecom.ui.ToastFactory;
+import com.android.server.telecom.voip.TransactionManager;
+import com.android.server.telecom.voip.VerifyCallStateChangeTransaction;
+import com.android.server.telecom.voip.VoipCallTransactionResult;
import java.io.IOException;
import java.text.SimpleDateFormat;
@@ -118,6 +123,24 @@
private static final char NO_DTMF_TONE = '\0';
+
+ /**
+ * Listener for CallState changes which can be leveraged by a Transaction.
+ */
+ public interface CallStateListener {
+ void onCallStateChanged(int newCallState);
+ }
+
+ public List<CallStateListener> mCallStateListeners = new ArrayList<>();
+
+ public void addCallStateListener(CallStateListener newListener) {
+ mCallStateListeners.add(newListener);
+ }
+
+ public boolean removeCallStateListener(CallStateListener newListener) {
+ return mCallStateListeners.remove(newListener);
+ }
+
/**
* Listener for events on the call.
*/
@@ -1328,6 +1351,10 @@
Log.addEvent(this, event, stringData);
}
+ for (CallStateListener listener : mCallStateListeners) {
+ listener.onCallStateChanged(newState);
+ }
+
mCallStateChangedAtomWriter
.setDisconnectCause(getDisconnectCause())
.setSelfManaged(isSelfManaged())
@@ -2898,11 +2925,16 @@
hold(null /* reason */);
}
+ /**
+ * This method requests the ConnectionService or TransactionalService hosting the call to put
+ * the call on hold
+ */
public void hold(String reason) {
if (mState == CallState.ACTIVE) {
if (mTransactionalService != null) {
mTransactionalService.onSetInactive(this);
} else if (mConnectionService != null) {
+ awaitCallStateChangeAndMaybeDisconnectCall(CallState.ON_HOLD, isSelfManaged(), "hold");
mConnectionService.hold(this);
} else {
Log.e(this, new NullPointerException(),
@@ -2913,6 +2945,27 @@
}
/**
+ * helper that can be used for any callback that requests a call state change and wants to
+ * verify the change
+ */
+ public void awaitCallStateChangeAndMaybeDisconnectCall(int targetCallState,
+ boolean shouldDisconnectUponTimeout, String callingMethod) {
+ TransactionManager tm = TransactionManager.getInstance();
+ tm.addTransaction(new VerifyCallStateChangeTransaction(mCallsManager,
+ this, targetCallState, shouldDisconnectUponTimeout), new OutcomeReceiver<>() {
+ @Override
+ public void onResult(VoipCallTransactionResult result) {
+ }
+
+ @Override
+ public void onError(CallException e) {
+ Log.i(this, "awaitCallStateChangeAndMaybeDisconnectCall: %s: onError"
+ + " due to CallException=[%s]", callingMethod, e);
+ }
+ });
+ }
+
+ /**
* Releases the call from hold if it is currently active.
*/
@VisibleForTesting
@@ -3663,7 +3716,8 @@
}
String newName = callerInfo.getName();
- boolean contactNameChanged = mCallerInfo == null || !mCallerInfo.getName().equals(newName);
+ boolean contactNameChanged = mCallerInfo == null ||
+ !Objects.equals(mCallerInfo.getName(), newName);
mCallerInfo = callerInfo;
Log.i(this, "CallerInfo received for %s: %s", Log.piiHandle(mHandle), callerInfo);
diff --git a/src/com/android/server/telecom/CallIntentProcessor.java b/src/com/android/server/telecom/CallIntentProcessor.java
index 7953324..062c872 100644
--- a/src/com/android/server/telecom/CallIntentProcessor.java
+++ b/src/com/android/server/telecom/CallIntentProcessor.java
@@ -1,6 +1,7 @@
package com.android.server.telecom;
import com.android.server.telecom.components.ErrorDialogActivity;
+import com.android.server.telecom.flags.FeatureFlags;
import android.content.Context;
import android.content.Intent;
@@ -32,7 +33,7 @@
public class CallIntentProcessor {
public interface Adapter {
void processOutgoingCallIntent(Context context, CallsManager callsManager,
- Intent intent, String callingPackage);
+ Intent intent, String callingPackage, FeatureFlags featureFlags);
void processIncomingCallIntent(CallsManager callsManager, Intent intent);
void processUnknownCallIntent(CallsManager callsManager, Intent intent);
}
@@ -45,9 +46,9 @@
@Override
public void processOutgoingCallIntent(Context context, CallsManager callsManager,
- Intent intent, String callingPackage) {
+ Intent intent, String callingPackage, FeatureFlags featureFlags) {
CallIntentProcessor.processOutgoingCallIntent(context, callsManager, intent,
- callingPackage, mDefaultDialerCache);
+ callingPackage, mDefaultDialerCache, featureFlags);
}
@Override
@@ -73,12 +74,14 @@
private final Context mContext;
private final CallsManager mCallsManager;
private final DefaultDialerCache mDefaultDialerCache;
+ private final FeatureFlags mFeatureFlags;
public CallIntentProcessor(Context context, CallsManager callsManager,
- DefaultDialerCache defaultDialerCache) {
+ DefaultDialerCache defaultDialerCache, FeatureFlags featureFlags) {
this.mContext = context;
this.mCallsManager = callsManager;
this.mDefaultDialerCache = defaultDialerCache;
+ this.mFeatureFlags = featureFlags;
}
public void processIntent(Intent intent, String callingPackage) {
@@ -90,7 +93,7 @@
processUnknownCallIntent(mCallsManager, intent);
} else {
processOutgoingCallIntent(mContext, mCallsManager, intent, callingPackage,
- mDefaultDialerCache);
+ mDefaultDialerCache, mFeatureFlags);
}
Trace.endSection();
}
@@ -107,7 +110,8 @@
CallsManager callsManager,
Intent intent,
String callingPackage,
- DefaultDialerCache defaultDialerCache) {
+ DefaultDialerCache defaultDialerCache,
+ FeatureFlags featureFlags) {
Uri handle = intent.getData();
String scheme = handle.getScheme();
@@ -182,10 +186,9 @@
boolean isPrivilegedDialer = defaultDialerCache.isDefaultOrSystemDialer(callingPackage,
initiatingUser.getIdentifier());
-
NewOutgoingCallIntentBroadcaster broadcaster = new NewOutgoingCallIntentBroadcaster(
context, callsManager, intent, callsManager.getPhoneNumberUtilsAdapter(),
- isPrivilegedDialer, defaultDialerCache, new MmiUtils());
+ isPrivilegedDialer, defaultDialerCache, new MmiUtils(), featureFlags);
// If the broadcaster comes back with an immediate error, disconnect and show a dialog.
NewOutgoingCallIntentBroadcaster.CallDisposition disposition = broadcaster.evaluateCall();
diff --git a/src/com/android/server/telecom/CallLogManager.java b/src/com/android/server/telecom/CallLogManager.java
index 72aecac..85a4239 100644
--- a/src/com/android/server/telecom/CallLogManager.java
+++ b/src/com/android/server/telecom/CallLogManager.java
@@ -664,19 +664,16 @@
}
int maxCallId = -1;
int numFound;
- Cursor countCursor = resolver.query(providerUri,
+ try (Cursor countCursor = resolver.query(providerUri,
new String[]{Calls._ID},
null,
null,
- Calls._ID + " DESC");
- try {
+ Calls._ID + " DESC")) {
numFound = countCursor.getCount();
if (numFound > 0) {
countCursor.moveToFirst();
maxCallId = countCursor.getInt(0);
}
- } finally {
- countCursor.close();
}
return new Pair<>(numFound, maxCallId);
} catch (Exception e) {
diff --git a/src/com/android/server/telecom/CallsManager.java b/src/com/android/server/telecom/CallsManager.java
old mode 100644
new mode 100755
index abf3478..9c31572
--- a/src/com/android/server/telecom/CallsManager.java
+++ b/src/com/android/server/telecom/CallsManager.java
@@ -129,9 +129,12 @@
import com.android.server.telecom.callfiltering.DirectToVoicemailFilter;
import com.android.server.telecom.callfiltering.DndCallFilter;
import com.android.server.telecom.callfiltering.IncomingCallFilterGraph;
+import com.android.server.telecom.callfiltering.IncomingCallFilterGraphProvider;
import com.android.server.telecom.callredirection.CallRedirectionProcessor;
import com.android.server.telecom.components.ErrorDialogActivity;
import com.android.server.telecom.components.TelecomBroadcastReceiver;
+import com.android.server.telecom.components.UserCallIntentProcessor;
+import com.android.server.telecom.flags.FeatureFlags;
import com.android.server.telecom.stats.CallFailureCause;
import com.android.server.telecom.ui.AudioProcessingNotification;
import com.android.server.telecom.ui.CallRedirectionTimeoutDialogActivity;
@@ -286,11 +289,6 @@
public static final String EXCEPTION_RETRIEVING_PHONE_ACCOUNTS_EMERGENCY_ERROR_MSG =
"Exception thrown while retrieving list of potential phone accounts when placing an "
+ "emergency call.";
- public static final UUID EMERGENCY_CALL_DISCONNECTED_BEFORE_BEING_ADDED_ERROR_UUID =
- UUID.fromString("f9a916c8-8d61-4550-9ad3-11c2e84f6364");
- public static final String EMERGENCY_CALL_DISCONNECTED_BEFORE_BEING_ADDED_ERROR_MSG =
- "An emergency call was disconnected after the connection was created but before the "
- + "call was successfully added to CallsManager.";
public static final UUID EMERGENCY_CALL_ABORTED_NO_PHONE_ACCOUNTS_ERROR_UUID =
UUID.fromString("2e994acb-1997-4345-8bf3-bad04303de26");
public static final String EMERGENCY_CALL_ABORTED_NO_PHONE_ACCOUNTS_ERROR_MSG =
@@ -463,6 +461,9 @@
private final TransactionManager mTransactionManager;
private final UserManager mUserManager;
private final CallStreamingNotification mCallStreamingNotification;
+ private final FeatureFlags mFeatureFlags;
+
+ private final IncomingCallFilterGraphProvider mIncomingCallFilterGraphProvider;
private final ConnectionServiceFocusManager.CallsManagerRequester mRequester =
new ConnectionServiceFocusManager.CallsManagerRequester() {
@@ -577,7 +578,9 @@
TransactionManager transactionManager,
EmergencyCallDiagnosticLogger emergencyCallDiagnosticLogger,
CallAudioCommunicationDeviceTracker communicationDeviceTracker,
- CallStreamingNotification callStreamingNotification) {
+ CallStreamingNotification callStreamingNotification,
+ FeatureFlags featureFlags,
+ IncomingCallFilterGraphProvider incomingCallFilterGraphProvider) {
mContext = context;
mLock = lock;
@@ -596,6 +599,7 @@
mEmergencyCallHelper = emergencyCallHelper;
mCallerInfoLookupHelper = callerInfoLookupHelper;
mEmergencyCallDiagnosticLogger = emergencyCallDiagnosticLogger;
+ mIncomingCallFilterGraphProvider = incomingCallFilterGraphProvider;
mDtmfLocalTonePlayer =
new DtmfLocalTonePlayer(new DtmfLocalTonePlayer.ToneGeneratorProxy());
@@ -643,7 +647,7 @@
ringtoneFactory, systemVibrator,
new Ringer.VibrationEffectProxy(), mInCallController,
mContext.getSystemService(NotificationManager.class),
- accessibilityManagerAdapter);
+ accessibilityManagerAdapter, featureFlags);
mCallRecordingTonePlayer = new CallRecordingTonePlayer(mContext, audioManager,
mTimeoutsAdapter, mLock);
mCallAudioManager = new CallAudioManager(callAudioRouteStateMachine,
@@ -670,6 +674,7 @@
mBlockedNumbersAdapter = blockedNumbersAdapter;
mCallStreamingController = new CallStreamingController(mContext, mLock);
mCallStreamingNotification = callStreamingNotification;
+ mFeatureFlags = featureFlags;
mListeners.add(mInCallController);
mListeners.add(mInCallWakeLockController);
@@ -749,11 +754,10 @@
@Override
@VisibleForTesting
public void onSuccessfulOutgoingCall(Call call, int callState) {
- Log.v(this, "onSuccessfulOutgoingCall, %s", call);
+ Log.v(this, "onSuccessfulOutgoingCall, call=[%s], state=[%d]", call, callState);
call.setPostCallPackageName(getRoleManagerAdapter().getDefaultCallScreeningApp(
call.getAssociatedUser()));
- setCallState(call, callState, "successful outgoing call");
if (!mCalls.contains(call)) {
// Call was not added previously in startOutgoingCall due to it being a potential MMI
// code, so add it now.
@@ -765,7 +769,13 @@
listener.onConnectionServiceChanged(call, null, call.getConnectionService());
}
- markCallAsDialing(call);
+ // Allow the ConnectionService to start the call in the active state. This case is helpful
+ // for conference calls or meetings that can skip the dialing stage.
+ if (callState == CallState.ACTIVE) {
+ setCallState(call, callState, "skipping the dialing state and setting active");
+ } else {
+ markCallAsDialing(call);
+ }
}
@Override
@@ -784,11 +794,12 @@
? new Bundle()
: phoneAccount.getExtras();
TelephonyManager telephonyManager = getTelephonyManager();
+ boolean performDndFilter = mFeatureFlags.skipFilterPhoneAccountPerformDndFilter();
if (incomingCall.hasProperty(Connection.PROPERTY_EMERGENCY_CALLBACK_MODE) ||
incomingCall.hasProperty(Connection.PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL) ||
telephonyManager.isInEmergencySmsMode() ||
incomingCall.isSelfManaged() ||
- extras.getBoolean(PhoneAccount.EXTRA_SKIP_CALL_FILTERING)) {
+ (!performDndFilter && extras.getBoolean(PhoneAccount.EXTRA_SKIP_CALL_FILTERING))) {
Log.i(this, "Skipping call filtering for %s (ecm=%b, "
+ "networkIdentifiedEmergencyCall = %b, emergencySmsMode = %b, "
+ "selfMgd=%b, skipExtra=%b)",
@@ -806,12 +817,27 @@
.build(), false);
incomingCall.setIsUsingCallFiltering(false);
return;
+ } else if (performDndFilter && extras.getBoolean(PhoneAccount.EXTRA_SKIP_CALL_FILTERING)) {
+ IncomingCallFilterGraph graph = setupDndFilterOnlyGraph(incomingCall);
+ graph.performFiltering();
+ return;
}
IncomingCallFilterGraph graph = setUpCallFilterGraph(incomingCall);
graph.performFiltering();
}
+ private IncomingCallFilterGraph setupDndFilterOnlyGraph(Call incomingHfpCall) {
+ incomingHfpCall.setIsUsingCallFiltering(true);
+ DndCallFilter dndCallFilter = new DndCallFilter(incomingHfpCall, mRinger);
+ IncomingCallFilterGraph graph = mIncomingCallFilterGraphProvider.createGraph(
+ incomingHfpCall,
+ this::onCallFilteringComplete, mContext, mTimeoutsAdapter, mLock);
+ graph.addFilter(dndCallFilter);
+ mGraphHandlerThreads.add(graph.getHandlerThread());
+ return graph;
+ }
+
private IncomingCallFilterGraph setUpCallFilterGraph(Call incomingCall) {
incomingCall.setIsUsingCallFiltering(true);
String carrierPackageName = getCarrierPackageName();
@@ -824,7 +850,7 @@
mContext.getPackageManager(), packageName);
ParcelableCallUtils.Converter converter = new ParcelableCallUtils.Converter();
- IncomingCallFilterGraph graph = new IncomingCallFilterGraph(incomingCall,
+ IncomingCallFilterGraph graph = mIncomingCallFilterGraphProvider.createGraph(incomingCall,
this::onCallFilteringComplete, mContext, mTimeoutsAdapter, mLock);
DirectToVoicemailFilter voicemailFilter = new DirectToVoicemailFilter(incomingCall,
mCallerInfoLookupHelper);
@@ -1304,7 +1330,7 @@
return mCallAudioManager;
}
- InCallController getInCallController() {
+ public InCallController getInCallController() {
return mInCallController;
}
@@ -2311,6 +2337,15 @@
PhoneAccountHandle phoneAccountHandle = clientExtras.getParcelable(
TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE);
+ PhoneAccount account =
+ mPhoneAccountRegistrar.getPhoneAccount(phoneAccountHandle, initiatingUser);
+ boolean isSelfManaged = account != null && account.isSelfManaged();
+ // Enforce outgoing call restriction for conference calls. This is handled via
+ // UserCallIntentProcessor for normal MO calls.
+ if (UserUtil.hasOutgoingCallsUserRestriction(mContext, initiatingUser,
+ null, isSelfManaged, CallsManager.class.getCanonicalName())) {
+ return;
+ }
CompletableFuture<Call> callFuture = startOutgoingCall(participants, phoneAccountHandle,
clientExtras, initiatingUser, null/* originalIntent */, callingPackage,
true/* isconference*/);
@@ -2888,6 +2923,10 @@
call.answer(videoState);
} else {
// Hold or disconnect the active call and request call focus for the incoming call.
+ Bundle bundle = new Bundle();
+ bundle.putLong(TelecomManager.EXTRA_CALL_ANSWERED_TIME_MILLIS,
+ mClockProxy.currentTimeMillis());
+ call.putConnectionServiceExtras(bundle);
holdActiveCallForNewCall(call);
mConnectionSvrFocusMgr.requestFocus(
call,
@@ -3720,11 +3759,6 @@
// Notify listeners that the call was disconnected before being added to CallsManager.
// Listeners will not receive onAdded or onRemoved callbacks.
if (!mCalls.contains(call)) {
- if (call.isEmergencyCall()) {
- mAnomalyReporter.reportAnomaly(
- EMERGENCY_CALL_DISCONNECTED_BEFORE_BEING_ADDED_ERROR_UUID,
- EMERGENCY_CALL_DISCONNECTED_BEFORE_BEING_ADDED_ERROR_MSG);
- }
mListeners.forEach(l -> l.onCreateConnectionFailed(call));
}
diff --git a/src/com/android/server/telecom/ConnectionServiceWrapper.java b/src/com/android/server/telecom/ConnectionServiceWrapper.java
index de1ecec..a43000a 100644
--- a/src/com/android/server/telecom/ConnectionServiceWrapper.java
+++ b/src/com/android/server/telecom/ConnectionServiceWrapper.java
@@ -67,6 +67,7 @@
import com.android.internal.util.Preconditions;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -2395,6 +2396,7 @@
BindCallback callback = new BindCallback() {
@Override
public void onSuccess() {
+ if (!isServiceValid("connectionServiceFocusLost")) return;
try {
mServiceInterface.connectionServiceFocusLost(
Log.getExternalSession(TELECOM_ABBREVIATION));
@@ -2414,6 +2416,7 @@
BindCallback callback = new BindCallback() {
@Override
public void onSuccess() {
+ if (!isServiceValid("connectionServiceFocusGained")) return;
try {
mServiceInterface.connectionServiceFocusGained(
Log.getExternalSession(TELECOM_ABBREVIATION));
@@ -2492,12 +2495,11 @@
*/
private void handleConnectionServiceDeath() {
if (!mPendingResponses.isEmpty()) {
- CreateConnectionResponse[] responses = mPendingResponses.values().toArray(
- new CreateConnectionResponse[mPendingResponses.values().size()]);
+ Collection<CreateConnectionResponse> responses = mPendingResponses.values();
mPendingResponses.clear();
- for (int i = 0; i < responses.length; i++) {
- responses[i].handleCreateConnectionFailure(
- new DisconnectCause(DisconnectCause.ERROR, "CS_DEATH"));
+ for (CreateConnectionResponse response : responses) {
+ response.handleCreateConnectionFailure(new DisconnectCause(DisconnectCause.ERROR,
+ "CS_DEATH"));
}
}
mCallIdMapper.clear();
diff --git a/src/com/android/server/telecom/InCallController.java b/src/com/android/server/telecom/InCallController.java
index 166ebd9..ca264c1 100644
--- a/src/com/android/server/telecom/InCallController.java
+++ b/src/com/android/server/telecom/InCallController.java
@@ -2430,7 +2430,9 @@
try {
inCallService.updateCall(
sanitizeParcelableCallForService(info, parcelableCall));
- } catch (RemoteException ignored) {
+ } catch (RemoteException exception) {
+ Log.w(this, "Call status update did not send to: "
+ + componentName +" successfully with error " + exception);
}
}
Log.i(this, "Components updated: %s", componentsUpdated);
diff --git a/src/com/android/server/telecom/NewOutgoingCallIntentBroadcaster.java b/src/com/android/server/telecom/NewOutgoingCallIntentBroadcaster.java
index 3b402b1..2740ff5 100644
--- a/src/com/android/server/telecom/NewOutgoingCallIntentBroadcaster.java
+++ b/src/com/android/server/telecom/NewOutgoingCallIntentBroadcaster.java
@@ -37,6 +37,7 @@
import android.text.TextUtils;
import com.android.internal.annotations.VisibleForTesting;
+import com.android.server.telecom.flags.FeatureFlags;
import com.android.server.telecom.callredirection.CallRedirectionProcessor;
// TODO: Needed for move to system service: import com.android.internal.R;
@@ -77,6 +78,7 @@
private final TelecomSystem.SyncRoot mLock;
private final DefaultDialerCache mDefaultDialerCache;
private final MmiUtils mMmiUtils;
+ private final FeatureFlags mFeatureFlags;
/*
* Whether or not the outgoing call intent originated from the default phone application. If
@@ -100,7 +102,8 @@
@VisibleForTesting
public NewOutgoingCallIntentBroadcaster(Context context, CallsManager callsManager,
Intent intent, PhoneNumberUtilsAdapter phoneNumberUtilsAdapter,
- boolean isDefaultPhoneApp, DefaultDialerCache defaultDialerCache, MmiUtils mmiUtils) {
+ boolean isDefaultPhoneApp, DefaultDialerCache defaultDialerCache, MmiUtils mmiUtils,
+ FeatureFlags featureFlags) {
mContext = context;
mCallsManager = callsManager;
mIntent = intent;
@@ -109,6 +112,7 @@
mLock = mCallsManager.getLock();
mDefaultDialerCache = defaultDialerCache;
mMmiUtils = mmiUtils;
+ mFeatureFlags = featureFlags;
}
/**
@@ -128,7 +132,8 @@
// Once the NEW_OUTGOING_CALL broadcast is finished, the resultData is
// used as the actual number to call. (If null, no call will be placed.)
String resultNumber = getResultData();
- Log.i(this, "Received new-outgoing-call-broadcast for %s with data %s", mCall,
+ Log.i(NewOutgoingCallIntentBroadcaster.this,
+ "Received new-outgoing-call-broadcast for %s with data %s", mCall,
Log.pii(resultNumber));
boolean endEarly = false;
@@ -320,6 +325,7 @@
String scheme = mPhoneNumberUtilsAdapter.isUriNumber(number)
? PhoneAccount.SCHEME_SIP : PhoneAccount.SCHEME_TEL;
result.callingAddress = Uri.fromParts(scheme, number, null);
+
return result;
}
@@ -351,7 +357,7 @@
public void processCall(Call call, CallDisposition disposition) {
mCall = call;
- if (disposition.callImmediately) {
+ if (disposition.callImmediately || mFeatureFlags.isNewOutgoingCallBroadcastUnblocking()) {
boolean speakerphoneOn = mIntent.getBooleanExtra(
TelecomManager.EXTRA_START_CALL_WITH_SPEAKERPHONE, false);
int videoState = mIntent.getIntExtra(
@@ -390,7 +396,6 @@
if (disposition.sendBroadcast) {
UserHandle targetUser = mCall.getAssociatedUser();
- Log.i(this, "Sending NewOutgoingCallBroadcast for %s to %s", mCall, targetUser);
broadcastIntent(mIntent, disposition.number,
!disposition.callImmediately && !callRedirectionWithService, targetUser);
}
@@ -415,28 +420,44 @@
if (number != null) {
broadcastIntent.putExtra(Intent.EXTRA_PHONE_NUMBER, number);
}
-
- // Force receivers of this broadcast intent to run at foreground priority because we
- // want to finish processing the broadcast intent as soon as possible.
- broadcastIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND
- | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
Log.v(this, "Broadcasting intent: %s.", broadcastIntent);
checkAndCopyProviderExtras(originalCallIntent, broadcastIntent);
- final BroadcastOptions options = BroadcastOptions.makeBasic();
- options.setBackgroundActivityStartsAllowed(true);
- mContext.sendOrderedBroadcastAsUser(
- broadcastIntent,
- targetUser,
- android.Manifest.permission.PROCESS_OUTGOING_CALLS,
- AppOpsManager.OP_PROCESS_OUTGOING_CALLS,
- options.toBundle(),
- receiverRequired ? new NewOutgoingCallBroadcastIntentReceiver() : null,
- null, // scheduler
- Activity.RESULT_OK, // initialCode
- number, // initialData: initial value for the result data (number to be modified)
- null); // initialExtras
+ if (mFeatureFlags.isNewOutgoingCallBroadcastUnblocking()) {
+ // Where the new outgoing call broadcast is unblocking, do not give receiver FG priority
+ // and do not allow background activity starts.
+ broadcastIntent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
+ Log.i(this, "broadcastIntent: Sending non-blocking for %s to %s", mCall.getId(),
+ targetUser);
+ mContext.sendBroadcastAsUser(
+ broadcastIntent,
+ targetUser,
+ android.Manifest.permission.PROCESS_OUTGOING_CALLS,
+ AppOpsManager.OP_PROCESS_OUTGOING_CALLS); // initialExtras
+ } else {
+ Log.i(this, "broadcastIntent: Sending ordered for %s to %s, waitForResult=%b",
+ mCall.getId(), targetUser, receiverRequired);
+ final BroadcastOptions options = BroadcastOptions.makeBasic();
+ options.setBackgroundActivityStartsAllowed(true);
+ // Force receivers of this broadcast intent to run at foreground priority because we
+ // want to finish processing the broadcast intent as soon as possible.
+ broadcastIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND
+ | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
+
+ mContext.sendOrderedBroadcastAsUser(
+ broadcastIntent,
+ targetUser,
+ android.Manifest.permission.PROCESS_OUTGOING_CALLS,
+ AppOpsManager.OP_PROCESS_OUTGOING_CALLS,
+ options.toBundle(),
+ receiverRequired ? new NewOutgoingCallBroadcastIntentReceiver() : null,
+ null, // scheduler
+ Activity.RESULT_OK, // initialCode
+ number, // initialData: initial value for the result data (number to be
+ // modified)
+ null); // initialExtras
+ }
}
/**
diff --git a/src/com/android/server/telecom/ParcelableCallUtils.java b/src/com/android/server/telecom/ParcelableCallUtils.java
index 673b99a..c77e605 100644
--- a/src/com/android/server/telecom/ParcelableCallUtils.java
+++ b/src/com/android/server/telecom/ParcelableCallUtils.java
@@ -158,6 +158,10 @@
properties |= android.telecom.Call.Details.PROPERTY_VOIP_AUDIO_MODE;
}
+ if (call.isTransactionalCall()) {
+ properties |= android.telecom.Call.Details.PROPERTY_IS_TRANSACTIONAL;
+ }
+
// If this is a single-SIM device, the "default SIM" will always be the only SIM.
boolean isDefaultSmsAccount = phoneAccountRegistrar != null &&
phoneAccountRegistrar.isUserSelectedSmsPhoneAccount(call.getTargetPhoneAccount());
diff --git a/src/com/android/server/telecom/Ringer.java b/src/com/android/server/telecom/Ringer.java
index 16dc5c4..4570957 100644
--- a/src/com/android/server/telecom/Ringer.java
+++ b/src/com/android/server/telecom/Ringer.java
@@ -22,10 +22,12 @@
import static android.provider.Settings.Global.ZEN_MODE_OFF;
import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.Person;
import android.content.Context;
+import android.content.res.Resources;
import android.media.AudioManager;
import android.media.Ringtone;
import android.media.VolumeShaper;
@@ -38,13 +40,21 @@
import android.os.VibrationAttributes;
import android.os.VibrationEffect;
import android.os.Vibrator;
+import android.os.vibrator.persistence.ParsedVibration;
+import android.os.vibrator.persistence.VibrationXmlParser;
import android.telecom.Log;
import android.telecom.TelecomManager;
+import android.text.TextUtils;
import android.view.accessibility.AccessibilityManager;
import com.android.internal.annotations.VisibleForTesting;
import com.android.server.telecom.LogUtils.EventTimer;
+import com.android.server.telecom.flags.FeatureFlags;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
@@ -59,6 +69,8 @@
*/
@VisibleForTesting
public class Ringer {
+ private static final String TAG = "TelecomRinger";
+
public interface AccessibilityManagerAdapter {
boolean startFlashNotificationSequence(@NonNull Context context,
@AccessibilityManager.FlashNotificationReason int reason);
@@ -84,6 +96,16 @@
// Used for test to notify the completion of RingerAttributes
private CountDownLatch mAttributesLatch;
+ /**
+ * Delay to be used between consecutive vibrations when a non-repeating vibration effect is
+ * provided by the device.
+ *
+ * <p>If looking to customize the loop delay for a device's ring vibration, the desired repeat
+ * behavior should be encoded directly in the effect specification in the device configuration
+ * rather than changing the here (i.e. in `R.raw.default_ringtone_vibration_effect` resource).
+ */
+ private static int DEFAULT_RING_VIBRATION_LOOP_DELAY_MS = 1000;
+
private static final long[] PULSE_PRIMING_PATTERN = {0,12,250,12,500}; // priming + interval
private static final int[] PULSE_PRIMING_AMPLITUDE = {0,255,0,255,0}; // priming + interval
@@ -96,9 +118,11 @@
private static final int[] PULSE_RAMPING_AMPLITUDE = {
77,77,78,79,81,84,87,93,101,114,133,162,205,255,255,0};
- private static final long[] PULSE_PATTERN;
+ @VisibleForTesting
+ public static final long[] PULSE_PATTERN;
- private static final int[] PULSE_AMPLITUDE;
+ @VisibleForTesting
+ public static final int[] PULSE_AMPLITUDE;
private static final int RAMPING_RINGER_VIBRATION_DURATION = 5000;
private static final int RAMPING_RINGER_DURATION = 10000;
@@ -207,7 +231,8 @@
VibrationEffectProxy vibrationEffectProxy,
InCallController inCallController,
NotificationManager notificationManager,
- AccessibilityManagerAdapter accessibilityManagerAdapter) {
+ AccessibilityManagerAdapter accessibilityManagerAdapter,
+ FeatureFlags featureFlags) {
mLock = new Object();
mSystemSettingsUtil = systemSettingsUtil;
@@ -223,13 +248,9 @@
mNotificationManager = notificationManager;
mAccessibilityManagerAdapter = accessibilityManagerAdapter;
- if (mContext.getResources().getBoolean(R.bool.use_simple_vibration_pattern)) {
- mDefaultVibrationEffect = mVibrationEffectProxy.createWaveform(SIMPLE_VIBRATION_PATTERN,
- SIMPLE_VIBRATION_AMPLITUDE, REPEAT_SIMPLE_VIBRATION_AT);
- } else {
- mDefaultVibrationEffect = mVibrationEffectProxy.createWaveform(PULSE_PATTERN,
- PULSE_AMPLITUDE, REPEAT_VIBRATION_AT);
- }
+ mDefaultVibrationEffect =
+ loadDefaultRingVibrationEffect(
+ mContext, mVibrator, mVibrationEffectProxy, featureFlags);
mIsHapticPlaybackSupportedByDevice =
mSystemSettingsUtil.isHapticPlaybackSupported(mContext);
@@ -757,4 +778,65 @@
return false;
}
}
+
+ @Nullable
+ private static VibrationEffect loadSerializedDefaultRingVibration(
+ Resources resources, Vibrator vibrator) {
+ try {
+ InputStream vibrationInputStream =
+ resources.openRawResource(
+ com.android.internal.R.raw.default_ringtone_vibration_effect);
+ ParsedVibration parsedVibration = VibrationXmlParser
+ .parseDocument(
+ new InputStreamReader(vibrationInputStream, StandardCharsets.UTF_8));
+ if (parsedVibration == null) {
+ Log.w(TAG, "Got null parsed default ring vibration effect.");
+ return null;
+ }
+ return parsedVibration.resolve(vibrator);
+ } catch (IOException | Resources.NotFoundException e) {
+ Log.e(TAG, e, "Error parsing default ring vibration effect.");
+ return null;
+ }
+ }
+
+ private static VibrationEffect loadDefaultRingVibrationEffect(
+ Context context,
+ Vibrator vibrator,
+ VibrationEffectProxy vibrationEffectProxy,
+ FeatureFlags featureFlags) {
+ Resources resources = context.getResources();
+
+ if (resources.getBoolean(R.bool.use_simple_vibration_pattern)) {
+ Log.i(TAG, "Using simple default ring vibration.");
+ return createSimpleRingVibration(vibrationEffectProxy);
+ }
+
+ if (featureFlags.useDeviceProvidedSerializedRingerVibration()) {
+ VibrationEffect parsedEffect = loadSerializedDefaultRingVibration(resources, vibrator);
+ if (parsedEffect != null) {
+ Log.i(TAG, "Using parsed default ring vibration.");
+ // Make the parsed effect repeating to make it vibrate continuously during ring.
+ // If the effect is already repeating, this API call is a no-op.
+ // Otherwise, it uses `DEFAULT_RING_VIBRATION_LOOP_DELAY_MS` when changing a
+ // non-repeating vibration to a repeating vibration.
+ // This is so that we ensure consecutive loops of the vibration play with some gap
+ // in between.
+ return parsedEffect.applyRepeatingIndefinitely(
+ /* wantRepeating= */ true, DEFAULT_RING_VIBRATION_LOOP_DELAY_MS);
+ }
+ // Fallback to the simple vibration if the serialized effect cannot be loaded.
+ return createSimpleRingVibration(vibrationEffectProxy);
+ }
+
+ Log.i(TAG, "Using pulse default ring vibration.");
+ return vibrationEffectProxy.createWaveform(
+ PULSE_PATTERN, PULSE_AMPLITUDE, REPEAT_VIBRATION_AT);
+ }
+
+ private static VibrationEffect createSimpleRingVibration(
+ VibrationEffectProxy vibrationEffectProxy) {
+ return vibrationEffectProxy.createWaveform(SIMPLE_VIBRATION_PATTERN,
+ SIMPLE_VIBRATION_AMPLITUDE, REPEAT_SIMPLE_VIBRATION_AT);
+ }
}
diff --git a/src/com/android/server/telecom/TelecomServiceImpl.java b/src/com/android/server/telecom/TelecomServiceImpl.java
index 9b48bc2..1dd68c9 100644
--- a/src/com/android/server/telecom/TelecomServiceImpl.java
+++ b/src/com/android/server/telecom/TelecomServiceImpl.java
@@ -79,6 +79,7 @@
import com.android.internal.telecom.ITelecomService;
import com.android.internal.util.IndentingPrintWriter;
import com.android.server.telecom.components.UserCallIntentProcessorFactory;
+import com.android.server.telecom.flags.FeatureFlags;
import com.android.server.telecom.settings.BlockedNumbersActivity;
import com.android.server.telecom.voip.IncomingCallTransaction;
import com.android.server.telecom.voip.OutgoingCallTransaction;
@@ -88,6 +89,7 @@
import java.io.FileDescriptor;
import java.io.PrintWriter;
+import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
@@ -1551,6 +1553,23 @@
}
mCallIntentProcessorAdapter.processIncomingCallIntent(
mCallsManager, intent);
+ if (mFeatureFlags.earlyBindingToIncallService()) {
+ PhoneAccount account =
+ mPhoneAccountRegistrar.getPhoneAccountUnchecked(
+ phoneAccountHandle);
+ Bundle accountExtra =
+ account == null ? new Bundle() : account.getExtras();
+ PackageManager packageManager = mContext.getPackageManager();
+ // Start binding to InCallServices for wearable calls that do not
+ // require call filtering. This is to wake up default dialer earlier
+ // to mitigate InCallService binding latency.
+ if (packageManager.hasSystemFeature(PackageManager.FEATURE_WATCH)
+ && accountExtra != null && accountExtra.getBoolean(
+ PhoneAccount.EXTRA_SKIP_CALL_FILTERING,
+ false)) {
+ mCallsManager.getInCallController().bindToServices(null);
+ }
+ }
} finally {
Binder.restoreCallingIdentity(token);
}
@@ -1967,6 +1986,11 @@
pw.increaseIndent();
Analytics.dump(pw);
pw.decreaseIndent();
+
+ pw.println("Flag Configurations: ");
+ pw.increaseIndent();
+ reflectAndPrintFlagConfigs(pw);
+ pw.decreaseIndent();
}
if (isTimeLineView) {
Log.dumpEventsTimeline(pw);
@@ -1976,6 +2000,28 @@
}
/**
+ * Print all feature flag configurations that Telecom is using for debugging purposes.
+ */
+ private void reflectAndPrintFlagConfigs(IndentingPrintWriter pw) {
+
+ try {
+ // Look away, a forbidden technique (reflection) is being used to allow us to get
+ // all flag configs without having to add them manually to this method.
+ Method[] methods = FeatureFlags.class.getMethods();
+ if (methods.length == 0) {
+ pw.println("NONE");
+ return;
+ }
+ for (Method m : methods) {
+ pw.println(m.getName() + "-> " + m.invoke(mFeatureFlags));
+ }
+ } catch (Exception e) {
+ pw.println("[ERROR]");
+ }
+
+ }
+
+ /**
* @see android.telecom.TelecomManager#createManageBlockedNumbersIntent
*/
@Override
@@ -2138,7 +2184,7 @@
try {
Log.i(this, "handleCallIntent: handling call intent");
mCallIntentProcessorAdapter.processOutgoingCallIntent(mContext,
- mCallsManager, intent, callingPackage);
+ mCallsManager, intent, callingPackage, mFeatureFlags);
} finally {
Binder.restoreCallingIdentity(token);
}
@@ -2511,6 +2557,7 @@
private final TelecomSystem.SyncRoot mLock;
private TransactionManager mTransactionManager;
private final TransactionalServiceRepository mTransactionalServiceRepository;
+ private final FeatureFlags mFeatureFlags;
public TelecomServiceImpl(
Context context,
@@ -2521,6 +2568,7 @@
DefaultDialerCache defaultDialerCache,
SubscriptionManagerAdapter subscriptionManagerAdapter,
SettingsSecureAdapter settingsSecureAdapter,
+ FeatureFlags featureFlags,
TelecomSystem.SyncRoot lock) {
mContext = context;
mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
@@ -2528,6 +2576,7 @@
mPackageManager = mContext.getPackageManager();
mCallsManager = callsManager;
+ mFeatureFlags = featureFlags;
mLock = lock;
mPhoneAccountRegistrar = phoneAccountRegistrar;
mUserCallIntentProcessorFactory = userCallIntentProcessorFactory;
diff --git a/src/com/android/server/telecom/TelecomSystem.java b/src/com/android/server/telecom/TelecomSystem.java
index 3686e86..57d7139 100644
--- a/src/com/android/server/telecom/TelecomSystem.java
+++ b/src/com/android/server/telecom/TelecomSystem.java
@@ -45,8 +45,12 @@
import com.android.server.telecom.bluetooth.BluetoothRouteManager;
import com.android.server.telecom.bluetooth.BluetoothStateReceiver;
import com.android.server.telecom.callfiltering.BlockedNumbersAdapter;
+import com.android.server.telecom.callfiltering.CallFilterResultCallback;
+import com.android.server.telecom.callfiltering.IncomingCallFilterGraph;
+import com.android.server.telecom.callfiltering.IncomingCallFilterGraphProvider;
import com.android.server.telecom.components.UserCallIntentProcessor;
import com.android.server.telecom.components.UserCallIntentProcessorFactory;
+import com.android.server.telecom.flags.FeatureFlags;
import com.android.server.telecom.ui.AudioProcessingNotification;
import com.android.server.telecom.ui.CallStreamingNotification;
import com.android.server.telecom.ui.DisconnectedCallNotifier;
@@ -224,7 +228,8 @@
Ringer.AccessibilityManagerAdapter accessibilityManagerAdapter,
Executor asyncTaskExecutor,
Executor asyncCallAudioTaskExecutor,
- BlockedNumbersAdapter blockedNumbersAdapter) {
+ BlockedNumbersAdapter blockedNumbersAdapter,
+ FeatureFlags featureFlags) {
mContext = context.getApplicationContext();
LogUtils.initLogging(mContext);
android.telecom.Log.setLock(mLock);
@@ -406,7 +411,9 @@
transactionManager,
emergencyCallDiagnosticLogger,
communicationDeviceTracker,
- callStreamingNotification);
+ callStreamingNotification,
+ featureFlags,
+ IncomingCallFilterGraph::new);
mIncomingCallNotifier = incomingCallNotifier;
incomingCallNotifier.setCallsManagerProxy(new IncomingCallNotifier.CallsManagerProxy() {
@@ -450,7 +457,7 @@
}
mCallIntentProcessor = new CallIntentProcessor(mContext, mCallsManager,
- defaultDialerCache);
+ defaultDialerCache, featureFlags);
mTelecomBroadcastIntentProcessor = new TelecomBroadcastIntentProcessor(
mContext, mCallsManager);
@@ -474,6 +481,7 @@
defaultDialerCache,
new TelecomServiceImpl.SubscriptionManagerAdapterImpl(),
new TelecomServiceImpl.SettingsSecureAdapterImpl(),
+ featureFlags,
mLock);
} finally {
Log.endSession();
diff --git a/src/com/android/server/telecom/UserUtil.java b/src/com/android/server/telecom/UserUtil.java
index a304401..d0a561a 100644
--- a/src/com/android/server/telecom/UserUtil.java
+++ b/src/com/android/server/telecom/UserUtil.java
@@ -16,10 +16,16 @@
package com.android.server.telecom;
+import android.app.admin.DevicePolicyManager;
import android.content.Context;
+import android.content.Intent;
import android.content.pm.UserInfo;
+import android.net.Uri;
import android.os.UserHandle;
import android.os.UserManager;
+import android.telecom.Log;
+
+import com.android.server.telecom.components.ErrorDialogActivity;
public final class UserUtil {
@@ -40,4 +46,57 @@
UserInfo userInfo = getUserInfoFromUserHandle(context, userHandle);
return userInfo != null && userInfo.profileGroupId != userInfo.id;
}
+
+ public static void showErrorDialogForRestrictedOutgoingCall(Context context,
+ int stringId, String tag, String reason) {
+ final Intent intent = new Intent(context, ErrorDialogActivity.class);
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ intent.putExtra(ErrorDialogActivity.ERROR_MESSAGE_ID_EXTRA, stringId);
+ context.startActivityAsUser(intent, UserHandle.CURRENT);
+ Log.w(tag, "Rejecting non-emergency phone call because "
+ + reason);
+ }
+
+ public static boolean hasOutgoingCallsUserRestriction(Context context,
+ UserHandle userHandle, Uri handle, boolean isSelfManaged, String tag) {
+ // Set handle for conference calls. Refer to {@link Connection#ADHOC_CONFERENCE_ADDRESS}.
+ if (handle == null) {
+ handle = Uri.parse("tel:conf-factory");
+ }
+
+ if(!isSelfManaged) {
+ // Check DISALLOW_OUTGOING_CALLS restriction. Note: We are skipping this
+ // check in a managed profile user because this check can always be bypassed
+ // by copying and pasting the phone number into the personal dialer.
+ if (!UserUtil.isManagedProfile(context, userHandle)) {
+ // Only emergency calls are allowed for users with the DISALLOW_OUTGOING_CALLS
+ // restriction.
+ if (!TelephonyUtil.shouldProcessAsEmergency(context, handle)) {
+ final UserManager userManager =
+ (UserManager) context.getSystemService(Context.USER_SERVICE);
+ if (userManager.hasBaseUserRestriction(UserManager.DISALLOW_OUTGOING_CALLS,
+ userHandle)) {
+ String reason = "of DISALLOW_OUTGOING_CALLS restriction";
+ showErrorDialogForRestrictedOutgoingCall(context,
+ R.string.outgoing_call_not_allowed_user_restriction, tag, reason);
+ return true;
+ } else if (userManager.hasUserRestriction(UserManager.DISALLOW_OUTGOING_CALLS,
+ userHandle)) {
+ final DevicePolicyManager dpm =
+ context.getSystemService(DevicePolicyManager.class);
+ if (dpm == null) {
+ return true;
+ }
+ final Intent adminSupportIntent = dpm.createAdminSupportIntent(
+ UserManager.DISALLOW_OUTGOING_CALLS);
+ if (adminSupportIntent != null) {
+ context.startActivityAsUser(adminSupportIntent, userHandle);
+ }
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
}
diff --git a/src/com/android/server/telecom/bluetooth/BluetoothDeviceManager.java b/src/com/android/server/telecom/bluetooth/BluetoothDeviceManager.java
index cc9c769..e32f72c 100644
--- a/src/com/android/server/telecom/bluetooth/BluetoothDeviceManager.java
+++ b/src/com/android/server/telecom/bluetooth/BluetoothDeviceManager.java
@@ -718,7 +718,9 @@
}
public boolean isInbandRingingEnabled() {
- BluetoothDevice activeDevice = mBluetoothRouteManager.getBluetoothAudioConnectedDevice();
+ // Get the inband ringing enabled status of expected BT device to route call audio instead
+ // of using the address of currently connected device.
+ BluetoothDevice activeDevice = mBluetoothRouteManager.getMostRecentlyReportedActiveDevice();
Log.i(this, "isInbandRingingEnabled: activeDevice: " + activeDevice);
if (mBluetoothRouteManager.isCachedLeAudioDevice(activeDevice)) {
if (mBluetoothLeAudioService == null) {
diff --git a/src/com/android/server/telecom/bluetooth/BluetoothRouteManager.java b/src/com/android/server/telecom/bluetooth/BluetoothRouteManager.java
index 91c03b6..b411b25 100644
--- a/src/com/android/server/telecom/bluetooth/BluetoothRouteManager.java
+++ b/src/com/android/server/telecom/bluetooth/BluetoothRouteManager.java
@@ -20,8 +20,8 @@
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothHearingAid;
-import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothLeAudio;
+import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.media.AudioDeviceInfo;
import android.os.Message;
@@ -38,12 +38,10 @@
import com.android.server.telecom.TelecomSystem;
import com.android.server.telecom.Timeouts;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
-import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
@@ -138,7 +136,7 @@
Log.w(LOG_TAG, "Entering AudioOff state but device %s appears to be connected. " +
"Switching to audio-on state for that device.", erroneouslyConnectedDevice);
// change this to just transition to the new audio on state
- transitionToActualState();
+ transitionToActualState(null /* excludeAddress */);
}
cleanupStatesForDisconnectedDevices();
if (mListener != null) {
@@ -261,7 +259,7 @@
case LOST_DEVICE:
removeDevice((String) args.arg2);
if (Objects.equals(address, mDeviceAddress)) {
- transitionToActualState();
+ transitionToActualState(null /* excludeAddress */);
}
break;
case CONNECT_BT:
@@ -301,7 +299,7 @@
case CONNECTION_TIMEOUT:
Log.i(LOG_TAG, "Connection with device %s timed out.",
mDeviceAddress);
- transitionToActualState();
+ transitionToActualState(null /* excludeAddress */);
break;
case BT_AUDIO_IS_ON:
if (Objects.equals(mDeviceAddress, address)) {
@@ -318,7 +316,7 @@
if (Objects.equals(mDeviceAddress, address) || address == null) {
Log.i(LOG_TAG, "Connection with device %s failed.",
mDeviceAddress);
- transitionToActualState();
+ transitionToActualState(address);
} else {
Log.w(LOG_TAG, "Got BT lost message for device %s while" +
" connecting to %s.", address, mDeviceAddress);
@@ -378,7 +376,7 @@
case LOST_DEVICE:
removeDevice((String) args.arg2);
if (Objects.equals(address, mDeviceAddress)) {
- transitionToActualState();
+ transitionToActualState(null /* excludeAddress */);
}
break;
case CONNECT_BT:
@@ -435,7 +433,7 @@
case BT_AUDIO_LOST:
if (Objects.equals(mDeviceAddress, address) || address == null) {
Log.i(LOG_TAG, "BT connection with device %s lost.", mDeviceAddress);
- transitionToActualState();
+ transitionToActualState(address);
} else {
Log.w(LOG_TAG, "Got BT lost message for device %s while" +
" connected to %s.", address, mDeviceAddress);
@@ -652,6 +650,10 @@
}
}
+ public BluetoothDevice getMostRecentlyReportedActiveDevice() {
+ return mMostRecentlyReportedActiveDevice;
+ }
+
public boolean hasBtActiveDevice() {
return mLeAudioActiveDeviceCache != null ||
mHearingAidActiveDeviceCache != null ||
@@ -717,7 +719,7 @@
actualAddress)) {
Log.i(this, "trying to connect to already connected device -- skipping connection"
+ " and going into the actual connected state.");
- transitionToActualState();
+ transitionToActualState(null /* excludeAddress */);
return null;
}
@@ -753,9 +755,10 @@
return null;
}
- private void transitionToActualState() {
+ private void transitionToActualState(String excludeAddress) {
BluetoothDevice possiblyAlreadyConnectedDevice = getBluetoothAudioConnectedDevice();
- if (possiblyAlreadyConnectedDevice != null) {
+ if (possiblyAlreadyConnectedDevice != null
+ && !possiblyAlreadyConnectedDevice.getAddress().equals(excludeAddress)) {
Log.i(LOG_TAG, "Device %s is already connected; going to AudioConnected.",
possiblyAlreadyConnectedDevice);
transitionTo(getConnectedStateForAddress(
diff --git a/src/com/android/server/telecom/callfiltering/IncomingCallFilterGraphProvider.java b/src/com/android/server/telecom/callfiltering/IncomingCallFilterGraphProvider.java
new file mode 100644
index 0000000..1501280
--- /dev/null
+++ b/src/com/android/server/telecom/callfiltering/IncomingCallFilterGraphProvider.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2023 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.server.telecom.callfiltering;
+
+import android.content.Context;
+
+import com.android.server.telecom.Call;
+import com.android.server.telecom.TelecomSystem;
+import com.android.server.telecom.Timeouts;
+
+/**
+ * Interface to provide a {@link IncomingCallFilterGraph}. This class serve for unit test purpose
+ * to mock an incoming call filter graph in test code.
+ */
+public interface IncomingCallFilterGraphProvider {
+
+
+ /**
+ * Provide a {@link IncomingCallFilterGraph}
+ * @param call The call for the filters.
+ * @param listener Callback object to trigger when filtering is done.
+ * @param context An android context.
+ * @param timeoutsAdapter Adapter to provide timeout value for call filtering.
+ * @param lock Telecom lock.
+ * @return
+ */
+ IncomingCallFilterGraph createGraph(Call call, CallFilterResultCallback listener,
+ Context context,
+ Timeouts.Adapter timeoutsAdapter, TelecomSystem.SyncRoot lock);
+}
diff --git a/src/com/android/server/telecom/components/TelecomService.java b/src/com/android/server/telecom/components/TelecomService.java
index 90a683f..9a5f2a7 100644
--- a/src/com/android/server/telecom/components/TelecomService.java
+++ b/src/com/android/server/telecom/components/TelecomService.java
@@ -61,6 +61,7 @@
import com.android.server.telecom.TelecomWakeLock;
import com.android.server.telecom.Timeouts;
import com.android.server.telecom.callfiltering.BlockedNumbersAdapter;
+import com.android.server.telecom.flags.FeatureFlagsImpl;
import com.android.server.telecom.settings.BlockedNumbersUtil;
import com.android.server.telecom.ui.IncomingCallNotifier;
import com.android.server.telecom.ui.MissedCallNotifierImpl;
@@ -230,7 +231,8 @@
BlockedNumbersUtil.updateEmergencyCallNotification(context,
showNotification);
}
- }));
+ },
+ new FeatureFlagsImpl()));
}
}
diff --git a/src/com/android/server/telecom/components/UserCallIntentProcessor.java b/src/com/android/server/telecom/components/UserCallIntentProcessor.java
index a4602c1..41232c2 100755
--- a/src/com/android/server/telecom/components/UserCallIntentProcessor.java
+++ b/src/com/android/server/telecom/components/UserCallIntentProcessor.java
@@ -105,47 +105,17 @@
handle = Uri.fromParts(PhoneAccount.SCHEME_SIP, uriString, null);
}
- if(!isSelfManaged) {
- // Check DISALLOW_OUTGOING_CALLS restriction. Note: We are skipping this
- // check in a managed profile user because this check can always be bypassed
- // by copying and pasting the phone number into the personal dialer.
- if (!UserUtil.isManagedProfile(mContext, mUserHandle)) {
- // Only emergency calls are allowed for users with the DISALLOW_OUTGOING_CALLS
- // restriction.
- if (!TelephonyUtil.shouldProcessAsEmergency(mContext, handle)) {
- final UserManager userManager =
- (UserManager) mContext.getSystemService(Context.USER_SERVICE);
- if (userManager.hasBaseUserRestriction(UserManager.DISALLOW_OUTGOING_CALLS,
- mUserHandle)) {
- showErrorDialogForRestrictedOutgoingCall(mContext,
- R.string.outgoing_call_not_allowed_user_restriction);
- Log.w(this, "Rejecting non-emergency phone call "
- + "due to DISALLOW_OUTGOING_CALLS restriction");
- return;
- } else if (userManager.hasUserRestriction(UserManager.DISALLOW_OUTGOING_CALLS,
- mUserHandle)) {
- final DevicePolicyManager dpm =
- mContext.getSystemService(DevicePolicyManager.class);
- if (dpm == null) {
- return;
- }
- final Intent adminSupportIntent = dpm.createAdminSupportIntent(
- UserManager.DISALLOW_OUTGOING_CALLS);
- if (adminSupportIntent != null) {
- mContext.startActivity(adminSupportIntent);
- }
- return;
- }
- }
- }
- }
+ if (UserUtil.hasOutgoingCallsUserRestriction(mContext, mUserHandle,
+ handle, isSelfManaged, UserCallIntentProcessor.class.getCanonicalName())) {
+ return;
+ }
if (!isSelfManaged && !canCallNonEmergency &&
!TelephonyUtil.shouldProcessAsEmergency(mContext, handle)) {
- showErrorDialogForRestrictedOutgoingCall(mContext,
- R.string.outgoing_call_not_allowed_no_permission);
- Log.w(this, "Rejecting non-emergency phone call because "
- + android.Manifest.permission.CALL_PHONE + " permission is not granted.");
+ String reason = android.Manifest.permission.CALL_PHONE + " permission is not granted.";
+ UserUtil.showErrorDialogForRestrictedOutgoingCall(mContext,
+ R.string.outgoing_call_not_allowed_no_permission,
+ this.getClass().getCanonicalName(), reason);
return;
}
@@ -187,11 +157,4 @@
}
return true;
}
-
- private static void showErrorDialogForRestrictedOutgoingCall(Context context, int stringId) {
- final Intent intent = new Intent(context, ErrorDialogActivity.class);
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- intent.putExtra(ErrorDialogActivity.ERROR_MESSAGE_ID_EXTRA, stringId);
- context.startActivityAsUser(intent, UserHandle.CURRENT);
- }
}
diff --git a/src/com/android/server/telecom/voip/VerifyCallStateChangeTransaction.java b/src/com/android/server/telecom/voip/VerifyCallStateChangeTransaction.java
new file mode 100644
index 0000000..b17dedd
--- /dev/null
+++ b/src/com/android/server/telecom/voip/VerifyCallStateChangeTransaction.java
@@ -0,0 +1,147 @@
+/*
+ * Copyright (C) 2023 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.server.telecom.voip;
+
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.server.telecom.Call;
+import com.android.server.telecom.CallsManager;
+
+import android.telecom.DisconnectCause;
+import android.telecom.Log;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionStage;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * VerifyCallStateChangeTransaction is a transaction that verifies a CallState change and has
+ * the ability to disconnect if the CallState is not changed within the timeout window.
+ * <p>
+ * Note: This transaction has a timeout of 2 seconds.
+ */
+public class VerifyCallStateChangeTransaction extends VoipCallTransaction {
+ private static final String TAG = VerifyCallStateChangeTransaction.class.getSimpleName();
+ public static final int FAILURE_CODE = 0;
+ public static final int SUCCESS_CODE = 1;
+ public static final int TIMEOUT_SECONDS = 2;
+ private final Call mCall;
+ private final CallsManager mCallsManager;
+ private final int mTargetCallState;
+ private final boolean mShouldDisconnectUponFailure;
+ private final CompletableFuture<Integer> mCallStateOrTimeoutResult = new CompletableFuture<>();
+ private final CompletableFuture<VoipCallTransactionResult> mTransactionResult =
+ new CompletableFuture<>();
+
+ @VisibleForTesting
+ public Call.CallStateListener mCallStateListenerImpl = new Call.CallStateListener() {
+ @Override
+ public void onCallStateChanged(int newCallState) {
+ Log.d(TAG, "newState=[%d], expectedState=[%d]", newCallState, mTargetCallState);
+ if (newCallState == mTargetCallState) {
+ mCallStateOrTimeoutResult.complete(SUCCESS_CODE);
+ }
+ // NOTE:: keep listening to the call state until the timeout is reached. It's possible
+ // another call state is reached in between...
+ }
+ };
+
+ public VerifyCallStateChangeTransaction(CallsManager callsManager, Call call,
+ int targetCallState, boolean shouldDisconnectUponFailure) {
+ super(callsManager.getLock());
+ mCallsManager = callsManager;
+ mCall = call;
+ mTargetCallState = targetCallState;
+ mShouldDisconnectUponFailure = shouldDisconnectUponFailure;
+ }
+
+ @Override
+ public CompletionStage<VoipCallTransactionResult> processTransaction(Void v) {
+ Log.d(TAG, "processTransaction:");
+ // It's possible the Call is already in the expected call state
+ if (isNewCallStateTargetCallState()) {
+ mTransactionResult.complete(
+ new VoipCallTransactionResult(VoipCallTransactionResult.RESULT_SUCCEED,
+ TAG));
+ return mTransactionResult;
+ }
+ initCallStateListenerOnTimeout();
+ // At this point, the mCallStateOrTimeoutResult has been completed. There are 2 scenarios:
+ // (1) newCallState == targetCallState --> the transaction is successful
+ // (2) timeout is reached --> evaluate the current call state and complete the t accordingly
+ // also need to do cleanup for the transaction
+ evaluateCallStateUponChangeOrTimeout();
+
+ return mTransactionResult;
+ }
+
+ private boolean isNewCallStateTargetCallState() {
+ return mCall.getState() == mTargetCallState;
+ }
+
+ private void initCallStateListenerOnTimeout() {
+ mCall.addCallStateListener(mCallStateListenerImpl);
+ mCallStateOrTimeoutResult.completeOnTimeout(FAILURE_CODE, TIMEOUT_SECONDS,
+ TimeUnit.SECONDS);
+ }
+
+ private void evaluateCallStateUponChangeOrTimeout() {
+ mCallStateOrTimeoutResult.thenAcceptAsync((result) -> {
+ Log.i(TAG, "processTransaction: thenAcceptAsync: result=[%s]", result);
+ mCall.removeCallStateListener(mCallStateListenerImpl);
+ if (isNewCallStateTargetCallState()) {
+ mTransactionResult.complete(
+ new VoipCallTransactionResult(VoipCallTransactionResult.RESULT_SUCCEED,
+ TAG));
+ } else {
+ maybeDisconnectCall();
+ mTransactionResult.complete(
+ new VoipCallTransactionResult(VoipCallTransactionResult.RESULT_FAILED,
+ TAG));
+ }
+ }).exceptionally(exception -> {
+ Log.i(TAG, "hit exception=[%s] while completing future", exception);
+ mTransactionResult.complete(
+ new VoipCallTransactionResult(VoipCallTransactionResult.RESULT_FAILED,
+ TAG));
+ return null;
+ });
+ }
+
+ private void maybeDisconnectCall() {
+ if (mShouldDisconnectUponFailure) {
+ mCallsManager.markCallAsDisconnected(mCall,
+ new DisconnectCause(DisconnectCause.ERROR,
+ "did not hold in timeout window"));
+ mCallsManager.markCallAsRemoved(mCall);
+ }
+ }
+
+ @VisibleForTesting
+ public CompletableFuture<Integer> getCallStateOrTimeoutResult() {
+ return mCallStateOrTimeoutResult;
+ }
+
+ @VisibleForTesting
+ public CompletableFuture<VoipCallTransactionResult> getTransactionResult() {
+ return mTransactionResult;
+ }
+
+ @VisibleForTesting
+ public Call.CallStateListener getCallStateListenerImpl() {
+ return mCallStateListenerImpl;
+ }
+}
diff --git a/testapps/transactionalVoipApp/res/values-zh-rCN/strings.xml b/testapps/transactionalVoipApp/res/values-zh-rCN/strings.xml
index a434e35..a74cbb5 100644
--- a/testapps/transactionalVoipApp/res/values-zh-rCN/strings.xml
+++ b/testapps/transactionalVoipApp/res/values-zh-rCN/strings.xml
@@ -19,7 +19,7 @@
xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="app_name" msgid="2907804426411305091">"事务性 API 测试活动"</string>
<string name="in_call_activity_name" msgid="7545884666442897585">"通话活动中的事务"</string>
- <string name="register_phone_account" msgid="1920315963082350332">"注册电话帐号"</string>
+ <string name="register_phone_account" msgid="1920315963082350332">"注册电话账号"</string>
<string name="start_foreground_service" msgid="8968755699895128574">"启动 FGS(在后台模拟 MT + 应用)"</string>
<string name="start_outgoing" msgid="1441644037370361864">"开始去电"</string>
<string name="start_incoming" msgid="6444983300186361271">"开始来电"</string>
diff --git a/tests/src/com/android/server/telecom/tests/BluetoothDeviceManagerTest.java b/tests/src/com/android/server/telecom/tests/BluetoothDeviceManagerTest.java
index 2dc077a..da3f40c 100644
--- a/tests/src/com/android/server/telecom/tests/BluetoothDeviceManagerTest.java
+++ b/tests/src/com/android/server/telecom/tests/BluetoothDeviceManagerTest.java
@@ -758,19 +758,14 @@
when(mBluetoothLeAudio.isInbandRingtoneEnabled(1)).thenReturn(true);
when(mBluetoothLeAudio.getGroupId(eq(device3))).thenReturn(1);
receiverUnderTest.onReceive(mContext,
- buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device1,
- BluetoothDeviceManager.DEVICE_TYPE_HEADSET));
- receiverUnderTest.onReceive(mContext,
- buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device2,
- BluetoothDeviceManager.DEVICE_TYPE_HEADSET));
- receiverUnderTest.onReceive(mContext,
buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device3,
BluetoothDeviceManager.DEVICE_TYPE_LE_AUDIO));
leAudioCallbacksTest.getValue().onGroupNodeAdded(device3, 1);
- when(mBluetoothLeAudio.getConnectedGroupLeadDevice(1)).thenReturn(device3);
when(mRouteManager.getBluetoothAudioConnectedDevice()).thenReturn(device3);
when(mRouteManager.isCachedLeAudioDevice(eq(device3))).thenReturn(true);
- assertEquals(3, mBluetoothDeviceManager.getNumConnectedDevices());
+ when(mBluetoothLeAudio.getConnectedGroupLeadDevice(1)).thenReturn(device3);
+ when(mRouteManager.getMostRecentlyReportedActiveDevice()).thenReturn(device3);
+ assertEquals(1, mBluetoothDeviceManager.getNumConnectedDevices());
assertTrue(mBluetoothDeviceManager.isInbandRingingEnabled());
}
diff --git a/tests/src/com/android/server/telecom/tests/BluetoothRouteManagerTest.java b/tests/src/com/android/server/telecom/tests/BluetoothRouteManagerTest.java
index 2b5e5ac..8e31f9c 100644
--- a/tests/src/com/android/server/telecom/tests/BluetoothRouteManagerTest.java
+++ b/tests/src/com/android/server/telecom/tests/BluetoothRouteManagerTest.java
@@ -16,6 +16,15 @@
package com.android.server.telecom.tests;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
@@ -47,16 +56,6 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyBoolean;
-import static org.mockito.ArgumentMatchers.nullable;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.reset;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
@RunWith(JUnit4.class)
public class BluetoothRouteManagerTest extends TelecomTestCase {
private static final int TEST_TIMEOUT = 1000;
@@ -173,6 +172,19 @@
sm.quitNow();
}
+ @SmallTest
+ @Test
+ public void testSkipInactiveBtDeviceWhenEvaluateActualState() {
+ BluetoothRouteManager sm = setupStateMachine(
+ BluetoothRouteManager.AUDIO_CONNECTED_STATE_NAME_PREFIX, HEARING_AID_DEVICE);
+ setupConnectedDevices(null, new BluetoothDevice[]{HEARING_AID_DEVICE},
+ null, null, HEARING_AID_DEVICE, null);
+ executeRoutingAction(sm, BluetoothRouteManager.BT_AUDIO_LOST,
+ HEARING_AID_DEVICE.getAddress());
+ assertEquals(BluetoothRouteManager.AUDIO_OFF_STATE_NAME, sm.getCurrentState().getName());
+ sm.quitNow();
+ }
+
private BluetoothRouteManager setupStateMachine(String initialState,
BluetoothDevice initialDevice) {
resetMocks();
diff --git a/tests/src/com/android/server/telecom/tests/CallAudioRouteStateMachineTest.java b/tests/src/com/android/server/telecom/tests/CallAudioRouteStateMachineTest.java
index a4dd1fe..9cf1834 100644
--- a/tests/src/com/android/server/telecom/tests/CallAudioRouteStateMachineTest.java
+++ b/tests/src/com/android/server/telecom/tests/CallAudioRouteStateMachineTest.java
@@ -260,6 +260,7 @@
foundValid = true;
}
assertTrue(foundValid);
+ verify(mockBluetoothRouteManager, timeout(1000L)).getBluetoothAudioConnectedDevice();
}
@MediumTest
diff --git a/tests/src/com/android/server/telecom/tests/CallsManagerTest.java b/tests/src/com/android/server/telecom/tests/CallsManagerTest.java
index 00be89f..5577290 100644
--- a/tests/src/com/android/server/telecom/tests/CallsManagerTest.java
+++ b/tests/src/com/android/server/telecom/tests/CallsManagerTest.java
@@ -124,6 +124,8 @@
import com.android.server.telecom.bluetooth.BluetoothStateReceiver;
import com.android.server.telecom.callfiltering.BlockedNumbersAdapter;
import com.android.server.telecom.callfiltering.CallFilteringResult;
+import com.android.server.telecom.flags.FeatureFlags;
+import com.android.server.telecom.callfiltering.IncomingCallFilterGraph;
import com.android.server.telecom.ui.AudioProcessingNotification;
import com.android.server.telecom.ui.CallStreamingNotification;
import com.android.server.telecom.ui.DisconnectedCallNotifier;
@@ -279,6 +281,9 @@
@Mock private PhoneCapability mPhoneCapability;
@Mock private CallAudioCommunicationDeviceTracker mCommunicationDeviceTracker;
@Mock private CallStreamingNotification mCallStreamingNotification;
+ @Mock private FeatureFlags mFeatureFlags;
+
+ @Mock private IncomingCallFilterGraph mIncomingCallFilterGraph;
private CallsManager mCallsManager;
@@ -353,7 +358,9 @@
TransactionManager.getTestInstance(),
mEmergencyCallDiagnosticLogger,
mCommunicationDeviceTracker,
- mCallStreamingNotification);
+ mCallStreamingNotification,
+ mFeatureFlags,
+ (call, listener, context, timeoutsAdapter, lock) -> mIncomingCallFilterGraph);
when(mPhoneAccountRegistrar.getPhoneAccount(
eq(SELF_MANAGED_HANDLE), any())).thenReturn(SELF_MANAGED_ACCOUNT);
@@ -1323,8 +1330,9 @@
@SmallTest
@Test
- public void testNoFilteringOfCallsWhenPhoneAccountRequestsSkipped() {
+ public void testDndFilterAppliesOfCallsWhenPhoneAccountRequestsSkipped() {
// GIVEN an incoming call which is from a PhoneAccount that requested to skip filtering.
+ when(mFeatureFlags.skipFilterPhoneAccountPerformDndFilter()).thenReturn(true);
Call incomingCall = addSpyCall(SIM_1_HANDLE, CallState.NEW);
Bundle extras = new Bundle();
extras.putBoolean(PhoneAccount.EXTRA_SKIP_CALL_FILTERING, true);
@@ -1344,7 +1352,35 @@
// WHEN the incoming call is successfully added.
mCallsManager.onSuccessfulIncomingCall(incomingCall);
- // THEN the incoming call is not using call filtering
+ // THEN the incoming call is still applying Dnd filter.
+ verify(incomingCall).setIsUsingCallFiltering(eq(true));
+ }
+
+ @SmallTest
+ @Test
+ public void testNoFilterAppliesOfCallsWhenFlagNotEnabled() {
+ // Flag is not enabled.
+ when(mFeatureFlags.skipFilterPhoneAccountPerformDndFilter()).thenReturn(false);
+ Call incomingCall = addSpyCall(SIM_1_HANDLE, CallState.NEW);
+ Bundle extras = new Bundle();
+ extras.putBoolean(PhoneAccount.EXTRA_SKIP_CALL_FILTERING, true);
+ PhoneAccount skipRequestedAccount = new PhoneAccount.Builder(SIM_2_HANDLE, "Skipper")
+ .setCapabilities(PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION
+ | PhoneAccount.CAPABILITY_CALL_PROVIDER)
+ .setExtras(extras)
+ .setIsEnabled(true)
+ .build();
+ when(mPhoneAccountRegistrar.getPhoneAccountUnchecked(SIM_1_HANDLE))
+ .thenReturn(skipRequestedAccount);
+ doReturn(false).when(incomingCall).can(Connection.CAPABILITY_HOLD);
+ doReturn(false).when(incomingCall).can(Connection.CAPABILITY_SUPPORT_HOLD);
+ doReturn(false).when(incomingCall).isSelfManaged();
+ doReturn(true).when(incomingCall).setState(anyInt(), any());
+
+ // WHEN the incoming call is successfully added.
+ mCallsManager.onSuccessfulIncomingCall(incomingCall);
+
+ // THEN the incoming call is not applying filter.
verify(incomingCall).setIsUsingCallFiltering(eq(false));
}
@@ -2505,6 +2541,30 @@
assertEquals(DEFAULT_CALL_SCREENING_APP, outgoingCall.getPostCallPackageName());
}
+ /**
+ * Verify the only call state set from calling onSuccessfulOutgoingCall is CallState.DIALING.
+ */
+ @SmallTest
+ @Test
+ public void testOutgoingCallStateIsSetToAPreviousStateAndIgnored() {
+ Call outgoingCall = addSpyCall(CallState.CONNECTING);
+ mCallsManager.onSuccessfulOutgoingCall(outgoingCall, CallState.NEW);
+ verify(outgoingCall, never()).setState(eq(CallState.NEW), any());
+ verify(outgoingCall, times(1)).setState(eq(CallState.DIALING), any());
+ }
+
+ /**
+ * Verify a ConnectionService can start the call in the active state and avoid the dialing state
+ */
+ @SmallTest
+ @Test
+ public void testOutgoingCallStateCanAvoidDialingAndGoStraightToActive() {
+ Call outgoingCall = addSpyCall(CallState.CONNECTING);
+ mCallsManager.onSuccessfulOutgoingCall(outgoingCall, CallState.ACTIVE);
+ verify(outgoingCall, never()).setState(eq(CallState.DIALING), any());
+ verify(outgoingCall, times(1)).setState(eq(CallState.ACTIVE), any());
+ }
+
@SmallTest
@Test
public void testRejectIncomingCallOnPAHInactive_SecondaryUser() throws Exception {
diff --git a/tests/src/com/android/server/telecom/tests/ComponentContextFixture.java b/tests/src/com/android/server/telecom/tests/ComponentContextFixture.java
index df855e9..a26813f 100644
--- a/tests/src/com/android/server/telecom/tests/ComponentContextFixture.java
+++ b/tests/src/com/android/server/telecom/tests/ComponentContextFixture.java
@@ -27,6 +27,8 @@
import org.mockito.stubbing.Answer;
import android.Manifest;
+import android.annotation.Nullable;
+import android.annotation.RequiresPermission;
import android.app.AppOpsManager;
import android.app.NotificationManager;
import android.app.StatusBarManager;
@@ -81,8 +83,10 @@
import android.util.DisplayMetrics;
import android.view.accessibility.AccessibilityManager;
+import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -415,6 +419,12 @@
}
@Override
+ public void sendBroadcastAsUser(Intent intent, UserHandle user, String receiverPermission,
+ int appOp) {
+ // Override so that this can be verified via spy.
+ }
+
+ @Override
public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler,
int initialCode, String initialData, Bundle initialExtras) {
@@ -802,6 +812,11 @@
when(mResources.getStringArray(eq(id))).thenReturn(value);
}
+ public void putRawResource(int id, String content) {
+ when(mResources.openRawResource(id))
+ .thenReturn(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)));
+ }
+
public void setTelecomManager(TelecomManager telecomManager) {
mTelecomManager = telecomManager;
}
diff --git a/tests/src/com/android/server/telecom/tests/NewOutgoingCallIntentBroadcasterTest.java b/tests/src/com/android/server/telecom/tests/NewOutgoingCallIntentBroadcasterTest.java
index 33acd98..76d4a2b 100644
--- a/tests/src/com/android/server/telecom/tests/NewOutgoingCallIntentBroadcasterTest.java
+++ b/tests/src/com/android/server/telecom/tests/NewOutgoingCallIntentBroadcasterTest.java
@@ -53,6 +53,7 @@
import android.telephony.TelephonyManager;
import android.test.suitebuilder.annotation.SmallTest;
+import com.android.server.telecom.flags.FeatureFlags;
import com.android.server.telecom.Call;
import com.android.server.telecom.CallsManager;
import com.android.server.telecom.DefaultDialerCache;
@@ -75,6 +76,8 @@
@RunWith(JUnit4.class)
public class NewOutgoingCallIntentBroadcasterTest extends TelecomTestCase {
+ private static final Uri TEST_URI = Uri.parse("tel:16505551212");
+
private static class ReceiverIntentPair {
public BroadcastReceiver receiver;
public Intent intent;
@@ -93,6 +96,7 @@
@Mock private PhoneAccountRegistrar mPhoneAccountRegistrar;
@Mock private RoleManagerAdapter mRoleManagerAdapter;
@Mock private DefaultDialerCache mDefaultDialerCache;
+ @Mock private FeatureFlags mFeatureFlags;
@Mock private MmiUtils mMmiUtils;
private PhoneNumberUtilsAdapter mPhoneNumberUtilsAdapter = new PhoneNumberUtilsAdapterImpl();
@@ -113,6 +117,7 @@
any(PhoneAccountHandle.class))).thenReturn(mPhoneAccount);
when(mPhoneAccount.isSelfManaged()).thenReturn(true);
when(mSystemStateHelper.isCarModeOrProjectionActive()).thenReturn(false);
+ when(mFeatureFlags.isNewOutgoingCallBroadcastUnblocking()).thenReturn(false);
}
@Override
@@ -510,6 +515,85 @@
testUnmodifiedRegularCall();
}
+ /**
+ * Where the flag `isNewOutgoingCallBroadcastUnblocking` is off, verify that we sent an ordered
+ * broadcast and did not try to start the call immediately (legacy behavior).
+ */
+ @SmallTest
+ @Test
+ public void testSendBroadcastBlocking() {
+ when(mFeatureFlags.isNewOutgoingCallBroadcastUnblocking()).thenReturn(false);
+ Intent intent = new Intent(Intent.ACTION_CALL, TEST_URI);
+ NewOutgoingCallIntentBroadcaster nocib = new NewOutgoingCallIntentBroadcaster(
+ mContext, mCallsManager, intent, mPhoneNumberUtilsAdapter,
+ true /* isDefaultPhoneApp */, mDefaultDialerCache, mMmiUtils, mFeatureFlags);
+
+ NewOutgoingCallIntentBroadcaster.CallDisposition disposition = nocib.evaluateCall();
+ nocib.processCall(mCall, disposition);
+
+ // We should not have not short-circuited to place the outgoing call directly.
+ verify(mCall, never()).setNewOutgoingCallIntentBroadcastIsDone();
+ verify(mCallsManager, never()).placeOutgoingCall(any(Call.class), any(Uri.class),
+ any(GatewayInfo.class), anyBoolean(), anyInt());
+
+ // Ensure we did send the broadcast ordered
+ verifyBroadcastSent(TEST_URI.getSchemeSpecificPart(),
+ createNumberExtras(TEST_URI.getSchemeSpecificPart()));
+
+ // Ensure we did not try to directly send the broadcast unordered.
+ verify(mContext, never()).sendBroadcastAsUser(
+ any(Intent.class),
+ eq(UserHandle.CURRENT),
+ eq(android.Manifest.permission.PROCESS_OUTGOING_CALLS),
+ eq(AppOpsManager.OP_PROCESS_OUTGOING_CALLS));
+ }
+
+ /**
+ * Where the flag `isNewOutgoingCallBroadcastUnblocking` is off, verify that we sent an ordered
+ * broadcast and did not try to start the call immediately. Also ensure that the broadcast
+ * flags are correct.
+ */
+ @SmallTest
+ @Test
+ public void testSendBroadcastNonBlocking() {
+ when(mFeatureFlags.isNewOutgoingCallBroadcastUnblocking()).thenReturn(true);
+ Intent intent = new Intent(Intent.ACTION_CALL, TEST_URI);
+ NewOutgoingCallIntentBroadcaster nocib = new NewOutgoingCallIntentBroadcaster(
+ mContext, mCallsManager, intent, mPhoneNumberUtilsAdapter,
+ true /* isDefaultPhoneApp */, mDefaultDialerCache, mMmiUtils, mFeatureFlags);
+
+ NewOutgoingCallIntentBroadcaster.CallDisposition disposition = nocib.evaluateCall();
+ nocib.processCall(mCall, disposition);
+
+ // We should have started the outgoing call flow immediately.
+ verify(mCall).setNewOutgoingCallIntentBroadcastIsDone();
+ verify(mCallsManager).placeOutgoingCall(any(Call.class), any(Uri.class),
+ nullable(GatewayInfo.class), anyBoolean(), anyInt());
+
+ // Ensure we didn't send an ordered broadcast.
+ verify(mContext, never()).sendOrderedBroadcastAsUser(
+ any(Intent.class),
+ any(UserHandle.class),
+ anyString(),
+ anyInt(),
+ any(Bundle.class),
+ any(BroadcastReceiver.class),
+ any(Handler.class),
+ eq(Activity.RESULT_OK),
+ anyString(),
+ any(Bundle.class));
+
+ // But that we did send a regular broadcast.
+ ArgumentCaptor<Intent> intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class);
+ verify(mContext).sendBroadcastAsUser(
+ intentArgumentCaptor.capture(),
+ eq(UserHandle.CURRENT),
+ eq(android.Manifest.permission.PROCESS_OUTGOING_CALLS),
+ eq(AppOpsManager.OP_PROCESS_OUTGOING_CALLS));
+ Intent capturedIntent = intentArgumentCaptor.getValue();
+ assertEquals(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND, capturedIntent.getFlags());
+ }
+
private ReceiverIntentPair regularCallTestHelper(Intent intent,
Bundle expectedAdditionalExtras) {
Uri handle = intent.getData();
@@ -542,7 +626,7 @@
boolean isDefaultPhoneApp) {
NewOutgoingCallIntentBroadcaster b = new NewOutgoingCallIntentBroadcaster(
mContext, mCallsManager, intent, mPhoneNumberUtilsAdapter,
- isDefaultPhoneApp, mDefaultDialerCache, mMmiUtils);
+ isDefaultPhoneApp, mDefaultDialerCache, mMmiUtils, mFeatureFlags);
NewOutgoingCallIntentBroadcaster.CallDisposition cd = b.evaluateCall();
if (cd.disconnectCause == DisconnectCause.NOT_DISCONNECTED) {
b.processCall(mCall, cd);
diff --git a/tests/src/com/android/server/telecom/tests/RingerTest.java b/tests/src/com/android/server/telecom/tests/RingerTest.java
index 34360ca..f232525 100644
--- a/tests/src/com/android/server/telecom/tests/RingerTest.java
+++ b/tests/src/com/android/server/telecom/tests/RingerTest.java
@@ -17,8 +17,11 @@
package com.android.server.telecom.tests;
import static android.provider.Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS;
+import static android.os.VibrationEffect.EFFECT_CLICK;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
@@ -30,6 +33,7 @@
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -40,6 +44,7 @@
import android.app.NotificationManager;
import android.content.ComponentName;
import android.content.Context;
+import android.content.res.Resources;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.Ringtone;
@@ -50,11 +55,17 @@
import android.os.UserManager;
import android.os.VibrationAttributes;
import android.os.VibrationEffect;
+import android.os.vibrator.persistence.VibrationXmlParser;
import android.os.Vibrator;
+import android.os.VibratorInfo;
+import android.platform.test.flag.junit.CheckFlagsRule;
+import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
import android.test.suitebuilder.annotation.SmallTest;
+import androidx.test.InstrumentationRegistry;
+
import com.android.server.telecom.AsyncRingtonePlayer;
import com.android.server.telecom.Call;
import com.android.server.telecom.CallState;
@@ -63,9 +74,11 @@
import com.android.server.telecom.Ringer;
import com.android.server.telecom.RingtoneFactory;
import com.android.server.telecom.SystemSettingsUtil;
+import com.android.server.telecom.flags.FeatureFlags;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -73,23 +86,35 @@
import org.mockito.Spy;
import java.util.concurrent.CompletableFuture;
+import java.time.Duration;
@RunWith(JUnit4.class)
public class RingerTest extends TelecomTestCase {
+ @Rule
+ public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
+
private static final Uri FAKE_RINGTONE_URI = Uri.parse("content://media/fake/audio/1729");
// Returned when the a URI-based VibrationEffect is attempted, to avoid depending on actual
// device configuration for ringtone URIs. The actual Uri can be verified via the
// VibrationEffectProxy mock invocation.
private static final VibrationEffect URI_VIBRATION_EFFECT =
VibrationEffect.createPredefined(VibrationEffect.EFFECT_CLICK);
+ private static final VibrationEffect EXPECTED_SIMPLE_VIBRATION_PATTERN =
+ VibrationEffect.createWaveform(
+ new long[] {0, 1000, 1000}, new int[] {0, 255, 0}, 1);
+ private static final VibrationEffect EXPECTED_PULSE_VIBRATION_PATTERN =
+ VibrationEffect.createWaveform(
+ Ringer.PULSE_PATTERN, Ringer.PULSE_AMPLITUDE, 5);
@Mock InCallTonePlayer.Factory mockPlayerFactory;
@Mock SystemSettingsUtil mockSystemSettingsUtil;
@Mock RingtoneFactory mockRingtoneFactory;
@Mock Vibrator mockVibrator;
+ @Mock VibratorInfo mockVibratorInfo;
@Mock InCallController mockInCallController;
@Mock NotificationManager mockNotificationManager;
@Mock Ringer.AccessibilityManagerAdapter mockAccessibilityManagerAdapter;
+ @Mock private FeatureFlags mFeatureFlags;
@Spy Ringer.VibrationEffectProxy spyVibrationEffectProxy;
@@ -111,11 +136,12 @@
@Before
public void setUp() throws Exception {
super.setUp();
- mContext = mComponentContextFixture.getTestDouble().getApplicationContext();
+ mContext = spy(mComponentContextFixture.getTestDouble().getApplicationContext());
doReturn(URI_VIBRATION_EFFECT).when(spyVibrationEffectProxy).get(any(), any());
when(mockPlayerFactory.createPlayer(anyInt())).thenReturn(mockTonePlayer);
mockAudioManager = mContext.getSystemService(AudioManager.class);
when(mockAudioManager.getRingerMode()).thenReturn(AudioManager.RINGER_MODE_NORMAL);
+ when(mockVibrator.getInfo()).thenReturn(mockVibratorInfo);
when(mockSystemSettingsUtil.isHapticPlaybackSupported(any(Context.class)))
.thenAnswer((invocation) -> mIsHapticPlaybackSupported);
mockNotificationManager =mContext.getSystemService(NotificationManager.class);
@@ -140,7 +166,8 @@
private void createRingerUnderTest() {
mRingerUnderTest = new Ringer(mockPlayerFactory, mContext, mockSystemSettingsUtil,
asyncRingtonePlayer, mockRingtoneFactory, mockVibrator, spyVibrationEffectProxy,
- mockInCallController, mockNotificationManager, mockAccessibilityManagerAdapter);
+ mockInCallController, mockNotificationManager, mockAccessibilityManagerAdapter,
+ mFeatureFlags);
// This future is used to wait for AsyncRingtonePlayer to finish its part.
mRingerUnderTest.setBlockOnRingingFuture(mRingCompletionFuture);
}
@@ -153,6 +180,151 @@
@SmallTest
@Test
+ public void testSimpleVibrationPrecedesValidSupportedDefaultRingVibrationOverride()
+ throws Exception {
+ when(mFeatureFlags.useDeviceProvidedSerializedRingerVibration()).thenReturn(true);
+ mockVibrationResourceValues(
+ """
+ <vibration>
+ <predefined-effect name="click"/>
+ </vibration>
+ """,
+ /* useSimpleVibration= */ true);
+ when(mockVibratorInfo.areVibrationFeaturesSupported(any())).thenReturn(true);
+
+ createRingerUnderTest();
+
+ assertEquals(EXPECTED_SIMPLE_VIBRATION_PATTERN, mRingerUnderTest.mDefaultVibrationEffect);
+ }
+
+ @SmallTest
+ @Test
+ public void testDefaultRingVibrationOverrideNotUsedWhenFeatureIsDisabled()
+ throws Exception {
+ when(mFeatureFlags.useDeviceProvidedSerializedRingerVibration()).thenReturn(false);
+ mockVibrationResourceValues(
+ """
+ <vibration>
+ <waveform-effect>
+ <waveform-entry durationMs="100" amplitude="0"/>
+ <repeating>
+ <waveform-entry durationMs="500" amplitude="default"/>
+ <waveform-entry durationMs="700" amplitude="0"/>
+ </repeating>
+ </waveform-effect>
+ </vibration>
+ """,
+ /* useSimpleVibration= */ false);
+ when(mockVibratorInfo.areVibrationFeaturesSupported(any())).thenReturn(true);
+
+ createRingerUnderTest();
+
+ assertEquals(EXPECTED_PULSE_VIBRATION_PATTERN, mRingerUnderTest.mDefaultVibrationEffect);
+ }
+
+ @SmallTest
+ @Test
+ public void testValidSupportedRepeatingDefaultRingVibrationOverride() throws Exception {
+ when(mFeatureFlags.useDeviceProvidedSerializedRingerVibration()).thenReturn(true);
+ mockVibrationResourceValues(
+ """
+ <vibration>
+ <waveform-effect>
+ <waveform-entry durationMs="100" amplitude="0"/>
+ <repeating>
+ <waveform-entry durationMs="500" amplitude="default"/>
+ <waveform-entry durationMs="700" amplitude="0"/>
+ </repeating>
+ </waveform-effect>
+ </vibration>
+ """,
+ /* useSimpleVibration= */ false);
+ when(mockVibratorInfo.areVibrationFeaturesSupported(any())).thenReturn(true);
+
+ createRingerUnderTest();
+
+ assertEquals(
+ VibrationEffect.createWaveform(new long[]{100, 500, 700}, /* repeat= */ 1),
+ mRingerUnderTest.mDefaultVibrationEffect);
+ }
+
+ @SmallTest
+ @Test
+ public void testValidSupportedNonRepeatingDefaultRingVibrationOverride() throws Exception {
+ when(mFeatureFlags.useDeviceProvidedSerializedRingerVibration()).thenReturn(true);
+ mockVibrationResourceValues(
+ """
+ <vibration>
+ <predefined-effect name="click"/>
+ </vibration>
+ """,
+ /* useSimpleVibration= */ false);
+ when(mockVibratorInfo.areVibrationFeaturesSupported(any())).thenReturn(true);
+
+ createRingerUnderTest();
+
+ assertEquals(
+ VibrationEffect
+ .startComposition()
+ .repeatEffectIndefinitely(
+ VibrationEffect
+ .startComposition()
+ .addEffect(VibrationEffect.createPredefined(EFFECT_CLICK))
+ .addOffDuration(Duration.ofSeconds(1))
+ .compose()
+ )
+ .compose(),
+ mRingerUnderTest.mDefaultVibrationEffect);
+ }
+
+ @SmallTest
+ @Test
+ public void testValidButUnsupportedDefaultRingVibrationOverride() throws Exception {
+ when(mFeatureFlags.useDeviceProvidedSerializedRingerVibration()).thenReturn(true);
+ mockVibrationResourceValues(
+ """
+ <vibration>
+ <predefined-effect name="click"/>
+ </vibration>
+ """,
+ /* useSimpleVibration= */ false);
+ when(mockVibratorInfo.areVibrationFeaturesSupported(
+ eq(VibrationEffect.createPredefined(EFFECT_CLICK)))).thenReturn(false);
+
+ createRingerUnderTest();
+
+ assertEquals(EXPECTED_SIMPLE_VIBRATION_PATTERN, mRingerUnderTest.mDefaultVibrationEffect);
+ }
+
+ @SmallTest
+ @Test
+ public void testInvalidDefaultRingVibrationOverride() throws Exception {
+ when(mFeatureFlags.useDeviceProvidedSerializedRingerVibration()).thenReturn(true);
+ mockVibrationResourceValues(
+ /* defaultVibrationContent= */ "bad serialization",
+ /* useSimpleVibration= */ false);
+ when(mockVibratorInfo.areVibrationFeaturesSupported(any())).thenReturn(true);
+
+ createRingerUnderTest();
+
+ assertEquals(EXPECTED_SIMPLE_VIBRATION_PATTERN, mRingerUnderTest.mDefaultVibrationEffect);
+ }
+
+ @SmallTest
+ @Test
+ public void testEmptyDefaultRingVibrationOverride() throws Exception {
+ when(mFeatureFlags.useDeviceProvidedSerializedRingerVibration()).thenReturn(true);
+ mockVibrationResourceValues(
+ /* defaultVibrationContent= */ "", /* useSimpleVibration= */ false);
+ when(mockVibratorInfo.areVibrationFeaturesSupported(any())).thenReturn(true);
+
+ createRingerUnderTest();
+
+ assertEquals(EXPECTED_SIMPLE_VIBRATION_PATTERN, mRingerUnderTest.mDefaultVibrationEffect);
+ }
+
+ @SmallTest
+ @Test
public void testNoActionInTheaterMode() throws Exception {
// Start call waiting to make sure that it doesn't stop when we start ringing
mRingerUnderTest.startCallWaiting(mockCall1);
@@ -670,4 +842,13 @@
when(mockRingtoneFactory.getHapticOnlyRingtone()).thenReturn(mockRingtone);
return mockRingtone;
}
+
+ private void mockVibrationResourceValues(
+ String defaultVibrationContent, boolean useSimpleVibration) {
+ mComponentContextFixture.putRawResource(
+ com.android.internal.R.raw.default_ringtone_vibration_effect,
+ defaultVibrationContent);
+ mComponentContextFixture.putBooleanResource(
+ R.bool.use_simple_vibration_pattern, useSimpleVibration);
+ }
}
diff --git a/tests/src/com/android/server/telecom/tests/TelecomServiceImplTest.java b/tests/src/com/android/server/telecom/tests/TelecomServiceImplTest.java
index 8bc1f2a..e9466ee 100644
--- a/tests/src/com/android/server/telecom/tests/TelecomServiceImplTest.java
+++ b/tests/src/com/android/server/telecom/tests/TelecomServiceImplTest.java
@@ -58,11 +58,13 @@
import com.android.server.telecom.CallState;
import com.android.server.telecom.CallsManager;
import com.android.server.telecom.DefaultDialerCache;
+import com.android.server.telecom.InCallController;
import com.android.server.telecom.PhoneAccountRegistrar;
import com.android.server.telecom.TelecomServiceImpl;
import com.android.server.telecom.TelecomSystem;
import com.android.server.telecom.components.UserCallIntentProcessor;
import com.android.server.telecom.components.UserCallIntentProcessorFactory;
+import com.android.server.telecom.flags.FeatureFlags;
import com.android.server.telecom.voip.IncomingCallTransaction;
import com.android.server.telecom.voip.OutgoingCallTransaction;
import com.android.server.telecom.voip.TransactionManager;
@@ -76,6 +78,7 @@
import org.mockito.ArgumentMatcher;
import org.mockito.Mock;
+import java.lang.reflect.Method;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.Executor;
@@ -86,6 +89,7 @@
import static android.Manifest.permission.WRITE_SECURE_SETTINGS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
@@ -122,7 +126,7 @@
public static class CallIntentProcessAdapterFake implements CallIntentProcessor.Adapter {
@Override
public void processOutgoingCallIntent(Context context, CallsManager callsManager,
- Intent intent, String callingPackage) {
+ Intent intent, String callingPackage, FeatureFlags flags) {
}
@@ -192,6 +196,9 @@
@Mock private ICallEventCallback mICallEventCallback;
@Mock private TransactionManager mTransactionManager;
@Mock private AnomalyReporterAdapter mAnomalyReporterAdapter;
+ @Mock private FeatureFlags mFeatureFlags;
+
+ @Mock private InCallController mInCallController;
private final TelecomSystem.SyncRoot mLock = new TelecomSystem.SyncRoot() { };
@@ -219,6 +226,7 @@
doReturn(mContext).when(mContext).getApplicationContext();
doReturn(mContext).when(mContext).createContextAsUser(any(UserHandle.class), anyInt());
+ when(mFakeCallsManager.getInCallController()).thenReturn(mInCallController);
doNothing().when(mContext).sendBroadcastAsUser(any(Intent.class), any(UserHandle.class),
anyString());
when(mContext.checkCallingOrSelfPermission(Manifest.permission.INTERACT_ACROSS_USERS))
@@ -242,6 +250,7 @@
mDefaultDialerCache,
mSubscriptionManagerAdapter,
mSettingsSecureAdapter,
+ mFeatureFlags,
mLock);
telecomServiceImpl.setTransactionManager(mTransactionManager);
telecomServiceImpl.setAnomalyReporterAdapter(mAnomalyReporterAdapter);
@@ -260,6 +269,7 @@
mPackageManager = mContext.getPackageManager();
when(mPackageManager.getPackageUid(anyString(), eq(0))).thenReturn(Binder.getCallingUid());
+ when(mFeatureFlags.earlyBindingToIncallService()).thenReturn(true);
}
@Override
@@ -1040,6 +1050,7 @@
verify(mFakePhoneAccountRegistrar).getPhoneAccount(
TEL_PA_HANDLE_16, TEL_PA_HANDLE_16.getUserHandle());
+ verify(mInCallController, never()).bindToServices(any());
addCallTestHelper(TelecomManager.ACTION_INCOMING_CALL,
CallIntentProcessor.KEY_IS_INCOMING_CALL, extras,
TEL_PA_HANDLE_16, false);
@@ -1047,6 +1058,81 @@
@SmallTest
@Test
+ public void testAddNewIncomingFlagDisabledNoEarlyBinding() throws Exception {
+ when(mFeatureFlags.earlyBindingToIncallService()).thenReturn(false);
+ PhoneAccount phoneAccount = makeSkipCallFilteringPhoneAccount(TEL_PA_HANDLE_16).build();
+ phoneAccount.setIsEnabled(true);
+ doReturn(phoneAccount).when(mFakePhoneAccountRegistrar).getPhoneAccount(
+ eq(TEL_PA_HANDLE_16), any(UserHandle.class));
+ doReturn(phoneAccount).when(mFakePhoneAccountRegistrar).getPhoneAccountUnchecked(
+ eq(TEL_PA_HANDLE_16));
+ doNothing().when(mAppOpsManager).checkPackage(anyInt(), anyString());
+ when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_WATCH)).thenReturn(true);
+ Bundle extras = createSampleExtras();
+
+ mTSIBinder.addNewIncomingCall(TEL_PA_HANDLE_16, extras, CALLING_PACKAGE);
+
+ verify(mInCallController, never()).bindToServices(null);
+ }
+
+ @SmallTest
+ @Test
+ public void testAddNewIncomingCallEarlyBindingForNoCallFilterCalls() throws Exception {
+ PhoneAccount phoneAccount = makeSkipCallFilteringPhoneAccount(TEL_PA_HANDLE_16).build();
+ phoneAccount.setIsEnabled(true);
+ doReturn(phoneAccount).when(mFakePhoneAccountRegistrar).getPhoneAccount(
+ eq(TEL_PA_HANDLE_16), any(UserHandle.class));
+ doReturn(phoneAccount).when(mFakePhoneAccountRegistrar).getPhoneAccountUnchecked(
+ eq(TEL_PA_HANDLE_16));
+ doNothing().when(mAppOpsManager).checkPackage(anyInt(), anyString());
+ when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_WATCH)).thenReturn(true);
+ Bundle extras = createSampleExtras();
+
+ mTSIBinder.addNewIncomingCall(TEL_PA_HANDLE_16, extras, CALLING_PACKAGE);
+
+ verify(mInCallController).bindToServices(null);
+ }
+
+ @SmallTest
+ @Test
+ public void testAddNewIncomingCallEarlyBindingNotEnableForNonWatchDevices() throws Exception {
+ PhoneAccount phoneAccount = makeSkipCallFilteringPhoneAccount(TEL_PA_HANDLE_16).build();
+ phoneAccount.setIsEnabled(true);
+ doReturn(phoneAccount).when(mFakePhoneAccountRegistrar).getPhoneAccount(
+ eq(TEL_PA_HANDLE_16), any(UserHandle.class));
+ doReturn(phoneAccount).when(mFakePhoneAccountRegistrar).getPhoneAccountUnchecked(
+ eq(TEL_PA_HANDLE_16));
+ doNothing().when(mAppOpsManager).checkPackage(anyInt(), anyString());
+ when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_WATCH)).thenReturn(false);
+ Bundle extras = createSampleExtras();
+
+ mTSIBinder.addNewIncomingCall(TEL_PA_HANDLE_16, extras, CALLING_PACKAGE);
+
+ verify(mInCallController, never()).bindToServices(null);
+ }
+
+ @SmallTest
+ @Test
+ public void testAddNewIncomingCallEarlyBindingNotEnableForPhoneAccountHasCallFilters()
+ throws Exception {
+ PhoneAccount phoneAccount = makePhoneAccount(TEL_PA_HANDLE_16).build();
+ phoneAccount.setIsEnabled(true);
+ doReturn(phoneAccount).when(mFakePhoneAccountRegistrar).getPhoneAccount(
+ eq(TEL_PA_HANDLE_16), any(UserHandle.class));
+ doReturn(phoneAccount).when(mFakePhoneAccountRegistrar).getPhoneAccountUnchecked(
+ eq(TEL_PA_HANDLE_16));
+ doNothing().when(mAppOpsManager).checkPackage(anyInt(), anyString());
+ when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_WATCH)).thenReturn(true);
+ Bundle extras = createSampleExtras();
+
+ mTSIBinder.addNewIncomingCall(TEL_PA_HANDLE_16, extras, CALLING_PACKAGE);
+
+ verify(mInCallController, never()).bindToServices(null);
+ }
+
+
+ @SmallTest
+ @Test
public void testAddNewIncomingCallFailure() throws Exception {
try {
mTSIBinder.addNewIncomingCall(TEL_PA_HANDLE_16, null, CALLING_PACKAGE);
@@ -1703,6 +1789,28 @@
verify(mContext, never()).sendBroadcastAsUser(any(Intent.class), any(UserHandle.class));
}
+ /**
+ * FeatureFlags is autogenerated code, so there could be a situation where something changes
+ * outside of Telecom control that breaks reflection. This test attempts to ensure that changes
+ * to auto-generated FeatureFlags code that breaks reflection are caught early.
+ */
+ @SmallTest
+ @Test
+ public void testFlagConfigReflectionWorks() {
+ try {
+ Method[] methods = FeatureFlags.class.getMethods();
+ for (Method m : methods) {
+ // test getting the name and invoking the flag code
+ String name = m.getName();
+ Object val = m.invoke(mFeatureFlags);
+ assertNotNull(name);
+ assertNotNull(val);
+ }
+ } catch (Exception e) {
+ fail("Reflection failed for FeatureFlags with error: " + e);
+ }
+ }
+
@SmallTest
@Test
public void testIsVoicemailNumber() throws Exception {
@@ -2144,6 +2252,12 @@
return new PhoneAccount.Builder(paHandle, "testLabel");
}
+ private PhoneAccount.Builder makeSkipCallFilteringPhoneAccount(PhoneAccountHandle paHandle) {
+ Bundle extras = new Bundle();
+ extras.putBoolean(PhoneAccount.EXTRA_SKIP_CALL_FILTERING, true);
+ return new PhoneAccount.Builder(paHandle, "testLabel").setExtras(extras);
+ }
+
private Bundle createSampleExtras() {
Bundle extras = new Bundle();
extras.putString("test_key", "test_value");
diff --git a/tests/src/com/android/server/telecom/tests/TelecomSystemTest.java b/tests/src/com/android/server/telecom/tests/TelecomSystemTest.java
index ed96d74..868ca25 100644
--- a/tests/src/com/android/server/telecom/tests/TelecomSystemTest.java
+++ b/tests/src/com/android/server/telecom/tests/TelecomSystemTest.java
@@ -99,6 +99,7 @@
import com.android.server.telecom.bluetooth.BluetoothRouteManager;
import com.android.server.telecom.callfiltering.BlockedNumbersAdapter;
import com.android.server.telecom.components.UserCallIntentProcessor;
+import com.android.server.telecom.flags.FeatureFlags;
import com.android.server.telecom.ui.IncomingCallNotifier;
import com.google.common.base.Predicate;
@@ -217,6 +218,8 @@
BlockedNumbersAdapter mBlockedNumbersAdapter;
@Mock
CallAudioCommunicationDeviceTracker mCommunicationDeviceTracker;
+ @Mock
+ FeatureFlags mFeatureFlags;
final ComponentName mInCallServiceComponentNameX =
new ComponentName(
@@ -555,7 +558,8 @@
}, mDeviceIdleControllerAdapter, mAccessibilityManagerAdapter,
Runnable::run,
Runnable::run,
- mBlockedNumbersAdapter);
+ mBlockedNumbersAdapter,
+ mFeatureFlags);
mComponentContextFixture.setTelecomManager(new TelecomManager(
mComponentContextFixture.getTestDouble(),
diff --git a/tests/src/com/android/server/telecom/tests/TransactionTests.java b/tests/src/com/android/server/telecom/tests/TransactionTests.java
index 3fc87a9..d733d9d 100644
--- a/tests/src/com/android/server/telecom/tests/TransactionTests.java
+++ b/tests/src/com/android/server/telecom/tests/TransactionTests.java
@@ -16,7 +16,11 @@
package com.android.server.telecom.tests;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -39,11 +43,14 @@
import android.telecom.DisconnectCause;
import android.telecom.PhoneAccountHandle;
+import androidx.test.filters.SmallTest;
+
import com.android.server.telecom.Call;
import com.android.server.telecom.CallState;
import com.android.server.telecom.CallerInfoLookupHelper;
import com.android.server.telecom.CallsManager;
import com.android.server.telecom.ClockProxy;
+import com.android.server.telecom.ConnectionServiceWrapper;
import com.android.server.telecom.PhoneNumberUtilsAdapter;
import com.android.server.telecom.TelecomSystem;
import com.android.server.telecom.ui.ToastFactory;
@@ -53,6 +60,8 @@
import com.android.server.telecom.voip.OutgoingCallTransaction;
import com.android.server.telecom.voip.MaybeHoldCallForNewCallTransaction;
import com.android.server.telecom.voip.RequestNewActiveCallTransaction;
+import com.android.server.telecom.voip.VerifyCallStateChangeTransaction;
+import com.android.server.telecom.voip.VoipCallTransactionResult;
import org.junit.After;
import org.junit.Before;
@@ -62,6 +71,11 @@
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
public class TransactionTests extends TelecomTestCase {
@@ -250,6 +264,63 @@
isA(Boolean.class));
}
+ /**
+ * This test verifies if the ConnectionService call is NOT transitioned to the desired call
+ * state (within timeout period), Telecom will disconnect the call.
+ */
+ @SmallTest
+ @Test
+ public void testCallStateChangeTimesOut()
+ throws ExecutionException, InterruptedException, TimeoutException {
+ VerifyCallStateChangeTransaction t = new VerifyCallStateChangeTransaction(mCallsManager,
+ mMockCall1, CallState.ON_HOLD, true);
+ // WHEN
+ setupHoldableCall();
+
+ // simulate the transaction being processed and the CompletableFuture timing out
+ t.processTransaction(null);
+ CompletableFuture<Integer> timeoutFuture = t.getCallStateOrTimeoutResult();
+ timeoutFuture.complete(VerifyCallStateChangeTransaction.FAILURE_CODE);
+
+ // THEN
+ verify(mMockCall1, times(1)).addCallStateListener(t.getCallStateListenerImpl());
+ assertEquals(timeoutFuture.get().intValue(), VerifyCallStateChangeTransaction.FAILURE_CODE);
+ assertEquals(VoipCallTransactionResult.RESULT_FAILED,
+ t.getTransactionResult().get(2, TimeUnit.SECONDS).getResult());
+ verify(mMockCall1, atLeastOnce()).removeCallStateListener(any());
+ verify(mCallsManager, times(1)).markCallAsDisconnected(eq(mMockCall1), any());
+ verify(mCallsManager, times(1)).markCallAsRemoved(eq(mMockCall1));
+ }
+
+ /**
+ * This test verifies that when an application transitions a call to the requested state,
+ * Telecom does not disconnect the call and transaction completes successfully.
+ */
+ @SmallTest
+ @Test
+ public void testCallStateIsSuccessfullyChanged()
+ throws ExecutionException, InterruptedException, TimeoutException {
+ VerifyCallStateChangeTransaction t = new VerifyCallStateChangeTransaction(mCallsManager,
+ mMockCall1, CallState.ON_HOLD, true);
+ // WHEN
+ setupHoldableCall();
+
+ // simulate the transaction being processed and the setOnHold() being called / state change
+ t.processTransaction(null);
+ t.getCallStateListenerImpl().onCallStateChanged(CallState.ON_HOLD);
+ when(mMockCall1.getState()).thenReturn(CallState.ON_HOLD);
+
+ // THEN
+ verify(mMockCall1, times(1)).addCallStateListener(t.getCallStateListenerImpl());
+ assertEquals(t.getCallStateOrTimeoutResult().get().intValue(),
+ VerifyCallStateChangeTransaction.SUCCESS_CODE);
+ assertEquals(VoipCallTransactionResult.RESULT_SUCCEED,
+ t.getTransactionResult().get(2, TimeUnit.SECONDS).getResult());
+ verify(mMockCall1, atLeastOnce()).removeCallStateListener(any());
+ verify(mCallsManager, never()).markCallAsDisconnected(eq(mMockCall1), any());
+ verify(mCallsManager, never()).markCallAsRemoved(eq(mMockCall1));
+ }
+
private Call createSpyCall(PhoneAccountHandle targetPhoneAccount, int initialState, String id) {
when(mCallsManager.getCallerInfoLookupHelper()).thenReturn(mCallerInfoLookupHelper);
@@ -280,4 +351,12 @@
return callSpy;
}
+
+ private void setupHoldableCall(){
+ when(mMockCall1.getState()).thenReturn(CallState.ACTIVE);
+ when(mMockCall1.getConnectionServiceWrapper()).thenReturn(
+ mock(ConnectionServiceWrapper.class));
+ doNothing().when(mMockCall1).addCallStateListener(any());
+ doReturn(true).when(mMockCall1).removeCallStateListener(any());
+ }
}
\ No newline at end of file