Skip to content

Defer deviceId/deviceName initialization in EndpointInfoFactory #4310

@guiyanakuang

Description

@guiyanakuang

Background

EndpointInfoFactory currently calls deviceUtils.getDeviceId() and
deviceUtils.getDeviceName() directly from its property initializers, so
the calls run as soon as Koin instantiates the factory.

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 accepts the privacy policy.

Proposal

Convert deviceName and deviceId in EndpointInfoFactory to by lazy
so the values are computed on first access inside createEndpointInfo()
instead of at construction time.

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 that property
    initializers gave us.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions