Skip to content

Commit

Permalink
Merge pull request #376 from alxndrsn/smssync_log-closing
Browse files Browse the repository at this point in the history
Don't close the `FileManager` on every write
Fixes #375
  • Loading branch information
eyedol committed Apr 22, 2016
2 parents 60e0832 + f43d7d8 commit b8cd41a
Show file tree
Hide file tree
Showing 17 changed files with 51 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ private void sendSMSWithMessageResultsAPIEnabled(SyncUrl syncUrl, List<Message>
msg.setMessageType(Message.Type.TASK);
if (response.getUuids().contains(msg.getMessageUuid())) {
sendTaskSms(msg);
mFileManager.appendAndClose(mContext.getString(R.string.processed_task,
mFileManager.append(mContext.getString(R.string.processed_task,
msg.getMessageBody()));
}
}
Expand Down Expand Up @@ -378,13 +378,13 @@ public void performTask() {
messageHttpClient.execute();
gson = new Gson();
final String response = messageHttpClient.getResponse().body().string();
mFileManager.appendAndClose("HTTP Client Response: " + response);
mFileManager.append("HTTP Client Response: " + response);
smssyncResponses = gson.fromJson(response, SmssyncResponse.class);
} catch (Exception e) {
Logger.log(TAG, "Task checking crashed " + e.getMessage() + " response: "
+ messageHttpClient.getResponse());
try {
mFileManager.appendAndClose(
mFileManager.append(
"Task crashed: " + e.getMessage() + " response: " + messageHttpClient
.getResponse().body().string());
} catch (IOException e1) {
Expand All @@ -394,7 +394,7 @@ public void performTask() {

if (smssyncResponses != null) {
Logger.log(TAG, "TaskCheckResponse: " + smssyncResponses.toString());
mFileManager.appendAndClose("TaskCheckResponse: " + smssyncResponses.toString());
mFileManager.append("TaskCheckResponse: " + smssyncResponses.toString());

if (smssyncResponses.getPayload() != null) {
String task = smssyncResponses.getPayload().getTask();
Expand Down Expand Up @@ -424,7 +424,7 @@ public void performTask() {
}
}

mFileManager.appendAndClose(
mFileManager.append(
mContext.getString(R.string.finish_task_check) + " " + mErrorMessage + " for "
+ syncUrl.getUrl());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,13 @@ protected void deleteMessage(Message message) {
}

protected void logActivities(@StringRes int id) {
mFileManager.appendAndClose(mContext.getString(id));
mFileManager.append(mContext.getString(id));
}

protected void deleteFromSmsInbox(Message message) {
if (mPrefsFactory.autoDelete().get()) {
mProcessSms.delSmsFromInbox(map(message));
mFileManager.appendAndClose(
mFileManager.append(
mContext.getString(R.string.auto_message_deleted, message.getMessageBody()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private void sendMessageResultPOSTRequest(SyncUrl syncUrl, List<MessageResult> r
try {
urlSecretEncoded = URLEncoder.encode(urlSecret, "UTF-8");
} catch (java.io.UnsupportedEncodingException e) {
mFileManager.appendAndClose(e.getLocalizedMessage());
mFileManager.append(e.getLocalizedMessage());
}
newEndPointURL = newEndPointURL.concat(urlSecretEncoded);
}
Expand All @@ -141,10 +141,10 @@ private void sendMessageResultPOSTRequest(SyncUrl syncUrl, List<MessageResult> r
mAppHttpClient.setRequestBody(body);
mAppHttpClient.execute();
} catch (Exception e) {
mFileManager.appendAndClose(mContext.getString(R.string.message_processed_failed));
mFileManager.append(mContext.getString(R.string.message_processed_failed));
} finally {
if (200 == mAppHttpClient.getResponse().code()) {
mFileManager.appendAndClose(mContext.getString(R.string.message_processed_success));
mFileManager.append(mContext.getString(R.string.message_processed_success));
}
}
}
Expand All @@ -171,24 +171,24 @@ public MessagesUUIDSResponse sendQueuedMessagesPOSTRequest(SyncUrl syncUrl,
mAppHttpClient.execute();
} catch (Exception e) {
e.printStackTrace();
mFileManager.appendAndClose("process crashed");
mFileManager.appendAndClose(mContext.getString(R.string.message_processed_failed));
mFileManager.appendAndClose(
mFileManager.append("process crashed");
mFileManager.append(mContext.getString(R.string.message_processed_failed));
mFileManager.append(
mContext.getString(R.string.message_processed_failed) + " " + e
.getMessage());
} finally {
if (200 == mAppHttpClient.getResponse().code()) {

mFileManager.appendAndClose(
mFileManager.append(
mContext.getString(R.string.message_processed_success));
response = parseMessagesUUIDSResponse(mAppHttpClient);
response.setSuccess(true);
mFileManager.appendAndClose(
mFileManager.append(
mContext.getString(R.string.message_processed_success));

} else {
response = new MessagesUUIDSResponse(mAppHttpClient.getResponse().code());
mFileManager.appendAndClose(
mFileManager.append(
mContext.getString(R.string.queued_messages_request_status,
mAppHttpClient.getResponse().code(),
mAppHttpClient.getResponse()));
Expand Down Expand Up @@ -217,7 +217,7 @@ public MessagesUUIDSResponse sendMessageResultGETRequest(SyncUrl syncUrl) {
try {
urlSecretEncoded = URLEncoder.encode(urlSecret, "UTF-8");
} catch (java.io.UnsupportedEncodingException e) {
mFileManager.appendAndClose(e.getLocalizedMessage());
mFileManager.append(e.getLocalizedMessage());
}
newEndPointURL = newEndPointURL.concat(urlSecretEncoded);
}
Expand All @@ -227,19 +227,19 @@ public MessagesUUIDSResponse sendMessageResultGETRequest(SyncUrl syncUrl) {
mAppHttpClient.setMethod(BaseHttpClient.HttpMethod.GET);
mAppHttpClient.execute();
} catch (JSONException e) {
mFileManager.appendAndClose(
mFileManager.append(
mContext.getString(R.string.message_processed_json_failed) + " " + e
.getMessage());
} catch (Exception e) {
mFileManager.appendAndClose(
mFileManager.append(
mContext.getString(R.string.message_processed_failed) + " " + e.getMessage());
} finally {
if (200 == mAppHttpClient.getResponse().code()) {
response = parseMessagesUUIDSResponse(mAppHttpClient);
response.setSuccess(true);
} else {
response = new MessagesUUIDSResponse(mAppHttpClient.getResponse().code());
mFileManager.appendAndClose(
mFileManager.append(
mContext.getString(R.string.messages_result_request_status,
mAppHttpClient.getResponse().code(), mAppHttpClient.getResponse()));
}
Expand Down Expand Up @@ -271,7 +271,7 @@ private MessagesUUIDSResponse parseMessagesUUIDSResponse(AppHttpClient client) {
} catch (Exception e) {
e.printStackTrace();
response = new MessagesUUIDSResponse(client.getResponse().code());
mFileManager.appendAndClose(mContext.getString(R.string.message_processed_json_failed));
mFileManager.append(mContext.getString(R.string.message_processed_json_failed));
}
return response;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,13 @@ private void setHttpEntity(SyncScheme.SyncDataFormat format) throws Exception {
case JSON:
body = RequestBody.create(JSON, DataFormatUtil.makeJSONString(getParams()));
log("setHttpEntity format JSON");
mFileManager.appendAndClose("setHttpEntity format JSON");
mFileManager.append("setHttpEntity format JSON");
break;
case XML:
body = RequestBody.create(XML,
DataFormatUtil.makeXMLString(getParams(), "payload", UTF_8.name()));
log("setHttpEntity format XML");
mFileManager.appendAndClose(mContext.getString(R.string.http_entity_format, "XML"));
mFileManager.append(mContext.getString(R.string.http_entity_format, "XML"));
break;
case URLEncoded:
log("setHttpEntity format URLEncoded");
Expand All @@ -178,12 +178,12 @@ private void setHttpEntity(SyncScheme.SyncDataFormat format) throws Exception {
for (HttpNameValuePair pair : params) {
formEncodingBuilder.add(pair.getName(), pair.getValue());
}
mFileManager.appendAndClose(
mFileManager.append(
mContext.getString(R.string.http_entity_format, "URLEncoded"));
body = formEncodingBuilder.build();
break;
default:
mFileManager.appendAndClose(mContext.getString(R.string.invalid_data_format));
mFileManager.append(mContext.getString(R.string.invalid_data_format));
throw new Exception("Invalid data format");
}

Expand All @@ -200,7 +200,7 @@ public void setClientError(String error) {
Resources res = mContext.getResources();
mClientError = String.format(Locale.getDefault(), "%s",
res.getString(R.string.sending_failed_custom_error, error));
mFileManager.appendAndClose(mClientError);
mFileManager.append(mClientError);
}

public String getServerError() {
Expand All @@ -213,7 +213,7 @@ public void setServerError(String error, int statusCode) {
mServerError = String
.format(res.getString(R.string.sending_failed_custom_error, error),
res.getString(R.string.sending_failed_http_code, statusCode));
mFileManager.appendAndClose(mServerError);
mFileManager.append(mServerError);
}

public SmssyncResponse getServerSuccessResp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ public void lowBatteryLevelRequest(int batteryLevel) {
mAppHttpClient.setMethod(BaseHttpClient.HttpMethod.POST);
mAppHttpClient.execute();
} catch (Exception e) {
mFileManager.appendAndClose(e.getMessage());
mFileManager.append(e.getMessage());
} finally {
if ((mAppHttpClient.getResponse()) != null && (200 == mAppHttpClient
.getResponse().code())) {
mFileManager.appendAndClose(
mFileManager.append(
mContext.getResources()
.getString(R.string.successful_alert_to_server));
}
Expand Down Expand Up @@ -125,11 +125,11 @@ public void smsSendFailedRequest(String resultMessage,
mAppHttpClient.setMethod(BaseHttpClient.HttpMethod.POST);
mAppHttpClient.execute();
} catch (Exception e) {
mFileManager.appendAndClose(e.getMessage());
mFileManager.append(e.getMessage());
} finally {
if (mAppHttpClient.getResponse() != null) {
if (200 == mAppHttpClient.getResponse().code()) {
mFileManager.appendAndClose(mContext.getResources().getString(
mFileManager.append(mContext.getResources().getString(
R.string.successful_alert_to_server));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public String isServerOKRequest(Context context) {
try {
mAppHttpClient.execute();
} catch (Exception e) {
mFileManager.appendAndClose(e.getMessage());
mFileManager.append(e.getMessage());
}

if (responseCode != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ public void onReceive(Context context, Intent intent) {
if (shutdown) {
final long currentTime = System.currentTimeMillis();
final String time = Utility.formatTimestamp(context, currentTime);
fileManager.appendAndClose(context.getString(R.string.device_shutdown, time));
fileManager.append(context.getString(R.string.device_shutdown, time));
}

if (rebooted) {
fileManager.appendAndClose(context.getString(R.string.device_reboot));
fileManager.append(context.getString(R.string.device_reboot));
// Is SMSsync enabled
if (prefsFactory.serviceEnabled().get()) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ public void run() {
mAlertPresenter.lostConnectionThread.start();
}
App.getAppComponent().fileManager()
.appendAndClose(context.getString(R.string.no_data_connection));
.append(context.getString(R.string.no_data_connection));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void onReceive(final Context context, Intent intent) {
AlertPresenter alertPresenter = App.getAppComponent().alertPresenter();
if (mBatteryLow) {
// is smssync service enabled
fileManager.appendAndClose(context.getString(R.string.battery_low));
fileManager.append(context.getString(R.string.battery_low));
if (prefsFactory.serviceEnabled().get()) {
Utility.clearAll(context);
// Stop the service that pushes pending messages
Expand All @@ -86,7 +86,7 @@ public void run() {
}

if (batteryOkay) {
fileManager.appendAndClose(context.getString(R.string.battery_okay));
fileManager.append(context.getString(R.string.battery_okay));
// is smssync enabled
if (prefsFactory.serviceEnabled().get()) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ public void onReceive(Context context, Intent intent) {
resultMessage = context.getResources().getString(R.string.sms_delivered);
Toast.makeText(context, context.getResources().getString(R.string.sms_delivered),
Toast.LENGTH_LONG);
fileManager.appendAndClose(context.getResources().getString(
fileManager.append(context.getResources().getString(
R.string.sms_delivered));
break;
case Activity.RESULT_CANCELED:
resultMessage = context.getResources().getString(R.string.sms_not_delivered);
Toast.makeText(context,
context.getResources().getString(R.string.sms_not_delivered),
Toast.LENGTH_LONG);
fileManager.appendAndClose(
fileManager.append(
context.getResources().getString(R.string.sms_not_delivered));
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,6 @@ private void log(String message) {

private void logActivities(String message) {
FileManager fileManager = App.getAppComponent().fileManager();
fileManager.appendAndClose(message);
fileManager.append(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ protected void executeTask(Intent intent) {
}
return;
}
mFileManager.appendAndClose(getString(R.string.no_data_connection));
mFileManager.append(getString(R.string.no_data_connection));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void onCreate() {
@Override
public void executeTask(Intent intent) {
log(getString(R.string.checking_scheduled_message));
mFileManager.appendAndClose(getString(R.string.checking_scheduled_message));
mFileManager.append(getString(R.string.checking_scheduled_message));
mProcessMessageResult.processMessageResult();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public Scheduler(Context context, FileManager fileManager, Intent intent, int re
public void stopScheduler() {
if (mAlarmManager != null && mPendingIntent != null) {
Logger.log(CLASS_TAG, "Stop scheduler");
mFileManager.appendAndClose(mContext.getString(R.string.stopping_scheduler));
mFileManager.append(mContext.getString(R.string.stopping_scheduler));
mAlarmManager.cancel(mPendingIntent);
}
}
Expand All @@ -75,7 +75,7 @@ public void updateScheduler(long interval) {
Logger.log(CLASS_TAG, "updating scheduler");
if (mAlarmManager != null && mPendingIntent != null) {
Logger.log(CLASS_TAG, "Update scheduler to " + interval);
mFileManager.appendAndClose(mContext.getString(R.string.scheduler_updated_to));
mFileManager.append(mContext.getString(R.string.scheduler_updated_to));
mAlarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime() + 60000, interval, mPendingIntent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void runMessageResultsService() {
final Intent intent = new Intent(mContext,
MessageResultsScheduledReceiver.class);
Logger.log(CLASS_TAG, "Message Results service started - interval: " + interval);
mFileManager.appendAndClose("Message Results service started - interval: " + interval);
mFileManager.append("Message Results service started - interval: " + interval);
// run the service
runServices(intent, ServiceConstants.MESSAGE_RESULTS_SCHEDULED_SERVICE_REQUEST_CODE,
interval);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ protected void handleSmsReceived(Intent intent) {
}
log("handleSmsReceived() messagesUuid: " + messagesUuid);
// Log received SMS
mFileManager.appendAndClose(
mFileManager.append(
getString(R.string.received_msg, msg.getMessageBody(), msg.getMessageFrom()));

// Route the SMS
Expand All @@ -300,7 +300,7 @@ private void showNotification(boolean status) {
} else {
Utility.showFailNotification(this, messagesBody,
getString(R.string.sending_succeeded));
mFileManager.appendAndClose(getString(R.string.sending_succeeded));
mFileManager.append(getString(R.string.sending_succeeded));
}
statusIntent.putExtra("sentstatus", 0);
sendBroadcast(statusIntent);
Expand Down
Loading

0 comments on commit b8cd41a

Please sign in to comment.