Merge "Change unnecessary List usage in TRM to Set" into rvc-dev
This commit is contained in:
@@ -15,8 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.server.tv.tunerresourcemanager;
|
package com.android.server.tv.tunerresourcemanager;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A client profile object used by the Tuner Resource Manager to record the registered clients'
|
* A client profile object used by the Tuner Resource Manager to record the registered clients'
|
||||||
@@ -65,7 +65,7 @@ public final class ClientProfile {
|
|||||||
/**
|
/**
|
||||||
* List of the frontend ids that are used by the current client.
|
* List of the frontend ids that are used by the current client.
|
||||||
*/
|
*/
|
||||||
private List<Integer> mUsingFrontendIds = new ArrayList<>();
|
private Set<Integer> mUsingFrontendIds = new HashSet<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optional arbitrary priority value given by the client.
|
* Optional arbitrary priority value given by the client.
|
||||||
@@ -131,7 +131,7 @@ public final class ClientProfile {
|
|||||||
mUsingFrontendIds.add(frontendId);
|
mUsingFrontendIds.add(frontendId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Integer> getInUseFrontendIds() {
|
public Iterable<Integer> getInUseFrontendIds() {
|
||||||
return mUsingFrontendIds;
|
return mUsingFrontendIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,12 +15,11 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.server.tv.tunerresourcemanager;
|
package com.android.server.tv.tunerresourcemanager;
|
||||||
|
|
||||||
import android.annotation.Nullable;
|
|
||||||
import android.media.tv.tuner.frontend.FrontendSettings.Type;
|
import android.media.tv.tuner.frontend.FrontendSettings.Type;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.Collection;
|
||||||
import java.util.Arrays;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A frontend resource object used by the Tuner Resource Manager to record the tuner frontend
|
* A frontend resource object used by the Tuner Resource Manager to record the tuner frontend
|
||||||
@@ -50,7 +49,7 @@ public final class FrontendResource {
|
|||||||
/**
|
/**
|
||||||
* An array to save all the FE ids under the same exclisive group.
|
* An array to save all the FE ids under the same exclisive group.
|
||||||
*/
|
*/
|
||||||
private List<Integer> mExclusiveGroupMemberFeIds = new ArrayList<>();
|
private Set<Integer> mExclusiveGroupMemberFeIds = new HashSet<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the current resource is in use. Once resources under the same exclusive group id is in use
|
* If the current resource is in use. Once resources under the same exclusive group id is in use
|
||||||
@@ -82,12 +81,12 @@ public final class FrontendResource {
|
|||||||
return mExclusiveGroupId;
|
return mExclusiveGroupId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Integer> getExclusiveGroupMemberFeIds() {
|
public Set<Integer> getExclusiveGroupMemberFeIds() {
|
||||||
return mExclusiveGroupMemberFeIds;
|
return mExclusiveGroupMemberFeIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add one id into the exclusive group member id list.
|
* Add one id into the exclusive group member id collection.
|
||||||
*
|
*
|
||||||
* @param id the id to be added.
|
* @param id the id to be added.
|
||||||
*/
|
*/
|
||||||
@@ -96,21 +95,21 @@ public final class FrontendResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add one id list to the exclusive group member id list.
|
* Add one id collection to the exclusive group member id collection.
|
||||||
*
|
*
|
||||||
* @param ids the id list to be added.
|
* @param ids the id collection to be added.
|
||||||
*/
|
*/
|
||||||
public void addExclusiveGroupMemberFeId(List<Integer> ids) {
|
public void addExclusiveGroupMemberFeIds(Collection<Integer> ids) {
|
||||||
mExclusiveGroupMemberFeIds.addAll(ids);
|
mExclusiveGroupMemberFeIds.addAll(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove one id from the exclusive group member id list.
|
* Remove one id from the exclusive group member id collection.
|
||||||
*
|
*
|
||||||
* @param id the id to be removed.
|
* @param id the id to be removed.
|
||||||
*/
|
*/
|
||||||
public void removeExclusiveGroupMemberFeId(int id) {
|
public void removeExclusiveGroupMemberFeId(int id) {
|
||||||
mExclusiveGroupMemberFeIds.remove(new Integer(id));
|
mExclusiveGroupMemberFeIds.remove(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInUse() {
|
public boolean isInUse() {
|
||||||
@@ -143,22 +142,10 @@ public final class FrontendResource {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return "FrontendResource[id=" + this.mId + ", type=" + this.mType
|
return "FrontendResource[id=" + this.mId + ", type=" + this.mType
|
||||||
+ ", exclusiveGId=" + this.mExclusiveGroupId + ", exclusiveGMemeberIds="
|
+ ", exclusiveGId=" + this.mExclusiveGroupId + ", exclusiveGMemeberIds="
|
||||||
+ Arrays.toString(this.mExclusiveGroupMemberFeIds.toArray())
|
+ this.mExclusiveGroupMemberFeIds
|
||||||
+ ", isInUse=" + this.mIsInUse + ", ownerClientId=" + this.mOwnerClientId + "]";
|
+ ", isInUse=" + this.mIsInUse + ", ownerClientId=" + this.mOwnerClientId + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(@Nullable Object o) {
|
|
||||||
if (o instanceof FrontendResource) {
|
|
||||||
FrontendResource fe = (FrontendResource) o;
|
|
||||||
return mId == fe.getId() && mType == fe.getType()
|
|
||||||
&& mExclusiveGroupId == fe.getExclusiveGroupId()
|
|
||||||
&& mExclusiveGroupMemberFeIds.equals(fe.getExclusiveGroupMemberFeIds())
|
|
||||||
&& mIsInUse == fe.isInUse() && mOwnerClientId == fe.getOwnerClientId();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder class for {@link FrontendResource}.
|
* Builder class for {@link FrontendResource}.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -37,8 +37,10 @@ import android.util.SparseArray;
|
|||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.server.SystemService;
|
import com.android.server.SystemService;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides a system service that manages the TV tuner resources.
|
* This class provides a system service that manages the TV tuner resources.
|
||||||
@@ -52,16 +54,12 @@ public class TunerResourceManagerService extends SystemService {
|
|||||||
public static final int INVALID_CLIENT_ID = -1;
|
public static final int INVALID_CLIENT_ID = -1;
|
||||||
private static final int MAX_CLIENT_PRIORITY = 1000;
|
private static final int MAX_CLIENT_PRIORITY = 1000;
|
||||||
|
|
||||||
// Array of the registered client profiles
|
// Map of the registered client profiles
|
||||||
@VisibleForTesting private SparseArray<ClientProfile> mClientProfiles = new SparseArray<>();
|
private Map<Integer, ClientProfile> mClientProfiles = new HashMap<>();
|
||||||
private int mNextUnusedClientId = 0;
|
private int mNextUnusedClientId = 0;
|
||||||
private List<Integer> mRegisteredClientIds = new ArrayList<Integer>();
|
|
||||||
|
|
||||||
// Array of the current available frontend resources
|
// Map of the current available frontend resources
|
||||||
@VisibleForTesting
|
private Map<Integer, FrontendResource> mFrontendResources = new HashMap<>();
|
||||||
private SparseArray<FrontendResource> mFrontendResources = new SparseArray<>();
|
|
||||||
// Array of the current available frontend ids
|
|
||||||
private List<Integer> mAvailableFrontendIds = new ArrayList<Integer>();
|
|
||||||
|
|
||||||
private SparseArray<IResourcesReclaimListener> mListeners = new SparseArray<>();
|
private SparseArray<IResourcesReclaimListener> mListeners = new SparseArray<>();
|
||||||
|
|
||||||
@@ -261,9 +259,8 @@ public class TunerResourceManagerService extends SystemService {
|
|||||||
.build();
|
.build();
|
||||||
clientProfile.setPriority(getClientPriority(profile.getUseCase(), pid));
|
clientProfile.setPriority(getClientPriority(profile.getUseCase(), pid));
|
||||||
|
|
||||||
mClientProfiles.append(clientId[0], clientProfile);
|
addClientProfile(clientId[0], clientProfile);
|
||||||
mListeners.append(clientId[0], listener);
|
mListeners.append(clientId[0], listener);
|
||||||
mRegisteredClientIds.add(clientId[0]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -271,15 +268,8 @@ public class TunerResourceManagerService extends SystemService {
|
|||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Slog.d(TAG, "unregisterClientProfile(clientId=" + clientId + ")");
|
Slog.d(TAG, "unregisterClientProfile(clientId=" + clientId + ")");
|
||||||
}
|
}
|
||||||
for (int id : getClientProfile(clientId).getInUseFrontendIds()) {
|
removeClientProfile(clientId);
|
||||||
getFrontendResource(id).removeOwner();
|
|
||||||
for (int groupMemberId : getFrontendResource(id).getExclusiveGroupMemberFeIds()) {
|
|
||||||
getFrontendResource(groupMemberId).removeOwner();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mClientProfiles.remove(clientId);
|
|
||||||
mListeners.remove(clientId);
|
mListeners.remove(clientId);
|
||||||
mRegisteredClientIds.remove(clientId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -313,56 +303,32 @@ public class TunerResourceManagerService extends SystemService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// An arrayList to record the frontends pending on updating. Ids will be removed
|
// A set to record the frontends pending on updating. Ids will be removed
|
||||||
// from this list once its updating finished. Any frontend left in this list when all
|
// from this set once its updating finished. Any frontend left in this set when all
|
||||||
// the updates are done will be removed from mAvailableFrontendIds and
|
// the updates are done will be removed from mFrontendResources.
|
||||||
// mFrontendResources.
|
Set<Integer> updatingFrontendIds = new HashSet<>(getFrontendResources().keySet());
|
||||||
List<Integer> updatingFrontendIds = new ArrayList<>(mAvailableFrontendIds);
|
|
||||||
|
|
||||||
// Update frontendResources sparse array and other mappings accordingly
|
// Update frontendResources map and other mappings accordingly
|
||||||
for (int i = 0; i < infos.length; i++) {
|
for (int i = 0; i < infos.length; i++) {
|
||||||
if (getFrontendResource(infos[i].getId()) != null) {
|
if (getFrontendResource(infos[i].getId()) != null) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Slog.d(TAG, "Frontend id=" + infos[i].getId() + "exists.");
|
Slog.d(TAG, "Frontend id=" + infos[i].getId() + "exists.");
|
||||||
}
|
}
|
||||||
updatingFrontendIds.remove(new Integer(infos[i].getId()));
|
updatingFrontendIds.remove(infos[i].getId());
|
||||||
} else {
|
} else {
|
||||||
// Add a new fe resource
|
// Add a new fe resource
|
||||||
FrontendResource newFe = new FrontendResource.Builder(infos[i].getId())
|
FrontendResource newFe = new FrontendResource.Builder(infos[i].getId())
|
||||||
.type(infos[i].getFrontendType())
|
.type(infos[i].getFrontendType())
|
||||||
.exclusiveGroupId(infos[i].getExclusiveGroupId())
|
.exclusiveGroupId(infos[i].getExclusiveGroupId())
|
||||||
.build();
|
.build();
|
||||||
// Update the exclusive group member list in all the existing Frontend resource
|
addFrontendResource(newFe);
|
||||||
for (Integer feId : mAvailableFrontendIds) {
|
|
||||||
FrontendResource fe = getFrontendResource(feId.intValue());
|
|
||||||
if (fe.getExclusiveGroupId() == newFe.getExclusiveGroupId()) {
|
|
||||||
newFe.addExclusiveGroupMemberFeId(fe.getId());
|
|
||||||
newFe.addExclusiveGroupMemberFeId(fe.getExclusiveGroupMemberFeIds());
|
|
||||||
for (Integer excGroupmemberFeId : fe.getExclusiveGroupMemberFeIds()) {
|
|
||||||
getFrontendResource(excGroupmemberFeId.intValue())
|
|
||||||
.addExclusiveGroupMemberFeId(newFe.getId());
|
|
||||||
}
|
|
||||||
fe.addExclusiveGroupMemberFeId(newFe.getId());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Update resource list and available id list
|
|
||||||
mFrontendResources.append(newFe.getId(), newFe);
|
|
||||||
mAvailableFrontendIds.add(newFe.getId());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO check if the removing resource is in use or not. Handle the conflict.
|
// TODO check if the removing resource is in use or not. Handle the conflict.
|
||||||
for (Integer removingId : updatingFrontendIds) {
|
for (int removingId : updatingFrontendIds) {
|
||||||
// update the exclusive group id memver list
|
// update the exclusive group id member list
|
||||||
FrontendResource fe = getFrontendResource(removingId.intValue());
|
removeFrontendResource(removingId);
|
||||||
fe.removeExclusiveGroupMemberFeId(new Integer(fe.getId()));
|
|
||||||
for (Integer excGroupmemberFeId : fe.getExclusiveGroupMemberFeIds()) {
|
|
||||||
getFrontendResource(excGroupmemberFeId.intValue())
|
|
||||||
.removeExclusiveGroupMemberFeId(new Integer(fe.getId()));
|
|
||||||
}
|
|
||||||
mFrontendResources.remove(removingId.intValue());
|
|
||||||
mAvailableFrontendIds.remove(removingId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -383,25 +349,24 @@ public class TunerResourceManagerService extends SystemService {
|
|||||||
int inUseLowestPriorityFrId = -1;
|
int inUseLowestPriorityFrId = -1;
|
||||||
// Priority max value is 1000
|
// Priority max value is 1000
|
||||||
int currentLowestPriority = MAX_CLIENT_PRIORITY + 1;
|
int currentLowestPriority = MAX_CLIENT_PRIORITY + 1;
|
||||||
for (int id : mAvailableFrontendIds) {
|
for (FrontendResource fr : getFrontendResources().values()) {
|
||||||
FrontendResource fr = getFrontendResource(id);
|
|
||||||
if (fr.getType() == request.getFrontendType()) {
|
if (fr.getType() == request.getFrontendType()) {
|
||||||
if (!fr.isInUse()) {
|
if (!fr.isInUse()) {
|
||||||
// Grant unused frontend with no exclusive group members first.
|
// Grant unused frontend with no exclusive group members first.
|
||||||
if (fr.getExclusiveGroupMemberFeIds().size() == 0) {
|
if (fr.getExclusiveGroupMemberFeIds().isEmpty()) {
|
||||||
grantingFrontendId = id;
|
grantingFrontendId = fr.getId();
|
||||||
break;
|
break;
|
||||||
} else if (grantingFrontendId < 0) {
|
} else if (grantingFrontendId < 0) {
|
||||||
// Grant the unused frontend with lower id first if all the unused
|
// Grant the unused frontend with lower id first if all the unused
|
||||||
// frontends have exclusive group members.
|
// frontends have exclusive group members.
|
||||||
grantingFrontendId = id;
|
grantingFrontendId = fr.getId();
|
||||||
}
|
}
|
||||||
} else if (grantingFrontendId < 0) {
|
} else if (grantingFrontendId < 0) {
|
||||||
// Record the frontend id with the lowest client priority among all the
|
// Record the frontend id with the lowest client priority among all the
|
||||||
// in use frontends when no available frontend has been found.
|
// in use frontends when no available frontend has been found.
|
||||||
int priority = getOwnerClientPriority(id);
|
int priority = getOwnerClientPriority(fr);
|
||||||
if (currentLowestPriority > priority) {
|
if (currentLowestPriority > priority) {
|
||||||
inUseLowestPriorityFrId = id;
|
inUseLowestPriorityFrId = fr.getId();
|
||||||
currentLowestPriority = priority;
|
currentLowestPriority = priority;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -471,33 +436,73 @@ public class TunerResourceManagerService extends SystemService {
|
|||||||
/**
|
/**
|
||||||
* Get the owner client's priority from the frontend id.
|
* Get the owner client's priority from the frontend id.
|
||||||
*
|
*
|
||||||
* @param frontendId an in use frontend id.
|
* @param frontend an in use frontend.
|
||||||
* @return the priority of the owner client of the frontend.
|
* @return the priority of the owner client of the frontend.
|
||||||
*/
|
*/
|
||||||
private int getOwnerClientPriority(int frontendId) {
|
private int getOwnerClientPriority(FrontendResource frontend) {
|
||||||
return getClientProfile(getFrontendResource(frontendId).getOwnerClientId()).getPriority();
|
return getClientProfile(frontend.getOwnerClientId()).getPriority();
|
||||||
}
|
|
||||||
|
|
||||||
private ClientProfile getClientProfile(int clientId) {
|
|
||||||
return mClientProfiles.get(clientId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
@Nullable
|
||||||
protected FrontendResource getFrontendResource(int frontendId) {
|
protected FrontendResource getFrontendResource(int frontendId) {
|
||||||
return mFrontendResources.get(frontendId);
|
return mFrontendResources.get(frontendId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected SparseArray<ClientProfile> getClientProfiles() {
|
protected Map<Integer, FrontendResource> getFrontendResources() {
|
||||||
return mClientProfiles;
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
protected SparseArray<FrontendResource> getFrontendResources() {
|
|
||||||
return mFrontendResources;
|
return mFrontendResources;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addFrontendResource(FrontendResource newFe) {
|
||||||
|
// Update the exclusive group member list in all the existing Frontend resource
|
||||||
|
for (FrontendResource fe : getFrontendResources().values()) {
|
||||||
|
if (fe.getExclusiveGroupId() == newFe.getExclusiveGroupId()) {
|
||||||
|
newFe.addExclusiveGroupMemberFeId(fe.getId());
|
||||||
|
newFe.addExclusiveGroupMemberFeIds(fe.getExclusiveGroupMemberFeIds());
|
||||||
|
for (int excGroupmemberFeId : fe.getExclusiveGroupMemberFeIds()) {
|
||||||
|
getFrontendResource(excGroupmemberFeId)
|
||||||
|
.addExclusiveGroupMemberFeId(newFe.getId());
|
||||||
|
}
|
||||||
|
fe.addExclusiveGroupMemberFeId(newFe.getId());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Update resource list and available id list
|
||||||
|
mFrontendResources.put(newFe.getId(), newFe);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeFrontendResource(int removingId) {
|
||||||
|
FrontendResource fe = getFrontendResource(removingId);
|
||||||
|
for (int excGroupmemberFeId : fe.getExclusiveGroupMemberFeIds()) {
|
||||||
|
getFrontendResource(excGroupmemberFeId)
|
||||||
|
.removeExclusiveGroupMemberFeId(fe.getId());
|
||||||
|
}
|
||||||
|
mFrontendResources.remove(removingId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
@Nullable
|
||||||
|
protected ClientProfile getClientProfile(int clientId) {
|
||||||
|
return mClientProfiles.get(clientId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addClientProfile(int clientId, ClientProfile profile) {
|
||||||
|
mClientProfiles.put(clientId, profile);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeClientProfile(int clientId) {
|
||||||
|
for (int id : getClientProfile(clientId).getInUseFrontendIds()) {
|
||||||
|
getFrontendResource(id).removeOwner();
|
||||||
|
for (int groupMemberId : getFrontendResource(id).getExclusiveGroupMemberFeIds()) {
|
||||||
|
getFrontendResource(groupMemberId).removeOwner();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mClientProfiles.remove(clientId);
|
||||||
|
}
|
||||||
|
|
||||||
private boolean checkClientExists(int clientId) {
|
private boolean checkClientExists(int clientId) {
|
||||||
return mRegisteredClientIds.contains(clientId);
|
return mClientProfiles.keySet().contains(clientId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enforceAccessPermission() {
|
private void enforceAccessPermission() {
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ import java.io.File;
|
|||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides the Tuner Resource Manager use case priority hints config info including a
|
* This class provides the Tuner Resource Manager use case priority hints config info including a
|
||||||
@@ -56,7 +56,7 @@ public class UseCasePriorityHints {
|
|||||||
*/
|
*/
|
||||||
SparseArray<int[]> mPriorityHints = new SparseArray<>();
|
SparseArray<int[]> mPriorityHints = new SparseArray<>();
|
||||||
|
|
||||||
List<Integer> mVendorDefinedUseCase = new ArrayList<>();
|
Set<Integer> mVendorDefinedUseCase = new HashSet<>();
|
||||||
|
|
||||||
private int mDefaultForeground = 150;
|
private int mDefaultForeground = 150;
|
||||||
private int mDefaultBackground = 50;
|
private int mDefaultBackground = 50;
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ import org.mockito.MockitoAnnotations;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link TunerResourceManagerService} class.
|
* Tests for {@link TunerResourceManagerService} class.
|
||||||
@@ -118,7 +119,7 @@ public class TunerResourceManagerServiceTest {
|
|||||||
new TunerFrontendInfo(1 /*id*/, FrontendSettings.TYPE_DVBT, 1 /*exclusiveGroupId*/);
|
new TunerFrontendInfo(1 /*id*/, FrontendSettings.TYPE_DVBT, 1 /*exclusiveGroupId*/);
|
||||||
mTunerResourceManagerService.setFrontendInfoListInternal(infos);
|
mTunerResourceManagerService.setFrontendInfoListInternal(infos);
|
||||||
|
|
||||||
SparseArray<FrontendResource> resources =
|
Map<Integer, FrontendResource> resources =
|
||||||
mTunerResourceManagerService.getFrontendResources();
|
mTunerResourceManagerService.getFrontendResources();
|
||||||
for (int id = 0; id < infos.length; id++) {
|
for (int id = 0; id < infos.length; id++) {
|
||||||
assertThat(resources.get(infos[id].getId())
|
assertThat(resources.get(infos[id].getId())
|
||||||
@@ -128,7 +129,7 @@ public class TunerResourceManagerServiceTest {
|
|||||||
assertThat(resources.get(infos[id].getId())
|
assertThat(resources.get(infos[id].getId())
|
||||||
.getExclusiveGroupMemberFeIds().size()).isEqualTo(0);
|
.getExclusiveGroupMemberFeIds().size()).isEqualTo(0);
|
||||||
}
|
}
|
||||||
assertThat(sparseArrayToList(resources)).comparingElementsUsing(FR_TFI_COMPARE)
|
assertThat(resources.values()).comparingElementsUsing(FR_TFI_COMPARE)
|
||||||
.containsExactlyElementsIn(Arrays.asList(infos));
|
.containsExactlyElementsIn(Arrays.asList(infos));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,19 +147,15 @@ public class TunerResourceManagerServiceTest {
|
|||||||
new TunerFrontendInfo(3 /*id*/, FrontendSettings.TYPE_ATSC, 1 /*exclusiveGroupId*/);
|
new TunerFrontendInfo(3 /*id*/, FrontendSettings.TYPE_ATSC, 1 /*exclusiveGroupId*/);
|
||||||
mTunerResourceManagerService.setFrontendInfoListInternal(infos);
|
mTunerResourceManagerService.setFrontendInfoListInternal(infos);
|
||||||
|
|
||||||
SparseArray<FrontendResource> resources =
|
Map<Integer, FrontendResource> resources =
|
||||||
mTunerResourceManagerService.getFrontendResources();
|
mTunerResourceManagerService.getFrontendResources();
|
||||||
assertThat(sparseArrayToList(resources)).comparingElementsUsing(FR_TFI_COMPARE)
|
assertThat(resources.values()).comparingElementsUsing(FR_TFI_COMPARE)
|
||||||
.containsExactlyElementsIn(Arrays.asList(infos));
|
.containsExactlyElementsIn(Arrays.asList(infos));
|
||||||
|
|
||||||
assertThat(resources.get(0).getExclusiveGroupMemberFeIds())
|
assertThat(resources.get(0).getExclusiveGroupMemberFeIds()).isEmpty();
|
||||||
.isEqualTo(new ArrayList<Integer>());
|
assertThat(resources.get(1).getExclusiveGroupMemberFeIds()).containsExactly(2, 3);
|
||||||
assertThat(resources.get(1).getExclusiveGroupMemberFeIds())
|
assertThat(resources.get(2).getExclusiveGroupMemberFeIds()).containsExactly(1, 3);
|
||||||
.isEqualTo(new ArrayList<Integer>(Arrays.asList(2, 3)));
|
assertThat(resources.get(3).getExclusiveGroupMemberFeIds()).containsExactly(1, 2);
|
||||||
assertThat(resources.get(2).getExclusiveGroupMemberFeIds())
|
|
||||||
.isEqualTo(new ArrayList<Integer>(Arrays.asList(1, 3)));
|
|
||||||
assertThat(resources.get(3).getExclusiveGroupMemberFeIds())
|
|
||||||
.isEqualTo(new ArrayList<Integer>(Arrays.asList(1, 2)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -171,11 +168,11 @@ public class TunerResourceManagerServiceTest {
|
|||||||
new TunerFrontendInfo(1 /*id*/, FrontendSettings.TYPE_DVBS, 1 /*exclusiveGroupId*/);
|
new TunerFrontendInfo(1 /*id*/, FrontendSettings.TYPE_DVBS, 1 /*exclusiveGroupId*/);
|
||||||
|
|
||||||
mTunerResourceManagerService.setFrontendInfoListInternal(infos);
|
mTunerResourceManagerService.setFrontendInfoListInternal(infos);
|
||||||
SparseArray<FrontendResource> resources0 =
|
Map<Integer, FrontendResource> resources0 =
|
||||||
mTunerResourceManagerService.getFrontendResources();
|
mTunerResourceManagerService.getFrontendResources();
|
||||||
|
|
||||||
mTunerResourceManagerService.setFrontendInfoListInternal(infos);
|
mTunerResourceManagerService.setFrontendInfoListInternal(infos);
|
||||||
SparseArray<FrontendResource> resources1 =
|
Map<Integer, FrontendResource> resources1 =
|
||||||
mTunerResourceManagerService.getFrontendResources();
|
mTunerResourceManagerService.getFrontendResources();
|
||||||
|
|
||||||
assertThat(resources0).isEqualTo(resources1);
|
assertThat(resources0).isEqualTo(resources1);
|
||||||
@@ -198,13 +195,13 @@ public class TunerResourceManagerServiceTest {
|
|||||||
new TunerFrontendInfo(1 /*id*/, FrontendSettings.TYPE_DVBT, 1 /*exclusiveGroupId*/);
|
new TunerFrontendInfo(1 /*id*/, FrontendSettings.TYPE_DVBT, 1 /*exclusiveGroupId*/);
|
||||||
mTunerResourceManagerService.setFrontendInfoListInternal(infos1);
|
mTunerResourceManagerService.setFrontendInfoListInternal(infos1);
|
||||||
|
|
||||||
SparseArray<FrontendResource> resources =
|
Map<Integer, FrontendResource> resources =
|
||||||
mTunerResourceManagerService.getFrontendResources();
|
mTunerResourceManagerService.getFrontendResources();
|
||||||
for (int id = 0; id < infos1.length; id++) {
|
for (int id = 0; id < infos1.length; id++) {
|
||||||
assertThat(resources.get(infos1[id].getId())
|
assertThat(resources.get(infos1[id].getId())
|
||||||
.getExclusiveGroupMemberFeIds().size()).isEqualTo(0);
|
.getExclusiveGroupMemberFeIds().size()).isEqualTo(0);
|
||||||
}
|
}
|
||||||
assertThat(sparseArrayToList(resources)).comparingElementsUsing(FR_TFI_COMPARE)
|
assertThat(resources.values()).comparingElementsUsing(FR_TFI_COMPARE)
|
||||||
.containsExactlyElementsIn(Arrays.asList(infos1));
|
.containsExactlyElementsIn(Arrays.asList(infos1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,13 +222,13 @@ public class TunerResourceManagerServiceTest {
|
|||||||
new TunerFrontendInfo(1 /*id*/, FrontendSettings.TYPE_DVBT, 1 /*exclusiveGroupId*/);
|
new TunerFrontendInfo(1 /*id*/, FrontendSettings.TYPE_DVBT, 1 /*exclusiveGroupId*/);
|
||||||
mTunerResourceManagerService.setFrontendInfoListInternal(infos1);
|
mTunerResourceManagerService.setFrontendInfoListInternal(infos1);
|
||||||
|
|
||||||
SparseArray<FrontendResource> resources =
|
Map<Integer, FrontendResource> resources =
|
||||||
mTunerResourceManagerService.getFrontendResources();
|
mTunerResourceManagerService.getFrontendResources();
|
||||||
for (int id = 0; id < infos1.length; id++) {
|
for (int id = 0; id < infos1.length; id++) {
|
||||||
assertThat(resources.get(infos1[id].getId())
|
assertThat(resources.get(infos1[id].getId())
|
||||||
.getExclusiveGroupMemberFeIds().size()).isEqualTo(0);
|
.getExclusiveGroupMemberFeIds().size()).isEqualTo(0);
|
||||||
}
|
}
|
||||||
assertThat(sparseArrayToList(resources)).comparingElementsUsing(FR_TFI_COMPARE)
|
assertThat(resources.values()).comparingElementsUsing(FR_TFI_COMPARE)
|
||||||
.containsExactlyElementsIn(Arrays.asList(infos1));
|
.containsExactlyElementsIn(Arrays.asList(infos1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -352,9 +349,9 @@ public class TunerResourceManagerServiceTest {
|
|||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
assertThat(frontendId[0]).isEqualTo(infos[1].getId());
|
assertThat(frontendId[0]).isEqualTo(infos[1].getId());
|
||||||
assertThat(mTunerResourceManagerService.getFrontendResources().get(infos[1].getId())
|
assertThat(mTunerResourceManagerService.getFrontendResource(infos[1].getId())
|
||||||
.isInUse()).isTrue();
|
.isInUse()).isTrue();
|
||||||
assertThat(mTunerResourceManagerService.getFrontendResources().get(infos[2].getId())
|
assertThat(mTunerResourceManagerService.getFrontendResource(infos[2].getId())
|
||||||
.isInUse()).isTrue();
|
.isInUse()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -372,12 +369,12 @@ public class TunerResourceManagerServiceTest {
|
|||||||
mTunerResourceManagerService.registerClientProfileInternal(
|
mTunerResourceManagerService.registerClientProfileInternal(
|
||||||
profiles[0], null /*listener*/, clientId0);
|
profiles[0], null /*listener*/, clientId0);
|
||||||
assertThat(clientId0[0]).isNotEqualTo(TunerResourceManagerService.INVALID_CLIENT_ID);
|
assertThat(clientId0[0]).isNotEqualTo(TunerResourceManagerService.INVALID_CLIENT_ID);
|
||||||
mTunerResourceManagerService.getClientProfiles().get(clientId0[0])
|
mTunerResourceManagerService.getClientProfile(clientId0[0])
|
||||||
.setPriority(clientPriorities[0]);
|
.setPriority(clientPriorities[0]);
|
||||||
mTunerResourceManagerService.registerClientProfileInternal(
|
mTunerResourceManagerService.registerClientProfileInternal(
|
||||||
profiles[1], null /*listener*/, clientId1);
|
profiles[1], null /*listener*/, clientId1);
|
||||||
assertThat(clientId1[0]).isNotEqualTo(TunerResourceManagerService.INVALID_CLIENT_ID);
|
assertThat(clientId1[0]).isNotEqualTo(TunerResourceManagerService.INVALID_CLIENT_ID);
|
||||||
mTunerResourceManagerService.getClientProfiles().get(clientId1[0])
|
mTunerResourceManagerService.getClientProfile(clientId1[0])
|
||||||
.setPriority(clientPriorities[1]);
|
.setPriority(clientPriorities[1]);
|
||||||
|
|
||||||
// Init frontend resources.
|
// Init frontend resources.
|
||||||
@@ -433,12 +430,12 @@ public class TunerResourceManagerServiceTest {
|
|||||||
mTunerResourceManagerService.registerClientProfileInternal(
|
mTunerResourceManagerService.registerClientProfileInternal(
|
||||||
profiles[0], null /*listener*/, clientId0);
|
profiles[0], null /*listener*/, clientId0);
|
||||||
assertThat(clientId0[0]).isNotEqualTo(TunerResourceManagerService.INVALID_CLIENT_ID);
|
assertThat(clientId0[0]).isNotEqualTo(TunerResourceManagerService.INVALID_CLIENT_ID);
|
||||||
mTunerResourceManagerService.getClientProfiles().get(clientId0[0])
|
mTunerResourceManagerService.getClientProfile(clientId0[0])
|
||||||
.setPriority(clientPriorities[0]);
|
.setPriority(clientPriorities[0]);
|
||||||
mTunerResourceManagerService.registerClientProfileInternal(
|
mTunerResourceManagerService.registerClientProfileInternal(
|
||||||
profiles[1], null /*listener*/, clientId1);
|
profiles[1], null /*listener*/, clientId1);
|
||||||
assertThat(clientId1[0]).isNotEqualTo(TunerResourceManagerService.INVALID_CLIENT_ID);
|
assertThat(clientId1[0]).isNotEqualTo(TunerResourceManagerService.INVALID_CLIENT_ID);
|
||||||
mTunerResourceManagerService.getClientProfiles().get(clientId1[0])
|
mTunerResourceManagerService.getClientProfile(clientId1[0])
|
||||||
.setPriority(clientPriorities[1]);
|
.setPriority(clientPriorities[1]);
|
||||||
|
|
||||||
// Init frontend resources.
|
// Init frontend resources.
|
||||||
@@ -469,14 +466,14 @@ public class TunerResourceManagerServiceTest {
|
|||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
assertThat(frontendId[0]).isEqualTo(infos[1].getId());
|
assertThat(frontendId[0]).isEqualTo(infos[1].getId());
|
||||||
assertThat(mTunerResourceManagerService.getFrontendResources().get(infos[0].getId())
|
assertThat(mTunerResourceManagerService.getFrontendResource(infos[0].getId())
|
||||||
.isInUse()).isTrue();
|
.isInUse()).isTrue();
|
||||||
assertThat(mTunerResourceManagerService.getFrontendResources().get(infos[1].getId())
|
assertThat(mTunerResourceManagerService.getFrontendResource(infos[1].getId())
|
||||||
.isInUse()).isTrue();
|
.isInUse()).isTrue();
|
||||||
assertThat(mTunerResourceManagerService.getFrontendResources()
|
assertThat(mTunerResourceManagerService.getFrontendResource(infos[0].getId())
|
||||||
.get(infos[0].getId()).getOwnerClientId()).isEqualTo(clientId1[0]);
|
.getOwnerClientId()).isEqualTo(clientId1[0]);
|
||||||
assertThat(mTunerResourceManagerService.getFrontendResources()
|
assertThat(mTunerResourceManagerService.getFrontendResource(infos[1].getId())
|
||||||
.get(infos[1].getId()).getOwnerClientId()).isEqualTo(clientId1[0]);
|
.getOwnerClientId()).isEqualTo(clientId1[0]);
|
||||||
assertThat(mReclaimingId).isEqualTo(clientId0[0]);
|
assertThat(mReclaimingId).isEqualTo(clientId0[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -508,16 +505,16 @@ public class TunerResourceManagerServiceTest {
|
|||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
assertThat(frontendId[0]).isEqualTo(infos[0].getId());
|
assertThat(frontendId[0]).isEqualTo(infos[0].getId());
|
||||||
assertThat(mTunerResourceManagerService.getFrontendResources().get(infos[0].getId())
|
assertThat(mTunerResourceManagerService.getFrontendResource(infos[0].getId())
|
||||||
.isInUse()).isTrue();
|
.isInUse()).isTrue();
|
||||||
assertThat(mTunerResourceManagerService.getFrontendResources().get(infos[1].getId())
|
assertThat(mTunerResourceManagerService.getFrontendResource(infos[1].getId())
|
||||||
.isInUse()).isTrue();
|
.isInUse()).isTrue();
|
||||||
|
|
||||||
// Unregister client when using frontend
|
// Unregister client when using frontend
|
||||||
mTunerResourceManagerService.unregisterClientProfileInternal(clientId[0]);
|
mTunerResourceManagerService.unregisterClientProfileInternal(clientId[0]);
|
||||||
assertThat(mTunerResourceManagerService.getFrontendResources().get(infos[0].getId())
|
assertThat(mTunerResourceManagerService.getFrontendResource(infos[0].getId())
|
||||||
.isInUse()).isFalse();
|
.isInUse()).isFalse();
|
||||||
assertThat(mTunerResourceManagerService.getFrontendResources().get(infos[1].getId())
|
assertThat(mTunerResourceManagerService.getFrontendResource(infos[1].getId())
|
||||||
.isInUse()).isFalse();
|
.isInUse()).isFalse();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user