Migliorie varie
This commit is contained in:
parent
d91eaf3412
commit
6f070e6998
@ -24,19 +24,4 @@ public class CommonConst {
|
||||
public static String RECOVER_COLLO_FILE = "recover_ul.json";
|
||||
}
|
||||
|
||||
public static class Mail {
|
||||
|
||||
public static String[] forErrorsDebug = {
|
||||
"g.scorrano@integry.it",
|
||||
"v.castellana@integry.it"
|
||||
};
|
||||
|
||||
public static String[] forErrors = {
|
||||
// "syslogs@integry.it",
|
||||
"g.scorrano@integry.it",
|
||||
"v.castellana@integry.it"
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -90,10 +90,10 @@ public class AppContext {
|
||||
Logger.addLogAdapter(new AndroidLogAdapter());
|
||||
|
||||
logsFolder = new File(mApplicationContext.getExternalFilesDir(null).getAbsolutePath());
|
||||
removeOldLogs(logsFolder);
|
||||
|
||||
int maxBytesSize = 5 * 1024 * 1024;
|
||||
Logger.addLogAdapter(new DiskLogAdapter(logsFolder, maxBytesSize));
|
||||
|
||||
removeOldLogs(logsFolder);
|
||||
}
|
||||
|
||||
private void removeOldLogs(File logsFolder) {
|
||||
|
||||
@ -1,8 +1,5 @@
|
||||
package it.integry.integrywmsnative.core.rest.consumers;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
@ -17,8 +14,6 @@ import java.util.concurrent.ExecutorService;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import it.integry.integrywmsnative.BuildConfig;
|
||||
import it.integry.integrywmsnative.core.CommonConst;
|
||||
import it.integry.integrywmsnative.core.expansion.RunnableArgs;
|
||||
import it.integry.integrywmsnative.core.rest.RESTBuilder;
|
||||
import it.integry.integrywmsnative.core.rest.handler.ManagedErrorCallback;
|
||||
@ -27,9 +22,7 @@ import it.integry.integrywmsnative.core.rest.model.MailRequestDTO;
|
||||
import it.integry.integrywmsnative.core.rest.model.NativeSqlRequestDTO;
|
||||
import it.integry.integrywmsnative.core.rest.model.ServiceRESTResponse;
|
||||
import it.integry.integrywmsnative.core.rest.model.system.LatestAppVersionInfoDTO;
|
||||
import it.integry.integrywmsnative.core.settings.SettingsManager;
|
||||
import it.integry.integrywmsnative.core.utility.UtilityGson;
|
||||
import it.integry.integrywmsnative.core.utility.UtilityString;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Response;
|
||||
|
||||
@ -110,36 +103,6 @@ public class SystemRESTConsumer extends _BaseRESTConsumer {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void sendErrorLogMail(String message, Runnable onComplete, RunnableArgs<Exception> onFailed) {
|
||||
|
||||
String currentAzienda = UtilityString.isNullOrEmpty(SettingsManager.i().getUserSession().getProfileDB()) ? "" : " [" + SettingsManager.i().getUserSession().getProfileDB() + "]";
|
||||
|
||||
String dest = "";
|
||||
if (BuildConfig.DEBUG) {
|
||||
dest = TextUtils.join(";", CommonConst.Mail.forErrorsDebug);
|
||||
} else {
|
||||
dest = TextUtils.join(";", CommonConst.Mail.forErrors);
|
||||
}
|
||||
|
||||
|
||||
MailRequestDTO mailDTO = new MailRequestDTO()
|
||||
.setFrom("sender@integry.it")
|
||||
.setFromName((BuildConfig.DEBUG ? "[DEBUG] " : "") + "WMS Android")
|
||||
.setTo(dest)
|
||||
.setSubject("Bug notification" + currentAzienda)
|
||||
.setMsgText(message)
|
||||
.setHtml(true);
|
||||
|
||||
sendMail(mailDTO, () -> {
|
||||
if (onComplete != null) onComplete.run();
|
||||
}, ex -> {
|
||||
Log.e(SystemRESTConsumer.class.getName(), "", ex);
|
||||
if (onFailed != null) onFailed.run(ex);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void sendMailSynchronized(MailRequestDTO mailDTO) throws Exception {
|
||||
SystemRESTConsumerService service = restBuilder.getService(SystemRESTConsumerService.class);
|
||||
var response = service.sendMail(mailDTO).execute();
|
||||
|
||||
@ -49,8 +49,12 @@ public class LoginViewModel {
|
||||
|
||||
FirebaseInstallations.getInstance().getId().addOnCompleteListener(fid -> {
|
||||
|
||||
SettingsManager.i().createUserSession();
|
||||
retrieveAvailableProfiles(protocol, host, port, username, password, selectedProfile -> {
|
||||
SettingsManager.i().createUserSession();
|
||||
if(selectedProfile == null) {
|
||||
this.sendOnLoadingEnded();
|
||||
return;
|
||||
}
|
||||
|
||||
authenticate(protocol, host, port, username, password, selectedProfile, fid.getResult(), fullName -> {
|
||||
|
||||
@ -126,6 +130,8 @@ public class LoginViewModel {
|
||||
}
|
||||
|
||||
private void authenticate(String protocol, String host, int port, String username, String password, String profileDb, String deviceSalt, RunnableArgs<String> onComplete) {
|
||||
|
||||
|
||||
mAuthenticationRESTConsumer.authenticate(protocol, host, port, username, password, profileDb, deviceSalt, sessionData -> {
|
||||
|
||||
var claims = JwtUtils.parseJwt(sessionData.getAccessToken());
|
||||
|
||||
@ -33,7 +33,9 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@ -258,81 +260,98 @@ public class MainSettingsFragment extends PreferenceFragmentCompat implements IT
|
||||
private void exportLog() {
|
||||
var handler = new Handler(Looper.getMainLooper());
|
||||
|
||||
DialogYesNoView.newInstance("Esportazione log", "Vuoi inviare il log degli eventi al supporto?", result -> {
|
||||
if (result == DialogConsts.Results.NO || result == DialogConsts.Results.ABORT)
|
||||
return;
|
||||
executorService.execute(() -> {
|
||||
|
||||
this.openProgress();
|
||||
if(!askConfirmToExportLog()) {
|
||||
return;
|
||||
}
|
||||
|
||||
executorService.execute(() -> {
|
||||
this.openProgress();
|
||||
|
||||
|
||||
File logFilePath = appContext.getLogFilePath();
|
||||
var files = logFilePath.listFiles();
|
||||
File logFilePath = appContext.getLogFilePath();
|
||||
var files = logFilePath.listFiles();
|
||||
|
||||
var fileToShare = Arrays.stream(files)
|
||||
.sorted(Comparator.reverseOrder())
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
try {
|
||||
List<MailAttachmentDTO> attachmentDTOList = new ArrayList<>();
|
||||
var fileToShare = Arrays.stream(files)
|
||||
.sorted(Comparator.reverseOrder())
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
try {
|
||||
List<MailAttachmentDTO> attachmentDTOList = new ArrayList<>();
|
||||
|
||||
if (fileToShare != null) {
|
||||
var htmlContent = createAppLogAttachment(fileToShare);
|
||||
if (fileToShare != null) {
|
||||
var htmlContent = createAppLogAttachment(fileToShare);
|
||||
|
||||
byte[] buffer = htmlContent.getBytes();//specify the size to allow.
|
||||
String base64 = Base64.encodeToString(buffer, Base64.NO_WRAP);
|
||||
byte[] buffer = htmlContent.getBytes();//specify the size to allow.
|
||||
String base64 = Base64.encodeToString(buffer, Base64.NO_WRAP);
|
||||
|
||||
var logAttachment = new MailAttachmentDTO()
|
||||
.setFileName("wms_log.html")
|
||||
.setFileb64Content(base64);
|
||||
attachmentDTOList.add(logAttachment);
|
||||
}
|
||||
var logAttachment = new MailAttachmentDTO()
|
||||
.setFileName("wms_log.html")
|
||||
.setFileb64Content(base64);
|
||||
attachmentDTOList.add(logAttachment);
|
||||
}
|
||||
|
||||
|
||||
rawDao.vacuumDb(new SimpleSQLiteQuery("pragma wal_checkpoint(full)"));
|
||||
File[] dbFiles = new File[3];
|
||||
dbFiles[0] = requireContext().getDatabasePath("integry_wms");
|
||||
dbFiles[1] = requireContext().getDatabasePath("integry_wms-shm");
|
||||
dbFiles[2] = requireContext().getDatabasePath("integry_wms-wal");
|
||||
rawDao.vacuumDb(new SimpleSQLiteQuery("pragma wal_checkpoint(full)"));
|
||||
rawDao.vacuumDb(new SimpleSQLiteQuery("VACUUM;"));
|
||||
File[] dbFiles = new File[3];
|
||||
dbFiles[0] = requireContext().getDatabasePath("integry_wms");
|
||||
dbFiles[1] = requireContext().getDatabasePath("integry_wms-shm");
|
||||
dbFiles[2] = requireContext().getDatabasePath("integry_wms-wal");
|
||||
|
||||
for (int i = 0; i < dbFiles.length; i++) {
|
||||
byte[] dbFileBytes = new byte[(int) dbFiles[i].length()];
|
||||
FileInputStream inputStream = new FileInputStream(dbFiles[i]);
|
||||
final int read = inputStream.read(dbFileBytes);
|
||||
inputStream.close();
|
||||
for (int i = 0; i < dbFiles.length; i++) {
|
||||
byte[] dbFileBytes = new byte[(int) dbFiles[i].length()];
|
||||
FileInputStream inputStream = new FileInputStream(dbFiles[i]);
|
||||
final int read = inputStream.read(dbFileBytes);
|
||||
inputStream.close();
|
||||
|
||||
var dbAttachment = new MailAttachmentDTO()
|
||||
.setFileName(dbFiles[i].getName())
|
||||
.setFileb64Content(Base64.encodeToString(dbFileBytes, Base64.NO_WRAP));
|
||||
attachmentDTOList.add(dbAttachment);
|
||||
}
|
||||
var dbAttachment = new MailAttachmentDTO()
|
||||
.setFileName(dbFiles[i].getName())
|
||||
.setFileb64Content(Base64.encodeToString(dbFileBytes, Base64.NO_WRAP));
|
||||
attachmentDTOList.add(dbAttachment);
|
||||
}
|
||||
|
||||
var mailRequest = new MailRequestDTO()
|
||||
.setTo("developer@integry.it")
|
||||
.setMsgText("Questa è una mail contenente il log del WMS")
|
||||
.setSubject("Internal WMS log")
|
||||
.setAttachments(attachmentDTOList);
|
||||
var mailRequest = new MailRequestDTO()
|
||||
.setTo("developer@integry.it")
|
||||
.setMsgText("Questa è una mail contenente il log del WMS")
|
||||
.setSubject("Internal WMS log")
|
||||
.setAttachments(attachmentDTOList);
|
||||
|
||||
|
||||
systemRESTConsumer.sendMailSynchronized(mailRequest);
|
||||
systemRESTConsumer.sendMailSynchronized(mailRequest);
|
||||
|
||||
this.closeProgress();
|
||||
} catch (Exception ex) {
|
||||
handler.post(() -> {
|
||||
FirebaseCrashlytics.getInstance().recordException(ex, new CustomKeysAndValues.Builder() {{
|
||||
putString("ExportLog", "Error while exporting log");
|
||||
}}.build());
|
||||
this.closeProgress();
|
||||
UtilityExceptions.defaultException(requireContext(), ex);
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
.show(getParentFragmentManager(), "tag");
|
||||
this.closeProgress();
|
||||
} catch (Exception ex) {
|
||||
handler.post(() -> {
|
||||
FirebaseCrashlytics.getInstance().recordException(ex, new CustomKeysAndValues.Builder() {{
|
||||
putString("ExportLog", "Error while exporting log");
|
||||
}}.build());
|
||||
this.closeProgress();
|
||||
UtilityExceptions.defaultException(requireContext(), ex);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private boolean askConfirmToExportLog() {
|
||||
CountDownLatch countDownLatch = new CountDownLatch(1);
|
||||
AtomicBoolean userConfirmed = new AtomicBoolean(false);
|
||||
|
||||
DialogYesNoView.newInstance("Esportazione log", "Vuoi inviare il log degli eventi al supporto?", result -> {
|
||||
userConfirmed.set(result != DialogConsts.Results.NO && result != DialogConsts.Results.ABORT);
|
||||
countDownLatch.countDown();
|
||||
}).show(getParentFragmentManager(), "tag");
|
||||
|
||||
try {
|
||||
countDownLatch.await();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return userConfirmed.get();
|
||||
}
|
||||
|
||||
private void openProgress() {
|
||||
// executorService.execute(() -> {
|
||||
this.mCurrentProgress.show(requireActivity().getSupportFragmentManager());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user