Simple email application for Android. Original source code: https://framagit.org/dystopia-project/simple-email
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
4.2 KiB

  1. package eu.faircode.email;
  2. /*
  3. This file is part of Safe email.
  4. Safe email is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. NetGuard is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with NetGuard. If not, see <http://www.gnu.org/licenses/>.
  14. Copyright 2018 by Marcel Bokhorst (M66B)
  15. */
  16. import android.content.Context;
  17. import android.content.res.Resources;
  18. import android.os.Build;
  19. import android.text.TextUtils;
  20. import android.util.Log;
  21. import android.util.TypedValue;
  22. import java.io.BufferedReader;
  23. import java.io.IOException;
  24. import java.io.InputStreamReader;
  25. public class Helper {
  26. static final String TAG = BuildConfig.APPLICATION_ID;
  27. static int resolveColor(Context context, int attr) {
  28. TypedValue typedValue = new TypedValue();
  29. Resources.Theme theme = context.getTheme();
  30. theme.resolveAttribute(attr, typedValue, true);
  31. return typedValue.data;
  32. }
  33. static String localizeFolderName(Context context, String name) {
  34. if ("INBOX".equals(name))
  35. return context.getString(R.string.title_folder_inbox);
  36. else if ("OUTBOX".equals(name))
  37. return context.getString(R.string.title_folder_outbox);
  38. else
  39. return name;
  40. }
  41. static String localizeFolderName(Context context, TupleFolderEx folder) {
  42. if (TextUtils.isEmpty(folder.accountName))
  43. return localizeFolderName(context, folder.name);
  44. else
  45. return localizeFolderName(context, folder.name) + "/" + folder.accountName;
  46. }
  47. static String formatThrowable(Throwable ex) {
  48. StringBuilder sb = new StringBuilder();
  49. sb.append(ex.getMessage());
  50. Throwable cause = ex.getCause();
  51. while (cause != null) {
  52. sb.append(" ").append(cause.getMessage());
  53. cause = cause.getCause();
  54. }
  55. return sb.toString();
  56. }
  57. static StringBuilder getDebugInfo() {
  58. StringBuilder sb = new StringBuilder();
  59. // Get version info
  60. sb.append(String.format("%s: %s/%d\r\n", BuildConfig.APPLICATION_ID, BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE));
  61. sb.append(String.format("Android: %s (SDK %d)\r\n", Build.VERSION.RELEASE, Build.VERSION.SDK_INT));
  62. sb.append("\r\n");
  63. // Get device info
  64. sb.append(String.format("Brand: %s\r\n", Build.BRAND));
  65. sb.append(String.format("Manufacturer: %s\r\n", Build.MANUFACTURER));
  66. sb.append(String.format("Model: %s\r\n", Build.MODEL));
  67. sb.append(String.format("Product: %s\r\n", Build.PRODUCT));
  68. sb.append(String.format("Device: %s\r\n", Build.DEVICE));
  69. sb.append(String.format("Host: %s\r\n", Build.HOST));
  70. sb.append(String.format("Display: %s\r\n", Build.DISPLAY));
  71. sb.append(String.format("Id: %s\r\n", Build.ID));
  72. sb.append("\r\n");
  73. // Get logcat
  74. Process proc = null;
  75. BufferedReader br = null;
  76. try {
  77. String[] cmd = new String[]{"logcat", "-d", "-v", "threadtime"};
  78. proc = Runtime.getRuntime().exec(cmd);
  79. br = new BufferedReader(new InputStreamReader(proc.getInputStream()));
  80. String line;
  81. while ((line = br.readLine()) != null)
  82. sb.append(line).append("\r\n");
  83. } catch (IOException ex) {
  84. Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
  85. } finally {
  86. if (br != null)
  87. try {
  88. br.close();
  89. } catch (IOException ignored) {
  90. }
  91. if (proc != null)
  92. try {
  93. proc.destroy();
  94. } catch (Throwable ex) {
  95. Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
  96. }
  97. }
  98. return sb;
  99. }
  100. }