Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/platform interaction stability improvements #106

Merged

Conversation

Sergey-Makarov
Copy link
Contributor

@Sergey-Makarov Sergey-Makarov commented Sep 28, 2023

Behavioural changes:

  • MediaCodecInfo from CodecInfoProvider is now guaranteed to have capabilities of type List<String> instead of List<String?>
  • DevicePersonalizationInfoProvider.availableLocales() is now guaranteed to return Array<String> instead of Array<String?>
    It is achieved by converting nullable strings to "null" string. This way fingerprints are guaranteed to not be affected.

@Test
fun safeErrorRetrievable() {
val errorId = "Hello"
val v = safe { throw Exception(errorId) }

Check warning

Code scanning / detekt

Thrown exception is too generic. Prefer throwing project specific exceptions to handle error cases. Warning test

Exception is a too generic Exception. Prefer throwing specific exceptions that indicate a specific error case.
@Test
fun safeLazyEvaluatedOnceOnError() {
var count = 0
val lazy = safeLazy { ++count; throw Exception() }

Check warning

Code scanning / detekt

Thrown exception is too generic. Prefer throwing project specific exceptions to handle error cases. Warning test

Exception is a too generic Exception. Prefer throwing specific exceptions that indicate a specific error case.
TestCase.assertTrue(errCause is Exception && errCause.message == errorId)
countDownLatch.countDown()
}
) { throw Exception(errorId) }

Check warning

Code scanning / detekt

Thrown exception is too generic. Prefer throwing project specific exceptions to handle error cases. Warning test

Exception is a too generic Exception. Prefer throwing specific exceptions that indicate a specific error case.
TestCase.assertTrue(
err is ExecutionTimeoutException
&& err.executionThreadStackTrace != null
&& err.executionThreadStackTrace.any { it.className == "java.lang.Thread" && it.methodName == "sleep" }

Check warning

Code scanning / detekt

Line detected that is longer than the defined maximum line length in the code style. Warning test

Line detected that is longer than the defined maximum line length in the code style.
fun safeFromMultipleThreadsIsNotBlocked() {
val countDownLatch = CountDownLatch(2)
val elapsedTime = elapsedTimeMs {
safeAsync(timeoutMs = TimeConstants.t2) { safe { Thread.sleep(TimeConstants.t1); countDownLatch.countDown() } }

Check warning

Code scanning / detekt

Line detected that is longer than the defined maximum line length in the code style. Warning test

Line detected that is longer than the defined maximum line length in the code style.
val countDownLatch = CountDownLatch(2)
val elapsedTime = elapsedTimeMs {
safeAsync(timeoutMs = TimeConstants.t2) { safe { Thread.sleep(TimeConstants.t1); countDownLatch.countDown() } }
safeAsync(timeoutMs = TimeConstants.t2) { safe { Thread.sleep(TimeConstants.t1); countDownLatch.countDown() } }

Check warning

Code scanning / detekt

Line detected that is longer than the defined maximum line length in the code style. Warning test

Line detected that is longer than the defined maximum line length in the code style.
TestCase.assertTrue(
errImmutable is ExecutionTimeoutException
&& errImmutable.executionThreadStackTrace != null
&& errImmutable.executionThreadStackTrace.any { it.className == "java.lang.Thread" && it.methodName == "sleep" }

Check warning

Code scanning / detekt

Line detected that is longer than the defined maximum line length in the code style. Warning test

Line detected that is longer than the defined maximum line length in the code style.


/**
* A factory for [Fingerprinter] class.
*/
public object FingerprinterFactory {

private var configuration: Configuration = Configuration(version = Fingerprinter.Version.fingerprintingGroupedSignalsLastVersion.intValue)
private var configuration = Configuration(version = Fingerprinter.Version.fingerprintingGroupedSignalsLastVersion.intValue)

Check warning

Code scanning / detekt

Line detected that is longer than the defined maximum line length in the code style. Warning

Line detected that is longer than the defined maximum line length in the code style.
targetSdk = 33

minSdk = 21

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.
// As for now, I don't see any non-deprecated ways of accomplishing this task.
// Discussions:
// https://stackoverflow.com/questions/76084080/apply-targetsdk-in-android-instrumentation-test
// https://issuetracker.google.com/issues/230625468 (looks like lint.targetSdk and testOptions.targetSdk will become available soon)

Check warning

Code scanning / detekt

Line detected that is longer than the defined maximum line length in the code style. Warning

Line detected that is longer than the defined maximum line length in the code style.
}
}

compileSdk = 34

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.
@@ -8,7 +8,7 @@
}

android {
compileSdk = 33
compileSdk = 34

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.
1. moving all platform calls into try-catch block, even in factory code
2. implementing a timeout for platform code execution to avoid infinite hangs
3. adding high-level try-catch blocks for Fingerprinter methods. in case of any unexpected error, the result from DummyResults will be returned
@Sergey-Makarov Sergey-Makarov force-pushed the fix/platform-interaction-stability-improvements branch from 5551948 to 1d3d7d7 Compare September 29, 2023 11:54

internal fun Logger.ePleaseReport(throwable: Throwable?) {
e(
msg = "Unexpected error occurred. Feel free to create an issue on Github repository of the fingerprintjs-android library.",

Check warning

Code scanning / detekt

Line detected that is longer than the defined maximum line length in the code style. Warning

Line detected that is longer than the defined maximum line length in the code style.
import java.util.Locale
import java.util.TimeZone


@Deprecated(message = DeprecationMessages.UNREACHABLE_SYMBOL_UNINTENDED_PUBLIC_API)
public interface DevicePersonalizationInfoProvider {
public fun ringtoneSource(): String
public fun availableLocales(): Array<String>
public fun availableLocales(): Array<String> // // theoretically, may contain "null" strings for backwards compatibility reasons

Check warning

Code scanning / detekt

Line detected that is longer than the defined maximum line length in the code style. Warning

Line detected that is longer than the defined maximum line length in the code style.
// defaults from Executors.newCachedThreadPool()
ThreadPoolExecutor(
0, Integer.MAX_VALUE,
60L, TimeUnit.SECONDS,

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.
@Sergey-Makarov Sergey-Makarov merged commit 3285701 into main Oct 2, 2023
3 checks passed
@Sergey-Makarov Sergey-Makarov deleted the fix/platform-interaction-stability-improvements branch April 23, 2024 16:14
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.

2 participants