public synchronized EventData getEventData() { return conversation.getEventData(); // TODO: make conversation immutable }
/** * Saves conversation data to the disk synchronously. Returns <code>true</code> * if succeed. */ private synchronized void saveConversationData() throws SerializerException { if (ApptentiveLog.canLog(ApptentiveLog.Level.VERBOSE)) { ApptentiveLog.v(CONVERSATION, "Saving conversation data..."); ApptentiveLog.v(CONVERSATION, "EventData: %s", getEventData().toString()); ApptentiveLog.v(CONVERSATION, "Messages: %s", messageManager.getMessageStore().toString()); } long start = System.currentTimeMillis(); FileSerializer serializer = new EncryptedFileSerializer(conversationDataFile, encryptionKey); serializer.serialize(conversationData); ApptentiveLog.v(CONVERSATION, "Conversation data saved (took %d ms)", System.currentTimeMillis() - start); }
private void migrateEventData() { EventData eventData = conversation.getEventData(); String codePointString = prefs.getString(Constants.PREF_KEY_CODE_POINT_STORE, null); try { CodePointStore codePointStore = new CodePointStore(codePointString); Map<String, EventRecord> migratedEvents = codePointStore.migrateCodePoints(); Map<String, EventRecord> migratedInteractions = codePointStore.migrateInteractions(); if (migratedEvents != null) { eventData.setEvents(migratedEvents); } if (migratedInteractions != null) { eventData.setInteractions(migratedInteractions); } } catch (Exception e) { ApptentiveLog.w(CONVERSATION, e, "Error migrating Event Data."); logException(e); } }
public String getApplicableInteraction(String eventLabel, boolean verbose) { JSONArray invocations = optJSONArray(eventLabel); if (invocations != null) { for (int i = 0; i < invocations.length(); i++) { JSONObject invocationObject = invocations.optJSONObject(i); if (invocationObject != null) { try { Invocation invocation = new Invocation(invocationObject.toString()); Conversation conversation = ApptentiveInternal.getInstance().getConversation(); FieldManager fieldManager = new FieldManager(ApptentiveInternal.getInstance().getApplicationContext(), conversation.getVersionHistory(), conversation.getEventData(), conversation.getPerson(), conversation.getDevice(), conversation.getAppRelease()); if (invocation.isCriteriaMet(fieldManager, verbose)) { return invocation.getInteractionId(); } } catch (JSONException e) { logException(e); } } } } ApptentiveLog.v(INTERACTIONS, "No runnable Interactions for EventLabel: %s", eventLabel); return null; } }
FieldManager fieldManager = new FieldManager(context, conversation.getVersionHistory(), conversation.getEventData(), conversation.getPerson(), conversation.getDevice(), conversation.getAppRelease()); if (invocation.isCriteriaMet(fieldManager, true)) { interactionIdToLaunch = invocation.getInteractionId();
private static boolean doEngage(Conversation conversation, Context context, String eventLabel) { checkConversationQueue(); Interaction interaction = conversation.getApplicableInteraction(eventLabel, true); if (interaction != null) { String versionName = ApptentiveInternal.getInstance().getApplicationVersionName(); int versionCode = ApptentiveInternal.getInstance().getApplicationVersionCode(); conversation.getEventData().storeInteractionForCurrentAppVersion(Util.currentTimeSeconds(), versionCode, versionName, interaction.getId()); launchInteraction(context, interaction); return true; } ApptentiveLog.d(INTERACTIONS, "No interaction to show for event: '%s'", eventLabel); return false; }
public static synchronized boolean engage(Context context, Conversation conversation, String vendor, String interaction, String interactionId, String eventName, String data, Map<String, Object> customData, ExtendedData... extendedData) { checkConversationQueue(); if (context == null) { throw new IllegalArgumentException("Context is null"); } if (conversation == null) { throw new IllegalArgumentException("Conversation is null"); } Assert.assertTrue(ApptentiveInternal.isApptentiveRegistered()); if (!ApptentiveInternal.isApptentiveRegistered()) { return false; } try { String eventLabel = generateEventLabel(vendor, interaction, eventName); ApptentiveLog.i(INTERACTIONS, "Engage event: '%s'", eventLabel); String versionName = ApptentiveInternal.getInstance().getApplicationVersionName(); int versionCode = ApptentiveInternal.getInstance().getApplicationVersionCode(); conversation.getEventData().storeEventForCurrentAppVersion(Util.currentTimeSeconds(), versionCode, versionName, eventLabel); conversation.addPayload(new EventPayload(eventLabel, interactionId, data, customData, extendedData)); return doEngage(conversation, context, eventLabel); } catch (Exception e) { ApptentiveLog.e(INTERACTIONS, e, "Exception while engaging event '%s'", eventName); logException(e); } return false; }