mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-07 09:38:52 -06:00
Send bug report on the body of email, instead of attachment
This commit is contained in:
@@ -154,7 +154,7 @@ abstract public class BaseActivity extends AppCompatActivity implements Thread.U
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
HabitsApplication.generateLogFile();
|
HabitsApplication.dumpBugReportToFile();
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ import java.io.File;
|
|||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
public class HabitsApplication extends Application
|
public class HabitsApplication extends Application
|
||||||
{
|
{
|
||||||
@@ -87,6 +88,7 @@ public class HabitsApplication extends Application
|
|||||||
|
|
||||||
public static String getLogcat() throws IOException
|
public static String getLogcat() throws IOException
|
||||||
{
|
{
|
||||||
|
int maxNLines = 250;
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
String[] command = new String[] { "logcat", "-d"};
|
String[] command = new String[] { "logcat", "-d"};
|
||||||
@@ -95,10 +97,18 @@ public class HabitsApplication extends Application
|
|||||||
InputStreamReader in = new InputStreamReader(process.getInputStream());
|
InputStreamReader in = new InputStreamReader(process.getInputStream());
|
||||||
BufferedReader bufferedReader = new BufferedReader(in);
|
BufferedReader bufferedReader = new BufferedReader(in);
|
||||||
|
|
||||||
|
LinkedList<String> log = new LinkedList<>();
|
||||||
|
|
||||||
String line;
|
String line;
|
||||||
while ((line = bufferedReader.readLine()) != null)
|
while ((line = bufferedReader.readLine()) != null)
|
||||||
{
|
{
|
||||||
builder.append(line);
|
log.addLast(line);
|
||||||
|
if(log.size() > maxNLines) log.removeFirst();
|
||||||
|
}
|
||||||
|
|
||||||
|
for(String l : log)
|
||||||
|
{
|
||||||
|
builder.append(l);
|
||||||
builder.append('\n');
|
builder.append('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,10 +140,8 @@ public class HabitsApplication extends Application
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static File generateLogFile() throws IOException
|
public static File dumpBugReportToFile() throws IOException
|
||||||
{
|
{
|
||||||
String logcat = getLogcat();
|
|
||||||
String deviceInfo = getDeviceInfo();
|
|
||||||
String date = DateHelper.getBackupDateFormat().format(DateHelper.getLocalTime());
|
String date = DateHelper.getBackupDateFormat().format(DateHelper.getLocalTime());
|
||||||
|
|
||||||
if(context == null) throw new RuntimeException("application context should not be null");
|
if(context == null) throw new RuntimeException("application context should not be null");
|
||||||
@@ -142,10 +150,17 @@ public class HabitsApplication extends Application
|
|||||||
|
|
||||||
File logFile = new File(String.format("%s/Log %s.txt", dir.getPath(), date));
|
File logFile = new File(String.format("%s/Log %s.txt", dir.getPath(), date));
|
||||||
FileWriter output = new FileWriter(logFile);
|
FileWriter output = new FileWriter(logFile);
|
||||||
output.write(deviceInfo);
|
output.write(generateBugReport());
|
||||||
output.write(logcat);
|
|
||||||
output.close();
|
output.close();
|
||||||
|
|
||||||
return logFile;
|
return logFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public static String generateBugReport() throws IOException
|
||||||
|
{
|
||||||
|
String logcat = getLogcat();
|
||||||
|
String deviceInfo = getDeviceInfo();
|
||||||
|
return deviceInfo + "\n" + logcat;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ import org.isoron.uhabits.widgets.HistoryWidgetProvider;
|
|||||||
import org.isoron.uhabits.widgets.ScoreWidgetProvider;
|
import org.isoron.uhabits.widgets.ScoreWidgetProvider;
|
||||||
import org.isoron.uhabits.widgets.StreakWidgetProvider;
|
import org.isoron.uhabits.widgets.StreakWidgetProvider;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class MainActivity extends BaseActivity
|
public class MainActivity extends BaseActivity
|
||||||
@@ -239,12 +238,25 @@ public class MainActivity extends BaseActivity
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File logFile = HabitsApplication.generateLogFile();
|
HabitsApplication.dumpBugReportToFile();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
// ignored
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String log = "---------- BUG REPORT BEGINS ----------\n";
|
||||||
|
log += HabitsApplication.generateBugReport();
|
||||||
|
log += "---------- BUG REPORT ENDS ------------\n";
|
||||||
|
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.setAction(Intent.ACTION_SENDTO);
|
intent.setAction(Intent.ACTION_SEND);
|
||||||
intent.setData(Uri.parse(getString(R.string.bugReportURL)));
|
intent.setType("message/rfc822");
|
||||||
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(logFile));
|
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "dev@loophabits.org" });
|
||||||
|
intent.putExtra(Intent.EXTRA_SUBJECT, "Bug Report - Loop Habit Tracker");
|
||||||
|
intent.putExtra(Intent.EXTRA_TEXT, log);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
|
|||||||
Reference in New Issue
Block a user