Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setTicketToken exposed to jni and java layer for Android apps to set tokens like AAD #1131

Merged
merged 5 commits into from
May 3, 2023
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 @@ -23,6 +23,8 @@ public interface ILogManager extends AutoCloseable {

public Status resumeTransmission();

public Status setTicketToken(TicketType type, final String tokenValue);

public Status setTransmitProfile(TransmitProfile profile);

public Status setTransmitProfile(String profile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,21 @@ public static Status resumeTransmission() {
return Status.getEnum(nativeResumeTransmission());
}

private static native int nativeSetIntTicketToken(int type, final String tokenValue);

/**
* Sets the token ID with the value.
*
* @param type Type of token(like AAD etc)
* @param tokenValue Value of the token
* @return Status enum corresponding to the native API execution status_t.
*/
public static Status setTicketToken(TicketType type, final String tokenValue) {
if (type == null) throw new IllegalArgumentException("type is null");

return Status.getEnum(nativeSetIntTicketToken(type.getValue(), tokenValue));
}

private static native int nativeSetIntTransmitProfile(int profile);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ public Status resumeTransmission() {
return Status.getEnum(nativeResumeTransmission(nativeLogManager));
}

protected native int nativeSetIntTicketToken(long nativeLogManager, int type, final String tokenValue);

@Override
public Status setTicketToken(TicketType type, final String tokenValue) {
return Status.getEnum(nativeSetIntTicketToken(nativeLogManager, type.getValue(), tokenValue));
}

protected native int nativeSetTransmitProfileTP(long nativeLogManager, int profile);

@Override
Expand Down
10 changes: 10 additions & 0 deletions lib/include/public/LogManagerBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,16 @@ namespace MAT_NS_BEGIN
static IAuthTokensController* GetAuthTokensController()
LM_SAFE_CALL_PTR(GetAuthTokensController);

/// <summary>
///Sets the ticket token with a value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put the comment into <summary></summary> node.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

/// </summary>
static status_t SetTicketToken(TicketType type, const std::string& tokenValue)
{
if (isHost())
LM_SAFE_CALL(GetAuthTokensController()->SetTicketToken, type, tokenValue.c_str());
return STATUS_EPERM; // Permission denied
}

/// <summary>
/// Obtain event filter collection.
/// Notes:
Expand Down
12 changes: 12 additions & 0 deletions lib/jni/LogManager_jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@ extern "C"
return static_cast<jint>(WrapperLogManager::ResumeTransmission());
}

JNIEXPORT jint JNICALL
Java_com_microsoft_applications_events_LogManager_nativeSetIntTicketToken(
JNIEnv* env,
jclass /* this */,
jint jType,
jstring jstrTokenValue)
{
auto ticketValue = JStringToStdString(env, jstrTokenValue);
return static_cast<jint>(WrapperLogManager::SetTicketToken(
static_cast<TicketType>(jType), ticketValue));
}

JNIEXPORT jint JNICALL
Java_com_microsoft_applications_events_LogManager_nativeSetIntTransmitProfile(
JNIEnv* /* env */,
Expand Down