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

Commit 6c3b2891 authored by Brad Ebinger's avatar Brad Ebinger
Browse files

Integrate Registration APIs

1) Pipe ImsRegistration interface through ImsResolver
so that ImsManager can access the ImsService's
Registration APIs.

2) Tear down ImsManager when the ImsService becomes
unavailable and recreate it with the new ImsService.

3) Update namespaces.

Bug: 63987047
Test: Manual, Telephony unit tests
Change-Id: I1e07e15bc8effc06a4687183f0e67f4e253656ab
parent b1b4a4ea
Loading
Loading
Loading
Loading
+23 −2
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.internal.telephony.ims;

import android.Manifest;
import android.annotation.Nullable;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
@@ -40,6 +41,7 @@ import android.util.SparseArray;

import com.android.ims.internal.IImsMMTelFeature;
import com.android.ims.internal.IImsRcsFeature;
import com.android.ims.internal.IImsRegistration;
import com.android.ims.internal.IImsServiceFeatureCallback;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.PhoneConstants;
@@ -344,9 +346,20 @@ public class ImsResolver implements ImsServiceController.ImsServiceControllerCal
        return (controller != null) ? controller.getRcsFeature(slotId) : null;
    }

    /**
     * Returns the ImsRegistration structure associated with the slotId and feature specified.
     */
    public @Nullable IImsRegistration getImsRegistration(int slotId, int feature)
            throws RemoteException {
        ImsServiceController controller = getImsServiceController(slotId, feature);
        if (controller != null) {
            return controller.getRegistration(slotId);
        }
        return null;
    }

    @VisibleForTesting
    public ImsServiceController getImsServiceControllerAndListen(int slotId, int feature,
            IImsServiceFeatureCallback callback) {
    public ImsServiceController getImsServiceController(int slotId, int feature) {
        if (slotId < 0 || slotId >= mNumSlots) {
            return null;
        }
@@ -358,6 +371,14 @@ public class ImsResolver implements ImsServiceController.ImsServiceControllerCal
            }
            controller = services.get(feature);
        }
        return controller;
    }

    @VisibleForTesting
    public ImsServiceController getImsServiceControllerAndListen(int slotId, int feature,
            IImsServiceFeatureCallback callback) {
        ImsServiceController controller = getImsServiceController(slotId, feature);

        if (controller != null) {
            controller.addImsServiceFeatureListener(callback);
            return controller;
+12 −4
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.util.Pair;
import com.android.ims.internal.IImsFeatureStatusCallback;
import com.android.ims.internal.IImsMMTelFeature;
import com.android.ims.internal.IImsRcsFeature;
import com.android.ims.internal.IImsRegistration;
import com.android.ims.internal.IImsServiceController;
import com.android.ims.internal.IImsServiceFeatureCallback;
import com.android.internal.annotations.VisibleForTesting;
@@ -366,10 +367,8 @@ public class ImsServiceController {
    }

    /**
     * Finds the difference between the set of features that the ImsService has active and the new
     * set defined in newImsFeatures. For every feature that is added,
     * {@link IImsServiceController#createImsFeature} is called on the service. For every ImsFeature
     * that is removed, {@link IImsServiceController#removeImsFeature} is called.
     * For every feature that is added, the service calls the associated create. For every
     * ImsFeature that is removed, {@link IImsServiceController#removeImsFeature} is called.
     */
    public void changeImsServiceFeatures(HashSet<Pair<Integer, Integer>> newImsFeatures)
            throws RemoteException {
@@ -466,6 +465,15 @@ public class ImsServiceController {
        }
    }

    /**
     * @return the IImsRegistration that corresponds to the slot id specified.
     */
    public IImsRegistration getRegistration(int slotId) throws RemoteException {
        synchronized (mLock) {
            return mIImsServiceController.getRegistration(slotId);
        }
    }

    private void removeImsServiceFeatureListener() {
        synchronized (mLock) {
            mImsStatusCallbacks.clear();
+35 −23
Original line number Diff line number Diff line
@@ -665,7 +665,10 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
    };

    // Callback fires when ImsManager MMTel Feature changes state
    private ImsServiceProxy.INotifyStatusChanged mNotifyStatusChangedCallback = () -> {
    private ImsServiceProxy.IFeatureUpdate mNotifyStatusChangedCallback =
            new ImsServiceProxy.IFeatureUpdate() {
                @Override
                public void notifyStateChanged() {
                    try {
                        int status = mImsManager.getImsServiceStatus();
                        log("Status Changed: " + status);
@@ -688,6 +691,12 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
                        // Could not get the ImsService, retry!
                        retryGetImsService();
                    }
                }

                @Override
                public void notifyUnavailable() {
                    retryGetImsService();
                }
            };

    @VisibleForTesting
@@ -794,7 +803,7 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
        mImsManager.addNotifyStatusChangedCallbackIfAvailable(mNotifyStatusChangedCallback);
        // Wait for ImsService.STATE_READY to start listening for calls.
        // Call the callback right away for compatibility with older devices that do not use states.
        mNotifyStatusChangedCallback.notifyStatusChanged();
        mNotifyStatusChangedCallback.notifyStateChanged();
    }

    private void startListeningForCalls() throws ImsException {
@@ -3301,6 +3310,9 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
        if (mImsManager.isServiceAvailable()) {
            return;
        }
        // remove callback so we do not receive updates from old ImsServiceProxy when switching
        // between ImsServices.
        mImsManager.removeNotifyStatusChangedCallback(mNotifyStatusChangedCallback);
        //Leave mImsManager as null, then CallStateException will be thrown when dialing
        mImsManager = null;
        // Exponential backoff during retry, limited to 32 seconds.
+30 −9
Original line number Diff line number Diff line
@@ -14,26 +14,28 @@
 * limitations under the License.
 */

package android.telephony.ims.internal;
package android.telephony.ims;

import static junit.framework.Assert.assertEquals;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;

import android.net.Uri;
import android.os.Parcel;
import android.os.RemoteException;
import android.support.test.runner.AndroidJUnit4;
import android.telephony.ServiceState;
import android.telephony.ims.internal.aidl.IImsRegistration;
import android.telephony.ims.internal.feature.ImsFeature;
import android.telephony.ims.internal.stub.ImsFeatureConfiguration;
import android.telephony.ims.internal.stub.ImsRegistrationImplBase;
import android.telephony.ims.stub.ImsRegistrationImplBase;
import android.test.suitebuilder.annotation.SmallTest;

import com.android.ims.ImsReasonInfo;
import com.android.ims.internal.IImsRegistration;
import com.android.ims.internal.IImsRegistrationCallback;

import org.junit.After;
import org.junit.Before;
@@ -45,14 +47,15 @@ import org.mockito.Spy;
@RunWith(AndroidJUnit4.class)
public class ImsRegistrationTests {

    @Spy private ImsRegistrationImplBase.Callback mCallback;
    private TestImsRegistration mRegistration;
    @Spy private IImsRegistrationCallback.Stub mCallback;
    @Spy private IImsRegistrationCallback.Stub mCallback2;
    private ImsRegistrationImplBase mRegistration;
    private IImsRegistration mRegBinder;

    @Before
    public void setup() throws RemoteException {
        MockitoAnnotations.initMocks(this);
        mRegistration = new TestImsRegistration();
        mRegistration = new ImsRegistrationImplBase();
        mRegBinder = mRegistration.getBinder();
        mRegBinder.addRegistrationCallback(mCallback);
    }
@@ -148,6 +151,17 @@ public class ImsRegistrationTests {
                eq(ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN), eq(info));
    }

    @SmallTest
    @Test
    public void testSubscriberUrisChanged() throws RemoteException {
        Uri[] uris = new Uri[1];
        uris[0] = Uri.fromParts("tel", "5555551212", null);

        mRegistration.onSubscriberAssociatedUriChanged(uris);

        verify(mCallback).onSubscriberAssociatedUriChanged(eq(uris));
    }

    @SmallTest
    @Test
    public void testRegistrationCallbackAfterUnregistered() throws RemoteException {
@@ -161,7 +175,6 @@ public class ImsRegistrationTests {
    @SmallTest
    @Test
    public void testRegistrationCallbackSendCurrentState() throws RemoteException {
        ImsRegistrationImplBase.Callback mCallback2 = spy(new ImsRegistrationImplBase.Callback());
        mRegistration.onRegistered(ImsRegistrationImplBase.REGISTRATION_TECH_LTE);

        mRegBinder.addRegistrationCallback(mCallback2);
@@ -181,7 +194,6 @@ public class ImsRegistrationTests {
    @SmallTest
    @Test
    public void testRegistrationCallbackSendCurrentStateDisconnected() throws RemoteException {
        ImsRegistrationImplBase.Callback mCallback2 = spy(new ImsRegistrationImplBase.Callback());
        ImsReasonInfo info = new ImsReasonInfo(ImsReasonInfo.CODE_LOCAL_NETWORK_NO_LTE_COVERAGE, 0);
        mRegistration.onDeregistered(info);

@@ -206,4 +218,13 @@ public class ImsRegistrationTests {
        assertEquals(ImsRegistrationImplBase.REGISTRATION_TECH_NONE,
                mRegBinder.getRegistrationTechnology());
    }

    @SmallTest
    @Test
    public void testRegistrationCallbackNoCallbackIfUnknown() throws RemoteException {
        mRegBinder.addRegistrationCallback(mCallback2);
        // Verify that if we have never set the registration state, we do not callback immediately
        // with onDeregistered.
        verify(mCallback2, never()).onDeregistered(any(ImsReasonInfo.class));
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ import android.support.test.runner.AndroidJUnit4;
import android.telephony.ims.internal.feature.CapabilityChangeRequest;
import android.telephony.ims.internal.feature.ImsFeature;
import android.telephony.ims.internal.feature.MmTelFeature;
import android.telephony.ims.internal.stub.ImsRegistrationImplBase;
import android.telephony.ims.stub.ImsRegistrationImplBase;
import android.test.suitebuilder.annotation.SmallTest;

import com.android.ims.internal.IImsFeatureStatusCallback;
Loading