-
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.
Disable Background Task Instrumentation (#614)
* Added logic to disable instrumentation for background task * Apply spotless * Cleanup * Cleanup * Addressed comments * Private constructor * Made the constructor private
- Loading branch information
1 parent
9385cd0
commit fdff8fa
Showing
5 changed files
with
86 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
50 changes: 50 additions & 0 deletions
50
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,50 @@ | ||
/* | ||
* Copyright Splunk Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.splunk.rum; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.app.Application; | ||
import android.os.Build; | ||
import java.lang.reflect.Method; | ||
import java.util.Objects; | ||
|
||
public final class BackgroundProcessDetector { | ||
|
||
private BackgroundProcessDetector() {} | ||
|
||
public static Boolean isBackgroundProcess(String applicationId) { | ||
String applicationProcessName = getApplicationProcessName(); | ||
return Objects.equals(applicationProcessName, applicationId); | ||
} | ||
|
||
private static String getApplicationProcessName() { | ||
if (Build.VERSION.SDK_INT >= 28) { | ||
return Application.getProcessName(); | ||
} else { | ||
try { | ||
@SuppressLint("PrivateApi") | ||
Class<?> activityThread = Class.forName("android.app.ActivityThread"); | ||
String methodName = "currentProcessName"; | ||
@SuppressLint("PrivateApi") | ||
Method getProcessName = activityThread.getDeclaredMethod(methodName); | ||
return (String) getProcessName.invoke(null); | ||
} catch (Exception e) { | ||
return null; | ||
} | ||
} | ||
} | ||
} |
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