Skip to content
Draft
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
22 changes: 11 additions & 11 deletions android/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[versions]
agp = "8.9.3"
agp = "8.11.1"
# This is the lowest version of AGP supported by the measure gradle plugin
agp741 = "7.4.1"
bundletool = "1.17.0"
agp860 = "8.6.0"
bundletool = "1.18.1"
# android-tools is used for calculating app size and aab size by the gradle plugin.
# The version should remain compatible with lower versions of android gradle plugin. New versions
# are not backwords compatible.
android-tools = "30.4.1"
android-tools = "31.11.1"
junit-platform-launcher = "1.10.2"
kotlin = "1.9.21"
# Use the latest snapshot (local maven) version of measure-android for
Expand All @@ -20,13 +20,13 @@ androidx-junit = "1.1.5"
androidx-compose-ui = "1.4.3"
androidx-compose-material3 = "1.0.1"
androidx-runtime-android = "1.5.4"
androidx-espresso = "3.5.1"
androidx-espresso = "3.6.1"
androidx-fragment-ktx = "1.2.5"
androidx-annotation = "1.7.1"
androidx-test-rules = "1.5.0"
androidx-annotation = "1.9.1"
androidx-test-rules = "1.6.1"
androidx-lifecycle = "2.6.2"
androidx-uiautomator = "2.3.0"
androidx-benchmark-macro-junit4 = "1.3.3"
androidx-benchmark-macro-junit4 = "1.3.4"
androidx-navigation-fragment = "2.7.6"
androidx-navigation-compose = "2.6.0"
androidx-activity = "1.9.2"
Expand All @@ -45,9 +45,9 @@ squareup-curtains = "1.2.5"
squareup-okhttp = "4.12.0"
squareup-okio = "3.7.0"
squareup-leakcanary = "2.14"
robolectric = "4.14.1"
robolectric = "4.15.1"
kolinx-binary-compatibility-validator = "0.13.2"
diffplug-spotless = "6.24.0"
diffplug-spotless = "7.2.1"
compose-plugin = "1.5.11"
gradle-plugin-publish = "1.2.0"
autonomousapps-testkit = "0.12"
Expand Down Expand Up @@ -84,7 +84,7 @@ androidx-compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling
androidx-compose-runtime-android = { module = "androidx.compose.runtime:runtime-android", version.ref = "androidx-runtime-android" }
androidx-uiautomator = { module = "androidx.test.uiautomator:uiautomator", version.ref = "androidx-uiautomator" }
androidx-orchestrator = { module = "androidx.test:orchestrator", version.ref = "orchestrator" }
agp741 = { module = "com.android.tools.build:gradle", version.ref = "agp741" }
agp860 = { module = "com.android.tools.build:gradle", version.ref = "agp860" }
asm-commons = { module = "org.ow2.asm:asm-commons", version.ref = "asm-util" }
asm-util = { module = "org.ow2.asm:asm-util", version.ref = "asm-util" }
android-tools-bundletool = { module = "com.android.tools.build:bundletool", version.ref = "bundletool" }
Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Mar 17 10:37:45 IST 2025
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
6 changes: 3 additions & 3 deletions android/measure-android-gradle/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ extensions.configure<SpotlessExtension>("spotless") {
"docs/**/*.md",
"src/**/*.properties",
)
indentWithSpaces()
leadingTabsToSpaces()
trimTrailingWhitespace()
endWithNewline()
}
Expand All @@ -113,7 +113,7 @@ fun configureSpotlessKotlin(spotlessExtension: SpotlessExtension) {
}

dependencies {
compileOnly(libs.agp741)
compileOnly(libs.agp860)
compileOnly(libs.asm.util)
compileOnly(libs.asm.commons)

Expand All @@ -132,7 +132,7 @@ dependencies {
testImplementation(libs.squareup.okhttp.mockwebserver)
testImplementation(libs.asm.util)
testImplementation(libs.asm.commons)
testImplementation(libs.agp741)
testImplementation(libs.agp860)
testImplementation(libs.mockitokotlin2.mockito.kotlin)
testImplementationAar(libs.measure.android)

Expand Down
2 changes: 1 addition & 1 deletion android/measure-android-gradle/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
MEASURE_PLUGIN_GROUP_ID=sh.measure
MEASURE_PLUGIN_ARTIFACT_ID=sh.measure.android.gradle.gradle.plugin
MEASURE_PLUGIN_VERSION_NAME=0.9.0
MEASURE_PLUGIN_VERSION_NAME=0.10.0-SNAPSHOT

RELEASE_SIGNING_ENABLED = false
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,11 @@ class MeasurePluginTest {
@JvmStatic
fun versions(): Stream<Arguments> {
return Stream.of(
Arguments.of(SemVer(7, 4, 1), GradleVersion.version("7.5")),
Arguments.of(SemVer(8, 0, 2), GradleVersion.version("8.0")),
Arguments.of(SemVer(8, 3, 2), GradleVersion.version("8.5")),
Arguments.of(SemVer(8, 5, 2), GradleVersion.version("8.7")),
Arguments.of(SemVer(8, 6, 0), GradleVersion.version("8.7")),
Arguments.of(SemVer(8, 7, 3), GradleVersion.version("8.9")),
Arguments.of(SemVer(8, 8, 0), GradleVersion.version("8.10.2")),
Arguments.of(SemVer(8, 9, 0), GradleVersion.version("8.11.1")),
Arguments.of(SemVer(8, 11, 1), GradleVersion.version("8.13")),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class MeasurePlugin : Plugin<Project> {
const val DEFAULT_RETRIES = 3
}

@Suppress("UnstableApiUsage")
@Suppress("NewApi")
override fun apply(project: Project) {
if (!project.plugins.hasPlugin("com.android.application")) {
project.logger.warn(
Expand Down Expand Up @@ -131,8 +131,6 @@ class MeasurePlugin : Plugin<Project> {
}
}

private fun getFlutterExtension(project: Project): Any? = project.extensions.findByName("flutter")

private fun appSizeFileProvider(project: Project, variant: Variant): Provider<RegularFile> {
return project.layout.buildDirectory.file("intermediates/measure/${variant.name}/appSize.txt")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class NavigationMethodVisitor(
loadArg(2)

visitMethodInsn(
Opcodes.INVOKESTATIC,
INVOKESTATIC,
"sh/measure/android/navigation/ComposeNavigationCollectorKt",
"withMeasureNavigationListener",
"(Landroidx/navigation/NavHostController;Landroidx/compose/runtime/Composer;I)Landroidx/navigation/NavHostController;",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ class OkHttpMethodVisitor(
// [builder, MeasureOkHttpApplicationInterceptor]
// [builder]
override fun onMethodEnter() {
visitVarInsn(Opcodes.ALOAD, 1)
visitVarInsn(ALOAD, 1)

// create MeasureEventListenerFactory and add it to the OkHttpClient.Builder
visitTypeInsn(NEW, "sh/measure/android/okhttp/MeasureEventListenerFactory")
visitInsn(DUP)
visitVarInsn(Opcodes.ALOAD, 1)
visitVarInsn(ALOAD, 1)
visitMethodInsn(
Opcodes.INVOKEVIRTUAL,
INVOKEVIRTUAL,
"okhttp3/OkHttpClient\$Builder",
"getEventListenerFactory\$okhttp",
"()Lokhttp3/EventListener\$Factory;",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,13 +651,9 @@ class EventsTest {
}
}

private fun String.containsEvent(eventType: EventType): Boolean {
return contains("\"type\":\"${eventType.value}\"")
}
private fun String.containsEvent(eventType: EventType): Boolean = contains("\"type\":\"${eventType.value}\"")

private fun String.containsAttribute(key: String, value: String): Boolean {
return contains("\"$key\":\"$value\"")
}
private fun String.containsAttribute(key: String, value: String): Boolean = contains("\"$key\":\"$value\"")

private fun triggerExport() {
Measure.simulateAppCrash(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,11 @@ internal class FakeConfigProvider : ConfigProvider {
// no-op
}

override fun shouldTrackHttpBody(url: String, contentType: String?): Boolean {
return false
}
override fun shouldTrackHttpBody(url: String, contentType: String?): Boolean = false

override fun shouldTrackHttpUrl(url: String): Boolean {
return false
}
override fun shouldTrackHttpUrl(url: String): Boolean = false

override fun shouldTrackHttpHeader(key: String): Boolean {
return false
}
override fun shouldTrackHttpHeader(key: String): Boolean = false

override fun setMeasureUrl(url: String) {
// No-op
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import sh.measure.android.bugreport.ShakeDetector

internal class FakeShakeDetector : ShakeDetector {
private var listener: ShakeDetector.Listener? = null
override fun start(): Boolean {
return true
}
override fun start(): Boolean = true

override fun stop() {
// No-op
Expand All @@ -16,7 +14,5 @@ internal class FakeShakeDetector : ShakeDetector {
this.listener = listener
}

override fun getShakeListener(): ShakeDetector.Listener? {
return listener
}
override fun getShakeListener(): ShakeDetector.Listener? = listener
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package sh.measure.android
import sh.measure.android.utils.SystemClock
import java.util.concurrent.TimeUnit

internal class TestClock private constructor(private var currentEpochMillis: Long) :
SystemClock {
internal class TestClock private constructor(private var currentEpochMillis: Long) : SystemClock {
fun setTime(time: Long) {
this.currentEpochMillis = time
}
Expand All @@ -13,22 +12,16 @@ internal class TestClock private constructor(private var currentEpochMillis: Lon
advance(time, TimeUnit.MILLISECONDS)
}

override fun epochTime(): Long {
return currentEpochMillis
}
override fun epochTime(): Long = currentEpochMillis

override fun monotonicTimeSinceBoot(): Long {
return currentEpochMillis
}
override fun monotonicTimeSinceBoot(): Long = currentEpochMillis

private fun advance(duration: Long, unit: TimeUnit) {
currentEpochMillis += unit.toMillis(duration)
}

companion object {
// Default time set to Wed Oct 25 2023 18:20:15 GMT+0530
fun create(timeInMillis: Long = 1698238215): TestClock {
return TestClock(timeInMillis)
}
fun create(timeInMillis: Long = 1698238215): TestClock = TestClock(timeInMillis)
}
}
4 changes: 1 addition & 3 deletions android/measure/src/main/java/sh/measure/android/Handlers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import android.os.Looper
import android.os.Message
import androidx.core.os.MessageCompat

internal fun isMainThread(): Boolean {
return Looper.myLooper() == Looper.getMainLooper()
}
internal fun isMainThread(): Boolean = Looper.myLooper() == Looper.getMainLooper()

internal val mainHandler by lazy {
Handler(Looper.getMainLooper())
Expand Down
48 changes: 18 additions & 30 deletions android/measure/src/main/java/sh/measure/android/Measure.kt
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,10 @@ object Measure {
*
* @return [Span] A new span instance if the SDK is initialized, or an invalid no-op span if not initialized
*/
fun startSpan(name: String): Span {
return if (isInitialized.get()) {
measure.startSpan(name)
} else {
Span.invalid()
}
fun startSpan(name: String): Span = if (isInitialized.get()) {
measure.startSpan(name)
} else {
Span.invalid()
}

/**
Expand All @@ -259,12 +257,10 @@ object Measure {
* Note: Use this method when you need to trace an operation that has already started and you have
* captured its start time using [getCurrentTime].
*/
fun startSpan(name: String, timestamp: Long): Span {
return if (isInitialized.get()) {
measure.startSpan(name, timestamp = timestamp)
} else {
Span.invalid()
}
fun startSpan(name: String, timestamp: Long): Span = if (isInitialized.get()) {
measure.startSpan(name, timestamp = timestamp)
} else {
Span.invalid()
}

/**
Expand All @@ -278,12 +274,10 @@ object Measure {
*
* Note: Use this method when you need to create a span without immediately starting it.
*/
fun createSpanBuilder(name: String): SpanBuilder? {
return if (isInitialized.get()) {
measure.createSpan(name)
} else {
null
}
fun createSpanBuilder(name: String): SpanBuilder? = if (isInitialized.get()) {
measure.createSpan(name)
} else {
null
}

/**
Expand All @@ -301,9 +295,7 @@ object Measure {
* Note: Use this value in the `traceparent` HTTP header when making API calls to enable
* distributed tracing between your mobile app and backend services.
*/
fun getTraceParentHeaderValue(span: Span): String {
return measure.getTraceParentHeaderValue(span)
}
fun getTraceParentHeaderValue(span: Span): String = measure.getTraceParentHeaderValue(span)

/**
* Returns the W3C traceparent header key/name.
Expand All @@ -314,9 +306,7 @@ object Measure {
* @see getTraceParentHeaderValue
* @see <a href="https://www.w3.org/TR/trace-context/#header-name">W3C Trace Context specification</a>
*/
fun getTraceParentHeaderKey(): String {
return measure.getTraceParentHeaderKey()
}
fun getTraceParentHeaderKey(): String = measure.getTraceParentHeaderKey()

/**
* Returns the current time in milliseconds since epoch using a monotonic clock source.
Expand All @@ -326,12 +316,10 @@ object Measure {
* Note: Use this method to obtain timestamps when creating spans to ensure consistent time
* measurements and avoid clock drift issues within traces.
*/
fun getCurrentTime(): Long {
return if (isInitialized.get()) {
measure.timeProvider.now()
} else {
System.currentTimeMillis()
}
fun getCurrentTime(): Long = if (isInitialized.get()) {
measure.timeProvider.now()
} else {
System.currentTimeMillis()
}

/**
Expand Down
Loading
Loading