1 /* 2 * Copyright 2025 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.media.projection; 18 19 import android.annotation.FlaggedApi; 20 import android.graphics.Bitmap; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 24 import androidx.annotation.NonNull; 25 26 import java.util.Objects; 27 28 /** 29 * Holds information about content an app can share via the MediaProjection APIs. 30 * <p> 31 * An application requesting a {@link MediaProjection session} can add its own content in the 32 * list of available content along with the whole screen or a single application. 33 * <p> 34 * Each instance of {@link MediaProjectionAppContent} contains an id that is used to identify the 35 * content chosen by the user back to the advertising application, thus the meaning of the id is 36 * only relevant to that application. 37 */ 38 @FlaggedApi(com.android.media.projection.flags.Flags.FLAG_APP_CONTENT_SHARING) 39 public final class MediaProjectionAppContent implements Parcelable { 40 41 private final Bitmap mThumbnail; 42 private final CharSequence mTitle; 43 private final int mId; 44 45 /** 46 * Constructor to pass a thumbnail, title and id. 47 * 48 * @param thumbnail The thumbnail representing this content to be shown to the user. 49 * @param title A user visible string representing the title of this content. 50 * @param id An arbitrary int defined by the advertising application to be fed back once 51 * the user made their choice. 52 */ MediaProjectionAppContent(@onNull Bitmap thumbnail, @NonNull CharSequence title, int id)53 public MediaProjectionAppContent(@NonNull Bitmap thumbnail, @NonNull CharSequence title, 54 int id) { 55 mThumbnail = Objects.requireNonNull(thumbnail, "thumbnail can't be null").asShared(); 56 mTitle = Objects.requireNonNull(title, "title can't be null"); 57 mId = id; 58 } 59 60 /** 61 * Returns thumbnail representing this content to be shown to the user. 62 * 63 * @hide 64 */ 65 @NonNull getThumbnail()66 public Bitmap getThumbnail() { 67 return mThumbnail; 68 } 69 70 /** 71 * Returns user visible string representing the title of this content. 72 * 73 * @hide 74 */ 75 @NonNull getTitle()76 public CharSequence getTitle() { 77 return mTitle; 78 } 79 80 /** 81 * Returns the arbitrary int defined by the advertising application to be fed back once 82 * the user made their choice. 83 * 84 * @hide 85 */ getId()86 public int getId() { 87 return mId; 88 } 89 MediaProjectionAppContent(Parcel in)90 private MediaProjectionAppContent(Parcel in) { 91 mThumbnail = in.readParcelable(this.getClass().getClassLoader(), Bitmap.class); 92 mTitle = in.readCharSequence(); 93 mId = in.readInt(); 94 } 95 96 @Override writeToParcel(@onNull Parcel dest, int flags)97 public void writeToParcel(@NonNull Parcel dest, int flags) { 98 dest.writeParcelable(mThumbnail, flags); 99 dest.writeCharSequence(mTitle); 100 dest.writeInt(mId); 101 } 102 103 @Override describeContents()104 public int describeContents() { 105 return 0; 106 } 107 108 @NonNull 109 public static final Creator<MediaProjectionAppContent> CREATOR = 110 new Creator<>() { 111 @NonNull 112 @Override 113 public MediaProjectionAppContent createFromParcel(@NonNull Parcel in) { 114 return new MediaProjectionAppContent(in); 115 } 116 117 @NonNull 118 @Override 119 public MediaProjectionAppContent[] newArray(int size) { 120 return new MediaProjectionAppContent[size]; 121 } 122 }; 123 } 124