Merge "[TIAF] Fix FD leak in AdBuffer" into udc-dev

This commit is contained in:
Hongguang Chen
2023-05-05 02:15:14 +00:00
committed by Android (Google) Code Review
7 changed files with 56 additions and 4 deletions

View File

@@ -22,6 +22,8 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.os.SharedMemory;
import java.io.IOException;
/**
* Buffer for advertisement data.
*/
@@ -57,6 +59,16 @@ public final class AdBuffer implements Parcelable {
this.mFlags = flags;
}
/** @hide **/
public static AdBuffer dupAdBuffer(AdBuffer buffer) throws IOException {
if (buffer == null) {
return null;
}
return new AdBuffer(buffer.mId, buffer.mMimeType,
SharedMemory.fromFileDescriptor(buffer.mBuffer.getFdDup()), buffer.mOffset,
buffer.mLength, buffer.mPresentationTimeUs, buffer.mFlags);
}
/**
* Gets corresponding AD request ID.
*

View File

@@ -72,6 +72,22 @@ public final class AdRequest implements Parcelable {
private final Bundle mMetadata;
private final Uri mUri;
/**
* The key for video metadata.
*
* @see #getMetadata()
* @hide
*/
public static final String KEY_VIDEO_METADATA = "key_video_metadata";
/**
* The key for audio metadata.
*
* @see #getMetadata()
* @hide
*/
public static final String KEY_AUDIO_METADATA = "key_audio_metadata";
public AdRequest(int id, @RequestType int requestType,
@Nullable ParcelFileDescriptor fileDescriptor, long startTime, long stopTime,
long echoInterval, @Nullable String mediaFileType, @NonNull Bundle metadata) {

View File

@@ -3737,6 +3737,10 @@ public final class TvInputManager {
mService.notifyAdBufferReady(mToken, buffer, mUserId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
} finally {
if (buffer != null) {
buffer.getSharedMemory().close();
}
}
}

View File

@@ -1608,6 +1608,10 @@ public final class TvInteractiveAppManager {
mService.notifyAdBufferConsumed(mToken, buffer, mUserId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
} finally {
if (buffer != null) {
buffer.getSharedMemory().close();
}
}
}

View File

@@ -69,6 +69,7 @@ import android.widget.FrameLayout;
import com.android.internal.os.SomeArgs;
import java.io.IOException;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
@@ -1973,9 +1974,9 @@ public abstract class TvInteractiveAppService extends Service {
"notifyAdBufferReady(buffer=" + buffer + ")");
}
if (mSessionCallback != null) {
mSessionCallback.onAdBufferReady(buffer);
mSessionCallback.onAdBufferReady(AdBuffer.dupAdBuffer(buffer));
}
} catch (RemoteException e) {
} catch (RemoteException | IOException e) {
Log.w(TAG, "error in notifyAdBuffer", e);
}
}

View File

@@ -2629,6 +2629,10 @@ public final class TvInputManagerService extends SystemService {
getSessionLocked(sessionState).notifyAdBufferReady(buffer);
} catch (RemoteException | SessionNotFoundException e) {
Slog.e(TAG, "error in notifyAdBuffer", e);
} finally {
if (buffer != null) {
buffer.getSharedMemory().close();
}
}
}
} finally {
@@ -3891,10 +3895,13 @@ public final class TvInputManagerService extends SystemService {
return;
}
try {
mSessionState.client.onAdBufferConsumed(
buffer, mSessionState.seq);
mSessionState.client.onAdBufferConsumed(buffer, mSessionState.seq);
} catch (RemoteException e) {
Slog.e(TAG, "error in onAdBufferConsumed", e);
} finally {
if (buffer != null) {
buffer.getSharedMemory().close();
}
}
}
}

View File

@@ -2007,6 +2007,10 @@ public class TvInteractiveAppManagerService extends SystemService {
getSessionLocked(sessionState).notifyAdBufferConsumed(buffer);
} catch (RemoteException | SessionNotFoundException e) {
Slogf.e(TAG, "error in notifyAdBufferConsumed", e);
} finally {
if (buffer != null) {
buffer.getSharedMemory().close();
}
}
}
} finally {
@@ -3063,6 +3067,10 @@ public class TvInteractiveAppManagerService extends SystemService {
mSessionState.mClient.onAdBufferReady(buffer, mSessionState.mSeq);
} catch (RemoteException e) {
Slogf.e(TAG, "error in onAdBuffer", e);
} finally {
if (buffer != null) {
buffer.getSharedMemory().close();
}
}
}
}