diff --git a/CHANGELOG.md b/CHANGELOG.md index b99c734b8..919cf3695 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [1.21.2](https://github.com/rudderlabs/rudder-sdk-android/compare/v1.21.1...v1.21.2) (2024-01-25) + + +### Bug Fixes + +* added synchronization to RudderContext ([#372](https://github.com/rudderlabs/rudder-sdk-android/issues/372)) ([ad9baa0](https://github.com/rudderlabs/rudder-sdk-android/commit/ad9baa07ab5685a82c9b6822e01824db227642a3)) + ### [1.21.1](https://github.com/rudderlabs/rudder-sdk-android/compare/v1.21.0...v1.21.1) (2023-12-13) diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 2abc92cbc..000000000 --- a/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2021 RudderStack - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 000000000..bacb9917d --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,44 @@ +### Elastic License 2.0 (ELv2) ### + +## Acceptance ## +By using the software, you agree to all of the terms and conditions below. + +## Copyright License ## +The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below + +## Limitations ## +You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software. + +You may not move, change, disable, or circumvent the license key functionality in the software, and you may not remove or obscure any functionality in the software that is protected by the license key. + +You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law. + +## Patents ## +The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company. + +## Notices ## +You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms. + +If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software. + +## No Other Rights ## +These terms do not imply any licenses other than those expressly granted in these terms. + +## Termination ## +If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently. + +## No Liability ## +As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim. + +## Definitions ## +The *licensor* is the entity offering these terms, and the *software* is the software the licensor makes available under these terms, including any portion of it. + +*you* refers to the individual or entity agreeing to these terms. + +*your company* is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. *control* means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect. + +*your licenses* are all the licenses granted to you for the software under these terms. + +*use* means anything you do with the software requiring one of your licenses. + +*trademark* means trademarks, service marks, and similar rights. diff --git a/core/src/main/java/com/rudderstack/android/sdk/core/RudderApp.java b/core/src/main/java/com/rudderstack/android/sdk/core/RudderApp.java index a32d96520..ea0b61a51 100644 --- a/core/src/main/java/com/rudderstack/android/sdk/core/RudderApp.java +++ b/core/src/main/java/com/rudderstack/android/sdk/core/RudderApp.java @@ -9,30 +9,39 @@ class RudderApp { @SerializedName("build") - private String build; + private final String build; @SerializedName("name") - private String name; + private final String name; @SerializedName("namespace") - private String nameSpace; + private final String nameSpace; @SerializedName("version") - private String version; + private final String version; // internal constructor // to be used while creating a cache of context RudderApp(Application application) { + String buildValue = null; + String nameValue = null; + String nameSpaceValue = null; + String versionValue = null; try { String packageName = application.getPackageName(); PackageManager packageManager = application.getPackageManager(); PackageInfo packageInfo = packageManager.getPackageInfo(packageName, 0); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) - this.build = Long.toString(packageInfo.getLongVersionCode()); - else this.build = Integer.toString(packageInfo.versionCode); - this.name = packageInfo.applicationInfo.loadLabel(packageManager).toString(); - this.nameSpace = packageName; - this.version = packageInfo.versionName; + buildValue = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)? + Long.toString(packageInfo.getLongVersionCode()): Integer.toString(packageInfo.versionCode); + nameValue = packageInfo.applicationInfo.loadLabel(packageManager).toString(); + nameSpaceValue = packageName; + versionValue = packageInfo.versionName; } catch (PackageManager.NameNotFoundException ex) { ReportManager.reportError(ex); RudderLogger.logError(ex.getCause()); } + finally { + this.build = buildValue; + this.name = nameValue; + this.nameSpace = nameSpaceValue; + this.version = versionValue; + } } } diff --git a/core/src/main/java/com/rudderstack/android/sdk/core/RudderClient.java b/core/src/main/java/com/rudderstack/android/sdk/core/RudderClient.java index c9ec32eec..b12bd95e0 100644 --- a/core/src/main/java/com/rudderstack/android/sdk/core/RudderClient.java +++ b/core/src/main/java/com/rudderstack/android/sdk/core/RudderClient.java @@ -37,7 +37,7 @@ public class RudderClient { private static RudderOption defaultOptions; private static String deviceToken; private static String authToken; - private static ReentrantLock reentrantLock = new ReentrantLock(); + private static final ReentrantLock reentrantLock = new ReentrantLock(); private static final int NUMBER_OF_FLUSH_CALLS_IN_QUEUE = 1; diff --git a/core/src/main/java/com/rudderstack/android/sdk/core/RudderContext.java b/core/src/main/java/com/rudderstack/android/sdk/core/RudderContext.java index 9fb525dc7..c84f7db17 100644 --- a/core/src/main/java/com/rudderstack/android/sdk/core/RudderContext.java +++ b/core/src/main/java/com/rudderstack/android/sdk/core/RudderContext.java @@ -118,7 +118,9 @@ public class RudderContext { void resetTraits() { RudderTraits traits = new RudderTraits(); // convert the whole traits to map and take care of the extras - this.traits = Utils.convertToMap(RudderGson.getInstance().toJson(traits)); + synchronized (this) { + this.traits = Utils.convertToMap(RudderGson.getInstance().toJson(traits)); + } } void updateTraits(RudderTraits traits) { @@ -135,13 +137,17 @@ void updateTraits(RudderTraits traits) { // If a user is already loggedIn and then a new user tries to login if (existingId != null && newId != null && !existingId.equals(newId)) { - this.traits = traitsMap; + synchronized (this) { + this.traits = traitsMap; + } resetExternalIds(); return; } // update traits object here - this.traits.putAll(traitsMap); + synchronized (this) { + this.traits.putAll(traitsMap); + } } @@ -154,7 +160,9 @@ void persistTraits() { try { if (RudderClient.getApplication() != null) { RudderPreferenceManager preferenceManger = RudderPreferenceManager.getInstance(RudderClient.getApplication()); - preferenceManger.saveTraits(RudderGson.getInstance().toJson(this.traits)); + synchronized (this) { + preferenceManger.saveTraits(RudderGson.getInstance().toJson(this.traits)); + } } } catch (NullPointerException ex) { ReportManager.reportError(ex); @@ -386,7 +394,9 @@ RudderContext copy() { copy.app = this.app; if (this.traits != null) { - copy.traits = new HashMap<>(this.traits); + synchronized (this) { + copy.traits = new HashMap<>(this.traits); + } } copy.libraryInfo = this.libraryInfo; copy.osInfo = this.osInfo; diff --git a/core/src/main/java/com/rudderstack/android/sdk/core/RudderLibraryInfo.java b/core/src/main/java/com/rudderstack/android/sdk/core/RudderLibraryInfo.java index bc7c39dd9..462fd175a 100644 --- a/core/src/main/java/com/rudderstack/android/sdk/core/RudderLibraryInfo.java +++ b/core/src/main/java/com/rudderstack/android/sdk/core/RudderLibraryInfo.java @@ -4,7 +4,7 @@ class RudderLibraryInfo { @SerializedName("name") - private String name = BuildConfig.LIBRARY_PACKAGE_NAME; + private final String name = BuildConfig.LIBRARY_PACKAGE_NAME; @SerializedName("version") - private String version = BuildConfig.VERSION_NAME; + private final String version = BuildConfig.VERSION_NAME; } diff --git a/core/src/main/java/com/rudderstack/android/sdk/core/RudderOSInfo.java b/core/src/main/java/com/rudderstack/android/sdk/core/RudderOSInfo.java index c218c185b..6b58d28e2 100644 --- a/core/src/main/java/com/rudderstack/android/sdk/core/RudderOSInfo.java +++ b/core/src/main/java/com/rudderstack/android/sdk/core/RudderOSInfo.java @@ -6,7 +6,7 @@ class RudderOSInfo { @SerializedName("name") - private String name = "Android"; + private final String name = "Android"; @SerializedName("version") - private String version = Build.VERSION.RELEASE; + private final String version = Build.VERSION.RELEASE; } diff --git a/gradle.properties b/gradle.properties index f68b340a5..df3e5d1a7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,8 +5,8 @@ android.enableJetifier=true android.enableR8.fullMode=true kotlin.code.style=official GROUP=com.rudderstack.android.sdk -VERSION_CODE=23 -VERSION_NAME=1.21.1 +VERSION_CODE=24 +VERSION_NAME=1.21.2 POM_NAME=Rudderstack SDK for android POM_DESCRIPTION=Rudderstack SDK for android POM_ARTIFACT_ID=core diff --git a/package.json b/package.json index 393cd0bbd..a6f4c8d4a 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "1.21.1", + "version": "1.21.2", "dependencies": { "properties-reader": "^2.2.0" }