Address PR comments:
Add return values to initializePrivacyGuard Add return value to appendCommonDataContext Throw if appendCommonDataContext is called with null CommonDataContext Fix bug where spPrivacyGuard wasn't registered with LogManager
This commit is contained in:
Родитель
fd76d05580
Коммит
e72e003d18
|
@ -3,64 +3,49 @@ package com.microsoft.applications.events;
|
|||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* `CommonDataContexts` provide a convinient struct to convey common information to
|
||||
* `CommonDataContexts` provide a convenient struct to convey common information to
|
||||
* detect in the data being uploaded. This is expected to be internal information that
|
||||
* the host application may have access to, but do not wish to be uploaded via the 1DS
|
||||
* SDK path.
|
||||
*/
|
||||
public class CommonDataContext {
|
||||
/**
|
||||
* Default constructor to initialize all properties to default values.
|
||||
*/
|
||||
public CommonDataContext()
|
||||
{
|
||||
domainName = "";
|
||||
machineName = "";
|
||||
userName = "";
|
||||
userAlias = "";
|
||||
ipAddresses = new Vector<String>();
|
||||
languageIdentifiers = new Vector<String>();
|
||||
machineIds = new Vector<String>();
|
||||
outOfScopeIdentifiers = new Vector<String>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Domain Name for the current machine
|
||||
*/
|
||||
public String domainName;
|
||||
public String domainName = "";
|
||||
|
||||
/**
|
||||
* Friendly Machine Name
|
||||
*/
|
||||
public String machineName;
|
||||
public String machineName = "";
|
||||
|
||||
/**
|
||||
* Unique UserName such as the log-in name
|
||||
*/
|
||||
public String userName;
|
||||
public String userName = "";
|
||||
|
||||
/**
|
||||
* Unique User Alias, if different than UserName
|
||||
*/
|
||||
public String userAlias;
|
||||
public String userAlias = "";
|
||||
|
||||
/**
|
||||
* IP Addresses for local network ports such as IPv4, IPv6, etc.
|
||||
*/
|
||||
public Vector<String> ipAddresses;
|
||||
public Vector<String> ipAddresses = new Vector<>();
|
||||
|
||||
/**
|
||||
* Collection of Language identifiers
|
||||
*/
|
||||
public Vector<String> languageIdentifiers;
|
||||
public Vector<String> languageIdentifiers = new Vector<>();
|
||||
|
||||
/**
|
||||
* Collection of Machine ID such as Machine Name, Motherboard ID, MAC Address, etc.
|
||||
*/
|
||||
public Vector<String> machineIds;
|
||||
public Vector<String> machineIds = new Vector<>();
|
||||
|
||||
/**
|
||||
* Collection of OutOfScope Identifiers such as SQM_ID, Client_ID, etc.
|
||||
*/
|
||||
public Vector<String> outOfScopeIdentifiers;
|
||||
public Vector<String> outOfScopeIdentifiers = new Vector<>();
|
||||
}
|
||||
|
|
|
@ -385,5 +385,5 @@ public interface ILogger extends AutoCloseable {
|
|||
* All Data Concerns will be sent to this logger.
|
||||
* @param dataContext (Optional) Common Data Context to provide additional information to look for.
|
||||
*/
|
||||
public void InitializePrivacyGuard(CommonDataContext dataContext);
|
||||
public void initializePrivacyGuard(final CommonDataContext dataContext);
|
||||
}
|
||||
|
|
|
@ -1376,7 +1376,7 @@ class Logger implements ILogger {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void InitializePrivacyGuard(CommonDataContext dataContext)
|
||||
public void initializePrivacyGuard(final CommonDataContext dataContext)
|
||||
{
|
||||
PrivacyGuard.initializePrivacyGuardFromLogger(m_nativePtr, dataContext);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package com.microsoft.applications.events;
|
|||
public class PrivacyGuard {
|
||||
|
||||
//Initialize PG
|
||||
private static native void nativeInitializePrivacyGuard(
|
||||
private static native boolean nativeInitializePrivacyGuard(
|
||||
long iLoggerNativePtr,
|
||||
String domainName,
|
||||
String machineName,
|
||||
|
@ -14,17 +14,18 @@ public class PrivacyGuard {
|
|||
Object[] machineIds,
|
||||
Object[] outOfScopeIdentifiers);
|
||||
|
||||
private static native void nativeInitializePrivacyGuardWithoutCommonDataContext(long iLoggerNativePtr);
|
||||
private static native boolean nativeInitializePrivacyGuardWithoutCommonDataContext(long iLoggerNativePtr);
|
||||
/**
|
||||
* 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.
|
||||
* @return True if Privacy Guard has not been initalized before, False otherwise.
|
||||
*/
|
||||
/*package-private*/ static void initializePrivacyGuardFromLogger(long loggerNativePtr, CommonDataContext dataContext)
|
||||
/*package-private*/ static boolean initializePrivacyGuardFromLogger(long loggerNativePtr, final CommonDataContext dataContext)
|
||||
{
|
||||
if(dataContext != null)
|
||||
{
|
||||
nativeInitializePrivacyGuard(loggerNativePtr,
|
||||
return nativeInitializePrivacyGuard(loggerNativePtr,
|
||||
dataContext.domainName,
|
||||
dataContext.machineName,
|
||||
dataContext.userName,
|
||||
|
@ -35,15 +36,22 @@ public class PrivacyGuard {
|
|||
dataContext.outOfScopeIdentifiers.toArray());
|
||||
} else
|
||||
{
|
||||
nativeInitializePrivacyGuardWithoutCommonDataContext(loggerNativePtr);
|
||||
return nativeInitializePrivacyGuardWithoutCommonDataContext(loggerNativePtr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Uninitialize the current instance of Privacy Guard
|
||||
* This is useful if the app would like to change the logger associated with the instance of Privacy Guard.
|
||||
* @return True if Privacy Guard was uninitialized, false if Privacy Guard had not been initialized before.
|
||||
*/
|
||||
public static native boolean uninitializePrivacyGuard();
|
||||
|
||||
/**
|
||||
* Set the Enabled state for Privacy Guard
|
||||
* @param isEnabled New Enabled value
|
||||
*/
|
||||
public static native void setEnabled(boolean isEnabled);
|
||||
public static native void setEnabled(final boolean isEnabled);
|
||||
|
||||
/**
|
||||
* Get the Enabled state for Privacy Guard
|
||||
|
@ -51,7 +59,7 @@ public class PrivacyGuard {
|
|||
*/
|
||||
public static native boolean isEnabled();
|
||||
|
||||
private static native void nativeAppendCommonDataContext(
|
||||
private static native boolean nativeAppendCommonDataContext(
|
||||
String domainName,
|
||||
String machineName,
|
||||
String userName,
|
||||
|
@ -64,15 +72,17 @@ public class PrivacyGuard {
|
|||
/**
|
||||
* Append fresh common data context to current instance of Privacy Guard
|
||||
* @param freshDataContext Fresh set of Common Data Context.
|
||||
* @return False if either data is null or Privacy Guard has not been initialized yet. True otherwise.
|
||||
* @throws IllegalArgumentException if freshDataContext value is null.
|
||||
*/
|
||||
public static void appendCommonDataContext(CommonDataContext freshDataContext)
|
||||
public static boolean appendCommonDataContext(final CommonDataContext freshDataContext)
|
||||
{
|
||||
if(freshDataContext == null)
|
||||
{
|
||||
return;
|
||||
throw new IllegalArgumentException("Passed Common Data Context is null");
|
||||
}
|
||||
|
||||
nativeAppendCommonDataContext(
|
||||
return nativeAppendCommonDataContext(
|
||||
freshDataContext.domainName,
|
||||
freshDataContext.machineName,
|
||||
freshDataContext.userName,
|
||||
|
@ -83,7 +93,7 @@ public class PrivacyGuard {
|
|||
freshDataContext.outOfScopeIdentifiers.toArray());
|
||||
}
|
||||
|
||||
private static native void nativeAddIgnoredConcern(String eventName, String fieldName, int dataConcern);
|
||||
private static native void nativeAddIgnoredConcern(final String eventName, final String fieldName, final int dataConcern);
|
||||
|
||||
/**
|
||||
* Add a known concern to be ignored.
|
||||
|
@ -91,7 +101,7 @@ public class PrivacyGuard {
|
|||
* @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)
|
||||
public static void addIgnoredConcern(final String eventName, final String fieldName, final DataConcernType dataConcern)
|
||||
{
|
||||
nativeAddIgnoredConcern(eventName, fieldName, dataConcern.getValue());
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include <jni.h>
|
||||
#include "modules/privacyguard/PrivacyGuard.hpp"
|
||||
#include "JniConvertors.hpp"
|
||||
#include "LogManager.hpp"
|
||||
|
||||
using namespace MAT;
|
||||
|
||||
|
@ -8,18 +9,20 @@ extern "C"
|
|||
{
|
||||
std::shared_ptr<PrivacyGuard> spPrivacyGuard;
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_microsoft_applications_events_PrivacyGuard_nativeInitializePrivacyGuardWithoutCommonDataContext(
|
||||
JNIEnv *env, jclass /* this */, jlong iLoggerNativePtr) {
|
||||
if (spPrivacyGuard != nullptr) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto logger = reinterpret_cast<ILogger *>(iLoggerNativePtr);
|
||||
spPrivacyGuard = std::make_shared<PrivacyGuard>(logger, nullptr);
|
||||
LogManager::GetInstance()->SetDataInspector(spPrivacyGuard);
|
||||
return true;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_microsoft_applications_events_PrivacyGuard_nativeInitializePrivacyGuard(
|
||||
JNIEnv *env, jclass /* this */, jlong iLoggerNativePtr,
|
||||
jstring domainName,
|
||||
|
@ -31,7 +34,7 @@ Java_com_microsoft_applications_events_PrivacyGuard_nativeInitializePrivacyGuard
|
|||
jobjectArray machineIds,
|
||||
jobjectArray outOfScopeIdentifiers) {
|
||||
if (spPrivacyGuard != nullptr) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto logger = reinterpret_cast<ILogger *>(iLoggerNativePtr);
|
||||
|
@ -46,6 +49,22 @@ Java_com_microsoft_applications_events_PrivacyGuard_nativeInitializePrivacyGuard
|
|||
outOfScopeIdentifiers));
|
||||
|
||||
spPrivacyGuard = std::make_shared<PrivacyGuard>(logger, std::move(cdc));
|
||||
LogManager::GetInstance()->SetDataInspector(spPrivacyGuard);
|
||||
return true;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_microsoft_applications_events_PrivacyGuard_uninitializePrivacyGuard(JNIEnv *env, jclass /*this*/)
|
||||
{
|
||||
if(spPrivacyGuard == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
LogManager::GetInstance()->SetDataInspector(nullptr);
|
||||
spPrivacyGuard.reset();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
|
@ -61,7 +80,7 @@ Java_com_microsoft_applications_events_PrivacyGuard_isEnabled(JNIEnv *env, jclas
|
|||
return spPrivacyGuard != nullptr && spPrivacyGuard->IsEnabled();
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_microsoft_applications_events_PrivacyGuard_nativeAppendCommonDataContext(
|
||||
JNIEnv *env, jclass /* this */,
|
||||
jstring domainName,
|
||||
|
@ -73,7 +92,7 @@ Java_com_microsoft_applications_events_PrivacyGuard_nativeAppendCommonDataContex
|
|||
jobjectArray machineIds,
|
||||
jobjectArray outOfScopeIdentifiers) {
|
||||
if (spPrivacyGuard == nullptr) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto cdc = std::make_unique<CommonDataContexts>(GenerateCommonDataContextObject(env,
|
||||
|
@ -87,6 +106,8 @@ Java_com_microsoft_applications_events_PrivacyGuard_nativeAppendCommonDataContex
|
|||
outOfScopeIdentifiers));
|
||||
|
||||
spPrivacyGuard->AppendCommonDataContext(std::move(cdc));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
|
|
Загрузка…
Ссылка в новой задаче