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

Commit b5817df8 authored by sangyun's avatar sangyun Committed by Sangyun Yun
Browse files

Fix NoSuchElementException is threw when unlinkToDeath is called

Parameter flags in Binder::linkToDeath must be matched as a pair
with the recipient in unlinkToDeath to be removed from mObituaries
and deleted.
Since each service's cookie list meaningfully starts from 1,
setting the flag to 0 in unlinkToDeath is equivalent to not to
find an existing recipient in mObituaries.
Therefore, for truly unlinking, use the flag set in the linkToDeath
again to unlink it and remove it from the binder.

Bug: 340156301
Test: Basic telephony funcationlity tests
Test: atest FrameworksTelephonyTests
Change-Id: Ib1172bc8cdbfc8d6f42474c8e2adffe3f92af3b3
parent dbb96945
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -466,16 +466,19 @@ public class RIL extends BaseCommands implements CommandsInterface {
    private final class BinderServiceDeathRecipient implements IBinder.DeathRecipient {
        private IBinder mBinder;
        private final int mService;
        private long mLinkedFlags;

        BinderServiceDeathRecipient(int service) {
            mService = service;
            mLinkedFlags = 0;
        }

        public void linkToDeath(IBinder service) throws RemoteException {
            if (service != null) {
                riljLog("Linked to death for service " + serviceToString(mService));
                mBinder = service;
                mBinder.linkToDeath(this, (int) mServiceCookies.get(mService).incrementAndGet());
                mLinkedFlags = mServiceCookies.get(mService).incrementAndGet();
                mBinder.linkToDeath(this, (int) mLinkedFlags);
            } else {
                riljLoge("Unable to link to death for service " + serviceToString(mService));
            }
@@ -483,8 +486,9 @@ public class RIL extends BaseCommands implements CommandsInterface {

        public synchronized void unlinkToDeath() {
            if (mBinder != null) {
                mBinder.unlinkToDeath(this, 0);
                mBinder.unlinkToDeath(this, (int) mLinkedFlags);
                mBinder = null;
                mLinkedFlags = 0;
            }
        }

@@ -494,10 +498,10 @@ public class RIL extends BaseCommands implements CommandsInterface {
            if (mFeatureFlags.combineRilDeathHandle()) {
                mRilHandler.sendMessageAtFrontOfQueue(mRilHandler.obtainMessage(
                        EVENT_AIDL_PROXY_DEAD, mService, 0 /* ignored arg2 */,
                        mServiceCookies.get(mService).get()));
                        mLinkedFlags));
            } else {
                mRilHandler.sendMessage(mRilHandler.obtainMessage(EVENT_AIDL_PROXY_DEAD, mService,
                        0 /* ignored arg2 */, mServiceCookies.get(mService).get()));
                        0 /* ignored arg2 */, mLinkedFlags));
            }
            unlinkToDeath();
        }