Skip to content

Commit

Permalink
Merge pull request #121 from fingerprintjs/fix/remove-resource-leaks
Browse files Browse the repository at this point in the history
Fix/remove resource leaks
  • Loading branch information
Sergey-Makarov authored Dec 9, 2024
2 parents 48c8100 + 76e3c21 commit 736c42f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 25 deletions.
19 changes: 18 additions & 1 deletion app/src/main/java/com/fingerprintjs/android/playground/App.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.fingerprintjs.android.playground

import android.app.Application
import android.os.StrictMode
import com.fingerprintjs.android.playground.di.AppComponent
import com.fingerprintjs.android.playground.di.DaggerAppComponent

Expand All @@ -10,10 +11,26 @@ class App : Application() {
private set

override fun onCreate() {
setupStrictMode()
super.onCreate()
appComponent = DaggerAppComponent
.builder()
.app(this)
.build()
}
}

private fun setupStrictMode() {
if (BuildConfig.DEBUG) {
StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.Builder()
.detectAll()
.penaltyLog()
.penaltyDeath()
.build())
StrictMode.setVmPolicy(StrictMode.VmPolicy.Builder()
.detectAll()
.penaltyLog()
.penaltyDeath()
.build())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,11 @@ public class GsfIdProvider(
val URI = Uri.parse(URI_GSF_CONTENT_PROVIDER)
val params = arrayOf(ID_KEY)
return try {
val cursor = contentResolver!!
.query(URI, null, null, params, null)

if (cursor == null) {
return null
}

if (!cursor.moveToFirst() || cursor.columnCount < 2) {
cursor.close()
return null
}
try {
val result: String? = java.lang.Long.toHexString(cursor.getString(1).toLong())
cursor.close()
result
} catch (e: NumberFormatException) {
cursor.close()
null
contentResolver!!.query(URI, null, null, params, null)!!.use { cursor ->
check(cursor.moveToFirst() && cursor.columnCount >= 2)
java.lang.Long.toHexString(cursor.getString(1).toLong())
}
} catch (e: Exception) {
} catch (_: Exception) {
null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ internal class CpuInfoProviderImpl :

private fun getCpuInfo(): Map<String, String> {
val map: MutableMap<String, String> = HashMap()
val s = Scanner(File(CPU_INFO_PATH))
while (s.hasNextLine()) {
val cpuInfoValues = s.nextLine()!!.split(KEY_VALUE_DELIMITER)
if (cpuInfoValues.size > 1) map[cpuInfoValues[0].trim { it <= ' ' }] =
cpuInfoValues[1].trim { it <= ' ' }
Scanner(File(CPU_INFO_PATH)).use { s ->
while (s.hasNextLine()) {
val cpuInfoValues = s.nextLine()!!.split(KEY_VALUE_DELIMITER)
if (cpuInfoValues.size > 1) map[cpuInfoValues[0].trim { it <= ' ' }] =
cpuInfoValues[1].trim { it <= ' ' }
}
}

return map
Expand Down

0 comments on commit 736c42f

Please sign in to comment.