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

Commit 2e3a4ed5 authored by Brad Ebinger's avatar Brad Ebinger Committed by gitbuildkicker
Browse files

Retry Connecting to ImsService if it is not up yet

When the ImsService crashes, there is a possibility of the
ACTION_IMS_SERVICE_UP broadcast getting received before the ImsService
is available from ServiceManager. This change introduces a retry timer to
try reconnecting the ImsService if it fails to bind.

Bug: 29891063
Change-Id: Id3d69d76630752f892ec80573d79f4da55c70395
parent 75d597e6
Loading
Loading
Loading
Loading
+54 −34
Original line number Diff line number Diff line
@@ -68,7 +68,6 @@ import com.android.ims.ImsServiceClass;
import com.android.ims.ImsSuppServiceNotification;
import com.android.ims.ImsUtInterface;
import com.android.ims.internal.IImsVideoCallProvider;
import com.android.ims.internal.ImsVideoCallProvider;
import com.android.ims.internal.ImsVideoCallProviderWrapper;
import com.android.internal.telephony.Call;
import com.android.internal.telephony.CallStateException;
@@ -197,9 +196,15 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
    private static final int EVENT_EXIT_ECBM_BEFORE_PENDINGMO = 21;
    private static final int EVENT_VT_DATA_USAGE_UPDATE = 22;
    private static final int EVENT_DATA_ENABLED_CHANGED = 23;
    private static final int EVENT_GET_IMS_SERVICE = 24;

    private static final int TIMEOUT_HANGUP_PENDINGMO = 500;

    // The number of times we will try to connect to the ImsService before giving up.
    private static final int NUM_IMS_SERVICE_RETRIES = 10;
    // The number of milliseconds in between each try.
    private static final int TIME_BETWEEN_IMS_SERVICE_RETRIES_MS = 400; // ms

    //***** Instance Variables
    private ArrayList<ImsPhoneConnection> mConnections = new ArrayList<ImsPhoneConnection>();
    private RegistrantList mVoiceCallEndedRegistrants = new RegistrantList();
@@ -232,6 +237,7 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {

    private PhoneConstants.State mState = PhoneConstants.State.IDLE;

    private int mImsServiceRetryCount;
    private ImsManager mImsManager;
    private int mServiceId = -1;

@@ -299,12 +305,10 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
        mPhone.getDefaultPhone().registerForDataEnabledChanged(
                this, EVENT_DATA_ENABLED_CHANGED, null);

        Thread t = new Thread() {
            public void run() {
                getImsService();
            }
        };
        t.start();
        mImsServiceRetryCount = 0;
        // Send a message to connect to the Ims Service and open a connection through
        // getImsService().
        sendEmptyMessage(EVENT_GET_IMS_SERVICE);
    }

    private PendingIntent createIncomingCallPendingIntent() {
@@ -314,10 +318,9 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
                PendingIntent.FLAG_UPDATE_CURRENT);
    }

    private void getImsService() {
    private void getImsService() throws ImsException {
        if (DBG) log("getImsService");
        mImsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
        try {
        mServiceId = mImsManager.open(ImsServiceClass.MMTEL,
                createIncomingCallPendingIntent(),
                mImsConnectionStateListener);
@@ -341,11 +344,6 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
            multiEndpoint.setExternalCallStateListener(
                    mPhone.getExternalCallTracker().getExternalCallStateListener());
        }
        } catch (ImsException e) {
            loge("getImsService: " + e);
            //Leave mImsManager as null, then CallStateException will be thrown when dialing
            mImsManager = null;
        }
    }

    public void dispose() {
@@ -358,6 +356,7 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
        clearDisconnected();
        mPhone.getContext().unregisterReceiver(mReceiver);
        mPhone.unregisterForDataEnabledChanged(this);
        removeMessages(EVENT_GET_IMS_SERVICE);
    }

    @Override
@@ -2189,6 +2188,27 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
                    onDataEnabledChanged(p.first, p.second);
                }
                break;
            case EVENT_GET_IMS_SERVICE:
                try {
                    getImsService();
                } catch (ImsException e) {
                    loge("getImsService: " + e);
                    //Leave mImsManager as null, then CallStateException will be thrown when dialing
                    mImsManager = null;
                    if (mImsServiceRetryCount < NUM_IMS_SERVICE_RETRIES) {
                        loge("getImsService: Retrying getting ImsService...");
                        sendEmptyMessageDelayed(EVENT_GET_IMS_SERVICE,
                                TIME_BETWEEN_IMS_SERVICE_RETRIES_MS);
                        mImsServiceRetryCount++;
                    } else {
                        // We have been unable to connect for
                        // NUM_IMS_SERVICE_RETRIES*TIME_BETWEEN_IMS_SERVICE_RETRIES_MS ms. We will
                        // probably never be able to connect, so we should just give up.
                        loge("getImsService: ImsService retrieval timeout... ImsService is " +
                                "unavailable.");
                    }
                }
                break;
        }
    }