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

Commit f91cfca9 authored by Android Build Prod User's avatar Android Build Prod User Committed by Android (Google) Code Review
Browse files

Merge "Make Tuner resource reclaiming synchronous"

parents 7628ab93 cc7c8d64
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -53,7 +53,6 @@ import android.media.tv.tunerresourcemanager.TunerFrontendRequest;
import android.media.tv.tunerresourcemanager.TunerLnbRequest;
import android.media.tv.tunerresourcemanager.TunerResourceManager;
import android.os.Handler;
import android.os.HandlerExecutor;
import android.os.Looper;
import android.os.Message;
import android.os.Process;
@@ -354,7 +353,7 @@ public class Tuner implements AutoCloseable {
        profile.tvInputSessionId = tvInputSessionId;
        profile.useCase = useCase;
        mTunerResourceManager.registerClientProfile(
                profile, new HandlerExecutor(mHandler), mResourceListener, clientId);
                profile, Runnable::run, mResourceListener, clientId);
        mClientId = clientId[0];

        mUserId = Process.myUid();
+2 −2
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ package android.media.tv.tunerresourcemanager;
 *
 * @hide
 */
oneway interface IResourcesReclaimListener {
interface IResourcesReclaimListener {
    /*
     * TRM invokes this method when the client's resources need to be reclaimed.
     *
+28 −14
Original line number Diff line number Diff line
@@ -922,10 +922,12 @@ public class TunerResourceManagerService extends SystemService implements IBinde
        }
        if (clientId == fe.getOwnerClientId()) {
            ClientProfile ownerClient = getClientProfile(fe.getOwnerClientId());
            if (ownerClient != null) {
                for (int shareOwnerId : ownerClient.getShareFeClientIds()) {
                    clearFrontendAndClientMapping(getClientProfile(shareOwnerId));
                }
            }
        }
        clearFrontendAndClientMapping(getClientProfile(clientId));
    }

@@ -1039,20 +1041,13 @@ public class TunerResourceManagerService extends SystemService implements IBinde
    @VisibleForTesting
    protected boolean reclaimResource(int reclaimingClientId,
            @TunerResourceManager.TunerResourceType int resourceType) {
        if (DEBUG) {
            Slog.d(TAG, "Reclaiming resources because higher priority client request resource type "
                    + resourceType);
        }
        try {
            mListeners.get(reclaimingClientId).getListener().onReclaimResources();
        } catch (RemoteException e) {
            Slog.e(TAG, "Failed to reclaim resources on client " + reclaimingClientId, e);
            return false;
        }

        // Reclaim all the resources of the share owners of the frontend that is used by the current
        // resource reclaimed client.
        ClientProfile profile = getClientProfile(reclaimingClientId);
        if (profile == null) {
            return true;
        }
        Set<Integer> shareFeClientIds = profile.getShareFeClientIds();
        for (int clientId : shareFeClientIds) {
            try {
@@ -1063,6 +1058,17 @@ public class TunerResourceManagerService extends SystemService implements IBinde
            }
            clearAllResourcesAndClientMapping(getClientProfile(clientId));
        }

        if (DEBUG) {
            Slog.d(TAG, "Reclaiming resources because higher priority client request resource type "
                    + resourceType + ", clientId:" + reclaimingClientId);
        }
        try {
            mListeners.get(reclaimingClientId).getListener().onReclaimResources();
        } catch (RemoteException e) {
            Slog.e(TAG, "Failed to reclaim resources on client " + reclaimingClientId, e);
            return false;
        }
        clearAllResourcesAndClientMapping(profile);
        return true;
    }
@@ -1319,13 +1325,21 @@ public class TunerResourceManagerService extends SystemService implements IBinde
    }

    private void clearFrontendAndClientMapping(ClientProfile profile) {
        if (profile == null) {
            return;
        }
        for (Integer feId : profile.getInUseFrontendHandles()) {
            FrontendResource fe = getFrontendResource(feId);
            if (fe.getOwnerClientId() == profile.getId()) {
            int ownerClientId = fe.getOwnerClientId();
            if (ownerClientId == profile.getId()) {
                fe.removeOwner();
                continue;
            }
            getClientProfile(fe.getOwnerClientId()).stopSharingFrontend(profile.getId());
            ClientProfile ownerClientProfile = getClientProfile(ownerClientId);
            if (ownerClientProfile != null) {
                ownerClientProfile.stopSharingFrontend(profile.getId());
            }

        }
        profile.releaseFrontend();
    }