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.service.games; 18 19 import android.annotation.IntDef; 20 import android.annotation.NonNull; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 24 import java.lang.annotation.Retention; 25 import java.lang.annotation.RetentionPolicy; 26 import java.util.Objects; 27 28 /** 29 * Result object for calls to {@link IGameSessionController#takeScreenshot}. 30 * 31 * It includes a status only (see {@link #getStatus}). 32 * 33 * @hide 34 */ 35 public final class GameScreenshotResult implements Parcelable { 36 37 /** 38 * The status of a call to {@link IGameSessionController#takeScreenshot} will be represented by 39 * one of these values. 40 * 41 * @hide 42 */ 43 @IntDef(flag = false, prefix = {"GAME_SCREENSHOT_"}, value = { 44 GAME_SCREENSHOT_SUCCESS, // 0 45 GAME_SCREENSHOT_ERROR_INTERNAL_ERROR, // 1 46 }) 47 @Retention(RetentionPolicy.SOURCE) 48 public @interface GameScreenshotStatus { 49 } 50 51 /** 52 * Indicates that the result of a call to {@link IGameSessionController#takeScreenshot} was 53 * successful. 54 * 55 * @hide 56 */ 57 public static final int GAME_SCREENSHOT_SUCCESS = 0; 58 59 /** 60 * Indicates that the result of a call to {@link IGameSessionController#takeScreenshot} failed 61 * due to an internal error. 62 * 63 * This error may occur if the device is not in a suitable state for a screenshot to be taken 64 * (e.g., the screen is off) or if the game task is not in a suitable state for a screenshot 65 * to be taken (e.g., the task is not visible). To make sure that the device and game are 66 * in a suitable state, the caller can monitor the lifecycle methods for the {@link 67 * GameSession} to make sure that the game task is focused. If the conditions are met, then the 68 * caller may try again immediately. 69 * 70 * @hide 71 */ 72 public static final int GAME_SCREENSHOT_ERROR_INTERNAL_ERROR = 1; 73 74 @NonNull 75 public static final Parcelable.Creator<GameScreenshotResult> CREATOR = 76 new Parcelable.Creator<GameScreenshotResult>() { 77 @Override 78 public GameScreenshotResult createFromParcel(Parcel source) { 79 return new GameScreenshotResult(source.readInt()); 80 } 81 82 @Override 83 public GameScreenshotResult[] newArray(int size) { 84 return new GameScreenshotResult[0]; 85 } 86 }; 87 88 @GameScreenshotStatus 89 private final int mStatus; 90 91 /** 92 * Creates a successful {@link GameScreenshotResult}. 93 */ createSuccessResult()94 public static GameScreenshotResult createSuccessResult() { 95 return new GameScreenshotResult(GAME_SCREENSHOT_SUCCESS); 96 } 97 98 /** 99 * Creates a failed {@link GameScreenshotResult} with an 100 * {@link #GAME_SCREENSHOT_ERROR_INTERNAL_ERROR} status. 101 */ createInternalErrorResult()102 public static GameScreenshotResult createInternalErrorResult() { 103 return new GameScreenshotResult(GAME_SCREENSHOT_ERROR_INTERNAL_ERROR); 104 } 105 GameScreenshotResult(@ameScreenshotStatus int status)106 private GameScreenshotResult(@GameScreenshotStatus int status) { 107 this.mStatus = status; 108 } 109 110 @Override describeContents()111 public int describeContents() { 112 return 0; 113 } 114 115 @Override writeToParcel(@onNull Parcel dest, int flags)116 public void writeToParcel(@NonNull Parcel dest, int flags) { 117 dest.writeInt(mStatus); 118 } 119 120 @GameScreenshotStatus getStatus()121 public int getStatus() { 122 return mStatus; 123 } 124 125 @Override toString()126 public String toString() { 127 return "GameScreenshotResult{" 128 + "mStatus=" 129 + mStatus 130 + "}"; 131 } 132 133 @Override equals(Object o)134 public boolean equals(Object o) { 135 if (this == o) { 136 return true; 137 } 138 139 if (!(o instanceof GameScreenshotResult)) { 140 return false; 141 } 142 143 GameScreenshotResult that = (GameScreenshotResult) o; 144 return mStatus == that.mStatus; 145 } 146 147 @Override hashCode()148 public int hashCode() { 149 return Objects.hash(mStatus); 150 } 151 } 152