@Test public void testStartSession() throws Exception { MockSharedPreferences prefs = (MockSharedPreferences) context.getSharedPreferences(null, 0); BaseMPMessage sessionStart = manager.startSession(appStateManager.getSession()); Mockito.verify(messageHandler, Mockito.times(2)).sendMessage(Mockito.any(Message.class)); assertNotNull(sessionStart); assertEquals(Constants.MessageType.SESSION_START, sessionStart.getMessageType()); assertFalse(sessionStart.has(Constants.MessageKey.PREVIOUS_SESSION_LENGTH)); assertNull(sessionStart.optString(Constants.MessageKey.PREVIOUS_SESSION_ID, null)); assertFalse(sessionStart.has(Constants.MessageKey.PREVIOUS_SESSION_START)); assertEquals(appStateManager.getSession().mSessionID, configManager.getUserStorage().getPreviousSessionId(null)); assertFalse(prefs.getBoolean(Constants.PrefKeys.FIRSTRUN_MESSAGE + configManager.getApiKey(), true)); configManager.getUserStorage().setPreviousSessionForeground(42000); configManager.getUserStorage().setPreviousSessionStart(24000); prefs.commit(); sessionStart = manager.startSession(appStateManager.getSession()); assertNotNull(sessionStart); assertEquals(Constants.MessageType.SESSION_START, sessionStart.getMessageType()); assertEquals(42, sessionStart.getLong(Constants.MessageKey.PREVIOUS_SESSION_LENGTH)); assertEquals(24000, sessionStart.getLong(Constants.MessageKey.PREVIOUS_SESSION_START)); Mockito.verify(messageHandler, Mockito.times(1)).sendMessage(messageHandler.obtainMessage(MessageHandler.END_ORPHAN_SESSIONS, configManager.getMpid())); }
public BaseMPMessage startSession(InternalSession session) { try { BaseMPMessage message = new BaseMPMessage.Builder(MessageType.SESSION_START) .timestamp(mAppStateManager.getSession().mSessionStartTime) .build(session, mLocation, mConfigManager.getMpid()); SharedPreferences.Editor editor = sPreferences.edit(); long timeInFg = mConfigManager.getUserStorage().getPreviousSessionForegound(); if (timeInFg > 0) { message.put(MessageKey.PREVIOUS_SESSION_LENGTH, timeInFg / 1000); mConfigManager.getUserStorage().clearPreviousTimeInForeground(); } String prevSessionId = mConfigManager.getUserStorage().getPreviousSessionId(); mConfigManager.getUserStorage().setPreviousSessionId(session.mSessionID); if (!MPUtility.isEmpty(prevSessionId)) { message.put(MessageKey.PREVIOUS_SESSION_ID, prevSessionId); } long prevSessionStart = mConfigManager.getUserStorage().getPreviousSessionStart(-1); mConfigManager.getUserStorage().setPreviousSessionStart(session.mSessionStartTime); if (prevSessionStart > 0) { message.put(MessageKey.PREVIOUS_SESSION_START, prevSessionStart); } editor.apply(); if (isFirstRunForMessage()) { setFirstRunForMessage(false); try { JSONObject firstRunMessage = createFirstRunMessage(); mMessageHandler.sendMessage(mMessageHandler.obtainMessage(MessageHandler.STORE_MESSAGE, firstRunMessage)); } catch (JSONException e) { Logger.warning("Failed to create First Run Message."); } }else{ mMessageHandler.sendMessage(mMessageHandler.obtainMessage(MessageHandler.END_ORPHAN_SESSIONS, mConfigManager.getMpid())); } mMessageHandler.sendMessage(mMessageHandler.obtainMessage(MessageHandler.STORE_MESSAGE, message)); mConfigManager.getUserStorage().incrementSessionCounter(); return message; } catch (JSONException e) { Logger.warning("Failed to create mParticle start session message."); return null; } }
MessageManager implements MessageManagerCallbacks, ReportingManager { public BaseMPMessage startSession(InternalSession session) { try { BaseMPMessage message = new BaseMPMessage.Builder(MessageType.SESSION_START) .timestamp(mAppStateManager.getSession().mSessionStartTime) .build(session, mLocation, mConfigManager.getMpid()); SharedPreferences.Editor editor = sPreferences.edit(); long timeInFg = mConfigManager.getUserStorage().getPreviousSessionForegound(); if (timeInFg > 0) { message.put(MessageKey.PREVIOUS_SESSION_LENGTH, timeInFg / 1000); mConfigManager.getUserStorage().clearPreviousTimeInForeground(); } String prevSessionId = mConfigManager.getUserStorage().getPreviousSessionId(); mConfigManager.getUserStorage().setPreviousSessionId(session.mSessionID); if (!MPUtility.isEmpty(prevSessionId)) { message.put(MessageKey.PREVIOUS_SESSION_ID, prevSessionId); } long prevSessionStart = mConfigManager.getUserStorage().getPreviousSessionStart(-1); mConfigManager.getUserStorage().setPreviousSessionStart(session.mSessionStartTime); if (prevSessionStart > 0) { message.put(MessageKey.PREVIOUS_SESSION_START, prevSessionStart); } editor.apply(); if (isFirstRunForMessage()) { setFirstRunForMessage(false); try { JSONObject firstRunMessage = createFirstRunMessage(); mMessageHandler.sendMessage(mMessageHandler.obtainMessage(MessageHandler.STORE_MESSAGE, firstRunMessage)); } catch (JSONException e) { Logger.warning("Failed to create First Run Message."); } }else{ mMessageHandler.sendMessage(mMessageHandler.obtainMessage(MessageHandler.END_ORPHAN_SESSIONS, mConfigManager.getMpid())); } mMessageHandler.sendMessage(mMessageHandler.obtainMessage(MessageHandler.STORE_MESSAGE, message)); mConfigManager.getUserStorage().incrementSessionCounter(); return message; } catch (JSONException e) { Logger.warning("Failed to create mParticle start session message."); return null; } } }
MessageManager implements MessageManagerCallbacks, ReportingManager { public BaseMPMessage startSession(InternalSession session) { try { BaseMPMessage message = new BaseMPMessage.Builder(MessageType.SESSION_START) .timestamp(mAppStateManager.getSession().mSessionStartTime) .build(session, mLocation, mConfigManager.getMpid()); SharedPreferences.Editor editor = sPreferences.edit(); long timeInFg = mConfigManager.getUserStorage().getPreviousSessionForegound(); if (timeInFg > 0) { message.put(MessageKey.PREVIOUS_SESSION_LENGTH, timeInFg / 1000); mConfigManager.getUserStorage().clearPreviousTimeInForeground(); } String prevSessionId = mConfigManager.getUserStorage().getPreviousSessionId(); mConfigManager.getUserStorage().setPreviousSessionId(session.mSessionID); if (!MPUtility.isEmpty(prevSessionId)) { message.put(MessageKey.PREVIOUS_SESSION_ID, prevSessionId); } long prevSessionStart = mConfigManager.getUserStorage().getPreviousSessionStart(-1); mConfigManager.getUserStorage().setPreviousSessionStart(session.mSessionStartTime); if (prevSessionStart > 0) { message.put(MessageKey.PREVIOUS_SESSION_START, prevSessionStart); } editor.apply(); if (isFirstRunForMessage()) { setFirstRunForMessage(false); try { JSONObject firstRunMessage = createFirstRunMessage(); mMessageHandler.sendMessage(mMessageHandler.obtainMessage(MessageHandler.STORE_MESSAGE, firstRunMessage)); } catch (JSONException e) { Logger.warning("Failed to create First Run Message."); } }else{ mMessageHandler.sendMessage(mMessageHandler.obtainMessage(MessageHandler.END_ORPHAN_SESSIONS, mConfigManager.getMpid())); } mMessageHandler.sendMessage(mMessageHandler.obtainMessage(MessageHandler.STORE_MESSAGE, message)); mConfigManager.getUserStorage().incrementSessionCounter(); return message; } catch (JSONException e) { Logger.warning("Failed to create mParticle start session 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 startSession(InternalSession session) { try { BaseMPMessage message = new BaseMPMessage.Builder(MessageType.SESSION_START) .timestamp(mAppStateManager.getSession().mSessionStartTime) .build(session, mLocation, mConfigManager.getMpid()); SharedPreferences.Editor editor = sPreferences.edit(); long timeInFg = mConfigManager.getUserStorage().getPreviousSessionForegound(); if (timeInFg > 0) { message.put(MessageKey.PREVIOUS_SESSION_LENGTH, timeInFg / 1000); mConfigManager.getUserStorage().clearPreviousTimeInForeground(); } String prevSessionId = mConfigManager.getUserStorage().getPreviousSessionId(); mConfigManager.getUserStorage().setPreviousSessionId(session.mSessionID); if (!MPUtility.isEmpty(prevSessionId)) { message.put(MessageKey.PREVIOUS_SESSION_ID, prevSessionId); } long prevSessionStart = mConfigManager.getUserStorage().getPreviousSessionStart(-1); mConfigManager.getUserStorage().setPreviousSessionStart(session.mSessionStartTime); if (prevSessionStart > 0) { message.put(MessageKey.PREVIOUS_SESSION_START, prevSessionStart); } editor.apply(); if (isFirstRunForMessage()) { setFirstRunForMessage(false); try { JSONObject firstRunMessage = createFirstRunMessage(); mMessageHandler.sendMessage(mMessageHandler.obtainMessage(MessageHandler.STORE_MESSAGE, firstRunMessage)); } catch (JSONException e) { Logger.warning("Failed to create First Run Message."); } }else{ mMessageHandler.sendMessage(mMessageHandler.obtainMessage(MessageHandler.END_ORPHAN_SESSIONS, mConfigManager.getMpid())); } mMessageHandler.sendMessage(mMessageHandler.obtainMessage(MessageHandler.STORE_MESSAGE, message)); mConfigManager.getUserStorage().incrementSessionCounter(); return message; } catch (JSONException e) { Logger.warning("Failed to create mParticle start session 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 startSession(InternalSession session) { try { BaseMPMessage message = new BaseMPMessage.Builder(MessageType.SESSION_START) .timestamp(mAppStateManager.getSession().mSessionStartTime) .build(session, mLocation, mConfigManager.getMpid()); SharedPreferences.Editor editor = sPreferences.edit(); long timeInFg = mConfigManager.getUserStorage().getPreviousSessionForegound(); if (timeInFg > 0) { message.put(MessageKey.PREVIOUS_SESSION_LENGTH, timeInFg / 1000); mConfigManager.getUserStorage().clearPreviousTimeInForeground(); } String prevSessionId = mConfigManager.getUserStorage().getPreviousSessionId(); mConfigManager.getUserStorage().setPreviousSessionId(session.mSessionID); if (!MPUtility.isEmpty(prevSessionId)) { message.put(MessageKey.PREVIOUS_SESSION_ID, prevSessionId); } long prevSessionStart = mConfigManager.getUserStorage().getPreviousSessionStart(-1); mConfigManager.getUserStorage().setPreviousSessionStart(session.mSessionStartTime); if (prevSessionStart > 0) { message.put(MessageKey.PREVIOUS_SESSION_START, prevSessionStart); } editor.apply(); if (isFirstRunForMessage()) { setFirstRunForMessage(false); try { JSONObject firstRunMessage = createFirstRunMessage(); mMessageHandler.sendMessage(mMessageHandler.obtainMessage(MessageHandler.STORE_MESSAGE, firstRunMessage)); } catch (JSONException e) { Logger.warning("Failed to create First Run Message."); } }else{ mMessageHandler.sendMessage(mMessageHandler.obtainMessage(MessageHandler.END_ORPHAN_SESSIONS, mConfigManager.getMpid())); } mMessageHandler.sendMessage(mMessageHandler.obtainMessage(MessageHandler.STORE_MESSAGE, message)); mConfigManager.getUserStorage().incrementSessionCounter(); return message; } catch (JSONException e) { Logger.warning("Failed to create mParticle start session 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; }