Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ public interface ILogManager extends AutoCloseable {

public boolean unregisterSignals();

public boolean registerSanitizer();

public boolean unregisterSanitizer();

public void pauseActivity();
public void resumeActivity();
public void waitPause();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,18 @@ public static boolean unregisterSignals() {
return Signals.isInitialized() && nativeUnregisterSignalsOnDefaultLogManager();
}

private static native boolean nativeRegisterSanitizerOnDefaultLogManager();

public static boolean registerSanitizer() {
return Sanitizer.isInitialized() && nativeRegisterSanitizerOnDefaultLogManager();
}

private static native boolean nativeUnregisterSanitizerOnDefaultLogManager();

public static boolean unregisterSanitizer() {
return Sanitizer.isInitialized() && nativeUnregisterSanitizerOnDefaultLogManager();
}

public static native void pauseActivity();
public static native void resumeActivity();
public static native void waitPause();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,18 @@ public boolean unregisterSignals() {
return Signals.isInitialized() && nativeUnregisterSignals(nativeLogManager);
}

private native boolean nativeRegisterSanitizer(long nativeLogManager);
@Override
public boolean registerSanitizer() {
return Sanitizer.isInitialized() && nativeRegisterSanitizer(nativeLogManager);
}

private native boolean nativeUnregisterSanitizer(long nativeLogManager);
@Override
public boolean unregisterSanitizer() {
return Sanitizer.isInitialized() && nativeUnregisterSanitizer(nativeLogManager);
}

protected native void nativePauseActivity(long nativeLogManager);
protected native void nativeResumeActivity(long nativeLogManager);
protected native void nativeWaitPause(long nativeLogManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@

public class Sanitizer {

/**
* Initializes the sanitizer with the given logger pointer and optional notification event name.
*
* @param loggerNativePtr Native pointer to ILogger.
* @param notificationEventName Optional event name for sanitizer notifications.
* @param enforceSanitization Flag to control whether sanitization is enforced.
* @return true if initialization was successful, false otherwise.
*/
private static native boolean nativeInitialize(long loggerNativePtr, String notificationEventName, boolean enforceSanitization);

/**
* Initializes the sanitizer with the provided configuration.
*
Expand Down Expand Up @@ -43,16 +53,7 @@ public static boolean initialize(SanitizerConfiguration config) {
*/
public static native boolean isInitialized();

/**
* Initializes the sanitizer with the given logger pointer and optional notification event name.
*
* @param loggerNativePtr Native pointer to ILogger.
* @param notificationEventName Optional event name for sanitizer notifications.
* @param warningsOff Flag to control whether warnings are suppressed.
* @return true if initialization was successful, false otherwise.
*/
public static native boolean nativeInitialize(long loggerNativePtr, String notificationEventName, boolean warningsOff);


/**
* Uninitializes the sanitizer.
*
Expand Down
67 changes: 67 additions & 0 deletions lib/jni/LogManager_jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
#include "modules/signals/Signals.hpp"
#define HAS_SS true
#endif
#if __has_include("modules/sanitizer/Sanitizer.hpp")
#include "SanitizerHelper.hpp"
#include "modules/sanitizer/Sanitizer.hpp"
#define HAS_SAN true
#endif
#endif

#include <utils/Utils.hpp>
Expand Down Expand Up @@ -346,6 +351,34 @@ extern "C"
logManager->RemoveDataInspector(ss->GetName());
return true;
}
#endif
return false;
}

JNIEXPORT jboolean JNICALL
Java_com_microsoft_applications_events_LogManager_nativeRegisterSanitizerOnDefaultLogManager(
JNIEnv *env, jclass clazz) {
#if HAS_SAN
auto logManager = WrapperLogManager::GetInstance();
auto ss = SanitizerHelper::GetSanitizerPtr();
if (ss != nullptr) {
logManager->SetDataInspector(ss);
return true;
}
#endif
return false;
}

JNIEXPORT jboolean JNICALL
Java_com_microsoft_applications_events_LogManager_nativeUnregisterSanitizerOnDefaultLogManager(
JNIEnv *env, jclass clazz) {
#if HAS_SAN
auto logManager = WrapperLogManager::GetInstance();
auto ss = SanitizerHelper::GetSanitizerPtr();
if (ss != nullptr) {
logManager->RemoveDataInspector(ss->GetName());
return true;
}
#endif
return false;
}
Expand Down Expand Up @@ -1640,6 +1673,23 @@ Java_com_microsoft_applications_events_LogManagerProvider_00024LogManagerImpl_na
return false;
}

extern "C"
JNIEXPORT jboolean JNICALL
Java_com_microsoft_applications_events_LogManagerProvider_00024LogManagerImpl_nativeRegisterSanitizer(
JNIEnv *env,
jobject thiz,
jlong native_log_manager) {
#if HAS_SAN
auto logManager = getLogManager(native_log_manager);
auto sa = SanitizerHelper::GetSanitizerPtr();
if (sa != nullptr) {
logManager->SetDataInspector(sa);
return true;
}
#endif
return false;
}

extern "C"
JNIEXPORT void JNICALL
Java_com_microsoft_applications_events_LogManager_pauseActivity(JNIEnv *env, jclass clazz) {
Expand Down Expand Up @@ -1734,6 +1784,23 @@ Java_com_microsoft_applications_events_LogManagerProvider_00024LogManagerImpl_na
return false;
}

extern "C"
JNIEXPORT jboolean JNICALL
Java_com_microsoft_applications_events_LogManagerProvider_00024LogManagerImpl_nativeUnregisterSanitizer(
JNIEnv *env,
jobject thiz,
jlong native_log_manager) {
#if HAS_SAN
auto logManager = getLogManager(native_log_manager);
auto sa = SanitizerHelper::GetSanitizerPtr();
if (sa != nullptr) {
logManager->RemoveDataInspector(sa->GetName());
return true;
}
#endif
return false;
}

extern "C"
JNIEXPORT jboolean JNICALL
Java_com_microsoft_applications_events_LogManagerProvider_00024LogManagerImpl_nativeStartActivity(
Expand Down
2 changes: 1 addition & 1 deletion lib/jni/Sanitizer_jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Java_com_microsoft_applications_events_Sanitizer_nativeInitialize(
SanitizerConfiguration sanitizerConfig(reinterpret_cast<ILogger*>(iLoggerNativePtr));

if (notificationEventName != nullptr) {
sanitizerConfig.NotificationEventName = JStringToStdString(env, notificationEventName).c_str();
sanitizerConfig.NotificationEventName = JStringToStdString(env, notificationEventName);
}

sanitizerConfig.SetAllWarningsToSanitizations = static_cast<bool>(warningsToSanitization);
Expand Down
Loading