@Test public void testLogUserAttributeChangeNewAttribute() throws Exception { BaseMPMessage message = manager.logUserAttributeChangeMessage("this is a key", "this is the new value", null, false, false, 0, 1); assertEquals("this is a key", message.getString("n")); assertEquals("this is the new value", message.getString("nv")); assertEquals(JSONObject.NULL, message.get("ov")); assertEquals(false, message.getBoolean("d")); }
public BaseMPMessage logUserAttributeChangeMessage(String userAttributeKey, Object newValue, Object oldValue, boolean deleted, boolean isNewAttribute, long time, long mpId) { try { BaseMPMessage message = new BaseMPMessage.Builder(MessageType.USER_ATTRIBUTE_CHANGE) .timestamp(time) .build(mAppStateManager.getSession(), mLocation, mpId); message.put(MessageKey.NAME, userAttributeKey); if (newValue == null || deleted) { newValue = JSONObject.NULL; } else if (newValue instanceof List) { JSONArray newValueArray = new JSONArray(); for (int i = 0; i < ((List) newValue).size(); i++) { String value = (String)((List) newValue).get(i); newValueArray.put(value); } newValue = newValueArray; } message.put(MessageKey.NEW_ATTRIBUTE_VALUE, newValue); if (oldValue == null) { oldValue = JSONObject.NULL; } else if (oldValue instanceof List) { JSONArray oldValueArray = new JSONArray(); for (int i = 0; i < ((List) oldValue).size(); i++) { String value = (String)((List) oldValue).get(i); oldValueArray.put(value); } oldValue = oldValueArray; } message.put(MessageKey.OLD_ATTRIBUTE_VALUE, oldValue); message.put(MessageKey.ATTRIBUTE_DELETED, deleted); message.put(MessageKey.IS_NEW_ATTRIBUTE, isNewAttribute); message.put(MessageKey.USER_ATTRIBUTES, mMParticleDBManager.getAllUserAttributesJson(mpId)); mMessageHandler.handleMessageImpl(mMessageHandler.obtainMessage(MessageHandler.STORE_MESSAGE, message)); return message; } catch (JSONException e) { Logger.warning("Failed to create mParticle user-attribute-change message."); } return null; }
MessageManager implements MessageManagerCallbacks, ReportingManager { public BaseMPMessage logUserAttributeChangeMessage(String userAttributeKey, Object newValue, Object oldValue, boolean deleted, boolean isNewAttribute, long time, long mpId) { try { BaseMPMessage message = new BaseMPMessage.Builder(MessageType.USER_ATTRIBUTE_CHANGE) .timestamp(time) .build(mAppStateManager.getSession(), mLocation, mpId); message.put(MessageKey.NAME, userAttributeKey); if (newValue == null || deleted) { newValue = JSONObject.NULL; } else if (newValue instanceof List) { JSONArray newValueArray = new JSONArray(); for (int i = 0; i < ((List) newValue).size(); i++) { String value = (String)((List) newValue).get(i); newValueArray.put(value); } newValue = newValueArray; } message.put(MessageKey.NEW_ATTRIBUTE_VALUE, newValue); if (oldValue == null) { oldValue = JSONObject.NULL; } else if (oldValue instanceof List) { JSONArray oldValueArray = new JSONArray(); for (int i = 0; i < ((List) oldValue).size(); i++) { String value = (String)((List) oldValue).get(i); oldValueArray.put(value); } oldValue = oldValueArray; } message.put(MessageKey.OLD_ATTRIBUTE_VALUE, oldValue); message.put(MessageKey.ATTRIBUTE_DELETED, deleted); message.put(MessageKey.IS_NEW_ATTRIBUTE, isNewAttribute); message.put(MessageKey.USER_ATTRIBUTES, mMParticleDBManager.getAllUserAttributesJson(mpId)); mMessageHandler.handleMessageImpl(mMessageHandler.obtainMessage(MessageHandler.STORE_MESSAGE, message)); return message; } catch (JSONException e) { Logger.warning("Failed to create mParticle user-attribute-change message."); } return null; } }
MessageManager implements MessageManagerCallbacks, ReportingManager { public BaseMPMessage logUserAttributeChangeMessage(String userAttributeKey, Object newValue, Object oldValue, boolean deleted, boolean isNewAttribute, long time, long mpId) { try { BaseMPMessage message = new BaseMPMessage.Builder(MessageType.USER_ATTRIBUTE_CHANGE) .timestamp(time) .build(mAppStateManager.getSession(), mLocation, mpId); message.put(MessageKey.NAME, userAttributeKey); if (newValue == null || deleted) { newValue = JSONObject.NULL; } else if (newValue instanceof List) { JSONArray newValueArray = new JSONArray(); for (int i = 0; i < ((List) newValue).size(); i++) { String value = (String)((List) newValue).get(i); newValueArray.put(value); } newValue = newValueArray; } message.put(MessageKey.NEW_ATTRIBUTE_VALUE, newValue); if (oldValue == null) { oldValue = JSONObject.NULL; } else if (oldValue instanceof List) { JSONArray oldValueArray = new JSONArray(); for (int i = 0; i < ((List) oldValue).size(); i++) { String value = (String)((List) oldValue).get(i); oldValueArray.put(value); } oldValue = oldValueArray; } message.put(MessageKey.OLD_ATTRIBUTE_VALUE, oldValue); message.put(MessageKey.ATTRIBUTE_DELETED, deleted); message.put(MessageKey.IS_NEW_ATTRIBUTE, isNewAttribute); message.put(MessageKey.USER_ATTRIBUTES, mMParticleDBManager.getAllUserAttributesJson(mpId)); mMessageHandler.handleMessageImpl(mMessageHandler.obtainMessage(MessageHandler.STORE_MESSAGE, message)); return message; } catch (JSONException e) { Logger.warning("Failed to create mParticle user-attribute-change message."); } return null; } MessageManager();  MessageManager(Context appContext, ConfigManager configManager, MParticle.InstallType installType, AppStateManager appStateManager, MParticleDBManager dbManager, MessageHandler messageHandler, UploadHandler uploadHandler);  MessageManager(ConfigManager configManager, AppStateManager appStateManager, boolean devicePerformanceMetricsDisabled, MParticleDBManager dbManager, MParticleOptions options); }
MessageManager implements MessageManagerCallbacks, ReportingManager { public BaseMPMessage logUserAttributeChangeMessage(String userAttributeKey, Object newValue, Object oldValue, boolean deleted, boolean isNewAttribute, long time, long mpId) { try { BaseMPMessage message = new BaseMPMessage.Builder(MessageType.USER_ATTRIBUTE_CHANGE) .timestamp(time) .build(mAppStateManager.getSession(), mLocation, mpId); message.put(MessageKey.NAME, userAttributeKey); if (newValue == null || deleted) { newValue = JSONObject.NULL; } else if (newValue instanceof List) { JSONArray newValueArray = new JSONArray(); for (int i = 0; i < ((List) newValue).size(); i++) { String value = (String)((List) newValue).get(i); newValueArray.put(value); } newValue = newValueArray; } message.put(MessageKey.NEW_ATTRIBUTE_VALUE, newValue); if (oldValue == null) { oldValue = JSONObject.NULL; } else if (oldValue instanceof List) { JSONArray oldValueArray = new JSONArray(); for (int i = 0; i < ((List) oldValue).size(); i++) { String value = (String)((List) oldValue).get(i); oldValueArray.put(value); } oldValue = oldValueArray; } message.put(MessageKey.OLD_ATTRIBUTE_VALUE, oldValue); message.put(MessageKey.ATTRIBUTE_DELETED, deleted); message.put(MessageKey.IS_NEW_ATTRIBUTE, isNewAttribute); message.put(MessageKey.USER_ATTRIBUTES, mMParticleDBManager.getAllUserAttributesJson(mpId)); mMessageHandler.handleMessageImpl(mMessageHandler.obtainMessage(MessageHandler.STORE_MESSAGE, message)); return message; } catch (JSONException e) { Logger.warning("Failed to create mParticle user-attribute-change message."); } return null; } MessageManager();  MessageManager(Context appContext, ConfigManager configManager, MParticle.InstallType installType, AppStateManager appStateManager, MParticleDBManager dbManager, MessageHandler messageHandler, UploadHandler uploadHandler);  MessageManager(ConfigManager configManager, AppStateManager appStateManager, boolean devicePerformanceMetricsDisabled, MParticleDBManager dbManager, MParticleOptions options); boolean isDevicePerformanceMetricsDisabled(); void setDevicePerformanceMetricsDisabled(boolean disabled); static JSONObject getStateInfo(); static long getTotalMemory(); static long getSystemMemoryThreshold(); BaseMPMessage createFirstRunMessage(); BaseMPMessage startSession(InternalSession session); void updateSessionEnd(InternalSession session); void endSession(InternalSession session); void installReferrerUpdated(); BaseMPMessage logEvent(MPEvent event, String currentActivity); BaseMPMessage logEvent(CommerceEvent event); BaseMPMessage logScreen(MPEvent event, boolean started); BaseMPMessage logBreadcrumb(String breadcrumb); BaseMPMessage optOut(long time, boolean optOutStatus); BaseMPMessage logErrorEvent(String errorMessage, Throwable t, JSONObject attributes); BaseMPMessage logErrorEvent(String errorMessage, Throwable t, JSONObject attributes, boolean caught); BaseMPMessage logNetworkPerformanceEvent(long time, String method, String url, long length, long bytesSent, long bytesReceived, String requestString); BaseMPMessage setPushRegistrationId(String token, boolean registeringFlag); void setSessionAttributes(); void startUploadLoop(); void doUpload(); @Override void messagesClearedForUpload(); void setLocation(@Nullable Location location); Location getLocation(); BaseMPMessage logStateTransition(String stateTransInit, String currentActivity,
                                            String launchUri, String launchExtras, String launchSourcePackage, long previousForegroundTime, long suspendedTime, int interruptions); void logNotification(ProviderCloudMessage cloudMessage, String appState); @Override void logNotification(int contentId, String payload, String appState, int newBehavior); void logProfileAction(String action); BaseMPMessage logUserIdentityChangeMessage(JSONObject newIdentity, JSONObject oldIdentity, JSONArray userIdentities, long mpId); BaseMPMessage logUserAttributeChangeMessage(String userAttributeKey, Object newValue, Object oldValue, boolean deleted, boolean isNewAttribute, long time, long mpId); @Override String getApiKey(); @SuppressLint("MissingPermission") @Override void delayedStart(); @Override void endUploadLoop(); @Override void checkForTrigger(BaseMPMessage message); void refreshConfiguration(); void initConfigDelayed(); @Override void log(JsonReportingMessage reportingMessage); @Override void logAll(List<? extends JsonReportingMessage> messageList); Map<String, Object> getUserAttributes(final UserAttributeListener listener, long mpId); void removeUserAttribute(String key, long mpId); @Override void attributeRemoved(String key, long mpId); void setUserAttribute(String key, Object value, long mpId); void setUserAttribute(String key, Object value, long mpId, boolean synchronously); void incrementUserAttribute(String key, int value, long mpId); synchronized DeviceAttributes getDeviceAttributes(); Map<MParticle.IdentityType, String> getUserIdentities(long mpId); JSONArray getUserIdentityJson(long mpId); void setDataConnection(NetworkInfo activeNetwork); BackgroundTaskHandler getTaskHandler(); Handler getMessageHandler(); MParticleDBManager getMParticleDBManager(); void disableHandlers(); void logAliasRequest(final AliasRequest aliasRequest); }
MessageManager implements MessageManagerCallbacks, ReportingManager { public BaseMPMessage logUserAttributeChangeMessage(String userAttributeKey, Object newValue, Object oldValue, boolean deleted, boolean isNewAttribute, long time, long mpId) { try { BaseMPMessage message = new BaseMPMessage.Builder(MessageType.USER_ATTRIBUTE_CHANGE) .timestamp(time) .build(mAppStateManager.getSession(), mLocation, mpId); message.put(MessageKey.NAME, userAttributeKey); if (newValue == null || deleted) { newValue = JSONObject.NULL; } else if (newValue instanceof List) { JSONArray newValueArray = new JSONArray(); for (int i = 0; i < ((List) newValue).size(); i++) { String value = (String)((List) newValue).get(i); newValueArray.put(value); } newValue = newValueArray; } message.put(MessageKey.NEW_ATTRIBUTE_VALUE, newValue); if (oldValue == null) { oldValue = JSONObject.NULL; } else if (oldValue instanceof List) { JSONArray oldValueArray = new JSONArray(); for (int i = 0; i < ((List) oldValue).size(); i++) { String value = (String)((List) oldValue).get(i); oldValueArray.put(value); } oldValue = oldValueArray; } message.put(MessageKey.OLD_ATTRIBUTE_VALUE, oldValue); message.put(MessageKey.ATTRIBUTE_DELETED, deleted); message.put(MessageKey.IS_NEW_ATTRIBUTE, isNewAttribute); message.put(MessageKey.USER_ATTRIBUTES, mMParticleDBManager.getAllUserAttributesJson(mpId)); mMessageHandler.handleMessageImpl(mMessageHandler.obtainMessage(MessageHandler.STORE_MESSAGE, message)); return message; } catch (JSONException e) { Logger.warning("Failed to create mParticle user-attribute-change message."); } return null; } MessageManager();  MessageManager(Context appContext, ConfigManager configManager, MParticle.InstallType installType, AppStateManager appStateManager, MParticleDBManager dbManager, MessageHandler messageHandler, UploadHandler uploadHandler);  MessageManager(ConfigManager configManager, AppStateManager appStateManager, boolean devicePerformanceMetricsDisabled, MParticleDBManager dbManager, MParticleOptions options); boolean isDevicePerformanceMetricsDisabled(); void setDevicePerformanceMetricsDisabled(boolean disabled); static JSONObject getStateInfo(); static long getTotalMemory(); static long getSystemMemoryThreshold(); BaseMPMessage createFirstRunMessage(); BaseMPMessage startSession(InternalSession session); void updateSessionEnd(InternalSession session); void endSession(InternalSession session); void installReferrerUpdated(); BaseMPMessage logEvent(MPEvent event, String currentActivity); BaseMPMessage logEvent(CommerceEvent event); BaseMPMessage logScreen(MPEvent event, boolean started); BaseMPMessage logBreadcrumb(String breadcrumb); BaseMPMessage optOut(long time, boolean optOutStatus); BaseMPMessage logErrorEvent(String errorMessage, Throwable t, JSONObject attributes); BaseMPMessage logErrorEvent(String errorMessage, Throwable t, JSONObject attributes, boolean caught); BaseMPMessage logNetworkPerformanceEvent(long time, String method, String url, long length, long bytesSent, long bytesReceived, String requestString); BaseMPMessage setPushRegistrationId(String token, boolean registeringFlag); void setSessionAttributes(); void startUploadLoop(); void doUpload(); @Override void messagesClearedForUpload(); void setLocation(@Nullable Location location); Location getLocation(); BaseMPMessage logStateTransition(String stateTransInit, String currentActivity,
                                            String launchUri, String launchExtras, String launchSourcePackage, long previousForegroundTime, long suspendedTime, int interruptions); void logNotification(ProviderCloudMessage cloudMessage, String appState); @Override void logNotification(int contentId, String payload, String appState, int newBehavior); void logProfileAction(String action); BaseMPMessage logUserIdentityChangeMessage(JSONObject newIdentity, JSONObject oldIdentity, JSONArray userIdentities, long mpId); BaseMPMessage logUserAttributeChangeMessage(String userAttributeKey, Object newValue, Object oldValue, boolean deleted, boolean isNewAttribute, long time, long mpId); @Override String getApiKey(); @SuppressLint("MissingPermission") @Override void delayedStart(); @Override void endUploadLoop(); @Override void checkForTrigger(BaseMPMessage message); void refreshConfiguration(); void initConfigDelayed(); @Override void log(JsonReportingMessage reportingMessage); @Override void logAll(List<? extends JsonReportingMessage> messageList); Map<String, Object> getUserAttributes(final UserAttributeListener listener, long mpId); void removeUserAttribute(String key, long mpId); @Override void attributeRemoved(String key, long mpId); void setUserAttribute(String key, Object value, long mpId); void setUserAttribute(String key, Object value, long mpId, boolean synchronously); void incrementUserAttribute(String key, int value, long mpId); synchronized DeviceAttributes getDeviceAttributes(); Map<MParticle.IdentityType, String> getUserIdentities(long mpId); JSONArray getUserIdentityJson(long mpId); void setDataConnection(NetworkInfo activeNetwork); BackgroundTaskHandler getTaskHandler(); Handler getMessageHandler(); MParticleDBManager getMParticleDBManager(); void disableHandlers(); void logAliasRequest(final AliasRequest aliasRequest); public UploadHandler mUploadHandler; }