Skip to content

Commit 7b6dac7

Browse files
authored
Add more trace buttons to sessions test app (#7014)
Add more trace buttons to sessions test app to match the detailed test cases easier
1 parent 622955a commit 7b6dac7

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

firebase-sessions/test-app/src/main/kotlin/com/google/firebase/testing/sessions/FirstFragment.kt

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ import androidx.fragment.app.Fragment
3030
import androidx.lifecycle.lifecycleScope
3131
import com.google.firebase.crashlytics.FirebaseCrashlytics
3232
import com.google.firebase.perf.FirebasePerformance
33+
import com.google.firebase.perf.trace
3334
import com.google.firebase.testing.sessions.databinding.FragmentFirstBinding
35+
import java.net.HttpURLConnection
36+
import java.net.URL
3437
import java.util.Date
3538
import java.util.Locale
3639
import kotlinx.coroutines.Dispatchers
@@ -52,7 +55,7 @@ class FirstFragment : Fragment() {
5255
override fun onCreateView(
5356
inflater: LayoutInflater,
5457
container: ViewGroup?,
55-
savedInstanceState: Bundle?
58+
savedInstanceState: Bundle?,
5659
): View? {
5760

5861
_binding = FragmentFirstBinding.inflate(inflater, container, false)
@@ -79,6 +82,28 @@ class FirstFragment : Fragment() {
7982
performanceTrace.stop()
8083
}
8184
}
85+
binding.createTrace2.setOnClickListener {
86+
lifecycleScope.launch(Dispatchers.IO) {
87+
val performanceTrace = performance.newTrace("test_trace_2")
88+
performanceTrace.start()
89+
delay(1200)
90+
performanceTrace.stop()
91+
}
92+
}
93+
binding.createNetworkTrace.setOnClickListener {
94+
lifecycleScope.launch(Dispatchers.IO) {
95+
val url = URL("https://www.google.com")
96+
val metric =
97+
performance.newHttpMetric("https://www.google.com", FirebasePerformance.HttpMethod.GET)
98+
metric.trace {
99+
val conn = url.openConnection() as HttpURLConnection
100+
val content = conn.inputStream.bufferedReader().use { it.readText() }
101+
setHttpResponseCode(conn.responseCode)
102+
setResponsePayloadSize(content.length.toLong())
103+
conn.disconnect()
104+
}
105+
}
106+
}
82107
binding.buttonForegroundProcess.setOnClickListener {
83108
if (binding.buttonForegroundProcess.getText().startsWith("Start")) {
84109
ForegroundService.startService(requireContext(), "Starting service at ${getDateText()}")

firebase-sessions/test-app/src/main/res/layout/fragment_first.xml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,30 @@
5555
app:layout_constraintLeft_toLeftOf="parent"
5656
app:layout_constraintTop_toBottomOf="@id/button_anr" />
5757

58+
<Button
59+
android:id="@+id/create_trace_2"
60+
android:layout_width="wrap_content"
61+
android:layout_height="wrap_content"
62+
android:text="@string/create_trace_2"
63+
app:layout_constraintLeft_toLeftOf="parent"
64+
app:layout_constraintTop_toBottomOf="@id/create_trace" />
65+
66+
<Button
67+
android:id="@+id/create_network_trace"
68+
android:layout_width="wrap_content"
69+
android:layout_height="wrap_content"
70+
android:text="@string/create_network_trace"
71+
app:layout_constraintLeft_toLeftOf="parent"
72+
app:layout_constraintTop_toBottomOf="@id/create_trace_2" />
73+
74+
5875
<Button
5976
android:id="@+id/button_foreground_process"
6077
android:layout_width="wrap_content"
6178
android:layout_height="wrap_content"
6279
android:text="@string/start_foreground_service_text"
6380
app:layout_constraintLeft_toLeftOf="parent"
64-
app:layout_constraintTop_toBottomOf="@id/button_anr" />
81+
app:layout_constraintTop_toBottomOf="@id/create_network_trace" />
6582

6683
<Button
6784
android:id="@+id/start_splitscreen"

firebase-sessions/test-app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
<string name="non_fatal_button_text">Non Fatal</string>
2525
<string name="button_anr_text">ANR</string>
2626
<string name="create_trace">Create New Trace: test_trace</string>
27+
<string name="create_trace_2">Create New Trace: test_trace_2</string>
28+
<string name="create_network_trace">Create network trace</string>
2729
<string name="start_foreground_service_text">Start Foreground Service</string>
2830
<string name="start_splitcreen_text">Start splitscreen - Different activity</string>
2931
<string name="start_splitcreen_same_text">Start splitscreen - Same activity</string>

firebase-sessions/test-app/test-app.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ android {
3838

3939
defaultConfig {
4040
applicationId = "com.google.firebase.testing.sessions"
41+
applicationIdSuffix = "" // e.g. app3
4142
minSdk = minSdkVersion
4243
targetSdk = targetSdkVersion
4344
versionCode = 1
@@ -55,6 +56,7 @@ android {
5556
}
5657

5758
buildTypes {
59+
release { signingConfig = signingConfigs["debug"] }
5860
create("benchmark") {
5961
initWith(buildTypes["release"])
6062
signingConfig = signingConfigs["debug"]

0 commit comments

Comments
 (0)