From c7320db42ef39950c1f34b92f6dd6500f8ff69ed Mon Sep 17 00:00:00 2001 From: Tomas Chladek Date: Fri, 10 Jan 2025 15:25:15 +0100 Subject: [PATCH] Interactions Signed-off-by: Tomas Chladek --- agent/build.gradle.kts | 1 + buildSrc/src/main/kotlin/Dependencies.kt | 2 + integration/interactions/build.gradle.kts | 32 +++++++ integration/interactions/consumer-rules.pro | 0 integration/interactions/lint-baseline.xml | 4 + integration/interactions/proguard-rules.pro | 0 .../interactions/src/main/AndroidManifest.xml | 10 +++ .../interactions/InteractionsConfigurator.kt | 88 +++++++++++++++++++ .../interactions/InteractionsInstaller.kt | 40 +++++++++ .../InteractionsModuleConfiguration.kt | 21 +++++ settings.gradle | 3 +- 11 files changed, 200 insertions(+), 1 deletion(-) create mode 100644 integration/interactions/build.gradle.kts create mode 100644 integration/interactions/consumer-rules.pro create mode 100644 integration/interactions/lint-baseline.xml create mode 100644 integration/interactions/proguard-rules.pro create mode 100644 integration/interactions/src/main/AndroidManifest.xml create mode 100644 integration/interactions/src/main/java/com/cisco/android/rum/integration/interactions/InteractionsConfigurator.kt create mode 100644 integration/interactions/src/main/java/com/cisco/android/rum/integration/interactions/InteractionsInstaller.kt create mode 100644 integration/interactions/src/main/java/com/cisco/android/rum/integration/interactions/InteractionsModuleConfiguration.kt diff --git a/agent/build.gradle.kts b/agent/build.gradle.kts index aa7b409c..5179c58c 100644 --- a/agent/build.gradle.kts +++ b/agent/build.gradle.kts @@ -26,5 +26,6 @@ dependencies { api(project(":integration:anr")) api(project(":integration:networkrequest")) api(project(":integration:startup")) + api(project(":integration:interactions")) } diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt index e01c415a..1dd11725 100644 --- a/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -88,6 +88,8 @@ object Dependencies { private const val version = "1.0.10" const val logger = "com.cisco.android:sr-common-logger:$version" + const val frameCapturer = "com.cisco.android:sr-instrumentation-session-recording-frame-capturer:$version" + const val interactions = "com.cisco.android:sr-instrumentation-session-recording-interactions:$version" } } diff --git a/integration/interactions/build.gradle.kts b/integration/interactions/build.gradle.kts new file mode 100644 index 00000000..c62518f6 --- /dev/null +++ b/integration/interactions/build.gradle.kts @@ -0,0 +1,32 @@ +import plugins.ConfigAndroidLibrary +import plugins.ConfigPublish +import utils.artifactIdProperty +import utils.artifactPrefix +import utils.integrationPrefix +import utils.versionProperty + +plugins { + id("com.android.library") + id("kotlin-android") +} + +apply() +apply() + +ext { + set(artifactIdProperty, "$artifactPrefix$integrationPrefix${project.name}") + set(versionProperty, Configurations.sdkVersionName) +} + +android { + namespace = "com.cisco.android.rum.integration.interactions" +} + +dependencies { + implementation(project(":common:utils")) + implementation(project(":integration:agent:internal")) + + implementation(Dependencies.Android.SessionReplay.logger) + implementation(Dependencies.Android.SessionReplay.frameCapturer) + implementation(Dependencies.Android.SessionReplay.interactions) +} diff --git a/integration/interactions/consumer-rules.pro b/integration/interactions/consumer-rules.pro new file mode 100644 index 00000000..e69de29b diff --git a/integration/interactions/lint-baseline.xml b/integration/interactions/lint-baseline.xml new file mode 100644 index 00000000..27ab162a --- /dev/null +++ b/integration/interactions/lint-baseline.xml @@ -0,0 +1,4 @@ + + + + diff --git a/integration/interactions/proguard-rules.pro b/integration/interactions/proguard-rules.pro new file mode 100644 index 00000000..e69de29b diff --git a/integration/interactions/src/main/AndroidManifest.xml b/integration/interactions/src/main/AndroidManifest.xml new file mode 100644 index 00000000..a048c1b0 --- /dev/null +++ b/integration/interactions/src/main/AndroidManifest.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/integration/interactions/src/main/java/com/cisco/android/rum/integration/interactions/InteractionsConfigurator.kt b/integration/interactions/src/main/java/com/cisco/android/rum/integration/interactions/InteractionsConfigurator.kt new file mode 100644 index 00000000..7d3ad1ba --- /dev/null +++ b/integration/interactions/src/main/java/com/cisco/android/rum/integration/interactions/InteractionsConfigurator.kt @@ -0,0 +1,88 @@ +/* + * Copyright 2024 Splunk Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.cisco.android.rum.integration.interactions + +import android.app.Application +import android.content.Context +import com.cisco.android.common.logger.Logger +import com.cisco.android.instrumentation.recording.capturer.FrameCapturer +import com.cisco.android.instrumentation.recording.interactions.Interactions +import com.cisco.android.instrumentation.recording.interactions.OnInteractionListener +import com.cisco.android.instrumentation.recording.interactions.model.Interaction +import com.cisco.android.instrumentation.recording.interactions.model.LegacyData +import com.cisco.android.instrumentation.recording.wireframe.model.Wireframe +import com.cisco.android.instrumentation.recording.wireframe.stats.WireframeStats +import com.cisco.android.rum.integration.agent.internal.AgentIntegration +import com.cisco.android.rum.integration.agent.internal.config.ModuleConfigurationManager +import com.cisco.android.rum.integration.agent.internal.config.RemoteModuleConfiguration + +internal object InteractionsConfigurator { + + private const val TAG = "InteractionsConfigurator" + private const val MODULE_NAME = "interactions" + + init { + AgentIntegration.registerModule(MODULE_NAME) + } + + fun attach(context: Context) { + AgentIntegration.obtainInstance(context).listeners += installationListener + + val application = context.applicationContext as Application + + Interactions.attach(application) + FrameCapturer.attach(application) + + FrameCapturer.listeners += object : FrameCapturer.Listener { + override fun onNewWireframe(frame: Wireframe.Frame, stats: WireframeStats) { + Interactions.updateWireframe(frame) + } + } + + Interactions.listeners += interactionsListener + } + + private val interactionsListener = object : OnInteractionListener { + override fun onInteraction(interaction: Interaction, legacyData: LegacyData?) { + Logger.d(TAG, "onInteraction(interaction: $interaction, legacyData: $legacyData)") + + // TODO process interaction + } + } + + private val configManagerListener = object : ModuleConfigurationManager.Listener { + override fun onRemoteModuleConfigurationsChanged(manager: ModuleConfigurationManager, remoteConfigurations: List) { + Logger.d(TAG, "onRemoteModuleConfigurationsChanged(remoteConfigurations: $remoteConfigurations)") + setModuleConfiguration(remoteConfigurations) + } + } + + private fun setModuleConfiguration(remoteConfigurations: List) { + Logger.d(TAG, "setModuleConfiguration(remoteConfigurations: $remoteConfigurations)") + } + + private val installationListener = object : AgentIntegration.Listener { + override fun onInstall(context: Context) { + Logger.d(TAG, "onInstall()") + + val integration = AgentIntegration.obtainInstance(context) + integration.moduleConfigurationManager.listeners += configManagerListener + + setModuleConfiguration(integration.moduleConfigurationManager.remoteConfigurations) + } + } +} diff --git a/integration/interactions/src/main/java/com/cisco/android/rum/integration/interactions/InteractionsInstaller.kt b/integration/interactions/src/main/java/com/cisco/android/rum/integration/interactions/InteractionsInstaller.kt new file mode 100644 index 00000000..2007dbc9 --- /dev/null +++ b/integration/interactions/src/main/java/com/cisco/android/rum/integration/interactions/InteractionsInstaller.kt @@ -0,0 +1,40 @@ +/* + * Copyright 2024 Splunk Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.cisco.android.rum.integration.interactions + +import android.content.ContentProvider +import android.content.ContentValues +import android.database.Cursor +import android.net.Uri + +internal class InteractionsInstaller : ContentProvider() { + + override fun onCreate(): Boolean { + InteractionsConfigurator.attach(context!!) + return true + } + + override fun query(uri: Uri, projection: Array?, selection: String?, selectionArgs: Array?, sortOrder: String?): Cursor? = null + + override fun getType(uri: Uri): String? = null + + override fun insert(uri: Uri, values: ContentValues?): Uri? = null + + override fun delete(uri: Uri, selection: String?, selectionArgs: Array?): Int = 0 + + override fun update(uri: Uri, values: ContentValues?, selection: String?, selectionArgs: Array?): Int = 0 +} diff --git a/integration/interactions/src/main/java/com/cisco/android/rum/integration/interactions/InteractionsModuleConfiguration.kt b/integration/interactions/src/main/java/com/cisco/android/rum/integration/interactions/InteractionsModuleConfiguration.kt new file mode 100644 index 00000000..15f3c77c --- /dev/null +++ b/integration/interactions/src/main/java/com/cisco/android/rum/integration/interactions/InteractionsModuleConfiguration.kt @@ -0,0 +1,21 @@ +/* + * Copyright 2024 Splunk Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.cisco.android.rum.integration.interactions + +import com.cisco.android.rum.integration.agent.module.ModuleConfiguration + +class InteractionsModuleConfiguration : ModuleConfiguration diff --git a/settings.gradle b/settings.gradle index a0040981..619caedc 100644 --- a/settings.gradle +++ b/settings.gradle @@ -16,7 +16,8 @@ include ':instrumentation:runtime:crash', include ':integration:agent:api', ':integration:agent:module', ':integration:agent:internal', - ':integration:startup' + ':integration:startup', + ':integration:interactions' // Integration tests // TODO disable it for now because of different artifactory include ':integration-run'