Skip to content

Commit

Permalink
Merge branch 'Iterable:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
devcsomnicg authored Jun 2, 2023
2 parents d0cbe30 + 62ac73e commit 47ca7c1
Show file tree
Hide file tree
Showing 11 changed files with 214 additions and 30 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/jira.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
on:
issues:
types: [opened]

name: Create Jira Issue

jobs:
build:
runs-on: ubuntu-latest
name: Create Jira Issue
steps:
- name: Login
uses: atlassian/gajira-login@v3
env:
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
JIRA_USER_EMAIL: ${{ secrets.JIRA_ILYA_USER_EMAIL }}
JIRA_API_TOKEN: ${{ secrets.JIRA_ILYA_API_TOKEN }}

- name: Create
id: create
uses: atlassian/gajira-create@v3
with:
project: MOB
issuetype: Bug
summary: "${{ github.repository }}: #${{ github.event.issue.number }} by ${{ github.event.issue.user.login }}: ${{ github.event.issue.title }}"
description: ${{ github.event.issue.body }}
fields: '{"customfield_11268": {"id": "10668"} }'
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'jacoco'

repositories {
mavenCentral()
}

android {
compileSdkVersion 29
buildToolsVersion '29.0.3'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.iterable.iterableapi.util.DeviceInfoUtils;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Iterator;
Expand Down Expand Up @@ -57,10 +58,8 @@ public void onActivityStarted(Activity activity) {
@Override
public void onActivityResumed(Activity activity) {
currentActivity = new WeakReference<>(activity);
String amazonFireTvHardware = "amazon.hardware.fire_tv";
String amazonModel = Build.MODEL;

if (!inForeground || amazonModel.matches("AFTN") || activity.getPackageManager().hasSystemFeature(amazonFireTvHardware)) {
if (!inForeground || DeviceInfoUtils.isFireTV(activity.getPackageManager())) {
inForeground = true;
for (WeakReference<AppStateCallback> callback : callbacks) {
if (callback.get() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import androidx.annotation.RestrictTo;
import androidx.annotation.VisibleForTesting;

import com.iterable.iterableapi.util.DeviceInfoUtils;

import org.json.JSONException;
import org.json.JSONObject;

Expand Down Expand Up @@ -38,6 +40,8 @@ public class IterableApi {
private IterableNotificationData _notificationData;
private String _deviceId;
private boolean _firstForegroundHandled;
private IterableHelper.SuccessHandler _setUserSuccessCallbackHandler;
private IterableHelper.FailureHandler _setUserFailureCallbackHandler;

IterableApiClient apiClient = new IterableApiClient(new IterableApiAuthProvider());
private @Nullable IterableInAppManager inAppManager;
Expand Down Expand Up @@ -276,6 +280,8 @@ private void completeUserLogin() {

if (config.autoPushRegistration) {
registerForPush();
} else if (_setUserSuccessCallbackHandler != null) {
_setUserSuccessCallbackHandler.onSuccess(new JSONObject()); // passing blank json object here as onSuccess is @Nonnull
}

getInAppManager().syncInApp();
Expand Down Expand Up @@ -469,7 +475,7 @@ protected void registerDeviceToken(@Nullable String email, @Nullable String user
IterableLogger.e(TAG, "registerDeviceToken: applicationName is null, check that pushIntegrationName is set in IterableConfig");
}

apiClient.registerDeviceToken(email, userId, authToken, applicationName, deviceToken, dataFields, deviceAttributes);
apiClient.registerDeviceToken(email, userId, authToken, applicationName, deviceToken, dataFields, deviceAttributes, _setUserSuccessCallbackHandler, _setUserFailureCallbackHandler);
}
//endregion

Expand Down Expand Up @@ -499,12 +505,26 @@ public static void initialize(@NonNull Context context, @NonNull String apiKey,
IterableActivityMonitor.getInstance().addCallback(sharedInstance.activityMonitorListener);

if (sharedInstance.inAppManager == null) {
sharedInstance.inAppManager = new IterableInAppManager(sharedInstance, sharedInstance.config.inAppHandler,
sharedInstance.config.inAppDisplayInterval);
sharedInstance.inAppManager = new IterableInAppManager(
sharedInstance,
sharedInstance.config.inAppHandler,
sharedInstance.config.inAppDisplayInterval,
sharedInstance.config.useInMemoryStorageForInApps);
}

loadLastSavedConfiguration(context);
IterablePushNotificationUtil.processPendingAction(context);
if (DeviceInfoUtils.isFireTV(context.getPackageManager())) {
try {
JSONObject dataFields = new JSONObject();
JSONObject deviceDetails = new JSONObject();
DeviceInfoUtils.populateDeviceDetails(deviceDetails, context, sharedInstance.getDeviceId());
dataFields.put(IterableConstants.KEY_FIRETV, deviceDetails);
sharedInstance.apiClient.updateUser(dataFields, false);
} catch (JSONException e) {
IterableLogger.e(TAG, "initialize: exception", e);
}
}
}

public static void setContext(Context context) {
Expand Down Expand Up @@ -557,10 +577,18 @@ public IterableAttributionInfo getAttributionInfo() {
}

public void setEmail(@Nullable String email) {
setEmail(email, null);
setEmail(email, null, null, null);
}

public void setEmail(@Nullable String email, @Nullable IterableHelper.SuccessHandler successHandler, @Nullable IterableHelper.FailureHandler failureHandler) {
setEmail(email, null, successHandler, failureHandler);
}

public void setEmail(@Nullable String email, @Nullable String authToken) {
setEmail(email, authToken, null, null);
}

public void setEmail(@Nullable String email, @Nullable String authToken, @Nullable IterableHelper.SuccessHandler successHandler, @Nullable IterableHelper.FailureHandler failureHandler) {
//Only if passed in same non-null email
if (_email != null && _email.equals(email)) {
checkAndUpdateAuthToken(authToken);
Expand All @@ -575,16 +603,26 @@ public void setEmail(@Nullable String email, @Nullable String authToken) {

_email = email;
_userId = null;
_setUserSuccessCallbackHandler = successHandler;
_setUserFailureCallbackHandler = failureHandler;
storeAuthData();

onLogin(authToken);
}

public void setUserId(@Nullable String userId) {
setUserId(userId, null);
setUserId(userId, null, null, null);
}

public void setUserId(@Nullable String userId, @Nullable IterableHelper.SuccessHandler successHandler, @Nullable IterableHelper.FailureHandler failureHandler) {
setUserId(userId, null, successHandler, failureHandler);
}

public void setUserId(@Nullable String userId, @Nullable String authToken) {
setUserId(userId, authToken, null, null);
}

public void setUserId(@Nullable String userId, @Nullable String authToken, @Nullable IterableHelper.SuccessHandler successHandler, @Nullable IterableHelper.FailureHandler failureHandler) {
//If same non null userId is passed
if (_userId != null && _userId.equals(userId)) {
checkAndUpdateAuthToken(authToken);
Expand All @@ -599,6 +637,8 @@ public void setUserId(@Nullable String userId, @Nullable String authToken) {

_email = null;
_userId = userId;
_setUserSuccessCallbackHandler = successHandler;
_setUserFailureCallbackHandler = failureHandler;
storeAuthData();

onLogin(authToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import androidx.annotation.Nullable;
import androidx.core.app.NotificationManagerCompat;

import com.iterable.iterableapi.util.DeviceInfoUtils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand Down Expand Up @@ -204,7 +206,7 @@ public void getInAppMessages(int count, @NonNull IterableHelper.IterableActionHa
try {
addEmailOrUserIdToJson(requestJSON);
requestJSON.put(IterableConstants.ITERABLE_IN_APP_COUNT, count);
requestJSON.put(IterableConstants.KEY_PLATFORM, IterableConstants.ITBL_PLATFORM_ANDROID);
requestJSON.put(IterableConstants.KEY_PLATFORM, DeviceInfoUtils.isFireTV(authProvider.getContext().getPackageManager()) ? IterableConstants.ITBL_PLATFORM_OTT : IterableConstants.ITBL_PLATFORM_ANDROID);
requestJSON.put(IterableConstants.ITBL_KEY_SDK_VERSION, IterableConstants.ITBL_KEY_SDK_VERSION_NUMBER);
requestJSON.put(IterableConstants.ITBL_SYSTEM_VERSION, Build.VERSION.RELEASE);
requestJSON.put(IterableConstants.KEY_PACKAGE_NAME, authProvider.getContext().getPackageName());
Expand Down Expand Up @@ -411,7 +413,7 @@ protected void disableToken(@Nullable String email, @Nullable String userId, @Nu
}
}

protected void registerDeviceToken(@Nullable String email, @Nullable String userId, @Nullable String authToken, @NonNull String applicationName, @NonNull String deviceToken, @Nullable JSONObject dataFields, HashMap<String, String> deviceAttributes) {
protected void registerDeviceToken(@Nullable String email, @Nullable String userId, @Nullable String authToken, @NonNull String applicationName, @NonNull String deviceToken, @Nullable JSONObject dataFields, HashMap<String, String> deviceAttributes, @Nullable final IterableHelper.SuccessHandler successHandler, @Nullable final IterableHelper.FailureHandler failureHandler) {
Context context = authProvider.getContext();
JSONObject requestJSON = new JSONObject();
try {
Expand All @@ -427,18 +429,7 @@ protected void registerDeviceToken(@Nullable String email, @Nullable String user

dataFields.put(IterableConstants.FIREBASE_TOKEN_TYPE, IterableConstants.MESSAGING_PLATFORM_FIREBASE);
dataFields.put(IterableConstants.FIREBASE_COMPATIBLE, true);
dataFields.put(IterableConstants.DEVICE_BRAND, Build.BRAND); //brand: google
dataFields.put(IterableConstants.DEVICE_MANUFACTURER, Build.MANUFACTURER); //manufacturer: samsung
dataFields.put(IterableConstants.DEVICE_SYSTEM_NAME, Build.DEVICE); //device name: toro
dataFields.put(IterableConstants.DEVICE_SYSTEM_VERSION, Build.VERSION.RELEASE); //version: 4.0.4
dataFields.put(IterableConstants.DEVICE_MODEL, Build.MODEL); //device model: Galaxy Nexus
dataFields.put(IterableConstants.DEVICE_SDK_VERSION, Build.VERSION.SDK_INT); //sdk version/api level: 15

dataFields.put(IterableConstants.DEVICE_ID, authProvider.getDeviceId()); // Random UUID
dataFields.put(IterableConstants.DEVICE_APP_PACKAGE_NAME, context.getPackageName());
dataFields.put(IterableConstants.DEVICE_APP_VERSION, IterableUtil.getAppVersion(context));
dataFields.put(IterableConstants.DEVICE_APP_BUILD, IterableUtil.getAppVersionCode(context));
dataFields.put(IterableConstants.DEVICE_ITERABLE_SDK_VERSION, IterableConstants.ITBL_KEY_SDK_VERSION_NUMBER);
DeviceInfoUtils.populateDeviceDetails(dataFields, context, authProvider.getDeviceId());
dataFields.put(IterableConstants.DEVICE_NOTIFICATIONS_ENABLED, NotificationManagerCompat.from(context).areNotificationsEnabled());

JSONObject device = new JSONObject();
Expand All @@ -453,7 +444,7 @@ protected void registerDeviceToken(@Nullable String email, @Nullable String user
requestJSON.put(IterableConstants.KEY_PREFER_USER_ID, true);
}

sendPostRequest(IterableConstants.ENDPOINT_REGISTER_DEVICE_TOKEN, requestJSON, authToken);
sendPostRequest(IterableConstants.ENDPOINT_REGISTER_DEVICE_TOKEN, requestJSON, authToken, successHandler, failureHandler);
} catch (JSONException e) {
IterableLogger.e(TAG, "registerDeviceToken: exception", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ public class IterableConfig {
*/
final String[] allowedProtocols;

/**
* This controls whether the in-app content should be saved to disk, or only kept in memory.
* By default, the SDK will save in-apps to disk.
*/
final boolean useInMemoryStorageForInApps;

private IterableConfig(Builder builder) {
pushIntegrationName = builder.pushIntegrationName;
urlHandler = builder.urlHandler;
Expand All @@ -83,6 +89,7 @@ private IterableConfig(Builder builder) {
authHandler = builder.authHandler;
expiringAuthTokenRefreshPeriod = builder.expiringAuthTokenRefreshPeriod;
allowedProtocols = builder.allowedProtocols;
useInMemoryStorageForInApps = builder.useInMemoryStorageForInApps;
}

public static class Builder {
Expand All @@ -97,6 +104,8 @@ public static class Builder {
private IterableAuthHandler authHandler;
private long expiringAuthTokenRefreshPeriod = 60000L;
private String[] allowedProtocols = new String[0];
private boolean useInMemoryStorageForInApps = false;

public Builder() {}

/**
Expand Down Expand Up @@ -217,6 +226,17 @@ public Builder setAllowedProtocols(@NonNull String[] allowedProtocols) {
return this;
}

/**
* Set whether the SDK should store in-apps only in memory, or in file storage
* @param useInMemoryStorageForInApps `true` will have in-apps be only in memory
*/

@NonNull
public Builder setUseInMemoryStorageForInApps(boolean useInMemoryStorageForInApps) {
this.useInMemoryStorageForInApps = useInMemoryStorageForInApps;
return this;
}

@NonNull
public IterableConfig build() {
return new IterableConfig(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public final class IterableConstants {
public static final String KEY_USER_TEXT = "userText";
public static final String KEY_INBOX_SESSION_ID = "inboxSessionId";
public static final String KEY_OFFLINE_MODE = "offlineMode";
public static final String KEY_FIRETV = "FireTV";

//API Endpoint Key Constants
public static final String ENDPOINT_DISABLE_DEVICE = "users/disableDevice";
Expand Down Expand Up @@ -245,6 +246,7 @@ public final class IterableConstants {

public static final String ITBL_KEY_SDK_VERSION = "SDKVersion";
public static final String ITBL_PLATFORM_ANDROID = "Android";
public static final String ITBL_PLATFORM_OTT = "OTT";
public static final String ITBL_KEY_SDK_VERSION_NUMBER = BuildConfig.ITERABLE_SDK_VERSION;
public static final String ITBL_SYSTEM_VERSION = "systemVersion";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
Expand Down Expand Up @@ -50,11 +51,11 @@ public interface Listener {
private long lastInAppShown = 0;
private boolean autoDisplayPaused = false;

IterableInAppManager(IterableApi iterableApi, IterableInAppHandler handler, double inAppDisplayInterval) {
IterableInAppManager(IterableApi iterableApi, IterableInAppHandler handler, double inAppDisplayInterval, boolean useInMemoryStorageForInApps) {
this(iterableApi,
handler,
inAppDisplayInterval,
new IterableInAppFileStorage(iterableApi.getMainActivityContext()),
IterableInAppManager.getInAppStorageModel(iterableApi, useInMemoryStorageForInApps),
IterableActivityMonitor.getInstance(),
new IterableInAppDisplayer(IterableActivityMonitor.getInstance()));
}
Expand Down Expand Up @@ -435,6 +436,26 @@ private void handleIterableCustomAction(String actionName, IterableInAppMessage
}
}

private static IterableInAppStorage getInAppStorageModel(IterableApi iterableApi, boolean useInMemoryForInAppStorage) {
if (useInMemoryForInAppStorage) {
checkAndDeleteUnusedInAppFileStorage(iterableApi.getMainActivityContext());

return new IterableInAppMemoryStorage();
} else {
return new IterableInAppFileStorage(iterableApi.getMainActivityContext());
}
}

private static void checkAndDeleteUnusedInAppFileStorage(Context context) {
File sdkFilesDirectory = IterableUtil.getSDKFilesDirectory(context);
File inAppContentFolder = IterableUtil.getDirectory(sdkFilesDirectory, "IterableInAppFileStorage");
File inAppBlob = new File(inAppContentFolder, "itbl_inapp.json");

if (inAppBlob.exists()) {
inAppBlob.delete();
}
}

@Override
public void onSwitchToForeground() {
if (IterableUtil.currentTimeMillis() - lastSyncTime > MOVE_TO_FOREGROUND_SYNC_INTERVAL_MS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@

import java.io.File;

class IterableUtil {
public class IterableUtil {
@VisibleForTesting
static IterableUtilImpl instance = new IterableUtilImpl();

private IterableUtil() { }

static long currentTimeMillis() {
return instance.currentTimeMillis();
}

static String getAppVersion(Context context) {
public static String getAppVersion(Context context) {
return instance.getAppVersion(context);
}

static String getAppVersionCode(Context context) {
public static String getAppVersionCode(Context context) {
return instance.getAppVersionCode(context);
}

Expand Down
Loading

0 comments on commit 47ca7c1

Please sign in to comment.