diff --git a/CHANGELOG.md b/CHANGELOG.md index d70e2582f..51240bf80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## 22.02.0 -* Fixed notification trampoline restrictions in Android 12 using reverse activity trampolining implementation. + * Fixed notification trampoline restrictions in Android 12 using reverse activity trampolining implementation. + * Adding a call to provide user properties during initialization. ## 21.11.2 * Fixed bug that caused crashes when migrating from older versions that don't have a device ID type stored. When migrating from no device ID and no type, SDK will fall back to a generated ID. When migrating from device ID and no type, SDK will set id type to 'DEVELOPER_SUPPLIED' if a custom ID was provided during init. Otherwise the new type will be 'OPEN_UDID'. Adding handling for additional edge cases. diff --git a/app/src/main/java/ly/count/android/demo/App.java b/app/src/main/java/ly/count/android/demo/App.java index a7ee17671..7fac7b21d 100644 --- a/app/src/main/java/ly/count/android/demo/App.java +++ b/app/src/main/java/ly/count/android/demo/App.java @@ -124,6 +124,10 @@ public void onCreate() { customCrashSegmentation.put("EarBook", "3.5"); customCrashSegmentation.put("AdGiver", "6.5"); + //properties that we want to sent at init time + Map customUserProperties = new HashMap<>(); + customUserProperties.put("A", 1); + CountlyConfig config = (new CountlyConfig(this, COUNTLY_APP_KEY, COUNTLY_SERVER_URL)).setIdMode(DeviceIdType.OPEN_UDID)//.setDeviceId("67567") .setLoggingEnabled(true) .setLogListener(new ModuleLog.LogCallback() { @@ -202,7 +206,10 @@ public void callback(String error) { //.setMetricOverride(metricOverride) - .setEnableAttribution(true); + .setEnableAttribution(true) + + + .setUserProperties(customUserProperties); Countly.sharedInstance().init(config); //Log.i(demoTag, "After calling init. This should return 'true', the value is:" + Countly.sharedInstance().isInitialized()); diff --git a/sdk/src/main/java/ly/count/android/sdk/Countly.java b/sdk/src/main/java/ly/count/android/sdk/Countly.java index 5f68f43fc..bf8238dbe 100644 --- a/sdk/src/main/java/ly/count/android/sdk/Countly.java +++ b/sdk/src/main/java/ly/count/android/sdk/Countly.java @@ -514,6 +514,7 @@ public synchronized Countly init(CountlyConfig config) { moduleDeviceId = new ModuleDeviceId(this, config); moduleCrash = new ModuleCrash(this, config); moduleEvents = new ModuleEvents(this, config); + moduleUserProfile = new ModuleUserProfile(this, config);//this has to be set before the session module so that we can update remote config before sending anything session related moduleViews = new ModuleViews(this, config); moduleRatings = new ModuleRatings(this, config); moduleSessions = new ModuleSessions(this, config); @@ -522,7 +523,6 @@ public synchronized Countly init(CountlyConfig config) { moduleLocation = new ModuleLocation(this, config); moduleFeedback = new ModuleFeedback(this, config); moduleAttribution = new ModuleAttribution(this, config); - moduleUserProfile = new ModuleUserProfile(this, config); modules.clear(); modules.add(moduleRequestQueue); @@ -530,6 +530,7 @@ public synchronized Countly init(CountlyConfig config) { modules.add(moduleDeviceId); modules.add(moduleCrash); modules.add(moduleEvents); + modules.add(moduleUserProfile);//this has to be set before the session module so that we can update remote config before sending anything session related modules.add(moduleViews); modules.add(moduleRatings); modules.add(moduleSessions); @@ -538,7 +539,7 @@ public synchronized Countly init(CountlyConfig config) { modules.add(moduleLocation); modules.add(moduleFeedback); modules.add(moduleAttribution); - modules.add(moduleUserProfile); + if(config.testModuleListener != null) { modules.add(config.testModuleListener); diff --git a/sdk/src/main/java/ly/count/android/sdk/CountlyConfig.java b/sdk/src/main/java/ly/count/android/sdk/CountlyConfig.java index 721bcba9f..00a959f91 100644 --- a/sdk/src/main/java/ly/count/android/sdk/CountlyConfig.java +++ b/sdk/src/main/java/ly/count/android/sdk/CountlyConfig.java @@ -35,6 +35,8 @@ public class CountlyConfig { protected boolean checkForNativeCrashDumps = true; + protected Map providedUserProperties = null; + //used to deliver this object to connection queue //protected DeviceId deviceIdInstance = null; @@ -876,4 +878,14 @@ public synchronized CountlyConfig setIndirectAttribution(Map att iaAttributionValues = attributionValues; return this; } + + /** + * Used to provide user properties that would be sent as soon as possible + * + * @return Returns the same config object for convenient linking + */ + public synchronized CountlyConfig setUserProperties(Map userProperties) { + providedUserProperties = userProperties; + return this; + } } diff --git a/sdk/src/main/java/ly/count/android/sdk/ModuleUserProfile.java b/sdk/src/main/java/ly/count/android/sdk/ModuleUserProfile.java index 0590c6941..4a08a3d8c 100644 --- a/sdk/src/main/java/ly/count/android/sdk/ModuleUserProfile.java +++ b/sdk/src/main/java/ly/count/android/sdk/ModuleUserProfile.java @@ -304,15 +304,24 @@ void setPropertiesInternal(@NonNull Map data) { } void saveInternal() { - Countly.sharedInstance().L.w("[ModuleUserProfile] saveInternal"); + Countly.sharedInstance().L.d("[ModuleUserProfile] saveInternal"); Countly.userData.save(); } void clearInternal() { - Countly.sharedInstance().L.w("[ModuleUserProfile] clearInternal"); + Countly.sharedInstance().L.d("[ModuleUserProfile] clearInternal"); Countly.userData.clear(); } + @Override + void initFinished(@NonNull final CountlyConfig config) { + if(config.providedUserProperties != null) { + L.i("[ModuleUserProfile] Custom user properties were provided during init [" + config.providedUserProperties.size() + "]"); + setPropertiesInternal(config.providedUserProperties); + saveInternal(); + } + } + @Override void halt() { userProfileInterface = null; diff --git a/sdk/src/main/java/ly/count/android/sdk/messaging/CountlyPush.java b/sdk/src/main/java/ly/count/android/sdk/messaging/CountlyPush.java index c11d62218..98e883992 100644 --- a/sdk/src/main/java/ly/count/android/sdk/messaging/CountlyPush.java +++ b/sdk/src/main/java/ly/count/android/sdk/messaging/CountlyPush.java @@ -244,6 +244,7 @@ public void onReceive(Context context, Intent broadcast) { * @return token string or null if no token is currently available. */ private static String getToken(Context context, Countly.CountlyMessagingProvider prov, ModuleLog L) { + //todo this seems to be broken if (prov == Countly.CountlyMessagingProvider.FCM) { try { Object instance = UtilsMessaging.reflectiveCall(FIREBASE_INSTANCEID_CLASS, null, "getInstance", L);