@@ -7,6 +7,10 @@ import android.os.Build
77import android.os.Process
88import com.google.android.gms.common.util.ProcessUtils
99
10+ /* *
11+ * A singleton that contains helper functions to get relevant process details. TODO(b/418041083):
12+ * Explore using a common utility.
13+ */
1014object AppProcessesProvider {
1115 /* * Gets the details for all of this app's running processes. */
1216 @JvmStatic
@@ -22,18 +26,19 @@ object AppProcessesProvider {
2226 }
2327
2428 /* *
25- * Gets this app's current process details .
29+ * Gets this app's current process name .
2630 *
2731 * If the current process details are not found for whatever reason, returns app's package name.
2832 */
2933 @JvmStatic
3034 fun getProcessName (context : Context ): String {
3135 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)
3338 }
3439
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 {
3742 if (Build .VERSION .SDK_INT > Build .VERSION_CODES .TIRAMISU ) {
3843 return Process .myProcessName()
3944 }
@@ -49,7 +54,7 @@ object AppProcessesProvider {
4954 return it
5055 }
5156
52- // Default to an empty string if nothing works.
53- return " "
57+ // Returns default if nothing works.
58+ return default
5459 }
5560}
0 commit comments