Skip to content

Commit

Permalink
Merge pull request #480 from CleverTap/develop
Browse files Browse the repository at this point in the history
Release Clevertap-Android-SDK v5.2.1 and Clevertap-Xiaomi-SDK v1.5.4
  • Loading branch information
Anush-Shand authored Oct 12, 2023
2 parents 4068a12 + d49ef8e commit c02bfa7
Show file tree
Hide file tree
Showing 24 changed files with 379 additions and 41 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## CHANGE LOG.

### 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 @@ -170,6 +170,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 @@ -187,6 +188,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 @@ -2974,6 +2996,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 @@ -2982,9 +3006,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 @@ -3384,4 +3414,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 @@ -31,6 +31,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 @@ -162,6 +164,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
Expand Up @@ -16,6 +16,10 @@ public class ManifestInfo {

private static String accountRegion;

private static String proxyDomain;

private static String spikyProxyDomain;

private static boolean useADID;

private static boolean appLaunchedDisabled;
Expand Down Expand Up @@ -78,6 +82,12 @@ private ManifestInfo(Context context) {
if (accountRegion == null) {
accountRegion = _getManifestStringValueForKey(metaData, Constants.LABEL_REGION);
}
if (proxyDomain == null) {
proxyDomain = _getManifestStringValueForKey(metaData, Constants.LABEL_PROXY_DOMAIN);
}
if (spikyProxyDomain == null) {
spikyProxyDomain = _getManifestStringValueForKey(metaData, Constants.LABEL_SPIKY_PROXY_DOMAIN);
}
notificationIcon = _getManifestStringValueForKey(metaData, Constants.LABEL_NOTIFICATION_ICON);
useADID = "1".equals(_getManifestStringValueForKey(metaData, Constants.LABEL_USE_GOOGLE_AD_ID));
appLaunchedDisabled = "1".equals(_getManifestStringValueForKey(metaData, Constants.LABEL_DISABLE_APP_LAUNCH));
Expand Down Expand Up @@ -174,6 +184,18 @@ String getAcountToken() {
return accountToken;
}

@RestrictTo(RestrictTo.Scope.LIBRARY)
public String getProxyDomain() {
Logger.v("ManifestInfo: getProxyDomain called, returning proxyDomain:" + proxyDomain);
return proxyDomain;
}

@RestrictTo(RestrictTo.Scope.LIBRARY)
public String getSpikeyProxyDomain() {
Logger.v("ManifestInfo: getSpikeyProxyDomain called, returning spikeyProxyDomain:" + spikyProxyDomain);
return spikyProxyDomain;
}

String getPackageName() {
return packageName;
}
Expand Down Expand Up @@ -212,6 +234,13 @@ static void changeCredentials(String id, String token, String region) {
accountRegion = region;
}

static void changeCredentials(String id, String token, String _proxyDomain, String _spikyProxyDomain) {
accountId = id;
accountToken = token;
proxyDomain = _proxyDomain;
spikyProxyDomain = _spikyProxyDomain;
}

static void changeXiaomiCredentials(String xiaomiAppID, String xiaomiAppKey) {
if (ManifestInfo.xiaomiAppID != null || ManifestInfo.xiaomiAppKey != null) {
Logger.i("Xiaomi SDK already initialized with AppID:" + ManifestInfo.xiaomiAppID
Expand Down
Loading

0 comments on commit c02bfa7

Please sign in to comment.