Skip to content

Commit b4b8679

Browse files
committed
Add process name to each activity
1 parent 2a7279f commit b4b8679

File tree

5 files changed

+28
-0
lines changed

5 files changed

+28
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.google.firebase.testing.sessions
1818

19+
import android.app.Application
1920
import android.content.Intent
2021
import android.content.Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT
2122
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
@@ -103,6 +104,7 @@ class FirstFragment : Fragment() {
103104
intent.addFlags(FLAG_ACTIVITY_NEW_TASK)
104105
startActivity(intent)
105106
}
107+
binding.processName.setText(getProcessName())
106108
}
107109

108110
override fun onResume() {
@@ -125,5 +127,9 @@ class FirstFragment : Fragment() {
125127
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
126128
SimpleDateFormat("HH:mm:ss", Locale.getDefault()).format(Date())
127129
else "unknown"
130+
131+
fun getProcessName(): String =
132+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) Application.getProcessName()
133+
else "unknown"
128134
}
129135
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
package com.google.firebase.testing.sessions
1818

1919
import android.app.ActivityManager
20+
import android.app.Application
2021
import android.content.Intent
2122
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
2223
import android.os.Build
2324
import android.os.Bundle
2425
import android.widget.Button
26+
import android.widget.TextView
2527
import androidx.lifecycle.lifecycleScope
2628
import com.google.firebase.perf.FirebasePerformance
2729
import kotlinx.coroutines.delay
@@ -55,6 +57,7 @@ class SecondActivity : BaseActivity() {
5557
.killBackgroundProcesses("com.google.firebase.testing.sessions")
5658
}
5759
}
60+
findViewById<TextView>(R.id.process_name_second).text = getProcessName()
5861
}
5962

6063
override fun onResume() {
@@ -66,4 +69,10 @@ class SecondActivity : BaseActivity() {
6669
super.onPause()
6770
TestApplication.sessionSubscriber.unregisterView(findViewById(R.id.session_id_second_text))
6871
}
72+
73+
companion object {
74+
fun getProcessName(): String =
75+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) Application.getProcessName()
76+
else "unknown"
77+
}
6978
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@
5454
app:layout_constraintTop_toBottomOf="@id/second_crash_button"
5555
app:layout_constraintLeft_toLeftOf="parent" />
5656

57+
<TextView
58+
android:id="@+id/process_name_second"
59+
android:layout_width="match_parent"
60+
android:layout_height="wrap_content"
61+
android:text=""/>
62+
5763
<LinearLayout
5864
android:layout_width="match_parent"
5965
android:layout_height="match_parent"

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@
8787
app:layout_constraintLeft_toLeftOf="parent"
8888
app:layout_constraintTop_toBottomOf="@id/start_splitscreen_same" />
8989

90+
<TextView
91+
android:id="@+id/process_name"
92+
android:layout_width="match_parent"
93+
android:layout_height="wrap_content"
94+
android:text=""/>
95+
9096
<LinearLayout
9197
android:layout_width="match_parent"
9298
android:layout_height="match_parent"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@
3232
<string name="kill_processes_button_text">Kill Background Processes</string>
3333
<string name="no_session_text">No Session Set</string>
3434
<string name="session_id_label">Session Id: </string>
35+
<string name="process_name_label">Process Name: </string>
3536
</resources>

0 commit comments

Comments
 (0)