Skip to content

Commit

Permalink
Merge pull request #8 from fingerprintjs/develop
Browse files Browse the repository at this point in the history
Release v1.0.0
  • Loading branch information
Alexey-Verkhovsky authored Sep 20, 2021
2 parents 590107c + 672a0c4 commit f822492
Show file tree
Hide file tree
Showing 17 changed files with 276 additions and 89 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/blank.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Test

on:
push:
branches: [ main, develop ]
pull_request:
paths-ignore:
- '**.md'
- app/**

env:
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
RELEASE_SIGN_KEY_ALIAS: ${{ secrets.RELEASE_SIGN_KEY_ALIAS }}
RELEASE_SIGN_KEY_PASSWORD: ${{ secrets.RELEASE_SIGN_KEY_PASSWORD }}

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Make gradlew executable
run: chmod +x ./gradlew

- name: Lint
run: ./gradlew fpjs-pro:lint

- name: Build library
run: ./gradlew fpjs-pro:assembleRelease

- name: Save library to artifacts
uses: actions/upload-artifact@v2
with:
path: fpjs-pro/build/outputs/aar/*

- name: Build App
run: ./gradlew app:assembleRelease

- name: Save application to artifacts
uses: actions/upload-artifact@v2
with:
path: app/build/outputs/apk/release/*
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,12 @@ allprojects {
}}
```

### 2. Download the *.aar lib from the latest [release](https://github.com/fingerprintjs/fingerprintjs-pro-android-integrations/releases) to the `libs` folder of your application module.


### 3. Add a dependency to your `build.gradle` file of the module
### 2. Add a dependency to your `build.gradle` file

```gradle
dependencies {
implementation "com.github.fingerprintjs:fingerprint-android:1.2"
implementation files("libs/fpjs-pro-release.aar")
implementation 'com.github.fingerprintjs:fingerprintjs-pro-android-integrations:v1.0.0-rc5'
// If you use Java for you project, add also this line
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"}
Expand All @@ -59,11 +56,12 @@ buildscript {
```
*Note: You can find your Kotlin version in Android Studio > File > Settings > Languages & Frameworks > Kotlin.*

### 4. Get the visitor identifier
### 3. Get the visitor identifier

Retrieve the visitor identifier using browser token. You can find your [browser token](https://dev.fingerprintjs.com/docs) in your [dashboard](https://dashboard.fingerprintjs.com/subscriptions/).

#### 4.1 Kotlin example

#### 3.1 Kotlin example

```kotlin
// Initialization
Expand All @@ -84,7 +82,8 @@ fpjsClient.getVisitorId { visitorId ->
}
```

#### 4.2 Java example

#### 3.2 Java example

```java

Expand Down
29 changes: 18 additions & 11 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,46 @@ plugins {
}

android {
compileSdk 30
compileSdk 31
buildToolsVersion "30.0.3"

defaultConfig {
applicationId "com.fingerprintjs.android.fpjs_pro_demo"
minSdk 21
targetSdk 30
versionCode 1
versionName "1.0"
targetSdk 31
versionCode Integer.parseInt(project.VERSION_CODE)
versionName project.VERSION_NAME

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

signingConfigs {
release {
storeFile file("release.jks")
storePassword System.getenv('KEYSTORE_PASSWORD')
keyAlias System.getenv('RELEASE_SIGN_KEY_ALIAS')
keyPassword System.getenv('RELEASE_SIGN_KEY_PASSWORD')
}
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'

applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "FPJS-Pro-Playground-${variant.name}-${variant.versionName}.apk"
}
}
}

dependencies {
implementation project(":fpjs-pro")
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation "com.github.fingerprintjs:fingerprint-android:1.2"
implementation 'com.google.android.material:material:1.4.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
Expand Down
Binary file added app/release.jks
Binary file not shown.
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.4.30'
ext.kotlin_version = '1.5.10'
repositories {
google()
mavenCentral()
Expand All @@ -11,7 +11,6 @@ buildscript {
}
}


task clean(type: Delete) {
delete rootProject.buildDir
}
35 changes: 23 additions & 12 deletions fpjs-pro/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,26 @@ plugins {
id 'maven-publish'
}

group='com.github.fingerprintjs'
publishing {
publications {
mavenJava(MavenPublication) {
groupId = 'com.github.fingerprintjs'
artifactId = "fpjs-pro"
version = '1.0.0'
artifact("$buildDir/outputs/aar/fpjs-pro-1.0.0-release.aar")
}
}
}

android {
compileSdkVersion 30
compileSdkVersion 31
buildToolsVersion "30.0.3"

defaultConfig {
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
targetSdkVersion 31
versionCode Integer.parseInt(project.VERSION_CODE)
versionName project.VERSION_NAME
}

buildTypes {
Expand All @@ -23,17 +32,19 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'

libraryVariants.all { variant ->
variant.outputs.all { output ->
if (outputFile != null && outputFileName.endsWith('.aar')) {
outputFileName = "fpjs-pro-${defaultConfig.versionName}-${variant.name}.aar"
}
}
}

}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation "com.github.fingerprintjs:fingerprint-android:1.2"
}
2 changes: 1 addition & 1 deletion fpjs-pro/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fingerprintjs.android.fpjs_pro">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
</manifest>
11 changes: 5 additions & 6 deletions fpjs-pro/src/main/assets/index.html

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ package com.fingerprintjs.android.fpjs_pro


import android.content.Context
import com.fingerprintjs.android.fingerprint.FingerprinterFactory
import com.fingerprintjs.android.fpjs_pro.device_id_providers.AndroidIdProvider
import com.fingerprintjs.android.fpjs_pro.device_id_providers.GsfIdProvider
import com.fingerprintjs.android.fpjs_pro.device_id_providers.MediaDrmIdProvider


interface FPJSProClient {
fun getVisitorId(listener: (String) -> Unit)
}

class Configuration(
class Configuration @JvmOverloads constructor(
val apiToken: String,
val region: Region = Region.US,
val endpointUrl: String = region.endpointUrl
Expand All @@ -34,11 +36,16 @@ class FPJSProFactory(
}

fun createInterface(configuration: Configuration = Configuration("")): FPJSProInterface {
val fingerprinter = FingerprinterFactory.getInstance(
applicationContext,
com.fingerprintjs.android.fingerprint.Configuration(3)
val contentResolver = applicationContext.contentResolver!!
val androidIdProvider = AndroidIdProvider(contentResolver)
val gsfIdProvider = GsfIdProvider(contentResolver)
val mediaDrmIdProvider = MediaDrmIdProvider()
return FPJSProInterface(
configuration.apiToken,
configuration.endpointUrl,
androidIdProvider,
gsfIdProvider,
mediaDrmIdProvider
)

return FPJSProInterface(fingerprinter, configuration.apiToken, configuration.endpointUrl)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import android.webkit.ConsoleMessage
import android.webkit.JsResult
import android.webkit.WebChromeClient
import android.webkit.WebView
import com.fingerprintjs.android.fingerprint.Configuration
import com.fingerprintjs.android.fingerprint.FingerprinterFactory
import com.fingerprintjs.android.fingerprint.tools.executeSafe
import com.fingerprintjs.android.fpjs_pro.device_id_providers.AndroidIdProvider
import com.fingerprintjs.android.fpjs_pro.device_id_providers.GsfIdProvider
import com.fingerprintjs.android.fpjs_pro.device_id_providers.MediaDrmIdProvider
import com.fingerprintjs.android.fpjs_pro.tools.executeSafe
import java.lang.ref.WeakReference
import java.util.concurrent.Executors

Expand All @@ -36,8 +37,10 @@ class FPJSProClientImpl(
}

private fun init(listener: (String) -> (Unit)) {
val fingerprinter =
FingerprinterFactory.getInstance(applicationContext, Configuration(3))
val contentResolver = applicationContext.contentResolver!!
val androidIdProvider = AndroidIdProvider(contentResolver)
val gsfIdProvider = GsfIdProvider(contentResolver)
val mediaDrmIdProvider = MediaDrmIdProvider()

webViewWeakRef.get()?.webChromeClient = object : WebChromeClient() {

Expand Down Expand Up @@ -66,7 +69,12 @@ class FPJSProClientImpl(
webViewWeakRef.get()?.settings?.defaultTextEncodingName = "utf-8"
webViewWeakRef.get()
?.addJavascriptInterface(
FPJSProInterface(fingerprinter, apiToken, endpointUrl),
FPJSProInterface(
apiToken, endpointUrl,
androidIdProvider,
gsfIdProvider,
mediaDrmIdProvider
),
JS_INTERFACE_NAME
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,33 @@ package com.fingerprintjs.android.fpjs_pro


import android.webkit.JavascriptInterface
import com.fingerprintjs.android.fingerprint.Fingerprinter
import java.util.concurrent.CountDownLatch
import com.fingerprintjs.android.fpjs_pro.device_id_providers.AndroidIdProvider
import com.fingerprintjs.android.fpjs_pro.device_id_providers.GsfIdProvider
import com.fingerprintjs.android.fpjs_pro.device_id_providers.MediaDrmIdProvider
import com.fingerprintjs.android.fpjs_pro.tools.executeSafe


class FPJSProInterface internal constructor(
private val fingerprinter: Fingerprinter,
private val apiToken: String,
private val endpointUrl: String,
private val androidIdProvider: AndroidIdProvider,
private val gsfIdProvider: GsfIdProvider,
private val mediaDrmIdProvider: MediaDrmIdProvider
) {
@JavascriptInterface
fun getDeviceId(): String {
val countDownLatch = CountDownLatch(1)
var result = ""
fingerprinter.getDeviceId {
result = it.deviceId
countDownLatch.countDown()
}
countDownLatch.await()
return result
}
fun getDeviceId(): String = nativeDeviceId()

@JavascriptInterface
fun getEndpoint(): String = endpointUrl

@JavascriptInterface
fun getApiToken(): String = apiToken

private fun nativeDeviceId(): String {
val mediaDrmId = mediaDrmIdProvider.getMediaDrmId()
val gsfId = gsfIdProvider.getGsfAndroidId()
val androidId = androidIdProvider.getAndroidId()

return gsfId ?: mediaDrmId ?: androidId
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.fingerprintjs.android.fpjs_pro.device_id_providers


import android.annotation.SuppressLint
import android.content.ContentResolver
import android.provider.Settings
import com.fingerprintjs.android.fpjs_pro.tools.executeSafe


class AndroidIdProvider(
private val contentResolver: ContentResolver
) {
@SuppressLint("HardwareIds")
fun getAndroidId(): String {
return executeSafe({
Settings.Secure.getString(
contentResolver,
Settings.Secure.ANDROID_ID
)
}, "")
}
}
Loading

0 comments on commit f822492

Please sign in to comment.