Skip to content

Commit

Permalink
Merge pull request #8 from shortcut/master
Browse files Browse the repository at this point in the history
Fix the bugs causing the sdk not to work properly
  • Loading branch information
Morteza-Rastgoo committed Sep 7, 2021
2 parents 7135265 + 7e2e37f commit 7f115fe
Show file tree
Hide file tree
Showing 16 changed files with 255 additions and 165 deletions.
1 change: 1 addition & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,19 @@ if (TSMobileAnalytics.getInstance() != null) {

This method will allow third-party cookies.

If you have a `react-native` project, there is a [known bug](https://github.com/facebook/react-native/commit/29249e19bd9cb4de8cb5b00edcd17f2c49d0d02c#diff-5eeea7cc5d0049418255078dfb3555cdbc3fc02e370392f4b6a31dd831720270) that doesn't let the SDK work properly. This is how you can fix it until it is resolved in the main react-native repo:

```
//>>>>> ReactAndroid/src/main/java/com/facebook/react/ReactActivity.java
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
mDelegate.onActivityResult(requestCode, resultCode, data);
}
```


## Debugging
There are several more advanced functions in the framework. The purpose of them is to help out if there are any problems or issues with the tagging that needs to be traced. It is possible to get information about pending requests and to subscribe on notifications when a tag request has completed or failed, and more. To see some examples on how to use these functions, have a look at the source code for the test application.
Expand Down
9 changes: 7 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ apply plugin: 'kotlin-android-extensions'
version = "4.0.1"

android {
compileSdkVersion 29
compileSdkVersion 30
defaultConfig {
applicationId "se.kantarsifo.mobileanalytics.sampleapp"
minSdkVersion 14
targetSdkVersion 29
targetSdkVersion 30
versionCode 1
versionName version
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand All @@ -25,6 +25,10 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
// applicationVariants.all { variant ->
// variant.outputs.each { output ->
// def outputFile = output.outputFile
Expand All @@ -48,6 +52,7 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test:core-ktx:1.4.0'
}

//task copyAARToReleaseFolder() << {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.android.tools.build:gradle:4.2.2'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ org.gradle.jvmargs=-Xmx1536m
# This option should only be used with decoupled projects. More details, visit
# http:https://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
android.useAndroidX=true
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\:https://services.gradle.org/distributions/gradle-5.4.1-all.zip
distributionUrl=https\:https://services.gradle.org/distributions/gradle-6.7.1-all.zip
9 changes: 5 additions & 4 deletions libmobiletagging/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ apply plugin: 'com.github.dcendents.android-maven'

group='myGroups'

version = "4.0.1"
version = "4.1.0"


android {
compileSdkVersion 29
compileSdkVersion 30
defaultConfig {
minSdkVersion 14
targetSdkVersion 29
targetSdkVersion 30
versionCode 1
versionName version
publishNonDefault true
buildConfigField("long", "VERSION_CODE", "${defaultConfig.versionCode}")
buildConfigField("String","VERSION_NAME","\"${defaultConfig.versionName}\"")
}
buildTypes {
release {
Expand All @@ -36,7 +38,6 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'commons-lang:commons-lang:2.3'

testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:3.1.0'
Expand Down
9 changes: 8 additions & 1 deletion libmobiletagging/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="se.kantarsifo.mobileanalytics.framework"/>
<manifest package="se.kantarsifo.mobileanalytics.framework"
xmlns:android="http:https://schemas.android.com/apk/res/android">
<queries>
<package android:name="com.google.android.webview" />
<package android:name="se.poll.android" />
<package android:name="se.tns_sifo.ipm" />
</queries>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ class ActivityResultImpl(private val registry: ActivityResultRegistry,
try {
startForResult.launch(intent)
} catch (e: Exception) {
e.printStackTrace()
onResult(null)
// e.printStackTrace()
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package se.kantarsifo.mobileanalytics.framework

import android.util.Log

object Logger {
const val TAG = "MobileAppTagging"
fun log(message: String) {
if (TSMobileAnalytics.logPrintsActivated) {
Log.d(TAG, "***********************************")
Log.d(TAG, message)
Log.d(TAG, "***********************************")
}
}

fun error(message: String) {
if (TSMobileAnalytics.logPrintsActivated) {
Log.e(TAG, "***********************************")
Log.e(TAG, message)
Log.e(TAG, "***********************************")
}
}

fun fatalError(message: String) {
Log.e(TAG, "***********************************")
Log.e(TAG, message)
Log.e(TAG, "***********************************")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.content.pm.PackageManager
import android.net.Uri
import androidx.activity.ComponentActivity
import org.json.JSONArray
import org.json.JSONException
import se.kantarsifo.mobileanalytics.framework.Logger.error
import se.kantarsifo.mobileanalytics.framework.Utils.isPackageInstalled
import java.io.BufferedReader
import java.io.FileInputStream
import java.io.IOException
Expand Down Expand Up @@ -36,8 +37,7 @@ internal object PanelistHandler {
}

fun syncCookies(context: Context, activity: ComponentActivity, onComplete: () -> Unit) {
val pm = context.packageManager
val isInstalled: Boolean = isPackageInstalled(TagStringsAndValues.SIFO_PANELIST_PACKAGE_NAME_V2, pm)
val isInstalled: Boolean = context.isPackageInstalled(TagStringsAndValues.SIFO_PANELIST_PACKAGE_NAME_V2)
val sharedPref = activity.getSharedPreferences(TagStringsAndValues.SIFO_PREFERENCE_KEY, Context.MODE_PRIVATE)
if (isInstalled) {
if (shouldUpdateCookieValues(activity)) {
Expand Down Expand Up @@ -79,13 +79,6 @@ internal object PanelistHandler {
sharedPreferences.edit().remove(TagStringsAndValues.SIFO_PREFERENCE_COOKIES_SYNC_TIME).commit()
}

private fun isPackageInstalled(packageName: String?, packageManager: PackageManager): Boolean {
return try {
packageManager.getApplicationInfo(packageName, 0).enabled
} catch (e: PackageManager.NameNotFoundException) {
false
}
}

/**
* Opens a FileInputStream from TNS Sifo-Panelen
Expand All @@ -99,7 +92,7 @@ internal object PanelistHandler {
context.createPackageContext(packageName, 0).openFileInput(filename)
} catch (e: Exception) {

TSMobileAnalyticsBackend.logError("Error Getting InputStream")
error("Error Getting InputStream")
null
}
}
Expand All @@ -113,7 +106,7 @@ internal object PanelistHandler {
cookieList.add(CookieHandler.getCookieFromJson(entry))
}
} catch (e: JSONException) {
TSMobileAnalyticsBackend.logError("Error parsing TNS Panelist JSON data")
error("Error parsing TNS Panelist JSON data")
}
return cookieList
}
Expand All @@ -128,7 +121,7 @@ internal object PanelistHandler {
cookieList.add(CookieHandler.getCookieFromJson(entry))
}
} catch (e: JSONException) {
TSMobileAnalyticsBackend.logError("Error parsing TNS Panelist JSON data")
error("Error parsing TNS Panelist JSON data")
}
return cookieList
}
Expand All @@ -155,12 +148,12 @@ internal object PanelistHandler {
}
return buffer.toString()
} catch (e: Exception) {
TSMobileAnalyticsBackend.logError(errorString)
error(errorString)
} finally {
try {
input?.close()
} catch (e: IOException) { // Should never happen
TSMobileAnalyticsBackend.logError("Error Closing InputStream")
error("Error Closing InputStream")
}
}
return ""
Expand Down
Loading

0 comments on commit 7f115fe

Please sign in to comment.