Merge "Add client Id as the parameter of all the release resources APIs in TRM" into rvc-dev

This commit is contained in:
Amy Zhang
2020-04-17 03:31:43 +00:00
committed by Android (Google) Code Review
6 changed files with 78 additions and 47 deletions

View File

@@ -897,7 +897,7 @@ public final class MediaCas implements AutoCloseable {
synchronized (mSessionMap) { synchronized (mSessionMap) {
if (mSessionMap.get(session) != null) { if (mSessionMap.get(session) != null) {
mTunerResourceManager.releaseCasSession(mSessionMap.get(session)); mTunerResourceManager.releaseCasSession(mSessionMap.get(session), mClientId);
mSessionMap.remove(session); mSessionMap.remove(session);
} }
} }

View File

@@ -351,12 +351,12 @@ public class Tuner implements AutoCloseable {
public void close() { public void close() {
if (mFrontendHandle != null) { if (mFrontendHandle != null) {
nativeCloseFrontendByHandle(mFrontendHandle); nativeCloseFrontendByHandle(mFrontendHandle);
mTunerResourceManager.releaseFrontend(mFrontendHandle); mTunerResourceManager.releaseFrontend(mFrontendHandle, mClientId);
mFrontendHandle = null; mFrontendHandle = null;
mFrontend = null; mFrontend = null;
} }
if (mLnb != null) { if (mLnb != null) {
mTunerResourceManager.releaseLnb(mLnbHandle); mTunerResourceManager.releaseLnb(mLnbHandle, mClientId);
mLnb = null; mLnb = null;
mLnbHandle = null; mLnbHandle = null;
} }

View File

@@ -85,7 +85,8 @@ interface ITunerResourceManager {
* Updates the available Frontend resources information on the current device. * Updates the available Frontend resources information on the current device.
* *
* <p><strong>Note:</strong> This update must happen before the first * <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. * @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. * Updates the available Cas resource information on the current device.
* *
* <p><strong>Note:</strong> This update must happen before the first * <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 casSystemId id of the updating CAS system.
* @param maxSessionNum the max session number of the CAS system that is updated. * @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. * Updates the available Lnb resource information on the current device.
* *
* <p><strong>Note:</strong> This update must happen before the first * <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. * @param lnbIds ids of the updating lnbs.
*/ */
@@ -255,8 +257,9 @@ interface ITunerResourceManager {
* before this release. * before this release.
* *
* @param frontendHandle the handle of the released frontend. * @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. * 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. * <p>Client must call this whenever it releases a demux.
* *
* @param demuxHandle the handle of the released Tuner 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. * 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. * <p>Client must call this whenever it releases a descrambler.
* *
* @param demuxHandle the handle of the released Tuner 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. * 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. * <p><strong>Note:</strong> {@link #updateCasInfo(int, int)} must be called before this release.
* *
* @param sessionResourceId the id of the released CAS session. * @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. * 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. * <p><strong>Note:</strong> {@link #setLnbInfos(int[])} must be called before this release.
* *
* @param lnbHandle the handle of the released Tuner Lnb. * @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. * Compare two clients' priority.

View File

@@ -180,7 +180,8 @@ public class TunerResourceManager {
* Updates the current TRM of the TunerHAL Frontend information. * Updates the current TRM of the TunerHAL Frontend information.
* *
* <p><strong>Note:</strong> This update must happen before the first * <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. * @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. * Updates the TRM of the current CAS information.
* *
* <p><strong>Note:</strong> This update must happen before the first * <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. * call.
* *
* @param casSystemId id of the updating CAS system. * @param casSystemId id of the updating CAS system.
@@ -214,7 +215,7 @@ public class TunerResourceManager {
* Updates the TRM of the current Lnb information. * Updates the TRM of the current Lnb information.
* *
* <p><strong>Note:</strong> This update must happen before the first * <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. * @param lnbIds ids of the updating lnbs.
*/ */
@@ -420,10 +421,11 @@ public class TunerResourceManager {
* before this release. * before this release.
* *
* @param frontendHandle the handle of the released frontend. * @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 { try {
mService.releaseFrontend(frontendHandle); mService.releaseFrontend(frontendHandle, clientId);
} catch (RemoteException e) { } catch (RemoteException e) {
throw e.rethrowFromSystemServer(); throw e.rethrowFromSystemServer();
} }
@@ -435,10 +437,11 @@ public class TunerResourceManager {
* <p>Client must call this whenever it releases an Demux. * <p>Client must call this whenever it releases an Demux.
* *
* @param demuxHandle the handle of the released Tuner 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 { try {
mService.releaseDemux(demuxHandle); mService.releaseDemux(demuxHandle, clientId);
} catch (RemoteException e) { } catch (RemoteException e) {
throw e.rethrowFromSystemServer(); throw e.rethrowFromSystemServer();
} }
@@ -450,10 +453,11 @@ public class TunerResourceManager {
* <p>Client must call this whenever it releases an Descrambler. * <p>Client must call this whenever it releases an Descrambler.
* *
* @param descramblerHandle the handle of the released Tuner 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 { try {
mService.releaseDescrambler(descramblerHandle); mService.releaseDescrambler(descramblerHandle, clientId);
} catch (RemoteException e) { } catch (RemoteException e) {
throw e.rethrowFromSystemServer(); throw e.rethrowFromSystemServer();
} }
@@ -468,10 +472,11 @@ public class TunerResourceManager {
* release. * release.
* *
* @param sessionResourceId the id of the released CAS session. * @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 { try {
mService.releaseCasSession(sessionResourceId); mService.releaseCasSession(sessionResourceId, clientId);
} catch (RemoteException e) { } catch (RemoteException e) {
throw e.rethrowFromSystemServer(); throw e.rethrowFromSystemServer();
} }
@@ -485,10 +490,11 @@ public class TunerResourceManager {
* <p><strong>Note:</strong> {@link #setLnbInfoList(int[])} must be called before this release. * <p><strong>Note:</strong> {@link #setLnbInfoList(int[])} must be called before this release.
* *
* @param lnbHandle the handle of the released Tuner Lnb. * @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 { try {
mService.releaseLnb(lnbHandle); mService.releaseLnb(lnbHandle, clientId);
} catch (RemoteException e) { } catch (RemoteException e) {
throw e.rethrowFromSystemServer(); throw e.rethrowFromSystemServer();
} }

View File

@@ -257,20 +257,28 @@ public class TunerResourceManagerService extends SystemService {
} }
@Override @Override
public void releaseFrontend(int frontendHandle) throws RemoteException { public void releaseFrontend(int frontendHandle, int clientId) throws RemoteException {
enforceTunerAccessPermission("releaseFrontend"); enforceTunerAccessPermission("releaseFrontend");
enforceTrmAccessPermission("releaseFrontend"); enforceTrmAccessPermission("releaseFrontend");
if (!validateResourceHandle(TunerResourceManager.TUNER_RESOURCE_TYPE_FRONTEND, if (!validateResourceHandle(TunerResourceManager.TUNER_RESOURCE_TYPE_FRONTEND,
frontendHandle)) { frontendHandle)) {
throw new RemoteException("frontendHandle can't be invalid"); 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) { synchronized (mLock) {
releaseFrontendInternal(getResourceIdFromHandle(frontendHandle)); releaseFrontendInternal(fe);
} }
} }
@Override @Override
public void releaseDemux(int demuxHandle) { public void releaseDemux(int demuxHandle, int clientId) {
enforceTunerAccessPermission("releaseDemux"); enforceTunerAccessPermission("releaseDemux");
enforceTrmAccessPermission("releaseDemux"); enforceTrmAccessPermission("releaseDemux");
if (DEBUG) { if (DEBUG) {
@@ -279,7 +287,7 @@ public class TunerResourceManagerService extends SystemService {
} }
@Override @Override
public void releaseDescrambler(int descramblerHandle) { public void releaseDescrambler(int descramblerHandle, int clientId) {
enforceTunerAccessPermission("releaseDescrambler"); enforceTunerAccessPermission("releaseDescrambler");
enforceTrmAccessPermission("releaseDescrambler"); enforceTrmAccessPermission("releaseDescrambler");
if (DEBUG) { if (DEBUG) {
@@ -288,7 +296,7 @@ public class TunerResourceManagerService extends SystemService {
} }
@Override @Override
public void releaseCasSession(int sessionResourceId) { public void releaseCasSession(int sessionResourceId, int clientId) {
enforceTrmAccessPermission("releaseCasSession"); enforceTrmAccessPermission("releaseCasSession");
if (DEBUG) { if (DEBUG) {
Slog.d(TAG, "releaseCasSession(sessionResourceId=" + sessionResourceId + ")"); Slog.d(TAG, "releaseCasSession(sessionResourceId=" + sessionResourceId + ")");
@@ -296,14 +304,22 @@ public class TunerResourceManagerService extends SystemService {
} }
@Override @Override
public void releaseLnb(int lnbHandle) throws RemoteException { public void releaseLnb(int lnbHandle, int clientId) throws RemoteException {
enforceTunerAccessPermission("releaseLnb"); enforceTunerAccessPermission("releaseLnb");
enforceTrmAccessPermission("releaseLnb"); enforceTrmAccessPermission("releaseLnb");
if (!validateResourceHandle(TunerResourceManager.TUNER_RESOURCE_TYPE_LNB, lnbHandle)) { if (!validateResourceHandle(TunerResourceManager.TUNER_RESOURCE_TYPE_LNB, lnbHandle)) {
throw new RemoteException("lnbHandle can't be invalid"); 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) { synchronized (mLock) {
releaseLnbInternal(getResourceIdFromHandle(lnbHandle)); releaseLnbInternal(lnb);
} }
} }
@@ -568,19 +584,19 @@ public class TunerResourceManagerService extends SystemService {
} }
@VisibleForTesting @VisibleForTesting
void releaseFrontendInternal(int frontendId) { void releaseFrontendInternal(FrontendResource fe) {
if (DEBUG) { if (DEBUG) {
Slog.d(TAG, "releaseFrontend(id=" + frontendId + ")"); Slog.d(TAG, "releaseFrontend(id=" + fe.getId() + ")");
} }
updateFrontendClientMappingOnRelease(frontendId); updateFrontendClientMappingOnRelease(fe);
} }
@VisibleForTesting @VisibleForTesting
void releaseLnbInternal(int lnbId) { void releaseLnbInternal(LnbResource lnb) {
if (DEBUG) { if (DEBUG) {
Slog.d(TAG, "releaseLnb(lnbId=" + lnbId + ")"); Slog.d(TAG, "releaseLnb(lnbId=" + lnb.getId() + ")");
} }
updateLnbClientMappingOnRelease(lnbId); updateLnbClientMappingOnRelease(lnb);
} }
@VisibleForTesting @VisibleForTesting
@@ -588,6 +604,7 @@ public class TunerResourceManagerService extends SystemService {
if (DEBUG) { if (DEBUG) {
Slog.d(TAG, "requestDemux(request=" + request + ")"); 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); demuxHandle[0] = generateResourceHandle(TunerResourceManager.TUNER_RESOURCE_TYPE_DEMUX, 0);
return true; return true;
} }
@@ -597,6 +614,7 @@ public class TunerResourceManagerService extends SystemService {
if (DEBUG) { if (DEBUG) {
Slog.d(TAG, "requestDescrambler(request=" + request + ")"); Slog.d(TAG, "requestDescrambler(request=" + request + ")");
} }
// There are enough Descrambler resources, so we don't manage Descrambler in R.
descramblerHandle[0] = descramblerHandle[0] =
generateResourceHandle(TunerResourceManager.TUNER_RESOURCE_TYPE_DESCRAMBLER, 0); generateResourceHandle(TunerResourceManager.TUNER_RESOURCE_TYPE_DESCRAMBLER, 0);
return true; return true;
@@ -694,11 +712,10 @@ public class TunerResourceManagerService extends SystemService {
} }
} }
private void updateFrontendClientMappingOnRelease(int frontendId) { private void updateFrontendClientMappingOnRelease(@NonNull FrontendResource releasingFrontend) {
FrontendResource releasingFrontend = getFrontendResource(frontendId);
ClientProfile ownerProfile = getClientProfile(releasingFrontend.getOwnerClientId()); ClientProfile ownerProfile = getClientProfile(releasingFrontend.getOwnerClientId());
releasingFrontend.removeOwner(); releasingFrontend.removeOwner();
ownerProfile.releaseFrontend(frontendId); ownerProfile.releaseFrontend(releasingFrontend.getId());
for (int exclusiveGroupMember : releasingFrontend.getExclusiveGroupMemberFeIds()) { for (int exclusiveGroupMember : releasingFrontend.getExclusiveGroupMemberFeIds()) {
getFrontendResource(exclusiveGroupMember).removeOwner(); getFrontendResource(exclusiveGroupMember).removeOwner();
ownerProfile.releaseFrontend(exclusiveGroupMember); ownerProfile.releaseFrontend(exclusiveGroupMember);
@@ -712,11 +729,10 @@ public class TunerResourceManagerService extends SystemService {
ownerProfile.useLnb(grantingId); ownerProfile.useLnb(grantingId);
} }
private void updateLnbClientMappingOnRelease(int lnbId) { private void updateLnbClientMappingOnRelease(@NonNull LnbResource releasingLnb) {
LnbResource releasingLnb = getLnbResource(lnbId);
ClientProfile ownerProfile = getClientProfile(releasingLnb.getOwnerClientId()); ClientProfile ownerProfile = getClientProfile(releasingLnb.getOwnerClientId());
releasingLnb.removeOwner(); releasingLnb.removeOwner();
ownerProfile.releaseLnb(lnbId); ownerProfile.releaseLnb(releasingLnb.getId());
} }
/** /**
@@ -761,7 +777,7 @@ public class TunerResourceManagerService extends SystemService {
private void removeFrontendResource(int removingId) { private void removeFrontendResource(int removingId) {
FrontendResource fe = getFrontendResource(removingId); FrontendResource fe = getFrontendResource(removingId);
if (fe.isInUse()) { if (fe.isInUse()) {
releaseFrontendInternal(removingId); releaseFrontendInternal(fe);
} }
for (int excGroupmemberFeId : fe.getExclusiveGroupMemberFeIds()) { for (int excGroupmemberFeId : fe.getExclusiveGroupMemberFeIds()) {
getFrontendResource(excGroupmemberFeId) getFrontendResource(excGroupmemberFeId)
@@ -789,7 +805,7 @@ public class TunerResourceManagerService extends SystemService {
private void removeLnbResource(int removingId) { private void removeLnbResource(int removingId) {
LnbResource lnb = getLnbResource(removingId); LnbResource lnb = getLnbResource(removingId);
if (lnb.isInUse()) { if (lnb.isInUse()) {
releaseLnbInternal(removingId); releaseLnbInternal(lnb);
} }
mLnbResources.remove(removingId); mLnbResources.remove(removingId);
} }

View File

@@ -519,7 +519,8 @@ public class TunerResourceManagerServiceTest {
.getFrontendResource(infos[1].getId()).isInUse()).isTrue(); .getFrontendResource(infos[1].getId()).isInUse()).isTrue();
// Release frontend // Release frontend
mTunerResourceManagerService.releaseFrontendInternal(frontendId); mTunerResourceManagerService.releaseFrontendInternal(mTunerResourceManagerService
.getFrontendResource(frontendId));
assertThat(mTunerResourceManagerService assertThat(mTunerResourceManagerService
.getFrontendResource(frontendId).isInUse()).isFalse(); .getFrontendResource(frontendId).isInUse()).isFalse();
assertThat(mTunerResourceManagerService assertThat(mTunerResourceManagerService
@@ -609,7 +610,8 @@ public class TunerResourceManagerServiceTest {
assertThat(lnbId).isEqualTo(lnbIds[0]); assertThat(lnbId).isEqualTo(lnbIds[0]);
// Release lnb // Release lnb
mTunerResourceManagerService.releaseLnbInternal(lnbId); mTunerResourceManagerService.releaseLnbInternal(mTunerResourceManagerService
.getLnbResource(lnbId));
assertThat(mTunerResourceManagerService assertThat(mTunerResourceManagerService
.getLnbResource(lnbId).isInUse()).isFalse(); .getLnbResource(lnbId).isInUse()).isFalse();
assertThat(mTunerResourceManagerService assertThat(mTunerResourceManagerService