diff --git a/README.md b/README.md index 35f46a7fcbe52c49429e081635346258a4d9bc04..2ac3a5d03095b5cfc0165f7a799da9aca5144389 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # eDrive -eDrive is a [persistent][doc-persistence] application provided by default with /e/OS. +eDrive is an application provided by default with /e/OS. It synchronizes user's data files to /e/Cloud or a self-hosted cloud. ## Install diff --git a/app/src/main/java/foundation/e/drive/utils/ServiceExceptionHandler.java b/app/src/main/java/foundation/e/drive/utils/ServiceExceptionHandler.java deleted file mode 100644 index 71da229771426b739640e5e0b2d986e2c80d385c..0000000000000000000000000000000000000000 --- a/app/src/main/java/foundation/e/drive/utils/ServiceExceptionHandler.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright © CLEUS SAS 2018-2019. - * Copyright © ECORP SAS 2022. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Public License v3.0 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/gpl.html - */ -package foundation.e.drive.utils; -import android.annotation.SuppressLint; -import android.app.Service; -import android.os.Environment; - -import androidx.annotation.NonNull; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.lang.Thread.UncaughtExceptionHandler; - -/** - * todo: check if still usefull or if it can be remove - * @author Vincent Bourgmayer - */ -public class ServiceExceptionHandler implements UncaughtExceptionHandler { - public final static String CRASH_LOG_FOLDER = "crash-logs"; - public final static String LOG_FILE_NAME_PREFIX = "eDrive-crash-"; - public final static String LOG_FILE_EXTENSION = ".log"; - private final UncaughtExceptionHandler defaultUEH; - - Service service; - - /** - * Update the service which use this handler - * @param service current running service - */ - public void setService(@NonNull Service service) { - this.service = service; - } - - public ServiceExceptionHandler(@NonNull Service service) { - this.service = service; - defaultUEH = Thread.getDefaultUncaughtExceptionHandler(); - } - - @SuppressLint("SetWorldReadable") - @Override - public void uncaughtException(@NonNull Thread t, @NonNull Throwable exception) { - - if (isExternalStorageAvailable() && !isExternalStorageReadOnly()) { - - final long timestamp = System.currentTimeMillis(); - - final String fileName = LOG_FILE_NAME_PREFIX+timestamp+LOG_FILE_EXTENSION; - - final File downloadDir = service.getApplication().getExternalFilesDir(CRASH_LOG_FOLDER); - final File logFile = new File(downloadDir, fileName); - try (FileOutputStream fos = new FileOutputStream(logFile)) { - fos.write(service.getClass().getSimpleName().getBytes()); - fos.write(getStackTraceAsString(exception).getBytes()); - logFile.setReadable(true, false); - } catch (IOException ioException) { - ioException.printStackTrace(); - } - } - //source: https://stackoverflow.com/questions/9050962/rethrow-uncaughtexceptionhandler-exception-after-logging-it/9050990#9050990 - if (defaultUEH != null) { - defaultUEH.uncaughtException(t, exception); - } else { - System.exit(1); //Kill /e/ Drive... - } - } - - //source: https://www.journaldev.com/9400/android-external-storage-read-write-save-file - private static boolean isExternalStorageAvailable() { - final String extStorageState = Environment.getExternalStorageState(); - return Environment.MEDIA_MOUNTED.equals(extStorageState); - } - - //source: https://www.journaldev.com/9400/android-external-storage-read-write-save-file - private static boolean isExternalStorageReadOnly() { - final String extStorageState = Environment.getExternalStorageState(); - return Environment.MEDIA_MOUNTED_READ_ONLY.equals(extStorageState); - } - - /** - * Return the stackTrace of the exception as a String - * @param exception the exception - * @return the Stacktrace as a string - */ - @NonNull - private String getStackTraceAsString(Throwable exception) { - final StringWriter sw = new StringWriter(); - final PrintWriter pw = new PrintWriter(sw); - exception.printStackTrace(pw); - return sw.toString(); - } -} \ No newline at end of file