fingerprintjs / fingerprintjs-android

Swiss army knife for identifying and fingerprinting Android devices. MIT license, no restrictions on usage in production.
https://fingerprint.com/github/
MIT License
572 stars 83 forks source link

Fingerpint result is not being cached contrary to what doc says #68

Closed Sergey-Makarov closed 1 year ago

Sergey-Makarov commented 2 years ago

Just some self-explanatory code:

    fun okCase(fingerprinter: Fingerprinter) {
        fingerprinter.getDeviceId(
            listener = { deviceId1 ->
                fingerprinter.getDeviceId(
                    listener = { deviceId2 ->
                        // The following check returns true which is ok because the result
                        // is cached internally.

                        // Still have concerns whether we really need this though.
                        deviceId1 === deviceId2
                    }
                )
            }
        )
    }

    fun bugCase(fingerprinter: Fingerprinter) {
        fingerprinter.getFingerprint(
            stabilityLevel = StabilityLevel.OPTIMAL,
            listener = { fingerprintResult1 ->
                fingerprinter.getFingerprint(
                    stabilityLevel = StabilityLevel.OPTIMAL,
                    listener = { fingerprintResult2 ->
                        // Returns false which is not expected.
                        fingerprintResult1 === fingerprintResult2
                    }
                )
            }
        )
    }
Sergey-Makarov commented 2 years ago

Probably we should stop caching anything at all and remove the statement about it from our doc.

Sergey-Makarov commented 1 year ago

This behaviour has been slightly changed in the newer API methods introduced with v2.0.0 (note: this does not apply to methods that are marked as deprecated). From now on, the signals are always cached internally, be it device id or fingerprint signals. The results returned from the newer methods will be equal structurally, but not referentially (see Equality page for explanation).