mirror of https://github.com/M66B/FairEmail.git
Debug larger files
This commit is contained in:
parent
6fa1fef827
commit
a0b3b88cc7
|
@ -30,6 +30,7 @@ import android.content.pm.PackageManager;
|
|||
import android.database.sqlite.SQLiteDatabaseCorruptException;
|
||||
import android.graphics.Paint;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Debug;
|
||||
import android.provider.Settings;
|
||||
|
@ -57,10 +58,13 @@ import androidx.lifecycle.Observer;
|
|||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.SortedMap;
|
||||
|
@ -105,9 +109,12 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
|||
private TextView tvFingerprint;
|
||||
private Button btnCharsets;
|
||||
private Button btnCiphers;
|
||||
private Button btnFiles;
|
||||
|
||||
private Group grpDebug;
|
||||
|
||||
private final static long MIN_FILE_SIZE = 1024 * 1024L;
|
||||
|
||||
private final static String[] RESET_OPTIONS = new String[]{
|
||||
"shortcuts", "fts", "language", "watchdog", "updates",
|
||||
"experiments", "query_threads", "crash_reports", "cleanup_attachments",
|
||||
|
@ -166,6 +173,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
|||
tvFingerprint = view.findViewById(R.id.tvFingerprint);
|
||||
btnCharsets = view.findViewById(R.id.btnCharsets);
|
||||
btnCiphers = view.findViewById(R.id.btnCiphers);
|
||||
btnFiles = view.findViewById(R.id.btnFiles);
|
||||
|
||||
grpDebug = view.findViewById(R.id.grpDebug);
|
||||
|
||||
|
@ -387,6 +395,16 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
new SimpleTask<SortedMap<String, Charset>>() {
|
||||
@Override
|
||||
protected void onPreExecute(Bundle args) {
|
||||
btnCharsets.setEnabled(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Bundle args) {
|
||||
btnCharsets.setEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SortedMap<String, Charset> onExecute(Context context, Bundle args) {
|
||||
return Charset.availableCharsets();
|
||||
|
@ -468,6 +486,87 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
|||
}
|
||||
});
|
||||
|
||||
final String title = getString(R.string.title_advanced_files, Helper.humanReadableByteCount(MIN_FILE_SIZE));
|
||||
btnFiles.setText(title);
|
||||
|
||||
btnFiles.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
new SimpleTask<List<File>>() {
|
||||
@Override
|
||||
protected void onPreExecute(Bundle args) {
|
||||
btnFiles.setEnabled(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Bundle args) {
|
||||
btnFiles.setEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<File> onExecute(Context context, Bundle args) {
|
||||
List<File> files = new ArrayList<>();
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
|
||||
files.addAll(getFiles(context.getFilesDir(), MIN_FILE_SIZE));
|
||||
files.addAll(getFiles(context.getCacheDir(), MIN_FILE_SIZE));
|
||||
} else
|
||||
files.addAll(getFiles(context.getDataDir(), MIN_FILE_SIZE));
|
||||
Collections.sort(files, new Comparator<File>() {
|
||||
@Override
|
||||
public int compare(File f1, File f2) {
|
||||
return -Long.compare(f1.length(), f2.length());
|
||||
}
|
||||
});
|
||||
return files;
|
||||
}
|
||||
|
||||
private List<File> getFiles(File dir, long minSize) {
|
||||
List<File> files = new ArrayList();
|
||||
File[] listed = dir.listFiles();
|
||||
if (listed != null)
|
||||
for (File file : listed)
|
||||
if (file.isDirectory())
|
||||
files.addAll(getFiles(file, minSize));
|
||||
else if (file.length() > minSize)
|
||||
files.add(file);
|
||||
return files;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onExecuted(Bundle args, List<File> files) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
sb.append("Data: ").append(getContext().getDataDir()).append("\r\n");
|
||||
sb.append("Files: ").append(getContext().getFilesDir()).append("\r\n");
|
||||
sb.append("Cache: ").append(getContext().getCacheDir()).append("\r\n");
|
||||
|
||||
for (File file : files)
|
||||
sb.append(file.getAbsolutePath())
|
||||
.append(' ')
|
||||
.append(Helper.humanReadableByteCount(file.length()))
|
||||
.append("\r\n");
|
||||
|
||||
new AlertDialog.Builder(getContext())
|
||||
.setTitle(title)
|
||||
.setMessage(sb.toString())
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// Do nothing
|
||||
}
|
||||
})
|
||||
.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Log.unexpectedError(getParentFragmentManager(), ex);
|
||||
}
|
||||
}.execute(FragmentOptionsMisc.this, new Bundle(), "setup:files");
|
||||
}
|
||||
});
|
||||
|
||||
tvFtsIndexed.setText(null);
|
||||
|
||||
DB db = DB.getInstance(getContext());
|
||||
|
|
|
@ -495,10 +495,20 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/btnCharsets" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnFiles"
|
||||
style="?android:attr/buttonStyleSmall"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_advanced_files"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/btnCiphers" />
|
||||
|
||||
<androidx.constraintlayout.widget.Group
|
||||
android:id="@+id/grpDebug"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:constraint_referenced_ids="swAuthPlain,swAuthLogin,swAuthSasl,tvProcessors,tvMemoryClass,tvMemoryUsage,tvStorageUsage,tvFingerprint,btnCharsets,btnCiphers" />
|
||||
app:constraint_referenced_ids="swAuthPlain,swAuthLogin,swAuthSasl,tvProcessors,tvMemoryClass,tvMemoryUsage,tvStorageUsage,tvFingerprint,btnCharsets,btnCiphers,btnFiles" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</eu.faircode.email.ScrollViewEx>
|
||||
|
|
|
@ -523,6 +523,7 @@
|
|||
<string name="title_advanced_storage_usage" translatable="false">Storage space: %1$s/%2$s</string>
|
||||
<string name="title_advanced_charsets" translatable="false">Charsets</string>
|
||||
<string name="title_advanced_ciphers" translatable="false">Ciphers</string>
|
||||
<string name="title_advanced_files" translatable="false">Files >%1$s</string>
|
||||
|
||||
<string name="title_advanced_manual_hint">If receiving messages is disabled, it is still possible to manually receive messages by pulling down the message list</string>
|
||||
<string name="title_advanced_poll_hint">Periodically checking for new messages will compare local and remote messages every time, which is an expensive operation that may result in extra battery usage, especially if there are a lot of messages. Always receive will prevent this by continuously following changes.</string>
|
||||
|
|
Loading…
Reference in New Issue