Skip to content

Commit 8da0a72

Browse files
committed
test: add bytecode instrumentation integration test
1 parent 71f395c commit 8da0a72

File tree

19 files changed

+398
-35
lines changed

19 files changed

+398
-35
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
plugins {
2+
id("com.android.application")
3+
id("io.embrace.swazzler")
4+
id("io.embrace.android.testplugin")
5+
id("org.jetbrains.kotlin.android")
6+
}
7+
8+
repositories {
9+
google()
10+
mavenCentral()
11+
mavenLocal()
12+
}
13+
14+
def globalDisable = project.hasProperty("globalDisable") ? project.getProperty("globalDisable") == "true" : false
15+
def individualDisable = project.hasProperty("individualDisable") ? project.getProperty("individualDisable") == "true" : false
16+
def disableByVariant = project.hasProperty("disableByVariant") ? project.getProperty("disableByVariant") == "true" : false
17+
18+
embrace {
19+
autoAddEmbraceDependencies.set(true)
20+
bytecodeInstrumentation {
21+
if (globalDisable) {
22+
enabled.set(false)
23+
}
24+
if (individualDisable) {
25+
okhttpEnabled.set(false)
26+
onClickEnabled.set(false)
27+
onLongClickEnabled.set(false)
28+
webviewOnPageStartedEnabled.set(false)
29+
} else {
30+
firebasePushNotificationsEnabled.set(true)
31+
}
32+
}
33+
34+
if (disableByVariant) {
35+
buildVariantFilter {
36+
if (it.name.contains("release")) {
37+
it.disableBytecodeInstrumentationForVariant()
38+
}
39+
}
40+
}
41+
}
42+
43+
android {
44+
kotlinOptions {
45+
jvmTarget = "1.8"
46+
}
47+
}
48+
49+
dependencies {
50+
implementation("com.squareup.okhttp3:okhttp:4.12.0")
51+
implementation("com.google.firebase:firebase-messaging:23.1.0")
52+
implementation("io.embrace:embrace-android-fcm:+")
53+
}
54+
55+
android {
56+
namespace = "com.example"
57+
compileSdk = 35
58+
59+
defaultConfig {
60+
applicationId = "com.example.app"
61+
minSdk = 24
62+
versionCode = 1
63+
versionName = "1.0"
64+
}
65+
buildTypes {
66+
release {
67+
minifyEnabled = true
68+
proguardFiles(
69+
getDefaultProguardFile("proguard-android.txt"),
70+
"proguard-rules.pro"
71+
)
72+
}
73+
}
74+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-keep class com.example.app.** { *; }
2+
-keep class okhttp3.** { *; }
3+
-keep class io.embrace.android.embracesdk.internal.config.instrumented.** { *; }
4+
-keep class io.embrace.android.embracesdk.ViewSwazzledHooks$OnClickListener { *; }
5+
-keep class io.embrace.android.embracesdk.ViewSwazzledHooks$OnLongClickListener { *; }
6+
-keep class com.google.firebase.messaging.RemoteMessage
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.example.app
2+
3+
import com.google.firebase.messaging.FirebaseMessagingService
4+
import com.google.firebase.messaging.RemoteMessage
5+
6+
class FcmServiceFixture : FirebaseMessagingService() {
7+
8+
override fun onMessageReceived(message: RemoteMessage) {
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.example.app
2+
3+
val okHttp = okhttp3.OkHttpClient.Builder().build()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.example.app
2+
3+
import android.view.View
4+
5+
/**
6+
* A custom object which implements OnClickListener.
7+
*/
8+
class OnClickListenerFixture : View.OnClickListener {
9+
override fun onClick(view: View) {
10+
if (view.isActivated) {
11+
return
12+
}
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.example.app
2+
3+
import android.view.View
4+
5+
/**
6+
* A custom object which implements OnLongClickListener.
7+
*/
8+
class OnLongClickListenerFixture : View.OnLongClickListener {
9+
10+
override fun onLongClick(view: View?): Boolean {
11+
return view?.isActivated ?: false
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.example.app
2+
3+
import android.graphics.Bitmap
4+
import android.webkit.WebView
5+
import android.webkit.WebViewClient
6+
7+
class WebViewClientFixture : WebViewClient() {
8+
9+
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
10+
super.onPageStarted(view, url, favicon)
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package io.embrace.android.gradle.integration.framework.smali
2+
3+
import com.squareup.moshi.Moshi
4+
import io.embrace.android.embracesdk.ResourceReader
5+
import io.embrace.android.gradle.integration.framework.ApkDisassembler
6+
import io.embrace.android.gradle.integration.framework.findArtifact
7+
import okio.buffer
8+
import okio.source
9+
import java.io.File
10+
11+
class SmaliConfigReader {
12+
13+
fun readSmaliFiles(projectDir: File, classNames: List<String>): List<File> {
14+
val apk = findArtifact(projectDir, "build/outputs/apk/release/", ".apk")
15+
val decodedApk = ApkDisassembler().disassembleApk(apk)
16+
val smaliFiles = decodedApk.getSmaliFiles(classNames)
17+
return smaliFiles
18+
}
19+
20+
fun readExpectedConfig(resName: String): ExpectedSmaliConfig {
21+
val adapter = Moshi.Builder().build().adapter(ExpectedSmaliConfig::class.java)
22+
return ResourceReader.readResource(resName).source().buffer().use {
23+
checkNotNull(adapter.fromJson(it))
24+
}
25+
}
26+
}

embrace-gradle-plugin-integration-tests/src/test/java/io/embrace/android/gradle/integration/framework/smali/SmaliMethod.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ import com.squareup.moshi.JsonClass
99
data class SmaliMethod(
1010
val signature: String,
1111
val returnValue: String? = null,
12+
val embraceHook: String? = null,
1213
)

0 commit comments

Comments
 (0)