Merge "Complete the resource reclaim implementation in TRM" into rvc-dev
This commit is contained in:
@@ -143,8 +143,6 @@ public final class ClientProfile {
|
|||||||
/**
|
/**
|
||||||
* Called when the client released a frontend.
|
* Called when the client released a frontend.
|
||||||
*
|
*
|
||||||
* <p>This could happen when client resource reclaimed.
|
|
||||||
*
|
|
||||||
* @param frontendId being released.
|
* @param frontendId being released.
|
||||||
*/
|
*/
|
||||||
public void releaseFrontend(int frontendId) {
|
public void releaseFrontend(int frontendId) {
|
||||||
@@ -167,14 +165,20 @@ public final class ClientProfile {
|
|||||||
/**
|
/**
|
||||||
* Called when the client released an lnb.
|
* Called when the client released an lnb.
|
||||||
*
|
*
|
||||||
* <p>This could happen when client resource reclaimed.
|
|
||||||
*
|
|
||||||
* @param lnbId being released.
|
* @param lnbId being released.
|
||||||
*/
|
*/
|
||||||
public void releaseLnb(int lnbId) {
|
public void releaseLnb(int lnbId) {
|
||||||
mUsingLnbIds.remove(lnbId);
|
mUsingLnbIds.remove(lnbId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called to reclaim all the resources being used by the current client.
|
||||||
|
*/
|
||||||
|
public void reclaimAllResources() {
|
||||||
|
mUsingFrontendIds.clear();
|
||||||
|
mUsingLnbIds.clear();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ClientProfile[id=" + this.mId + ", tvInputSessionId=" + this.mTvInputSessionId
|
return "ClientProfile[id=" + this.mId + ", tvInputSessionId=" + this.mTvInputSessionId
|
||||||
|
|||||||
@@ -516,10 +516,12 @@ public class TunerResourceManagerService extends SystemService {
|
|||||||
// When all the resources are occupied, grant the lowest priority resource if the
|
// When all the resources are occupied, grant the lowest priority resource if the
|
||||||
// request client has higher priority.
|
// request client has higher priority.
|
||||||
if (inUseLowestPriorityFrId > -1 && (requestClient.getPriority() > currentLowestPriority)) {
|
if (inUseLowestPriorityFrId > -1 && (requestClient.getPriority() > currentLowestPriority)) {
|
||||||
|
if (!reclaimResource(getFrontendResource(inUseLowestPriorityFrId).getOwnerClientId(),
|
||||||
|
TunerResourceManager.TUNER_RESOURCE_TYPE_FRONTEND)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
frontendHandle[0] = generateResourceHandle(
|
frontendHandle[0] = generateResourceHandle(
|
||||||
TunerResourceManager.TUNER_RESOURCE_TYPE_FRONTEND, inUseLowestPriorityFrId);
|
TunerResourceManager.TUNER_RESOURCE_TYPE_FRONTEND, inUseLowestPriorityFrId);
|
||||||
reclaimResource(getFrontendResource(inUseLowestPriorityFrId).getOwnerClientId(),
|
|
||||||
TunerResourceManager.TUNER_RESOURCE_TYPE_FRONTEND);
|
|
||||||
updateFrontendClientMappingOnNewGrant(inUseLowestPriorityFrId, request.getClientId());
|
updateFrontendClientMappingOnNewGrant(inUseLowestPriorityFrId, request.getClientId());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -572,10 +574,12 @@ public class TunerResourceManagerService extends SystemService {
|
|||||||
// request client has higher priority.
|
// request client has higher priority.
|
||||||
if (inUseLowestPriorityLnbId > -1
|
if (inUseLowestPriorityLnbId > -1
|
||||||
&& (requestClient.getPriority() > currentLowestPriority)) {
|
&& (requestClient.getPriority() > currentLowestPriority)) {
|
||||||
|
if (!reclaimResource(getLnbResource(inUseLowestPriorityLnbId).getOwnerClientId(),
|
||||||
|
TunerResourceManager.TUNER_RESOURCE_TYPE_LNB)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
lnbHandle[0] = generateResourceHandle(
|
lnbHandle[0] = generateResourceHandle(
|
||||||
TunerResourceManager.TUNER_RESOURCE_TYPE_LNB, inUseLowestPriorityLnbId);
|
TunerResourceManager.TUNER_RESOURCE_TYPE_LNB, inUseLowestPriorityLnbId);
|
||||||
reclaimResource(getLnbResource(inUseLowestPriorityLnbId).getOwnerClientId(),
|
|
||||||
TunerResourceManager.TUNER_RESOURCE_TYPE_LNB);
|
|
||||||
updateLnbClientMappingOnNewGrant(inUseLowestPriorityLnbId, request.getClientId());
|
updateLnbClientMappingOnNewGrant(inUseLowestPriorityLnbId, request.getClientId());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -668,18 +672,21 @@ public class TunerResourceManagerService extends SystemService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected void reclaimResource(int reclaimingId,
|
protected boolean reclaimResource(int reclaimingClientId,
|
||||||
@TunerResourceManager.TunerResourceType int resourceType) {
|
@TunerResourceManager.TunerResourceType int resourceType) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Slog.d(TAG, "Reclaiming resources because higher priority client request resource type "
|
Slog.d(TAG, "Reclaiming resources because higher priority client request resource type "
|
||||||
+ resourceType);
|
+ resourceType);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
mListeners.get(reclaimingId).getListener().onReclaimResources();
|
mListeners.get(reclaimingClientId).getListener().onReclaimResources();
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Slog.e(TAG, "Failed to reclaim resources on client " + reclaimingId, e);
|
Slog.e(TAG, "Failed to reclaim resources on client " + reclaimingClientId, e);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
// TODO clean all the client and resources mapping/ownership
|
ClientProfile profile = getClientProfile(reclaimingClientId);
|
||||||
|
reclaimingResourcesFromClient(profile);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -833,6 +840,16 @@ public class TunerResourceManagerService extends SystemService {
|
|||||||
mListeners.remove(clientId);
|
mListeners.remove(clientId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void reclaimingResourcesFromClient(ClientProfile profile) {
|
||||||
|
for (Integer feId : profile.getInUseFrontendIds()) {
|
||||||
|
getFrontendResource(feId).removeOwner();
|
||||||
|
}
|
||||||
|
for (Integer lnbId : profile.getInUseLnbIds()) {
|
||||||
|
getLnbResource(lnbId).removeOwner();
|
||||||
|
}
|
||||||
|
profile.reclaimAllResources();
|
||||||
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected boolean checkClientExists(int clientId) {
|
protected boolean checkClientExists(int clientId) {
|
||||||
return mClientProfiles.keySet().contains(clientId);
|
return mClientProfiles.keySet().contains(clientId);
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ import org.mockito.Mock;
|
|||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -463,6 +464,9 @@ public class TunerResourceManagerServiceTest {
|
|||||||
}
|
}
|
||||||
assertThat(mTunerResourceManagerService.getResourceIdFromHandle(frontendHandle[0]))
|
assertThat(mTunerResourceManagerService.getResourceIdFromHandle(frontendHandle[0]))
|
||||||
.isEqualTo(infos[0].getId());
|
.isEqualTo(infos[0].getId());
|
||||||
|
assertThat(mTunerResourceManagerService.getClientProfile(clientId0[0])
|
||||||
|
.getInUseFrontendIds()).isEqualTo(
|
||||||
|
new HashSet<Integer>(Arrays.asList(infos[0].getId(), infos[1].getId())));
|
||||||
|
|
||||||
request =
|
request =
|
||||||
new TunerFrontendRequest(clientId1[0] /*clientId*/, FrontendSettings.TYPE_DVBS);
|
new TunerFrontendRequest(clientId1[0] /*clientId*/, FrontendSettings.TYPE_DVBS);
|
||||||
@@ -553,7 +557,7 @@ public class TunerResourceManagerServiceTest {
|
|||||||
.setPriority(clientPriorities[1]);
|
.setPriority(clientPriorities[1]);
|
||||||
|
|
||||||
// Init lnb resources.
|
// Init lnb resources.
|
||||||
int[] lnbIds = {0};
|
int[] lnbIds = {1};
|
||||||
mTunerResourceManagerService.setLnbInfoListInternal(lnbIds);
|
mTunerResourceManagerService.setLnbInfoListInternal(lnbIds);
|
||||||
|
|
||||||
TunerLnbRequest request = new TunerLnbRequest(clientId0[0]);
|
TunerLnbRequest request = new TunerLnbRequest(clientId0[0]);
|
||||||
@@ -566,6 +570,8 @@ public class TunerResourceManagerServiceTest {
|
|||||||
}
|
}
|
||||||
assertThat(mTunerResourceManagerService.getResourceIdFromHandle(lnbHandle[0]))
|
assertThat(mTunerResourceManagerService.getResourceIdFromHandle(lnbHandle[0]))
|
||||||
.isEqualTo(lnbIds[0]);
|
.isEqualTo(lnbIds[0]);
|
||||||
|
assertThat(mTunerResourceManagerService.getClientProfile(clientId0[0])
|
||||||
|
.getInUseLnbIds()).isEqualTo(new HashSet<Integer>(Arrays.asList(lnbIds[0])));
|
||||||
|
|
||||||
request = new TunerLnbRequest(clientId1[0]);
|
request = new TunerLnbRequest(clientId1[0]);
|
||||||
try {
|
try {
|
||||||
@@ -581,6 +587,8 @@ public class TunerResourceManagerServiceTest {
|
|||||||
assertThat(mTunerResourceManagerService.getLnbResource(lnbIds[0])
|
assertThat(mTunerResourceManagerService.getLnbResource(lnbIds[0])
|
||||||
.getOwnerClientId()).isEqualTo(clientId1[0]);
|
.getOwnerClientId()).isEqualTo(clientId1[0]);
|
||||||
assertThat(listener.isRelaimed()).isTrue();
|
assertThat(listener.isRelaimed()).isTrue();
|
||||||
|
assertThat(mTunerResourceManagerService.getClientProfile(clientId0[0])
|
||||||
|
.getInUseLnbIds().size()).isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user