Skip to content

refactor(android SDK): convert MessageManager to Kotlin - #1002

Merged
nickolas-dimitrakas merged 1 commit into
refactor/convert-uploadhandler-to-kotlinfrom
refactor/convert-messagemanager-to-kotlin
Nov 10, 2026
Merged

nickolas-dimitrakas merged 1 commit into
refactor/convert-uploadhandler-to-kotlinfrom
refactor/convert-messagemanager-to-kotlin

Conversation

@nickolas-dimitrakas

Copy link
Copy Markdown
Contributor

Why

Risk class M.

This pull request converts row D5 of the Kotlin migration tracker from Java to Kotlin: MessageManager. It is stacked on row D4's pull request.

Programme

The Java-to-Kotlin migration of android-core, TRACKER.md row D5 (Stack D, event pipeline), converted under PLAYBOOK.md.

What changes

MessageManager becomes Kotlin in the same directory and package. Every public member keeps its JVM name and descriptor.

Decisions made by hand:

  • Thread start. The static block becomes the companion object's init block. The companion's properties keep the Java order around it, so the handler threads start at the same point of class loading.
  • Open. The class and its public members stay open.
  • Modifiers. Four @JvmStatic (getStateInfo, getTotalMemory, getSystemMemoryThreshold, destroy), ten @JvmField, one @Volatile, one @Synchronized and two @Throws(JSONException::class). No default arguments and no top-level declarations.
  • Package-private members. Members only Kotlin calls become internal. sPreferences, devicePerformanceMetricsDisabled and the nested classes' fields are internal with @JvmField, so ConfigManager still writes the flag as a static field.
  • Properties. Instance getters become properties with the same JVM names, the syntax Kotlin callers in the repository use. The four static methods stay functions, as their Kotlin callers call them by name.
  • Companion and tests. Kotlin calls getStateInfo through the companion, which Mockito.mockStatic does not reach, so MParticleDBManagerTest now runs the real getStateInfo on a mocked MPUtility.
  • setUserAttribute builds its maps with a nullable key type, so a null key still goes into the HashMap.

Nullability. Parameters are nullable and read with !! where the Java first used them. Departures from the playbook default:

  • createFirstRunMessage and getStateInfo return non-null values.
  • postToMessageThread asserts its Runnable non-null before Handler.post. Its one caller always passes one.

The log methods return BaseMPMessage?, and messageHandler and mParticleDBManager are nullable. MessageManagerTest, MessageManagerTests and MParticleDBManager read them with !!.

The API dump: MessageManager gains its Companion field and a MessageManager$Companion entry, and the four static methods become static final. scripts/check_api_dump.py reports these as reviewable internal changes and no frozen class.

Linked work

Stacked on row D4's pull request.

Rollout

This merges with no release, and it reaches apps in the next SDK release. No flag applies, because a library conversion has no runtime switch. To undo it, revert the squash commit. Risk class M: the stack's QA smoke run is needed before this merges.

Done before opening: scripts/check_api_dump.py against main reports reviewable internal changes in MessageManager, and the hand-made decisions are listed above.

Waiting for this pull request's jobs:

  • ./gradlew apiCheck test ktlintCheck lint: Unit Tests, Lint Checks and Kotlin Lint Checks.
  • Instrumented tests on an API 28 emulator, among them MessageManagerTests: the Instrumented Tests jobs.
  • Binary Compatibility, Kit Compatibility Test, build-kits, trunk check and SDK Size Impact.
  • The stack's QA smoke run.

Risks

  • The Kotlin fails to compile or a test fails on the first run, because no Android SDK was available where it was written. The fix goes on this pull request.
  • The handler threads start in a different order. The companion keeps the Java's order, and the instrumented tests start the SDK.
  • A message changes on a device. The statements keep the Java's order, and MessageManagerTest checks each message type.

Who

An AI coding agent wrote the conversion, as the next row of the tracker. The SDK team reviews it on this pull request.

Size

Hand-written: 1299 lines added, 1128 removed, in 8 files.
Cost: not yet read.
1 Kotlin file, 1257 lines, replacing 1 Java file of 1095 lines. Four test files, 29 lines added and 28 removed. The API dump gains 12 lines and loses 4.

@nickolas-dimitrakas
nickolas-dimitrakas requested a review from a team as a code owner November 9, 2026 23:25
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Kotlin migration progress

This pull request converts 1095 lines of Java to Kotlin.

Module Kotlin LOC Java LOC Java staying (facade) Java left to convert Kotlin share
android-core 8,640 17,301 9,716 7,585 33.3%
android-kit-base 601 5,405 1,651 3,754 10.0%
Total 9,241 22,706 11,367 11,339 28.9%

Conversion progress: 31.5% (11,339 of 16,550 baseline Java LOC left to convert). 96 Java files and 72 Kotlin files in scope.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Binary compatibility

  • ✅ android-core is compatible with 6.1.10 (112 classes compared, 0 with additions only).
  • ✅ android-kit-base is compatible with 6.1.10 (37 classes compared, 0 with additions only).

Compares this branch with the last version published to Maven Central, both built without R8, over the public classes and members that release keeps under their own names. It also checks that this branch's release AAR still keeps them (see the script docstring). Full japicmp HTML/XML reports are attached as the api-compat-reports workflow artifact. This check is not in the required-check set yet, so a red result here does not block merging.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

📦 SDK Size Impact Report

What the SDK adds to a minified release APK.

mParticle Core SDK

Measured against an empty baseline app. Unlike the Rokt kit, android-core ships no Compose and no resources, so there is nothing here that a host app would already provide.

Metric Target branch This PR Change
APK size 121.29 KB 121.39 KB +102 bytes
Download size 119.11 KB 119.21 KB +99 bytes
Dex bytes 217.96 KB 218.44 KB +496 bytes

mParticle Core + Rokt kit

Measured against a Compose + Material3 reference app, so these are the costs on top of an app that already ships Compose. The reference app's dependencies are a documented convention, not a measured average: see size-report-rokt/README.md.

Metric Target branch This PR Change
APK size 1.26 MB 1.26 MB 0 bytes
Download size 1.25 MB 1.25 MB -1.09 KB
Dex bytes 2.24 MB 2.24 MB +676 bytes

Rokt SDK+ umbrella (adds the payment extension)

Metric Target branch This PR Change On top of mParticle Core + Rokt kit
APK size 6.55 MB 6.55 MB 0 bytes +5.29 MB
Download size 6.43 MB 6.43 MB +369 bytes +5.19 MB
Dex bytes 7.12 MB 7.12 MB +568 bytes +4.89 MB

➡️ SDK size impact change is minimal.

Raw measurements

core, Target branch:

{"baseline_dex_bytes": 0, "baseline_download_bytes": 2514, "baseline_install_bytes": 7531, "core_dex_bytes": 223188, "core_download_bytes": 124483, "core_install_bytes": 131734}

core, This PR:

{"baseline_dex_bytes": 0, "baseline_download_bytes": 2513, "baseline_install_bytes": 7529, "core_dex_bytes": 223684, "core_download_bytes": 124581, "core_install_bytes": 131834}

rokt, Target branch:

{"baseline_dex_bytes": 1829108, "baseline_download_bytes": 1240062, "baseline_install_bytes": 1300934, "kit_dex_bytes": 4173016, "kit_download_bytes": 2549436, "kit_install_bytes": 2623275, "sdkplus_dex_bytes": 9297080, "sdkplus_download_bytes": 7987179, "sdkplus_install_bytes": 8165359}

rokt, This PR:

{"baseline_dex_bytes": 1829108, "baseline_download_bytes": 1240062, "baseline_install_bytes": 1300934, "kit_dex_bytes": 4173692, "kit_download_bytes": 2548319, "kit_install_bytes": 2623275, "sdkplus_dex_bytes": 9297648, "sdkplus_download_bytes": 7987548, "sdkplus_install_bytes": 8165359}

Measured 1d54c12 merged into 92871a2

@nickolas-dimitrakas nickolas-dimitrakas self-assigned this Nov 10, 2026
@nickolas-dimitrakas
nickolas-dimitrakas merged commit 0768242 into main Nov 10, 2026
87 of 89 checks passed
@nickolas-dimitrakas
nickolas-dimitrakas deleted the refactor/convert-messagemanager-to-kotlin branch November 10, 2026 01:40
@jamesnrokt jamesnrokt added the promoted Opened from Rokt's internal review process label Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

promoted Opened from Rokt's internal review process

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants