2018-08-06 13:04:53 +00:00
|
|
|
package eu.faircode.email;
|
|
|
|
|
|
|
|
/*
|
2018-08-14 05:53:24 +00:00
|
|
|
This file is part of FairEmail.
|
2018-08-06 13:04:53 +00:00
|
|
|
|
2018-08-14 05:53:24 +00:00
|
|
|
FairEmail is free software: you can redistribute it and/or modify
|
2018-08-06 13:04:53 +00:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
NetGuard is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with NetGuard. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
Copyright 2018 by Marcel Bokhorst (M66B)
|
|
|
|
*/
|
|
|
|
|
2018-08-12 07:51:33 +00:00
|
|
|
import android.content.Context;
|
2018-08-06 13:04:53 +00:00
|
|
|
import android.content.Intent;
|
2018-08-15 07:40:18 +00:00
|
|
|
import android.os.Build;
|
2018-08-06 13:04:53 +00:00
|
|
|
import android.os.Bundle;
|
2018-08-19 06:53:56 +00:00
|
|
|
import android.util.Log;
|
2018-08-06 13:04:53 +00:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
2018-09-12 10:54:37 +00:00
|
|
|
import java.io.BufferedOutputStream;
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileOutputStream;
|
2018-08-19 06:53:56 +00:00
|
|
|
import java.io.IOException;
|
2018-09-12 10:54:37 +00:00
|
|
|
import java.io.InputStreamReader;
|
|
|
|
import java.io.OutputStream;
|
2018-08-10 11:15:09 +00:00
|
|
|
import java.io.UnsupportedEncodingException;
|
2018-09-04 05:49:58 +00:00
|
|
|
import java.text.DateFormat;
|
|
|
|
import java.text.SimpleDateFormat;
|
2018-08-06 13:04:53 +00:00
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
import javax.mail.Address;
|
|
|
|
|
2018-08-08 06:55:47 +00:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
2018-09-03 19:11:16 +00:00
|
|
|
import androidx.fragment.app.FragmentTransaction;
|
2018-08-08 06:55:47 +00:00
|
|
|
|
2018-08-06 13:04:53 +00:00
|
|
|
public class FragmentAbout extends FragmentEx {
|
2018-09-03 19:11:16 +00:00
|
|
|
private TextView tvVersion;
|
|
|
|
private Button btnLog;
|
|
|
|
private Button btnDebugInfo;
|
|
|
|
|
2018-08-06 13:04:53 +00:00
|
|
|
@Override
|
|
|
|
@Nullable
|
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
|
|
|
setSubtitle(R.string.menu_about);
|
|
|
|
|
|
|
|
View view = inflater.inflate(R.layout.fragment_about, container, false);
|
|
|
|
|
2018-09-03 19:11:16 +00:00
|
|
|
tvVersion = view.findViewById(R.id.tvVersion);
|
|
|
|
btnLog = view.findViewById(R.id.btnLog);
|
|
|
|
btnDebugInfo = view.findViewById(R.id.btnDebugInfo);
|
2018-08-06 13:04:53 +00:00
|
|
|
|
|
|
|
tvVersion.setText(getString(R.string.title_version, BuildConfig.VERSION_NAME));
|
|
|
|
|
2018-09-03 19:11:16 +00:00
|
|
|
btnLog.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
|
|
|
|
fragmentTransaction.replace(R.id.content_frame, new FragmentLogs()).addToBackStack("logs");
|
|
|
|
fragmentTransaction.commit();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-08-06 13:04:53 +00:00
|
|
|
btnDebugInfo.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
2018-08-10 11:15:09 +00:00
|
|
|
btnDebugInfo.setEnabled(false);
|
2018-08-12 07:51:33 +00:00
|
|
|
new SimpleTask<Long>() {
|
2018-08-06 13:04:53 +00:00
|
|
|
@Override
|
2018-08-12 07:51:33 +00:00
|
|
|
protected Long onLoad(Context context, Bundle args) throws UnsupportedEncodingException {
|
2018-08-15 07:40:18 +00:00
|
|
|
StringBuilder sb = new StringBuilder();
|
2018-08-10 11:15:09 +00:00
|
|
|
|
2018-08-15 07:40:18 +00:00
|
|
|
sb.append(context.getString(R.string.title_debug_info_remark) + "\n\n\n\n");
|
|
|
|
|
|
|
|
// Get version info
|
2018-09-27 06:44:02 +00:00
|
|
|
sb.append(String.format("%s: %s %s/%s\r\n",
|
|
|
|
context.getString(R.string.app_name),
|
|
|
|
BuildConfig.APPLICATION_ID,
|
|
|
|
BuildConfig.VERSION_NAME,
|
|
|
|
Helper.hasValidFingerprint(context) ? "1" : "3"));
|
2018-08-15 07:40:18 +00:00
|
|
|
sb.append(String.format("Android: %s (SDK %d)\r\n", Build.VERSION.RELEASE, Build.VERSION.SDK_INT));
|
|
|
|
sb.append("\r\n");
|
|
|
|
|
|
|
|
// Get device info
|
|
|
|
sb.append(String.format("Brand: %s\r\n", Build.BRAND));
|
|
|
|
sb.append(String.format("Manufacturer: %s\r\n", Build.MANUFACTURER));
|
|
|
|
sb.append(String.format("Model: %s\r\n", Build.MODEL));
|
|
|
|
sb.append(String.format("Product: %s\r\n", Build.PRODUCT));
|
|
|
|
sb.append(String.format("Device: %s\r\n", Build.DEVICE));
|
|
|
|
sb.append(String.format("Host: %s\r\n", Build.HOST));
|
|
|
|
sb.append(String.format("Display: %s\r\n", Build.DISPLAY));
|
|
|
|
sb.append(String.format("Id: %s\r\n", Build.ID));
|
|
|
|
sb.append("\r\n");
|
|
|
|
|
2018-08-19 06:53:56 +00:00
|
|
|
String body = "<pre>" + sb.toString().replaceAll("\\r?\\n", "<br />") + "</pre>";
|
|
|
|
|
2018-08-13 06:00:59 +00:00
|
|
|
EntityMessage draft;
|
2018-09-12 10:54:37 +00:00
|
|
|
DB db = DB.getInstance(context);
|
2018-08-12 12:47:52 +00:00
|
|
|
try {
|
|
|
|
db.beginTransaction();
|
|
|
|
|
|
|
|
EntityFolder drafts = db.folder().getPrimaryDrafts();
|
|
|
|
if (drafts == null)
|
|
|
|
throw new IllegalArgumentException(context.getString(R.string.title_no_drafts));
|
|
|
|
|
2018-08-13 06:00:59 +00:00
|
|
|
draft = new EntityMessage();
|
2018-08-12 12:47:52 +00:00
|
|
|
draft.account = drafts.account;
|
|
|
|
draft.folder = drafts.id;
|
2018-08-15 07:40:18 +00:00
|
|
|
draft.msgid = EntityMessage.generateMessageId();
|
|
|
|
draft.to = new Address[]{Helper.myAddress()};
|
2018-09-08 09:10:34 +00:00
|
|
|
draft.subject = context.getString(R.string.app_name) + " " + BuildConfig.VERSION_NAME + " debug info";
|
2018-09-16 10:44:13 +00:00
|
|
|
draft.content = true;
|
2018-08-12 12:47:52 +00:00
|
|
|
draft.received = new Date().getTime();
|
|
|
|
draft.seen = false;
|
|
|
|
draft.ui_seen = false;
|
2018-09-07 15:12:43 +00:00
|
|
|
draft.flagged = false;
|
|
|
|
draft.ui_flagged = false;
|
2018-08-12 12:47:52 +00:00
|
|
|
draft.ui_hide = false;
|
2018-09-01 16:34:16 +00:00
|
|
|
draft.ui_found = false;
|
2018-08-12 12:47:52 +00:00
|
|
|
draft.id = db.message().insertMessage(draft);
|
2018-08-19 06:53:56 +00:00
|
|
|
draft.write(context, body);
|
2018-08-12 12:47:52 +00:00
|
|
|
|
2018-09-12 10:54:37 +00:00
|
|
|
// Attach recent log
|
|
|
|
{
|
|
|
|
EntityAttachment log = new EntityAttachment();
|
|
|
|
log.message = draft.id;
|
|
|
|
log.sequence = 1;
|
|
|
|
log.name = "log.txt";
|
|
|
|
log.type = "text/plain";
|
|
|
|
log.size = null;
|
|
|
|
log.progress = 0;
|
|
|
|
log.id = db.attachment().insertAttachment(log);
|
|
|
|
|
|
|
|
OutputStream os = null;
|
|
|
|
File file = EntityAttachment.getFile(context, log.id);
|
|
|
|
try {
|
|
|
|
os = new BufferedOutputStream(new FileOutputStream(file));
|
|
|
|
|
|
|
|
int size = 0;
|
|
|
|
long from = new Date().getTime() - 24 * 3600 * 1000L;
|
|
|
|
DateFormat DF = SimpleDateFormat.getTimeInstance();
|
|
|
|
for (EntityLog entry : db.log().getLogs(from)) {
|
|
|
|
String line = String.format("%s %s\r\n", DF.format(entry.time), entry.data);
|
|
|
|
byte[] bytes = line.getBytes();
|
|
|
|
os.write(bytes);
|
|
|
|
size += bytes.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
log.size = size;
|
|
|
|
log.progress = null;
|
|
|
|
log.available = true;
|
|
|
|
db.attachment().updateAttachment(log);
|
|
|
|
} finally {
|
|
|
|
if (os != null)
|
|
|
|
os.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attach logcat
|
|
|
|
{
|
|
|
|
EntityAttachment logcat = new EntityAttachment();
|
|
|
|
logcat.message = draft.id;
|
|
|
|
logcat.sequence = 2;
|
|
|
|
logcat.name = "logcat.txt";
|
|
|
|
logcat.type = "text/plain";
|
|
|
|
logcat.size = null;
|
|
|
|
logcat.progress = 0;
|
|
|
|
logcat.id = db.attachment().insertAttachment(logcat);
|
|
|
|
|
|
|
|
Process proc = null;
|
|
|
|
BufferedReader br = null;
|
|
|
|
OutputStream os = null;
|
|
|
|
File file = EntityAttachment.getFile(context, logcat.id);
|
|
|
|
try {
|
|
|
|
os = new BufferedOutputStream(new FileOutputStream(file));
|
|
|
|
|
|
|
|
String[] cmd = new String[]{"logcat",
|
|
|
|
"-d",
|
|
|
|
"-v", "threadtime",
|
|
|
|
//"-t", "1000",
|
|
|
|
Helper.TAG + ":I"};
|
|
|
|
proc = Runtime.getRuntime().exec(cmd);
|
|
|
|
br = new BufferedReader(new InputStreamReader(proc.getInputStream()));
|
|
|
|
|
|
|
|
int size = 0;
|
|
|
|
String line;
|
|
|
|
while ((line = br.readLine()) != null) {
|
|
|
|
line += "\r\n";
|
|
|
|
byte[] bytes = line.getBytes();
|
|
|
|
os.write(bytes);
|
|
|
|
size += bytes.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
logcat.size = size;
|
|
|
|
logcat.progress = null;
|
|
|
|
logcat.available = true;
|
|
|
|
db.attachment().updateAttachment(logcat);
|
|
|
|
} finally {
|
|
|
|
if (os != null)
|
|
|
|
os.close();
|
|
|
|
if (br != null)
|
|
|
|
br.close();
|
|
|
|
if (proc != null)
|
|
|
|
proc.destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-13 06:00:59 +00:00
|
|
|
EntityOperation.queue(db, draft, EntityOperation.ADD);
|
2018-08-12 12:47:52 +00:00
|
|
|
|
2018-08-13 06:00:59 +00:00
|
|
|
db.setTransactionSuccessful();
|
2018-08-19 06:53:56 +00:00
|
|
|
} catch (IOException ex) {
|
|
|
|
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
|
|
|
|
return null;
|
2018-08-12 12:47:52 +00:00
|
|
|
} finally {
|
|
|
|
db.endTransaction();
|
|
|
|
}
|
2018-08-13 06:00:59 +00:00
|
|
|
|
|
|
|
EntityOperation.process(context);
|
|
|
|
|
|
|
|
return draft.id;
|
2018-08-06 13:04:53 +00:00
|
|
|
}
|
2018-08-10 11:15:09 +00:00
|
|
|
|
|
|
|
@Override
|
2018-08-12 07:51:33 +00:00
|
|
|
protected void onLoaded(Bundle args, Long id) {
|
2018-08-10 11:15:09 +00:00
|
|
|
btnDebugInfo.setEnabled(true);
|
2018-08-19 06:53:56 +00:00
|
|
|
if (id != null)
|
|
|
|
startActivity(new Intent(getContext(), ActivityCompose.class)
|
|
|
|
.putExtra("action", "edit")
|
|
|
|
.putExtra("id", id));
|
2018-08-11 05:02:13 +00:00
|
|
|
}
|
2018-08-10 11:15:09 +00:00
|
|
|
|
2018-08-11 05:02:13 +00:00
|
|
|
@Override
|
2018-08-12 07:51:33 +00:00
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
2018-08-11 05:02:13 +00:00
|
|
|
btnDebugInfo.setEnabled(true);
|
2018-09-15 05:49:54 +00:00
|
|
|
Helper.unexpectedError(getContext(), ex);
|
2018-08-10 11:15:09 +00:00
|
|
|
}
|
2018-08-12 07:51:33 +00:00
|
|
|
}.load(FragmentAbout.this, new Bundle());
|
2018-08-06 13:04:53 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-09-30 15:33:57 +00:00
|
|
|
//boolean debug = PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean("debug", false);
|
|
|
|
//btnLog.setVisibility(debug || BuildConfig.DEBUG ? View.VISIBLE : View.GONE);
|
|
|
|
//btnDebugInfo.setVisibility(debug || BuildConfig.DEBUG ? View.VISIBLE : View.GONE);
|
2018-09-26 14:43:22 +00:00
|
|
|
|
2018-08-06 13:04:53 +00:00
|
|
|
return view;
|
|
|
|
}
|
|
|
|
}
|