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

Commit 8c68b8b7 authored by Kensuke Miyagi's avatar Kensuke Miyagi
Browse files

Fix race condition that can caluse NPE in removeClientProfile()

Bug: 205787488
Test: android.media.tv.tuner.cts.TunerTest
Change-Id: If310eb8019d96d6ff6ac0240a69d41d70dbbd68f
parent b58e05f1
Loading
Loading
Loading
Loading
+18 −11
Original line number Diff line number Diff line
@@ -457,6 +457,7 @@ public class TunerResourceManagerService extends SystemService implements IBinde
            if (!validateResourceHandle(TunerResourceManager.TUNER_RESOURCE_TYPE_LNB, lnbHandle)) {
                throw new RemoteException("lnbHandle can't be invalid");
            }
            synchronized (mLock) {
                if (!checkClientExists(clientId)) {
                    throw new RemoteException("Release lnb from unregistered client:" + clientId);
                }
@@ -465,9 +466,9 @@ public class TunerResourceManagerService extends SystemService implements IBinde
                    throw new RemoteException("Releasing lnb does not exist.");
                }
                if (lnb.getOwnerClientId() != clientId) {
                throw new RemoteException("Client is not the current owner of the releasing lnb.");
                    throw new RemoteException("Client is not the current owner "
                            + "of the releasing lnb.");
                }
            synchronized (mLock) {
                releaseLnbInternal(lnb);
            }
        }
@@ -869,6 +870,7 @@ public class TunerResourceManagerService extends SystemService implements IBinde

        frontendHandle[0] = TunerResourceManager.INVALID_RESOURCE_HANDLE;
        ClientProfile requestClient = getClientProfile(request.clientId);
        // TODO: check if this is really needed
        if (requestClient == null) {
            return false;
        }
@@ -1205,9 +1207,11 @@ public class TunerResourceManagerService extends SystemService implements IBinde
        @Override
        public void binderDied() {
            synchronized (mLock) {
                if (checkClientExists(mClientId)) {
                    removeClientProfile(mClientId);
                }
            }
        }

        public int getId() {
            return mClientId;
@@ -1246,6 +1250,7 @@ public class TunerResourceManagerService extends SystemService implements IBinde
        // Reclaim all the resources of the share owners of the frontend that is used by the current
        // resource reclaimed client.
        ClientProfile profile = getClientProfile(reclaimingClientId);
        // TODO: check if this check is really needed.
        if (profile == null) {
            return true;
        }
@@ -1553,6 +1558,7 @@ public class TunerResourceManagerService extends SystemService implements IBinde
    }

    private void clearFrontendAndClientMapping(ClientProfile profile) {
        // TODO: check if this check is really needed
        if (profile == null) {
            return;
        }
@@ -1573,6 +1579,7 @@ public class TunerResourceManagerService extends SystemService implements IBinde
    }

    private void clearAllResourcesAndClientMapping(ClientProfile profile) {
        // TODO: check if this check is really needed. Maybe needed for reclaimResource path.
        if (profile == null) {
            return;
        }