Implementata pulizia dei file di log.

Forzata chiusura app in caso di uncaught exception.
This commit is contained in:
Giuseppe Scorrano 2023-03-23 10:30:52 +01:00
parent d3c518b7df
commit e704bd1597
4 changed files with 40 additions and 58 deletions

View File

@ -70,19 +70,19 @@ public class MainApplication extends Application {
// handler listener // handler listener
private Thread.UncaughtExceptionHandler _unCaughtExceptionHandler = private final Thread.UncaughtExceptionHandler _unCaughtExceptionHandler =
new Thread.UncaughtExceptionHandler() { new Thread.UncaughtExceptionHandler() {
@Override @Override
public void uncaughtException(Thread thread, Throwable ex) { public void uncaughtException(Thread thread, Throwable ex) {
try {
UtilityLogger.error(new Exception(ex));
} catch (Exception e) {
Log.e("Uncaught error", "Exception Logger failed!", e);
//MainApplication.exit();
}
// re-throw critical exception further to the os (important) // re-throw critical exception further to the os (important)
defaultUncaughtExceptionHandler.uncaughtException(thread, ex); defaultUncaughtExceptionHandler.uncaughtException(thread, ex);
try {
UtilityLogger.error(new Exception(ex));
MainApplication.exit();
} catch (Exception e) {
Log.e("Uncaught error", "Exception Logger failed!", e);
}
} }
}; };

View File

@ -2,6 +2,7 @@ package it.integry.integrywmsnative.core.context;
import android.content.Context; import android.content.Context;
import com.annimon.stream.Stream;
import com.google.firebase.crashlytics.FirebaseCrashlytics; import com.google.firebase.crashlytics.FirebaseCrashlytics;
import com.orhanobut.logger.AndroidLogAdapter; import com.orhanobut.logger.AndroidLogAdapter;
import com.orhanobut.logger.DiskLogAdapter; import com.orhanobut.logger.DiskLogAdapter;
@ -91,6 +92,32 @@ public class AppContext {
logsFolder = new File(mApplicationContext.getExternalFilesDir(null).getAbsolutePath()); logsFolder = new File(mApplicationContext.getExternalFilesDir(null).getAbsolutePath());
int maxBytesSize = 5 * 1024 * 1024; int maxBytesSize = 5 * 1024 * 1024;
Logger.addLogAdapter(new DiskLogAdapter(logsFolder, maxBytesSize)); Logger.addLogAdapter(new DiskLogAdapter(logsFolder, maxBytesSize));
removeOldLogs(logsFolder);
}
private void removeOldLogs(File logsFolder) {
var files = logsFolder.listFiles();
if (files == null || files.length <= 1)
return;
var logFiles = Stream.of(files)
.sortBy(x -> -1 * x.lastModified())
.skip(1)
.toList();
for (var logFile : logFiles) {
boolean isDeleted = logFile.delete();
}
files = logsFolder.listFiles();
if (files == null || files.length > 1)
return;
final boolean isRenamed = files[0].renameTo(new File(files[0].getParentFile().getAbsolutePath() + "/" + "logs_0.csv"));
} }
} }

View File

@ -39,6 +39,9 @@ public class ColliDataRecoverService {
if(isFilePresent(CommonConst.Files.RECOVER_COLLO_FILE)) { if(isFilePresent(CommonConst.Files.RECOVER_COLLO_FILE)) {
loadLocalFile(); loadLocalFile();
} }
if(mtbColtsSessions == null)
mtbColtsSessions = new ArrayList<>();
} }
public boolean thereIsAnExistantSession() { public boolean thereIsAnExistantSession() {
@ -47,7 +50,6 @@ public class ColliDataRecoverService {
public List<Integer> getAllSessionIDs() { public List<Integer> getAllSessionIDs() {
if(thereIsAnExistantSession()) { if(thereIsAnExistantSession()) {
return Stream.of(mtbColtsSessions) return Stream.of(mtbColtsSessions)
.map(ColliDataRecoverDTO::getId) .map(ColliDataRecoverDTO::getId)
.toList(); .toList();
@ -56,7 +58,6 @@ public class ColliDataRecoverService {
} }
public ColliDataRecoverDTO getSession(Integer sessionID) { public ColliDataRecoverDTO getSession(Integer sessionID) {
if(sessionID == null) return null; if(sessionID == null) return null;
return getIfExists(sessionID); return getIfExists(sessionID);

View File

@ -1210,8 +1210,9 @@ public class SpedizioneViewModel {
.setOrders(orders); .setOrders(orders);
this.mColliScaricoRESTConsumer.createUDS(createUDSRequestDTO, createdUDS -> { this.mColliScaricoRESTConsumer.createUDS(createUDSRequestDTO, createdUDS -> {
this.mCurrentMtbColt = createdUDS;
mMtbColtSessionID = this.mColliDataRecoverService.startNewSession(createdUDS, mTestateOrdini); mMtbColtSessionID = this.mColliDataRecoverService.startNewSession(createdUDS, mTestateOrdini);
this.mCurrentMtbColt = createdUDS;
this.mIsNewLU = true; this.mIsNewLU = true;
if (onComplete != null) onComplete.run(); if (onComplete != null) onComplete.run();
@ -1342,53 +1343,6 @@ public class SpedizioneViewModel {
this.sendOnRowSaved(); this.sendOnRowSaved();
this.sendOnLoadingEnded(); this.sendOnLoadingEnded();
}, this::sendError); }, this::sendError);
// MtbColt mtbColt = new MtbColt()
// .setNumCollo(mtbColrToUpdate.getNumCollo())
// .setDataCollo(mtbColrToUpdate.getDataColloS())
// .setSerCollo(mtbColrToUpdate.getSerCollo())
// .setGestione(mtbColrToUpdate.getGestione())
// .setMtbColr(new ObservableArrayList<>());
// mtbColt.setOperation(CommonModelConsts.OPERATION.NO_OP);
//
// final MtbColr mtbColr = (MtbColr) mtbColrToUpdate.clone();
// mtbColr.setOperation(CommonModelConsts.OPERATION.INSERT);
// mtbColr.setRiga(null)
// .setPesoLordoKg(null)
// .setPesoNettoKg(null)
// .setNumCnf(numCnf.subtract(mtbColrToUpdate.getNumCnf()))
// .setQtaCnf(qtaCnf)
// .setQtaCol(qtaTot.subtract(mtbColrToUpdate.getQtaCol()))
// .setPartitaMag(partitaMag)
// .setDataScadPartita(dataScad);
//
// mtbColt.getMtbColr().add(mtbColr);
//
// this.mColliMagazzinoRESTConsumer.saveCollo(mtbColt, (value) -> {
//
// mtbColr
// .setNumCnf(numCnf)
// .setQtaCnf(qtaCnf)
// .setQtaCol(qtaTot);
//
// Optional<PickingObjectDTO> pickingObjectDTO = Stream.of(this.mPickingList.getValue())
// .filter(x -> Stream.of(x.getWithdrawMtbColrs())
// .anyMatch(y -> y == mtbColrToUpdate)).findSingle();
//
// if (pickingObjectDTO.isPresent()) {
// pickingObjectDTO.get().getWithdrawMtbColrs().remove(mtbColrToUpdate);
// pickingObjectDTO.get().getWithdrawMtbColrs().add(mtbColr);
// }
//
// this.mCurrentMtbColt.getMtbColr().remove(mtbColrToUpdate);
// this.mCurrentMtbColt.getMtbColr().add(mtbColr);
//
// this.resetMatchedRows();
// this.sendOnRowSaved();
// this.sendOnLoadingEnded();
//
// }, this::sendError);
} }