Merge "[TIAF] Fix FD leak in AdBuffer" into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
c246ee42f1
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user