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

Commit 6cc5ac49 authored by Pavel Zhamaitsiak's avatar Pavel Zhamaitsiak
Browse files

Fix race condition which caused extra ImsPhone object to be created.

Extra ImsPhone object was created if IMS service was available when
voice RAT was changing. Later this object was replaced inside GSM or
CDMA phone object, but it proceed receiving updates from IMS service.

Bug: 19986577
Change-Id: I2907569fc0270e58a37725d530da0a60ead4215e
parent 2ae7c587
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -1888,6 +1888,11 @@ public interface Phone {
     */
    public Phone getImsPhone();

    /**
     * Start listening for IMS service UP/DOWN events.
     */
    public void startMonitoringImsService();

    /**
     * Release the local instance of the ImsPhone and disconnect from
     * the phone.
+56 −41
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@ import java.util.concurrent.atomic.AtomicReference;
public abstract class PhoneBase extends Handler implements Phone {
    private static final String LOG_TAG = "PhoneBase";

    private boolean mImsIntentReceiverRegistered = false;
    private BroadcastReceiver mImsIntentReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
@@ -100,6 +101,7 @@ public abstract class PhoneBase extends Handler implements Phone {
                }
            }

            synchronized (PhoneProxy.lockForRadioTechnologyChange) {
                if (intent.getAction().equals(ImsManager.ACTION_IMS_SERVICE_UP)) {
                    mImsServiceReady = true;
                    updateImsPhone();
@@ -108,6 +110,7 @@ public abstract class PhoneBase extends Handler implements Phone {
                    updateImsPhone();
                }
            }
        }
    };

    // Key used to read and write the saved network selection numeric value
@@ -218,7 +221,6 @@ public abstract class PhoneBase extends Handler implements Phone {

    protected int mPhoneId;

    private final Object mImsLock = new Object();
    private boolean mImsServiceReady = false;
    protected ImsPhone mImsPhone = null;

@@ -425,6 +427,19 @@ public abstract class PhoneBase extends Handler implements Phone {
        mUiccController = UiccController.getInstance();
        mUiccController.registerForIccChanged(this, EVENT_ICC_CHANGED, null);

        mCi.registerForSrvccStateChanged(this, EVENT_SRVCC_STATE_CHANGED, null);
        mCi.setOnUnsolOemHookRaw(this, EVENT_UNSOL_OEM_HOOK_RAW, null);
    }

    @Override
    public void startMonitoringImsService() {
        synchronized(PhoneProxy.lockForRadioTechnologyChange) {
            IntentFilter filter = new IntentFilter();
            filter.addAction(ImsManager.ACTION_IMS_SERVICE_UP);
            filter.addAction(ImsManager.ACTION_IMS_SERVICE_DOWN);
            mContext.registerReceiver(mImsIntentReceiver, filter);
            mImsIntentReceiverRegistered = true;

            // Monitor IMS service - but first poll to see if already up (could miss
            // intent)
            ImsManager imsManager = ImsManager.getInstance(mContext, getPhoneId());
@@ -432,19 +447,16 @@ public abstract class PhoneBase extends Handler implements Phone {
                mImsServiceReady = true;
                updateImsPhone();
            }
        IntentFilter filter = new IntentFilter();
        filter.addAction(ImsManager.ACTION_IMS_SERVICE_UP);
        filter.addAction(ImsManager.ACTION_IMS_SERVICE_DOWN);
        mContext.registerReceiver(mImsIntentReceiver, filter);

        mCi.registerForSrvccStateChanged(this, EVENT_SRVCC_STATE_CHANGED, null);
        mCi.setOnUnsolOemHookRaw(this, EVENT_UNSOL_OEM_HOOK_RAW, null);
        }
    }

    @Override
    public void dispose() {
        synchronized(PhoneProxy.lockForRadioTechnologyChange) {
            if (mImsIntentReceiverRegistered) {
                mContext.unregisterReceiver(mImsIntentReceiver);
                mImsIntentReceiverRegistered = false;
            }
            mCi.unSetOnCallRing(this);
            // Must cleanup all connectionS and needs to use sendMessage!
            mDcTracker.cleanUpAllConnections(null);
@@ -1904,10 +1916,15 @@ public abstract class PhoneBase extends Handler implements Phone {

    @Override
    public ImsPhone relinquishOwnershipOfImsPhone() {
        synchronized (mImsLock) {
        synchronized (PhoneProxy.lockForRadioTechnologyChange) {
            if (mImsPhone == null)
                return null;

            if (mImsIntentReceiverRegistered) {
                mContext.unregisterReceiver(mImsIntentReceiver);
                mImsIntentReceiverRegistered = false;
            }

            ImsPhone imsPhone = mImsPhone;
            mImsPhone = null;

@@ -1920,7 +1937,7 @@ public abstract class PhoneBase extends Handler implements Phone {

    @Override
    public void acquireOwnershipOfImsPhone(ImsPhone imsPhone) {
        synchronized (mImsLock) {
        synchronized (PhoneProxy.lockForRadioTechnologyChange) {
            if (imsPhone == null)
                return;

@@ -1945,7 +1962,6 @@ public abstract class PhoneBase extends Handler implements Phone {
    }

    protected void updateImsPhone() {
        synchronized (mImsLock) {
        Rlog.d(LOG_TAG, "updateImsPhone"
                + " mImsServiceReady=" + mImsServiceReady);

@@ -1966,7 +1982,6 @@ public abstract class PhoneBase extends Handler implements Phone {
            mImsPhone = null;
        }
    }
    }

    /**
     * Dials a number.
+2 −0
Original line number Diff line number Diff line
@@ -151,9 +151,11 @@ public class PhoneFactory {
                    if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
                        phone = new GSMPhone(context,
                                sCommandsInterfaces[i], sPhoneNotifier, i);
                        phone.startMonitoringImsService();
                    } else if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
                        phone = new CDMALTEPhone(context,
                                sCommandsInterfaces[i], sPhoneNotifier, i);
                        phone.startMonitoringImsService();
                    }
                    Rlog.i(LOG_TAG, "Creating Phone with type = " + phoneType + " sub = " + i);

+4 −2
Original line number Diff line number Diff line
@@ -40,7 +40,6 @@ import com.android.internal.telephony.gsm.GSMPhone;
import com.android.internal.telephony.imsphone.ImsPhone;
import com.android.internal.telephony.test.SimulatedRadioControl;
import com.android.internal.telephony.cdma.CDMALTEPhone;
import com.android.internal.telephony.RadioCapability;
import com.android.internal.telephony.uicc.IccCardProxy;
import com.android.internal.telephony.uicc.IccFileHandler;
import com.android.internal.telephony.uicc.IsimRecords;
@@ -50,7 +49,6 @@ import com.android.internal.telephony.uicc.UsimServiceTable;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.List;
import java.util.Set;

import com.android.internal.telephony.dataconnection.DctController;

@@ -301,6 +299,7 @@ public class PhoneProxy extends Handler implements Phone {
            if (imsPhone != null) {
                mActivePhone.acquireOwnershipOfImsPhone(imsPhone);
            }
            mActivePhone.startMonitoringImsService();
            mActivePhone.registerForSimRecordsLoaded(this, EVENT_SIM_RECORDS_LOADED, null);
        }

@@ -1443,6 +1442,9 @@ public class PhoneProxy extends Handler implements Phone {
    @Override
    public ImsPhone relinquishOwnershipOfImsPhone() { return null; }

    @Override
    public void startMonitoringImsService() {}

    @Override
    public void acquireOwnershipOfImsPhone(ImsPhone imsPhone) { }