Merge "Make Tuner resource reclaiming synchronous"

This commit is contained in:
Android Build Prod User
2021-08-26 23:07:10 +00:00
committed by Android (Google) Code Review
3 changed files with 31 additions and 18 deletions

View File

@@ -53,7 +53,6 @@ import android.media.tv.tunerresourcemanager.TunerFrontendRequest;
import android.media.tv.tunerresourcemanager.TunerLnbRequest;
import android.media.tv.tunerresourcemanager.TunerResourceManager;
import android.os.Handler;
import android.os.HandlerExecutor;
import android.os.Looper;
import android.os.Message;
import android.os.Process;
@@ -354,7 +353,7 @@ public class Tuner implements AutoCloseable {
profile.tvInputSessionId = tvInputSessionId;
profile.useCase = useCase;
mTunerResourceManager.registerClientProfile(
profile, new HandlerExecutor(mHandler), mResourceListener, clientId);
profile, Runnable::run, mResourceListener, clientId);
mClientId = clientId[0];
mUserId = Process.myUid();

View File

@@ -21,7 +21,7 @@ package android.media.tv.tunerresourcemanager;
*
* @hide
*/
oneway interface IResourcesReclaimListener {
interface IResourcesReclaimListener {
/*
* TRM invokes this method when the client's resources need to be reclaimed.
*
@@ -30,4 +30,4 @@ oneway interface IResourcesReclaimListener {
* then grant the resource.
*/
void onReclaimResources();
}
}

View File

@@ -922,8 +922,10 @@ public class TunerResourceManagerService extends SystemService implements IBinde
}
if (clientId == fe.getOwnerClientId()) {
ClientProfile ownerClient = getClientProfile(fe.getOwnerClientId());
for (int shareOwnerId : ownerClient.getShareFeClientIds()) {
clearFrontendAndClientMapping(getClientProfile(shareOwnerId));
if (ownerClient != null) {
for (int shareOwnerId : ownerClient.getShareFeClientIds()) {
clearFrontendAndClientMapping(getClientProfile(shareOwnerId));
}
}
}
clearFrontendAndClientMapping(getClientProfile(clientId));
@@ -1039,20 +1041,13 @@ public class TunerResourceManagerService extends SystemService implements IBinde
@VisibleForTesting
protected boolean reclaimResource(int reclaimingClientId,
@TunerResourceManager.TunerResourceType int resourceType) {
if (DEBUG) {
Slog.d(TAG, "Reclaiming resources because higher priority client request resource type "
+ resourceType);
}
try {
mListeners.get(reclaimingClientId).getListener().onReclaimResources();
} catch (RemoteException e) {
Slog.e(TAG, "Failed to reclaim resources on client " + reclaimingClientId, e);
return false;
}
// Reclaim all the resources of the share owners of the frontend that is used by the current
// resource reclaimed client.
ClientProfile profile = getClientProfile(reclaimingClientId);
if (profile == null) {
return true;
}
Set<Integer> shareFeClientIds = profile.getShareFeClientIds();
for (int clientId : shareFeClientIds) {
try {
@@ -1063,6 +1058,17 @@ public class TunerResourceManagerService extends SystemService implements IBinde
}
clearAllResourcesAndClientMapping(getClientProfile(clientId));
}
if (DEBUG) {
Slog.d(TAG, "Reclaiming resources because higher priority client request resource type "
+ resourceType + ", clientId:" + reclaimingClientId);
}
try {
mListeners.get(reclaimingClientId).getListener().onReclaimResources();
} catch (RemoteException e) {
Slog.e(TAG, "Failed to reclaim resources on client " + reclaimingClientId, e);
return false;
}
clearAllResourcesAndClientMapping(profile);
return true;
}
@@ -1319,13 +1325,21 @@ public class TunerResourceManagerService extends SystemService implements IBinde
}
private void clearFrontendAndClientMapping(ClientProfile profile) {
if (profile == null) {
return;
}
for (Integer feId : profile.getInUseFrontendHandles()) {
FrontendResource fe = getFrontendResource(feId);
if (fe.getOwnerClientId() == profile.getId()) {
int ownerClientId = fe.getOwnerClientId();
if (ownerClientId == profile.getId()) {
fe.removeOwner();
continue;
}
getClientProfile(fe.getOwnerClientId()).stopSharingFrontend(profile.getId());
ClientProfile ownerClientProfile = getClientProfile(ownerClientId);
if (ownerClientProfile != null) {
ownerClientProfile.stopSharingFrontend(profile.getId());
}
}
profile.releaseFrontend();
}