Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.google.firebase.perf.FirebasePerformance
import com.google.firebase.perf.trace
import com.google.firebase.testing.sessions.databinding.FragmentFirstBinding
import java.net.HttpURLConnection
import java.net.URL
import java.util.Date
import java.util.Locale
import kotlinx.coroutines.Dispatchers
Expand All @@ -52,7 +55,7 @@ class FirstFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
savedInstanceState: Bundle?,
): View? {

_binding = FragmentFirstBinding.inflate(inflater, container, false)
Expand All @@ -79,6 +82,28 @@ class FirstFragment : Fragment() {
performanceTrace.stop()
}
}
binding.createTrace2.setOnClickListener {
lifecycleScope.launch(Dispatchers.IO) {
val performanceTrace = performance.newTrace("test_trace_2")
performanceTrace.start()
delay(1200)
performanceTrace.stop()
}
}
binding.createNetworkTrace.setOnClickListener {
lifecycleScope.launch(Dispatchers.IO) {
val url = URL("https://www.google.com")
val metric =
performance.newHttpMetric("https://www.google.com", FirebasePerformance.HttpMethod.GET)
metric.trace {
val conn = url.openConnection() as HttpURLConnection
val content = conn.inputStream.bufferedReader().use { it.readText() }
setHttpResponseCode(conn.responseCode)
setResponsePayloadSize(content.length.toLong())
conn.disconnect()
}
}
}
binding.buttonForegroundProcess.setOnClickListener {
if (binding.buttonForegroundProcess.getText().startsWith("Start")) {
ForegroundService.startService(requireContext(), "Starting service at ${getDateText()}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,30 @@
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/button_anr" />

<Button
android:id="@+id/create_trace_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/create_trace_2"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/create_trace" />

<Button
android:id="@+id/create_network_trace"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/create_network_trace"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/create_trace_2" />


<Button
android:id="@+id/button_foreground_process"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/start_foreground_service_text"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/button_anr" />
app:layout_constraintTop_toBottomOf="@id/create_network_trace" />

<Button
android:id="@+id/start_splitscreen"
Expand Down
2 changes: 2 additions & 0 deletions firebase-sessions/test-app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
<string name="non_fatal_button_text">Non Fatal</string>
<string name="button_anr_text">ANR</string>
<string name="create_trace">Create New Trace: test_trace</string>
<string name="create_trace_2">Create New Trace: test_trace_2</string>
<string name="create_network_trace">Create network trace</string>
<string name="start_foreground_service_text">Start Foreground Service</string>
<string name="start_splitcreen_text">Start splitscreen - Different activity</string>
<string name="start_splitcreen_same_text">Start splitscreen - Same activity</string>
Expand Down
2 changes: 2 additions & 0 deletions firebase-sessions/test-app/test-app.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ android {

defaultConfig {
applicationId = "com.google.firebase.testing.sessions"
applicationIdSuffix = "" // e.g. app3
minSdk = minSdkVersion
targetSdk = targetSdkVersion
versionCode = 1
Expand All @@ -55,6 +56,7 @@ android {
}

buildTypes {
release { signingConfig = signingConfigs["debug"] }
create("benchmark") {
initWith(buildTypes["release"])
signingConfig = signingConfigs["debug"]
Expand Down
Loading