Skip to content
Open
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
1 change: 1 addition & 0 deletions OpacityCore/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ dependencies {
implementation libs.geckoview
implementation libs.androidx.security.crypto
implementation libs.kotlinx.serialization.json
implementation libs.rustls.platform.verifier
testImplementation libs.junit
androidTestImplementation libs.androidx.junit
androidTestImplementation libs.androidx.espresso.core
Expand Down
3 changes: 2 additions & 1 deletion OpacityCore/consumer-rules.pro
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
-keep class com.opacitylabs.opacitycore.** { *; }
-keepclassmembers class com.opacitylabs.opacitycore.** { *; }
-keepclassmembers class com.opacitylabs.opacitycore.** { *; }
-keep, includedescriptorclasses class org.rustls.platformverifier.** { *; }
5 changes: 4 additions & 1 deletion OpacityCore/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,7 @@

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
#-renamesourcefileattribute SourceFile

# Keeps rustls-platform-verifier deps from being stripped
-keep, includedescriptorclasses class org.rustls.platformverifier.** { *; }
14 changes: 10 additions & 4 deletions OpacityCore/src/main/cpp/OpacityCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,14 +383,20 @@ android_get_browser_cookies_for_domain(const char *domain) {

extern "C" JNIEXPORT jint JNICALL
Java_com_opacitylabs_opacitycore_OpacityCore_init(
JNIEnv *env, jobject thiz, jstring api_key, jboolean dry_run,
jint environment_enum, jboolean show_errors_in_webview) {
JNIEnv *env, jobject thiz, jobject context, jstring api_key,
jboolean dry_run, jint environment_enum,
jboolean show_errors_in_webview) {
java_object = env->NewGlobalRef(thiz);
char *err;
const char *api_key_str = env->GetStringUTFChars(api_key, nullptr);
int android_init_result =
opacity_core::android_init((void *)env, (void *)context);
__android_log_print(ANDROID_LOG_DEBUG, "OpacityCore",
"android_init_result: %d", android_init_result);

int result = opacity_core::opacity_init(api_key_str, dry_run,
static_cast<int>(environment_enum),
show_errors_in_webview, &err);
static_cast<int>(environment_enum),
show_errors_in_webview, &err);
if (result != opacity_core::OPACITY_OK) {
jclass exceptionClass = env->FindClass("java/lang/Exception");
env->ThrowNew(exceptionClass, err);
Expand Down
2 changes: 2 additions & 0 deletions OpacityCore/src/main/jni/include/sdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ extern const int32_t OPACITY_ENVIRONMENT_STAGING;

extern const int32_t OPACITY_ENVIRONMENT_PRODUCTION;

int32_t android_init(void *raw_env, void *raw_context);

int32_t opacity_init(const char *api_key_str,
bool dry_run,
int32_t backend_environment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ object OpacityCore {
environment: Environment,
showErrorsInWebView: Boolean
): Int {
return init(apiKey, dryRun, environment.code, showErrorsInWebView)
return init(appContext, apiKey, dryRun, environment.code, showErrorsInWebView)
}

@JvmStatic
Expand Down Expand Up @@ -287,6 +287,7 @@ object OpacityCore {
}

private external fun init(
context: Context,
apiKey: String,
dryRun: Boolean,
environment: Int,
Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ kotlinx-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-
androidx-espresso-intents = { group = "androidx.test.espresso", name = "espresso-intents", version.ref = "espressoIntents" }
compose-compiler = { module = "androidx.compose.compiler:compiler", version.ref = "compose-compiler" }
work-runtime-ktx = { group = "androidx.work", name = "work-runtime-ktx", version.ref = "workRuntimeKtx" }
rustls-platform-verifier = { group = "rustls", name = "rustls-platform-verifier", version = "latest.release" }

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
Expand Down
22 changes: 22 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,31 @@ dependencyResolutionManagement {
mavenCentral()
maven("https://maven.mozilla.org/maven2/")
maven("https://jitpack.io")
maven {
url = uri(findRustlsPlatformVerifierMaven())
metadataSources.artifact()
}
}
}

@Suppress("UNCHECKED_CAST")
fun findRustlsPlatformVerifierMaven(): String {
val result = providers.exec {
workingDir = File(rootDir, "../")
commandLine(
"cargo", "metadata", "--format-version", "1",
"--filter-platform", "aarch64-linux-android",
"--manifest-path", "sdk/Cargo.toml"
)
}.standardOutput.asText.get()

val json = groovy.json.JsonSlurper().parseText(result) as Map<String, Any>
val packages = json["packages"] as List<Map<String, Any>>
val pkg = packages.first { it["name"] == "rustls-platform-verifier-android" }
val manifestPath = File(pkg["manifest_path"] as String)
return File(manifestPath.parentFile, "maven").path
}


rootProject.name = "OpacityAndroid"
include(":app")
Expand Down