Skip to content

Commit

Permalink
dispatcher: abort dispatcher initialization when running on 3.3+
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-roland committed Dec 7, 2023
1 parent 36bfc2c commit 5e78e33
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
1.0.1
-----

* Added verification to ensure the dispatcher is running on the right Piano SDK version (3.2.1 or older) while waiting for us to support the new version (3.3.0+).

1.0.0
-----

Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ A "ready-to-go" dispatcher that reflect event from the Batch SDK to the Piano da
- Android Studio 3.0+
- Android 16+
- Batch Android SDK 1.19.3+
- Piano Analytics 3.1.0+
- Piano Analytics [3.1.0...3.2.1]

> The Android Piano Analytics dispatcher requires version 3.2.1 or older of the Piano SDK since it does NOT support yet the rewritten Kotlin Piano SDK.
# Installation
Gradle (recommended)

```
implementation 'com.batch.android:piano-dispatcher:1.0.0'
implementation 'com.batch.android:piano-dispatcher:1.0.1'
```

Read our [setup documentation](https://doc.batch.com/) to follow a step by step tutorial for integrating Batch features into your app.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public class PianoRegistrar implements DispatcherRegistrar {
@Override
public BatchEventDispatcher getDispatcher(Context context) {
if (instance == null) {
// Abort initialization when the App is running on the new Piano SDK.
if (isNewPianoSDKPresent()) {
Log.e("Batch", "PianoDispatcher - It looks like you are using an unsupported version of the Piano SDK." +
" This dispatcher requires version 3.2.1 or older. Aborting initialization.");
return null;
}
instance = new PianoDispatcher(context);
instance.enableBatchCustomEvents(getBooleanMetaDataInfo(context, CUSTOM_EVENT_ENABLED_METADATA, false));
instance.enableBatchOnSiteAdsEvents(getBooleanMetaDataInfo(context, ONSITE_AD_EVENT_ENABLED_METADATA, true));
Expand Down Expand Up @@ -59,4 +65,17 @@ private boolean getBooleanMetaDataInfo(Context context, String key, boolean fall
}
return fallback;
}

/**
* Check if the new Kotlin Piano SDK (3.3.0+) is present.
* @return Whether the new Piano SDK is present.
*/
private boolean isNewPianoSDKPresent() {
try {
Class.forName("io.piano.android.analytics.PianoAnalytics");
return true;
} catch (ClassNotFoundException e) {
return false;
}
}
}

0 comments on commit 5e78e33

Please sign in to comment.