Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dfe5bb2f authored by Brad Ebinger's avatar Brad Ebinger Committed by Gerrit Code Review
Browse files

Merge "Notify ImsService Status Callbacks correctly"

parents 5eb93305 675f8030
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -533,15 +533,18 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {

        synchronized(Phone.lockForRadioTechnologyChange) {
            IntentFilter filter = new IntentFilter();
            ImsManager imsManager = ImsManager.getInstance(mContext, getPhoneId());
            // Don't listen to deprecated intents using the new dynamic binding.
            if (imsManager != null && !imsManager.isDynamicBinding()) {
                filter.addAction(ImsManager.ACTION_IMS_SERVICE_UP);
                filter.addAction(ImsManager.ACTION_IMS_SERVICE_DOWN);
            }
            filter.addAction(ImsConfig.ACTION_IMS_CONFIG_CHANGED);
            mContext.registerReceiver(mImsIntentReceiver, filter);

            // Monitor IMS service - but first poll to see if already up (could miss
            // intent). Also, when using new ImsResolver APIs, the service will be available soon,
            // so start trying to bind.
            ImsManager imsManager = ImsManager.getInstance(mContext, getPhoneId());
            if (imsManager != null) {
                // If it is dynamic binding, kick off ImsPhone creation now instead of waiting for
                // the service to be available.
+10 −5
Original line number Diff line number Diff line
@@ -284,7 +284,7 @@ public class ImsServiceController {
    }

    /**
     * Calls {@link IImsServiceController#removeImsFeature(int, int)} on all features that the
     * Calls {@link IImsServiceController#removeImsFeature} on all features that the
     * ImsService supports and then unbinds the service.
     */
    public void unbind() throws RemoteException {
@@ -459,7 +459,15 @@ public class ImsServiceController {
            Log.w(LOG_TAG, "removeImsServiceFeature called with null values.");
            return;
        }
        mIImsServiceController.removeImsFeature(featurePair.first, featurePair.second);
        ImsFeatureStatusCallback callbackToRemove = mFeatureStatusCallbacks.stream().filter(c ->
                c.mSlotId == featurePair.first && c.mFeatureType == featurePair.second)
                .findFirst().orElse(null);
        // Remove status callbacks from list.
        if (callbackToRemove != null) {
            mFeatureStatusCallbacks.remove(callbackToRemove);
        }
        mIImsServiceController.removeImsFeature(featurePair.first, featurePair.second,
                (callbackToRemove != null ? callbackToRemove.getCallback() : null));
        // Signal ImsResolver to change supported ImsFeatures for this ImsServiceController
        mCallbacks.imsServiceFeatureRemoved(featurePair.first, featurePair.second, this);
        // Send callback to ImsServiceProxy to change supported ImsFeatures
@@ -467,9 +475,6 @@ public class ImsServiceController {
        // ImsManager requests the ImsService while it is being removed in ImsResolver, this
        // callback will clean it up after.
        sendImsFeatureRemovedCallback(featurePair.first, featurePair.second);
        // Remove status callbacks from list.
        mFeatureStatusCallbacks.removeIf(c -> c.mSlotId == featurePair.first
                && c.mFeatureType == featurePair.second);
    }

    private void notifyAllFeaturesRemoved() {
+8 −2
Original line number Diff line number Diff line
@@ -43,6 +43,8 @@ public class ImsFeatureTest {
    @Mock
    private IImsFeatureStatusCallback mTestStatusCallback;
    @Mock
    private IImsFeatureStatusCallback mTestStatusCallback2;
    @Mock
    private ImsFeature.INotifyFeatureRemoved mTestRemovedCallback;

    private class TestImsFeature extends ImsFeature {
@@ -73,19 +75,23 @@ public class ImsFeatureTest {
    @Test
    @SmallTest
    public void testSetCallbackAndNotify() throws Exception {
        mTestImsService.setImsFeatureStatusCallback(mTestStatusCallback);
        mTestImsService.addImsFeatureStatusCallback(mTestStatusCallback);
        mTestImsService.addImsFeatureStatusCallback(mTestStatusCallback2);

        verify(mTestStatusCallback).notifyImsFeatureStatus(eq(ImsFeature.STATE_NOT_AVAILABLE));
        verify(mTestStatusCallback2).notifyImsFeatureStatus(eq(ImsFeature.STATE_NOT_AVAILABLE));
    }

    @Test
    @SmallTest
    public void testSetFeatureAndCheckCallback() throws Exception {
        mTestImsService.setImsFeatureStatusCallback(mTestStatusCallback);
        mTestImsService.addImsFeatureStatusCallback(mTestStatusCallback);
        mTestImsService.addImsFeatureStatusCallback(mTestStatusCallback2);

        mTestImsService.testSetFeatureState(ImsFeature.STATE_READY);

        verify(mTestStatusCallback).notifyImsFeatureStatus(eq(ImsFeature.STATE_READY));
        verify(mTestStatusCallback2).notifyImsFeatureStatus(eq(ImsFeature.STATE_READY));
        assertEquals(ImsFeature.STATE_READY, mTestImsService.getFeatureState());
    }

+9 −33
Original line number Diff line number Diff line
@@ -98,7 +98,7 @@ public class ImsServiceTest {
                mTestImsService.getImsFeatureFromType(features, ImsFeature.MMTEL));
        // Verify that upon creating a feature, we assign the callback and get the set feature state
        // when querying it.
        verify(mTestImsService.mSpyMMTelFeature).setImsFeatureStatusCallback(eq(mTestCallback));
        verify(mTestImsService.mSpyMMTelFeature).addImsFeatureStatusCallback(eq(mTestCallback));
        assertEquals(ImsFeature.STATE_READY, mTestImsServiceBinder.getFeatureStatus(TEST_SLOT_0,
                ImsFeature.MMTEL));
    }
@@ -108,10 +108,10 @@ public class ImsServiceTest {
    public void testRemoveMMTelFeature() throws RemoteException {
        mTestImsServiceBinder.createImsFeature(TEST_SLOT_0, ImsFeature.MMTEL, mTestCallback);

        mTestImsServiceBinder.removeImsFeature(TEST_SLOT_0, ImsFeature.MMTEL);
        mTestImsServiceBinder.removeImsFeature(TEST_SLOT_0, ImsFeature.MMTEL, mTestCallback);

        verify(mTestImsService.mSpyMMTelFeature).notifyFeatureRemoved(eq(0));
        verify(mTestImsService.mSpyMMTelFeature).setImsFeatureStatusCallback(null);
        verify(mTestImsService.mSpyMMTelFeature).removeImsFeatureStatusCallback(mTestCallback);
        SparseArray<ImsFeature> features = mTestImsService.getImsFeatureMap(TEST_SLOT_0);
        assertNull(mTestImsService.getImsFeatureFromType(features, ImsFeature.MMTEL));
    }
@@ -184,14 +184,11 @@ public class ImsServiceTest {
        mTestImsService.mSpyMMTelFeature.sendSetFeatureState(ImsFeature.STATE_READY);

        ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
        verify(mMockContext, times(2)).sendBroadcast(intentCaptor.capture());
        verify(mMockContext).sendBroadcast(intentCaptor.capture());
        try {
            // IMS_SERVICE_DOWN is always sent when createImsFeature completes
            assertNotNull(intentCaptor.getAllValues().get(0));
            verifyServiceDownSent(intentCaptor.getAllValues().get(0));
            // Verify IMS_SERVICE_UP is sent
            assertNotNull(intentCaptor.getAllValues().get(1));
            verifyServiceUpSent(intentCaptor.getAllValues().get(1));
            assertNotNull(intentCaptor.getValue());
            verifyServiceUpSent(intentCaptor.getValue());
        } catch (IndexOutOfBoundsException e) {
            fail("Did not receive all intents");
        }
@@ -209,37 +206,16 @@ public class ImsServiceTest {
        mTestImsService.mSpyMMTelFeature.sendSetFeatureState(ImsFeature.STATE_INITIALIZING);

        ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
        verify(mMockContext, times(2)).sendBroadcast(intentCaptor.capture());
        verify(mMockContext).sendBroadcast(intentCaptor.capture());
        try {
            // IMS_SERVICE_DOWN is always sent when createImsFeature completes.
            assertNotNull(intentCaptor.getAllValues().get(0));
            verifyServiceDownSent(intentCaptor.getAllValues().get(0));
            // IMS_SERVICE_DOWN is sent when the service is STATE_INITIALIZING.
            assertNotNull(intentCaptor.getAllValues().get(1));
            verifyServiceDownSent(intentCaptor.getAllValues().get(1));
            assertNotNull(intentCaptor.getValue());
            verifyServiceDownSent(intentCaptor.getValue());
        } catch (IndexOutOfBoundsException e) {
            fail("Did not receive all intents");
        }
    }

    /**
     * Tests that the new ImsService still sends the IMS_SERVICE_DOWN broadcast when the feature is
     * set to not available.
     */
    @Test
    @SmallTest
    public void testImsServiceDownSentCompatNotAvailable() throws RemoteException {
        mTestImsServiceBinder.createImsFeature(TEST_SLOT_0, ImsFeature.MMTEL, mTestCallback);

        // The ImsService will send the STATE_NOT_AVAILABLE status as soon as the feature is
        // created.

        ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
        verify(mMockContext).sendBroadcast(intentCaptor.capture());
        assertNotNull(intentCaptor.getValue());
        verifyServiceDownSent(intentCaptor.getValue());
    }

    private void verifyServiceDownSent(Intent testIntent) {
        assertEquals(ImsManager.ACTION_IMS_SERVICE_DOWN, testIntent.getAction());
        assertEquals(TEST_SLOT_0, testIntent.getIntExtra(ImsManager.EXTRA_PHONE_ID, -1));
+2 −1
Original line number Diff line number Diff line
@@ -52,7 +52,8 @@ public class TestImsServiceControllerAdapter {
        }

        @Override
        public void removeImsFeature(int slotId, int feature) throws RemoteException {
        public void removeImsFeature(int slotId, int feature, IImsFeatureStatusCallback c)
                throws RemoteException {
            TestImsServiceControllerAdapter.this.removeImsFeature(slotId, feature);
        }