Share debug info: always use attachment

* share debug info: always use attachment (before: send inline if it was small enough)
* use FileProvider for debug info attachment (for Android 7 compatibility)
* dav4android, ical4android fixes
pull/2/head
Ricki Hirner 8 years ago
parent 2e78e1e746
commit 8e5ca5a72d

@ -185,6 +185,16 @@
android:exported="true"
android:label="@string/debug_info_title">
</activity>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="at.bitfire.davdroid.log"
android:grantUriPermissions="true"
android:exported="false">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/log_paths" />
</provider>
</application>

@ -94,6 +94,8 @@ public class App extends Application {
boolean logToFile = settings.getBoolean(LOG_TO_EXTERNAL_STORAGE, false),
logVerbose = logToFile || Log.isLoggable(log.getName(), Log.DEBUG);
App.log.info("Verbose logging: " + logVerbose);
// set logging level according to preferences
final Logger rootLogger = Logger.getLogger("");
rootLogger.setLevel(logVerbose ? Level.ALL : Level.INFO);

@ -18,16 +18,17 @@ import android.content.Context;
import android.content.Intent;
import android.content.Loader;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.CalendarContract;
import android.provider.ContactsContract;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.commons.lang3.text.WordUtils;
@ -56,8 +57,6 @@ public class DebugInfoActivity extends AppCompatActivity implements LoaderManage
KEY_AUTHORITY = "authority",
KEY_PHASE = "phase";
private static final int MAX_INLINE_REPORT_LENGTH = 8000;
TextView tvReport;
String report;
@ -85,31 +84,25 @@ public class DebugInfoActivity extends AppCompatActivity implements LoaderManage
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "DAVdroid debug info");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "DAVdroid " + BuildConfig.VERSION_NAME + " debug info");
boolean inline = false;
try {
File debugInfoDir = new File(getCacheDir(), "debug-info");
debugInfoDir.mkdir();
if (report.length() > MAX_INLINE_REPORT_LENGTH)
// report is too long for inline text, send it as an attachment
try {
reportFile = File.createTempFile("davdroid-debug", ".txt", getExternalCacheDir());
App.log.fine("Writing debug info to " + reportFile.getAbsolutePath());
FileWriter writer = new FileWriter(reportFile);
writer.write(report);
writer.close();
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(reportFile));
} catch (IOException e) {
// let's hope the report is < 1 MB (Android IPC limit)
inline = true;
}
else
inline = true;
reportFile = new File(debugInfoDir, "davdroid-debug.txt");
App.log.fine("Writing debug info to " + reportFile.getAbsolutePath());
FileWriter writer = new FileWriter(reportFile);
writer.write(report);
writer.close();
if (inline)
sendIntent.putExtra(Intent.EXTRA_TEXT, report);
sendIntent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(this, "at.bitfire.davdroid.log", reportFile));
startActivity(sendIntent);
startActivity(Intent.createChooser(sendIntent, null));
} catch (IOException e) {
App.log.log(Level.SEVERE, "Couldn't write debug info file", e);
Toast.makeText(this, e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
}
}
}

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright © Ricki Hirner (bitfire web engineering).
~ All rights reserved. This program and the accompanying materials
~ are made available under the terms of the GNU Public License v3.0
~ which accompanies this distribution, and is available at
~ http://www.gnu.org/licenses/gpl.html
-->
<paths>
<!-- debug info can be deleted after it has been used, so let's use a cache dir -->
<cache-path name="debug-info" path="debug-info/"/>
</paths>

@ -1 +1 @@
Subproject commit fc4bd45099d918590f65f85b7d3f2d978e9dc2d3
Subproject commit de3a570bcd1ce108f240f493c562e7b3ee0bfc4f

@ -1 +1 @@
Subproject commit dd2510bc582cd210162a95fcbfe6bc52cff01da3
Subproject commit d049f7b5e50b7ade2405b16d0ce8ae518160f642
Loading…
Cancel
Save