Skip to content

Commit

Permalink
Merge pull request #209 from CleverTap/develop SDK-1163
Browse files Browse the repository at this point in the history
Fixes a Strict Mode Read violation(getDeviceID()) for low RAM devices
  • Loading branch information
piyush-kukadiya authored Nov 25, 2021
2 parents 17d6b9f + 074ac29 commit d3938de
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## CHANGE LOG

### November 25, 2021

*[CleverTap Android SDK v4.3.1](https://github.com/CleverTap/clevertap-android-sdk/blob/master/docs/CTCORECHANGELOG.md)

### November 2, 2021

* [CleverTap Android SDK v4.3.0](https://github.com/CleverTap/clevertap-android-sdk/blob/master/docs/CTCORECHANGELOG.md)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,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:4.3.0"
implementation "com.clevertap.android:clevertap-android-sdk:4.3.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-4.3.0", ext: 'aar')
implementation (name: "clevertap-android-sdk-4.3.1", ext: 'aar')
}
```

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

```groovy
dependencies {
implementation "com.clevertap.android:clevertap-android-sdk:4.3.0"
implementation "com.clevertap.android:clevertap-android-sdk:4.3.1"
implementation "androidx.core:core:1.3.0"
implementation "com.google.firebase:firebase-messaging:20.2.4"
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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@
import com.clevertap.android.sdk.login.LoginController;
import com.clevertap.android.sdk.network.NetworkManager;
import com.clevertap.android.sdk.pushnotification.PushProviders;
import com.clevertap.android.sdk.task.CTExecutorFactory;
import com.clevertap.android.sdk.task.MainLooperHandler;
import com.clevertap.android.sdk.task.Task;
import com.clevertap.android.sdk.validation.ValidationResultStack;
import com.clevertap.android.sdk.validation.Validator;

import java.util.concurrent.Callable;

class CleverTapFactory {

static CoreState getCoreState(Context context, CleverTapInstanceConfig cleverTapInstanceConfig,
Expand Down Expand Up @@ -58,14 +62,24 @@ static CoreState getCoreState(Context context, CleverTapInstanceConfig cleverTap
ctLockManager, callbackManager, deviceInfo, baseDatabaseManager);
coreState.setControllerManager(controllerManager);

if (coreState.getDeviceInfo() != null && coreState.getDeviceInfo().getDeviceID() != null
&& controllerManager.getInAppFCManager() == null) {
coreState.getConfig().getLogger()
.verbose(config.getAccountId() + ":async_deviceID",
"Initializing InAppFC with device Id = " + coreState.getDeviceInfo().getDeviceID());
controllerManager
.setInAppFCManager(new InAppFCManager(context, config, coreState.getDeviceInfo().getDeviceID()));
}
//Get device id should be async to avoid strict mode policy.
Task<Void> taskInitFCManager = CTExecutorFactory.executors(config).ioTask();
taskInitFCManager.execute("initFCManager", new Callable<Void>() {
@Override
public Void call() throws Exception {
if (coreState.getDeviceInfo() != null && coreState.getDeviceInfo().getDeviceID() != null
&& controllerManager.getInAppFCManager() == null) {
coreState.getConfig().getLogger()
.verbose(config.getAccountId() + ":async_deviceID",
"Initializing InAppFC with device Id = " + coreState.getDeviceInfo().getDeviceID());
controllerManager
.setInAppFCManager(new InAppFCManager(context, config, coreState.getDeviceInfo().getDeviceID()));
}
return null;
}
});



NetworkManager networkManager = new NetworkManager(context, config, deviceInfo, coreMetaData,
validationResultStack, controllerManager, baseDatabaseManager,
Expand All @@ -89,7 +103,16 @@ static CoreState getCoreState(Context context, CleverTapInstanceConfig cleverTap
coreState.setInAppController(inAppController);
coreState.getControllerManager().setInAppController(inAppController);

initFeatureFlags(context, controllerManager, config, deviceInfo, callbackManager, analyticsManager);
Task<Void> taskInitFeatureFlags = CTExecutorFactory.executors(config).ioTask();
taskInitFeatureFlags.execute("initFeatureFlags", new Callable<Void>() {
@Override
public Void call() throws Exception {
initFeatureFlags(context, controllerManager, config, deviceInfo, callbackManager, analyticsManager);
return null;
}
});



LocationManager locationManager = new LocationManager(context, config, coreMetaData, baseEventQueueManager);
coreState.setLocationManager(locationManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ private void resetFeatureFlags() {
.isInitialized()) {
ctFeatureFlagsController.resetWithGuid(deviceInfo.getDeviceID());
ctFeatureFlagsController.fetchFeatureFlags();
}else {
config.getLogger().verbose(config.getAccountId(),
Constants.FEATURE_DISPLAY_UNIT + "Can't reset Display Units, CTFeatureFlagsController is null");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ private void parseFeatureFlags(JSONObject responseKV) throws JSONException {

if (kvArray != null && controllerManager.getCTFeatureFlagsController() != null) {
controllerManager.getCTFeatureFlagsController().updateFeatureFlags(responseKV);
}else {
config.getLogger().verbose(config.getAccountId(),
Constants.FEATURE_FLAG_UNIT + "Can't parse feature flags, CTFeatureFlagsController is null");
}
}
}
4 changes: 4 additions & 0 deletions docs/CTCORECHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## CleverTap Android SDK CHANGE LOG


### Version 4.3.1 (November 25, 2021)
* Fixes a Strict Mode Read violation for low RAM devices

### Version 4.3.0 (November 2, 2021)
* Adds support for [apps targeting Android 12 (API 31)](https://developer.android.com/about/versions/12/behavior-changes-12)
This version is compatible with all new Android 12 changes like Notification Trampolines, Pending Intents Mutability and Safer Component Exporting.
Expand Down
2 changes: 1 addition & 1 deletion docs/CTGEOFENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Add the following dependencies to the `build.gradle`

```Groovy
implementation "com.clevertap.android:clevertap-geofence-sdk:1.1.0"
implementation "com.clevertap.android:clevertap-android-sdk:4.3.0" // 3.9.0 and above
implementation "com.clevertap.android:clevertap-android-sdk:4.3.1" // 3.9.0 and above
implementation "com.google.android.gms:play-services-location:18.0.0"
implementation "androidx.work:work-runtime:2.7.0" // required for FETCH_LAST_LOCATION_PERIODIC
implementation "androidx.concurrent:concurrent-futures:1.1.0" // required for FETCH_LAST_LOCATION_PERIODIC
Expand Down
3 changes: 3 additions & 0 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<!--Enable below line to test for Android GO devices-->
<!--<uses-feature android:name="android.hardware.ram.low" android:required="true"/>-->

<application
android:name=".MyApplication"
android:allowBackup="true"
Expand Down
16 changes: 16 additions & 0 deletions sample/src/main/java/com/clevertap/demo/MyApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.clevertap.demo
import android.app.NotificationManager
import android.content.Context
import android.content.Intent
import android.os.StrictMode
import android.util.Log
import androidx.multidex.MultiDex
import androidx.multidex.MultiDexApplication
Expand All @@ -20,6 +21,21 @@ class MyApplication : MultiDexApplication(), CTPushNotificationListener {

override fun onCreate() {

/*StrictMode.setThreadPolicy(
StrictMode.ThreadPolicy.Builder()
.detectAll() // or .detectAll() for all detectable problems
.penaltyLog()
//.penaltyDeath()
.build()
);
StrictMode.setVmPolicy(
StrictMode.VmPolicy.Builder()
.detectAll()
.penaltyLog()
//.penaltyDeath()
.build()
)*/

CleverTapAPI.setDebugLevel(VERBOSE)
ActivityLifecycleCallback.register(this)
super.onCreate()
Expand Down
4 changes: 4 additions & 0 deletions templates/CTCORECHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## CleverTap Android SDK CHANGE LOG


### Version 4.3.1 (November 25, 2021)
* Fixes a Strict Mode Read violation for low RAM devices

### Version 4.3.0 (November 2, 2021)
* Adds support for [apps targeting Android 12 (API 31)](https://developer.android.com/about/versions/12/behavior-changes-12)
This version is compatible with all new Android 12 changes like Notification Trampolines, Pending Intents Mutability and Safer Component Exporting.
Expand Down
2 changes: 1 addition & 1 deletion versions.properties
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ version.com.android.installreferrer..installreferrer=2.2
## # available=2.2
version.com.android.tools.lint..lint-api=27.0.1
version.com.android.tools.lint..lint-checks=27.0.1
version.com.clevertap.android..clevertap-android-sdk=4.3.0
version.com.clevertap.android..clevertap-android-sdk=4.3.1
version.com.clevertap.android..clevertap-geofence-sdk=1.1.0
version.com.clevertap.android..clevertap-hms-sdk=1.1.0
version.com.clevertap.android..clevertap-xiaomi-sdk=1.1.0
Expand Down

0 comments on commit d3938de

Please sign in to comment.