diff --git a/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java b/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java index 1643f63bbb..57e830375a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java +++ b/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java @@ -124,6 +124,7 @@ public class ApplicationContext extends Application implements DependencyInjecto public SignalCommunicationModule communicationModule; private Job firebaseInstanceIdJob; private Handler conversationListNotificationHandler; + private PersistentLogger persistentLogger; private volatile boolean isAppVisible; @@ -135,6 +136,10 @@ public class ApplicationContext extends Application implements DependencyInjecto return this.conversationListNotificationHandler; } + public PersistentLogger getPersistentLogger() { + return this.persistentLogger; + } + @Override public void onCreate() { super.onCreate(); @@ -277,7 +282,10 @@ public class ApplicationContext extends Application implements DependencyInjecto } private void initializeLogging() { - Log.initialize(new AndroidLogger(), new PersistentLogger(this)); + if (persistentLogger == null) { + persistentLogger = new PersistentLogger(this); + } + Log.initialize(new AndroidLogger(), persistentLogger); } private void initializeCrashHandling() { diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/ShareLogsDialog.kt b/app/src/main/java/org/thoughtcrime/securesms/preferences/ShareLogsDialog.kt index 58e0bc8df4..9ff7ebbc43 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/preferences/ShareLogsDialog.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/ShareLogsDialog.kt @@ -1,14 +1,20 @@ package org.thoughtcrime.securesms.preferences +import android.content.Intent +import android.os.Build import android.view.LayoutInflater +import android.widget.Toast import androidx.appcompat.app.AlertDialog import androidx.lifecycle.lifecycleScope import kotlinx.android.synthetic.main.dialog_share_logs.view.* import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlinx.coroutines.launch +import network.loki.messenger.BuildConfig import network.loki.messenger.R +import org.thoughtcrime.securesms.ApplicationContext import org.thoughtcrime.securesms.conversation.v2.utilities.BaseDialog +import org.thoughtcrime.securesms.providers.BlobProvider class ShareLogsDialog : BaseDialog() { @@ -31,7 +37,28 @@ class ShareLogsDialog : BaseDialog() { private fun shareLogs() { shareJob?.cancel() shareJob = lifecycleScope.launch(Dispatchers.IO) { + val persistentLogger = ApplicationContext.getInstance(context).persistentLogger + try { + val logs = persistentLogger.logs.get() + val fileName = "${Build.MANUFACTURER}-${Build.DEVICE}-API${Build.VERSION.SDK_INT}-v${BuildConfig.VERSION_NAME}.log" + val logUri = BlobProvider().forData(logs.toByteArray()) + .withFileName(fileName) + .withMimeType("text/plain") + .createForSingleSessionOnDisk(requireContext(),null) + val shareIntent = Intent().apply { + action = Intent.ACTION_SEND + putExtra(Intent.EXTRA_STREAM, logUri) + type = "text/plain" + } + + dismiss() + + startActivity(Intent.createChooser(shareIntent, getString(R.string.share))) + } catch (e: Exception) { + Toast.makeText(context,"Error saving logs", Toast.LENGTH_LONG).show() + dismiss() + } } } diff --git a/app/src/main/res/layout/dialog_share_logs.xml b/app/src/main/res/layout/dialog_share_logs.xml index e6f48f3a01..1d8cf124c1 100644 --- a/app/src/main/res/layout/dialog_share_logs.xml +++ b/app/src/main/res/layout/dialog_share_logs.xml @@ -42,10 +42,10 @@ android:text="@string/cancel" />