Add client Id as the parameter of all the release resources APIs in TRM
Test: atest com.android.server.tv.tunerresourcemanager Bug: 150952662 Change-Id: I7a028dfde8d93148f3a4c0dd1a607533f8a7b1a7
This commit is contained in:
@@ -897,7 +897,7 @@ public final class MediaCas implements AutoCloseable {
|
||||
|
||||
synchronized (mSessionMap) {
|
||||
if (mSessionMap.get(session) != null) {
|
||||
mTunerResourceManager.releaseCasSession(mSessionMap.get(session));
|
||||
mTunerResourceManager.releaseCasSession(mSessionMap.get(session), mClientId);
|
||||
mSessionMap.remove(session);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,12 +351,12 @@ public class Tuner implements AutoCloseable {
|
||||
public void close() {
|
||||
if (mFrontendHandle != null) {
|
||||
nativeCloseFrontendByHandle(mFrontendHandle);
|
||||
mTunerResourceManager.releaseFrontend(mFrontendHandle);
|
||||
mTunerResourceManager.releaseFrontend(mFrontendHandle, mClientId);
|
||||
mFrontendHandle = null;
|
||||
mFrontend = null;
|
||||
}
|
||||
if (mLnb != null) {
|
||||
mTunerResourceManager.releaseLnb(mLnbHandle);
|
||||
mTunerResourceManager.releaseLnb(mLnbHandle, mClientId);
|
||||
mLnb = null;
|
||||
mLnbHandle = null;
|
||||
}
|
||||
|
||||
@@ -85,7 +85,8 @@ interface ITunerResourceManager {
|
||||
* Updates the available Frontend resources information on the current device.
|
||||
*
|
||||
* <p><strong>Note:</strong> This update must happen before the first
|
||||
* {@link #requestFrontend(TunerFrontendRequest,int[])} and {@link #releaseFrontend(int)} call.
|
||||
* {@link #requestFrontend(TunerFrontendRequest,int[])} and {@link #releaseFrontend(int, int)}
|
||||
* call.
|
||||
*
|
||||
* @param infos an array of the available {@link TunerFrontendInfo} information.
|
||||
*/
|
||||
@@ -95,7 +96,8 @@ interface ITunerResourceManager {
|
||||
* Updates the available Cas resource information on the current device.
|
||||
*
|
||||
* <p><strong>Note:</strong> This update must happen before the first
|
||||
* {@link #requestCasSession(CasSessionRequest, int[])} and {@link #releaseCasSession(int)} call.
|
||||
* {@link #requestCasSession(CasSessionRequest, int[])} and {@link #releaseCasSession(int, int)}
|
||||
* call.
|
||||
*
|
||||
* @param casSystemId id of the updating CAS system.
|
||||
* @param maxSessionNum the max session number of the CAS system that is updated.
|
||||
@@ -106,7 +108,7 @@ interface ITunerResourceManager {
|
||||
* Updates the available Lnb resource information on the current device.
|
||||
*
|
||||
* <p><strong>Note:</strong> This update must happen before the first
|
||||
* {@link #requestLnb(TunerLnbRequest, int[])} and {@link #releaseLnb(int)} call.
|
||||
* {@link #requestLnb(TunerLnbRequest, int[])} and {@link #releaseLnb(int, int)} call.
|
||||
*
|
||||
* @param lnbIds ids of the updating lnbs.
|
||||
*/
|
||||
@@ -255,8 +257,9 @@ interface ITunerResourceManager {
|
||||
* before this release.
|
||||
*
|
||||
* @param frontendHandle the handle of the released frontend.
|
||||
* @param clientId the id of the client that is releasing the frontend.
|
||||
*/
|
||||
void releaseFrontend(in int frontendHandle);
|
||||
void releaseFrontend(in int frontendHandle, int clientId);
|
||||
|
||||
/*
|
||||
* Notifies the TRM that the Demux with the given handle was released.
|
||||
@@ -264,8 +267,9 @@ interface ITunerResourceManager {
|
||||
* <p>Client must call this whenever it releases a demux.
|
||||
*
|
||||
* @param demuxHandle the handle of the released Tuner Demux.
|
||||
* @param clientId the id of the client that is releasing the demux.
|
||||
*/
|
||||
void releaseDemux(in int demuxHandle);
|
||||
void releaseDemux(in int demuxHandle, int clientId);
|
||||
|
||||
/*
|
||||
* Notifies the TRM that the Descrambler with the given handle was released.
|
||||
@@ -273,8 +277,9 @@ interface ITunerResourceManager {
|
||||
* <p>Client must call this whenever it releases a descrambler.
|
||||
*
|
||||
* @param demuxHandle the handle of the released Tuner Descrambler.
|
||||
* @param clientId the id of the client that is releasing the descrambler.
|
||||
*/
|
||||
void releaseDescrambler(in int descramblerHandle);
|
||||
void releaseDescrambler(in int descramblerHandle, int clientId);
|
||||
|
||||
/*
|
||||
* Notifies the TRM that the given Cas session has been released.
|
||||
@@ -284,8 +289,9 @@ interface ITunerResourceManager {
|
||||
* <p><strong>Note:</strong> {@link #updateCasInfo(int, int)} must be called before this release.
|
||||
*
|
||||
* @param sessionResourceId the id of the released CAS session.
|
||||
* @param clientId the id of the client that is releasing the cas session.
|
||||
*/
|
||||
void releaseCasSession(in int sessionResourceId);
|
||||
void releaseCasSession(in int sessionResourceId, int clientId);
|
||||
|
||||
/*
|
||||
* Notifies the TRM that the Lnb with the given handle was released.
|
||||
@@ -295,8 +301,9 @@ interface ITunerResourceManager {
|
||||
* <p><strong>Note:</strong> {@link #setLnbInfos(int[])} must be called before this release.
|
||||
*
|
||||
* @param lnbHandle the handle of the released Tuner Lnb.
|
||||
* @param clientId the id of the client that is releasing the lnb.
|
||||
*/
|
||||
void releaseLnb(in int lnbHandle);
|
||||
void releaseLnb(in int lnbHandle, int clientId);
|
||||
|
||||
/*
|
||||
* Compare two clients' priority.
|
||||
|
||||
@@ -180,7 +180,8 @@ public class TunerResourceManager {
|
||||
* Updates the current TRM of the TunerHAL Frontend information.
|
||||
*
|
||||
* <p><strong>Note:</strong> This update must happen before the first
|
||||
* {@link #requestFrontend(TunerFrontendRequest, int[])} and {@link #releaseFrontend(int)} call.
|
||||
* {@link #requestFrontend(TunerFrontendRequest, int[])} and
|
||||
* {@link #releaseFrontend(int, int)} call.
|
||||
*
|
||||
* @param infos an array of the available {@link TunerFrontendInfo} information.
|
||||
*/
|
||||
@@ -196,7 +197,7 @@ public class TunerResourceManager {
|
||||
* Updates the TRM of the current CAS information.
|
||||
*
|
||||
* <p><strong>Note:</strong> This update must happen before the first
|
||||
* {@link #requestCasSession(CasSessionRequest, int[])} and {@link #releaseCasSession(int)}
|
||||
* {@link #requestCasSession(CasSessionRequest, int[])} and {@link #releaseCasSession(int, int)}
|
||||
* call.
|
||||
*
|
||||
* @param casSystemId id of the updating CAS system.
|
||||
@@ -214,7 +215,7 @@ public class TunerResourceManager {
|
||||
* Updates the TRM of the current Lnb information.
|
||||
*
|
||||
* <p><strong>Note:</strong> This update must happen before the first
|
||||
* {@link #requestLnb(TunerLnbRequest, int[])} and {@link #releaseLnb(int)} call.
|
||||
* {@link #requestLnb(TunerLnbRequest, int[])} and {@link #releaseLnb(int, int)} call.
|
||||
*
|
||||
* @param lnbIds ids of the updating lnbs.
|
||||
*/
|
||||
@@ -420,10 +421,11 @@ public class TunerResourceManager {
|
||||
* before this release.
|
||||
*
|
||||
* @param frontendHandle the handle of the released frontend.
|
||||
* @param clientId the id of the client that is releasing the frontend.
|
||||
*/
|
||||
public void releaseFrontend(int frontendHandle) {
|
||||
public void releaseFrontend(int frontendHandle, int clientId) {
|
||||
try {
|
||||
mService.releaseFrontend(frontendHandle);
|
||||
mService.releaseFrontend(frontendHandle, clientId);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
@@ -435,10 +437,11 @@ public class TunerResourceManager {
|
||||
* <p>Client must call this whenever it releases an Demux.
|
||||
*
|
||||
* @param demuxHandle the handle of the released Tuner Demux.
|
||||
* @param clientId the id of the client that is releasing the demux.
|
||||
*/
|
||||
public void releaseDemux(int demuxHandle) {
|
||||
public void releaseDemux(int demuxHandle, int clientId) {
|
||||
try {
|
||||
mService.releaseDemux(demuxHandle);
|
||||
mService.releaseDemux(demuxHandle, clientId);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
@@ -450,10 +453,11 @@ public class TunerResourceManager {
|
||||
* <p>Client must call this whenever it releases an Descrambler.
|
||||
*
|
||||
* @param descramblerHandle the handle of the released Tuner Descrambler.
|
||||
* @param clientId the id of the client that is releasing the descrambler.
|
||||
*/
|
||||
public void releaseDescrambler(int descramblerHandle) {
|
||||
public void releaseDescrambler(int descramblerHandle, int clientId) {
|
||||
try {
|
||||
mService.releaseDescrambler(descramblerHandle);
|
||||
mService.releaseDescrambler(descramblerHandle, clientId);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
@@ -468,10 +472,11 @@ public class TunerResourceManager {
|
||||
* release.
|
||||
*
|
||||
* @param sessionResourceId the id of the released CAS session.
|
||||
* @param clientId the id of the client that is releasing the cas session.
|
||||
*/
|
||||
public void releaseCasSession(int sessionResourceId) {
|
||||
public void releaseCasSession(int sessionResourceId, int clientId) {
|
||||
try {
|
||||
mService.releaseCasSession(sessionResourceId);
|
||||
mService.releaseCasSession(sessionResourceId, clientId);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
@@ -485,10 +490,11 @@ public class TunerResourceManager {
|
||||
* <p><strong>Note:</strong> {@link #setLnbInfoList(int[])} must be called before this release.
|
||||
*
|
||||
* @param lnbHandle the handle of the released Tuner Lnb.
|
||||
* @param clientId the id of the client that is releasing the lnb.
|
||||
*/
|
||||
public void releaseLnb(int lnbHandle) {
|
||||
public void releaseLnb(int lnbHandle, int clientId) {
|
||||
try {
|
||||
mService.releaseLnb(lnbHandle);
|
||||
mService.releaseLnb(lnbHandle, clientId);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
|
||||
@@ -257,20 +257,28 @@ public class TunerResourceManagerService extends SystemService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseFrontend(int frontendHandle) throws RemoteException {
|
||||
public void releaseFrontend(int frontendHandle, int clientId) throws RemoteException {
|
||||
enforceTunerAccessPermission("releaseFrontend");
|
||||
enforceTrmAccessPermission("releaseFrontend");
|
||||
if (!validateResourceHandle(TunerResourceManager.TUNER_RESOURCE_TYPE_FRONTEND,
|
||||
frontendHandle)) {
|
||||
throw new RemoteException("frontendHandle can't be invalid");
|
||||
}
|
||||
int frontendId = getResourceIdFromHandle(frontendHandle);
|
||||
FrontendResource fe = getFrontendResource(frontendId);
|
||||
if (fe == null) {
|
||||
throw new RemoteException("Releasing frontend does not exist.");
|
||||
}
|
||||
if (fe.getOwnerClientId() != clientId) {
|
||||
throw new RemoteException("Client is not the current owner of the releasing fe.");
|
||||
}
|
||||
synchronized (mLock) {
|
||||
releaseFrontendInternal(getResourceIdFromHandle(frontendHandle));
|
||||
releaseFrontendInternal(fe);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseDemux(int demuxHandle) {
|
||||
public void releaseDemux(int demuxHandle, int clientId) {
|
||||
enforceTunerAccessPermission("releaseDemux");
|
||||
enforceTrmAccessPermission("releaseDemux");
|
||||
if (DEBUG) {
|
||||
@@ -279,7 +287,7 @@ public class TunerResourceManagerService extends SystemService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseDescrambler(int descramblerHandle) {
|
||||
public void releaseDescrambler(int descramblerHandle, int clientId) {
|
||||
enforceTunerAccessPermission("releaseDescrambler");
|
||||
enforceTrmAccessPermission("releaseDescrambler");
|
||||
if (DEBUG) {
|
||||
@@ -288,7 +296,7 @@ public class TunerResourceManagerService extends SystemService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseCasSession(int sessionResourceId) {
|
||||
public void releaseCasSession(int sessionResourceId, int clientId) {
|
||||
enforceTrmAccessPermission("releaseCasSession");
|
||||
if (DEBUG) {
|
||||
Slog.d(TAG, "releaseCasSession(sessionResourceId=" + sessionResourceId + ")");
|
||||
@@ -296,14 +304,22 @@ public class TunerResourceManagerService extends SystemService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseLnb(int lnbHandle) throws RemoteException {
|
||||
public void releaseLnb(int lnbHandle, int clientId) throws RemoteException {
|
||||
enforceTunerAccessPermission("releaseLnb");
|
||||
enforceTrmAccessPermission("releaseLnb");
|
||||
if (!validateResourceHandle(TunerResourceManager.TUNER_RESOURCE_TYPE_LNB, lnbHandle)) {
|
||||
throw new RemoteException("lnbHandle can't be invalid");
|
||||
}
|
||||
int lnbId = getResourceIdFromHandle(lnbHandle);
|
||||
LnbResource lnb = getLnbResource(lnbId);
|
||||
if (lnb == null) {
|
||||
throw new RemoteException("Releasing lnb does not exist.");
|
||||
}
|
||||
if (lnb.getOwnerClientId() != clientId) {
|
||||
throw new RemoteException("Client is not the current owner of the releasing lnb.");
|
||||
}
|
||||
synchronized (mLock) {
|
||||
releaseLnbInternal(getResourceIdFromHandle(lnbHandle));
|
||||
releaseLnbInternal(lnb);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -568,19 +584,19 @@ public class TunerResourceManagerService extends SystemService {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void releaseFrontendInternal(int frontendId) {
|
||||
void releaseFrontendInternal(FrontendResource fe) {
|
||||
if (DEBUG) {
|
||||
Slog.d(TAG, "releaseFrontend(id=" + frontendId + ")");
|
||||
Slog.d(TAG, "releaseFrontend(id=" + fe.getId() + ")");
|
||||
}
|
||||
updateFrontendClientMappingOnRelease(frontendId);
|
||||
updateFrontendClientMappingOnRelease(fe);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void releaseLnbInternal(int lnbId) {
|
||||
void releaseLnbInternal(LnbResource lnb) {
|
||||
if (DEBUG) {
|
||||
Slog.d(TAG, "releaseLnb(lnbId=" + lnbId + ")");
|
||||
Slog.d(TAG, "releaseLnb(lnbId=" + lnb.getId() + ")");
|
||||
}
|
||||
updateLnbClientMappingOnRelease(lnbId);
|
||||
updateLnbClientMappingOnRelease(lnb);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -588,6 +604,7 @@ public class TunerResourceManagerService extends SystemService {
|
||||
if (DEBUG) {
|
||||
Slog.d(TAG, "requestDemux(request=" + request + ")");
|
||||
}
|
||||
// There are enough Demux resources, so we don't manage Demux in R.
|
||||
demuxHandle[0] = generateResourceHandle(TunerResourceManager.TUNER_RESOURCE_TYPE_DEMUX, 0);
|
||||
return true;
|
||||
}
|
||||
@@ -597,6 +614,7 @@ public class TunerResourceManagerService extends SystemService {
|
||||
if (DEBUG) {
|
||||
Slog.d(TAG, "requestDescrambler(request=" + request + ")");
|
||||
}
|
||||
// There are enough Descrambler resources, so we don't manage Descrambler in R.
|
||||
descramblerHandle[0] =
|
||||
generateResourceHandle(TunerResourceManager.TUNER_RESOURCE_TYPE_DESCRAMBLER, 0);
|
||||
return true;
|
||||
@@ -694,11 +712,10 @@ public class TunerResourceManagerService extends SystemService {
|
||||
}
|
||||
}
|
||||
|
||||
private void updateFrontendClientMappingOnRelease(int frontendId) {
|
||||
FrontendResource releasingFrontend = getFrontendResource(frontendId);
|
||||
private void updateFrontendClientMappingOnRelease(@NonNull FrontendResource releasingFrontend) {
|
||||
ClientProfile ownerProfile = getClientProfile(releasingFrontend.getOwnerClientId());
|
||||
releasingFrontend.removeOwner();
|
||||
ownerProfile.releaseFrontend(frontendId);
|
||||
ownerProfile.releaseFrontend(releasingFrontend.getId());
|
||||
for (int exclusiveGroupMember : releasingFrontend.getExclusiveGroupMemberFeIds()) {
|
||||
getFrontendResource(exclusiveGroupMember).removeOwner();
|
||||
ownerProfile.releaseFrontend(exclusiveGroupMember);
|
||||
@@ -712,11 +729,10 @@ public class TunerResourceManagerService extends SystemService {
|
||||
ownerProfile.useLnb(grantingId);
|
||||
}
|
||||
|
||||
private void updateLnbClientMappingOnRelease(int lnbId) {
|
||||
LnbResource releasingLnb = getLnbResource(lnbId);
|
||||
private void updateLnbClientMappingOnRelease(@NonNull LnbResource releasingLnb) {
|
||||
ClientProfile ownerProfile = getClientProfile(releasingLnb.getOwnerClientId());
|
||||
releasingLnb.removeOwner();
|
||||
ownerProfile.releaseLnb(lnbId);
|
||||
ownerProfile.releaseLnb(releasingLnb.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -761,7 +777,7 @@ public class TunerResourceManagerService extends SystemService {
|
||||
private void removeFrontendResource(int removingId) {
|
||||
FrontendResource fe = getFrontendResource(removingId);
|
||||
if (fe.isInUse()) {
|
||||
releaseFrontendInternal(removingId);
|
||||
releaseFrontendInternal(fe);
|
||||
}
|
||||
for (int excGroupmemberFeId : fe.getExclusiveGroupMemberFeIds()) {
|
||||
getFrontendResource(excGroupmemberFeId)
|
||||
@@ -789,7 +805,7 @@ public class TunerResourceManagerService extends SystemService {
|
||||
private void removeLnbResource(int removingId) {
|
||||
LnbResource lnb = getLnbResource(removingId);
|
||||
if (lnb.isInUse()) {
|
||||
releaseLnbInternal(removingId);
|
||||
releaseLnbInternal(lnb);
|
||||
}
|
||||
mLnbResources.remove(removingId);
|
||||
}
|
||||
|
||||
@@ -519,7 +519,8 @@ public class TunerResourceManagerServiceTest {
|
||||
.getFrontendResource(infos[1].getId()).isInUse()).isTrue();
|
||||
|
||||
// Release frontend
|
||||
mTunerResourceManagerService.releaseFrontendInternal(frontendId);
|
||||
mTunerResourceManagerService.releaseFrontendInternal(mTunerResourceManagerService
|
||||
.getFrontendResource(frontendId));
|
||||
assertThat(mTunerResourceManagerService
|
||||
.getFrontendResource(frontendId).isInUse()).isFalse();
|
||||
assertThat(mTunerResourceManagerService
|
||||
@@ -609,7 +610,8 @@ public class TunerResourceManagerServiceTest {
|
||||
assertThat(lnbId).isEqualTo(lnbIds[0]);
|
||||
|
||||
// Release lnb
|
||||
mTunerResourceManagerService.releaseLnbInternal(lnbId);
|
||||
mTunerResourceManagerService.releaseLnbInternal(mTunerResourceManagerService
|
||||
.getLnbResource(lnbId));
|
||||
assertThat(mTunerResourceManagerService
|
||||
.getLnbResource(lnbId).isInUse()).isFalse();
|
||||
assertThat(mTunerResourceManagerService
|
||||
|
||||
Reference in New Issue
Block a user