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

Commit 7cffcfdc authored by Vishwajeet Rana's avatar Vishwajeet Rana
Browse files

Introduce support for notifying specific media projection events to enable...

Introduce support for notifying specific media projection events to enable handling of projections post-call end

Bug: 390343524
Test: atest MediaProjectionStopControllerTest
Flag: com.android.media.projection.flags.show_stop_dialog_post_call_end
Design Doc: go/dd-stop-dialog-on-call-end

Change-Id: Iad8f1f075631ae05057e211ef49e62d27cb96fe1
parent 399ca9c8
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -29,3 +29,13 @@ flag {
    is_exported: true
}

flag {
    namespace: "media_projection"
    name: "show_stop_dialog_post_call_end"
    description: "Shows a stop dialog for MediaProjection sessions that started during call and remain active after a call ends"
    bug: "390343524"
    metadata {
      purpose: PURPOSE_BUGFIX
    }
    is_exported: true
}
+16 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.media.projection;

import android.media.projection.MediaProjectionInfo;
import android.view.ContentRecordingSession;
import android.media.projection.MediaProjectionEvent;

/** {@hide} */
oneway interface IMediaProjectionWatcherCallback {
@@ -35,4 +36,19 @@ oneway interface IMediaProjectionWatcherCallback {
        in MediaProjectionInfo info,
        in @nullable ContentRecordingSession session
    );

    /**
     * Called when a specific {@link MediaProjectionEvent} occurs during the media projection session.
     *
     * @param event   contains the event type, which describes the nature/context of the event.
     * @param info    optional {@link MediaProjectionInfo} containing details about the media
                      projection host.
     * @param session the recording session for the current media projection. Can be
     *                {@code null} when the recording will stop.
     */
    void onMediaProjectionEvent(
        in MediaProjectionEvent event,
        in @nullable MediaProjectionInfo info,
        in @nullable ContentRecordingSession session
    );
}
+3 −0
Original line number Diff line number Diff line
package android.media.projection;

parcelable MediaProjectionEvent;
 No newline at end of file
+103 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.media.projection;

import android.annotation.IntDef;
import android.os.Parcel;
import android.os.Parcelable;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Objects;

/** @hide */
public final class MediaProjectionEvent implements Parcelable {

    /**
     * Represents various media projection events.
     */
    @IntDef({PROJECTION_STARTED_DURING_CALL_AND_ACTIVE_POST_CALL})
    @Retention(RetentionPolicy.SOURCE)
    public @interface EventType {}

    /** Event type for when a call ends but the session is still active. */
    public static final int PROJECTION_STARTED_DURING_CALL_AND_ACTIVE_POST_CALL = 0;

    private final @EventType int mEventType;
    private final long mTimestampMillis;

    public MediaProjectionEvent(@EventType int eventType, long timestampMillis) {
        mEventType = eventType;
        mTimestampMillis = timestampMillis;
    }

    private MediaProjectionEvent(Parcel in) {
        mEventType = in.readInt();
        mTimestampMillis = in.readLong();
    }

    public @EventType int getEventType() {
        return mEventType;
    }

    public long getTimestampMillis() {
        return mTimestampMillis;
    }

    @Override
    public boolean equals(Object o) {
        if (o instanceof MediaProjectionEvent other) {
            return mEventType == other.mEventType && mTimestampMillis == other.mTimestampMillis;
        }
        return false;
    }

    @Override
    public int hashCode() {
        return Objects.hash(mEventType, mTimestampMillis);
    }

    @Override
    public String toString() {
        return "MediaProjectionEvent{mEventType=" + mEventType + ", mTimestampMillis="
                + mTimestampMillis + "}";
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel out, int flags) {
        out.writeInt(mEventType);
        out.writeLong(mTimestampMillis);
    }

    public static final Parcelable.Creator<MediaProjectionEvent> CREATOR =
            new Parcelable.Creator<>() {
                @Override
                public MediaProjectionEvent createFromParcel(Parcel in) {
                    return new MediaProjectionEvent(in);
                }

                @Override
                public MediaProjectionEvent[] newArray(int size) {
                    return new MediaProjectionEvent[size];
                }
            };
}
+21 −0
Original line number Diff line number Diff line
@@ -363,6 +363,19 @@ public final class MediaProjectionManager {
                @Nullable ContentRecordingSession session
        ) {
        }

        /**
         * Called when a specific {@link MediaProjectionEvent} occurs during the media projection
         * session.
         *
         * @param event the media projection event details.
         * @param info optional details about the media projection host.
         * @param session optional associated recording session details.
         */
        public void onMediaProjectionEvent(
                final MediaProjectionEvent event,
                @Nullable MediaProjectionInfo info,
                @Nullable final ContentRecordingSession session) {}
    }

    /** @hide */
@@ -405,5 +418,13 @@ public final class MediaProjectionManager {
        ) {
            mHandler.post(() -> mCallback.onRecordingSessionSet(info, session));
        }

        @Override
        public void onMediaProjectionEvent(
                final MediaProjectionEvent event,
                @Nullable MediaProjectionInfo info,
                @Nullable final ContentRecordingSession session) {
            mHandler.post(() -> mCallback.onMediaProjectionEvent(event, info, session));
        }
    }
}
Loading