Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DO NOT MERGE: OboeTester: Add game mode for testing dynamic workload activity #2137

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion apps/OboeTester/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:requestLegacyExternalStorage="true"
android:banner="@mipmap/ic_launcher">
android:banner="@mipmap/ic_launcher"
android:appCategory="game">
<meta-data android:name="android.game_mode_config"
android:resource="@xml/game_mode_config" />
<activity
android:name=".MainActivity"
android:launchMode="singleTask"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,26 @@

package com.mobileer.oboetester;

import android.app.GameManager;
import android.app.GameState;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.media.AudioManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;

import androidx.annotation.RequiresApi;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Locale;
Expand Down Expand Up @@ -81,6 +90,11 @@ public class DynamicWorkloadActivity extends TestOutputActivityBase {
private int mWorkloadHigh; // this will get set later
private WorkloadView mDynamicWorkloadView;

private GameManager mGameManager;
private Spinner mGameStateModeSpinner;
private CheckBox mGameStateIsLoadingBox;
private TextView mActualGameModeView;

// Periodically query the status of the streams.
protected class WorkloadUpdateThread {
public static final int SNIFFER_UPDATE_PERIOD_MSEC = 40;
Expand Down Expand Up @@ -184,6 +198,14 @@ public void run() {
+ "\nRecovery = " + recoveryTimeString;
postResult(message);

runOnUiThread(new Runnable() {
public void run() {
if (mGameManager != null) {
mActualGameModeView.setText(convertGameModeToText(mGameManager.getGameMode()));
}
}
});

mHandler.postDelayed(runnableCode, SNIFFER_UPDATE_PERIOD_MSEC);
}
};
Expand Down Expand Up @@ -339,6 +361,29 @@ public void onClick(View view) {
mDynamicWorkloadView.setFaderNormalizedProgress(WORKLOAD_PROGRESS_FOR_70_VOICES);
}

mGameStateModeSpinner = (Spinner) findViewById(R.id.spinner_game_state_mode);
mGameStateIsLoadingBox = (CheckBox) findViewById(R.id.checkbox_is_loading);
mActualGameModeView = (TextView) findViewById(R.id.actual_game_mode);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
mGameManager = getApplicationContext().getSystemService(GameManager.class);

mGameStateModeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
setGameMode();
}

@Override
public void onNothingSelected(AdapterView<?> adapterView) {
// no-op
}
});

mGameStateIsLoadingBox.setOnClickListener(buttonView -> {
setGameMode();
});
}

updateButtons(false);
updateEnabledWidgets();
hideSettingsViews(); // make more room
Expand Down Expand Up @@ -470,4 +515,82 @@ void stopAutomaticTest() {
maybeWriteTestResult(report);
mTestRunningByIntent = false;
}

void setGameMode() {
if (mGameManager != null) {
int gameStateMode = convertTextToGameStateMode(mGameStateModeSpinner.getSelectedItem().toString());
boolean gameStateIsLoading = mGameStateIsLoadingBox.isChecked();
GameState gameState = new GameState(gameStateIsLoading, gameStateMode);
mGameManager.setGameState(gameState);
}
}

public static String convertGameStateModeToText(int gameStateMode) {
switch (gameStateMode) {
case GameState.MODE_UNKNOWN:
return "UNKNOWN";
case GameState.MODE_NONE:
return "NONE";
case GameState.MODE_GAMEPLAY_INTERRUPTIBLE:
return "GAMEPLAY_INTERRUPTIBLE";
case GameState.MODE_GAMEPLAY_UNINTERRUPTIBLE:
return "GAMEPLAY_UNINTERRUPTIBLE";
case GameState.MODE_CONTENT:
return "CONTENT";
default:
return "?=" + gameStateMode;
}
}

public static int convertTextToGameStateMode(String text) {
switch (text) {
case "UNKNOWN":
return GameState.MODE_UNKNOWN;
case "NONE":
return GameState.MODE_NONE;
case "GAMEPLAY_INTERRUPTIBLE":
return GameState.MODE_GAMEPLAY_INTERRUPTIBLE;
case "GAMEPLAY_UNINTERRUPTIBLE":
return GameState.MODE_GAMEPLAY_UNINTERRUPTIBLE;
case "CONTENT":
return GameState.MODE_CONTENT;
default:
return -1;
}
}

public static String convertGameModeToText(int gameMode)
{
switch (gameMode) {
case GameManager.GAME_MODE_UNSUPPORTED:
return "UNSUPPORTED";
case GameManager.GAME_MODE_STANDARD:
return "STANDARD";
case GameManager.GAME_MODE_PERFORMANCE:
return "PERFORMANCE";
case GameManager.GAME_MODE_BATTERY:
return "BATTERY";
case GameManager.GAME_MODE_CUSTOM:
return "CUSTOM";
default:
return "?=" + gameMode;
}
}

public static int convertTextToGameMode(String text) {
switch (text) {
case "UNSUPPORTED":
return GameManager.GAME_MODE_UNSUPPORTED;
case "STANDARD":
return GameManager.GAME_MODE_STANDARD;
case "PERFORMANCE":
return GameManager.GAME_MODE_PERFORMANCE;
case "BATTERY":
return GameManager.GAME_MODE_BATTERY;
case "CUSTOM":
return GameManager.GAME_MODE_CUSTOM;
default:
return -1;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,8 @@

<include layout="@layout/merge_audio_simple" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lines="1"
android:text="CPUs:"
android:textSize="18sp"
android:textStyle="bold" />

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
Expand Down Expand Up @@ -53,6 +44,18 @@
android:layout_height="wrap_content"
android:layout_marginRight="8sp"
android:text="Alt ADPF" />
</LinearLayout>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="@dimen/small_horizontal_margin"
android:paddingTop="@dimen/small_vertical_margin"
android:paddingRight="@dimen/small_horizontal_margin"
android:paddingBottom="@dimen/small_vertical_margin"
tools:context="com.mobileer.oboetester.DynamicWorkloadActivity">

<CheckBox
android:id="@+id/hear_workload"
Expand All @@ -70,6 +73,64 @@
android:text="Scroll" />
</LinearLayout>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="@dimen/small_horizontal_margin"
android:paddingTop="@dimen/small_vertical_margin"
android:paddingRight="@dimen/small_horizontal_margin"
android:paddingBottom="@dimen/small_vertical_margin"
tools:context="com.mobileer.oboetester.DynamicWorkloadActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/game_state_mode_prompt" />

<Spinner
android:id="@+id/spinner_game_state_mode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="@array/game_state_modes"
android:prompt="@string/game_state_mode_prompt" />
</LinearLayout>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="@dimen/small_horizontal_margin"
android:paddingTop="@dimen/small_vertical_margin"
android:paddingRight="@dimen/small_horizontal_margin"
android:paddingBottom="@dimen/small_vertical_margin"
tools:context="com.mobileer.oboetester.DynamicWorkloadActivity">

<CheckBox
android:id="@+id/checkbox_is_loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="8sp"
android:checked="false"
android:text="Is Loading" />

<TextView
android:id="@+id/actual_game_mode_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/actual_game_mode" />

<TextView
android:id="@+id/actual_game_mode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="\?" />
</LinearLayout>

<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
Expand Down
10 changes: 10 additions & 0 deletions apps/OboeTester/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -309,4 +309,14 @@
<item>50000</item>
</string-array>

<string name="game_state_mode_prompt">Game State Mode:</string>
<string-array name="game_state_modes">
<item>UNKNOWN</item>
<item>NONE</item>
<item>GAMEPLAY_INTERRUPTIBLE</item>
<item>GAMEPLAY_UNINTERRUPTIBLE</item>
<item>CONTENT</item>
</string-array>
<string name="actual_game_mode">Actual Game Mode :</string>

</resources>
6 changes: 6 additions & 0 deletions apps/OboeTester/app/src/main/res/xml/game_mode_config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<game-mode-config
xmlns:android="http://schemas.android.com/apk/res/android"
android:supportsBatteryGameMode="true"
android:supportsPerformanceGameMode="true"
/>
Loading