Fix crash when service unbinding exception happens.
If the call screening service haven't been registered, trying to unbind
it will make the device crash. Wrap the unbinding process in a try-catch
block to avoid this crash.
Bug: 161952276
Test: atest TelecomUnitTests:CallScreeningServiceFilterTest
Change-Id: Ic4d8823efc4f91a866e6d5d72a0a94cc3438d232
diff --git a/src/com/android/server/telecom/callfiltering/CallScreeningServiceFilter.java b/src/com/android/server/telecom/callfiltering/CallScreeningServiceFilter.java
index 1e52c5a..486cd8d 100644
--- a/src/com/android/server/telecom/callfiltering/CallScreeningServiceFilter.java
+++ b/src/com/android/server/telecom/callfiltering/CallScreeningServiceFilter.java
@@ -289,7 +289,12 @@
public void unbindCallScreeningService() {
if (mConnection != null) {
- mContext.unbindService(mConnection);
+ try {
+ mContext.unbindService(mConnection);
+ } catch (IllegalArgumentException e) {
+ Log.i(this, "Exception when unbind service %s : %s", mConnection,
+ e.getMessage());
+ }
}
mConnection = null;
}
diff --git a/tests/src/com/android/server/telecom/tests/CallScreeningServiceFilterTest.java b/tests/src/com/android/server/telecom/tests/CallScreeningServiceFilterTest.java
index 1345c01..c7b3a7e 100644
--- a/tests/src/com/android/server/telecom/tests/CallScreeningServiceFilterTest.java
+++ b/tests/src/com/android/server/telecom/tests/CallScreeningServiceFilterTest.java
@@ -23,6 +23,7 @@
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -211,6 +212,19 @@
@SmallTest
@Test
+ public void testUnbindingException() {
+ // Make sure that exceptions when unbinding won't make the device crash.
+ doThrow(new IllegalArgumentException()).when(mContext)
+ .unbindService(nullable(ServiceConnection.class));
+ CallScreeningServiceFilter filter = new CallScreeningServiceFilter(mCall, PKG_NAME,
+ CallScreeningServiceFilter.PACKAGE_TYPE_CARRIER, mContext, mCallsManager,
+ mAppLabelProxy, mParcelableCallUtilsConverter);
+ filter.startFilterLookup(inputResult);
+ filter.unbindCallScreeningService();
+ }
+
+ @SmallTest
+ @Test
public void testAllowCall() throws Exception {
CallScreeningServiceFilter filter = new CallScreeningServiceFilter(mCall, PKG_NAME,
CallScreeningServiceFilter.PACKAGE_TYPE_CARRIER, mContext, mCallsManager,