diff --git a/app/build.gradle b/app/build.gradle index 9ba8659457b098d691a21ae0a94ea99fb92426a1..e94c1360f6476c6123402e4f01e3500b344dac04 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' 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 035751a0a95743a4e19d5342853e4dd4439928f6..24987dce4ae12c8122e30679bfc5d3b699f2893a 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 7e4c84748e48bda12aaf99f679d61e03bb5b3a89..58e3669cf1468cd05a8159cca637076ae48471e2 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 2dd503bfb861d2b04fe0d352e3845533224b44e6..156bcb7350dc3793cbf5ad3b176113df737c65dc 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 5e7feb917f408008fbb8efb5b83f08188c5de268..1309f6eeafbd62a3f9c6e8a6d1084926f6a52c66 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 99642ac5e2429bb20179019fd9f84ad7ed476644..560ef9f90ddf6382a7e1ea9b1aa6fb4bef3ff7e4 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