Loading services/core/java/com/android/server/tv/tunerresourcemanager/ClientProfile.java +20 −12 Original line number Diff line number Diff line Loading @@ -50,8 +50,6 @@ public final class ClientProfile { */ private final int mProcessId; private boolean mIsForeground; /** * All the clients that share the same resource would be under the same group id. * Loading Loading @@ -89,6 +87,12 @@ public final class ClientProfile { */ private int mUsingCiCamId = INVALID_RESOURCE_ID; /** * If the priority is overwritten through * {@link TunerResourceManagerService#setPriority(int, int)}. */ private boolean mIsPriorityOverwritten = false; /** * Optional arbitrary priority value given by the client. * Loading Loading @@ -121,17 +125,10 @@ public final class ClientProfile { } /** * Set the current isForeground status. */ public void setForeground(boolean isForeground) { mIsForeground = isForeground; } /** * Get the previous recorded isForeground status. * If the client priority is overwrttien. */ public boolean isForeground() { return mIsForeground; public boolean isPriorityOverwritten() { return mIsPriorityOverwritten; } public int getGroupId() { Loading @@ -153,6 +150,17 @@ public final class ClientProfile { mPriority = priority; } /** * Overwrite the client priority. */ public void overwritePriority(int priority) { if (priority < 0) { return; } mIsPriorityOverwritten = true; mPriority = priority; } public void setNiceValue(int niceValue) { mNiceValue = niceValue; } Loading services/core/java/com/android/server/tv/tunerresourcemanager/TunerResourceManagerService.java +19 −20 Original line number Diff line number Diff line Loading @@ -507,9 +507,8 @@ public class TunerResourceManagerService extends SystemService implements IBinde .useCase(profile.useCase) .processId(pid) .build(); clientProfile.setForeground(checkIsForeground(pid)); clientProfile.setPriority( getClientPriority(profile.useCase, clientProfile.isForeground())); getClientPriority(profile.useCase, checkIsForeground(pid))); addClientProfile(clientId[0], clientProfile, listener); } Loading Loading @@ -547,8 +546,7 @@ public class TunerResourceManagerService extends SystemService implements IBinde return false; } profile.setForeground(checkIsForeground(profile.getProcessId())); profile.setPriority(priority); profile.overwritePriority(priority); profile.setNiceValue(niceValue); return true; Loading Loading @@ -694,7 +692,7 @@ public class TunerResourceManagerService extends SystemService implements IBinde } else if (grantingFrontendHandle == TunerResourceManager.INVALID_RESOURCE_HANDLE) { // Record the frontend id with the lowest client priority among all the // in use frontends when no available frontend has been found. int priority = getOwnerClientPriority(fr.getOwnerClientId()); int priority = updateAndGetOwnerClientPriority(fr.getOwnerClientId()); if (currentLowestPriority > priority) { inUseLowestPriorityFrHandle = fr.getHandle(); currentLowestPriority = priority; Loading Loading @@ -760,7 +758,7 @@ public class TunerResourceManagerService extends SystemService implements IBinde } else { // Record the lnb id with the lowest client priority among all the // in use lnb when no available lnb has been found. int priority = getOwnerClientPriority(lnb.getOwnerClientId()); int priority = updateAndGetOwnerClientPriority(lnb.getOwnerClientId()); if (currentLowestPriority > priority) { inUseLowestPriorityLnbHandle = lnb.getHandle(); currentLowestPriority = priority; Loading Loading @@ -818,7 +816,7 @@ public class TunerResourceManagerService extends SystemService implements IBinde } for (int ownerId : cas.getOwnerClientIds()) { // Record the client id with lowest priority that is using the current Cas system. int priority = getOwnerClientPriority(ownerId); int priority = updateAndGetOwnerClientPriority(ownerId); if (currentLowestPriority > priority) { lowestPriorityOwnerId = ownerId; currentLowestPriority = priority; Loading Loading @@ -867,7 +865,7 @@ public class TunerResourceManagerService extends SystemService implements IBinde } for (int ownerId : ciCam.getOwnerClientIds()) { // Record the client id with lowest priority that is using the current Cas system. int priority = getOwnerClientPriority(ownerId); int priority = updateAndGetOwnerClientPriority(ownerId); if (currentLowestPriority > priority) { lowestPriorityOwnerId = ownerId; currentLowestPriority = priority; Loading Loading @@ -966,18 +964,17 @@ public class TunerResourceManagerService extends SystemService implements IBinde } @VisibleForTesting // This mothod is to sync up the request client's foreground/background status and update // the client priority accordingly whenever new resource request comes in. protected void clientPriorityUpdateOnRequest(ClientProfile requestProfile) { int pid = requestProfile.getProcessId(); boolean currentIsForeground = checkIsForeground(pid); if (requestProfile.isForeground() == currentIsForeground) { // This mothod is to sync up the request/holder client's foreground/background status and update // the client priority accordingly whenever a new resource request comes in. protected void clientPriorityUpdateOnRequest(ClientProfile profile) { if (profile.isPriorityOverwritten()) { // To avoid overriding the priority set through updateClientPriority API. return; } requestProfile.setForeground(currentIsForeground); requestProfile.setPriority( getClientPriority(requestProfile.getUseCase(), currentIsForeground)); int pid = profile.getProcessId(); boolean currentIsForeground = checkIsForeground(pid); profile.setPriority( getClientPriority(profile.getUseCase(), currentIsForeground)); } @VisibleForTesting Loading Loading @@ -1154,13 +1151,15 @@ public class TunerResourceManagerService extends SystemService implements IBinde } /** * Get the owner client's priority. * Update and get the owner client's priority. * * @param clientId the owner client id. * @return the priority of the owner client. */ private int getOwnerClientPriority(int clientId) { return getClientProfile(clientId).getPriority(); private int updateAndGetOwnerClientPriority(int clientId) { ClientProfile profile = getClientProfile(clientId); clientPriorityUpdateOnRequest(profile); return profile.getPriority(); } @VisibleForTesting Loading services/tests/servicestests/src/com/android/server/tv/tunerresourcemanager/TunerResourceManagerServiceTest.java +20 −20 Original line number Diff line number Diff line Loading @@ -365,13 +365,13 @@ public class TunerResourceManagerServiceTest { mTunerResourceManagerService.registerClientProfileInternal( profiles[0], listener, clientId0); assertThat(clientId0[0]).isNotEqualTo(TunerResourceManagerService.INVALID_CLIENT_ID); mTunerResourceManagerService.getClientProfile(clientId0[0]) .setPriority(clientPriorities[0]); mTunerResourceManagerService.updateClientPriorityInternal( clientId0[0], clientPriorities[0], 0/*niceValue*/); mTunerResourceManagerService.registerClientProfileInternal( profiles[1], new TestResourcesReclaimListener(), clientId1); assertThat(clientId1[0]).isNotEqualTo(TunerResourceManagerService.INVALID_CLIENT_ID); mTunerResourceManagerService.getClientProfile(clientId1[0]) .setPriority(clientPriorities[1]); mTunerResourceManagerService.updateClientPriorityInternal( clientId1[0], clientPriorities[1], 0/*niceValue*/); // Init frontend resources. TunerFrontendInfo[] infos = new TunerFrontendInfo[2]; Loading Loading @@ -415,13 +415,13 @@ public class TunerResourceManagerServiceTest { mTunerResourceManagerService.registerClientProfileInternal( profiles[0], listener, clientId0); assertThat(clientId0[0]).isNotEqualTo(TunerResourceManagerService.INVALID_CLIENT_ID); mTunerResourceManagerService.getClientProfile(clientId0[0]) .setPriority(clientPriorities[0]); mTunerResourceManagerService.updateClientPriorityInternal( clientId0[0], clientPriorities[0], 0/*niceValue*/); mTunerResourceManagerService.registerClientProfileInternal( profiles[1], new TestResourcesReclaimListener(), clientId1); assertThat(clientId1[0]).isNotEqualTo(TunerResourceManagerService.INVALID_CLIENT_ID); mTunerResourceManagerService.getClientProfile(clientId1[0]) .setPriority(clientPriorities[1]); mTunerResourceManagerService.updateClientPriorityInternal( clientId1[0], clientPriorities[1], 0/*niceValue*/); // Init frontend resources. TunerFrontendInfo[] infos = new TunerFrontendInfo[2]; Loading Loading @@ -511,13 +511,13 @@ public class TunerResourceManagerServiceTest { mTunerResourceManagerService.registerClientProfileInternal( profiles[0], listener, clientId0); assertThat(clientId0[0]).isNotEqualTo(TunerResourceManagerService.INVALID_CLIENT_ID); mTunerResourceManagerService.getClientProfile(clientId0[0]) .setPriority(clientPriorities[0]); mTunerResourceManagerService.updateClientPriorityInternal( clientId0[0], clientPriorities[0], 0/*niceValue*/); mTunerResourceManagerService.registerClientProfileInternal( profiles[1], new TestResourcesReclaimListener(), clientId1); assertThat(clientId1[0]).isNotEqualTo(TunerResourceManagerService.INVALID_CLIENT_ID); mTunerResourceManagerService.getClientProfile(clientId1[0]) .setPriority(clientPriorities[1]); mTunerResourceManagerService.updateClientPriorityInternal( clientId1[0], clientPriorities[1], 0/*niceValue*/); // Init cas resources. mTunerResourceManagerService.updateCasInfoInternal(1 /*casSystemId*/, 2 /*maxSessionNum*/); Loading Loading @@ -567,13 +567,13 @@ public class TunerResourceManagerServiceTest { mTunerResourceManagerService.registerClientProfileInternal( profiles[0], listener, clientId0); assertThat(clientId0[0]).isNotEqualTo(TunerResourceManagerService.INVALID_CLIENT_ID); mTunerResourceManagerService.getClientProfile(clientId0[0]) .setPriority(clientPriorities[0]); mTunerResourceManagerService.updateClientPriorityInternal( clientId0[0], clientPriorities[0], 0/*niceValue*/); mTunerResourceManagerService.registerClientProfileInternal( profiles[1], new TestResourcesReclaimListener(), clientId1); assertThat(clientId1[0]).isNotEqualTo(TunerResourceManagerService.INVALID_CLIENT_ID); mTunerResourceManagerService.getClientProfile(clientId1[0]) .setPriority(clientPriorities[1]); mTunerResourceManagerService.updateClientPriorityInternal( clientId1[0], clientPriorities[1], 0/*niceValue*/); // Init cicam/cas resources. mTunerResourceManagerService.updateCasInfoInternal(1 /*casSystemId*/, 2 /*maxSessionNum*/); Loading Loading @@ -697,13 +697,13 @@ public class TunerResourceManagerServiceTest { mTunerResourceManagerService.registerClientProfileInternal( profiles[0], listener, clientId0); assertThat(clientId0[0]).isNotEqualTo(TunerResourceManagerService.INVALID_CLIENT_ID); mTunerResourceManagerService.getClientProfile(clientId0[0]) .setPriority(clientPriorities[0]); mTunerResourceManagerService.updateClientPriorityInternal( clientId0[0], clientPriorities[0], 0/*niceValue*/); mTunerResourceManagerService.registerClientProfileInternal( profiles[1], new TestResourcesReclaimListener(), clientId1); assertThat(clientId1[0]).isNotEqualTo(TunerResourceManagerService.INVALID_CLIENT_ID); mTunerResourceManagerService.getClientProfile(clientId1[0]) .setPriority(clientPriorities[1]); mTunerResourceManagerService.updateClientPriorityInternal( clientId1[0], clientPriorities[1], 0/*niceValue*/); // Init lnb resources. int[] lnbHandles = {1}; Loading Loading
services/core/java/com/android/server/tv/tunerresourcemanager/ClientProfile.java +20 −12 Original line number Diff line number Diff line Loading @@ -50,8 +50,6 @@ public final class ClientProfile { */ private final int mProcessId; private boolean mIsForeground; /** * All the clients that share the same resource would be under the same group id. * Loading Loading @@ -89,6 +87,12 @@ public final class ClientProfile { */ private int mUsingCiCamId = INVALID_RESOURCE_ID; /** * If the priority is overwritten through * {@link TunerResourceManagerService#setPriority(int, int)}. */ private boolean mIsPriorityOverwritten = false; /** * Optional arbitrary priority value given by the client. * Loading Loading @@ -121,17 +125,10 @@ public final class ClientProfile { } /** * Set the current isForeground status. */ public void setForeground(boolean isForeground) { mIsForeground = isForeground; } /** * Get the previous recorded isForeground status. * If the client priority is overwrttien. */ public boolean isForeground() { return mIsForeground; public boolean isPriorityOverwritten() { return mIsPriorityOverwritten; } public int getGroupId() { Loading @@ -153,6 +150,17 @@ public final class ClientProfile { mPriority = priority; } /** * Overwrite the client priority. */ public void overwritePriority(int priority) { if (priority < 0) { return; } mIsPriorityOverwritten = true; mPriority = priority; } public void setNiceValue(int niceValue) { mNiceValue = niceValue; } Loading
services/core/java/com/android/server/tv/tunerresourcemanager/TunerResourceManagerService.java +19 −20 Original line number Diff line number Diff line Loading @@ -507,9 +507,8 @@ public class TunerResourceManagerService extends SystemService implements IBinde .useCase(profile.useCase) .processId(pid) .build(); clientProfile.setForeground(checkIsForeground(pid)); clientProfile.setPriority( getClientPriority(profile.useCase, clientProfile.isForeground())); getClientPriority(profile.useCase, checkIsForeground(pid))); addClientProfile(clientId[0], clientProfile, listener); } Loading Loading @@ -547,8 +546,7 @@ public class TunerResourceManagerService extends SystemService implements IBinde return false; } profile.setForeground(checkIsForeground(profile.getProcessId())); profile.setPriority(priority); profile.overwritePriority(priority); profile.setNiceValue(niceValue); return true; Loading Loading @@ -694,7 +692,7 @@ public class TunerResourceManagerService extends SystemService implements IBinde } else if (grantingFrontendHandle == TunerResourceManager.INVALID_RESOURCE_HANDLE) { // Record the frontend id with the lowest client priority among all the // in use frontends when no available frontend has been found. int priority = getOwnerClientPriority(fr.getOwnerClientId()); int priority = updateAndGetOwnerClientPriority(fr.getOwnerClientId()); if (currentLowestPriority > priority) { inUseLowestPriorityFrHandle = fr.getHandle(); currentLowestPriority = priority; Loading Loading @@ -760,7 +758,7 @@ public class TunerResourceManagerService extends SystemService implements IBinde } else { // Record the lnb id with the lowest client priority among all the // in use lnb when no available lnb has been found. int priority = getOwnerClientPriority(lnb.getOwnerClientId()); int priority = updateAndGetOwnerClientPriority(lnb.getOwnerClientId()); if (currentLowestPriority > priority) { inUseLowestPriorityLnbHandle = lnb.getHandle(); currentLowestPriority = priority; Loading Loading @@ -818,7 +816,7 @@ public class TunerResourceManagerService extends SystemService implements IBinde } for (int ownerId : cas.getOwnerClientIds()) { // Record the client id with lowest priority that is using the current Cas system. int priority = getOwnerClientPriority(ownerId); int priority = updateAndGetOwnerClientPriority(ownerId); if (currentLowestPriority > priority) { lowestPriorityOwnerId = ownerId; currentLowestPriority = priority; Loading Loading @@ -867,7 +865,7 @@ public class TunerResourceManagerService extends SystemService implements IBinde } for (int ownerId : ciCam.getOwnerClientIds()) { // Record the client id with lowest priority that is using the current Cas system. int priority = getOwnerClientPriority(ownerId); int priority = updateAndGetOwnerClientPriority(ownerId); if (currentLowestPriority > priority) { lowestPriorityOwnerId = ownerId; currentLowestPriority = priority; Loading Loading @@ -966,18 +964,17 @@ public class TunerResourceManagerService extends SystemService implements IBinde } @VisibleForTesting // This mothod is to sync up the request client's foreground/background status and update // the client priority accordingly whenever new resource request comes in. protected void clientPriorityUpdateOnRequest(ClientProfile requestProfile) { int pid = requestProfile.getProcessId(); boolean currentIsForeground = checkIsForeground(pid); if (requestProfile.isForeground() == currentIsForeground) { // This mothod is to sync up the request/holder client's foreground/background status and update // the client priority accordingly whenever a new resource request comes in. protected void clientPriorityUpdateOnRequest(ClientProfile profile) { if (profile.isPriorityOverwritten()) { // To avoid overriding the priority set through updateClientPriority API. return; } requestProfile.setForeground(currentIsForeground); requestProfile.setPriority( getClientPriority(requestProfile.getUseCase(), currentIsForeground)); int pid = profile.getProcessId(); boolean currentIsForeground = checkIsForeground(pid); profile.setPriority( getClientPriority(profile.getUseCase(), currentIsForeground)); } @VisibleForTesting Loading Loading @@ -1154,13 +1151,15 @@ public class TunerResourceManagerService extends SystemService implements IBinde } /** * Get the owner client's priority. * Update and get the owner client's priority. * * @param clientId the owner client id. * @return the priority of the owner client. */ private int getOwnerClientPriority(int clientId) { return getClientProfile(clientId).getPriority(); private int updateAndGetOwnerClientPriority(int clientId) { ClientProfile profile = getClientProfile(clientId); clientPriorityUpdateOnRequest(profile); return profile.getPriority(); } @VisibleForTesting Loading
services/tests/servicestests/src/com/android/server/tv/tunerresourcemanager/TunerResourceManagerServiceTest.java +20 −20 Original line number Diff line number Diff line Loading @@ -365,13 +365,13 @@ public class TunerResourceManagerServiceTest { mTunerResourceManagerService.registerClientProfileInternal( profiles[0], listener, clientId0); assertThat(clientId0[0]).isNotEqualTo(TunerResourceManagerService.INVALID_CLIENT_ID); mTunerResourceManagerService.getClientProfile(clientId0[0]) .setPriority(clientPriorities[0]); mTunerResourceManagerService.updateClientPriorityInternal( clientId0[0], clientPriorities[0], 0/*niceValue*/); mTunerResourceManagerService.registerClientProfileInternal( profiles[1], new TestResourcesReclaimListener(), clientId1); assertThat(clientId1[0]).isNotEqualTo(TunerResourceManagerService.INVALID_CLIENT_ID); mTunerResourceManagerService.getClientProfile(clientId1[0]) .setPriority(clientPriorities[1]); mTunerResourceManagerService.updateClientPriorityInternal( clientId1[0], clientPriorities[1], 0/*niceValue*/); // Init frontend resources. TunerFrontendInfo[] infos = new TunerFrontendInfo[2]; Loading Loading @@ -415,13 +415,13 @@ public class TunerResourceManagerServiceTest { mTunerResourceManagerService.registerClientProfileInternal( profiles[0], listener, clientId0); assertThat(clientId0[0]).isNotEqualTo(TunerResourceManagerService.INVALID_CLIENT_ID); mTunerResourceManagerService.getClientProfile(clientId0[0]) .setPriority(clientPriorities[0]); mTunerResourceManagerService.updateClientPriorityInternal( clientId0[0], clientPriorities[0], 0/*niceValue*/); mTunerResourceManagerService.registerClientProfileInternal( profiles[1], new TestResourcesReclaimListener(), clientId1); assertThat(clientId1[0]).isNotEqualTo(TunerResourceManagerService.INVALID_CLIENT_ID); mTunerResourceManagerService.getClientProfile(clientId1[0]) .setPriority(clientPriorities[1]); mTunerResourceManagerService.updateClientPriorityInternal( clientId1[0], clientPriorities[1], 0/*niceValue*/); // Init frontend resources. TunerFrontendInfo[] infos = new TunerFrontendInfo[2]; Loading Loading @@ -511,13 +511,13 @@ public class TunerResourceManagerServiceTest { mTunerResourceManagerService.registerClientProfileInternal( profiles[0], listener, clientId0); assertThat(clientId0[0]).isNotEqualTo(TunerResourceManagerService.INVALID_CLIENT_ID); mTunerResourceManagerService.getClientProfile(clientId0[0]) .setPriority(clientPriorities[0]); mTunerResourceManagerService.updateClientPriorityInternal( clientId0[0], clientPriorities[0], 0/*niceValue*/); mTunerResourceManagerService.registerClientProfileInternal( profiles[1], new TestResourcesReclaimListener(), clientId1); assertThat(clientId1[0]).isNotEqualTo(TunerResourceManagerService.INVALID_CLIENT_ID); mTunerResourceManagerService.getClientProfile(clientId1[0]) .setPriority(clientPriorities[1]); mTunerResourceManagerService.updateClientPriorityInternal( clientId1[0], clientPriorities[1], 0/*niceValue*/); // Init cas resources. mTunerResourceManagerService.updateCasInfoInternal(1 /*casSystemId*/, 2 /*maxSessionNum*/); Loading Loading @@ -567,13 +567,13 @@ public class TunerResourceManagerServiceTest { mTunerResourceManagerService.registerClientProfileInternal( profiles[0], listener, clientId0); assertThat(clientId0[0]).isNotEqualTo(TunerResourceManagerService.INVALID_CLIENT_ID); mTunerResourceManagerService.getClientProfile(clientId0[0]) .setPriority(clientPriorities[0]); mTunerResourceManagerService.updateClientPriorityInternal( clientId0[0], clientPriorities[0], 0/*niceValue*/); mTunerResourceManagerService.registerClientProfileInternal( profiles[1], new TestResourcesReclaimListener(), clientId1); assertThat(clientId1[0]).isNotEqualTo(TunerResourceManagerService.INVALID_CLIENT_ID); mTunerResourceManagerService.getClientProfile(clientId1[0]) .setPriority(clientPriorities[1]); mTunerResourceManagerService.updateClientPriorityInternal( clientId1[0], clientPriorities[1], 0/*niceValue*/); // Init cicam/cas resources. mTunerResourceManagerService.updateCasInfoInternal(1 /*casSystemId*/, 2 /*maxSessionNum*/); Loading Loading @@ -697,13 +697,13 @@ public class TunerResourceManagerServiceTest { mTunerResourceManagerService.registerClientProfileInternal( profiles[0], listener, clientId0); assertThat(clientId0[0]).isNotEqualTo(TunerResourceManagerService.INVALID_CLIENT_ID); mTunerResourceManagerService.getClientProfile(clientId0[0]) .setPriority(clientPriorities[0]); mTunerResourceManagerService.updateClientPriorityInternal( clientId0[0], clientPriorities[0], 0/*niceValue*/); mTunerResourceManagerService.registerClientProfileInternal( profiles[1], new TestResourcesReclaimListener(), clientId1); assertThat(clientId1[0]).isNotEqualTo(TunerResourceManagerService.INVALID_CLIENT_ID); mTunerResourceManagerService.getClientProfile(clientId1[0]) .setPriority(clientPriorities[1]); mTunerResourceManagerService.updateClientPriorityInternal( clientId1[0], clientPriorities[1], 0/*niceValue*/); // Init lnb resources. int[] lnbHandles = {1}; Loading