From ab8461932a961cd87dfe643a15eac0313e7bf55b Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Thu, 24 Aug 2023 07:13:21 +0200 Subject: [PATCH 1/2] bump telemetry lib version and target sdk --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 9ba86594..e94c1360 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -40,7 +40,7 @@ android { defaultConfig { applicationId "foundation.e.drive" minSdk 26 - targetSdk 31 + targetSdk 34 versionCode versionMajor * 1000000 + versionMinor * 1000 + versionPatch versionName "${versionMajor}.${versionMinor}.${versionPatch}" setProperty("archivesBaseName", "eDrive-$versionName") @@ -106,7 +106,7 @@ dependencies { implementation 'androidx.test:core:1.5.0' implementation 'com.jakewharton.timber:timber:5.0.1' implementation 'foundation.e:elib:0.0.1-alpha11' - implementation 'foundation.e.lib:telemetry:0.0.8-alpha' + implementation 'foundation.e.lib:telemetry:0.0.11-alpha' androidTestImplementation 'androidx.test:runner:1.5.2' androidTestImplementation 'androidx.test:rules:1.5.0' -- GitLab From 15faab2d68e6a6b065aed50d1db1060bc86ab009 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Thu, 24 Aug 2023 07:13:42 +0200 Subject: [PATCH 2/2] add try catch to report crash to sentry --- .../drive/work/CreateRemoteFolderWorker.java | 78 ++++++++++--------- .../e/drive/work/FirstStartWorker.java | 31 ++++---- .../e/drive/work/FullScanWorker.java | 35 +++++---- .../e/drive/work/ListAppsWorker.java | 21 +++-- .../e/drive/work/PeriodicWorker.java | 21 +++-- 5 files changed, 105 insertions(+), 81 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/work/CreateRemoteFolderWorker.java b/app/src/main/java/foundation/e/drive/work/CreateRemoteFolderWorker.java index 035751a0..24987dce 100644 --- a/app/src/main/java/foundation/e/drive/work/CreateRemoteFolderWorker.java +++ b/app/src/main/java/foundation/e/drive/work/CreateRemoteFolderWorker.java @@ -57,45 +57,47 @@ public class CreateRemoteFolderWorker extends Worker { @NonNull @Override public Result doWork() { - final Context context = getApplicationContext(); - final Account account = getAccount(); - if (account == null) { - Timber.d("doWork(): Can't get valid account"); - return Result.failure(); + try { + final Context context = getApplicationContext(); + final Account account = getAccount(); + if (account == null) { + Timber.d("doWork(): Can't get valid account"); + return Result.failure(); + } + + final boolean meteredNetworkAllowed = CommonUtils.isMeteredNetworkAllowed(account); + if (!CommonUtils.haveNetworkConnection(context, meteredNetworkAllowed)) { + Timber.d("doWork(): no usable connection"); + return Result.retry(); + } + + final SyncedFolder syncedFolder = getSyncedFolderFromData(); + if (syncedFolder == null) return Result.failure(); + + Timber.v("doWork() for : %s", syncedFolder.getLocalFolder()); + final File folder = new File(syncedFolder.getLocalFolder()); + if (!folder.exists()) { + folder.mkdirs(); + syncedFolder.setLastModified(folder.lastModified()); + } + + final OwnCloudClient client = DavClientProvider.getInstance().getClientInstance(account, context); + if (client == null) { + Timber.d("doWork(): Can't get OwnCloudClient"); + return Result.retry(); + } + + final CreateFolderRemoteOperation mkcolRequest = + new CreateFolderRemoteOperation(syncedFolder.getRemoteFolder(), true); + + @SuppressWarnings("deprecation") final RemoteOperationResult result = mkcolRequest.execute(client); + if (result.isSuccess() || result.getCode() == RemoteOperationResult.ResultCode.FOLDER_ALREADY_EXISTS) { + DbHelper.insertSyncedFolder(syncedFolder, context); + return Result.success(); + } + } catch (Exception exception) { + Timber.e(exception); } - - final boolean meteredNetworkAllowed = CommonUtils.isMeteredNetworkAllowed(account); - if (!CommonUtils.haveNetworkConnection(context, meteredNetworkAllowed)) { - Timber.d("doWork(): no usable connection"); - return Result.retry(); - } - - final SyncedFolder syncedFolder = getSyncedFolderFromData(); - if (syncedFolder == null) return Result.failure(); - - Timber.v("doWork() for : %s", syncedFolder.getLocalFolder()); - final File folder = new File(syncedFolder.getLocalFolder() ); - if (!folder.exists()) { - folder.mkdirs(); - syncedFolder.setLastModified(folder.lastModified()); - } - - final OwnCloudClient client = DavClientProvider.getInstance().getClientInstance(account, context); - if (client == null) { - Timber.d("doWork(): Can't get OwnCloudClient"); - return Result.retry(); - } - - final CreateFolderRemoteOperation mkcolRequest = - new CreateFolderRemoteOperation(syncedFolder.getRemoteFolder(), true); - - @SuppressWarnings("deprecation") - final RemoteOperationResult result = mkcolRequest.execute(client); - if (result.isSuccess() || result.getCode() == RemoteOperationResult.ResultCode.FOLDER_ALREADY_EXISTS) { - DbHelper.insertSyncedFolder(syncedFolder, context); - return Result.success(); - } - return Result.retry(); } diff --git a/app/src/main/java/foundation/e/drive/work/FirstStartWorker.java b/app/src/main/java/foundation/e/drive/work/FirstStartWorker.java index 7e4c8474..58e3669c 100644 --- a/app/src/main/java/foundation/e/drive/work/FirstStartWorker.java +++ b/app/src/main/java/foundation/e/drive/work/FirstStartWorker.java @@ -41,25 +41,30 @@ public class FirstStartWorker extends Worker { @Override public Result doWork() { Timber.v("FirstStartWorker.doWork()"); - final Context appContext = getApplicationContext(); + try { + final Context appContext = getApplicationContext(); - enqueueAppListGenerationWorkRequest(appContext); + enqueueAppListGenerationWorkRequest(appContext); - appContext.getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, - Context.MODE_PRIVATE) - .edit() - .putBoolean(AppConstants.INITIALIZATION_HAS_BEEN_DONE, true) - .putInt(INITIAL_FOLDER_NUMBER, 9) - .apply(); + appContext.getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, + Context.MODE_PRIVATE) + .edit() + .putBoolean(AppConstants.INITIALIZATION_HAS_BEEN_DONE, true) + .putInt(INITIAL_FOLDER_NUMBER, 9) + .apply(); - enqueuePeriodicFileScanWorkRequest(appContext); + enqueuePeriodicFileScanWorkRequest(appContext); - getApplicationContext().startService(new Intent(getApplicationContext(), foundation.e.drive.services.SynchronizationService.class)); - getApplicationContext().startService(new Intent(getApplicationContext(), foundation.e.drive.services.ObserverService.class)); + getApplicationContext().startService(new Intent(getApplicationContext(), foundation.e.drive.services.SynchronizationService.class)); + getApplicationContext().startService(new Intent(getApplicationContext(), foundation.e.drive.services.ObserverService.class)); - ((EdriveApplication) getApplicationContext()).startRecursiveFileObserver(); + ((EdriveApplication) getApplicationContext()).startRecursiveFileObserver(); - return Result.success(); + return Result.success(); + } catch (Exception exception) { + Timber.e(exception); + } + return Result.retry(); } private void enqueueAppListGenerationWorkRequest(@NonNull final Context context) { diff --git a/app/src/main/java/foundation/e/drive/work/FullScanWorker.java b/app/src/main/java/foundation/e/drive/work/FullScanWorker.java index 2dd503bf..156bcb73 100644 --- a/app/src/main/java/foundation/e/drive/work/FullScanWorker.java +++ b/app/src/main/java/foundation/e/drive/work/FullScanWorker.java @@ -43,21 +43,26 @@ public class FullScanWorker extends Worker { @NonNull @Override public Result doWork() { - Timber.v("doWork(): going to send intent to ObserverService"); - final SharedPreferences prefs = getApplicationContext().getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, - Context.MODE_PRIVATE); - final String accountName = prefs.getString(AccountManager.KEY_ACCOUNT_NAME, ""); - final String accountType = prefs.getString(AccountManager.KEY_ACCOUNT_TYPE, ""); - - final Account mAccount = CommonUtils.getAccount(accountName, accountType, AccountManager.get(this.getApplicationContext())); - - if (mAccount != null && CommonUtils.isSettingsSyncEnabled(mAccount) && CommonUtils.isMediaSyncEnabled(mAccount)) { - final Intent observerServiceIntent = new Intent(this.getApplicationContext(), ObserverService.class); - this.getApplicationContext().startService(observerServiceIntent); - } else { - Timber.d("Intent for ObserverService not send : account is null or \"settings sync\" & \"media sync\" settings are disabled"); - } + try { + Timber.v("doWork(): going to send intent to ObserverService"); + final SharedPreferences prefs = getApplicationContext().getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, + Context.MODE_PRIVATE); + final String accountName = prefs.getString(AccountManager.KEY_ACCOUNT_NAME, ""); + final String accountType = prefs.getString(AccountManager.KEY_ACCOUNT_TYPE, ""); + + final Account mAccount = CommonUtils.getAccount(accountName, accountType, AccountManager.get(this.getApplicationContext())); - return Result.success(); + if (mAccount != null && CommonUtils.isSettingsSyncEnabled(mAccount) && CommonUtils.isMediaSyncEnabled(mAccount)) { + final Intent observerServiceIntent = new Intent(this.getApplicationContext(), ObserverService.class); + this.getApplicationContext().startService(observerServiceIntent); + } else { + Timber.d("Intent for ObserverService not send : account is null or \"settings sync\" & \"media sync\" settings are disabled"); + } + + return Result.success(); + } catch (Exception exception) { + Timber.e(exception); + return Result.retry(); + } } } \ No newline at end of file diff --git a/app/src/main/java/foundation/e/drive/work/ListAppsWorker.java b/app/src/main/java/foundation/e/drive/work/ListAppsWorker.java index 5e7feb91..1309f6ee 100644 --- a/app/src/main/java/foundation/e/drive/work/ListAppsWorker.java +++ b/app/src/main/java/foundation/e/drive/work/ListAppsWorker.java @@ -45,13 +45,18 @@ public class ListAppsWorker extends Worker { @Override public Result doWork() { Timber.d("generateAppListFile()"); - final Context context = getApplicationContext(); - final StringBuilder fileContents = listRegularApps(context); - listPWAs(context, fileContents); - if (fileContents.length() == 0) return Result.success(); - - final boolean success = writeToFile(fileContents); - return success ? Result.success() : Result.failure(); + try { + final Context context = getApplicationContext(); + final StringBuilder fileContents = listRegularApps(context); + listPWAs(context, fileContents); + if (fileContents.length() == 0) return Result.success(); + + final boolean success = writeToFile(fileContents); + return success ? Result.success() : Result.failure(); + } catch (Exception exception) { + Timber.e(exception); + return Result.failure(); + } } private StringBuilder listRegularApps(@NonNull final Context context) { @@ -89,7 +94,7 @@ public class ListAppsWorker extends Worker { .append("\n"); } catch (IllegalArgumentException exception) { - Timber.e(exception, "Catched exception: invalid column names for cursor"); + Timber.e(exception, "Caught exception: invalid column names for cursor"); } } while (cursor.moveToNext()); diff --git a/app/src/main/java/foundation/e/drive/work/PeriodicWorker.java b/app/src/main/java/foundation/e/drive/work/PeriodicWorker.java index 99642ac5..560ef9f9 100644 --- a/app/src/main/java/foundation/e/drive/work/PeriodicWorker.java +++ b/app/src/main/java/foundation/e/drive/work/PeriodicWorker.java @@ -23,6 +23,8 @@ import androidx.work.WorkerParameters; import java.util.ArrayList; import java.util.List; +import timber.log.Timber; + /** * Worker that trigger the chain of worker that really need to be periodic * This worker is required because we cannot chain periodic work through WorkerAPI @@ -38,15 +40,20 @@ public class PeriodicWorker extends Worker { @NonNull @Override public Result doWork() { - final WorkManager workManager = WorkManager.getInstance(getApplicationContext()); + try { + final WorkManager workManager = WorkManager.getInstance(getApplicationContext()); - final List workRequestsLists = new ArrayList<>(); - workRequestsLists.add(WorkRequestFactory.getOneTimeWorkRequest(ONE_TIME_APP_LIST, null)); - workRequestsLists.add(WorkRequestFactory.getOneTimeWorkRequest(ONE_TIME_FULL_SCAN, null)); + final List workRequestsLists = new ArrayList<>(); + workRequestsLists.add(WorkRequestFactory.getOneTimeWorkRequest(ONE_TIME_APP_LIST, null)); + workRequestsLists.add(WorkRequestFactory.getOneTimeWorkRequest(ONE_TIME_FULL_SCAN, null)); - workManager.beginUniqueWork(FullScanWorker.UNIQUE_WORK_NAME, ExistingWorkPolicy.KEEP, workRequestsLists) - .enqueue(); + workManager.beginUniqueWork(FullScanWorker.UNIQUE_WORK_NAME, ExistingWorkPolicy.KEEP, workRequestsLists) + .enqueue(); - return Result.success(); + return Result.success(); + } catch (Exception exception) { + Timber.e(exception); + return Result.retry(); + } } } \ No newline at end of file -- GitLab