Add initial Java wrappers with JNI implementations.
This commit is contained in:
Родитель
3bf7bfe785
Коммит
d691da732b
|
@ -96,6 +96,14 @@ if(EXISTS ${SDK_ROOT}/lib/modules/dataviewer/)
|
|||
)
|
||||
endif()
|
||||
|
||||
if(EXISTS ${SDK_ROOT}/lib/modules/privacyguard/)
|
||||
list(APPEND SRCS
|
||||
${SDK_ROOT}/lib/jni/PrivacyGuard_jni.cpp
|
||||
${SDK_ROOT}/lib/modules/privacyguard/PrivacyGuard.cpp
|
||||
${SDK_ROOT}/lib/modules/privacyguard/RegisteredFileTypes.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
if (USE_ROOM)
|
||||
add_definitions("-DUSE_ROOM")
|
||||
list(APPEND SRCS ${SDK_ROOT}/lib/offline/OfflineStorage_Room.cpp)
|
||||
|
|
|
@ -1377,7 +1377,7 @@ class Logger implements ILogger {
|
|||
|
||||
public void InitializePrivacyGuard(CommonDataContext dataContext)
|
||||
{
|
||||
PrivacyGuard.InitializePrivacyGuard(m_nativePtr, dataContext);
|
||||
PrivacyGuard.InitializePrivacyGuardFromLogger(m_nativePtr, dataContext);
|
||||
}
|
||||
|
||||
public synchronized void clearNative() {
|
||||
|
|
|
@ -1,25 +1,7 @@
|
|||
package com.microsoft.applications.events;
|
||||
|
||||
import com.microsoft.applications.events.CommonDataContext;
|
||||
import com.microsoft.applications.events.DataConcernType;
|
||||
import com.microsoft.applications.events.Logger;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
public class PrivacyGuard {
|
||||
|
||||
private static String[] vectorToStringArray(Vector<String> vectorToConvert)
|
||||
{
|
||||
String[] strings = new String[vectorToConvert.size()];
|
||||
int index = 0;
|
||||
for(String str : vectorToConvert)
|
||||
{
|
||||
strings[index++] = str;
|
||||
}
|
||||
|
||||
return strings;
|
||||
}
|
||||
|
||||
//Initialize PG
|
||||
private static native void nativeInitializePrivacyGuard(
|
||||
long iLoggerNativePtr,
|
||||
|
@ -27,65 +9,87 @@ public class PrivacyGuard {
|
|||
String machineName,
|
||||
String userName,
|
||||
String userAlias,
|
||||
String[] ipAddresses,
|
||||
String[] languageIdentifiers,
|
||||
String[] machineIds,
|
||||
String[] outOfScopeIdentifiers);
|
||||
Object[] ipAddresses,
|
||||
Object[] languageIdentifiers,
|
||||
Object[] machineIds,
|
||||
Object[] outOfScopeIdentifiers);
|
||||
|
||||
public static void InitializePrivacyGuard(long loggerNativePtr, CommonDataContext dataContext)
|
||||
/**
|
||||
* Initialize Privacy Guard from Logger
|
||||
* @param loggerNativePtr Native Ptr to ILogger, only accessible in Logger.
|
||||
* @param dataContext Common Data Context to initialize Privacy Guard with.
|
||||
*/
|
||||
public static void InitializePrivacyGuardFromLogger(long loggerNativePtr, CommonDataContext dataContext)
|
||||
{
|
||||
nativeInitializePrivacyGuard(loggerNativePtr,
|
||||
dataContext.DomainName,
|
||||
dataContext.MachineName,
|
||||
dataContext.UserName,
|
||||
dataContext.UserAlias,
|
||||
vectorToStringArray(dataContext.IpAddresses),
|
||||
vectorToStringArray(dataContext.LanguageIdentifiers),
|
||||
vectorToStringArray(dataContext.MachineIds),
|
||||
vectorToStringArray(dataContext.OutOfScopeIdentifiers));
|
||||
dataContext.IpAddresses.toArray(),
|
||||
dataContext.LanguageIdentifiers.toArray(),
|
||||
dataContext.MachineIds.toArray(),
|
||||
dataContext.OutOfScopeIdentifiers.toArray());
|
||||
|
||||
}
|
||||
|
||||
//SetEnabled
|
||||
private static native void nativeSetEnabled(boolean isEnabled);
|
||||
|
||||
/**
|
||||
* Set the Enabled state for Privacy Guard
|
||||
* @param isEnabled New Enabled value
|
||||
*/
|
||||
public static void SetEnabled(boolean isEnabled)
|
||||
{
|
||||
nativeSetEnabled(isEnabled);
|
||||
}
|
||||
|
||||
//IsEnabled
|
||||
private static native boolean nativeIsEnabled();
|
||||
|
||||
/**
|
||||
* Get the Enabled state for Privacy Guard
|
||||
* @return `true` is Privacy Guard is initialized and enabled, `false` otherwise.
|
||||
*/
|
||||
public static boolean IsEnabled()
|
||||
{
|
||||
return nativeIsEnabled();
|
||||
}
|
||||
//AppendCommonDataContext
|
||||
|
||||
private static native void nativeAppendCommonDataContext(
|
||||
String domainName,
|
||||
String machineName,
|
||||
String userName,
|
||||
String userAlias,
|
||||
String[] ipAddresses,
|
||||
String[] languageIdentifiers,
|
||||
String[] machineIds,
|
||||
String[] outOfScopeIdentifiers);
|
||||
Object[] ipAddresses,
|
||||
Object[] languageIdentifiers,
|
||||
Object[] machineIds,
|
||||
Object[] outOfScopeIdentifiers);
|
||||
|
||||
public static void AppendCommonDataContext(CommonDataContext dataContext)
|
||||
/**
|
||||
* Append fresh common data context to current instance of Privacy Guard
|
||||
* @param freshDataContext Fresh set of Common Data Context.
|
||||
*/
|
||||
public static void AppendCommonDataContext(CommonDataContext freshDataContext)
|
||||
{
|
||||
nativeAppendCommonDataContext(
|
||||
dataContext.DomainName,
|
||||
dataContext.MachineName,
|
||||
dataContext.UserName,
|
||||
dataContext.UserAlias,
|
||||
vectorToStringArray(dataContext.IpAddresses),
|
||||
vectorToStringArray(dataContext.LanguageIdentifiers),
|
||||
vectorToStringArray(dataContext.MachineIds),
|
||||
vectorToStringArray(dataContext.OutOfScopeIdentifiers));
|
||||
freshDataContext.DomainName,
|
||||
freshDataContext.MachineName,
|
||||
freshDataContext.UserName,
|
||||
freshDataContext.UserAlias,
|
||||
freshDataContext.IpAddresses.toArray(),
|
||||
freshDataContext.LanguageIdentifiers.toArray(),
|
||||
freshDataContext.MachineIds.toArray(),
|
||||
freshDataContext.OutOfScopeIdentifiers.toArray());
|
||||
}
|
||||
|
||||
//AddIgnoredConcern
|
||||
private static native void nativeAddIgnoredConcern(String eventName, String fieldName, int dataConcern);
|
||||
|
||||
/**
|
||||
* Add a known concern to be ignored.
|
||||
* @param eventName EventName that might contain a concern. <b>Note:</b> If the ignored concern applies to Semantic Context field, set the Event name to 'SemanticContext'.
|
||||
* @param fieldName FieldName that might contain a concern.
|
||||
* @param dataConcern Specific DataConcernType you wish to ignore for the given event and field combination.
|
||||
*/
|
||||
public static void AddIgnoredConcern(String eventName, String fieldName, DataConcernType dataConcern)
|
||||
{
|
||||
nativeAddIgnoredConcern(eventName, fieldName, dataConcern.getValue());
|
||||
|
|
|
@ -174,4 +174,43 @@ EventProperties GetEventProperties(JNIEnv* env, const jstring& jstrEventName, co
|
|||
return eventProperties;
|
||||
}
|
||||
|
||||
std::vector<std::string> ConvertJObjectArrayToStdStringVector(JNIEnv* env, const jobjectArray& jArrayToConvert)
|
||||
{
|
||||
std::vector<std::string> stringVector;
|
||||
for(int i = 0; i < env->GetArrayLength(jArrayToConvert); i++)
|
||||
{
|
||||
auto jStringValue = static_cast<jstring>(env->GetObjectArrayElement(jArrayToConvert, i));
|
||||
auto stringValue = JStringToStdString(env, jStringValue);
|
||||
if(!stringValue.empty())
|
||||
{
|
||||
stringVector.push_back(stringValue);
|
||||
}
|
||||
}
|
||||
|
||||
return stringVector;
|
||||
}
|
||||
|
||||
CommonDataContexts GenerateCommonDataContextObject(JNIEnv *env,
|
||||
jstring domainName,
|
||||
jstring machineName,
|
||||
jstring userName,
|
||||
jstring userAlias,
|
||||
jobjectArray ipAddresses,
|
||||
jobjectArray languageIdentifiers,
|
||||
jobjectArray machineIds,
|
||||
jobjectArray outOfScopeIdentifiers) {
|
||||
CommonDataContexts cdc;
|
||||
cdc.DomainName = JStringToStdString(env, domainName);
|
||||
cdc.MachineName = JStringToStdString(env, machineName);
|
||||
cdc.UserName = JStringToStdString(env, userName);
|
||||
cdc.UserAlias = JStringToStdString(env, userAlias);
|
||||
cdc.IpAddresses = ConvertJObjectArrayToStdStringVector(env, ipAddresses);
|
||||
cdc.LanguageIdentifiers = ConvertJObjectArrayToStdStringVector(env, languageIdentifiers);
|
||||
cdc.MachineIds = ConvertJObjectArrayToStdStringVector(env, machineIds);
|
||||
cdc.OutOfScopeIdentifiers = ConvertJObjectArrayToStdStringVector(env, outOfScopeIdentifiers);
|
||||
|
||||
return cdc;
|
||||
}
|
||||
|
||||
|
||||
} MAT_NS_END
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <jni.h>
|
||||
#include <include/public/EventProperties.hpp>
|
||||
#include <include/public/IDataInspector.hpp>
|
||||
#include "Version.hpp"
|
||||
|
||||
#define MAT_USE_WEAK_LOGMANAGER
|
||||
|
@ -26,4 +27,16 @@ namespace MAT_NS_BEGIN
|
|||
EventProperties GetEventProperties(JNIEnv*, const jstring&, const jstring&, const jint&, const jint&,
|
||||
const jdouble&, const jlong&, const jlong&, const jobjectArray&, const jobjectArray&);
|
||||
|
||||
std::vector<std::string> ConvertJObjectArrayToStdStringVector(JNIEnv* env, const jobjectArray& jArray);
|
||||
|
||||
CommonDataContexts GenerateCommonDataContextObject(JNIEnv *env,
|
||||
jstring domainName,
|
||||
jstring machineName,
|
||||
jstring userName,
|
||||
jstring userAlias,
|
||||
jobjectArray ipAddresses,
|
||||
jobjectArray languageIdentifiers,
|
||||
jobjectArray machineIds,
|
||||
jobjectArray outOfScopeIdentifiers);
|
||||
|
||||
} MAT_NS_END
|
||||
|
|
|
@ -0,0 +1,98 @@
|
|||
#include <jni.h>
|
||||
#include "modules/privacyguard/PrivacyGuard.hpp"
|
||||
#include "JniConvertors.hpp"
|
||||
|
||||
using namespace MAT;
|
||||
|
||||
extern "C"
|
||||
{
|
||||
std::shared_ptr<PrivacyGuard> spPrivacyGuard;
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_microsoft_applications_events_PrivacyGuard_nativeInitializePrivacyGuard(
|
||||
JNIEnv *env, jclass /* this */, jlong iLoggerNativePtr,
|
||||
jstring domainName,
|
||||
jstring machineName,
|
||||
jstring userName,
|
||||
jstring userAlias,
|
||||
jobjectArray ipAddresses,
|
||||
jobjectArray languageIdentifiers,
|
||||
jobjectArray machineIds,
|
||||
jobjectArray outOfScopeIdentifiers) {
|
||||
if (spPrivacyGuard != nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto logger = reinterpret_cast<ILogger *>(iLoggerNativePtr);
|
||||
auto cdc = std::make_unique<CommonDataContexts>(GenerateCommonDataContextObject(env,
|
||||
domainName,
|
||||
machineName,
|
||||
userName,
|
||||
userAlias,
|
||||
ipAddresses,
|
||||
languageIdentifiers,
|
||||
machineIds,
|
||||
outOfScopeIdentifiers));
|
||||
|
||||
spPrivacyGuard = std::make_shared<PrivacyGuard>(logger, std::move(cdc));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_microsoft_applications_events_PrivacyGuard_nativeSetEnabled(JNIEnv *env, jclass /*this*/,
|
||||
jboolean isEnabled) {
|
||||
if (spPrivacyGuard != nullptr) {
|
||||
spPrivacyGuard->SetEnabled(static_cast<bool>(isEnabled));
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_microsoft_applications_events_PrivacyGuard_nativeIsEnabled(JNIEnv *env, jclass /*this*/) {
|
||||
return spPrivacyGuard != nullptr && spPrivacyGuard->IsEnabled();
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_microsoft_applications_events_PrivacyGuard_nativeAppendCommonDataContext(
|
||||
JNIEnv *env, jclass /* this */,
|
||||
jstring domainName,
|
||||
jstring machineName,
|
||||
jstring userName,
|
||||
jstring userAlias,
|
||||
jobjectArray ipAddresses,
|
||||
jobjectArray languageIdentifiers,
|
||||
jobjectArray machineIds,
|
||||
jobjectArray outOfScopeIdentifiers) {
|
||||
if (spPrivacyGuard == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto cdc = std::make_unique<CommonDataContexts>(GenerateCommonDataContextObject(env,
|
||||
domainName,
|
||||
machineName,
|
||||
userName,
|
||||
userAlias,
|
||||
ipAddresses,
|
||||
languageIdentifiers,
|
||||
machineIds,
|
||||
outOfScopeIdentifiers));
|
||||
|
||||
spPrivacyGuard->AppendCommonDataContext(std::move(cdc));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_microsoft_applications_events_PrivacyGuard_nativeAddIgnoredConcern(JNIEnv *env,
|
||||
jclass /* this */,
|
||||
jstring eventName,
|
||||
jstring fieldName,
|
||||
jint dataConcern) {
|
||||
if(spPrivacyGuard == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto eventNameStr = JStringToStdString(env, eventName);
|
||||
auto fieldNameStr = JStringToStdString(env, fieldName);
|
||||
auto dataConcernInt = static_cast<uint8_t>(dataConcern);
|
||||
spPrivacyGuard->AddIgnoredConcern(eventNameStr, fieldNameStr, static_cast<DataConcernType >(dataConcernInt));
|
||||
}
|
||||
|
||||
}
|
Загрузка…
Ссылка в новой задаче