diff --git a/Apps/FCM/android/gradle.properties b/Apps/FCM/android/gradle.properties index a46a5b90..a24956d6 100644 --- a/Apps/FCM/android/gradle.properties +++ b/Apps/FCM/android/gradle.properties @@ -39,3 +39,5 @@ newArchEnabled=false # Use this property to enable or disable the Hermes JS engine. # If set to false, you will be using JSC instead. hermesEnabled=true + +customerio.reactnative.excludePushMessaging=true \ No newline at end of file diff --git a/android/build.gradle b/android/build.gradle index 0b1d281e..2f28f5ab 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -24,6 +24,9 @@ def getExtOrIntegerDefault(name) { return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['customerio.reactnative.' + name]).toInteger() } +// Double negative to include by default +def shouldExcludePushMessaging = getExtOrDefault("excludePushMessaging") + android { namespace 'io.customer.reactnative.sdk' compileSdkVersion getExtOrIntegerDefault('compileSdkVersion') @@ -44,6 +47,16 @@ android { sourceCompatibility JavaVersion.VERSION_17 targetCompatibility JavaVersion.VERSION_17 } + + sourceSets { + main { + if (shouldExcludePushMessaging) { + java.srcDirs += ['src/push-noop'] + } else { + java.srcDirs += ['src/push'] + } + } + } } repositories { @@ -137,10 +150,14 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { } } -apply from: "./cio-core.gradle" - dependencies { // noinspection GradleDynamicVersion api 'com.facebook.react:react-native:+' implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + + implementation "io.customer.android:datapipelines:$cioAndroidSDKVersion" + implementation "io.customer.android:messaging-in-app:$cioAndroidSDKVersion" + if (!shouldExcludePushMessaging) { + implementation "io.customer.android:messaging-push-fcm:$cioAndroidSDKVersion" + } } diff --git a/android/cio-core.gradle b/android/cio-core.gradle deleted file mode 100644 index 353094e2..00000000 --- a/android/cio-core.gradle +++ /dev/null @@ -1,5 +0,0 @@ -dependencies { - implementation "io.customer.android:datapipelines:$cioAndroidSDKVersion" - implementation "io.customer.android:messaging-push-fcm:$cioAndroidSDKVersion" - implementation "io.customer.android:messaging-in-app:$cioAndroidSDKVersion" -} diff --git a/android/src/main/java/io/customer/reactnative/sdk/messagingpush/PermissionStatus.kt b/android/src/push-noop/io/customer/reactnative/sdk/messagingpush/PermissionStatus.kt similarity index 100% rename from android/src/main/java/io/customer/reactnative/sdk/messagingpush/PermissionStatus.kt rename to android/src/push-noop/io/customer/reactnative/sdk/messagingpush/PermissionStatus.kt diff --git a/android/src/push-noop/io/customer/reactnative/sdk/messagingpush/RNCIOPushMessaging.kt b/android/src/push-noop/io/customer/reactnative/sdk/messagingpush/RNCIOPushMessaging.kt new file mode 100644 index 00000000..2ed170ae --- /dev/null +++ b/android/src/push-noop/io/customer/reactnative/sdk/messagingpush/RNCIOPushMessaging.kt @@ -0,0 +1,78 @@ +package io.customer.reactnative.sdk.messagingpush + +import com.facebook.react.bridge.ReactApplicationContext +import com.facebook.react.bridge.ReactContextBaseJavaModule +import com.facebook.react.bridge.Promise +import com.facebook.react.bridge.ReactMethod +import com.facebook.react.bridge.ReadableMap +import io.customer.sdk.CustomerIOBuilder +import io.customer.sdk.core.di.SDKComponent +import io.customer.sdk.core.util.Logger +import java.lang.IllegalStateException + +/** + * ReactNative module to hold push messages features in a single place to bridge with native code. + */ +class RNCIOPushMessaging( + private val reactContext: ReactApplicationContext, +) : ReactContextBaseJavaModule(reactContext) { + override fun getName(): String = "CioRctPushMessaging" + + private val logger: Logger = SDKComponent.logger + + /** + * Adds push messaging module to native Android SDK based on the configuration provided by + * customer app. + * + * @param builder instance of CustomerIOBuilder to add push messaging module. + * @param config configuration provided by customer app for push messaging module. + */ + internal fun addNativeModuleFromConfig( + builder: CustomerIOBuilder, + config: Map + ) { + // No-op + } + + @ReactMethod + fun getPushPermissionStatus(promise: Promise) { + throw IllegalStateException("Push messaging is not enabled for CIO") + } + + /** + * To request push notification permissions using native apis. Push notifications doesn't + * require permissions for Android versions older than 13, so the results are returned instantly. + * For newer versions, the permission is requested and the promise is resolved after the request + * has been completed. + * + * @param pushConfigurationOptions configurations options for push notifications, required for + * iOS only, unused on Android. + * @param promise to resolve and return the results. + */ + @ReactMethod + fun showPromptForPushNotifications(pushConfigurationOptions: ReadableMap?, promise: Promise) { + throw IllegalStateException("Push messaging is not enabled for CIO") + } + + /** + * Handles push notification received. This is helpful in processing push notifications + * received outside the CIO SDK. + * + * @param message push payload received from FCM. + * @param handleNotificationTrigger indicating if the local notification should be triggered. + */ + @ReactMethod + fun handleMessage(message: ReadableMap?, handleNotificationTrigger: Boolean, promise: Promise) { + throw IllegalStateException("Push messaging is not enabled for CIO") + } + + /** + * Get the registered device token for the app. + * @returns Promise with device token as a string, or error if no token is + * registered or the method fails to fetch token. + */ + @ReactMethod + fun getRegisteredDeviceToken(promise: Promise) { + throw IllegalStateException("Push messaging is not enabled for CIO") + } +} diff --git a/android/src/push/io/customer/reactnative/sdk/messagingpush/PermissionStatus.kt b/android/src/push/io/customer/reactnative/sdk/messagingpush/PermissionStatus.kt new file mode 100644 index 00000000..06bc23f0 --- /dev/null +++ b/android/src/push/io/customer/reactnative/sdk/messagingpush/PermissionStatus.kt @@ -0,0 +1,9 @@ +package io.customer.reactnative.sdk.messagingpush + +/** + * Enum class for wrapping status of Android app permissions. + */ +enum class PermissionStatus { + Granted, + Denied, +} diff --git a/android/src/main/java/io/customer/reactnative/sdk/messagingpush/PushMessagingExtensions.kt b/android/src/push/io/customer/reactnative/sdk/messagingpush/PushMessagingExtensions.kt similarity index 100% rename from android/src/main/java/io/customer/reactnative/sdk/messagingpush/PushMessagingExtensions.kt rename to android/src/push/io/customer/reactnative/sdk/messagingpush/PushMessagingExtensions.kt diff --git a/android/src/main/java/io/customer/reactnative/sdk/messagingpush/RNCIOPushMessaging.kt b/android/src/push/io/customer/reactnative/sdk/messagingpush/RNCIOPushMessaging.kt similarity index 100% rename from android/src/main/java/io/customer/reactnative/sdk/messagingpush/RNCIOPushMessaging.kt rename to android/src/push/io/customer/reactnative/sdk/messagingpush/RNCIOPushMessaging.kt