-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support for wrapper SDKs (#442)
Co-authored-by: Shahroz Khan <[email protected]>
- Loading branch information
Showing
34 changed files
with
485 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,17 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
</manifest> | ||
<application> | ||
<!-- | ||
Meta-data tags added here to test challenges that may arise when merging multiple | ||
AndroidManifest.xml files with same meta-data tags. | ||
See AndroidManifest.xml in androidTest directory of core module for more details. | ||
--> | ||
<meta-data | ||
android:name="io.customer.sdk.android.core.SDK_SOURCE" | ||
android:value="CommonTestAndroidSDK" /> | ||
<meta-data | ||
android:name="io.customer.sdk.android.core.SDK_VERSION" | ||
android:value="0.1.0" /> | ||
</application> | ||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
|
||
<application> | ||
<!-- | ||
This is how wrapper SDKs can provide their own values for the SDK_SOURCE and SDK_VERSION meta-data. | ||
tools:replace="android:value" is used to replace the value of the meta-data. | ||
tools:node="replace" is used to replace the entire meta-data tag. | ||
Either of these attributes can be used to resolve any conflicts that may arise when merging | ||
multiple AndroidManifest.xml files with the same meta-data tags. | ||
--> | ||
<meta-data | ||
android:name="io.customer.sdk.android.core.SDK_SOURCE" | ||
android:value="TestUserAgent" | ||
tools:replace="android:value" /> | ||
<meta-data | ||
android:name="io.customer.sdk.android.core.SDK_VERSION" | ||
android:value="1.3.5" | ||
tools:node="replace" /> | ||
</application> | ||
</manifest> |
15 changes: 15 additions & 0 deletions
15
core/src/androidTest/java/io/customer/sdk/data/store/AndroidManifestClientTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.customer.sdk.data.store | ||
|
||
import io.customer.commontest.core.AndroidTest | ||
import io.customer.sdk.core.extensions.applicationMetaData | ||
import org.amshove.kluent.shouldBeEqualTo | ||
import org.junit.Test | ||
|
||
class AndroidManifestClientTest : AndroidTest() { | ||
@Test | ||
fun fromManifest_givenTestMetaData_expectClientWithTestMetaData() { | ||
val client = Client.fromMetadata(application.applicationMetaData()) | ||
|
||
client.toString() shouldBeEqualTo "TestUserAgent Client/1.3.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
core/src/main/kotlin/io/customer/sdk/core/extensions/ContextExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.customer.sdk.core.extensions | ||
|
||
import android.content.Context | ||
import android.content.pm.PackageManager | ||
import android.os.Build | ||
import android.os.Bundle | ||
import io.customer.sdk.core.di.SDKComponent | ||
|
||
/** | ||
* Retrieves application meta-data from AndroidManifest.xml file. | ||
* | ||
* @return The meta-data bundle from application info. | ||
*/ | ||
fun Context.applicationMetaData(): Bundle? = try { | ||
val applicationInfo = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { | ||
packageManager.getApplicationInfo( | ||
packageName, | ||
PackageManager.ApplicationInfoFlags.of(PackageManager.GET_META_DATA.toLong()) | ||
) | ||
} else { | ||
@Suppress("DEPRECATION") | ||
packageManager.getApplicationInfo( | ||
packageName, | ||
PackageManager.GET_META_DATA | ||
) | ||
} | ||
applicationInfo.metaData | ||
} catch (ex: Exception) { | ||
SDKComponent.logger.error("Failed to get ApplicationInfo with error: ${ex.message}") | ||
null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.