Debian Codegraph @

core/java/android/app/GameModeInfo.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2021 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.app;
18
19 import android.annotation.NonNull;
20 import android.annotation.SystemApi;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23
24 /**
25 * GameModeInfo returned from {@link GameManager#getGameModeInfo(String)}.
26 * @hide
27 */
28 @SystemApi
29 public final class GameModeInfo implements Parcelable {
30
31 public static final @NonNull Creator<GameModeInfo> CREATOR = new Creator<GameModeInfo>() {
32 @Override
33 public GameModeInfo createFromParcel(Parcel in) {
34 return new GameModeInfo(in);
35 }
36
37 @Override
38 public GameModeInfo[] newArray(int size) {
39 return new GameModeInfo[size];
40 }
41 };
42
43 public GameModeInfo(@GameManager.GameMode int activeGameMode,
44 @NonNull @GameManager.GameMode int[] availableGameModes) {
45 mActiveGameMode = activeGameMode;
46 mAvailableGameModes = availableGameModes;
47 }
48
49 GameModeInfo(Parcel in) {
50 mActiveGameMode = in.readInt();
51 final int availableGameModesCount = in.readInt();
52 mAvailableGameModes = new int[availableGameModesCount];
53 in.readIntArray(mAvailableGameModes);
54 }
55
56 /**
57 * Returns the {@link GameManager.GameMode} the application is currently using.
58 * Developers can enable game modes by adding
59 * <code>
60 * <meta-data android:name="android.game_mode_intervention"
61 * android:resource="@xml/GAME_MODE_CONFIG_FILE" />
62 * </code>
63 * to the {@link <application> tag}, where the GAME_MODE_CONFIG_FILE is an XML file that
64 * specifies the game mode enablement and configuration:
65 * <code>
66 * <game-mode-config xmlns:android="http://schemas.android.com/apk/res/android"
67 * android:gameModePerformance="true"
68 * android:gameModeBattery="false"
69 * />
70 * </code>
71 */
72 public @GameManager.GameMode int getActiveGameMode() {
73 return mActiveGameMode;
74 }
75
76 /**
77 * The collection of {@link GameManager.GameMode GameModes} that can be applied to the game.
78 */
79 @NonNull
80 public @GameManager.GameMode int[] getAvailableGameModes() {
81 return mAvailableGameModes;
82 }
83
84 // Ideally there should be callback that the caller can register to know when the available
85 // GameMode and/or the active GameMode is changed, however, there's no concrete use case
86 // at the moment so there's no callback mechanism introduced .
87 private final @GameManager.GameMode int[] mAvailableGameModes;
88 private final @GameManager.GameMode int mActiveGameMode;
89
90 @Override
91 public int describeContents() {
92 return 0;
93 }
94
95 @Override
96 public void writeToParcel(@NonNull Parcel dest, int flags) {
97 dest.writeInt(mActiveGameMode);
98 dest.writeInt(mAvailableGameModes.length);
99 dest.writeIntArray(mAvailableGameModes);
100 }
101 }