public boolean setAssociatedFiles(List<StoredFile> attachedFiles) { this.attachedFiles = attachedFiles; if (attachedFiles == null || attachedFiles.size() == 0) { hasNoAttachments = true; return false; } else { hasNoAttachments = false; } setTextOnly(hasNoAttachments); boolean bRet = false; try { Future<Boolean> future = ApptentiveInternal.getInstance().getApptentiveTaskManager().addCompoundMessageFiles(attachedFiles); bRet = future.get(); } catch (Exception e) { ApptentiveLog.e(MESSAGES, "Unable to set associated files in worker thread"); logException(e); } finally { return bRet; } }
public void deleteAssociatedFiles() { try { Future<List<StoredFile>> future = ApptentiveInternal.getInstance().getApptentiveTaskManager().getAssociatedFiles(getNonce()); List<StoredFile> associatedFiles = future.get(); // Delete local cached files if (associatedFiles == null || associatedFiles.size() == 0) { return; } for (StoredFile file : associatedFiles) { File localFile = new File(file.getLocalFilePath()); localFile.delete(); } // Delete records from db ApptentiveInternal.getInstance().getApptentiveTaskManager().deleteAssociatedFiles(getNonce()); } catch (Exception e) { ApptentiveLog.e(MESSAGES, "Unable to delete associated files in worker thread"); logException(e); } }
if (appInBackground) { ApptentiveLog.v(PAYLOADS, "The app went to the background so we won't remove the payload from the queue"); retrySending(5000); return; } else if (responseCode == -1) { ApptentiveLog.v(PAYLOADS, "Payload failed to send due to a connection error."); retrySending(5000); return; } else if (responseCode >= 500) { ApptentiveLog.v(PAYLOADS, "Payload failed to send due to a server error."); retrySending(5000); return; deletePayload(payload.getNonce());
public void resetSdkState() { globalSharedPrefs.edit().clear().apply(); taskManager.reset(appContext); }
public List<StoredFile> getAssociatedFiles() { if (hasNoAttachments) { return null; } List<StoredFile> associatedFiles = null; try { Future<List<StoredFile>> future = ApptentiveInternal.getInstance().getApptentiveTaskManager().getAssociatedFiles(getNonce()); associatedFiles = future.get(); } catch (Exception e) { ApptentiveLog.e(MESSAGES, "Unable to get associated files in worker thread"); logException(e); } finally { return associatedFiles; } }
payload = getOldestUnsentPayloadSync(); } catch (Exception e) { ApptentiveLog.e(e, "Exception while peeking the next payload for sending");
private ApptentiveInternal(Application application, String apptentiveKey, String apptentiveSignature, String serverUrl, boolean shouldEncryptStorage) { if (StringUtils.isNullOrEmpty(apptentiveKey)) { throw new IllegalArgumentException("Apptentive Key is null or empty"); } if (StringUtils.isNullOrEmpty(apptentiveSignature)) { throw new IllegalArgumentException("Apptentive Signature is null or empty"); } this.apptentiveKey = apptentiveKey; this.apptentiveSignature = apptentiveSignature; this.serverUrl = serverUrl; SecurityManager.init(application.getApplicationContext(), shouldEncryptStorage); appContext = application.getApplicationContext(); globalSharedPrefs = application.getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE); apptentiveHttpClient = new ApptentiveHttpClient(apptentiveKey, apptentiveSignature, getEndpointBase(globalSharedPrefs)); conversationManager = new ConversationManager(appContext, Util.getInternalDir(appContext, CONVERSATIONS_DIR, true), SecurityManager.getMasterKey()); appRelease = AppReleaseManager.generateCurrentAppRelease(application, this); taskManager = new ApptentiveTaskManager(appContext, apptentiveHttpClient, SecurityManager.getMasterKey()); ApptentiveNotificationCenter.defaultCenter() .addObserver(NOTIFICATION_CONVERSATION_STATE_DID_CHANGE, this) .addObserver(NOTIFICATION_CONVERSATION_WILL_LOGOUT, this) .addObserver(NOTIFICATION_AUTHENTICATION_FAILED, this) .addObserver(NOTIFICATION_INTERACTION_MANIFEST_FETCHED, this) .addObserver(NOTIFICATION_APP_ENTERED_FOREGROUND, this) .addObserver(NOTIFICATION_APP_ENTERED_BACKGROUND, this) .addObserver(NOTIFICATION_CONFIGURATION_FETCH_DID_FINISH, this); }
public void addPayload(Payload payload) { // TODO: figure out a better way of detecting new events if (payload instanceof EventPayload) { notifyEventGenerated((EventPayload) payload); } payload.setLocalConversationIdentifier(notNull(getLocalIdentifier())); payload.setConversationId(getConversationId()); payload.setToken(getConversationToken()); payload.setEncryptionKey(getEncryptionKey()); payload.setAuthenticated(isAuthenticated()); payload.setSessionId(getSessionId()); // TODO: don't use singleton here ApptentiveInternal.getInstance().getApptentiveTaskManager().addPayload(payload); }
sendNextPayload(); // when the app comes back from the background - we need to resume sending payloads } else if (notification.hasName(NOTIFICATION_APP_ENTERED_BACKGROUND)) { appInBackground = true;
Future<Boolean> future = ApptentiveInternal.getInstance().getApptentiveTaskManager().addCompoundMessageFiles(attachmentStoredFiles); bRet = future.get(); } catch (Exception e) {