@@ -7,6 +7,10 @@ import android.os.Build
7
7
import android.os.Process
8
8
import com.google.android.gms.common.util.ProcessUtils
9
9
10
+ /* *
11
+ * A singleton that contains helper functions to get relevant process details. TODO(b/418041083):
12
+ * Explore using a common utility.
13
+ */
10
14
object AppProcessesProvider {
11
15
/* * Gets the details for all of this app's running processes. */
12
16
@JvmStatic
@@ -22,18 +26,19 @@ object AppProcessesProvider {
22
26
}
23
27
24
28
/* *
25
- * Gets this app's current process details .
29
+ * Gets this app's current process name .
26
30
*
27
31
* If the current process details are not found for whatever reason, returns app's package name.
28
32
*/
29
33
@JvmStatic
30
34
fun getProcessName (context : Context ): String {
31
35
val pid = Process .myPid()
32
- return getAppProcesses(context).find { it.pid == pid }?.processName ? : getProcessName()
36
+ return getAppProcesses(context).find { it.pid == pid }?.processName
37
+ ? : getProcessName(default = context.packageName)
33
38
}
34
39
35
- /* * Gets the app's current process name. If it could not be found, returns an empty string . */
36
- private fun getProcessName (): String {
40
+ /* * Gets the app's current process name. If it could not be found, return the default . */
41
+ private fun getProcessName (default : String = "" ): String {
37
42
if (Build .VERSION .SDK_INT > Build .VERSION_CODES .TIRAMISU ) {
38
43
return Process .myProcessName()
39
44
}
@@ -49,7 +54,7 @@ object AppProcessesProvider {
49
54
return it
50
55
}
51
56
52
- // Default to an empty string if nothing works.
53
- return " "
57
+ // Returns default if nothing works.
58
+ return default
54
59
}
55
60
}
0 commit comments