Skip to content

Commit

Permalink
add an extra button for foreground service
Browse files Browse the repository at this point in the history
  • Loading branch information
robertwu1 committed Jul 11, 2024
1 parent 873637a commit f16d139
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class IntentBasedTestSupport {
public static final String KEY_FILE_NAME = "file";
public static final String KEY_BUFFER_BURSTS = "buffer_bursts";
public static final String KEY_BACKGROUND = "background";
public static final String KEY_FOREGROUND_SERVICE = "foreground_service";
public static final String KEY_VOLUME = "volume";

public static final String KEY_VOLUME_TYPE = "volume_type";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class MainActivity extends BaseOboeTesterActivity {
private Bundle mBundleFromIntent;
private CheckBox mWorkaroundsCheckBox;
private CheckBox mBackgroundCheckBox;
private CheckBox mForegroundServiceCheckBox;
private static String mVersionText;

@Override
Expand Down Expand Up @@ -111,6 +112,7 @@ public void onNothingSelected(AdapterView<?> adapterView) {
NativeEngine.setWorkaroundsEnabled(false);

mBackgroundCheckBox = (CheckBox) findViewById(R.id.boxEnableBackground);
mForegroundServiceCheckBox = (CheckBox) findViewById(R.id.boxEnableForegroundService);

mBuildTextView = (TextView) findViewById(R.id.text_build_info);
mBuildTextView.setText(Build.DISPLAY
Expand Down Expand Up @@ -149,16 +151,19 @@ private void processBundleFromIntent() {
}
Intent intent = getTestIntent(mBundleFromIntent);
if (intent != null) {
setBackgroundFromIntent();
setTogglesFromIntent();
startActivity(intent);
}
mBundleFromIntent = null;
}

private void setBackgroundFromIntent() {
private void setTogglesFromIntent() {
boolean backgroundEnabled = mBundleFromIntent.getBoolean(
IntentBasedTestSupport.KEY_BACKGROUND, false);
TestAudioActivity.setBackgroundEnabled(backgroundEnabled);
boolean foregroundServiceEnabled = mBundleFromIntent.getBoolean(
IntentBasedTestSupport.KEY_FOREGROUND_SERVICE, false);
TestAudioActivity.setBackgroundEnabled(foregroundServiceEnabled);
}

private Intent getTestIntent(Bundle bundle) {
Expand Down Expand Up @@ -255,6 +260,7 @@ private void applyUserOptions() {

NativeEngine.setWorkaroundsEnabled(mWorkaroundsCheckBox.isChecked());
TestAudioActivity.setBackgroundEnabled(mBackgroundCheckBox.isChecked());
TestAudioActivity.setForegroundServiceEnabled(mForegroundServiceCheckBox.isChecked());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ abstract class TestAudioActivity extends AppCompatActivity {
private int mSampleRate;
private int mSingleTestIndex = -1;
private static boolean mBackgroundEnabled;
private static boolean mForegroundServiceEnabled;

protected Bundle mBundleFromIntent;
protected boolean mTestRunningByIntent;
Expand Down Expand Up @@ -186,6 +187,14 @@ public static boolean isBackgroundEnabled() {
return mBackgroundEnabled;
}

public static void setForegroundServiceEnabled(boolean enabled) {
mForegroundServiceEnabled = enabled;
}

public static boolean isForegroundServiceEnabled() {
return mForegroundServiceEnabled;
}

public void onStreamClosed() {
}

Expand Down Expand Up @@ -240,7 +249,9 @@ protected void onStart() {
if (mCommunicationDeviceView != null) {
mCommunicationDeviceView.onStart();
}
enableForegroundService(true);
if (isForegroundServiceEnabled()) {
enableForegroundService(true);
}
}

protected void resetConfiguration() {
Expand Down Expand Up @@ -304,7 +315,9 @@ protected void onStop() {
if (!isBackgroundEnabled()) {
Log.i(TAG, "onStop() called so stop the test =========================");
onStopTest();
enableForegroundService(false);
if (isForegroundServiceEnabled()) {
enableForegroundService(false);
}
}
if (mCommunicationDeviceView != null) {
mCommunicationDeviceView.onStop();
Expand All @@ -317,7 +330,9 @@ protected void onDestroy() {
if (isBackgroundEnabled()) {
Log.i(TAG, "onDestroy() called so stop the test =========================");
onStopTest();
enableForegroundService(false);
if (isForegroundServiceEnabled()) {
enableForegroundService(false);
}
}
mAudioState = AUDIO_STATE_CLOSED;
super.onDestroy();
Expand Down
14 changes: 12 additions & 2 deletions apps/OboeTester/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,23 @@
app:layout_constraintTop_toBottomOf="@+id/boxEnableWorkarounds" />


<CheckBox
android:id="@+id/boxEnableForegroundService"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:checked="false"
android:text="enable foreground service"
app:layout_constraintStart_toStartOf="@+id/boxEnableBackground"
app:layout_constraintTop_toBottomOf="@+id/boxEnableBackground" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mode:"
app:layout_constraintBaseline_toBaselineOf="@+id/spinnerAudioMode"
app:layout_constraintStart_toStartOf="@+id/boxEnableBackground" />
app:layout_constraintStart_toStartOf="@+id/boxEnableForegroundService" />

<Spinner
android:id="@+id/spinnerAudioMode"
Expand All @@ -218,7 +228,7 @@
android:entries="@array/audio_modes"
android:prompt="@string/audio_mode_prompt"
app:layout_constraintStart_toEndOf="@+id/textView2"
app:layout_constraintTop_toBottomOf="@+id/boxEnableBackground" />
app:layout_constraintTop_toBottomOf="@+id/boxEnableForegroundService" />

<TextView
android:id="@+id/deviceView"
Expand Down

0 comments on commit f16d139

Please sign in to comment.