diff options
author | hyosun <hyosunkim@google.com> | 2022-04-11 14:41:16 +0000 |
---|---|---|
committer | hyosun <hyosunkim@google.com> | 2022-04-12 03:24:29 +0000 |
commit | 6d19fa7df288debda7ee4a298db83eeb89ef94c0 (patch) | |
tree | 5d648cec30966010b00836934ed2682bc1ec0f11 | |
parent | 7e286ec2d1af7a21ed0a928ba1f449637500a4a8 (diff) | |
download | ims-6d19fa7df288debda7ee4a298db83eeb89ef94c0.tar.gz |
Even though the state of the ImsFeature is set to STATE_UNAVAILABLE, fixed CapabilityCallbackManager#unregisterCallback to complete successfully.
Change CapabilityCallbackManager#unregisterCallback to use #isBinderAlive instead of using #checkServiceIsReady.
Bug: 225259107
Test: atest ImsCommonTests
Change-Id: Ie5fdc093701a6a1602372a80125629e96d7775bf
-rw-r--r-- | src/java/com/android/ims/MmTelFeatureConnection.java | 9 | ||||
-rw-r--r-- | tests/src/com/android/ims/MmTelFeatureConnectionTest.java | 92 |
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)); + } } |