Skip to content

Commit

Permalink
Merge branch 'client_side_inapps' of https://github.com/CleverTap/cle…
Browse files Browse the repository at this point in the history
…vertap-android-sdk into client_side_inapps
  • Loading branch information
shivamsharma2710 committed Nov 7, 2023
2 parents 57845e5 + 920bf6a commit 2170b64
Show file tree
Hide file tree
Showing 68 changed files with 1,555 additions and 879 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
## CHANGE LOG.

### October 27, 2023

* [CleverTap Push Templates SDK v1.2.0](docs/CTPUSHTEMPLATESCHANGELOG.md).

### October 12, 2023

* [CleverTap Android SDK v5.2.1](docs/CTCORECHANGELOG.md)
* [CleverTap Xiaomi Push SDK v1.5.4](docs/CTXIAOMIPUSHCHANGELOG.md)

### August 10, 2023

* [CleverTap Android SDK v5.2.0](docs/CTCORECHANGELOG.md)
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ We publish the SDK to `mavenCentral` as an `AAR` file. Just declare it as depend

```groovy
dependencies {
implementation "com.clevertap.android:clevertap-android-sdk:5.2.0"
implementation "com.clevertap.android:clevertap-android-sdk:5.2.1"
}
```

Alternatively, you can download and add the AAR file included in this repo in your Module libs directory and tell gradle to install it like this:

```groovy
dependencies {
implementation (name: "clevertap-android-sdk-5.2.0", ext: 'aar')
implementation (name: "clevertap-android-sdk-5.2.1", ext: 'aar')
}
```

Expand All @@ -46,10 +46,10 @@ Add the Firebase Messaging library and Android Support Library v4 as dependencie

```groovy
dependencies {
implementation "com.clevertap.android:clevertap-android-sdk:5.2.0"
implementation "com.clevertap.android:clevertap-android-sdk:5.2.1"
implementation "androidx.core:core:1.9.0"
implementation "com.google.firebase:firebase-messaging:23.0.6"
implementation "com.google.android.gms:play-services-ads:19.4.0" // Required only if you enable Google ADID collection in the SDK (turned off by default).
implementation "com.google.android.gms:play-services-ads:22.3.0" // Required only if you enable Google ADID collection in the SDK (turned off by default).
implementation "com.android.installreferrer:installreferrer:2.2" // Mandatory for v3.6.4 and above
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ public static void changeCredentials(String accountID, String token) {

/**
* This method is used to change the credentials of CleverTap account Id, token and region programmatically
* Once the SDK is initialized with a default instance, subsequent calls to this method will be ignored.
*
* @param accountID CleverTap Account Id
* @param token CleverTap Account Token
Expand All @@ -188,6 +189,27 @@ public static void changeCredentials(String accountID, String token, String regi
ManifestInfo.changeCredentials(accountID, token, region);
}

/**
* This method is used to change the credentials of CleverTap account Id, token, proxyDomain and spikyProxyDomain programmatically
*
* @param accountID CleverTap Account Id
* @param token CleverTap Account Token
* @param proxyDomain CleverTap Proxy Domain
* @param spikyProxyDomain CleverTap Spiky Proxy Domain
*/
public static void changeCredentials(String accountID, String token, String proxyDomain, String spikyProxyDomain) {
if (defaultConfig != null) {
Logger.i("CleverTap SDK already initialized with accountID:" + defaultConfig.getAccountId()
+ ", token:" + defaultConfig.getAccountToken() + ", proxyDomain: " + defaultConfig.getProxyDomain() +
" and spikyDomain: " + defaultConfig.getSpikyProxyDomain() +
". Cannot change credentials to accountID: " + accountID +
", token: " + token + ", proxyDomain: " + proxyDomain + "and spikyProxyDomain: " + spikyProxyDomain);
return;
}

ManifestInfo.changeCredentials(accountID, token, proxyDomain, spikyProxyDomain);
}

/**
* This method is used to change the credentials of Xiaomi app id and key programmatically.
*
Expand Down Expand Up @@ -2975,6 +2997,8 @@ private static CleverTapInstanceConfig getDefaultConfig(Context context) {
String accountId = manifest.getAccountId();
String accountToken = manifest.getAcountToken();
String accountRegion = manifest.getAccountRegion();
String proxyDomain = manifest.getProxyDomain();
String spikyProxyDomain = manifest.getSpikeyProxyDomain();
if (accountId == null || accountToken == null) {
Logger.i(
"Account ID or Account token is missing from AndroidManifest.xml, unable to create default instance");
Expand All @@ -2983,9 +3007,15 @@ private static CleverTapInstanceConfig getDefaultConfig(Context context) {
if (accountRegion == null) {
Logger.i("Account Region not specified in the AndroidManifest - using default region");
}
CleverTapInstanceConfig defaultInstanceConfig = CleverTapInstanceConfig.createDefaultInstance(context, accountId, accountToken, accountRegion);

return CleverTapInstanceConfig.createDefaultInstance(context, accountId, accountToken, accountRegion);

if (proxyDomain != null && proxyDomain.trim().length() > 0) {
defaultInstanceConfig.setProxyDomain(proxyDomain);
}
if (spikyProxyDomain != null && spikyProxyDomain.trim().length() > 0) {
defaultInstanceConfig.setSpikyProxyDomain(spikyProxyDomain);
}
return defaultInstanceConfig;
}

private static @Nullable
Expand Down Expand Up @@ -3410,4 +3440,27 @@ public void removeAllOneTimeVariablesChangedCallbacks() {
coreState.getCTVariables().removeAllOneTimeVariablesChangedCallbacks();
}

/**
* Use this method to set a custom locale for the current CleverTap instance
*
* @param locale - The custom locale to be set
*/
@SuppressWarnings({"unused"})
public void setLocale(String locale) {
if(TextUtils.isEmpty(locale)) {
Logger.i("Empty Locale provided for setLocale, not setting it");
return;
}
coreState.getDeviceInfo().setCustomLocale(locale);
}

/**
* Returns the custom locale set for the current CleverTap instance
*
* @return The customLocale string value
*/
@SuppressWarnings({"unused"})
public String getLocale() {
return coreState.getDeviceInfo().getCustomLocale();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public CleverTapInstanceConfig[] newArray(int size) {

private String accountToken;

private String proxyDomain;

private String spikyProxyDomain;

@NonNull
private ArrayList<String> allowedPushTypes = getAll();

Expand Down Expand Up @@ -107,6 +111,8 @@ public static CleverTapInstanceConfig createInstance(Context context, @NonNull S
this.accountId = config.accountId;
this.accountToken = config.accountToken;
this.accountRegion = config.accountRegion;
this.proxyDomain = config.proxyDomain;
this.spikyProxyDomain = config.spikyProxyDomain;
this.isDefaultInstance = config.isDefaultInstance;
this.analyticsOnly = config.analyticsOnly;
this.personalization = config.personalization;
Expand Down Expand Up @@ -170,6 +176,12 @@ private CleverTapInstanceConfig(String jsonString) throws Throwable {
if (configJsonObject.has(Constants.KEY_ACCOUNT_TOKEN)) {
this.accountToken = configJsonObject.getString(Constants.KEY_ACCOUNT_TOKEN);
}
if (configJsonObject.has(Constants.KEY_PROXY_DOMAIN)) {
this.proxyDomain = configJsonObject.getString(Constants.KEY_PROXY_DOMAIN);
}
if (configJsonObject.has(Constants.KEY_SPIKY_PROXY_DOMAIN)) {
this.spikyProxyDomain = configJsonObject.getString(Constants.KEY_SPIKY_PROXY_DOMAIN);
}
if (configJsonObject.has(Constants.KEY_ACCOUNT_REGION)) {
this.accountRegion = configJsonObject.getString(Constants.KEY_ACCOUNT_REGION);
}
Expand Down Expand Up @@ -234,6 +246,8 @@ private CleverTapInstanceConfig(Parcel in) {
accountId = in.readString();
accountToken = in.readString();
accountRegion = in.readString();
proxyDomain = in.readString();
spikyProxyDomain = in.readString();
analyticsOnly = in.readByte() != 0x00;
isDefaultInstance = in.readByte() != 0x00;
useGoogleAdId = in.readByte() != 0x00;
Expand Down Expand Up @@ -288,6 +302,22 @@ public int getDebugLevel() {
return debugLevel;
}

public String getProxyDomain() {
return proxyDomain;
}

public void setProxyDomain(String proxyDomain) {
this.proxyDomain = proxyDomain;
}

public String getSpikyProxyDomain() {
return spikyProxyDomain;
}

public void setSpikyProxyDomain(String spikyProxyDomain) {
this.spikyProxyDomain = spikyProxyDomain;
}

@SuppressWarnings({"unused"})
public void setDebugLevel(CleverTapAPI.LogLevel debugLevel) {
setDebugLevel(debugLevel.intValue());
Expand Down Expand Up @@ -367,6 +397,8 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeString(accountId);
dest.writeString(accountToken);
dest.writeString(accountRegion);
dest.writeString(proxyDomain);
dest.writeString(spikyProxyDomain);
dest.writeByte((byte) (analyticsOnly ? 0x01 : 0x00));
dest.writeByte((byte) (isDefaultInstance ? 0x01 : 0x00));
dest.writeByte((byte) (useGoogleAdId ? 0x01 : 0x00));
Expand Down Expand Up @@ -445,6 +477,8 @@ String toJSONString() {
configJsonObject.put(Constants.KEY_ACCOUNT_ID, getAccountId());
configJsonObject.put(Constants.KEY_ACCOUNT_TOKEN, getAccountToken());
configJsonObject.put(Constants.KEY_ACCOUNT_REGION, getAccountRegion());
configJsonObject.put(Constants.KEY_PROXY_DOMAIN, getProxyDomain());
configJsonObject.put(Constants.KEY_SPIKY_PROXY_DOMAIN, getSpikyProxyDomain());
configJsonObject.put(Constants.KEY_FCM_SENDER_ID, getFcmSenderId());
configJsonObject.put(Constants.KEY_ANALYTICS_ONLY, isAnalyticsOnly());
configJsonObject.put(Constants.KEY_DEFAULT_INSTANCE, isDefaultInstance());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public interface Constants {
String LABEL_NOTIFICATION_ICON = "CLEVERTAP_NOTIFICATION_ICON";
String LABEL_INAPP_EXCLUDE = "CLEVERTAP_INAPP_EXCLUDE";
String LABEL_REGION = "CLEVERTAP_REGION";
String LABEL_PROXY_DOMAIN = "CLEVERTAP_PROXY_DOMAIN";
String LABEL_SPIKY_PROXY_DOMAIN = "CLEVERTAP_SPIKY_PROXY_DOMAIN";
String LABEL_DISABLE_APP_LAUNCH = "CLEVERTAP_DISABLE_APP_LAUNCHED";
String LABEL_SSL_PINNING = "CLEVERTAP_SSL_PINNING";
String LABEL_BACKGROUND_SYNC = "CLEVERTAP_BACKGROUND_SYNC";
Expand Down Expand Up @@ -179,6 +181,8 @@ public interface Constants {
String KEY_ACCOUNT_ID = "accountId";
String KEY_ACCOUNT_TOKEN = "accountToken";
String KEY_ACCOUNT_REGION = "accountRegion";
String KEY_PROXY_DOMAIN = "proxyDomain";
String KEY_SPIKY_PROXY_DOMAIN = "spikyProxyDomain";
String KEY_ANALYTICS_ONLY = "analyticsOnly";
String KEY_DEFAULT_INSTANCE = "isDefaultInstance";
String KEY_USE_GOOGLE_AD_ID = "useGoogleAdId";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import android.net.NetworkInfo;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.WindowInsets;
import android.view.WindowManager;
Expand All @@ -38,6 +39,7 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Locale;
import java.util.UUID;
import java.util.concurrent.Callable;
import org.json.JSONObject;
Expand Down Expand Up @@ -89,6 +91,8 @@ private class DeviceCachedInfo {

private int localInAppCount;

private final String locale;

DeviceCachedInfo() {
versionName = getVersionName();
osName = getOsName();
Expand All @@ -107,6 +111,7 @@ private class DeviceCachedInfo {
widthPixels = getWidthPixels();
dpi = getDPI();
localInAppCount = getLocalInAppCountFromPreference();
locale = getDeviceLocale();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
appBucket = getAppBucket();
}
Expand Down Expand Up @@ -352,6 +357,18 @@ private int getWidthPixels() {
}
}

private String getDeviceLocale() {
String language = Locale.getDefault().getLanguage();
if ("".equals(language)) {
language = "xx";
}
String country = Locale.getDefault().getCountry();
if ("".equals(country)) {
country = "XX";
}
return language + "_" + country;
}

private double toTwoPlaces(double n) {
double result = n * 100;
result = Math.round(result);
Expand Down Expand Up @@ -430,6 +447,8 @@ private double toTwoPlaces(double n) {

private final ArrayList<ValidationResult> validationResults = new ArrayList<>();

private String customLocale;

/**
* Returns the integer identifier for the default app icon.
*
Expand Down Expand Up @@ -482,6 +501,7 @@ public static int getDeviceType(final Context context) {
this.context = context;
this.config = config;
this.library = null;
this.customLocale = null;
mCoreMetaData = coreMetaData;
onInitDeviceInfo(cleverTapID);
getConfigLogger().verbose(config.getAccountId() + ":async_deviceID", "DeviceInfo() called");
Expand Down Expand Up @@ -619,6 +639,23 @@ public void incrementLocalInAppCount() {
getDeviceCachedInfo().localInAppCount++;
}

public String getDeviceLocale() {
return getDeviceCachedInfo().locale;
}

public void setCustomLocale(String customLocale) {
this.customLocale = customLocale;
}

public String getCustomLocale() {
return customLocale;
}

public String getLocale() {
// If locale is set by the client then use that, otherwise fetch it from the device
return TextUtils.isEmpty(getCustomLocale()) ? getDeviceLocale() : getCustomLocale();
}

public ArrayList<ValidationResult> getValidationResults() {
// noinspection unchecked
ArrayList<ValidationResult> tempValidationResults = (ArrayList<ValidationResult>) validationResults.clone();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.clevertap.android.sdk;

public interface ILogger {
void debug(String message);

void debug(String suffix, String message);

void debug(String suffix, String message, Throwable t);

@SuppressWarnings("unused")
void debug(String message, Throwable t);

@SuppressWarnings("unused")
void info(String message);

void info(String suffix, String message);

@SuppressWarnings("unused")
void info(String suffix, String message, Throwable t);

@SuppressWarnings("unused")
void info(String message, Throwable t);

void verbose(String message);

void verbose(String suffix, String message);

void verbose(String suffix, String message, Throwable t);

void verbose(String message, Throwable t);
}
Loading

0 comments on commit 2170b64

Please sign in to comment.