aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHyosun Kim <hyosunkim@google.com>2022-04-14 00:50:55 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2022-04-14 00:50:55 +0000
commitf5d90cd6626fade981ea3b61da048ff4c5c43c0e (patch)
treeddbc44814d4a87def0b233fa8b24b008c7520cb8
parent148dbf8421e68f5ce03d6077a455dbff7d374907 (diff)
parentfe94689e8c85a4607252a1cee255af7fa7f1cdd4 (diff)
downloadims-f5d90cd6626fade981ea3b61da048ff4c5c43c0e.tar.gz
Merge "Even though the state of the ImsFeature is set to STATE_UNAVAILABLE, fixed CapabilityCallbackManager#unregisterCallback to complete successfully." am: b0d8ff36d4 am: fe94689e8c
Original change: https://android-review.googlesource.com/c/platform/frameworks/opt/net/ims/+/2063547 Change-Id: I1600d8b831037aab532f93c6ff1fc1147a9d6264 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--src/java/com/android/ims/MmTelFeatureConnection.java9
-rw-r--r--tests/src/com/android/ims/MmTelFeatureConnectionTest.java92
2 files changed, 90 insertions, 11 deletions
diff --git a/src/java/com/android/ims/MmTelFeatureConnection.java b/src/java/com/android/ims/MmTelFeatureConnection.java
index 333dc560..cd8c3f15 100644
--- a/src/java/com/android/ims/MmTelFeatureConnection.java
+++ b/src/java/com/android/ims/MmTelFeatureConnection.java
@@ -135,15 +135,12 @@ public class MmTelFeatureConnection extends FeatureConnection {
public void unregisterCallback(IImsCapabilityCallback localCallback) {
IImsMmTelFeature binder;
synchronized (mLock) {
- try {
- checkServiceIsReady();
- binder = getServiceInterface(mBinder);
- } catch (RemoteException e) {
- // binder is null
+ if (!isBinderAlive()) {
Log.w(TAG + " [" + mSlotId + "]", "CapabilityCallbackManager, unregister:"
- + " couldn't get binder.");
+ + " binder is not alive");
return;
}
+ binder = getServiceInterface(mBinder);
}
if (binder != null) {
try {
diff --git a/tests/src/com/android/ims/MmTelFeatureConnectionTest.java b/tests/src/com/android/ims/MmTelFeatureConnectionTest.java
index eb384452..f1148384 100644
--- a/tests/src/com/android/ims/MmTelFeatureConnectionTest.java
+++ b/tests/src/com/android/ims/MmTelFeatureConnectionTest.java
@@ -18,13 +18,13 @@ package com.android.ims;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.Mockito.when;
import android.content.Context;
import android.os.Binder;
import android.os.IBinder;
import android.os.IInterface;
+import android.telephony.ims.feature.ImsFeature;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;
@@ -33,6 +33,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Mock;
import java.util.ArrayList;
import java.util.List;
@@ -52,33 +53,56 @@ public class MmTelFeatureConnectionTest extends ImsTestBase {
ImsCallbackAdapterManager<TestCallback> {
List<TestCallback> mCallbacks = new ArrayList<>();
+ FeatureConnection mFeatureConnection;
- CallbackManagerTest(Context context, Object lock) {
- super(context, lock, 0 /*slotId*/, 1 /*subId*/);
+ CallbackManagerTest(Context context, Object lock, FeatureConnection featureConnection) {
+ super(context, lock, SLOT_ID, SUB_ID);
+ mFeatureConnection = featureConnection;
}
// A callback has been registered. Register that callback with the MmTelFeature.
@Override
public void registerCallback(TestCallback localCallback) {
+ if (!isBinderReady()) {
+ return;
+ }
mCallbacks.add(localCallback);
}
// A callback has been removed, unregister that callback with the MmTelFeature.
@Override
public void unregisterCallback(TestCallback localCallback) {
+ if (!mFeatureConnection.isBinderAlive()) {
+ return;
+ }
mCallbacks.remove(localCallback);
}
public boolean doesCallbackExist(TestCallback callback) {
return mCallbacks.contains(callback);
}
+
+ public boolean isBinderReady() {
+ return mFeatureConnection.isBinderAlive()
+ && mFeatureConnection.getFeatureState() == ImsFeature.STATE_READY;
+ }
}
+
private CallbackManagerTest mCallbackManagerUT;
+ @Mock
+ FeatureConnection mFeatureConnection;
+
+ public static final int SUB_ID = 1;
+ public static final int SLOT_ID = 0;
+
@Before
public void setUp() throws Exception {
super.setUp();
- mCallbackManagerUT = new CallbackManagerTest(mContext, this);
+
+ when(mFeatureConnection.isBinderAlive()).thenReturn(true);
+ when(mFeatureConnection.getFeatureState()).thenReturn(ImsFeature.STATE_READY);
+ mCallbackManagerUT = new CallbackManagerTest(mContext, this, mFeatureConnection);
}
@After
@@ -154,4 +178,62 @@ public class MmTelFeatureConnectionTest extends ImsTestBase {
assertFalse(mCallbackManagerUT.doesCallbackExist(testCallback1));
assertFalse(mCallbackManagerUT.doesCallbackExist(testCallback2));
}
+
+
+ /**
+ * UnregisterCallback is success After ImsFeatureState changed to STATE_UNAVAILABLE.
+ */
+ @Test
+ @SmallTest
+ public void testCallbackAdapter_removeCallbackSuccessAfterImsFeatureStateChangeToUnavailable()
+ throws Exception {
+ TestCallback testCallback1 = new TestCallback();
+ mCallbackManagerUT.addCallback(testCallback1);
+ assertTrue(mCallbackManagerUT.doesCallbackExist(testCallback1));
+ mCallbackManagerUT.removeCallback(testCallback1);
+ assertFalse(mCallbackManagerUT.doesCallbackExist(testCallback1));
+
+ TestCallback testCallback2 = new TestCallback();
+ mCallbackManagerUT.addCallback(testCallback2);
+ assertTrue(mCallbackManagerUT.doesCallbackExist(testCallback2));
+ assertTrue(mCallbackManagerUT.isBinderReady());
+ when(mFeatureConnection.getFeatureState()).thenReturn(ImsFeature.STATE_UNAVAILABLE);
+ assertFalse(mCallbackManagerUT.isBinderReady());
+ mCallbackManagerUT.removeCallback(testCallback2);
+ assertFalse(mCallbackManagerUT.doesCallbackExist(testCallback2));
+ }
+
+ /**
+ * UnregisterCallback is failed After binder isn't alive.
+ */
+ @Test
+ @SmallTest
+ public void testCallbackAdapter_removeCallbackFailedAfterBinderIsNotAlive() throws Exception {
+ TestCallback testCallback1 = new TestCallback();
+ mCallbackManagerUT.addCallback(testCallback1);
+ assertTrue(mCallbackManagerUT.doesCallbackExist(testCallback1));
+
+ when(mFeatureConnection.isBinderAlive()).thenReturn(false);
+ mCallbackManagerUT.removeCallback(testCallback1);
+ assertTrue(mCallbackManagerUT.doesCallbackExist(testCallback1));
+ }
+
+ /**
+ * RegisterCallback is failed After binder isn't ready.
+ */
+ @Test
+ @SmallTest
+ public void testCallbackAdapter_addCallbackFailedAfterBinderIsNotReady() throws Exception {
+ when(mFeatureConnection.isBinderAlive()).thenReturn(false);
+ assertFalse(mCallbackManagerUT.isBinderReady());
+ TestCallback testCallback1 = new TestCallback();
+ mCallbackManagerUT.addCallback(testCallback1);
+ assertFalse(mCallbackManagerUT.doesCallbackExist(testCallback1));
+
+ when(mFeatureConnection.isBinderAlive()).thenReturn(true);
+ when(mFeatureConnection.getFeatureState()).thenReturn(ImsFeature.STATE_UNAVAILABLE);
+ assertFalse(mCallbackManagerUT.isBinderReady());
+ mCallbackManagerUT.addCallback(testCallback1);
+ assertFalse(mCallbackManagerUT.doesCallbackExist(testCallback1));
+ }
}