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