diff --git a/src/com/android/server/telecom/CallsManager.java b/src/com/android/server/telecom/CallsManager.java index 5e46e5a08..7ff4e514b 100644 --- a/src/com/android/server/telecom/CallsManager.java +++ b/src/com/android/server/telecom/CallsManager.java @@ -23,6 +23,8 @@ import android.content.BroadcastReceiver; 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 @@ public class CallsManager extends Call.ListenerBase 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 7eb8f0e60..925efae55 100644 --- a/src/com/android/server/telecom/ParcelableCallUtils.java +++ b/src/com/android/server/telecom/ParcelableCallUtils.java @@ -18,11 +18,13 @@ package com.android.server.telecom; 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 @@ public class ParcelableCallUtils { return ParcelableCallUtils.toParcelableCall( call, includeVideoProvider, phoneAccountRegistrar, false, false); } + + public ParcelableCall toParcelableCallForScreening(Call call) { + return ParcelableCallUtils.toParcelableCallForScreening(call); + } } /** @@ -191,6 +197,53 @@ public class ParcelableCallUtils { call.getCreationTimeMillis()); } + /** + * Creates a ParcelableCall with the bare minimum properties required for a + * {@link android.telecom.CallScreeningService}. We ONLY expose the following: + * + * 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 ffa60354c..2daba61d9 100644 --- a/src/com/android/server/telecom/TelecomSystem.java +++ b/src/com/android/server/telecom/TelecomSystem.java @@ -196,7 +196,8 @@ public class TelecomSystem { 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 @@ public class TelecomSystem { } }; - 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 40bf39845..3ca95fffb 100644 --- a/src/com/android/server/telecom/callfiltering/CallScreeningServiceController.java +++ b/src/com/android/server/telecom/callfiltering/CallScreeningServiceController.java @@ -18,6 +18,7 @@ package com.android.server.telecom.callfiltering; 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 @@ import com.android.server.telecom.TelecomSystem; 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 @@ public class CallScreeningServiceController implements IncomingCallFilter.CallFi 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 @@ public class CallScreeningServiceController implements IncomingCallFilter.CallFi 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 @@ public class CallScreeningServiceController implements IncomingCallFilter.CallFi mTelecomLock = lock; mSettingsSecureAdapter = settingsSecureAdapter; mCallerInfoLookupHelper = callerInfoLookupHelper; + mAppLabelProxy = appLabelProxy; } @Override @@ -119,8 +131,8 @@ public class CallScreeningServiceController implements IncomingCallFilter.CallFi } @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 @@ public class CallScreeningServiceController implements IncomingCallFilter.CallFi bindDefaultDialerAndUserChosenService(); } else { createCallScreeningServiceFilter().startCallScreeningFilter(mCall, this, - carrierPackageName); + carrierPackageName, mAppLabelProxy.getAppLabel(carrierPackageName)); } // Carrier filtering timed out @@ -176,7 +188,8 @@ public class CallScreeningServiceController implements IncomingCallFilter.CallFi mIsDefaultDialerFinished = true; } else { createCallScreeningServiceFilter().startCallScreeningFilter(mCall, - CallScreeningServiceController.this, dialerPackageName); + CallScreeningServiceController.this, dialerPackageName, + mAppLabelProxy.getAppLabel(dialerPackageName)); } String userChosenPackageName = getUserChosenPackageName(); @@ -184,7 +197,8 @@ public class CallScreeningServiceController implements IncomingCallFilter.CallFi mIsUserChosenFinished = true; } else { createCallScreeningServiceFilter().startCallScreeningFilter(mCall, - CallScreeningServiceController.this, userChosenPackageName); + CallScreeningServiceController.this, userChosenPackageName, + mAppLabelProxy.getAppLabel(userChosenPackageName)); } if (mIsDefaultDialerFinished && mIsUserChosenFinished) { @@ -250,15 +264,6 @@ public class CallScreeningServiceController implements IncomingCallFilter.CallFi } 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 f0832e625..64e225a36 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.CallLog; 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 @@ public class CallScreeningServiceFilter { 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 @@ public class CallScreeningServiceFilter { } 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 @@ public class CallScreeningServiceFilter { 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 @@ public class CallScreeningServiceFilter { TelecomSystem.SyncRoot lock, SettingsSecureAdapter settingsSecureAdapter) { mContext = context; - mPhoneAccountRegistrar = phoneAccountRegistrar; mCallsManager = callsManager; mParcelableCallUtilsConverter = parcelableCallUtilsConverter; mTelecomLock = lock; @@ -189,7 +189,8 @@ public class CallScreeningServiceFilter { 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 @@ public class CallScreeningServiceFilter { 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 @@ public class CallScreeningServiceFilter { 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 153ddc435..1beae2bc5 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.ProximitySensorManagerFactory; 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 class TelecomService extends Service implements TelecomSystem.Component { 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 02443ba4f..9cb199220 100644 --- a/testapps/AndroidManifest.xml +++ b/testapps/AndroidManifest.xml @@ -238,5 +238,19 @@ + + + + + + + + + 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 000000000..05ba500e0 --- /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 000000000..81a469e5c --- /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 324375b5b..0004035d6 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.CallerInfoLookupHelper; 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 @@ public class CallScreeningServiceControllerTest extends TelecomTestCase { @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 @@ public class CallScreeningServiceControllerTest extends TelecomTestCase { @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 @@ public class CallScreeningServiceControllerTest extends TelecomTestCase { 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 @@ public class CallScreeningServiceControllerTest extends TelecomTestCase { @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 @@ public class CallScreeningServiceControllerTest extends TelecomTestCase { @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 @@ public class CallScreeningServiceControllerTest extends TelecomTestCase { CallScreeningServiceController controller = new CallScreeningServiceController(mContext, mCallsManager, mPhoneAccountRegistrar, mParcelableCallUtilsConverter, mLock, - mSettingsSecureAdapter, mCallerInfoLookupHelper); + mSettingsSecureAdapter, mCallerInfoLookupHelper, mAppLabelProxy); controller.startFilterLookup(mCall, mCallback); @@ -207,7 +224,7 @@ public class CallScreeningServiceControllerTest extends TelecomTestCase { CallScreeningServiceController controller = new CallScreeningServiceController(mContext, mCallsManager, mPhoneAccountRegistrar, mParcelableCallUtilsConverter, mLock, - mSettingsSecureAdapter, mCallerInfoLookupHelper); + mSettingsSecureAdapter, mCallerInfoLookupHelper, mAppLabelProxy); controller.startFilterLookup(mCall, mCallback); @@ -217,7 +234,7 @@ public class CallScreeningServiceControllerTest extends TelecomTestCase { 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 @@ public class CallScreeningServiceControllerTest extends TelecomTestCase { 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 @@ public class CallScreeningServiceControllerTest extends TelecomTestCase { @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 @@ public class CallScreeningServiceControllerTest extends TelecomTestCase { 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 @@ public class CallScreeningServiceControllerTest extends TelecomTestCase { 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 @@ public class CallScreeningServiceControllerTest extends TelecomTestCase { @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 @@ public class CallScreeningServiceControllerTest extends TelecomTestCase { 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 @@ public class CallScreeningServiceControllerTest extends TelecomTestCase { 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 fbdd0c0cd..0fc66668f 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 @@ public class CallScreeningServiceFilterTest extends TelecomTestCase { 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 @@ public class CallScreeningServiceFilterTest extends TelecomTestCase { @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 class CallScreeningServiceFilterTest extends TelecomTestCase { 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 @@ public class CallScreeningServiceFilterTest extends TelecomTestCase { @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 @@ public class CallScreeningServiceFilterTest extends TelecomTestCase { @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 class CallScreeningServiceFilterTest extends TelecomTestCase { 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 class CallScreeningServiceFilterTest extends TelecomTestCase { 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 @@ public class CallScreeningServiceFilterTest extends TelecomTestCase { @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 @@ public class CallScreeningServiceFilterTest extends TelecomTestCase { 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 @@ public class CallScreeningServiceFilterTest extends TelecomTestCase { 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 @@ public class CallScreeningServiceFilterTest extends TelecomTestCase { 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 @@ public class CallScreeningServiceFilterTest extends TelecomTestCase { 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 @@ public class CallScreeningServiceFilterTest extends TelecomTestCase { 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 @@ public class CallScreeningServiceFilterTest extends TelecomTestCase { 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 c60a4288f..119739621 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.PhoneNumberUtilsAdapter; 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 org.mockito.stubbing.Answer; 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 @@ public class TelecomSystemTest extends TelecomTestCase { @Mock AsyncRingtonePlayer mAsyncRingtonePlayer; @Mock IncomingCallNotifier mIncomingCallNotifier; @Mock ClockProxy mClockProxy; + @Mock RoleManagerAdapter mRoleManagerAdapter; final ComponentName mInCallServiceComponentNameX = new ComponentName( @@ -434,6 +437,9 @@ public class TelecomSystemTest extends TelecomTestCase { 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 @@ public class TelecomSystemTest extends TelecomTestCase { CallAudioRouteStateMachine.EARPIECE_FORCE_ENABLED); } }, - mClockProxy); + mClockProxy, + mRoleManagerAdapter); mComponentContextFixture.setTelecomManager(new TelecomManager( mComponentContextFixture.getTestDouble(),