Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ea3dee10 authored by shubang's avatar shubang
Browse files

[TIAF] Fix FD leak in AdBuffer

And add metadata keys.

Bug: 280886498
Test: atest TvInteractiveAppServiceTest#testNotifyAdBufferReady
Change-Id: Ib72139a80a671c6990e5fda1ccb6508ce2129155
parent 9c850b8a
Loading
Loading
Loading
Loading
+12 −0
Original line number Original line Diff line number Diff line
@@ -22,6 +22,8 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable;
import android.os.SharedMemory;
import android.os.SharedMemory;


import java.io.IOException;

/**
/**
 * Buffer for advertisement data.
 * Buffer for advertisement data.
 */
 */
@@ -57,6 +59,16 @@ public final class AdBuffer implements Parcelable {
        this.mFlags = flags;
        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.
     * Gets corresponding AD request ID.
     *
     *
+16 −0
Original line number Original line Diff line number Diff line
@@ -72,6 +72,22 @@ public final class AdRequest implements Parcelable {
    private final Bundle mMetadata;
    private final Bundle mMetadata;
    private final Uri mUri;
    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,
    public AdRequest(int id, @RequestType int requestType,
            @Nullable ParcelFileDescriptor fileDescriptor, long startTime, long stopTime,
            @Nullable ParcelFileDescriptor fileDescriptor, long startTime, long stopTime,
            long echoInterval, @Nullable String mediaFileType, @NonNull Bundle metadata) {
            long echoInterval, @Nullable String mediaFileType, @NonNull Bundle metadata) {
+4 −0
Original line number Original line Diff line number Diff line
@@ -3737,6 +3737,10 @@ public final class TvInputManager {
                mService.notifyAdBufferReady(mToken, buffer, mUserId);
                mService.notifyAdBufferReady(mToken, buffer, mUserId);
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
                throw e.rethrowFromSystemServer();
            } finally {
                if (buffer != null) {
                    buffer.getSharedMemory().close();
                }
            }
            }
        }
        }


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


+3 −2
Original line number Original line Diff line number Diff line
@@ -69,6 +69,7 @@ import android.widget.FrameLayout;


import com.android.internal.os.SomeArgs;
import com.android.internal.os.SomeArgs;


import java.io.IOException;
import java.lang.annotation.Retention;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.ArrayList;
@@ -1973,9 +1974,9 @@ public abstract class TvInteractiveAppService extends Service {
                                    "notifyAdBufferReady(buffer=" + buffer + ")");
                                    "notifyAdBufferReady(buffer=" + buffer + ")");
                        }
                        }
                        if (mSessionCallback != null) {
                        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);
                        Log.w(TAG, "error in notifyAdBuffer", e);
                    }
                    }
                }
                }
Loading