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

Commit 251f22a3 authored by Kensuke Miyagi's avatar Kensuke Miyagi
Browse files

Fix bug in DemuxResource allocation logic

The intended logic is to find demux resource for the requested
capability that has the least number of capabilities. This CL fixes:
- the issue where non-used resource won't be found if it has more number
  of capabilities than what is currently used
- the issue where smallestNumOfSupportedCapsInUse was not reset when the
  lower priority resource is found

Bug: 299858762
Test: atest TunerTest
Change-Id: I5fd1c85046b2dbe0e2d2039a7b08a5fe214c4200
parent d20d16da
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -1454,6 +1454,7 @@ public class TunerResourceManagerService extends SystemService implements IBinde
        boolean hasDesiredDemuxCap = request.desiredFilterTypes
                != DemuxFilterMainType.UNDEFINED;
        int smallestNumOfSupportedCaps = Integer.SIZE + 1;
        int smallestNumOfSupportedCapsInUse = Integer.SIZE + 1;
        for (DemuxResource dr : getDemuxResources().values()) {
            if (!hasDesiredDemuxCap || dr.hasSufficientCaps(request.desiredFilterTypes)) {
                if (!dr.isInUse()) {
@@ -1476,13 +1477,19 @@ public class TunerResourceManagerService extends SystemService implements IBinde
                            currentLowestPriority = priority;
                            isRequestFromSameProcess = (requestClient.getProcessId()
                                == (getClientProfile(dr.getOwnerClientId())).getProcessId());

                            // reset the smallest caps when lower priority resource is found
                            smallestNumOfSupportedCapsInUse = numOfSupportedCaps;

                            shouldUpdate = true;
                        }
                        // update smallest caps
                        if (smallestNumOfSupportedCaps > numOfSupportedCaps) {
                            smallestNumOfSupportedCaps = numOfSupportedCaps;
                        } else {
                            // This is the case when the priority is the same as previously found
                            // one. Update smallest caps when priority.
                            if (smallestNumOfSupportedCapsInUse > numOfSupportedCaps) {
                                smallestNumOfSupportedCapsInUse = numOfSupportedCaps;
                                shouldUpdate = true;
                            }
                        }
                        if (shouldUpdate) {
                            inUseLowestPriorityDrHandle = dr.getHandle();
                        }