Skip to content

Commit

Permalink
Merge pull request #227 from apptentive/branch_5.6.4
Browse files Browse the repository at this point in the history
Release 5.6.4
  • Loading branch information
twinklesharma1311 authored Jul 27, 2021
2 parents 7a4c0d8 + 74a7b25 commit 6e499b5
Show file tree
Hide file tree
Showing 16 changed files with 275 additions and 21 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @frankus @twinklesharma1311
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
# 2021-07-27 - v5.6.4

#### Fixes

* Prevent Clipboard Notifications for Release builds in Android 12.

#### Improvements

* Replace JCenter with Maven Central.

# 2021-07-07 - v5.6.3

#### Fixes

* Fixes a race condition where information about the SDK and app was failing to be recorded.
* Fixes a race condition where information about the SDK and app was failing to be recorded.

# 2021-01-28 - v5.6.2

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

#### Reporting Bugs

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.apptentive.android.sdk.module.engagement.logic;

import android.content.Context;

import androidx.test.platform.app.InstrumentationRegistry;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;

public class DefaultRandomPercentProviderTest {
// private final Context context = InstrumentationRegistry.getInstrumentation().getContext();
//
// @Before
// public void before() {
// DefaultRandomPercentProvider.clear(context);
// }
//
// @Test
// public void testRandomPercent() {
// final RandomPercentProvider provider = new DefaultRandomPercentProvider(context, "id");
// final double percent1 = provider.getPercent("key");
// final double percent2 = provider.getPercent("key");
// assertEquals(percent1, percent2, 0.0000001f);
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.apptentive.android.sdk.module.engagement.logic;

import android.content.Context;

import androidx.test.platform.app.InstrumentationRegistry;

import com.apptentive.android.sdk.storage.AppRelease;
import com.apptentive.android.sdk.storage.Device;
import com.apptentive.android.sdk.storage.EventData;
import com.apptentive.android.sdk.storage.Person;
import com.apptentive.android.sdk.storage.VersionHistory;

import org.junit.Test;

import java.math.BigDecimal;

import static org.junit.Assert.assertEquals;

public class FieldManagerTest {
// private final Context context = InstrumentationRegistry.getInstrumentation().getContext();
//
// @Test
// public void testRandomPercentWithKey() {
// final FieldManager fieldManager = createFieldManager(50);
// final Comparable expected = new BigDecimal(50);
// final Comparable actual = fieldManager.getValue("random/abc123xyz/percent");
// assertEquals(expected, actual);
// }
//
// @Test
// public void testRandomPercentWithoutKey() {
// final FieldManager fieldManager = createFieldManager(50);
// final Comparable expected = new BigDecimal(50);
// final Comparable actual = fieldManager.getValue("random/percent");
// assertEquals(expected, actual);
// }
//
// @Test
// public void testRandomPercentWithKeyDescription() {
// final FieldManager fieldManager = createFieldManager(50);
// final String expected = "random percent for key 'abc123xyz'";
// final String actual = fieldManager.getDescription("random/abc123xyz/percent");
// assertEquals(expected, actual);
// }
//
// @Test
// public void testRandomPercentWithoutKeyDescription() {
// final FieldManager fieldManager = createFieldManager(50);
// final String expected = "random percent";
// final String actual = fieldManager.getDescription("random/percent");
// assertEquals(expected, actual);
// }
//
// private FieldManager createFieldManager(double percent) {
// return new FieldManager(context, new VersionHistory(), new EventData(), new Person(), new Device(), new AppRelease(), new MockRandomPercentProvider(percent));
// }
//
// private static class MockRandomPercentProvider implements RandomPercentProvider {
// private final double percent;
//
// private MockRandomPercentProvider(double percent) {
// this.percent = percent;
// }
//
// @Override
// public double getPercent(String key) {
// return percent;
// }
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -202,5 +202,9 @@ public String getConversationToken() {
return conversation.getConversationToken();
}

//endregion
// public String getLocalIdentifier() {
// return conversation.getLocalIdentifier();
// }

//endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ private static void startSessionGuarded(final Context context, String appKey, St
return;
}

// don't try to read the the pasteboard if the system forbids it
if (!Util.canAccessClipboard(context)) {
ApptentiveLog.w(TROUBLESHOOT, "Unable to access device pasteboard");
return;
}

// attempt to create a new session based on the clipboard content
final String accessToken = readAccessTokenFromClipboard(context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
import com.apptentive.android.sdk.module.engagement.interaction.model.common.Action;
import com.apptentive.android.sdk.module.engagement.interaction.model.common.Actions;
import com.apptentive.android.sdk.module.engagement.interaction.model.common.LaunchInteractionAction;
import com.apptentive.android.sdk.module.engagement.logic.DefaultRandomPercentProvider;
import com.apptentive.android.sdk.module.engagement.logic.FieldManager;
import com.apptentive.android.sdk.module.engagement.logic.RandomPercentProvider;

import org.json.JSONException;
import org.json.JSONObject;
Expand Down Expand Up @@ -127,8 +129,9 @@ public void onClick(View view) {
LaunchInteractionAction launchInteractionButton = (LaunchInteractionAction) buttonAction;
List<Invocation> invocations = launchInteractionButton.getInvocations();
String interactionIdToLaunch = null;
//final RandomPercentProvider percentProvider = new DefaultRandomPercentProvider(getContext(), getConversation().getLocalIdentifier());
for (Invocation invocation : invocations) {
FieldManager fieldManager = new FieldManager(getContext(), getConversation().getVersionHistory(), getConversation().getEventData(), getConversation().getPerson(), getConversation().getDevice(), getConversation().getAppRelease());
FieldManager fieldManager = new FieldManager(getContext(), getConversation().getVersionHistory(), getConversation().getEventData(), getConversation().getPerson(), getConversation().getDevice(), getConversation().getAppRelease()/*,percentProvider*/);
if (invocation.isCriteriaMet(fieldManager, false)) { // TODO: should we print details here as well?
interactionIdToLaunch = invocation.getInteractionId();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@

package com.apptentive.android.sdk.module.engagement.interaction.model;

import android.content.Context;

import com.apptentive.android.sdk.ApptentiveInternal;
import com.apptentive.android.sdk.ApptentiveLog;
import com.apptentive.android.sdk.conversation.Conversation;
import com.apptentive.android.sdk.module.engagement.logic.DefaultRandomPercentProvider;
import com.apptentive.android.sdk.module.engagement.logic.FieldManager;
import com.apptentive.android.sdk.module.engagement.logic.RandomPercentProvider;

import org.json.JSONArray;
import org.json.JSONException;
Expand Down Expand Up @@ -38,7 +42,9 @@ public String getApplicableInteraction(String eventLabel, boolean verbose) {
try {
Invocation invocation = new Invocation(invocationObject.toString());
Conversation conversation = ApptentiveInternal.getInstance().getConversation();
FieldManager fieldManager = new FieldManager(ApptentiveInternal.getInstance().getApplicationContext(), conversation.getVersionHistory(), conversation.getEventData(), conversation.getPerson(), conversation.getDevice(), conversation.getAppRelease());
final Context context = ApptentiveInternal.getInstance().getApplicationContext();
//final RandomPercentProvider percentProvider = new DefaultRandomPercentProvider(context, conversation.getLocalIdentifier());
FieldManager fieldManager = new FieldManager(context, conversation.getVersionHistory(), conversation.getEventData(), conversation.getPerson(), conversation.getDevice(), conversation.getAppRelease()/*,percentProvider*/);

if (invocation.isCriteriaMet(fieldManager, verbose)) {
return invocation.getInteractionId();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.apptentive.android.sdk.module.engagement.logic;

import android.content.Context;
import android.content.SharedPreferences;

import androidx.annotation.VisibleForTesting;

import com.apptentive.android.sdk.util.ApplicationInfo;
import com.apptentive.android.sdk.util.RuntimeUtils;

import java.util.Random;

/**
* A concrete implementation of [RandomPercentProvider] which only generates a random percent for a
* give key once and stores it in shared preferences.
*/
public class DefaultRandomPercentProvider implements RandomPercentProvider {
// private final Context context;
// private final String id;
//
// /**
// * @param id - unique key for making a distinction between same keys used in different conversations.
// */
// public DefaultRandomPercentProvider(Context context, String id) {
// if (context == null) {
// throw new IllegalArgumentException("Context is null");
// }
// if (id == null) {
// throw new IllegalArgumentException("Id is null");
// }
// this.context = context.getApplicationContext();
// this.id = id;
// }
//
// @Override
// public double getPercent(String key) {
// final SharedPreferences prefs = getPrefs(context);
// if (key == null) {
// return getRandomPercent();
// } else {
// final String prefsKey = id + "_" + key;
// if (prefs.contains(prefsKey)) {
// return prefs.getFloat(prefsKey, 0.0f);
// }
// final float percent = getRandomPercent();
// prefs.edit().putFloat(prefsKey, percent).apply();
// return percent;
// }
// }
//
// private float getRandomPercent() {
// ApplicationInfo applicationInfo = RuntimeUtils.getApplicationInfo(context);
//
// if (applicationInfo.isDebuggable()) {
// return (float) 50;
// } else {
// return new Random().nextFloat() * 100;
// }
// }
//
// private static SharedPreferences getPrefs(Context context) {
// return context.getSharedPreferences("com.apptentive.RandomPercentProvider", Context.MODE_PRIVATE);
// }
//
// @VisibleForTesting
// public static void clear(Context context) {
// getPrefs(context).edit().clear().apply();
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import com.apptentive.android.sdk.Apptentive;
import com.apptentive.android.sdk.ApptentiveLog;
import com.apptentive.android.sdk.ApptentiveLogTag;
import com.apptentive.android.sdk.debug.Assert;
import com.apptentive.android.sdk.storage.AppRelease;
import com.apptentive.android.sdk.storage.CustomData;
Expand All @@ -29,26 +28,28 @@
import static com.apptentive.android.sdk.debug.ErrorMetrics.logException;

public class FieldManager {

Context context;
VersionHistory versionHistory;
EventData eventData;
Person person;
Device device;
AppRelease appRelease;
//private final RandomPercentProvider randomPercentProvider;

public FieldManager(Context context, VersionHistory versionHistory, EventData eventData, Person person, Device device, AppRelease appRelease) {
public FieldManager(Context context, VersionHistory versionHistory, EventData eventData, Person person, Device device, AppRelease appRelease/*,RandomPercentProvider randomPercentProvider*/) {
Assert.notNull(context);
Assert.notNull(versionHistory);
Assert.notNull(eventData);
Assert.notNull(person);
Assert.notNull(device);
//Assert.notNull(randomPercentProvider);
this.context = context;
this.versionHistory = versionHistory;
this.eventData = eventData;
this.person = person;
this.device = device;
this.appRelease = appRelease;
//this.randomPercentProvider = randomPercentProvider;
}

public boolean exists(String query) {
Expand All @@ -61,7 +62,6 @@ public Comparable getValue(String query) {
}

private Object doGetValue(String query) {

query = query.trim();
String[] tokens = query.split("/");
QueryPart topLevelQuery = QueryPart.parse(tokens[0]);
Expand Down Expand Up @@ -289,6 +289,22 @@ private Object doGetValue(String query) {
return null;
}
}
// case random: {
// if (tokens.length == 3) { // random/<key>/percent
// final String randomNumberKey = tokens[1];
// QueryPart subQuery = QueryPart.valueOf(tokens[2]);
// switch (subQuery) {
// case percent:
// return randomPercentProvider.getPercent(randomNumberKey);
// }
// } else if (tokens.length == 2) { // random/percent
// QueryPart subQuery = QueryPart.valueOf(tokens[1]);
// switch (subQuery) {
// case percent:
// return randomPercentProvider.getPercent(null);
// }
// }
// }
default:
break;
}
Expand Down Expand Up @@ -490,6 +506,22 @@ public String getDescription(String query) {
return null;
}
}
// case random: {
// if (tokens.length == 3) { // random/<key>/percent
// final String randomNumberKey = tokens[1];
// QueryPart subQuery = QueryPart.valueOf(tokens[2]);
// switch (subQuery) {
// case percent:
// return StringUtils.format("random percent for key '%s'", randomNumberKey);
// }
// } else if (tokens.length == 2) { // random/percent
// QueryPart subQuery = QueryPart.valueOf(tokens[1]);
// switch (subQuery) {
// case percent:
// return StringUtils.format("random percent");
// }
// }
// }
default:
break;
}
Expand Down Expand Up @@ -544,6 +576,10 @@ private enum QueryPart {
debug,
build,
time_ago,

// random,
// percent,

other;

public static QueryPart parse(String name) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.apptentive.android.sdk.module.engagement.logic;

/**
* Represents an object which returns a random percent for a give key.
*/
public interface RandomPercentProvider {
// /**
// * Returns a random percent for a give key in range from [0..100]
// */
// double getPercent(String key);
}
Loading

0 comments on commit 6e499b5

Please sign in to comment.