From b3e9bde0d4dc42bff03389173b4bd56759c97c96 Mon Sep 17 00:00:00 2001 From: Sergey Makarov Date: Fri, 6 Oct 2023 20:19:24 +0300 Subject: [PATCH] Long timeout for applications list. Just as a precaution --- .../fingerprint/device_id_providers/MediaDrmIdProvider.kt | 3 ++- .../fingerprint/info_providers/PackageManagerInfoProvider.kt | 5 +++-- .../android/fingerprint/tools/threading/safe/Safe.kt | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/fingerprint/src/main/java/com/fingerprintjs/android/fingerprint/device_id_providers/MediaDrmIdProvider.kt b/fingerprint/src/main/java/com/fingerprintjs/android/fingerprint/device_id_providers/MediaDrmIdProvider.kt index 02244a4..103e34c 100644 --- a/fingerprint/src/main/java/com/fingerprintjs/android/fingerprint/device_id_providers/MediaDrmIdProvider.kt +++ b/fingerprint/src/main/java/com/fingerprintjs/android/fingerprint/device_id_providers/MediaDrmIdProvider.kt @@ -5,6 +5,7 @@ import android.media.MediaDrm import android.os.Build import com.fingerprintjs.android.fingerprint.BuildConfig import com.fingerprintjs.android.fingerprint.tools.DeprecationMessages +import com.fingerprintjs.android.fingerprint.tools.threading.safe.Safe import com.fingerprintjs.android.fingerprint.tools.threading.safe.safeWithTimeout import java.security.MessageDigest import java.util.UUID @@ -48,4 +49,4 @@ private const val WIDEWINE_UUID_MOST_SIG_BITS = -0x121074568629b532L private const val WIDEWINE_UUID_LEAST_SIG_BITS = -0x5c37d8232ae2de13L // on CI, the timeout of 1s is not enough for emulator with api 32 and google apis. // therefore, let's make it much higher for CI tests and a bit higher for all builds (just in case) -private val MEDIA_DRM_ID_TIMEOUT_MS = if (BuildConfig.CI_TEST) 600_000L else 3000L +private val MEDIA_DRM_ID_TIMEOUT_MS = if (BuildConfig.CI_TEST) 600_000L else Safe.timeoutLong diff --git a/fingerprint/src/main/java/com/fingerprintjs/android/fingerprint/info_providers/PackageManagerInfoProvider.kt b/fingerprint/src/main/java/com/fingerprintjs/android/fingerprint/info_providers/PackageManagerInfoProvider.kt index ebbb142..b451c55 100644 --- a/fingerprint/src/main/java/com/fingerprintjs/android/fingerprint/info_providers/PackageManagerInfoProvider.kt +++ b/fingerprint/src/main/java/com/fingerprintjs/android/fingerprint/info_providers/PackageManagerInfoProvider.kt @@ -4,6 +4,7 @@ package com.fingerprintjs.android.fingerprint.info_providers import android.annotation.SuppressLint import android.content.pm.PackageManager import com.fingerprintjs.android.fingerprint.tools.DeprecationMessages +import com.fingerprintjs.android.fingerprint.tools.threading.safe.Safe import com.fingerprintjs.android.fingerprint.tools.threading.safe.safeWithTimeout @@ -25,7 +26,7 @@ internal class PackageManagerDataSourceImpl( private val packageManager: PackageManager?, ) : PackageManagerDataSource { @SuppressLint("QueryPermissionsNeeded") - override fun getApplicationsList() = safeWithTimeout { + override fun getApplicationsList() = safeWithTimeout(timeoutMs = Safe.timeoutLong) { packageManager!! .getInstalledApplications(PackageManager.GET_META_DATA) .map { @@ -37,7 +38,7 @@ internal class PackageManagerDataSourceImpl( @SuppressLint("QueryPermissionsNeeded") - override fun getSystemApplicationsList() = safeWithTimeout { + override fun getSystemApplicationsList() = safeWithTimeout(timeoutMs = Safe.timeoutLong) { packageManager!! .getInstalledApplications(PackageManager.GET_META_DATA) .filter { diff --git a/fingerprint/src/main/java/com/fingerprintjs/android/fingerprint/tools/threading/safe/Safe.kt b/fingerprint/src/main/java/com/fingerprintjs/android/fingerprint/tools/threading/safe/Safe.kt index 36250a2..348026d 100644 --- a/fingerprint/src/main/java/com/fingerprintjs/android/fingerprint/tools/threading/safe/Safe.kt +++ b/fingerprint/src/main/java/com/fingerprintjs/android/fingerprint/tools/threading/safe/Safe.kt @@ -11,6 +11,7 @@ import java.util.concurrent.atomic.AtomicReference internal object Safe { const val timeoutShort = 1_000L + const val timeoutLong = 3_000L private val runningInsideSafeWithTimeout = ThreadLocal()