Skip to content

Commit 2b1b06c

Browse files
authored
OboeTester: Don't crash cold start latency for invalid paths (#2298)
1 parent 6bafbfb commit 2b1b06c

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

apps/OboeTester/app/src/main/cpp/TestColdStartLatency.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ int32_t TestColdStartLatency::open(bool useInput, bool useLowLatency, bool useMm
5252
// Revert MMAP back to its previous state
5353
AAudioExtensions::getInstance().setMMapEnabled(wasMMapEnabled);
5454

55-
mDeviceId = mStream->getDeviceId();
55+
if (result == Result::OK) {
56+
mDeviceId = mStream->getDeviceId();
57+
}
5658

5759
return (int32_t) result;
5860
}
@@ -67,6 +69,9 @@ int32_t TestColdStartLatency::start() {
6769
}
6870

6971
int32_t TestColdStartLatency::close() {
72+
if (!mStream) {
73+
return (int32_t)Result::OK;
74+
}
7075
Result result1 = mStream->requestStop();
7176
Result result2 = mStream->close();
7277
return (int32_t)((result1 != Result::OK) ? result1 : result2);

apps/OboeTester/app/src/main/java/com/mobileer/oboetester/TestColdStartLatencyActivity.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import android.widget.RadioButton;
3030
import android.widget.Spinner;
3131
import android.widget.TextView;
32+
import android.widget.Toast;
3233

3334
import androidx.appcompat.app.AppCompatActivity;
3435

@@ -133,7 +134,18 @@ public void run() {
133134
loopCount++;
134135
try {
135136
sleep(closedSleepTimeMillis);
136-
openStream(useInput, useLowLatency, useMmap, useExclusive);
137+
int result = openStream(useInput, useLowLatency, useMmap, useExclusive);
138+
if (result != 0) {
139+
runOnUiThread(new Runnable() {
140+
@Override
141+
public void run() {
142+
Toast.makeText(TestColdStartLatencyActivity.this,
143+
"Error opening stream. Error: " + result,
144+
Toast.LENGTH_SHORT).show();
145+
}
146+
});
147+
break;
148+
}
137149
log("-------#" + loopCount + " Device Id: " + getAudioDeviceId());
138150
log("open() Latency: " + getOpenTimeMicros() / 1000 + " msec");
139151
sleep(openSleepTimeMillis);

0 commit comments

Comments
 (0)