-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added logic to disable instrumentation for background task
- Loading branch information
1 parent
f1bb12e
commit bb8a5ef
Showing
5 changed files
with
55 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
splunk-otel-android/src/main/java/com/splunk/rum/BackgroundProcessDetector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.splunk.rum; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.app.Application; | ||
import android.os.Build; | ||
import java.lang.reflect.Method; | ||
|
||
public class BackgroundProcessDetector { | ||
public static Boolean isBackgroundProcess(String applicationId) { | ||
String applicationProcessName = ""; | ||
if (Build.VERSION.SDK_INT >= 28) | ||
applicationProcessName = Application.getProcessName(); | ||
else { | ||
try { | ||
@SuppressLint("PrivateApi") | ||
Class<?> activityThread = Class.forName("android.app.ActivityThread"); | ||
String methodName = "currentProcessName"; | ||
@SuppressLint("PrivateApi") Method getProcessName = activityThread.getDeclaredMethod(methodName); | ||
applicationProcessName = (String) getProcessName.invoke(null); | ||
} catch (Exception e) { | ||
} | ||
} | ||
|
||
return applicationProcessName != null && applicationProcessName.equals(applicationId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters