@Test public void testLogScreen() throws Exception { manager.logScreen(new MPEvent.Builder("screen name").build(), true); manager.logScreen(null, true); appStateManager.getSession().start(context); Map<String, String> info = new HashMap<String, String>(); info.put("test key", "test value"); BaseMPMessage message = manager.logScreen(new MPEvent.Builder("screen name").addCustomFlag("flag 1", "value 1") .addCustomFlag("flag 1", "value 2").addCustomFlag("flag 2", "value 3").customAttributes(info).build(), true); assertNotNull(message); assertEquals(Constants.MessageType.SCREEN_VIEW, message.getMessageType()); assertEquals(appStateManager.getSession().mSessionID, message.getSessionId()); assertEquals(message.getDouble(Constants.MessageKey.EVENT_DURATION), 0, 2); assertEquals(message.getString(Constants.MessageKey.SCREEN_STARTED), "activity_started"); assertEquals(message.getLong(Constants.MessageKey.EVENT_START_TIME), appStateManager.getSession().mLastEventTime); JSONObject flags = message.getJSONObject("flags"); JSONArray flag1 = flags.getJSONArray("flag 1"); assertEquals(flag1.length(), 2); assertEquals(flag1.get(0), "value 1"); assertEquals(flag1.get(1), "value 2"); JSONArray flag2 = flags.getJSONArray("flag 2"); assertEquals(flag2.length(), 1); assertEquals(flag2.get(0), "value 3"); JSONObject attrs = message.getJSONObject(Constants.MessageKey.ATTRIBUTES); assertNotNull(attrs); assertEquals("test value", attrs.getString("test key")); assertEquals("screen name", message.getName()); message = manager.logScreen(new MPEvent.Builder("screen name 2").customAttributes(info).build(), false); assertEquals(message.getString(Constants.MessageKey.SCREEN_STARTED), "activity_stopped"); Mockito.verify(messageHandler, Mockito.times(3)).sendMessage(Mockito.any(Message.class)); }
public BaseMPMessage logScreen(MPEvent event, boolean started) { if (event != null && event.getEventName() != null) { try { BaseMPMessage message = new BaseMPMessage.Builder(MessageType.SCREEN_VIEW) .timestamp(mAppStateManager.getSession().mLastEventTime) .name(event.getEventName()) .flags(event.getCustomFlags()) .attributes(MPUtility.enforceAttributeConstraints(event.getCustomAttributes())) .build(mAppStateManager.getSession(), mLocation, mConfigManager.getMpid()); message.put(MessageKey.EVENT_START_TIME, mAppStateManager.getSession().mLastEventTime); message.put(MessageKey.EVENT_DURATION, 0); message.put(MessageKey.SCREEN_STARTED, started ? "activity_started" : "activity_stopped"); mMessageHandler.sendMessage(mMessageHandler.obtainMessage(MessageHandler.STORE_MESSAGE, message)); return message; } catch (JSONException e) { Logger.warning("Failed to create mParticle log event message."); } } return null; }
MessageManager implements MessageManagerCallbacks, ReportingManager { public BaseMPMessage logScreen(MPEvent event, boolean started) { if (event != null && event.getEventName() != null) { try { BaseMPMessage message = new BaseMPMessage.Builder(MessageType.SCREEN_VIEW) .timestamp(mAppStateManager.getSession().mLastEventTime) .name(event.getEventName()) .flags(event.getCustomFlags()) .attributes(MPUtility.enforceAttributeConstraints(event.getCustomAttributes())) .build(mAppStateManager.getSession(), mLocation, mConfigManager.getMpid()); message.put(MessageKey.EVENT_START_TIME, mAppStateManager.getSession().mLastEventTime); message.put(MessageKey.EVENT_DURATION, 0); message.put(MessageKey.SCREEN_STARTED, started ? "activity_started" : "activity_stopped"); mMessageHandler.sendMessage(mMessageHandler.obtainMessage(MessageHandler.STORE_MESSAGE, message)); return message; } catch (JSONException e) { Logger.warning("Failed to create mParticle log event message."); } } return null; } }
MessageManager implements MessageManagerCallbacks, ReportingManager { public BaseMPMessage logScreen(MPEvent event, boolean started) { if (event != null && event.getEventName() != null) { try { BaseMPMessage message = new BaseMPMessage.Builder(MessageType.SCREEN_VIEW) .timestamp(mAppStateManager.getSession().mLastEventTime) .name(event.getEventName()) .flags(event.getCustomFlags()) .attributes(MPUtility.enforceAttributeConstraints(event.getCustomAttributes())) .build(mAppStateManager.getSession(), mLocation, mConfigManager.getMpid()); message.put(MessageKey.EVENT_START_TIME, mAppStateManager.getSession().mLastEventTime); message.put(MessageKey.EVENT_DURATION, 0); message.put(MessageKey.SCREEN_STARTED, started ? "activity_started" : "activity_stopped"); mMessageHandler.sendMessage(mMessageHandler.obtainMessage(MessageHandler.STORE_MESSAGE, message)); return message; } catch (JSONException e) { Logger.warning("Failed to create mParticle log event 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 logScreen(MPEvent event, boolean started) { if (event != null && event.getEventName() != null) { try { BaseMPMessage message = new BaseMPMessage.Builder(MessageType.SCREEN_VIEW) .timestamp(mAppStateManager.getSession().mLastEventTime) .name(event.getEventName()) .flags(event.getCustomFlags()) .attributes(MPUtility.enforceAttributeConstraints(event.getCustomAttributes())) .build(mAppStateManager.getSession(), mLocation, mConfigManager.getMpid()); message.put(MessageKey.EVENT_START_TIME, mAppStateManager.getSession().mLastEventTime); message.put(MessageKey.EVENT_DURATION, 0); message.put(MessageKey.SCREEN_STARTED, started ? "activity_started" : "activity_stopped"); mMessageHandler.sendMessage(mMessageHandler.obtainMessage(MessageHandler.STORE_MESSAGE, message)); return message; } catch (JSONException e) { Logger.warning("Failed to create mParticle log event 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 logScreen(MPEvent event, boolean started) { if (event != null && event.getEventName() != null) { try { BaseMPMessage message = new BaseMPMessage.Builder(MessageType.SCREEN_VIEW) .timestamp(mAppStateManager.getSession().mLastEventTime) .name(event.getEventName()) .flags(event.getCustomFlags()) .attributes(MPUtility.enforceAttributeConstraints(event.getCustomAttributes())) .build(mAppStateManager.getSession(), mLocation, mConfigManager.getMpid()); message.put(MessageKey.EVENT_START_TIME, mAppStateManager.getSession().mLastEventTime); message.put(MessageKey.EVENT_DURATION, 0); message.put(MessageKey.SCREEN_STARTED, started ? "activity_started" : "activity_stopped"); mMessageHandler.sendMessage(mMessageHandler.obtainMessage(MessageHandler.STORE_MESSAGE, message)); return message; } catch (JSONException e) { Logger.warning("Failed to create mParticle log event 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; }