CallScreeningService behavior changes and improvements.
1. When sending information about a call to the CallScreeningService,
using a new parceling method which passes the bare minimum amount of info
about a call necessary to screen the call.
2. Fix bug where the app name was being logged as the package name for
screened calls. Adding an AppLabelProxy in the
CallScreeningServiceController to perform lookup of the app name for
logging purposes.
3. Change lookup of user-defined call screening app to make use of the
role manager proxy instead.
Bug: 63966743
Test: Created call screening service test app.
Test: Manually tested operation of user selected CS app using test app and
test override commands.
Merged-In: I51c816f36ad1e5dcd229271c608982113f97b751
Change-Id: I51c816f36ad1e5dcd229271c608982113f97b751
diff --git a/src/com/android/server/telecom/CallsManager.java b/src/com/android/server/telecom/CallsManager.java
index 5e46e5a..7ff4e51 100644
--- a/src/com/android/server/telecom/CallsManager.java
+++ b/src/com/android/server/telecom/CallsManager.java
@@ -23,6 +23,8 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.media.AudioManager;
import android.media.AudioSystem;
@@ -607,7 +609,21 @@
mCallerInfoLookupHelper, null));
filters.add(new CallScreeningServiceController(mContext, this, mPhoneAccountRegistrar,
new ParcelableCallUtils.Converter(), mLock,
- new TelecomServiceImpl.SettingsSecureAdapterImpl(), mCallerInfoLookupHelper));
+ new TelecomServiceImpl.SettingsSecureAdapterImpl(), mCallerInfoLookupHelper,
+ new CallScreeningServiceController.AppLabelProxy() {
+ @Override
+ public String getAppLabel(String packageName) {
+ PackageManager pm = mContext.getPackageManager();
+ try {
+ ApplicationInfo info = pm.getApplicationInfo(packageName, 0);
+ return (String) pm.getApplicationLabel(info);
+ } catch (PackageManager.NameNotFoundException nnfe) {
+ Log.w(this, "Could not determine package name.");
+ }
+
+ return null;
+ }
+ }));
new IncomingCallFilter(mContext, this, incomingCall, mLock,
mTimeoutsAdapter, filters).performFiltering();
}
diff --git a/src/com/android/server/telecom/ParcelableCallUtils.java b/src/com/android/server/telecom/ParcelableCallUtils.java
index 7eb8f0e..925efae 100644
--- a/src/com/android/server/telecom/ParcelableCallUtils.java
+++ b/src/com/android/server/telecom/ParcelableCallUtils.java
@@ -18,11 +18,13 @@
import android.net.Uri;
import android.telecom.Connection;
+import android.telecom.DisconnectCause;
import android.telecom.ParcelableCall;
import android.telecom.ParcelableRttCall;
import android.telecom.TelecomManager;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
/**
@@ -37,6 +39,10 @@
return ParcelableCallUtils.toParcelableCall(
call, includeVideoProvider, phoneAccountRegistrar, false, false);
}
+
+ public ParcelableCall toParcelableCallForScreening(Call call) {
+ return ParcelableCallUtils.toParcelableCallForScreening(call);
+ }
}
/**
@@ -191,6 +197,53 @@
call.getCreationTimeMillis());
}
+ /**
+ * Creates a ParcelableCall with the bare minimum properties required for a
+ * {@link android.telecom.CallScreeningService}. We ONLY expose the following:
+ * <ul>
+ * <li>Call Id (not exposed to public, but needed to associated calls)</li>
+ * <li>Call state</li>
+ * <li>Creation time</li>
+ * <li>Connection time</li>
+ * <li>Handle (phone number)</li>
+ * <li>Handle (phone number) presentation</li>
+ * </ul>
+ * All other fields are nulled or set to 0 values.
+ * @param call The telecom call to send to a call screening service.
+ * @return Minimal {@link ParcelableCall} to send to the call screening service.
+ */
+ public static ParcelableCall toParcelableCallForScreening(Call call) {
+ Uri handle = call.getHandlePresentation() == TelecomManager.PRESENTATION_ALLOWED ?
+ call.getHandle() : null;
+ return new ParcelableCall(
+ call.getId(),
+ getParcelableState(call, false /* supportsExternalCalls */),
+ new DisconnectCause(DisconnectCause.UNKNOWN),
+ null, /* cannedSmsResponses */
+ 0, /* capabilities */
+ 0, /* properties */
+ 0, /* supportedAudioRoutes */
+ call.getConnectTimeMillis(),
+ handle,
+ call.getHandlePresentation(),
+ null, /* callerDisplayName */
+ 0 /* callerDisplayNamePresentation */,
+ null, /* gatewayInfo */
+ null, /* targetPhoneAccount */
+ false, /* includeVideoProvider */
+ null, /* videoProvider */
+ false, /* includeRttCall */
+ null, /* rttCall */
+ null, /* parentCallId */
+ null, /* childCallIds */
+ null, /* statusHints */
+ 0, /* videoState */
+ Collections.emptyList(), /* conferenceableCallIds */
+ null, /* intentExtras */
+ null, /* callExtras */
+ call.getCreationTimeMillis());
+ }
+
private static int getParcelableState(Call call, boolean supportsExternalCalls) {
int state = CallState.NEW;
switch (call.getState()) {
diff --git a/src/com/android/server/telecom/TelecomSystem.java b/src/com/android/server/telecom/TelecomSystem.java
index ffa6035..2daba61 100644
--- a/src/com/android/server/telecom/TelecomSystem.java
+++ b/src/com/android/server/telecom/TelecomSystem.java
@@ -196,7 +196,8 @@
IncomingCallNotifier incomingCallNotifier,
InCallTonePlayer.ToneGeneratorFactory toneGeneratorFactory,
CallAudioRouteStateMachine.Factory callAudioRouteStateMachineFactory,
- ClockProxy clockProxy) {
+ ClockProxy clockProxy,
+ RoleManagerAdapter roleManagerAdapter) {
mContext = context.getApplicationContext();
LogUtils.initLogging(mContext);
DefaultDialerManagerAdapter defaultDialerAdapter =
@@ -261,8 +262,6 @@
}
};
- RoleManagerAdapter roleManagerAdapter = new RoleManagerAdapterImpl();
-
mCallsManager = new CallsManager(
mContext,
mLock,
diff --git a/src/com/android/server/telecom/callfiltering/CallScreeningServiceController.java b/src/com/android/server/telecom/callfiltering/CallScreeningServiceController.java
index 40bf398..3ca95ff 100644
--- a/src/com/android/server/telecom/callfiltering/CallScreeningServiceController.java
+++ b/src/com/android/server/telecom/callfiltering/CallScreeningServiceController.java
@@ -18,6 +18,7 @@
import android.content.ComponentName;
import android.content.Context;
+import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
@@ -50,6 +51,14 @@
public class CallScreeningServiceController implements IncomingCallFilter.CallFilter,
CallScreeningServiceFilter.CallScreeningFilterResultCallback {
+ /**
+ * Abstracts away dependency on the {@link PackageManager} required to fetch the label for an
+ * app.
+ */
+ public interface AppLabelProxy {
+ String getAppLabel(String packageName);
+ }
+
private final Context mContext;
private final CallsManager mCallsManager;
private final PhoneAccountRegistrar mPhoneAccountRegistrar;
@@ -57,6 +66,7 @@
private final TelecomSystem.SyncRoot mTelecomLock;
private final TelecomServiceImpl.SettingsSecureAdapter mSettingsSecureAdapter;
private final CallerInfoLookupHelper mCallerInfoLookupHelper;
+ private final AppLabelProxy mAppLabelProxy;
private final int CARRIER_CALL_FILTERING_TIMED_OUT = 2000; // 2 seconds
private final int CALL_FILTERING_TIMED_OUT = 4500; // 4.5 seconds
@@ -85,7 +95,8 @@
ParcelableCallUtils.Converter parcelableCallUtilsConverter,
TelecomSystem.SyncRoot lock,
TelecomServiceImpl.SettingsSecureAdapter settingsSecureAdapter,
- CallerInfoLookupHelper callerInfoLookupHelper) {
+ CallerInfoLookupHelper callerInfoLookupHelper,
+ AppLabelProxy appLabelProxy) {
mContext = context;
mCallsManager = callsManager;
mPhoneAccountRegistrar = phoneAccountRegistrar;
@@ -93,6 +104,7 @@
mTelecomLock = lock;
mSettingsSecureAdapter = settingsSecureAdapter;
mCallerInfoLookupHelper = callerInfoLookupHelper;
+ mAppLabelProxy = appLabelProxy;
}
@Override
@@ -119,8 +131,8 @@
}
@Override
- public void onCallScreeningFilterComplete(Call call, CallFilteringResult result, String
- packageName) {
+ public void onCallScreeningFilterComplete(Call call, CallFilteringResult result,
+ String packageName) {
synchronized (mTelecomLock) {
mResult = result.combine(mResult);
if (!TextUtils.isEmpty(packageName) && packageName.equals(getCarrierPackageName())) {
@@ -154,7 +166,7 @@
bindDefaultDialerAndUserChosenService();
} else {
createCallScreeningServiceFilter().startCallScreeningFilter(mCall, this,
- carrierPackageName);
+ carrierPackageName, mAppLabelProxy.getAppLabel(carrierPackageName));
}
// Carrier filtering timed out
@@ -176,7 +188,8 @@
mIsDefaultDialerFinished = true;
} else {
createCallScreeningServiceFilter().startCallScreeningFilter(mCall,
- CallScreeningServiceController.this, dialerPackageName);
+ CallScreeningServiceController.this, dialerPackageName,
+ mAppLabelProxy.getAppLabel(dialerPackageName));
}
String userChosenPackageName = getUserChosenPackageName();
@@ -184,7 +197,8 @@
mIsUserChosenFinished = true;
} else {
createCallScreeningServiceFilter().startCallScreeningFilter(mCall,
- CallScreeningServiceController.this, userChosenPackageName);
+ CallScreeningServiceController.this, userChosenPackageName,
+ mAppLabelProxy.getAppLabel(userChosenPackageName));
}
if (mIsDefaultDialerFinished && mIsUserChosenFinished) {
@@ -250,15 +264,6 @@
}
private String getUserChosenPackageName() {
- ComponentName componentName = null;
- String defaultCallScreeningApplication = mSettingsSecureAdapter.getStringForUser(mContext
- .getContentResolver(), Settings.Secure.CALL_SCREENING_DEFAULT_COMPONENT,
- UserHandle.USER_CURRENT);
-
- if (!TextUtils.isEmpty(defaultCallScreeningApplication)) {
- componentName = ComponentName.unflattenFromString(defaultCallScreeningApplication);
- }
-
- return componentName != null ? componentName.getPackageName() : null;
+ return mCallsManager.getRoleManagerAdapter().getDefaultCallScreeningApp();
}
}
diff --git a/src/com/android/server/telecom/callfiltering/CallScreeningServiceFilter.java b/src/com/android/server/telecom/callfiltering/CallScreeningServiceFilter.java
index f0832e6..64e225a 100644
--- a/src/com/android/server/telecom/callfiltering/CallScreeningServiceFilter.java
+++ b/src/com/android/server/telecom/callfiltering/CallScreeningServiceFilter.java
@@ -31,6 +31,7 @@
import android.provider.Settings;
import android.telecom.CallScreeningService;
import android.telecom.Log;
+import android.telecom.ParcelableCall;
import android.telecom.TelecomManager;
import android.telephony.CarrierConfigManager;
import android.text.TextUtils;
@@ -136,7 +137,7 @@
isServiceRequestingLogging, //shouldAddToCallLog
shouldShowNotification, // shouldShowNotification
CallLog.Calls.BLOCK_REASON_CALL_SCREENING_SERVICE, //callBlockReason
- componentName.getPackageName(), //callScreeningAppName
+ mAppName, //callScreeningAppName
componentName.flattenToString() //callScreeningComponentName
);
} else {
@@ -152,7 +153,6 @@
}
private final Context mContext;
- private final PhoneAccountRegistrar mPhoneAccountRegistrar;
private final CallsManager mCallsManager;
private final ParcelableCallUtils.Converter mParcelableCallUtilsConverter;
private final TelecomSystem.SyncRoot mTelecomLock;
@@ -163,6 +163,7 @@
private ICallScreeningService mService;
private ServiceConnection mConnection;
private String mPackageName;
+ private String mAppName;
private boolean mHasFinished = false;
private CallFilteringResult mResult = new CallFilteringResult(
@@ -180,7 +181,6 @@
TelecomSystem.SyncRoot lock,
SettingsSecureAdapter settingsSecureAdapter) {
mContext = context;
- mPhoneAccountRegistrar = phoneAccountRegistrar;
mCallsManager = callsManager;
mParcelableCallUtilsConverter = parcelableCallUtilsConverter;
mTelecomLock = lock;
@@ -189,7 +189,8 @@
public void startCallScreeningFilter(Call call,
CallScreeningFilterResultCallback callback,
- String packageName) {
+ String packageName,
+ String appName) {
if (mHasFinished) {
Log.w(this, "Attempting to reuse CallScreeningServiceFilter. Ignoring.");
return;
@@ -198,6 +199,7 @@
mCall = call;
mCallback = callback;
mPackageName = packageName;
+ mAppName = appName;
if (!bindService()) {
Log.i(this, "Could not bind to call screening service");
finishCallScreening();
@@ -268,11 +270,9 @@
private void onServiceBound(ICallScreeningService service) {
mService = service;
try {
+ // Important: Only send a minimal subset of the call to the screening service.
mService.screenCall(new CallScreeningAdapter(),
- mParcelableCallUtilsConverter.toParcelableCall(
- mCall,
- false, /* includeVideoProvider */
- mPhoneAccountRegistrar));
+ mParcelableCallUtilsConverter.toParcelableCallForScreening(mCall));
} catch (RemoteException e) {
Log.e(this, e, "Failed to set the call screening adapter.");
finishCallScreening();
diff --git a/src/com/android/server/telecom/components/TelecomService.java b/src/com/android/server/telecom/components/TelecomService.java
index 153ddc4..1beae2b 100644
--- a/src/com/android/server/telecom/components/TelecomService.java
+++ b/src/com/android/server/telecom/components/TelecomService.java
@@ -50,6 +50,8 @@
import com.android.server.telecom.InCallWakeLockController;
import com.android.server.telecom.ProximitySensorManager;
import com.android.server.telecom.R;
+import com.android.server.telecom.RoleManagerAdapter;
+import com.android.server.telecom.RoleManagerAdapterImpl;
import com.android.server.telecom.TelecomSystem;
import com.android.server.telecom.TelecomWakeLock;
import com.android.server.telecom.Timeouts;
@@ -185,7 +187,8 @@
public long elapsedRealtime() {
return SystemClock.elapsedRealtime();
}
- }));
+ },
+ new RoleManagerAdapterImpl()));
}
if (BluetoothAdapter.getDefaultAdapter() != null) {
context.startService(new Intent(context, BluetoothPhoneService.class));
diff --git a/testapps/AndroidManifest.xml b/testapps/AndroidManifest.xml
index 02443ba..9cb1992 100644
--- a/testapps/AndroidManifest.xml
+++ b/testapps/AndroidManifest.xml
@@ -238,5 +238,19 @@
<receiver android:exported="false"
android:process="com.android.server.telecom.testapps.SelfMangingCallingApp"
android:name="com.android.server.telecom.testapps.SelfManagedCallNotificationReceiver" />
+
+ <service
+ android:name=".TestCallScreeningService"
+ android:permission="android.permission.BIND_SCREENING_SERVICE">
+ <intent-filter>
+ <action android:name="android.telecom.CallScreeningService"/>
+ </intent-filter>
+ </service>
+
+ <activity android:name=".CallScreeningActivity"
+ android:configChanges="orientation|screenSize|keyboardHidden"
+ android:excludeFromRecents="true"
+ android:launchMode="singleInstance">
+ </activity>
</application>
</manifest>
diff --git a/testapps/src/com/android/server/telecom/testapps/CallScreeningActivity.java b/testapps/src/com/android/server/telecom/testapps/CallScreeningActivity.java
new file mode 100644
index 0000000..05ba500
--- /dev/null
+++ b/testapps/src/com/android/server/telecom/testapps/CallScreeningActivity.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2018 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.testapps;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.os.Bundle;
+import android.telecom.CallScreeningService;
+import android.view.WindowManager;
+
+public class CallScreeningActivity extends Activity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ AlertDialog alertDialog = new AlertDialog.Builder(this)
+ .setTitle("Test Call Screening")
+ .setMessage("Allow the call?")
+ .setNegativeButton("Block", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ if (TestCallScreeningService.getInstance() != null) {
+ TestCallScreeningService.getInstance().blockCall();
+ }
+ finish();
+ }
+ })
+ .setPositiveButton("Allow", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ if (TestCallScreeningService.getInstance() != null) {
+ TestCallScreeningService.getInstance().allowCall();
+ }
+ finish();
+ }
+ }).create();
+ alertDialog.show();
+ }
+}
diff --git a/testapps/src/com/android/server/telecom/testapps/TestCallScreeningService.java b/testapps/src/com/android/server/telecom/testapps/TestCallScreeningService.java
new file mode 100644
index 0000000..81a469e
--- /dev/null
+++ b/testapps/src/com/android/server/telecom/testapps/TestCallScreeningService.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2018 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.testapps;
+
+import android.content.Intent;
+import android.telecom.Call;
+import android.telecom.CallScreeningService;
+import android.telecom.Log;
+
+public class TestCallScreeningService extends CallScreeningService {
+ private Call.Details mDetails;
+ private static TestCallScreeningService sTestCallScreeningService;
+
+ public static TestCallScreeningService getInstance() {
+ return sTestCallScreeningService;
+ }
+
+ /**
+ * Handles request from the system to screen an incoming call.
+ * @param callDetails Information about a new incoming call, see {@link Call.Details}.
+ */
+ @Override
+ public void onScreenCall(Call.Details callDetails) {
+ Log.i(this, "onScreenCall: received call %s", callDetails);
+ sTestCallScreeningService = this;
+
+ mDetails = callDetails;
+ Intent errorIntent = new Intent(this, CallScreeningActivity.class);
+ errorIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ startActivity(errorIntent);
+ }
+
+ public void blockCall() {
+ CallScreeningService.CallResponse
+ response = new CallScreeningService.CallResponse.Builder()
+ .setDisallowCall(true)
+ .setRejectCall(true)
+ .setSkipCallLog(false)
+ .setSkipNotification(true)
+ .build();
+ respondToCall(mDetails, response);
+ }
+
+ public void allowCall() {
+ CallScreeningService.CallResponse
+ response = new CallScreeningService.CallResponse.Builder()
+ .setDisallowCall(false)
+ .setRejectCall(false)
+ .setSkipCallLog(false)
+ .setSkipNotification(false)
+ .build();
+ respondToCall(mDetails, response);
+ }
+}
diff --git a/tests/src/com/android/server/telecom/tests/CallScreeningServiceControllerTest.java b/tests/src/com/android/server/telecom/tests/CallScreeningServiceControllerTest.java
index 324375b..0004035 100644
--- a/tests/src/com/android/server/telecom/tests/CallScreeningServiceControllerTest.java
+++ b/tests/src/com/android/server/telecom/tests/CallScreeningServiceControllerTest.java
@@ -39,6 +39,7 @@
import com.android.server.telecom.CallsManager;
import com.android.server.telecom.ParcelableCallUtils;
import com.android.server.telecom.PhoneAccountRegistrar;
+import com.android.server.telecom.RoleManagerAdapter;
import com.android.server.telecom.TelecomServiceImpl;
import com.android.server.telecom.TelecomSystem;
import com.android.server.telecom.callfiltering.CallFilterResultCallback;
@@ -71,6 +72,7 @@
@Mock Call mCall;
@Mock private CallFilterResultCallback mCallback;
@Mock CallsManager mCallsManager;
+ @Mock RoleManagerAdapter mRoleManagerAdapter;
@Mock CarrierConfigManager mCarrierConfigManager;
@Mock private TelecomManager mTelecomManager;
@Mock PackageManager mPackageManager;
@@ -78,6 +80,14 @@
@Mock PhoneAccountRegistrar mPhoneAccountRegistrar;
@Mock private CallerInfoLookupHelper mCallerInfoLookupHelper;
+ CallScreeningServiceController.AppLabelProxy mAppLabelProxy =
+ new CallScreeningServiceController.AppLabelProxy() {
+ @Override
+ public String getAppLabel(String packageName) {
+ return APP_NAME;
+ }
+ };
+
private ResolveInfo mResolveInfo;
private TelecomServiceImpl.SettingsSecureAdapter mSettingsSecureAdapter =
spy(new CallScreeningServiceFilterTest.SettingsSecureAdapterFake());
@@ -88,6 +98,7 @@
private static final String DEFAULT_DIALER_PACKAGE = "com.android.dialer";
private static final String PKG_NAME = "com.android.services.telecom.tests";
private static final String CLS_NAME = "CallScreeningService";
+ private static final String APP_NAME = "Screeny McScreenface";
private static final ComponentName CARRIER_DEFINED_CALL_SCREENING = new ComponentName(
"com.android.carrier", "com.android.carrier.callscreeningserviceimpl");
private static final ComponentName DEFAULT_DIALER_CALL_SCREENING = new ComponentName(
@@ -120,6 +131,10 @@
@Before
public void setUp() throws Exception {
super.setUp();
+ when(mRoleManagerAdapter.getCallCompanionApps()).thenReturn(Collections.emptyList());
+ when(mRoleManagerAdapter.getDefaultCallScreeningApp()).thenReturn(null);
+ when(mRoleManagerAdapter.getCarModeDialerApp()).thenReturn(null);
+ when(mCallsManager.getRoleManagerAdapter()).thenReturn(mRoleManagerAdapter);
when(mCallsManager.getCurrentUserHandle()).thenReturn(UserHandle.CURRENT);
when(mContext.getPackageManager()).thenReturn(mPackageManager);
when(mCall.getId()).thenReturn(CALL_ID);
@@ -147,10 +162,12 @@
@SmallTest
@Test
public void testAllAllowCall() {
+ when(mRoleManagerAdapter.getDefaultCallScreeningApp()).thenReturn(
+ USER_CHOSEN_CALL_SCREENING.getPackageName());
CallScreeningServiceController controller = new CallScreeningServiceController(mContext,
- mCallsManager,
- mPhoneAccountRegistrar, mParcelableCallUtilsConverter, mLock,
- mSettingsSecureAdapter, mCallerInfoLookupHelper);
+ mCallsManager, mPhoneAccountRegistrar,
+ mParcelableCallUtilsConverter, mLock,
+ mSettingsSecureAdapter, mCallerInfoLookupHelper, mAppLabelProxy);
controller.startFilterLookup(mCall, mCallback);
@@ -181,7 +198,7 @@
CallScreeningServiceController controller = new CallScreeningServiceController(mContext,
mCallsManager,
mPhoneAccountRegistrar, mParcelableCallUtilsConverter, mLock,
- mSettingsSecureAdapter, mCallerInfoLookupHelper);
+ mSettingsSecureAdapter, mCallerInfoLookupHelper, mAppLabelProxy);
controller.startFilterLookup(mCall, mCallback);
@@ -207,7 +224,7 @@
CallScreeningServiceController controller = new CallScreeningServiceController(mContext,
mCallsManager,
mPhoneAccountRegistrar, mParcelableCallUtilsConverter, mLock,
- mSettingsSecureAdapter, mCallerInfoLookupHelper);
+ mSettingsSecureAdapter, mCallerInfoLookupHelper, mAppLabelProxy);
controller.startFilterLookup(mCall, mCallback);
@@ -217,7 +234,7 @@
false, // shouldAddToCallLog
true, // shouldShowNotification
CallLog.Calls.BLOCK_REASON_CALL_SCREENING_SERVICE,
- CARRIER_DEFINED_CALL_SCREENING.getPackageName(),
+ APP_NAME,
CARRIER_DEFINED_CALL_SCREENING.flattenToString()
), CARRIER_DEFINED_CALL_SCREENING.getPackageName());
@@ -232,7 +249,7 @@
false, // shouldAddToCallLog
true, // shouldShowNotification
CallLog.Calls.BLOCK_REASON_CALL_SCREENING_SERVICE, //callBlockReason
- CARRIER_DEFINED_CALL_SCREENING.getPackageName(), //callScreeningAppName
+ APP_NAME, //callScreeningAppName
CARRIER_DEFINED_CALL_SCREENING.flattenToString() //callScreeningComponentName
)));
}
@@ -240,10 +257,12 @@
@SmallTest
@Test
public void testDefaultDialerRejectCall() {
+ when(mRoleManagerAdapter.getDefaultCallScreeningApp()).thenReturn(
+ USER_CHOSEN_CALL_SCREENING.getPackageName());
CallScreeningServiceController controller = new CallScreeningServiceController(mContext,
mCallsManager,
mPhoneAccountRegistrar, mParcelableCallUtilsConverter, mLock,
- mSettingsSecureAdapter, mCallerInfoLookupHelper);
+ mSettingsSecureAdapter, mCallerInfoLookupHelper, mAppLabelProxy);
controller.startFilterLookup(mCall, mCallback);
@@ -261,7 +280,7 @@
false, // shouldAddToCallLog
true, // shouldShowNotification
CallLog.Calls.BLOCK_REASON_CALL_SCREENING_SERVICE,
- DEFAULT_DIALER_CALL_SCREENING.getPackageName(),
+ APP_NAME,
DEFAULT_DIALER_CALL_SCREENING.flattenToString()
), DEFAULT_DIALER_CALL_SCREENING.getPackageName());
@@ -276,7 +295,7 @@
false, // shouldAddToCallLog
true, // shouldShowNotification
CallLog.Calls.BLOCK_REASON_CALL_SCREENING_SERVICE, //callBlockReason
- DEFAULT_DIALER_CALL_SCREENING.getPackageName(), //callScreeningAppName
+ APP_NAME, //callScreeningAppName
DEFAULT_DIALER_CALL_SCREENING.flattenToString() //callScreeningComponentName
)));
}
@@ -284,10 +303,12 @@
@SmallTest
@Test
public void testUserChosenRejectCall() {
+ when(mRoleManagerAdapter.getDefaultCallScreeningApp()).thenReturn(
+ USER_CHOSEN_CALL_SCREENING.getPackageName());
CallScreeningServiceController controller = new CallScreeningServiceController(mContext,
mCallsManager,
mPhoneAccountRegistrar, mParcelableCallUtilsConverter, mLock,
- mSettingsSecureAdapter, mCallerInfoLookupHelper);
+ mSettingsSecureAdapter, mCallerInfoLookupHelper, mAppLabelProxy);
controller.startFilterLookup(mCall, mCallback);
@@ -307,7 +328,7 @@
false, // shouldAddToCallLog
true, // shouldShowNotification
CallLog.Calls.BLOCK_REASON_CALL_SCREENING_SERVICE,
- USER_CHOSEN_CALL_SCREENING.getPackageName(),
+ APP_NAME,
USER_CHOSEN_CALL_SCREENING.flattenToString()
), USER_CHOSEN_CALL_SCREENING.getPackageName());
@@ -322,7 +343,7 @@
false, // shouldAddToCallLog
true, // shouldShowNotification
CallLog.Calls.BLOCK_REASON_CALL_SCREENING_SERVICE, //callBlockReason
- USER_CHOSEN_CALL_SCREENING.getPackageName(), //callScreeningAppName
+ APP_NAME, //callScreeningAppName
USER_CHOSEN_CALL_SCREENING.flattenToString() //callScreeningComponentName
)));
}
diff --git a/tests/src/com/android/server/telecom/tests/CallScreeningServiceFilterTest.java b/tests/src/com/android/server/telecom/tests/CallScreeningServiceFilterTest.java
index fbdd0c0..0fc6666 100644
--- a/tests/src/com/android/server/telecom/tests/CallScreeningServiceFilterTest.java
+++ b/tests/src/com/android/server/telecom/tests/CallScreeningServiceFilterTest.java
@@ -88,17 +88,20 @@
spy(new SettingsSecureAdapterFake());
private static final String PKG_NAME = "com.android.services.telecom.tests";
+ private static final String APP_NAME = "TeleTestApp";
private static final String CLS_NAME = "CallScreeningService";
private static final ComponentName COMPONENT_NAME = new ComponentName(PKG_NAME, CLS_NAME);
private static final String CALL_ID = "u89prgt9ps78y5";
private static final String DEFAULT_DIALER_PACKAGE = "com.android.dialer";
private static final ComponentName CARRIER_DEFINED_CALL_SCREENING = new ComponentName(
"com.android.carrier", "com.android.carrier.callscreeningserviceimpl");
+ private static final String CARRIER_DEFINED_CALL_SCREENING_APP_NAME = "GMob";
private static final ComponentName DEFAULT_DIALER_CALL_SCREENING = new ComponentName(
"com.android.dialer", "com.android.dialer.callscreeningserviceimpl");
+ private static final String DEFAULT_DIALER_APP_NAME = "Dialer";
private static final ComponentName USER_CHOSEN_CALL_SCREENING = new ComponentName(
"com.android.userchosen", "com.android.userchosen.callscreeningserviceimpl");
-
+ private static final String USER_CHOSEN_CALL_SCREENING_APP_NAME = "UserChosen";
private ResolveInfo mResolveInfo;
private static final CallFilteringResult PASS_RESULT = new CallFilteringResult(
@@ -154,7 +157,7 @@
@SmallTest
@Test
public void testNoPackageName() {
- mFilter.startCallScreeningFilter(mCall, mCallback, null);
+ mFilter.startCallScreeningFilter(mCall, mCallback, null, null);
verify(mCallback).onCallScreeningFilterComplete(eq(mCall), eq(PASS_RESULT), eq(null));
}
@@ -163,7 +166,7 @@
public void testNoResolveEntries() {
when(mPackageManager.queryIntentServicesAsUser(nullable(Intent.class), anyInt(), anyInt()))
.thenReturn(Collections.emptyList());
- mFilter.startCallScreeningFilter(mCall, mCallback, PKG_NAME);
+ mFilter.startCallScreeningFilter(mCall, mCallback, PKG_NAME, APP_NAME);
verify(mCallback).onCallScreeningFilterComplete(eq(mCall), eq(PASS_RESULT), eq(PKG_NAME));
}
@@ -171,7 +174,7 @@
@Test
public void testBadResolveEntry() {
mResolveInfo.serviceInfo = null;
- mFilter.startCallScreeningFilter(mCall, mCallback, PKG_NAME);
+ mFilter.startCallScreeningFilter(mCall, mCallback, PKG_NAME, APP_NAME);
verify(mCallback).onCallScreeningFilterComplete(eq(mCall), eq(PASS_RESULT), eq(PKG_NAME));
}
@@ -179,7 +182,7 @@
@Test
public void testPermissionlessFilterService() {
mResolveInfo.serviceInfo.permission = null;
- mFilter.startCallScreeningFilter(mCall, mCallback, PKG_NAME);
+ mFilter.startCallScreeningFilter(mCall, mCallback, PKG_NAME, APP_NAME);
verify(mCallback).onCallScreeningFilterComplete(eq(mCall), eq(PASS_RESULT), eq(PKG_NAME));
}
@@ -188,7 +191,7 @@
public void testContextFailToBind() {
when(mContext.bindServiceAsUser(nullable(Intent.class), nullable(ServiceConnection.class),
anyInt(), eq(UserHandle.CURRENT))).thenReturn(false);
- mFilter.startCallScreeningFilter(mCall, mCallback, PKG_NAME);
+ mFilter.startCallScreeningFilter(mCall, mCallback, PKG_NAME, APP_NAME);
verify(mCallback).onCallScreeningFilterComplete(eq(mCall), eq(PASS_RESULT), eq(PKG_NAME));
}
@@ -197,7 +200,7 @@
public void testExceptionInScreeningService() throws Exception {
doThrow(new RemoteException()).when(mCallScreeningService).screenCall(
nullable(ICallScreeningAdapter.class), nullable(ParcelableCall.class));
- mFilter.startCallScreeningFilter(mCall, mCallback, PKG_NAME);
+ mFilter.startCallScreeningFilter(mCall, mCallback, PKG_NAME, APP_NAME);
ServiceConnection serviceConnection = verifyBindingIntent();
serviceConnection.onServiceConnected(COMPONENT_NAME, mBinder);
verify(mCallback).onCallScreeningFilterComplete(eq(mCall), eq(PASS_RESULT), eq(PKG_NAME));
@@ -206,7 +209,7 @@
@SmallTest
@Test
public void testAllowCall() throws Exception {
- mFilter.startCallScreeningFilter(mCall, mCallback, PKG_NAME);
+ mFilter.startCallScreeningFilter(mCall, mCallback, PKG_NAME, APP_NAME);
ServiceConnection serviceConnection = verifyBindingIntent();
serviceConnection.onServiceConnected(COMPONENT_NAME, mBinder);
ICallScreeningAdapter csAdapter = getCallScreeningAdapter();
@@ -224,7 +227,8 @@
when(mTelecomManager.getDefaultDialerPackage()).thenReturn(DEFAULT_DIALER_PACKAGE);
mFilter.startCallScreeningFilter(mCall, mCallback,
- CARRIER_DEFINED_CALL_SCREENING.getPackageName());
+ CARRIER_DEFINED_CALL_SCREENING.getPackageName(),
+ CARRIER_DEFINED_CALL_SCREENING_APP_NAME);
ServiceConnection serviceConnection = verifyBindingIntent();
serviceConnection.onServiceConnected(COMPONENT_NAME, mBinder);
ICallScreeningAdapter csAdapter = getCallScreeningAdapter();
@@ -240,7 +244,7 @@
false, // shouldAddToCallLog
true, // shouldShowNotification
CallLog.Calls.BLOCK_REASON_CALL_SCREENING_SERVICE, //callBlockReason
- CARRIER_DEFINED_CALL_SCREENING.getPackageName(), //callScreeningAppName
+ CARRIER_DEFINED_CALL_SCREENING_APP_NAME, //callScreeningAppName
CARRIER_DEFINED_CALL_SCREENING.flattenToString() //callScreeningComponentName
)), eq(CARRIER_DEFINED_CALL_SCREENING.getPackageName()));
}
@@ -255,7 +259,8 @@
when(mTelecomManager.getDefaultDialerPackage()).thenReturn(DEFAULT_DIALER_PACKAGE);
mFilter.startCallScreeningFilter(mCall, mCallback,
- DEFAULT_DIALER_CALL_SCREENING.getPackageName());
+ DEFAULT_DIALER_CALL_SCREENING.getPackageName(),
+ DEFAULT_DIALER_APP_NAME);
ServiceConnection serviceConnection = verifyBindingIntent();
serviceConnection.onServiceConnected(COMPONENT_NAME, mBinder);
ICallScreeningAdapter csAdapter = getCallScreeningAdapter();
@@ -271,7 +276,7 @@
true, // shouldAddToCallLog
true, // shouldShowNotification
CallLog.Calls.BLOCK_REASON_CALL_SCREENING_SERVICE, //callBlockReason
- DEFAULT_DIALER_CALL_SCREENING.getPackageName(), //callScreeningAppName
+ DEFAULT_DIALER_APP_NAME, //callScreeningAppName
DEFAULT_DIALER_CALL_SCREENING.flattenToString() //callScreeningComponentName
)), eq(DEFAULT_DIALER_CALL_SCREENING.getPackageName()));
}
@@ -286,7 +291,8 @@
when(mTelecomManager.getDefaultDialerPackage()).thenReturn(DEFAULT_DIALER_PACKAGE);
mFilter.startCallScreeningFilter(mCall, mCallback,
- USER_CHOSEN_CALL_SCREENING.getPackageName());
+ USER_CHOSEN_CALL_SCREENING.getPackageName(),
+ USER_CHOSEN_CALL_SCREENING_APP_NAME);
ServiceConnection serviceConnection = verifyBindingIntent();
serviceConnection.onServiceConnected(COMPONENT_NAME, mBinder);
ICallScreeningAdapter csAdapter = getCallScreeningAdapter();
@@ -302,7 +308,7 @@
true, // shouldAddToCallLog
true, // shouldShowNotification
CallLog.Calls.BLOCK_REASON_CALL_SCREENING_SERVICE, //callBlockReason
- USER_CHOSEN_CALL_SCREENING.getPackageName(), //callScreeningAppName
+ USER_CHOSEN_CALL_SCREENING_APP_NAME, //callScreeningAppName
USER_CHOSEN_CALL_SCREENING.flattenToString() //callScreeningComponentName
)), eq(USER_CHOSEN_CALL_SCREENING.getPackageName()));
}
diff --git a/tests/src/com/android/server/telecom/tests/TelecomSystemTest.java b/tests/src/com/android/server/telecom/tests/TelecomSystemTest.java
index c60a428..1197396 100644
--- a/tests/src/com/android/server/telecom/tests/TelecomSystemTest.java
+++ b/tests/src/com/android/server/telecom/tests/TelecomSystemTest.java
@@ -86,6 +86,7 @@
import com.android.server.telecom.PhoneNumberUtilsAdapterImpl;
import com.android.server.telecom.ProximitySensorManager;
import com.android.server.telecom.ProximitySensorManagerFactory;
+import com.android.server.telecom.RoleManagerAdapter;
import com.android.server.telecom.StatusBarNotifier;
import com.android.server.telecom.TelecomSystem;
import com.android.server.telecom.Timeouts;
@@ -104,6 +105,7 @@
import java.io.File;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -213,6 +215,7 @@
@Mock AsyncRingtonePlayer mAsyncRingtonePlayer;
@Mock IncomingCallNotifier mIncomingCallNotifier;
@Mock ClockProxy mClockProxy;
+ @Mock RoleManagerAdapter mRoleManagerAdapter;
final ComponentName mInCallServiceComponentNameX =
new ComponentName(
@@ -434,6 +437,9 @@
mClockProxy = mock(ClockProxy.class);
when(mClockProxy.currentTimeMillis()).thenReturn(TEST_CREATE_TIME);
when(mClockProxy.elapsedRealtime()).thenReturn(TEST_CREATE_ELAPSED_TIME);
+ when(mRoleManagerAdapter.getCallCompanionApps()).thenReturn(Collections.emptyList());
+ when(mRoleManagerAdapter.getDefaultCallScreeningApp()).thenReturn(null);
+ when(mRoleManagerAdapter.getCarModeDialerApp()).thenReturn(null);
mTelecomSystem = new TelecomSystem(
mComponentContextFixture.getTestDouble(),
(context, phoneAccountRegistrar, defaultDialerCache) -> mMissedCallNotifier,
@@ -469,7 +475,8 @@
CallAudioRouteStateMachine.EARPIECE_FORCE_ENABLED);
}
},
- mClockProxy);
+ mClockProxy,
+ mRoleManagerAdapter);
mComponentContextFixture.setTelecomManager(new TelecomManager(
mComponentContextFixture.getTestDouble(),