Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use meta-data for user agent client #439

Merged
merged 6 commits into from
Sep 25, 2024

Conversation

mrehan27
Copy link
Contributor

part of MBL-522

Changes

  • Moved Client class out of AndroidSDKComponent constructor and made it a singular dependency, allowing for decoupling
  • Simplified Client class by removing sealed implementation
  • Updated Client class to create user-agent client based on meta-data provided in AndroidManifest
  • Added and used extensions to fetch meta-data from AndroidManifest and fixed the deprecated method warning for ApplicationInfo
  • Added tests to verify the changes
  • Removed ClientArgument from TestArgument as it is no longer needed

Benefits of this approach

  • Client is no longer dependent on SDK initialization
  • Client will always remain the same, regardless of which classes initialize the SDK and register AndroidSDKComponent
  • Client can still be overridden in AndroidSDKComponent

User agent sent from Android SDK

Customer.io Android Client/4.2.0 (Google Pixel 6; 34) io.customer.android.sample.java_layout/1.0

User agent sent from React Native SDK (Pending changes)

Customer.io ReactNative Client/3.8.0 (Google sdk_gphone64_arm64; 33) io.customer.rn_sample.fcm/1.0

@mrehan27 mrehan27 self-assigned this Sep 19, 2024
Copy link

github-actions bot commented Sep 19, 2024

Sample app builds 📱

Below you will find the list of the latest versions of the sample apps. It's recommended to always download the latest builds of the sample apps to accurately test the pull request.


  • java_layout: rehan/mbl-522-user-agent (1727210909)
  • kotlin_compose: rehan/mbl-522-user-agent (1727210907)

Copy link

codecov bot commented Sep 19, 2024

Codecov Report

Attention: Patch coverage is 25.00000% with 18 lines in your changes missing coverage. Please review.

Please upload report for BASE (feature/react-native-cdp@0f20226). Learn more about missing BASE report.

Files with missing lines Patch % Lines
.../customer/sdk/core/extensions/ContextExtensions.kt 0.00% 12 Missing ⚠️
...lin/io/customer/sdk/core/di/AndroidSDKComponent.kt 0.00% 2 Missing ⚠️
...c/main/kotlin/io/customer/sdk/data/store/Client.kt 71.42% 0 Missing and 2 partials ⚠️
.../kotlin/io/customer/sdk/core/di/SDKComponentExt.kt 0.00% 1 Missing ⚠️
...messagingpush/CustomerIOPushNotificationHandler.kt 0.00% 1 Missing ⚠️
Additional details and impacted files
@@                     Coverage Diff                     @@
##             feature/react-native-cdp     #439   +/-   ##
===========================================================
  Coverage                            ?   51.88%           
  Complexity                          ?      289           
===========================================================
  Files                               ?       96           
  Lines                               ?     2253           
  Branches                            ?      352           
===========================================================
  Hits                                ?     1169           
  Misses                              ?      982           
  Partials                            ?      102           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

github-actions bot commented Sep 19, 2024

📏 SDK Binary Size Comparison Report

No changes detected in SDK binary size ✅

Copy link

Build available to test
Version: rehan-mbl-522-user-agent-SNAPSHOT
Repository: https://s01.oss.sonatype.org/content/repositories/snapshots/

<meta-data
android:name="io.customer.sdk.android.core.SDK_VERSION"
android:value="1.3.5" />
</application>
Copy link
Contributor Author

@mrehan27 mrehan27 Sep 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only for tests. But this is how we can modify these values in wrapper SDKs.

null
}
val appMetaData = applicationInfo?.metaData
val appMetaData = context.applicationMetaData()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reused extension to fix deprecated warning

@@ -43,8 +42,7 @@ abstract class BaseTest {
*/
private fun registerAndroidSDKComponent(testConfig: TestConfig) {
val application = testConfig.argumentOrNull<ApplicationArgument>()?.value ?: return
val client = testConfig.argumentOrNull<ClientArgument>()?.value ?: return
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now no longer need Client to register and initialize AndroidSDKComponent

Copy link
Contributor

@Shahroz16 Shahroz16 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approach looks solid, great idea, some suggestions and 1 thing to validate before we finalize

core/src/androidTest/AndroidManifest.xml Outdated Show resolved Hide resolved
core/src/main/kotlin/io/customer/sdk/data/store/Client.kt Outdated Show resolved Hide resolved
ignoreCase = true
) -> Flutter(sdkVersion = sdkVersion)
else -> Other(source = source, sdkVersion = sdkVersion)
fun fromMetadata(metadata: Bundle?): Client {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what would happen if both android SDK and react native SDK manifest have same values? shouldn't we override or handle that case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added values in common test to help verify manifest merger challenges

import org.amshove.kluent.shouldBeEqualTo
import org.junit.Test

class AndroidManifestClientTest : AndroidTest() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be great if we can test meta data merging here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added multiple manifests, test will not change because the changes have to be made when merging Manifest

@mrehan27 mrehan27 changed the base branch from main to feature/react-native-cdp September 24, 2024 15:29
Copy link
Contributor

@Shahroz16 Shahroz16 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@mrehan27 mrehan27 merged commit 5f55551 into feature/react-native-cdp Sep 25, 2024
33 of 35 checks passed
@mrehan27 mrehan27 deleted the rehan/mbl-522-user-agent branch September 25, 2024 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants