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

Commit e9e7e78f authored by Yixiao Luo's avatar Yixiao Luo Committed by Gerrit Code Review
Browse files

Merge "MediaCas: Release cas resource only when all sessions are closed" into main

parents 0b2278d9 2d3307f9
Loading
Loading
Loading
Loading
+28 −2
Original line number Diff line number Diff line
@@ -89,9 +89,35 @@ public class CasResource {
     * @param ownerId the removing client id of the owner.
     */
    public void removeOwner(int ownerId) {
        if (mOwnerClientIdsToSessionNum.containsKey(ownerId)) {
            mAvailableSessionNum += mOwnerClientIdsToSessionNum.get(ownerId);
            mOwnerClientIdsToSessionNum.remove(ownerId);
        }
    }

    /**
     * Remove a single session from resource
     *
     * @param ownerId the client Id of the owner of the session
     */
    public void removeSession(int ownerId) {
        if (mOwnerClientIdsToSessionNum.containsKey(ownerId)) {
            int sessionNum = mOwnerClientIdsToSessionNum.get(ownerId);
            if (sessionNum > 0) {
                mOwnerClientIdsToSessionNum.put(ownerId, --sessionNum);
                mAvailableSessionNum++;
            }
        }
    }

    /**
     * Check if there are any open sessions owned by a client
     *
     * @param ownerId the client Id of the owner of the sessions
     */
    public boolean hasOpenSessions(int ownerId) {
        return mOwnerClientIdsToSessionNum.get(ownerId) > 0;
    }

    public Set<Integer> getOwnerClientIds() {
        return mOwnerClientIdsToSessionNum.keySet();
+7 −5
Original line number Diff line number Diff line
@@ -1924,12 +1924,14 @@ public class TunerResourceManagerService extends SystemService implements IBinde
        ownerProfile.useCiCam(grantingId);
    }

    private void updateCasClientMappingOnRelease(
            @NonNull CasResource releasingCas, int ownerClientId) {
    private void updateCasClientMappingOnRelease(@NonNull CasResource cas, int ownerClientId) {
        cas.removeSession(ownerClientId);
        if (!cas.hasOpenSessions(ownerClientId)) {
            ClientProfile ownerProfile = getClientProfile(ownerClientId);
        releasingCas.removeOwner(ownerClientId);
            cas.removeOwner(ownerClientId);
            ownerProfile.releaseCas();
        }
    }

    private void updateCiCamClientMappingOnRelease(
            @NonNull CiCamResource releasingCiCam, int ownerClientId) {