Skip to content

Commit

Permalink
Merge pull request #3 from kantarsifo/release_4.0.1_rc
Browse files Browse the repository at this point in the history
Release 4.0.1
  • Loading branch information
dynamo-developer committed Sep 30, 2020
2 parents ecebeac + bcf1b42 commit 120764c
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 29 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@ Strings sent to the server will be encoded using UTF-8. If the String given to t


# FAQ

- **Why do I need to initialise the library by passing ComponentActivity and not just Context as before?**
To properly track information regarding Sifo panelist users the library needs to read information from the Sifo Internet app if it is also installed on the device.
In the past it was possible to read the needed information directly from the Sifo Internet app, however since the recent security updates on Android this is no longer possible.
The new solution is to request the information from the Sifo internet, app given it is installed on the same device.
This means on initialisation the app will send an intent request to the Sifo Internet app and wait for the result and this is why just passing the context is no longer enough.
- **How do I test and verify that the framework is correct integrated?**
See [Test Application](#test-application) and [Validation test with Kantar Sifo​](#validation-test-with-kantar-sifo) below.
- **Native app - how do I integrate the framework?**
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

version = "3.0.4"
version = "4.0.1"

android {
compileSdkVersion 29
Expand Down
2 changes: 1 addition & 1 deletion libmobiletagging/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apply plugin: 'com.github.dcendents.android-maven'

group='myGroups'

version = "4.0.0"
version = "4.0.1"


android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal object CookieHandler {
}

@Throws(JSONException::class)
fun getCookieFromJson(json: JSONObject, isPanelistOnly: Boolean, isWebBased: Boolean, version: String): HttpCookie {
fun getCookieFromJson(json: JSONObject): HttpCookie {
return createHttpCookie(
name = json.getString("key"),
value = json.getString("value"),
Expand Down Expand Up @@ -57,7 +57,7 @@ internal object CookieHandler {
return String.format("%s=%s", cookie.name, cookie.value)
}

private fun createHttpCookie(name: String,
fun createHttpCookie(name: String,
value: String?,
path: String = "/",
domain: String = TagStringsAndValues.DOMAIN_CODIGO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.content.Intent
import android.content.SharedPreferences
import android.content.pm.PackageManager
import android.net.Uri
import android.util.Log
import androidx.activity.ComponentActivity
import org.json.JSONArray
import org.json.JSONException
Expand Down Expand Up @@ -54,7 +53,6 @@ internal object PanelistHandler {
}
onComplete()
}
//han.launchIntent(intent)
}else{
onComplete()
}
Expand All @@ -66,16 +64,13 @@ internal object PanelistHandler {

fun getCookies(context: Context, activity: ComponentActivity): List<HttpCookie>? {
val sharedPref = activity.getSharedPreferences(TagStringsAndValues.SIFO_PREFERENCE_KEY, Context.MODE_PRIVATE)
val panelistOnly = sharedPref.getBoolean(TagStringsAndValues.SIFO_COOKIES_IS_PANELIST_ONLY, false)
val isWebBased = sharedPref.getBoolean(TagStringsAndValues.SIFO_COOKIES_IS_WEB_BASED, false)
val version = BuildConfig.VERSION_NAME
if (sharedPref.contains(TagStringsAndValues.SIFO_PREFERENCE_COOKIES)) {
return readCookiesFromJson(sharedPref.getString(TagStringsAndValues.SIFO_PREFERENCE_COOKIES, "") ?: "", panelistOnly, isWebBased, version)
return readCookiesFromJson(sharedPref.getString(TagStringsAndValues.SIFO_PREFERENCE_COOKIES, "") ?: "")
} else { // Fallback to old version of reading cookies from sifo panel app shared preference
val inputStream = getSifoInputStream(context,
TagStringsAndValues.SIFO_PANELIST_PACKAGE_NAME_V2,
TagStringsAndValues.SIFO_PANELIST_CREDENTIALS_FILENAME_V2)
return inputStream?.let { readCookieStore(it, panelistOnly, isWebBased, version) }
return inputStream?.let { readCookieStore(it) }
}
}

Expand Down Expand Up @@ -109,28 +104,28 @@ internal object PanelistHandler {
}
}

private fun readCookiesFromJson(content: String, panelistOnly: Boolean, isWebBased: Boolean, version: String): List<HttpCookie> {
private fun readCookiesFromJson(content: String): List<HttpCookie> {
val cookieList = mutableListOf<HttpCookie>()
try {
val jsonArray = JSONArray(content)
for (i in 0 until jsonArray.length()) {
val entry = jsonArray.getJSONObject(i)
cookieList.add(CookieHandler.getCookieFromJson(entry, panelistOnly, isWebBased, version))
cookieList.add(CookieHandler.getCookieFromJson(entry))
}
} catch (e: JSONException) {
TSMobileAnalyticsBackend.logError("Error parsing TNS Panelist JSON data")
}
return cookieList
}

private fun readCookieStore(stream: FileInputStream, panelistOnly: Boolean, isWebBased: Boolean, version: String): List<HttpCookie> {
private fun readCookieStore(stream: FileInputStream): List<HttpCookie> {
val content = readFile(stream, "Error reading TNS Panelist cookies")
val cookieList = mutableListOf<HttpCookie>()
try {
val jsonArray = JSONArray(content)
for (i in 0 until jsonArray.length()) {
val entry = jsonArray.getJSONObject(i)
cookieList.add(CookieHandler.getCookieFromJson(entry, panelistOnly, isWebBased, version))
cookieList.add(CookieHandler.getCookieFromJson(entry))
}
} catch (e: JSONException) {
TSMobileAnalyticsBackend.logError("Error parsing TNS Panelist JSON data")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ internal class TSMobileAnalyticsBackend : TSMobileAnalytics {
logFatalError("Mobile Application Tagging Framework Failed to initiate - context must not be null")
return frameworkInstance
}
val sharedPref = activity.getSharedPreferences(TagStringsAndValues.SIFO_PREFERENCE_KEY, Context.MODE_PRIVATE)
sharedPref.edit().putBoolean(TagStringsAndValues.SIFO_COOKIES_IS_PANELIST_ONLY, onlyPanelist).commit()
sharedPref.edit().putBoolean(TagStringsAndValues.SIFO_COOKIES_IS_WEB_BASED, isWebBased).commit()
val version = BuildConfig.VERSION_NAME
val cookieValue = "trackPanelistOnly=$onlyPanelist&isWebViewBased=$isWebBased&sdkVersion=$version"
val metaCookie = CookieHandler.createHttpCookie(TagStringsAndValues.SIFO_META_COOKIE_NAME, cookieValue)
CookieHandler.setupPanelistCookies(listOf(metaCookie))

if (frameworkInstance == null) {
if (paramsAreValid(cpID, applicationName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,6 @@ object TagStringsAndValues {
*/
internal const val SIFO_PREFERENCE_COOKIES = "SIFO_PREFERENCE_COOKIES"

/**
* Key for isPanelistOnly cookie tracking
*/
internal const val SIFO_COOKIES_IS_PANELIST_ONLY = "SIFO_COOKIES_IS_PANELIST_ONLY"

/**
* Key for isWebBased cookie tracking
*/
internal const val SIFO_COOKIES_IS_WEB_BASED = "SIFO_COOKIES_IS_WEB_BASED"

/**
* Key for last cookie sync time
*/
Expand All @@ -182,4 +172,9 @@ object TagStringsAndValues {
*/
internal const val SIFO_DEFAULT_CONFIG = "https://trafficgateway.research-int.se/TrafficCollector?siteId={siteIdValue}&appClientId={appClientIdValue}&cp={cpValue}&appId={appIDValue}&appName={appNameValue}&appRef={appRefValue}"

/**
* Meta cookie name
*/
internal const val SIFO_META_COOKIE_NAME = "sifo_config"

}

0 comments on commit 120764c

Please sign in to comment.