Skip to content

Commit

Permalink
Apptentive Android SDK 5.4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
weeeBox committed Jun 17, 2019
1 parent 129e174 commit 9149359
Show file tree
Hide file tree
Showing 16 changed files with 280 additions and 185 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 2019-06-17 - v5.4.3

#### Improvements

* Made Android ID collection optional on pre-Oreo targets.
* Fixed "Who" card in the Message Center.

# 2019-05-14 - v5.4.2

#### 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.4.2|aar)
##### Binary releases are hosted for Maven [here](http://search.maven.org/#artifactdetails|com.apptentive|apptentive-android|5.4.3|aar)

#### Reporting Bugs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class ApptentiveConfiguration {
private boolean shouldSanitizeLogMessages;
private boolean troubleshootingModeEnabled;
private Encryption encryption;
private boolean shouldCollectAndroidIdOnPreOreoTargets;

public ApptentiveConfiguration(@NonNull String apptentiveKey, @NonNull String apptentiveSignature) {
if (StringUtils.isNullOrEmpty(apptentiveKey)) {
Expand All @@ -36,6 +37,7 @@ public ApptentiveConfiguration(@NonNull String apptentiveKey, @NonNull String ap
this.shouldEncryptStorage = false;
this.shouldSanitizeLogMessages = true;
this.troubleshootingModeEnabled = true;
this.shouldCollectAndroidIdOnPreOreoTargets = true;
}

public String getApptentiveKey() {
Expand Down Expand Up @@ -122,4 +124,19 @@ public ApptentiveConfiguration setTroubleshootingModeEnabled(boolean troubleshoo
this.troubleshootingModeEnabled = troubleshootingModeEnabled;
return this;
}

/**
* Overrides if the SDK should collect Android ID on pre Android-O targets. If set to <code>false</code>
* a random value would be generated on the initial SDK launch and provided on each subsequent launch.
*/
public void setShouldCollectAndroidIdOnPreOreoTargets(boolean shouldCollectAndroidIdOnPreOreoTargets) {
this.shouldCollectAndroidIdOnPreOreoTargets = shouldCollectAndroidIdOnPreOreoTargets;
}

/**
* Indicates if the SDK should collect Android ID on pre Android-O targets.
*/
public boolean shouldCollectAndroidIdOnPreOreoTargets() {
return shouldCollectAndroidIdOnPreOreoTargets;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import com.apptentive.android.sdk.module.engagement.interaction.InteractionManager;
import com.apptentive.android.sdk.module.engagement.interaction.model.MessageCenterInteraction;
import com.apptentive.android.sdk.module.messagecenter.MessageManager;
import com.apptentive.android.sdk.module.metric.MetricModule;
import com.apptentive.android.sdk.module.rating.IRatingProvider;
import com.apptentive.android.sdk.module.rating.impl.GooglePlayRatingProvider;
import com.apptentive.android.sdk.module.survey.OnSurveyFinishedListener;
Expand Down Expand Up @@ -153,7 +152,7 @@ public ApptentiveInternal(Context appContext) {
appRelease = null;
}

private ApptentiveInternal(Application application, ApptentiveConfiguration configuration) {
private ApptentiveInternal(Application application, ApptentiveConfiguration configuration, @NonNull String androidID) {
if (configuration == null) {
throw new IllegalArgumentException("Configuration is null");
}
Expand All @@ -174,7 +173,8 @@ private ApptentiveInternal(Application application, ApptentiveConfiguration conf
globalSharedPrefs = application.getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE);
apptentiveHttpClient = new ApptentiveHttpClient(apptentiveKey, apptentiveSignature, getEndpointBase(globalSharedPrefs));

conversationManager = new ConversationManager(appContext, Util.getInternalDir(appContext, CONVERSATIONS_DIR, true), encryption);
DeviceManager deviceManager = new DeviceManager(androidID);
conversationManager = new ConversationManager(appContext, Util.getInternalDir(appContext, CONVERSATIONS_DIR, true), encryption, deviceManager);

appRelease = AppReleaseManager.generateCurrentAppRelease(application, this);
taskManager = new ApptentiveTaskManager(appContext, apptentiveHttpClient, encryption);
Expand Down Expand Up @@ -232,17 +232,20 @@ static void createInstance(@NonNull Application application, @NonNull Apptentive

synchronized (ApptentiveInternal.class) {
if (sApptentiveInternal == null) {
ApptentiveLog.i("Registering Apptentive Android SDK %s", Constants.getApptentiveSdkVersion());
ApptentiveLog.v("ApptentiveKey=%s ApptentiveSignature=%s", apptentiveKey, apptentiveSignature);
sApptentiveInternal = new ApptentiveInternal(application, configuration);
dispatchOnConversationQueue(new DispatchTask() {
@Override
protected void execute() {
sApptentiveInternal.start();
}
});
ApptentiveLog.i("Registering Apptentive Android SDK %s", Constants.getApptentiveSdkVersion());
ApptentiveLog.v("ApptentiveKey=%s ApptentiveSignature=%s", apptentiveKey, apptentiveSignature);
// resolve Android ID
boolean shouldGenerateRandomAndroidID = Build.VERSION.SDK_INT < Build.VERSION_CODES.O && !configuration.shouldCollectAndroidIdOnPreOreoTargets();
String androidID = resolveAndroidID(application.getApplicationContext(), shouldGenerateRandomAndroidID);
sApptentiveInternal = new ApptentiveInternal(application, configuration, androidID);
dispatchOnConversationQueue(new DispatchTask() {
@Override
protected void execute() {
sApptentiveInternal.start();
}
});

ApptentiveActivityLifecycleCallbacks.register(application);
ApptentiveActivityLifecycleCallbacks.register(application);
} else {
ApptentiveLog.w("Apptentive instance is already initialized");
}
Expand Down Expand Up @@ -1191,4 +1194,36 @@ private static void logException(Exception e) {
}

//endregion

//region Android ID

private static final String PREFS_NAME_ANDROID_ID = "com.apptentive.sdk.androidID";
private static final String PREFS_KEY_NAME_ANDROID_ID = "androidID";

private static String resolveAndroidID(Context context, boolean shouldGenerateRandomAndroidID) {
if (shouldGenerateRandomAndroidID) {
String existingAndroidID = loadAndroidID(context);
if (existingAndroidID != null) {
return existingAndroidID;
}

String androidID = StringUtils.randomAndroidID();
saveAndroidID(context, androidID);
return androidID;
}

return Util.getAndroidID(context);
}

private static String loadAndroidID(Context context) {
SharedPreferences sharedPreferences = context.getSharedPreferences(PREFS_NAME_ANDROID_ID, Context.MODE_PRIVATE);
return sharedPreferences.getString(PREFS_KEY_NAME_ANDROID_ID, null);
}

private static void saveAndroidID(Context context, String androidID) {
SharedPreferences sharedPreferences = context.getSharedPreferences(PREFS_NAME_ANDROID_ID, Context.MODE_PRIVATE);
sharedPreferences.edit().putString(PREFS_KEY_NAME_ANDROID_ID, androidID).apply();
}

//endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import com.apptentive.android.sdk.storage.AppRelease;
import com.apptentive.android.sdk.storage.AppReleaseManager;
import com.apptentive.android.sdk.storage.Device;
import com.apptentive.android.sdk.storage.DeviceManager;
import com.apptentive.android.sdk.storage.DevicePayloadDiff;
import com.apptentive.android.sdk.storage.PayloadRequestSender;
import com.apptentive.android.sdk.storage.Sdk;
import com.apptentive.android.sdk.storage.SdkManager;
Expand Down Expand Up @@ -168,7 +168,7 @@ public HttpJsonRequest createFirstLoginRequest(String token, AppRelease appRelea

ConversationTokenRequest conversationTokenRequest = new ConversationTokenRequest();
conversationTokenRequest.setSdkAndAppRelease(SdkManager.getPayload(sdk), AppReleaseManager.getPayload(appRelease));
conversationTokenRequest.setDevice(DeviceManager.getDiffPayload(null, device));
conversationTokenRequest.setDevice(DevicePayloadDiff.getDiffPayload(null, device));

try {
conversationTokenRequest.put("token", token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import com.apptentive.android.sdk.storage.DataChangedListener;
import com.apptentive.android.sdk.storage.Device;
import com.apptentive.android.sdk.storage.DeviceDataChangedListener;
import com.apptentive.android.sdk.storage.DeviceManager;
import com.apptentive.android.sdk.storage.DevicePayloadDiff;
import com.apptentive.android.sdk.storage.EncryptedFileSerializer;
import com.apptentive.android.sdk.storage.EventData;
import com.apptentive.android.sdk.storage.FileSerializer;
Expand Down Expand Up @@ -507,7 +507,7 @@ protected void execute() {
Device lastSentDevice = getLastSentDevice();
Device currentDevice = getDevice();
assertNotNull(currentDevice, "Current device object is null");
DevicePayload devicePayload = DeviceManager.getDiffPayload(lastSentDevice, currentDevice);
DevicePayload devicePayload = DevicePayloadDiff.getDiffPayload(lastSentDevice, currentDevice);
if (devicePayload != null) {
addPayload(devicePayload);
setLastSentDevice(currentDevice != null ? currentDevice.clone() : null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.apptentive.android.sdk.storage.AppReleaseManager;
import com.apptentive.android.sdk.storage.Device;
import com.apptentive.android.sdk.storage.DeviceManager;
import com.apptentive.android.sdk.storage.DevicePayloadDiff;
import com.apptentive.android.sdk.storage.Sdk;
import com.apptentive.android.sdk.storage.SdkManager;
import com.apptentive.android.sdk.storage.SerializerException;
Expand Down Expand Up @@ -89,6 +90,11 @@ public class ConversationManager {
*/
private final Encryption encryption;

/**
* Responsible for generating device payloads.
*/
private final DeviceManager deviceManager;

/**
* Current state of conversation metadata.
*/
Expand All @@ -103,7 +109,7 @@ public class ConversationManager {
*/
private boolean activeConversationFailedToResolve; // TODO: this is a temporary solution until we restore conversation state

public ConversationManager(@NonNull Context context, @NonNull File conversationsStorageDir, @NonNull Encryption encryption) {
public ConversationManager(@NonNull Context context, @NonNull File conversationsStorageDir, @NonNull Encryption encryption, @NonNull DeviceManager deviceManager) {
if (context == null) {
throw new IllegalArgumentException("Context is null");
}
Expand All @@ -116,9 +122,14 @@ public ConversationManager(@NonNull Context context, @NonNull File conversations
throw new IllegalArgumentException("Encryption is null");
}

if (deviceManager == null) {
throw new IllegalArgumentException("Device manager is null");
}

this.contextRef = new WeakReference<>(context.getApplicationContext());
this.conversationsStorageDir = conversationsStorageDir;
this.encryption = encryption;
this.deviceManager = deviceManager;

ApptentiveNotificationCenter.defaultCenter()
.addObserver(NOTIFICATION_APP_ENTERED_FOREGROUND, new ApptentiveNotificationObserver() {
Expand Down Expand Up @@ -464,11 +475,11 @@ private HttpRequest fetchConversationToken(final Conversation conversation) {
ConversationTokenRequest conversationTokenRequest = new ConversationTokenRequest();

// Send the Device and Sdk now, so they are available on the server from the start.
final Device device = DeviceManager.generateNewDevice(context);
final Device device = deviceManager.generateNewDevice(context);
final Sdk sdk = SdkManager.generateCurrentSdk(context);
final AppRelease appRelease = ApptentiveInternal.getInstance().getAppRelease();

conversationTokenRequest.setDevice(DeviceManager.getDiffPayload(null, device));
conversationTokenRequest.setDevice(DevicePayloadDiff.getDiffPayload(null, device));
conversationTokenRequest.setSdkAndAppRelease(SdkManager.getPayload(sdk), AppReleaseManager.getPayload(appRelease));

HttpRequest request = getHttpClient()
Expand Down Expand Up @@ -957,7 +968,7 @@ public boolean accept(ConversationMetadataItem item) {
setActiveConversation(new Conversation(dataFile, messagesFile, conversationEncryption, payloadEncryptionKey));

// TODO: if we don't set these here - device payload would return 4xx error code
activeConversation.setDevice(DeviceManager.generateNewDevice(getContext()));
activeConversation.setDevice(deviceManager.generateNewDevice(getContext()));
activeConversation.setAppRelease(ApptentiveInternal.getInstance().getAppRelease());
activeConversation.setSdk(SdkManager.generateCurrentSdk(getContext()));
}
Expand Down Expand Up @@ -998,7 +1009,7 @@ private void sendFirstLoginRequest(final String userId, final String token, fina

final AppRelease appRelease = ApptentiveInternal.getInstance().getAppRelease();
final Sdk sdk = SdkManager.generateCurrentSdk(getContext());
final Device device = DeviceManager.generateNewDevice(getContext());
final Device device = deviceManager.generateNewDevice(getContext());

HttpJsonRequest request = getHttpClient().createFirstLoginRequest(token, appRelease, sdk, device, new HttpRequest.Listener<HttpJsonRequest>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ public void onCloseWhoCard(String buttonLabel) {
}

private boolean shouldOpenComposerAfterClosingWhoCard() {
return interaction.getWhoCard().isRequire() && (recyclerViewContainsItemOfType(MESSAGE_CONTEXT) || recyclerViewContainsItemOfType(MESSAGE_OUTGOING));
return interaction.getWhoCard().isRequire() && !recyclerViewContainsItemOfType(MESSAGE_OUTGOING);
}

public void cleanupWhoCard() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ public String getTitle() {
}

public String getNameHint() {
if (isRequire() && isInitial()) {
// The Who Card will show up right when MC is opened in this scenario. Don't ask for the name at this time.
return null;
}
return getApplicableConfig().optString(KEY_NAME_HINT, null);
}

Expand Down
Loading

0 comments on commit 9149359

Please sign in to comment.