diff --git a/CHANGELOG.md b/CHANGELOG.md index 168eed5..9033889 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ # Change Log + +## [4.13.1](https://github.com/deltaDNA/android-sdk/releases/tag/4.13.1) + +### Fixed +- Time consuming calls on engage response errors no longer block the UI thread + ## [4.13.0](https://github.com/deltaDNA/android-sdk/releases/tag/4.13.0) ### Added diff --git a/README-CN.md b/README-CN.md index 455c14f..ddd2e53 100755 --- a/README-CN.md +++ b/README-CN.md @@ -43,7 +43,7 @@ allprojects { ``` 在你APP的构建脚本 ```groovy -compile 'com.deltadna.android:deltadna-sdk:4.13.0' +compile 'com.deltadna.android:deltadna-sdk:4.13.1' ``` ## 初始化 diff --git a/README.md b/README.md index 44fda11..ebfe2fa 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ allprojects { In your app's build script: ```groovy dependencies { - implementation 'com.deltadna.android:deltadna-sdk:4.13.0' + implementation 'com.deltadna.android:deltadna-sdk:4.13.1' } ``` The Java source and target compatibility needs to be set to 1.8 in you app's build script: diff --git a/gradle.properties b/gradle.properties index 7aef2c3..e07e712 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ GROUP=com.deltadna.android -VERSION_NAME=4.13.0 +VERSION_NAME=4.13.1 POM_DESCRIPTION=deltaDNA SDK for Android POM_URL=https://github.com/deltaDNA/android-sdk diff --git a/library-notifications/README-CN.md b/library-notifications/README-CN.md index 0e62c76..37d0374 100755 --- a/library-notifications/README-CN.md +++ b/library-notifications/README-CN.md @@ -41,8 +41,8 @@ allprojects { ``` 在你APP的构建脚本 ```groovy -compile 'com.deltadna.android:deltadna-sdk:4.13.0' -compile 'com.deltadna.android:deltadna-sdk-notifications:4.13.0' +compile 'com.deltadna.android:deltadna-sdk:4.13.1' +compile 'com.deltadna.android:deltadna-sdk-notifications:4.13.1' ``` ## 整合 diff --git a/library-notifications/README.md b/library-notifications/README.md index f53beb5..d992639 100644 --- a/library-notifications/README.md +++ b/library-notifications/README.md @@ -41,8 +41,8 @@ allprojects { In your app's build script: ```groovy dependencies { - implementation 'com.deltadna.android:deltadna-sdk:4.13.0' - implementation 'com.deltadna.android:deltadna-sdk-notifications:4.13.0' + implementation 'com.deltadna.android:deltadna-sdk:4.13.1' + implementation 'com.deltadna.android:deltadna-sdk-notifications:4.13.1' } ``` diff --git a/library/src/main/java/com/deltadna/android/sdk/EventHandler.java b/library/src/main/java/com/deltadna/android/sdk/EventHandler.java index f9d6b13..be37e51 100644 --- a/library/src/main/java/com/deltadna/android/sdk/EventHandler.java +++ b/library/src/main/java/com/deltadna/android/sdk/EventHandler.java @@ -18,6 +18,9 @@ import android.os.AsyncTask; import androidx.annotation.Nullable; + +import android.os.Handler; +import android.os.Looper; import android.util.Log; import com.deltadna.android.sdk.helpers.ClientInfo; import com.deltadna.android.sdk.listeners.EngageListener; @@ -48,6 +51,8 @@ final class EventHandler { new ScheduledThreadPoolExecutor(1, r -> new Thread( r, EventHandler.class.getSimpleName())); + + private final Handler mainThreadTaskHandler = new Handler(Looper.getMainLooper()); private final EventStore events; private final EngageStore engagements; @@ -218,25 +223,29 @@ public void onCompleted(Response result) { @Override public void onError(Throwable t) { - final JSONObject cached = engagements.get(engagement); - if (cached != null) { - try { - engagement.setResponse(new Response<>( - 200, - true, - null, - cached.put("isCachedResponse", true), - null)); - - Log.d(TAG, "Using cached response " + engagement.getJson()); - - listener.onCompleted(engagement); - } catch (JSONException e) { - listener.onError(e); + // This needs to be run off the main thread, as it involves blocking database + // operations that can cause ANRs. + executor.execute(() -> { + final JSONObject cached = engagements.get(engagement); + if (cached != null) { + try { + engagement.setResponse(new Response<>( + 200, + true, + null, + cached.put("isCachedResponse", true), + null)); + + Log.d(TAG, "Using cached response " + engagement.getJson()); + + mainThreadTaskHandler.post(() -> listener.onCompleted(engagement)); + } catch (JSONException e) { + mainThreadTaskHandler.post(() -> listener.onError(e)); + } + } else { + mainThreadTaskHandler.post(() -> listener.onError(t)); } - } else { - listener.onError(t); - } + }); } }, "config".equalsIgnoreCase(engagement.name) && "internal".equalsIgnoreCase(engagement.flavour)); return null;