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

Commit 30862cd2 authored by Etan Cohen's avatar Etan Cohen
Browse files

Remove race condition due to RAT technology change.

On RAT technology change old phone is destroyed and new phone created.
Original code performed unregistration of old phone and then registration
of new phone - small window where CallManager.getDefaultPhone() returned NULL.

Code changes order to make sure new phone is registered before old phone
is unregistered.

Bug: 17347478
Change-Id: Ife5b995de90bb5f8fab51af89f7b9aa50e7ec306
parent b6f7017f
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -1783,7 +1783,10 @@ public abstract class PhoneBase extends Handler implements Phone {
                Rlog.e(LOG_TAG, "acquireOwnershipOfImsPhone: non-null mImsPhone." +
                        " Shouldn't happen - but disposing");
                mImsPhone.dispose();
                mImsPhone.removeReferences();
                // Potential GC issue if someone keeps a reference to ImsPhone.
                // However: this change will make sure that such a reference does
                // not access functions through NULL pointer.
                //mImsPhone.removeReferences();
            }

            mImsPhone = imsPhone;
@@ -1811,7 +1814,10 @@ public abstract class PhoneBase extends Handler implements Phone {
                mImsPhone.unregisterForSilentRedial(this);

                mImsPhone.dispose();
                mImsPhone.removeReferences();
                // Potential GC issue if someone keeps a reference to ImsPhone.
                // However: this change will make sure that such a reference does
                // not access functions through NULL pointer.
                //mImsPhone.removeReferences();
                mImsPhone = null;
            }
        }
+10 −15
Original line number Diff line number Diff line
@@ -255,20 +255,6 @@ public class PhoneProxy extends Handler implements Phone {
                + (ServiceState.isGsm(newVoiceRadioTech) ? "GSM" : "CDMA"));


        if (oldPhone != null) {
            imsPhone = oldPhone.relinquishOwnershipOfImsPhone();
            CallManager.getInstance().unregisterPhone(oldPhone);
            logd("Disposing old phone..");
            oldPhone.dispose();
        }

        // Give the garbage collector a hint to start the garbage collection
        // asap NOTE this has been disabled since radio technology change could
        // happen during e.g. a multimedia playing and could slow the system.
        // Tests needs to be done to see the effects of the GC call here when
        // system is busy.
        // System.gc();

        if (ServiceState.isCdma(newVoiceRadioTech)) {
            mActivePhone = PhoneFactory.getCdmaPhone(mPhoneId);
        } else if (ServiceState.isGsm(newVoiceRadioTech)) {
@@ -276,7 +262,7 @@ public class PhoneProxy extends Handler implements Phone {
        }

        if (oldPhone != null) {
            oldPhone.removeReferences();
            imsPhone = oldPhone.relinquishOwnershipOfImsPhone();
        }

        if(mActivePhone != null) {
@@ -286,6 +272,15 @@ public class PhoneProxy extends Handler implements Phone {
            }
        }

        if (oldPhone != null) {
            CallManager.getInstance().unregisterPhone(oldPhone);
            logd("Disposing old phone..");
            oldPhone.dispose();
            // Potential GC issues: however, callers may have references to old
            // phone on which they perform hierarchical funcs: phone.getA().getB()
            // HENCE: do not delete references.
            //oldPhone.removeReferences();
        }
        oldPhone = null;
    }