Skip to content

🔨 lazy-init deviceId/deviceName in EndpointInfoFactory#4311

Merged
guiyanakuang merged 1 commit intomainfrom
hammer/issue-4310-lazy-init-endpoint-info-factory
Apr 29, 2026
Merged

🔨 lazy-init deviceId/deviceName in EndpointInfoFactory#4311
guiyanakuang merged 1 commit intomainfrom
hammer/issue-4310-lazy-init-endpoint-info-factory

Conversation

@guiyanakuang
Copy link
Copy Markdown
Member

Closes #4310

Summary

Defer deviceUtils.getDeviceId() / getDeviceName() calls in
EndpointInfoFactory from class construction to first access by
switching the two properties to by lazy.

Why

The commonMain source set is copied into the CrossPaste mobile
project. On Android, DeviceUtils.getDeviceId() reads
Settings.Secure.ANDROID_ID, and the domestic (Chinese app store)
flavor must not read hardware identifiers before the user consents to
the privacy policy. With this change, the values are only computed
when createEndpointInfo() is actually invoked (i.e. when device
sync begins), so Phase 0 startup on mobile no longer triggers the
hardware-ID read.

Desktop impact

None observable.

  • EndpointInfoFactory is only consumed once the network server is
    ready, and createEndpointInfo() is the only reader of these fields.
  • Desktop getDeviceId() does not touch hardware identifiers.
  • LazyThreadSafetyMode.SYNCHRONIZED (the default for by lazy)
    preserves the once-only initialization guarantee.

Test plan

  • ./gradlew ktlintFormat clean
  • ./gradlew :app:compileKotlinDesktop succeeds
  • Existing desktop test suite passes in CI
  • Manual: pair a desktop device and confirm EndpointInfo
    deviceId / deviceName fields are populated as before

Defer deviceUtils.getDeviceId() / getDeviceName() calls from class
construction to first access. Required by the mobile project so the
domestic flavor can comply with Chinese app store privacy regulations
(no hardware-ID reads before the user consents to the privacy policy).

No behavioral change on desktop.

Refs #4310
@guiyanakuang guiyanakuang merged commit ea1520c into main Apr 29, 2026
5 checks passed
@guiyanakuang guiyanakuang deleted the hammer/issue-4310-lazy-init-endpoint-info-factory branch April 29, 2026 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Defer deviceId/deviceName initialization in EndpointInfoFactory

1 participant