Export and share log instead of saving to file
This commit is contained in:
parent
50426a07cf
commit
6df27ff3c4
|
@ -102,6 +102,16 @@
|
|||
<action android:name="android.telecom.CallScreeningService" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="dummydomain.yetanothercallblocker.fileprovider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/file_paths" />
|
||||
</provider>
|
||||
</application>
|
||||
|
||||
</manifest>
|
|
@ -1,5 +1,6 @@
|
|||
package dummydomain.yetanothercallblocker;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
|
@ -23,11 +24,13 @@ import androidx.preference.SwitchPreferenceCompat;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import dummydomain.yetanothercallblocker.preference.IntListPreference;
|
||||
import dummydomain.yetanothercallblocker.utils.DebuggingUtils;
|
||||
import dummydomain.yetanothercallblocker.utils.FileUtils;
|
||||
import dummydomain.yetanothercallblocker.work.UpdateScheduler;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
@ -100,7 +103,7 @@ public class SettingsActivity extends AppCompatActivity
|
|||
private static final String PREF_CATEGORY_NOTIFICATIONS = "categoryNotifications";
|
||||
private static final String PREF_SCREEN_ADVANCED = "screenAdvanced";
|
||||
private static final String PREF_COUNTRY_CODES_INFO = "countryCodesInfo";
|
||||
private static final String PREF_SAVE_LOGCAT_TO_FILE = "saveLogcatToFile";
|
||||
private static final String PREF_EXPORT_LOGCAT = "exportLogcat";
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(SettingsFragment.class);
|
||||
|
||||
|
@ -244,9 +247,9 @@ public class SettingsActivity extends AppCompatActivity
|
|||
= requireNonNull(findPreference(Settings.PREF_COUNTRY_CODE_FOR_REVIEWS_OVERRIDE));
|
||||
countryCodeForReviewsPreference.setOnPreferenceChangeListener(countryCodeChangeListener);
|
||||
|
||||
requireNonNull((Preference) findPreference(PREF_SAVE_LOGCAT_TO_FILE))
|
||||
requireNonNull((Preference) findPreference(PREF_EXPORT_LOGCAT))
|
||||
.setOnPreferenceClickListener(preference -> {
|
||||
saveLogcatToFile();
|
||||
exportLogcat();
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
@ -257,19 +260,19 @@ public class SettingsActivity extends AppCompatActivity
|
|||
callScreeningPref.setChecked(PermissionHelper.isCallScreeningHeld(getActivity()));
|
||||
}
|
||||
|
||||
private void saveLogcatToFile() {
|
||||
boolean success = false;
|
||||
private void exportLogcat() {
|
||||
Activity activity = getActivity();
|
||||
|
||||
String path = null;
|
||||
try {
|
||||
DebuggingUtils.saveLogcatToFile(getActivity(), true);
|
||||
success = true;
|
||||
path = DebuggingUtils.saveLogcatInCache(activity);
|
||||
} catch (IOException e) {
|
||||
LOG.warn("saveLogcatToFile()", e);
|
||||
LOG.warn("exportLogcat()", e);
|
||||
}
|
||||
|
||||
Toast.makeText(getActivity(), success
|
||||
? R.string.save_logcat_to_file_done
|
||||
: R.string.save_logcat_to_file_error,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
if (path != null) {
|
||||
FileUtils.shareFile(activity, new File(path));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,7 +72,11 @@ public class DebuggingUtils {
|
|||
}
|
||||
|
||||
public static void saveLogcatToFile(Context context, boolean external) throws IOException {
|
||||
saveLogcatToFile(context, external, getDateString());
|
||||
saveLogcatToFile(getFilesDir(context, external).getAbsolutePath(), getDateString());
|
||||
}
|
||||
|
||||
public static String saveLogcatInCache(Context context) throws IOException {
|
||||
return saveLogcatToFile(context.getCacheDir().getAbsolutePath(), getDateString());
|
||||
}
|
||||
|
||||
private static void saveCrashToFile(Context context, Throwable th,
|
||||
|
@ -86,13 +90,13 @@ public class DebuggingUtils {
|
|||
}
|
||||
}
|
||||
|
||||
private static void saveLogcatToFile(Context context, boolean external, String name)
|
||||
throws IOException {
|
||||
String path = getFilesDir(context, external).getAbsolutePath()
|
||||
+ "/logcat_" + name + ".txt";
|
||||
private static String saveLogcatToFile(String path, String name) throws IOException {
|
||||
path += "/logcat_" + name + ".txt";
|
||||
|
||||
Log.d(TAG, "Saving logcat to " + path);
|
||||
Runtime.getRuntime().exec("logcat -d -f " + path);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
private static String getDateString() {
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package dummydomain.yetanothercallblocker.utils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
|
||||
import androidx.core.app.ShareCompat;
|
||||
import androidx.core.content.FileProvider;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class FileUtils {
|
||||
|
||||
private static final String FILEPROVIDER_AUTHORITY = "dummydomain.yetanothercallblocker.fileprovider";
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(FileUtils.class);
|
||||
|
||||
public static void shareFile(Activity activity, File file) {
|
||||
try {
|
||||
Uri uri = FileProvider.getUriForFile(activity, FILEPROVIDER_AUTHORITY, file);
|
||||
|
||||
ShareCompat.IntentBuilder shareBuilder = ShareCompat.IntentBuilder.from(activity)
|
||||
.setStream(uri)
|
||||
.setType(activity.getContentResolver().getType(uri));
|
||||
|
||||
shareBuilder.getIntent().addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
|
||||
shareBuilder.startChooser();
|
||||
} catch (Exception e) {
|
||||
LOG.warn("shareFile()", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -123,10 +123,6 @@
|
|||
<string name="save_crashes_to_external_storage_summary">Sauvegarder les rapports et les journaux d\'incidents sur le stockage public, sinon les rapports d\'incidents sont sauvegardés dans un dossier privé de l\'application. Les rapports peuvent contenir des données sensibles (numéros de téléphone, noms de contact). D\'autres applications ayant une autorisation de stockage peuvent avoir accès à ces données dans le stockage public</string>
|
||||
<string name="save_logcat_on_crash">Sauvegarder les journaux de log en cas de crash</string>
|
||||
<string name="save_logcat_on_crash_summary">Sauvegarder la copie du journal de log en cas de crash (en plus d\'un stacktrace de base)</string>
|
||||
<string name="save_logcat_to_file">Sauvegarder le journal de log</string>
|
||||
<string name="save_logcat_to_file_summary">Sauvegarder la copie du journal de log dans un fichier sur le stockage public (/sdcard/Android/data/dummydomain.yetanothercallblocker/files/). Les rapports peuvent contenir des données sensibles (numéros de téléphone, noms de contact). D\'autres applications ayant une autorisation de stockage peuvent avoir accès à ces données sur le stockage public</string>
|
||||
<string name="save_logcat_to_file_done">Terminé</string>
|
||||
<string name="save_logcat_to_file_error">Erreur</string>
|
||||
<string name="no_number"><![CDATA[<aucun numéro>]]></string>
|
||||
|
||||
<string name="open_debug_activity">Ouvrir l\'écran de débogage</string>
|
||||
|
|
|
@ -111,9 +111,7 @@
|
|||
<string name="save_crashes_to_external_storage_summary">Сохранять отчёты об ошибках и логи в общее хранилище. В противном случае отчёты сохраняются в личную папку приложения. Отчёты могут содержать конфиденциальные данные (номера телефонов, имена контактов). Другие приложения с разрешением на доступ к хранилищу могут иметь доступ к этим данным в общем хранилище</string>
|
||||
<string name="save_logcat_on_crash">Сохранять logcat при ошибках</string>
|
||||
<string name="save_logcat_on_crash_summary">Сохранять содержимое logcat при ошибках (в дополнение к обычныму stacktrace)</string>
|
||||
<string name="save_logcat_to_file">Сохранить logcat</string>
|
||||
<string name="save_logcat_to_file_summary">Сохранить содержимое logcat в файл в общем хранилище (/sdcard/Android/data/dummydomain.yetanothercallblocker/files/). Отчёты могут содержать конфиденциальные данные (номера телефонов, имена контактов). Другие приложения с разрешением на доступ к хранилищу могут иметь доступ к этим данным в общем хранилище</string>
|
||||
<string name="save_logcat_to_file_done">Выполнено</string>
|
||||
<string name="save_logcat_to_file_error">Ошибка</string>
|
||||
<string name="export_logcat">Экспортировать logcat</string>
|
||||
<string name="export_logcat_summary">Экспортировать и поделиться содержимым logcat с приложением по вашему выбору (например, с email-клиентом). Отчёты могут содержать конфиденциальные данные (номера телефонов, имена контактов). Только выбранное приложение получит доступ к этим данным</string>
|
||||
<string name="no_number"><![CDATA[<нет номера>]]></string>
|
||||
</resources>
|
|
@ -123,10 +123,8 @@
|
|||
<string name="save_crashes_to_external_storage_summary">Save crash reports and logs to public storage, otherwise crash reports are saved to a private app folder. The reports may contain sensitive data (phone numbers, contact names). Other apps with storage permission may have access to this data in public storage</string>
|
||||
<string name="save_logcat_on_crash">Save logcat on crash</string>
|
||||
<string name="save_logcat_on_crash_summary">Save logcat output on crash (in addition to a basic stacktrace)</string>
|
||||
<string name="save_logcat_to_file">Save logcat</string>
|
||||
<string name="save_logcat_to_file_summary">Save logcat output to a file in public storage (/sdcard/Android/data/dummydomain.yetanothercallblocker/files/). The reports may contain sensitive data (phone numbers, contact names). Other apps with storage permission may have access to this data in public storage</string>
|
||||
<string name="save_logcat_to_file_done">Done</string>
|
||||
<string name="save_logcat_to_file_error">Error</string>
|
||||
<string name="export_logcat">Export logcat</string>
|
||||
<string name="export_logcat_summary">Export and share logcat contents with an app of your choosing (for example with an email client). The reports may contain sensitive data (phone numbers, contact names). Only the chosen app will have access to this data</string>
|
||||
<string name="no_number"><![CDATA[<no number>]]></string>
|
||||
|
||||
<string name="open_debug_activity">Open debug screen</string>
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
<paths>
|
||||
<cache-path
|
||||
name="cache"
|
||||
path="./" />
|
||||
<external-files-path
|
||||
name="files"
|
||||
path="./" />
|
||||
</paths>
|
|
@ -82,6 +82,11 @@
|
|||
<PreferenceCategory
|
||||
app:key="categoryDebugging"
|
||||
app:title="@string/settings_category_debugging">
|
||||
<Preference
|
||||
app:key="exportLogcat"
|
||||
app:persistent="false"
|
||||
app:summary="@string/export_logcat_summary"
|
||||
app:title="@string/export_logcat" />
|
||||
<SwitchPreferenceCompat
|
||||
app:key="saveCrashesToExternalStorage"
|
||||
app:summary="@string/save_crashes_to_external_storage_summary"
|
||||
|
@ -90,11 +95,6 @@
|
|||
app:key="saveLogcatOnCrash"
|
||||
app:summary="@string/save_logcat_on_crash_summary"
|
||||
app:title="@string/save_logcat_on_crash" />
|
||||
<Preference
|
||||
app:key="saveLogcatToFile"
|
||||
app:persistent="false"
|
||||
app:summary="@string/save_logcat_to_file_summary"
|
||||
app:title="@string/save_logcat_to_file" />
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
</PreferenceCategory>
|
||||
|
|
Loading…
Reference in New Issue