mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-12 18:57:36 +01:00
Huami: Keep track of last debug logs titmestamp
This commit is contained in:
parent
58d4ebf509
commit
3902db5abd
@ -16,7 +16,7 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.fetch;
|
||||
|
||||
import android.widget.Toast;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -25,15 +25,11 @@ import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Locale;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSupport;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
||||
@ -43,7 +39,7 @@ public class FetchDebugLogsOperation extends AbstractFetchOperation {
|
||||
|
||||
private FileOutputStream logOutputStream;
|
||||
|
||||
public FetchDebugLogsOperation(HuamiSupport support) {
|
||||
public FetchDebugLogsOperation(final HuamiSupport support) {
|
||||
super(support);
|
||||
setName("fetch debug logs");
|
||||
}
|
||||
@ -54,7 +50,7 @@ public class FetchDebugLogsOperation extends AbstractFetchOperation {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void startFetching(TransactionBuilder builder) {
|
||||
protected void startFetching(final TransactionBuilder builder) {
|
||||
File dir;
|
||||
try {
|
||||
dir = FileUtils.getExternalFilesDir();
|
||||
@ -62,19 +58,17 @@ public class FetchDebugLogsOperation extends AbstractFetchOperation {
|
||||
return;
|
||||
}
|
||||
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss", Locale.US);
|
||||
String filename = "huamidebug_" + dateFormat.format(new Date()) + ".log";
|
||||
final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss", Locale.US);
|
||||
final String filename = "huamidebug_" + dateFormat.format(new Date()) + ".log";
|
||||
|
||||
File outputFile = new File(dir, filename );
|
||||
File outputFile = new File(dir, filename);
|
||||
try {
|
||||
logOutputStream = new FileOutputStream(outputFile);
|
||||
} catch (IOException e) {
|
||||
LOG.warn("could not create file " + outputFile, e);
|
||||
return;
|
||||
}
|
||||
|
||||
GregorianCalendar sinceWhen = BLETypeConversions.createCalendar();
|
||||
sinceWhen.add(Calendar.DAY_OF_MONTH, -10);
|
||||
final GregorianCalendar sinceWhen = getLastSuccessfulSyncTime();
|
||||
startFetching(builder, HuamiFetchDataType.DEBUG_LOGS.getCode(), sinceWhen);
|
||||
}
|
||||
|
||||
@ -89,8 +83,8 @@ public class FetchDebugLogsOperation extends AbstractFetchOperation {
|
||||
try {
|
||||
logOutputStream.close();
|
||||
logOutputStream = null;
|
||||
} catch (IOException e) {
|
||||
LOG.warn("could not close output stream", e);
|
||||
} catch (final IOException e) {
|
||||
LOG.error("could not close output stream", e);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -109,8 +103,7 @@ public class FetchDebugLogsOperation extends AbstractFetchOperation {
|
||||
try {
|
||||
logOutputStream.write(value, 1, value.length - 1);
|
||||
} catch (final IOException e) {
|
||||
LOG.warn("could not write to output stream", e);
|
||||
operationValid = false;
|
||||
LOG.error("could not write to output stream", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user