1 /* 2 * Copyright (C) 2022 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 static android.view.Display.DEFAULT_DISPLAY; 20 21 import static java.lang.annotation.RetentionPolicy.SOURCE; 22 23 import android.annotation.IntDef; 24 import android.annotation.IntRange; 25 import android.annotation.NonNull; 26 import android.annotation.Nullable; 27 import android.os.Parcelable; 28 29 import com.android.internal.util.AnnotationValidations; 30 import com.android.internal.util.DataClass; 31 32 import java.lang.annotation.Retention; 33 34 /** 35 * Configure the {@link MediaProjection} session requested from 36 * {@link MediaProjectionManager#createScreenCaptureIntent(MediaProjectionConfig)}. 37 */ 38 @DataClass( 39 genEqualsHashCode = true, 40 genAidl = true, 41 genSetters = false, 42 genConstructor = false, 43 genBuilder = false, 44 genToString = false, 45 genHiddenConstDefs = true, 46 genHiddenGetters = true, 47 genConstDefs = false 48 ) 49 public final class MediaProjectionConfig implements Parcelable { 50 51 /** 52 * The user, rather than the host app, determines which region of the display to capture. 53 * @hide 54 */ 55 public static final int CAPTURE_REGION_USER_CHOICE = 0; 56 57 /** 58 * The host app specifies a particular display to capture. 59 * @hide 60 */ 61 public static final int CAPTURE_REGION_FIXED_DISPLAY = 1; 62 63 /** @hide */ 64 @IntDef(prefix = "CAPTURE_REGION_", value = { 65 CAPTURE_REGION_USER_CHOICE, 66 CAPTURE_REGION_FIXED_DISPLAY 67 }) 68 @Retention(SOURCE) 69 public @interface CaptureRegion { 70 } 71 72 /** 73 * The particular display to capture. Only used when {@link #getRegionToCapture()} is 74 * {@link #CAPTURE_REGION_FIXED_DISPLAY}; ignored otherwise. 75 * 76 * Only supports values of {@link android.view.Display#DEFAULT_DISPLAY}. 77 */ 78 @IntRange(from = DEFAULT_DISPLAY, to = DEFAULT_DISPLAY) 79 private int mDisplayToCapture; 80 81 /** 82 * The region to capture. Defaults to the user's choice. 83 */ 84 @CaptureRegion 85 private int mRegionToCapture = CAPTURE_REGION_USER_CHOICE; 86 87 /** 88 * Default instance, with region set to the user's choice. 89 */ MediaProjectionConfig()90 private MediaProjectionConfig() { 91 } 92 93 /** 94 * Customized instance, with region set to the provided value. 95 */ MediaProjectionConfig(@aptureRegion int captureRegion)96 private MediaProjectionConfig(@CaptureRegion int captureRegion) { 97 mRegionToCapture = captureRegion; 98 } 99 100 /** 101 * Returns an instance which restricts the user to capturing the default display. 102 */ 103 @NonNull createConfigForDefaultDisplay()104 public static MediaProjectionConfig createConfigForDefaultDisplay() { 105 MediaProjectionConfig config = new MediaProjectionConfig(CAPTURE_REGION_FIXED_DISPLAY); 106 config.mDisplayToCapture = DEFAULT_DISPLAY; 107 return config; 108 } 109 110 /** 111 * Returns an instance which allows the user to decide which region is captured. The consent 112 * dialog presents the user with all possible options. If the user selects display capture, 113 * then only the {@link android.view.Display#DEFAULT_DISPLAY} is supported. 114 * 115 * <p> 116 * When passed in to 117 * {@link MediaProjectionManager#createScreenCaptureIntent(MediaProjectionConfig)}, the consent 118 * dialog shown to the user will be the same as if just 119 * {@link MediaProjectionManager#createScreenCaptureIntent()} was invoked. 120 * </p> 121 */ 122 @NonNull createConfigForUserChoice()123 public static MediaProjectionConfig createConfigForUserChoice() { 124 return new MediaProjectionConfig(CAPTURE_REGION_USER_CHOICE); 125 } 126 127 /** 128 * Returns string representation of the captured region. 129 */ 130 @NonNull captureRegionToString(int value)131 private static String captureRegionToString(int value) { 132 switch (value) { 133 case CAPTURE_REGION_USER_CHOICE: 134 return "CAPTURE_REGION_USERS_CHOICE"; 135 case CAPTURE_REGION_FIXED_DISPLAY: 136 return "CAPTURE_REGION_GIVEN_DISPLAY"; 137 default: 138 return Integer.toHexString(value); 139 } 140 } 141 142 @Override toString()143 public String toString() { 144 return "MediaProjectionConfig { " 145 + "displayToCapture = " + mDisplayToCapture + ", " 146 + "regionToCapture = " + captureRegionToString(mRegionToCapture) 147 + " }"; 148 } 149 150 151 152 153 154 // Code below generated by codegen v1.0.23. 155 // 156 // DO NOT MODIFY! 157 // CHECKSTYLE:OFF Generated code 158 // 159 // To regenerate run: 160 // $ codegen $ANDROID_BUILD_TOP/frameworks/base/media/java/android/media/projection/MediaProjectionConfig.java 161 // 162 // To exclude the generated code from IntelliJ auto-formatting enable (one-time): 163 // Settings > Editor > Code Style > Formatter Control 164 //@formatter:off 165 166 167 /** 168 * The particular display to capture. Only used when {@link #getRegionToCapture()} is 169 * {@link #CAPTURE_REGION_FIXED_DISPLAY}; ignored otherwise. 170 * 171 * Only supports values of {@link android.view.Display#DEFAULT_DISPLAY}. 172 * 173 * @hide 174 */ 175 @DataClass.Generated.Member getDisplayToCapture()176 public @IntRange(from = DEFAULT_DISPLAY, to = DEFAULT_DISPLAY) int getDisplayToCapture() { 177 return mDisplayToCapture; 178 } 179 180 /** 181 * The region to capture. Defaults to the user's choice. 182 * 183 * @hide 184 */ 185 @DataClass.Generated.Member getRegionToCapture()186 public @CaptureRegion int getRegionToCapture() { 187 return mRegionToCapture; 188 } 189 190 @Override 191 @DataClass.Generated.Member equals(@ullable Object o)192 public boolean equals(@Nullable Object o) { 193 // You can override field equality logic by defining either of the methods like: 194 // boolean fieldNameEquals(MediaProjectionConfig other) { ... } 195 // boolean fieldNameEquals(FieldType otherValue) { ... } 196 197 if (this == o) return true; 198 if (o == null || getClass() != o.getClass()) return false; 199 @SuppressWarnings("unchecked") 200 MediaProjectionConfig that = (MediaProjectionConfig) o; 201 //noinspection PointlessBooleanExpression 202 return true 203 && mDisplayToCapture == that.mDisplayToCapture 204 && mRegionToCapture == that.mRegionToCapture; 205 } 206 207 @Override 208 @DataClass.Generated.Member hashCode()209 public int hashCode() { 210 // You can override field hashCode logic by defining methods like: 211 // int fieldNameHashCode() { ... } 212 213 int _hash = 1; 214 _hash = 31 * _hash + mDisplayToCapture; 215 _hash = 31 * _hash + mRegionToCapture; 216 return _hash; 217 } 218 219 @Override 220 @DataClass.Generated.Member writeToParcel(@onNull android.os.Parcel dest, int flags)221 public void writeToParcel(@NonNull android.os.Parcel dest, int flags) { 222 // You can override field parcelling by defining methods like: 223 // void parcelFieldName(Parcel dest, int flags) { ... } 224 225 dest.writeInt(mDisplayToCapture); 226 dest.writeInt(mRegionToCapture); 227 } 228 229 @Override 230 @DataClass.Generated.Member describeContents()231 public int describeContents() { return 0; } 232 233 /** @hide */ 234 @SuppressWarnings({"unchecked", "RedundantCast"}) 235 @DataClass.Generated.Member MediaProjectionConfig(@onNull android.os.Parcel in)236 /* package-private */ MediaProjectionConfig(@NonNull android.os.Parcel in) { 237 // You can override field unparcelling by defining methods like: 238 // static FieldType unparcelFieldName(Parcel in) { ... } 239 240 int displayToCapture = in.readInt(); 241 int regionToCapture = in.readInt(); 242 243 this.mDisplayToCapture = displayToCapture; 244 AnnotationValidations.validate( 245 IntRange.class, null, mDisplayToCapture, 246 "from", DEFAULT_DISPLAY, 247 "to", DEFAULT_DISPLAY); 248 this.mRegionToCapture = regionToCapture; 249 AnnotationValidations.validate( 250 CaptureRegion.class, null, mRegionToCapture); 251 252 // onConstructed(); // You can define this method to get a callback 253 } 254 255 @DataClass.Generated.Member 256 public static final @NonNull Parcelable.Creator<MediaProjectionConfig> CREATOR 257 = new Parcelable.Creator<MediaProjectionConfig>() { 258 @Override 259 public MediaProjectionConfig[] newArray(int size) { 260 return new MediaProjectionConfig[size]; 261 } 262 263 @Override 264 public MediaProjectionConfig createFromParcel(@NonNull android.os.Parcel in) { 265 return new MediaProjectionConfig(in); 266 } 267 }; 268 269 @DataClass.Generated( 270 time = 1673548980960L, 271 codegenVersion = "1.0.23", 272 sourceFile = "frameworks/base/media/java/android/media/projection/MediaProjectionConfig.java", 273 inputSignatures = "public static final int CAPTURE_REGION_USER_CHOICE\npublic static final int CAPTURE_REGION_FIXED_DISPLAY\nprivate @android.annotation.IntRange int mDisplayToCapture\nprivate @android.media.projection.MediaProjectionConfig.CaptureRegion int mRegionToCapture\npublic static @android.annotation.NonNull android.media.projection.MediaProjectionConfig createConfigForDefaultDisplay()\npublic static @android.annotation.NonNull android.media.projection.MediaProjectionConfig createConfigForUserChoice()\nprivate static @android.annotation.NonNull java.lang.String captureRegionToString(int)\npublic @java.lang.Override java.lang.String toString()\nclass MediaProjectionConfig extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genEqualsHashCode=true, genAidl=true, genSetters=false, genConstructor=false, genBuilder=false, genToString=false, genHiddenConstDefs=true, genHiddenGetters=true, genConstDefs=false)") 274 @Deprecated __metadata()275 private void __metadata() {} 276 277 278 //@formatter:on 279 // End of generated code 280 281 } 282