From a8a3bee09374c39407a2264561a9518b7bd16fcd Mon Sep 17 00:00:00 2001 From: Henry Fang Date: Mon, 13 Mar 2023 22:39:33 +0000 Subject: [PATCH] yield resource if the request come from same client with same priority Change-Id: Ia1233f92f7c8f7a04be10fa30d3f66628ea6f43c bug: 264857199 Test: manual --- .../TunerResourceManagerService.java | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/tv/tunerresourcemanager/TunerResourceManagerService.java b/services/core/java/com/android/server/tv/tunerresourcemanager/TunerResourceManagerService.java index ed91775467945..2d3928ca57213 100644 --- a/services/core/java/com/android/server/tv/tunerresourcemanager/TunerResourceManagerService.java +++ b/services/core/java/com/android/server/tv/tunerresourcemanager/TunerResourceManagerService.java @@ -1019,6 +1019,7 @@ public class TunerResourceManagerService extends SystemService implements IBinde int inUseLowestPriorityFrHandle = TunerResourceManager.INVALID_RESOURCE_HANDLE; // Priority max value is 1000 int currentLowestPriority = MAX_CLIENT_PRIORITY + 1; + boolean isRequestFromSameProcess = false; // If the desired frontend id was specified, we only need to check the frontend. boolean hasDesiredFrontend = request.desiredId != TunerFrontendRequest.DEFAULT_DESIRED_ID; for (FrontendResource fr : getFrontendResources().values()) { @@ -1048,6 +1049,8 @@ public class TunerResourceManagerService extends SystemService implements IBinde if (currentLowestPriority > priority) { inUseLowestPriorityFrHandle = fr.getHandle(); currentLowestPriority = priority; + isRequestFromSameProcess = (requestClient.getProcessId() + == (getClientProfile(fr.getOwnerClientId())).getProcessId()); } } } @@ -1063,7 +1066,8 @@ public class TunerResourceManagerService extends SystemService implements IBinde // When all the resources are occupied, grant the lowest priority resource if the // request client has higher priority. if (inUseLowestPriorityFrHandle != TunerResourceManager.INVALID_RESOURCE_HANDLE - && (requestClient.getPriority() > currentLowestPriority)) { + && ((requestClient.getPriority() > currentLowestPriority) || ( + (requestClient.getPriority() == currentLowestPriority) && isRequestFromSameProcess))) { if (!reclaimResource( getFrontendResource(inUseLowestPriorityFrHandle).getOwnerClientId(), TunerResourceManager.TUNER_RESOURCE_TYPE_FRONTEND)) { @@ -1182,6 +1186,7 @@ public class TunerResourceManagerService extends SystemService implements IBinde int inUseLowestPriorityLnbHandle = TunerResourceManager.INVALID_RESOURCE_HANDLE; // Priority max value is 1000 int currentLowestPriority = MAX_CLIENT_PRIORITY + 1; + boolean isRequestFromSameProcess = false; for (LnbResource lnb : getLnbResources().values()) { if (!lnb.isInUse()) { // Grant the unused lnb with lower handle first @@ -1194,6 +1199,8 @@ public class TunerResourceManagerService extends SystemService implements IBinde if (currentLowestPriority > priority) { inUseLowestPriorityLnbHandle = lnb.getHandle(); currentLowestPriority = priority; + isRequestFromSameProcess = (requestClient.getProcessId() + == (getClientProfile(lnb.getOwnerClientId())).getProcessId()); } } } @@ -1208,7 +1215,8 @@ public class TunerResourceManagerService extends SystemService implements IBinde // When all the resources are occupied, grant the lowest priority resource if the // request client has higher priority. if (inUseLowestPriorityLnbHandle > TunerResourceManager.INVALID_RESOURCE_HANDLE - && (requestClient.getPriority() > currentLowestPriority)) { + && ((requestClient.getPriority() > currentLowestPriority) || ( + (requestClient.getPriority() == currentLowestPriority) && isRequestFromSameProcess))) { if (!reclaimResource(getLnbResource(inUseLowestPriorityLnbHandle).getOwnerClientId(), TunerResourceManager.TUNER_RESOURCE_TYPE_LNB)) { return false; @@ -1240,6 +1248,7 @@ public class TunerResourceManagerService extends SystemService implements IBinde int lowestPriorityOwnerId = -1; // Priority max value is 1000 int currentLowestPriority = MAX_CLIENT_PRIORITY + 1; + boolean isRequestFromSameProcess = false; if (!cas.isFullyUsed()) { casSessionHandle[0] = generateResourceHandle( TunerResourceManager.TUNER_RESOURCE_TYPE_CAS_SESSION, cas.getSystemId()); @@ -1252,12 +1261,15 @@ public class TunerResourceManagerService extends SystemService implements IBinde if (currentLowestPriority > priority) { lowestPriorityOwnerId = ownerId; currentLowestPriority = priority; + isRequestFromSameProcess = (requestClient.getProcessId() + == (getClientProfile(ownerId)).getProcessId()); } } // When all the Cas sessions are occupied, reclaim the lowest priority client if the // request client has higher priority. - if (lowestPriorityOwnerId > -1 && (requestClient.getPriority() > currentLowestPriority)) { + if (lowestPriorityOwnerId > -1 && ((requestClient.getPriority() > currentLowestPriority) + || ((requestClient.getPriority() == currentLowestPriority) && isRequestFromSameProcess))) { if (!reclaimResource(lowestPriorityOwnerId, TunerResourceManager.TUNER_RESOURCE_TYPE_CAS_SESSION)) { return false; @@ -1289,6 +1301,7 @@ public class TunerResourceManagerService extends SystemService implements IBinde int lowestPriorityOwnerId = -1; // Priority max value is 1000 int currentLowestPriority = MAX_CLIENT_PRIORITY + 1; + boolean isRequestFromSameProcess = false; if (!ciCam.isFullyUsed()) { ciCamHandle[0] = generateResourceHandle( TunerResourceManager.TUNER_RESOURCE_TYPE_FRONTEND_CICAM, ciCam.getCiCamId()); @@ -1301,12 +1314,16 @@ public class TunerResourceManagerService extends SystemService implements IBinde if (currentLowestPriority > priority) { lowestPriorityOwnerId = ownerId; currentLowestPriority = priority; + isRequestFromSameProcess = (requestClient.getProcessId() + == (getClientProfile(ownerId)).getProcessId()); } } // When all the CiCam sessions are occupied, reclaim the lowest priority client if the // request client has higher priority. - if (lowestPriorityOwnerId > -1 && (requestClient.getPriority() > currentLowestPriority)) { + if (lowestPriorityOwnerId > -1 && ((requestClient.getPriority() > currentLowestPriority) + || ((requestClient.getPriority() == currentLowestPriority) + && isRequestFromSameProcess))) { if (!reclaimResource(lowestPriorityOwnerId, TunerResourceManager.TUNER_RESOURCE_TYPE_FRONTEND_CICAM)) { return false; @@ -1424,6 +1441,7 @@ public class TunerResourceManagerService extends SystemService implements IBinde int inUseLowestPriorityDrHandle = TunerResourceManager.INVALID_RESOURCE_HANDLE; // Priority max value is 1000 int currentLowestPriority = MAX_CLIENT_PRIORITY + 1; + boolean isRequestFromSameProcess = false; // If the desired demux id was specified, we only need to check the demux. boolean hasDesiredDemuxCap = request.desiredFilterTypes != DemuxFilterMainType.UNDEFINED; @@ -1448,6 +1466,8 @@ public class TunerResourceManagerService extends SystemService implements IBinde // update lowest priority if (currentLowestPriority > priority) { currentLowestPriority = priority; + isRequestFromSameProcess = (requestClient.getProcessId() + == (getClientProfile(dr.getOwnerClientId())).getProcessId()); shouldUpdate = true; } // update smallest caps @@ -1473,7 +1493,8 @@ public class TunerResourceManagerService extends SystemService implements IBinde // When all the resources are occupied, grant the lowest priority resource if the // request client has higher priority. if (inUseLowestPriorityDrHandle != TunerResourceManager.INVALID_RESOURCE_HANDLE - && (requestClient.getPriority() > currentLowestPriority)) { + && ((requestClient.getPriority() > currentLowestPriority) || ( + (requestClient.getPriority() == currentLowestPriority) && isRequestFromSameProcess))) { if (!reclaimResource( getDemuxResource(inUseLowestPriorityDrHandle).getOwnerClientId(), TunerResourceManager.TUNER_RESOURCE_TYPE_DEMUX)) {