diff options
| -rw-r--r-- | core/api/current.txt | 6 | ||||
| -rw-r--r-- | core/java/android/app/GameState.java | 48 | ||||
| -rw-r--r-- | services/core/java/com/android/server/app/GameManagerService.java | 57 |
3 files changed, 69 insertions, 42 deletions
diff --git a/core/api/current.txt b/core/api/current.txt index ddfb14b83f6c..3d5e8d85856d 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -5559,11 +5559,11 @@ package android.app { public final class GameState implements android.os.Parcelable { ctor public GameState(boolean, int); - ctor public GameState(boolean, int, @Nullable String, @NonNull android.os.Bundle); + ctor public GameState(boolean, int, int, int); method public int describeContents(); - method @Nullable public String getDescription(); - method @NonNull public android.os.Bundle getMetadata(); + method public int getLabel(); method public int getMode(); + method public int getQuality(); method public boolean isLoading(); method public void writeToParcel(@NonNull android.os.Parcel, int); field @NonNull public static final android.os.Parcelable.Creator<android.app.GameState> CREATOR; diff --git a/core/java/android/app/GameState.java b/core/java/android/app/GameState.java index 979dd34e8276..fe6e5543a662 100644 --- a/core/java/android/app/GameState.java +++ b/core/java/android/app/GameState.java @@ -18,8 +18,6 @@ package android.app; import android.annotation.IntDef; import android.annotation.NonNull; -import android.annotation.Nullable; -import android.os.Bundle; import android.os.Parcel; import android.os.Parcelable; @@ -88,12 +86,11 @@ public final class GameState implements Parcelable { // One of the states listed above. private final @GameStateMode int mMode; - // This is a game specific description. For example can be level or scene name. - private final @Nullable String mDescription; + // A developer-supplied enum, e.g. to indicate level or scene. + private final int mLabel; - // This contains any other game specific parameters not covered by the fields above. It can be - // quality parameter data, settings, or game modes. - private final @NonNull Bundle mMetaData; + // The developer-supplied enum, e.g. to indicate the current quality level. + private final int mQuality; /** * Create a GameState with the specified loading status. @@ -101,29 +98,28 @@ public final class GameState implements Parcelable { * @param mode The game state mode of type @GameStateMode. */ public GameState(boolean isLoading, @GameStateMode int mode) { - this(isLoading, mode, null, new Bundle()); + this(isLoading, mode, -1, -1); } /** * Create a GameState with the given state variables. * @param isLoading Whether the game is in the loading state. - * @param mode The game state mode of type @GameStateMode. - * @param description An optional description of the state. - * @param metaData Optional metadata. + * @param mode The game state mode. + * @param label An optional developer-supplied enum e.g. for the current level. + * @param quality An optional developer-supplied enum, e.g. for the current quality level. */ - public GameState(boolean isLoading, @GameStateMode int mode, @Nullable String description, - @NonNull Bundle metaData) { + public GameState(boolean isLoading, @GameStateMode int mode, int label, int quality) { mIsLoading = isLoading; mMode = mode; - mDescription = description; - mMetaData = metaData; + mLabel = label; + mQuality = quality; } private GameState(Parcel in) { mIsLoading = in.readBoolean(); mMode = in.readInt(); - mDescription = in.readString(); - mMetaData = in.readBundle(); + mLabel = in.readInt(); + mQuality = in.readInt(); } /** @@ -141,17 +137,19 @@ public final class GameState implements Parcelable { } /** - * @return The state description, or null if one is not set. + * @return The developer-supplied enum, e.g. to indicate level or scene. The default value (if + * not supplied) is -1. */ - public @Nullable String getDescription() { - return mDescription; + public int getLabel() { + return mLabel; } /** - * @return metadata associated with the state. + * @return The developer-supplied enum, e.g. to indicate the current quality level. The default + * value (if not suplied) is -1. */ - public @NonNull Bundle getMetadata() { - return mMetaData; + public int getQuality() { + return mQuality; } @Override @@ -163,8 +161,8 @@ public final class GameState implements Parcelable { public void writeToParcel(@NonNull Parcel parcel, int flags) { parcel.writeBoolean(mIsLoading); parcel.writeInt(mMode); - parcel.writeString(mDescription); - parcel.writeBundle(mMetaData); + parcel.writeInt(mLabel); + parcel.writeInt(mQuality); } /** diff --git a/services/core/java/com/android/server/app/GameManagerService.java b/services/core/java/com/android/server/app/GameManagerService.java index b813bc48118a..0edbea0dbd28 100644 --- a/services/core/java/com/android/server/app/GameManagerService.java +++ b/services/core/java/com/android/server/app/GameManagerService.java @@ -90,6 +90,7 @@ import com.android.internal.annotations.VisibleForTesting; import com.android.internal.compat.CompatibilityOverrideConfig; import com.android.internal.compat.IPlatformCompat; import com.android.internal.os.BackgroundThread; +import com.android.internal.util.FrameworkStatsLog; import com.android.server.LocalServices; import com.android.server.ServiceThread; import com.android.server.SystemService; @@ -268,16 +269,34 @@ public final class GameManagerService extends IGameManagerService.Stub { break; } case SET_GAME_STATE: { - if (mPowerManagerInternal == null) { - final Bundle data = msg.getData(); - Slog.d(TAG, "Error setting loading mode for package " - + data.getString(PACKAGE_NAME_MSG_KEY) - + " and userId " + data.getInt(USER_ID_MSG_KEY)); - break; - } final GameState gameState = (GameState) msg.obj; final boolean isLoading = gameState.isLoading(); - mPowerManagerInternal.setPowerMode(Mode.GAME_LOADING, isLoading); + final Bundle data = msg.getData(); + final String packageName = data.getString(PACKAGE_NAME_MSG_KEY); + final int userId = data.getInt(USER_ID_MSG_KEY); + + // Restrict to games only. Requires performance mode to be enabled. + final boolean boostEnabled = + getGameMode(packageName, userId) == GameManager.GAME_MODE_PERFORMANCE; + int uid; + try { + uid = mPackageManager.getPackageUidAsUser(packageName, userId); + } catch (NameNotFoundException e) { + Slog.v(TAG, "Failed to get package metadata"); + uid = -1; + } + FrameworkStatsLog.write(FrameworkStatsLog.GAME_STATE_CHANGED, packageName, uid, + boostEnabled, gameStateModeToStatsdGameState(gameState.getMode()), + isLoading, gameState.getLabel(), gameState.getQuality()); + + if (boostEnabled) { + if (mPowerManagerInternal == null) { + Slog.d(TAG, "Error setting loading mode for package " + packageName + + " and userId " + userId); + break; + } + mPowerManagerInternal.setPowerMode(Mode.GAME_LOADING, isLoading); + } break; } } @@ -387,12 +406,6 @@ public final class GameManagerService extends IGameManagerService.Stub { // Restrict to games only. return; } - - if (getGameMode(packageName, userId) != GameManager.GAME_MODE_PERFORMANCE) { - // Requires performance mode to be enabled. - return; - } - final Message msg = mHandler.obtainMessage(SET_GAME_STATE); final Bundle data = new Bundle(); data.putString(PACKAGE_NAME_MSG_KEY, packageName); @@ -1543,6 +1556,22 @@ public final class GameManagerService extends IGameManagerService.Stub { return out.toString(); } + private static int gameStateModeToStatsdGameState(int mode) { + switch (mode) { + case GameState.MODE_NONE: + return FrameworkStatsLog.GAME_STATE_CHANGED__STATE__MODE_NONE; + case GameState.MODE_GAMEPLAY_INTERRUPTIBLE: + return FrameworkStatsLog.GAME_STATE_CHANGED__STATE__MODE_GAMEPLAY_INTERRUPTIBLE; + case GameState.MODE_GAMEPLAY_UNINTERRUPTIBLE: + return FrameworkStatsLog.GAME_STATE_CHANGED__STATE__MODE_GAMEPLAY_UNINTERRUPTIBLE; + case GameState.MODE_CONTENT: + return FrameworkStatsLog.GAME_STATE_CHANGED__STATE__MODE_CONTENT; + case GameState.MODE_UNKNOWN: + default: + return FrameworkStatsLog.GAME_STATE_CHANGED__STATE__MODE_UNKNOWN; + } + } + private static ServiceThread createServiceThread() { ServiceThread handlerThread = new ServiceThread(TAG, Process.THREAD_PRIORITY_BACKGROUND, true /*allowIo*/); |