From 53b2381ad86aaaab7d93147759f7e900df33c658 Mon Sep 17 00:00:00 2001 From: Guillaume Beraudo Date: Tue, 4 Oct 2011 10:10:42 +0200 Subject: [PATCH] Fix bug report generation temp file Use application space to store the temporary file if it cannot be stored in the default place. --- src/org/linphone/AboutActivity.java | 35 +++++++++++++++++------------ 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/org/linphone/AboutActivity.java b/src/org/linphone/AboutActivity.java index 8fd0c7474..3f0397805 100644 --- a/src/org/linphone/AboutActivity.java +++ b/src/org/linphone/AboutActivity.java @@ -73,26 +73,32 @@ public class AboutActivity extends Activity implements OnClickListener { thread.start(); } + private File writeLogs(String logs, File directory) { + File tempFile = null; + try { + tempFile = File.createTempFile("bugreport", ".txt", directory); + tempFile.deleteOnExit(); + FileWriter writer = new FileWriter(tempFile); + writer.append(logs); + return tempFile; + } catch (IOException e) { + Toast.makeText(this, getString(R.string.about_error_generating_bugreport_attachement), Toast.LENGTH_LONG).show(); + Log.e(e, "couldn't write to temporary file"); + return null; + } + } + private void onLogsRead(String logs) { - File tempFile; if (logs == null) { Toast.makeText(this, getString(R.string.about_logs_not_found), Toast.LENGTH_SHORT).show(); } else { - - try { - tempFile = File.createTempFile("bugreport", ".txt"); - tempFile.deleteOnExit(); - FileWriter writer = new FileWriter(tempFile); - writer.append(logs); - } catch (IOException e) { - Toast.makeText(this, getString(R.string.about_error_generating_bugreport_attachement), Toast.LENGTH_LONG).show(); - Log.e(e, "couldn't write to temporary file"); - return; - } finally { - thread = null; + File tempFile = writeLogs(logs, null); + if (tempFile == null) { + // If writing to temporary file to default location failed + // Write one to our storage place + tempFile = writeLogs(logs, getFilesDir()); } - Intent intent = new Intent(Intent.ACTION_SEND); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setType("plain/text"); @@ -114,6 +120,7 @@ public class AboutActivity extends Activity implements OnClickListener { @Override public void run() { onLogsRead(logs); + thread=null; } }); super.run();