Add share log file. Issue #1146

This commit is contained in:
Pavel Elagin 2018-08-28 15:03:57 +03:00 committed by Andreas Shimokawa
parent 4d1ce2b72c
commit 6904a62d41
6 changed files with 80 additions and 7 deletions

View File

@ -228,6 +228,10 @@ public class GBApplication extends Application {
logging.setupLogging(enabled);
}
public static String getLogPath(){
return logging.getLogPath();
}
private void setupExceptionHandler() {
LoggingExceptionHandler handler = new LoggingExceptionHandler(Thread.getDefaultUncaughtExceptionHandler());
Thread.setDefaultUncaughtExceptionHandler(handler);

View File

@ -54,6 +54,13 @@ public abstract class Logging {
}
}
public String getLogPath() {
if (fileLogger != null)
return fileLogger.getFile();
else
return null;
}
public void debugLoggingConfiguration() {
// For debugging problems with the logback configuration
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();

View File

@ -17,12 +17,15 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.activities;
import android.app.AlertDialog;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.support.v4.app.NotificationCompat;
@ -39,6 +42,7 @@ import android.widget.Toast;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.ArrayList;
import java.util.Objects;
@ -53,9 +57,9 @@ import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
import nodomain.freeyourgadget.gadgetbridge.model.RecordedDataTypes;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
import static android.content.Intent.EXTRA_SUBJECT;
import static nodomain.freeyourgadget.gadgetbridge.util.GB.NOTIFICATION_CHANNEL_ID;
public class DebugActivity extends AbstractGBActivity {
private static final Logger LOG = LoggerFactory.getLogger(DebugActivity.class);
@ -235,12 +239,58 @@ public class DebugActivity extends AbstractGBActivity {
testNewFunctionality();
}
});
Button shareLogButton = findViewById(R.id.shareLog);
shareLogButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showWarning();
}
});
}
private void showWarning() {
new AlertDialog.Builder(this)
.setCancelable(true)
.setTitle(R.string.warning)
.setMessage(R.string.share_log_warning)
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String fileName = GBApplication.getLogPath();
if (fileName != null && fileName.length() > 0) {
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("*/*");
emailIntent.putExtra(EXTRA_SUBJECT, "Gadgetbridge log file");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(fileName)));
startActivity(Intent.createChooser(emailIntent, "Share File"));
}
}
})
.setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// do nothing
}
})
.show();
}
private void testNewFunctionality() {
GBApplication.deviceService().onTestNewFunction();
}
private void shareLog() {
String fileName = GBApplication.getLogPath();
if(fileName != null && fileName.length() > 0) {
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("*/*");
emailIntent.putExtra(EXTRA_SUBJECT, "Gadgetbridge log file");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(fileName)));
startActivity(Intent.createChooser(emailIntent, "Share File"));
}
}
private void testNotification() {
Intent notificationIntent = new Intent(getApplicationContext(), DebugActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK

View File

@ -138,6 +138,13 @@
grid:layout_columnSpan="2"
grid:layout_gravity="fill_horizontal"
android:text="Test New Functionality" />
<Button
android:id="@+id/shareLog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
grid:layout_columnSpan="2"
grid:layout_gravity="fill_horizontal"
android:text="@string/share_log" />
</android.support.v7.widget.GridLayout>
</ScrollView>

View File

@ -522,7 +522,7 @@
<string name="devicetype_amazfit_cor">Amazfit Cor</string>
<string name="menuitem_shortcut_alipay">Alipay (ярлык)</string>
<string name="menuitem_alipay">Alipay</string>
<string name="on">Вкл.</string>
<string name="on">Вкл.</string>
<string name="select_all">Выбрать все</string>
<string name="share">Поделиться</string>
<string name="kind_firmware">Прошивка</string>
@ -573,7 +573,7 @@
<string name="preferences_miband2_settings">Настройки Mi Band 2</string>
<string name="preferences_miband3_settings">Настройки Mi Band 3</string>
<string name="menuitem_more">Ещё</string>
<string name="menuitem_music">Музыка</string>
<string name="menuitem_music">Музыка</string>
<string name="controlcenter_calibrate_device">Калибровать устройство</string>
@ -588,15 +588,16 @@
<string name="watch9_calibration_button">Калибровка</string>
<string name="title_activity_watch9_pairing">Сопряжение Watch 9</string>
<string name="title_activity_watch9_calibration">Калибровка Watch 9</string>
<string name="mi3_prefs_band_screen_unlock">Разблокировать экран устройства</string>
<string name="mi3_prefs_band_screen_unlock">Разблокировать экран устройства</string>
<string name="mi3_prefs_band_screen_unlock_summary">Смахните вверх, чтобы разблокировать экран устройства</string>
<string name="german">Немецкий язык</string>
<string name="italian">Итальянский язык</string>
<string name="french">Французский язык</string>
<string name="polish">Польский язык</string>
<string name="korean">Корейский язык</string>
<string name="japanese">Японский язык</string>
<string name="norwegian_bokmal">Норвежский (литературный)</string>
</resources>
<string name="share_log">Поделиться лог-файлом</string>
<string name="share_log_warning">Файлы журнала Gadgetbridge могут содержать личную информацию, например уникальные идентификаторы: (устройство, MAC-адрес), предпочтения в музыке и т.д. Рассмотрите возможность редактирования файла и удаления этой информации перед отправкой файла общедоступное место.</string>
<string name="warning">Внимание!</string>
</resources>

View File

@ -509,6 +509,7 @@
<string name="dbmanagementactivity_overwrite">Overwrite</string>
<string name="Cancel">Cancel</string>
<string name="Delete">Delete</string>
<string name="ok">Ok</string>
<!-- Strings related to Vibration Activity -->
<string name="title_activity_vibration">Vibration</string>
@ -630,4 +631,7 @@
<string name="watch9_calibration_button">Calibrate</string>
<string name="title_activity_watch9_pairing">Watch 9 pairing</string>
<string name="title_activity_watch9_calibration">Watch 9 calibration</string>
<string name="share_log">Share log</string>
<string name="share_log_warning">Please keep in mind Gadgetbridge log files may contain lots of personal information, including but not limited to health data, unique identifiers (such as a device MAC address), music preferences, etc. Consider editing the file and removing this information before sending the file to a public issue report.</string>
<string name="warning">Warning!</string>
</resources>