Skip to content

Commit

Permalink
Merge pull request #172 from apptentive/branch_5.3.2
Browse files Browse the repository at this point in the history
Release 5.3.2
  • Loading branch information
weeeBox authored Oct 25, 2018
2 parents 9b5d6e7 + 1a6f88d commit fc76707
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 8 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 2018-08-30 - v5.3.2

#### Fixes

* Fixed encrypted message store for logged-in users.
* Fixed the bug which prevented users from logging-in back after a logout.

# 2018-08-30 - v5.3.1

#### Fixes
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use your app, to talk to them at the right time, and in the right way.

##### [Release Notes](https://learn.apptentive.com/knowledge-base/android-sdk-release-notes/)

##### Binary releases are hosted for Maven [here](http://search.maven.org/#artifactdetails|com.apptentive|apptentive-android|5.3.1|aar)
##### Binary releases are hosted for Maven [here](http://search.maven.org/#artifactdetails|com.apptentive|apptentive-android|5.3.2|aar)

#### Reporting Bugs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ public class Conversation implements DataChangedListener, Destroyable, DeviceDat

private final MessageManager messageManager;

// we keep a reference to the message store in order to update encryption key (not the best solution but works for now)
private final FileMessageStore messageStore;

// we keep references to the tasks in order to dispatch them only once
private final DispatchTask saveConversationTask = new DispatchTask() {
@Override
Expand Down Expand Up @@ -140,7 +143,7 @@ public Conversation(File conversationDataFile, File conversationMessagesFile, @N

conversationData = new ConversationData();

FileMessageStore messageStore = new FileMessageStore(conversationMessagesFile, encryptionKey);
messageStore = new FileMessageStore(conversationMessagesFile, encryptionKey);
messageStore.migrateLegacyStorage();
messageManager = new MessageManager(this, messageStore); // it's important to initialize message manager in a constructor since other SDK parts depend on it via Apptentive singleton
}
Expand Down Expand Up @@ -691,6 +694,9 @@ public synchronized File getConversationMessagesFile() {

public void setEncryptionKey(@NonNull EncryptionKey encryptionKey) {
this.encryptionKey = encryptionKey;

// we need to update the old message store encryption key and overwrite current data file
messageStore.updateEncryptionKey(encryptionKey);
}

public @NonNull EncryptionKey getEncryptionKey() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ public class ConversationManager {
private Conversation activeConversation;
private ConversationProxy activeConversationProxy;

// TODO: this is a temporary solution until we restore conversation state
private boolean activeConversationLoaded;
/**
* Indicate a failure in resolving active conversation (there was an exception while loading
* metadata or conversation). Used to disable conversation-related SDK functionality (like login)
*/
private boolean activeConversationFailedToResolve; // TODO: this is a temporary solution until we restore conversation state

public ConversationManager(@NonNull Context context, @NonNull File conversationsStorageDir, @NonNull EncryptionKey encryptionKey) {
if (context == null) {
Expand Down Expand Up @@ -176,14 +179,14 @@ public boolean loadActiveConversation(Context context) {

activeConversation.startListeningForChanges();
activeConversation.scheduleSaveConversationData();
activeConversationLoaded = true;

handleConversationStateChange(activeConversation);
return true;
}

} catch (Exception e) {
ApptentiveLog.e(CONVERSATION, e, "Exception while loading active conversation");
activeConversationFailedToResolve = true;
}

ApptentiveNotificationCenter.defaultCenter()
Expand Down Expand Up @@ -791,7 +794,7 @@ private void requestLoggedInConversation(final String token, final LoginCallback
}

// Check if we have metadata
if (!activeConversationLoaded) {
if (activeConversationFailedToResolve) {
ApptentiveLog.e(CONVERSATION, "Unable to login: active conversation was not loaded");
callback.onLoginFail("Unable to login: active conversation was not loaded");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

package com.apptentive.android.sdk.conversation;

import android.support.annotation.NonNull;

import com.apptentive.android.sdk.ApptentiveLog;
import com.apptentive.android.sdk.debug.Assert;
import com.apptentive.android.sdk.encryption.EncryptionException;
Expand Down Expand Up @@ -54,7 +56,7 @@ class FileMessageStore implements MessageStore {

private final File file;
private final List<MessageEntry> messageEntries;
private final EncryptionKey encryptionKey;
private EncryptionKey encryptionKey;
private boolean shouldFetchFromFile;

FileMessageStore(File file, EncryptionKey encryptionKey) {
Expand Down Expand Up @@ -271,7 +273,9 @@ private void writeToFileGuarded() throws IOException,
for (MessageEntry entry : messageEntries) {
entry.writeExternal(dos);
}
long start = System.currentTimeMillis();
Encryptor.writeToEncryptedFile(encryptionKey, file, bos.toByteArray());
ApptentiveLog.v(MESSAGES, "Messages saved. Took %d ms", System.currentTimeMillis() - start);
}

//endregion
Expand All @@ -292,6 +296,16 @@ private MessageEntry findMessageEntry(String nonce) {
return null;
}

void updateEncryptionKey(@NonNull EncryptionKey encryptionKey) {
if (encryptionKey == null) {
throw new IllegalArgumentException("Encryption key is null");
}
this.encryptionKey = encryptionKey;

// update storage
writeToFile();
}

//endregion

//region Message Entry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class Constants {

public static final int API_VERSION = 9;
private static final String APPTENTIVE_SDK_VERSION = "5.3.1";
private static final String APPTENTIVE_SDK_VERSION = "5.3.2";

public static final int DEFAULT_CONNECT_TIMEOUT_MILLIS = 45000;
public static final int DEFAULT_READ_TIMEOUT_MILLIS = 45000;
Expand Down

0 comments on commit fc76707

Please sign in to comment.