From 2d62ae22cb3cf5e8fd001df7cf30a66f84037934 Mon Sep 17 00:00:00 2001 From: skykelsey Date: Wed, 3 Jan 2018 16:58:30 -0800 Subject: [PATCH] Apptentive Android SDK 4.1.4 --- CHANGELOG.md | 19 ++++++++++++++++++ .../android/sdk/ApptentiveViewActivity.java | 15 ++++++++++---- .../sdk/conversation/ConversationManager.java | 20 +++++++++++++++++-- .../module/messagecenter/MessageManager.java | 11 +++++++--- .../messagecenter/MessagePollingWorker.java | 1 + .../sdk/storage/ApptentiveTaskManager.java | 2 +- .../android/sdk/util/Constants.java | 2 +- 7 files changed, 59 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50b0b85a0..b14021b82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +# 2018-01-03 - v4.1.4 + +#### Bugs Fixed + +* Fix a NullPointerException that occurs when the Apptentive SDK is included in an Instant App, and the host app's Activity is not available when exiting the Apptentive UI. +* Fixed a potential crash when used in Instant Apps that don't contain a launcher Activity. +* Don't send payloads when the app is in the background. +* Don't poll for messages when the app is in the background. + + # 2017-12-02 - v4.1.3 #### Bugs Fixed @@ -29,6 +39,15 @@ * Fix global configuration fetching * Fix Love Dialog to stack buttons if their labels are too long +# 2018-01-03 - v4.0.3 + +#### Bugs Fixed + +* Fixed a potential crash when used in Instant Apps that don't contain a launcher Activity. +* Don't send payloads when the app is in the background. +* Don't poll for messages when the app is in the background. +* Fixed global Configuration polling. + # 2017-08-15 - v4.0.2 #### Bugs Fixed diff --git a/apptentive/src/main/java/com/apptentive/android/sdk/ApptentiveViewActivity.java b/apptentive/src/main/java/com/apptentive/android/sdk/ApptentiveViewActivity.java index 2da94d506..113b6f4af 100644 --- a/apptentive/src/main/java/com/apptentive/android/sdk/ApptentiveViewActivity.java +++ b/apptentive/src/main/java/com/apptentive/android/sdk/ApptentiveViewActivity.java @@ -338,10 +338,17 @@ private void startLauncherActivityIfRoot() { if (isTaskRoot()) { PackageManager packageManager = getPackageManager(); Intent intent = packageManager.getLaunchIntentForPackage(getPackageName()); - ComponentName componentName = intent.getComponent(); - /** Backwards compatible method that will clear all activities in the stack. */ - Intent mainIntent = Intent.makeRestartActivityTask(componentName); - startActivity(mainIntent); + /* + Make this work with Instant Apps. It is possible and even likely to create an Instant App + that doesn't have the Main Activity included in its APK. In such cases, this Intent is null, + and we can't do anything apart from exiting our Activity. + */ + if (intent != null) { + ComponentName componentName = intent.getComponent(); + // Backwards compatible method that will clear all activities in the stack. + Intent mainIntent = Intent.makeRestartActivityTask(componentName); + startActivity(mainIntent); + } } } diff --git a/apptentive/src/main/java/com/apptentive/android/sdk/conversation/ConversationManager.java b/apptentive/src/main/java/com/apptentive/android/sdk/conversation/ConversationManager.java index 8da9dcf29..dd544d61f 100644 --- a/apptentive/src/main/java/com/apptentive/android/sdk/conversation/ConversationManager.java +++ b/apptentive/src/main/java/com/apptentive/android/sdk/conversation/ConversationManager.java @@ -76,6 +76,8 @@ public class ConversationManager { private final WeakReference contextRef; + private boolean appIsInForeground; + /** * A basic directory for storing conversation-related data. */ @@ -101,6 +103,7 @@ public ConversationManager(Context context, File apptentiveConversationsStorageD @Override public void onReceiveNotification(ApptentiveNotification notification) { assertMainThread(); + appIsInForeground = true; if (activeConversation != null && activeConversation.hasActiveState()) { ApptentiveLog.v(CONVERSATION, "App entered foreground notification received. Trying to fetch app configuration and interactions..."); final Context context = getContext(); @@ -113,6 +116,15 @@ public void onReceiveNotification(ApptentiveNotification notification) { } } }); + + ApptentiveNotificationCenter.defaultCenter() + .addObserver(NOTIFICATION_APP_ENTERED_BACKGROUND, new ApptentiveNotificationObserver() { + @Override + public void onReceiveNotification(ApptentiveNotification notification) { + assertMainThread(); + appIsInForeground = false; + } + }); } //region Conversations @@ -456,8 +468,12 @@ private void handleConversationStateChange(Conversation conversation) { ObjectUtils.toMap(NOTIFICATION_KEY_CONVERSATION, conversation)); if (conversation.hasActiveState()) { - conversation.fetchInteractions(getContext()); - conversation.getMessageManager().startPollingMessages(); + if (appIsInForeground) { + // ConversationManager listens to the foreground event to fetch interactions when it comes to foreground + conversation.fetchInteractions(getContext()); + // Message Manager listens to foreground/background events itself + conversation.getMessageManager().attemptToStartMessagePolling(); + } // Fetch app configuration fetchAppConfiguration(conversation); diff --git a/apptentive/src/main/java/com/apptentive/android/sdk/module/messagecenter/MessageManager.java b/apptentive/src/main/java/com/apptentive/android/sdk/module/messagecenter/MessageManager.java index 9342e125c..62545fd05 100644 --- a/apptentive/src/main/java/com/apptentive/android/sdk/module/messagecenter/MessageManager.java +++ b/apptentive/src/main/java/com/apptentive/android/sdk/module/messagecenter/MessageManager.java @@ -425,8 +425,10 @@ public void destroy() { //region Polling - public void startPollingMessages() { - pollingWorker.startPolling(); + public void attemptToStartMessagePolling() { + if (conversation.isMessageCenterFeatureUsed()) { + pollingWorker.startPolling(); + } } public void stopPollingMessages() { @@ -536,6 +538,7 @@ private void setCurrentForegroundActivity(Activity activity) { } public void setMessageCenterInForeground(boolean bInForeground) { + conversation.setMessageCenterFeatureUsed(true); pollingWorker.setMessageCenterInForeground(bInForeground); } @@ -572,7 +575,9 @@ protected void execute() { private void appWentToForeground() { appInForeground.set(true); - pollingWorker.appWentToForeground(); + if (conversation.isMessageCenterFeatureUsed()) { + pollingWorker.appWentToForeground(); + } } private void appWentToBackground() { diff --git a/apptentive/src/main/java/com/apptentive/android/sdk/module/messagecenter/MessagePollingWorker.java b/apptentive/src/main/java/com/apptentive/android/sdk/module/messagecenter/MessagePollingWorker.java index 910de485f..95121ae74 100644 --- a/apptentive/src/main/java/com/apptentive/android/sdk/module/messagecenter/MessagePollingWorker.java +++ b/apptentive/src/main/java/com/apptentive/android/sdk/module/messagecenter/MessagePollingWorker.java @@ -41,6 +41,7 @@ class MessagePollingWorker implements Destroyable { conf = Configuration.load(); backgroundPollingInterval = conf.getMessageCenterBgPoll() * 1000; foregroundPollingInterval = conf.getMessageCenterFgPoll() * 1000; + ApptentiveLog.vv("Message Polling Worker: bg=%d, fg=%d", backgroundPollingInterval, foregroundPollingInterval); } @Override diff --git a/apptentive/src/main/java/com/apptentive/android/sdk/storage/ApptentiveTaskManager.java b/apptentive/src/main/java/com/apptentive/android/sdk/storage/ApptentiveTaskManager.java index 705c5d6b5..858bfbb2a 100644 --- a/apptentive/src/main/java/com/apptentive/android/sdk/storage/ApptentiveTaskManager.java +++ b/apptentive/src/main/java/com/apptentive/android/sdk/storage/ApptentiveTaskManager.java @@ -55,7 +55,7 @@ public class ApptentiveTaskManager implements PayloadStore, EventStore, Apptenti private final ThreadPoolExecutor singleThreadExecutor; // TODO: replace with a private concurrent dispatch queue private final PayloadSender payloadSender; - private boolean appInBackground; + private boolean appInBackground = true; /* * Creates an asynchronous task manager with one worker thread. This constructor must be invoked on the UI thread. diff --git a/apptentive/src/main/java/com/apptentive/android/sdk/util/Constants.java b/apptentive/src/main/java/com/apptentive/android/sdk/util/Constants.java index 06270248d..d4aa347ef 100644 --- a/apptentive/src/main/java/com/apptentive/android/sdk/util/Constants.java +++ b/apptentive/src/main/java/com/apptentive/android/sdk/util/Constants.java @@ -9,7 +9,7 @@ public class Constants { public static final int API_VERSION = 9; - public static final String APPTENTIVE_SDK_VERSION = "4.1.3"; + public static final String APPTENTIVE_SDK_VERSION = "4.1.4"; public static final int DEFAULT_CONNECT_TIMEOUT_MILLIS = 45000; public static final int DEFAULT_READ_TIMEOUT_MILLIS = 45000;