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 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());
|
Logger.addLogAdapter(new AndroidLogAdapter());
|
||||||
|
|
||||||
logsFolder = new File(mApplicationContext.getExternalFilesDir(null).getAbsolutePath());
|
logsFolder = new File(mApplicationContext.getExternalFilesDir(null).getAbsolutePath());
|
||||||
|
removeOldLogs(logsFolder);
|
||||||
|
|
||||||
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) {
|
private void removeOldLogs(File logsFolder) {
|
||||||
|
|||||||
@ -1,8 +1,5 @@
|
|||||||
package it.integry.integrywmsnative.core.rest.consumers;
|
package it.integry.integrywmsnative.core.rest.consumers;
|
||||||
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
@ -17,8 +14,6 @@ import java.util.concurrent.ExecutorService;
|
|||||||
|
|
||||||
import javax.inject.Singleton;
|
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.expansion.RunnableArgs;
|
||||||
import it.integry.integrywmsnative.core.rest.RESTBuilder;
|
import it.integry.integrywmsnative.core.rest.RESTBuilder;
|
||||||
import it.integry.integrywmsnative.core.rest.handler.ManagedErrorCallback;
|
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.NativeSqlRequestDTO;
|
||||||
import it.integry.integrywmsnative.core.rest.model.ServiceRESTResponse;
|
import it.integry.integrywmsnative.core.rest.model.ServiceRESTResponse;
|
||||||
import it.integry.integrywmsnative.core.rest.model.system.LatestAppVersionInfoDTO;
|
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.UtilityGson;
|
||||||
import it.integry.integrywmsnative.core.utility.UtilityString;
|
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Response;
|
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 {
|
public void sendMailSynchronized(MailRequestDTO mailDTO) throws Exception {
|
||||||
SystemRESTConsumerService service = restBuilder.getService(SystemRESTConsumerService.class);
|
SystemRESTConsumerService service = restBuilder.getService(SystemRESTConsumerService.class);
|
||||||
var response = service.sendMail(mailDTO).execute();
|
var response = service.sendMail(mailDTO).execute();
|
||||||
|
|||||||
@ -49,8 +49,12 @@ public class LoginViewModel {
|
|||||||
|
|
||||||
FirebaseInstallations.getInstance().getId().addOnCompleteListener(fid -> {
|
FirebaseInstallations.getInstance().getId().addOnCompleteListener(fid -> {
|
||||||
|
|
||||||
|
SettingsManager.i().createUserSession();
|
||||||
retrieveAvailableProfiles(protocol, host, port, username, password, selectedProfile -> {
|
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 -> {
|
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) {
|
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 -> {
|
mAuthenticationRESTConsumer.authenticate(protocol, host, port, username, password, profileDb, deviceSalt, sessionData -> {
|
||||||
|
|
||||||
var claims = JwtUtils.parseJwt(sessionData.getAccessToken());
|
var claims = JwtUtils.parseJwt(sessionData.getAccessToken());
|
||||||
|
|||||||
@ -33,7 +33,9 @@ import java.util.Arrays;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@ -258,81 +260,98 @@ public class MainSettingsFragment extends PreferenceFragmentCompat implements IT
|
|||||||
private void exportLog() {
|
private void exportLog() {
|
||||||
var handler = new Handler(Looper.getMainLooper());
|
var handler = new Handler(Looper.getMainLooper());
|
||||||
|
|
||||||
DialogYesNoView.newInstance("Esportazione log", "Vuoi inviare il log degli eventi al supporto?", result -> {
|
executorService.execute(() -> {
|
||||||
if (result == DialogConsts.Results.NO || result == DialogConsts.Results.ABORT)
|
|
||||||
return;
|
|
||||||
|
|
||||||
this.openProgress();
|
if(!askConfirmToExportLog()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
executorService.execute(() -> {
|
this.openProgress();
|
||||||
|
|
||||||
|
|
||||||
File logFilePath = appContext.getLogFilePath();
|
File logFilePath = appContext.getLogFilePath();
|
||||||
var files = logFilePath.listFiles();
|
var files = logFilePath.listFiles();
|
||||||
|
|
||||||
var fileToShare = Arrays.stream(files)
|
var fileToShare = Arrays.stream(files)
|
||||||
.sorted(Comparator.reverseOrder())
|
.sorted(Comparator.reverseOrder())
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
try {
|
try {
|
||||||
List<MailAttachmentDTO> attachmentDTOList = new ArrayList<>();
|
List<MailAttachmentDTO> attachmentDTOList = new ArrayList<>();
|
||||||
|
|
||||||
if (fileToShare != null) {
|
if (fileToShare != null) {
|
||||||
var htmlContent = createAppLogAttachment(fileToShare);
|
var htmlContent = createAppLogAttachment(fileToShare);
|
||||||
|
|
||||||
byte[] buffer = htmlContent.getBytes();//specify the size to allow.
|
byte[] buffer = htmlContent.getBytes();//specify the size to allow.
|
||||||
String base64 = Base64.encodeToString(buffer, Base64.NO_WRAP);
|
String base64 = Base64.encodeToString(buffer, Base64.NO_WRAP);
|
||||||
|
|
||||||
var logAttachment = new MailAttachmentDTO()
|
var logAttachment = new MailAttachmentDTO()
|
||||||
.setFileName("wms_log.html")
|
.setFileName("wms_log.html")
|
||||||
.setFileb64Content(base64);
|
.setFileb64Content(base64);
|
||||||
attachmentDTOList.add(logAttachment);
|
attachmentDTOList.add(logAttachment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
rawDao.vacuumDb(new SimpleSQLiteQuery("pragma wal_checkpoint(full)"));
|
rawDao.vacuumDb(new SimpleSQLiteQuery("pragma wal_checkpoint(full)"));
|
||||||
File[] dbFiles = new File[3];
|
rawDao.vacuumDb(new SimpleSQLiteQuery("VACUUM;"));
|
||||||
dbFiles[0] = requireContext().getDatabasePath("integry_wms");
|
File[] dbFiles = new File[3];
|
||||||
dbFiles[1] = requireContext().getDatabasePath("integry_wms-shm");
|
dbFiles[0] = requireContext().getDatabasePath("integry_wms");
|
||||||
dbFiles[2] = requireContext().getDatabasePath("integry_wms-wal");
|
dbFiles[1] = requireContext().getDatabasePath("integry_wms-shm");
|
||||||
|
dbFiles[2] = requireContext().getDatabasePath("integry_wms-wal");
|
||||||
|
|
||||||
for (int i = 0; i < dbFiles.length; i++) {
|
for (int i = 0; i < dbFiles.length; i++) {
|
||||||
byte[] dbFileBytes = new byte[(int) dbFiles[i].length()];
|
byte[] dbFileBytes = new byte[(int) dbFiles[i].length()];
|
||||||
FileInputStream inputStream = new FileInputStream(dbFiles[i]);
|
FileInputStream inputStream = new FileInputStream(dbFiles[i]);
|
||||||
final int read = inputStream.read(dbFileBytes);
|
final int read = inputStream.read(dbFileBytes);
|
||||||
inputStream.close();
|
inputStream.close();
|
||||||
|
|
||||||
var dbAttachment = new MailAttachmentDTO()
|
var dbAttachment = new MailAttachmentDTO()
|
||||||
.setFileName(dbFiles[i].getName())
|
.setFileName(dbFiles[i].getName())
|
||||||
.setFileb64Content(Base64.encodeToString(dbFileBytes, Base64.NO_WRAP));
|
.setFileb64Content(Base64.encodeToString(dbFileBytes, Base64.NO_WRAP));
|
||||||
attachmentDTOList.add(dbAttachment);
|
attachmentDTOList.add(dbAttachment);
|
||||||
}
|
}
|
||||||
|
|
||||||
var mailRequest = new MailRequestDTO()
|
var mailRequest = new MailRequestDTO()
|
||||||
.setTo("developer@integry.it")
|
.setTo("developer@integry.it")
|
||||||
.setMsgText("Questa è una mail contenente il log del WMS")
|
.setMsgText("Questa è una mail contenente il log del WMS")
|
||||||
.setSubject("Internal WMS log")
|
.setSubject("Internal WMS log")
|
||||||
.setAttachments(attachmentDTOList);
|
.setAttachments(attachmentDTOList);
|
||||||
|
|
||||||
|
|
||||||
systemRESTConsumer.sendMailSynchronized(mailRequest);
|
systemRESTConsumer.sendMailSynchronized(mailRequest);
|
||||||
|
|
||||||
this.closeProgress();
|
this.closeProgress();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
handler.post(() -> {
|
handler.post(() -> {
|
||||||
FirebaseCrashlytics.getInstance().recordException(ex, new CustomKeysAndValues.Builder() {{
|
FirebaseCrashlytics.getInstance().recordException(ex, new CustomKeysAndValues.Builder() {{
|
||||||
putString("ExportLog", "Error while exporting log");
|
putString("ExportLog", "Error while exporting log");
|
||||||
}}.build());
|
}}.build());
|
||||||
this.closeProgress();
|
this.closeProgress();
|
||||||
UtilityExceptions.defaultException(requireContext(), ex);
|
UtilityExceptions.defaultException(requireContext(), ex);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
|
||||||
.show(getParentFragmentManager(), "tag");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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() {
|
private void openProgress() {
|
||||||
// executorService.execute(() -> {
|
// executorService.execute(() -> {
|
||||||
this.mCurrentProgress.show(requireActivity().getSupportFragmentManager());
|
this.mCurrentProgress.show(requireActivity().getSupportFragmentManager());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user