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

Commit 66f1b323 authored by Yixiao Luo's avatar Yixiao Luo Committed by Automerger Merge Worker
Browse files

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

Merge "MediaCas: Release cas resource only when all sessions are closed" into main am: e9e7e78f am: 89d3bb5a

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/3016424



Change-Id: I792a8f3f03bc9372f9f5cdb84dd5d09130d8b6fd
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents dcaec879 89d3bb5a
Loading
Loading
Loading
Loading
+28 −2
Original line number Original line Diff line number Diff line
@@ -89,9 +89,35 @@ public class CasResource {
     * @param ownerId the removing client id of the owner.
     * @param ownerId the removing client id of the owner.
     */
     */
    public void removeOwner(int ownerId) {
    public void removeOwner(int ownerId) {
        if (mOwnerClientIdsToSessionNum.containsKey(ownerId)) {
            mAvailableSessionNum += mOwnerClientIdsToSessionNum.get(ownerId);
            mAvailableSessionNum += mOwnerClientIdsToSessionNum.get(ownerId);
            mOwnerClientIdsToSessionNum.remove(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() {
    public Set<Integer> getOwnerClientIds() {
        return mOwnerClientIdsToSessionNum.keySet();
        return mOwnerClientIdsToSessionNum.keySet();
+7 −5
Original line number Original line Diff line number Diff line
@@ -1924,12 +1924,14 @@ public class TunerResourceManagerService extends SystemService implements IBinde
        ownerProfile.useCiCam(grantingId);
        ownerProfile.useCiCam(grantingId);
    }
    }


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


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