Don't use external storage for crash/test reports.

This commit is contained in:
akwizgran
2016-01-28 16:29:06 +00:00
parent ce9a81ff98
commit 2584fb52b9
3 changed files with 32 additions and 133 deletions

View File

@@ -8,7 +8,6 @@ import android.content.Intent;
import android.content.res.Resources;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.AsyncTask;
@@ -29,13 +28,10 @@ import org.briarproject.android.util.AndroidUtils;
import org.briarproject.android.util.HorizontalBorder;
import org.briarproject.android.util.LayoutUtils;
import org.briarproject.android.util.ListLoadingProgressBar;
import org.briarproject.api.android.AndroidExecutor;
import org.briarproject.util.StringUtils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection;
@@ -44,8 +40,6 @@ import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.logging.Logger;
import java.util.regex.Pattern;
@@ -53,8 +47,8 @@ import static android.bluetooth.BluetoothAdapter.SCAN_MODE_CONNECTABLE;
import static android.bluetooth.BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE;
import static android.content.Intent.ACTION_SEND;
import static android.content.Intent.EXTRA_EMAIL;
import static android.content.Intent.EXTRA_STREAM;
import static android.content.Intent.EXTRA_SUBJECT;
import static android.content.Intent.EXTRA_TEXT;
import static android.net.ConnectivityManager.TYPE_MOBILE;
import static android.net.ConnectivityManager.TYPE_WIFI;
import static android.net.wifi.WifiManager.WIFI_STATE_ENABLED;
@@ -63,28 +57,25 @@ import static android.view.Gravity.CENTER_HORIZONTAL;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static android.widget.LinearLayout.VERTICAL;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.android.TestingConstants.SHARE_CRASH_REPORTS;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1;
public class CrashReportActivity extends AppCompatActivity implements OnClickListener {
public class CrashReportActivity extends AppCompatActivity
implements OnClickListener {
private static final Logger LOG =
Logger.getLogger(CrashReportActivity.class.getName());
private final AndroidExecutor androidExecutor =
new AndroidExecutorImpl(getApplication());
private ScrollView scroll = null;
private ListLoadingProgressBar progress = null;
private LinearLayout status = null;
private File temp = null;
private volatile String stack = null;
private volatile int pid = -1;
private volatile BluetoothAdapter bt = null;
@Override
public void onCreate(Bundle state) {
@@ -93,6 +84,7 @@ public class CrashReportActivity extends AppCompatActivity implements OnClickLis
Intent i = getIntent();
stack = i.getStringExtra("briar.STACK_TRACE");
pid = i.getIntExtra("briar.PID", -1);
bt = BluetoothAdapter.getDefaultAdapter();
LinearLayout layout = new LinearLayout(this);
layout.setLayoutParams(MATCH_MATCH);
@@ -138,12 +130,6 @@ public class CrashReportActivity extends AppCompatActivity implements OnClickLis
refresh();
}
@Override
public void onDestroy() {
super.onDestroy();
if (temp != null) temp.delete();
}
@Override
public void onBackPressed() {
// show home screen, otherwise we are crashing again
@@ -322,19 +308,6 @@ public class CrashReportActivity extends AppCompatActivity implements OnClickLis
statusMap.put("Wi-Fi:", wifiStatus);
// Is Bluetooth available?
BluetoothAdapter bt = null;
try {
bt = androidExecutor.submit(new Callable<BluetoothAdapter>() {
public BluetoothAdapter call() throws Exception {
return BluetoothAdapter.getDefaultAdapter();
}
}).get();
} catch (InterruptedException e) {
LOG.warning("Interrupted while getting BluetoothAdapter");
Thread.currentThread().interrupt();
} catch (ExecutionException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
}
boolean btAvailable = bt != null;
// Is Bluetooth enabled?
boolean btEnabled = bt != null && bt.isEnabled() &&
@@ -401,43 +374,19 @@ public class CrashReportActivity extends AppCompatActivity implements OnClickLis
}
private void share() {
new AsyncTask<Void, Void, Map<String, String>>() {
@Override
protected Map<String, String> doInBackground(Void... args) {
return getStatusMap();
}
@Override
protected void onPostExecute(Map<String, String> result) {
try {
File shared = Environment.getExternalStorageDirectory();
temp = File.createTempFile("crash", ".txt", shared);
if (LOG.isLoggable(INFO))
LOG.info("Writing to " + temp.getPath());
PrintStream p = new PrintStream(new FileOutputStream(temp));
for (Entry<String, String> e : result.entrySet()) {
p.println(e.getKey());
p.println(e.getValue());
p.println();
}
p.flush();
p.close();
sendEmail(Uri.fromFile(temp));
} catch (IOException e) {
if (LOG.isLoggable(WARNING))
LOG.log(WARNING, e.toString(), e);
}
}
}.execute();
}
private void sendEmail(Uri attachment) {
StringBuilder s = new StringBuilder();
for (Entry<String, String> e : getStatusMap().entrySet()) {
s.append(e.getKey());
s.append('\n');
s.append(e.getValue());
s.append("\n\n");
}
String body = s.toString();
Intent i = new Intent(ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(EXTRA_EMAIL, new String[] { "briartest@gmail.com" });
i.putExtra(EXTRA_EMAIL, new String[] { "contact@briarproject.org" });
i.putExtra(EXTRA_SUBJECT, "Crash report");
i.putExtra(EXTRA_STREAM, attachment);
i.putExtra(EXTRA_TEXT, body);
startActivity(Intent.createChooser(i, "Send to developers"));
}
}