From e2a1e0f2172c42af96bda9caffe8559c67881c26 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Tue, 7 Feb 2023 17:07:31 +0100 Subject: [PATCH 1/5] Fix execution of first fullScan --- .../foundation/e/drive/utils/CommonUtils.java | 2 +- .../e/drive/work/FirstStartWorker.java | 12 ++++++++ .../e/drive/work/WorkRequestFactory.java | 30 +++++++++++-------- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/utils/CommonUtils.java b/app/src/main/java/foundation/e/drive/utils/CommonUtils.java index 9a6ba862..9ea5a025 100644 --- a/app/src/main/java/foundation/e/drive/utils/CommonUtils.java +++ b/app/src/main/java/foundation/e/drive/utils/CommonUtils.java @@ -302,7 +302,7 @@ public abstract class CommonUtils { workRequests.add(createRemoteFolderWorkRequest); } - final OneTimeWorkRequest firstStartRequest = WorkRequestFactory.getOneTimeWorkRequest(WorkRequestFactory.WorkType.FIRST_START, null); + final OneTimeWorkRequest firstStartRequest = WorkRequestFactory.getOneTimeWorkRequest(WorkRequestFactory.WorkType.FIRST_START, null); workManager.beginWith(getUserInfoRequest) .then(workRequests) 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 6663c143..8277bee9 100644 --- a/app/src/main/java/foundation/e/drive/work/FirstStartWorker.java +++ b/app/src/main/java/foundation/e/drive/work/FirstStartWorker.java @@ -9,6 +9,7 @@ package foundation.e.drive.work; import static foundation.e.drive.utils.AppConstants.INITIALFOLDERS_NUMBER; +import static foundation.e.drive.work.WorkRequestFactory.WorkType.ONE_TIME_APP_LIST; import static foundation.e.drive.work.WorkRequestFactory.WorkType.PERIODIC_SCAN; import android.content.Context; @@ -40,7 +41,11 @@ public class FirstStartWorker extends Worker { @Override public Result doWork() { Timber.v("FirstStartWorker.doWork()"); + final Context appContext = getApplicationContext(); + + generateFirstAppListFile(appContext); + appContext.getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE) .edit() @@ -53,11 +58,18 @@ public class FirstStartWorker extends Worker { 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(); return Result.success(); } + + private void generateFirstAppListFile(@NonNull final Context context) { + final WorkManager workManager = WorkManager.getInstance(context); + workManager.enqueue(WorkRequestFactory.getOneTimeWorkRequest(ONE_TIME_APP_LIST, null)); + } + private void registerPeriodicWork(@NonNull final Context context) { final WorkManager workManager = WorkManager.getInstance(context); diff --git a/app/src/main/java/foundation/e/drive/work/WorkRequestFactory.java b/app/src/main/java/foundation/e/drive/work/WorkRequestFactory.java index 8627ceb6..efdf29cc 100644 --- a/app/src/main/java/foundation/e/drive/work/WorkRequestFactory.java +++ b/app/src/main/java/foundation/e/drive/work/WorkRequestFactory.java @@ -26,6 +26,7 @@ import androidx.work.Constraints; import androidx.work.Data; import androidx.work.NetworkType; import androidx.work.OneTimeWorkRequest; +import androidx.work.OutOfQuotaPolicy; import androidx.work.PeriodicWorkRequest; import java.security.InvalidParameterException; @@ -122,13 +123,17 @@ public class WorkRequestFactory { } } + /** + * Create a workRequest to generate file which contains list of installed apps + * @param expedited if request is expedited + * @returnthe workRequest + */ private static OneTimeWorkRequest createOneTimeAppListGenerationWorkRequest() { - final OneTimeWorkRequest workRequest = - new OneTimeWorkRequest.Builder(ListAppsWorker.class) - .setBackoffCriteria(BackoffPolicy.LINEAR, 2, TimeUnit.MINUTES) - .addTag(AppConstants.WORK_GENERIC_TAG) - .build(); - return workRequest; + final OneTimeWorkRequest.Builder builder= new OneTimeWorkRequest.Builder(ListAppsWorker.class); + + return builder.setBackoffCriteria(BackoffPolicy.LINEAR, 2, TimeUnit.MINUTES) + .addTag(AppConstants.WORK_GENERIC_TAG) + .build(); } /** @@ -140,13 +145,12 @@ public class WorkRequestFactory { private static OneTimeWorkRequest createOneTimeFullScanWorkRequest() { final Constraints constraints = createUnmeteredNetworkAndHighBatteryConstraints(); - final OneTimeWorkRequest workRequest = - new OneTimeWorkRequest.Builder(FullScanWorker.class) - .setBackoffCriteria(BackoffPolicy.LINEAR, 2, TimeUnit.MINUTES) + final OneTimeWorkRequest.Builder builder= new OneTimeWorkRequest.Builder(FullScanWorker.class); + + return builder.setBackoffCriteria(BackoffPolicy.LINEAR, 2, TimeUnit.MINUTES) .setConstraints(constraints) .addTag(AppConstants.WORK_GENERIC_TAG) .build(); - return workRequest; } @@ -157,13 +161,13 @@ public class WorkRequestFactory { private static OneTimeWorkRequest createOneTimeGetUserInfoWorkRequest() { final Constraints constraints = createUnmeteredNetworkAndHighBatteryConstraints(); - final OneTimeWorkRequest workRequest = new OneTimeWorkRequest.Builder(AccountUserInfoWorker.class) - .setBackoffCriteria(BackoffPolicy.LINEAR, 2, TimeUnit.MINUTES) + final OneTimeWorkRequest.Builder builder= new OneTimeWorkRequest.Builder(AccountUserInfoWorker.class); + + return builder.setBackoffCriteria(BackoffPolicy.LINEAR, 2, TimeUnit.MINUTES) .addTag(AppConstants.WORK_GENERIC_TAG) .addTag(AppConstants.WORK_INITIALIZATION_TAG) .setConstraints(constraints) .build(); - return workRequest; } /** -- GitLab From e6099c8faa81dbed97b1bac4df72f6f21187ad01 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 8 Feb 2023 10:34:10 +0100 Subject: [PATCH 2/5] Add missing permission in AndroidManifest --- app/src/main/AndroidManifest.xml | 1 + app/src/main/java/foundation/e/drive/utils/CommonUtils.java | 2 +- app/src/main/java/foundation/e/drive/work/FirstStartWorker.java | 2 -- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0014e0bf..0dcd3211 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -13,6 +13,7 @@ + diff --git a/app/src/main/java/foundation/e/drive/utils/CommonUtils.java b/app/src/main/java/foundation/e/drive/utils/CommonUtils.java index 9ea5a025..9a6ba862 100644 --- a/app/src/main/java/foundation/e/drive/utils/CommonUtils.java +++ b/app/src/main/java/foundation/e/drive/utils/CommonUtils.java @@ -302,7 +302,7 @@ public abstract class CommonUtils { workRequests.add(createRemoteFolderWorkRequest); } - final OneTimeWorkRequest firstStartRequest = WorkRequestFactory.getOneTimeWorkRequest(WorkRequestFactory.WorkType.FIRST_START, null); + final OneTimeWorkRequest firstStartRequest = WorkRequestFactory.getOneTimeWorkRequest(WorkRequestFactory.WorkType.FIRST_START, null); workManager.beginWith(getUserInfoRequest) .then(workRequests) 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 8277bee9..7cdbf4f1 100644 --- a/app/src/main/java/foundation/e/drive/work/FirstStartWorker.java +++ b/app/src/main/java/foundation/e/drive/work/FirstStartWorker.java @@ -41,7 +41,6 @@ public class FirstStartWorker extends Worker { @Override public Result doWork() { Timber.v("FirstStartWorker.doWork()"); - final Context appContext = getApplicationContext(); generateFirstAppListFile(appContext); @@ -58,7 +57,6 @@ public class FirstStartWorker extends Worker { 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(); return Result.success(); -- GitLab From 18cbb452fbeca873631f36078de666a2edae2aee Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 8 Feb 2023 11:39:47 +0100 Subject: [PATCH 3/5] move constant from AppConstant to list app worker. make tmp_app_list.csv hidden file --- .../foundation/e/drive/utils/AppConstants.java | 1 - .../foundation/e/drive/work/ListAppsWorker.java | 16 +++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/utils/AppConstants.java b/app/src/main/java/foundation/e/drive/utils/AppConstants.java index 69be96f2..bad256e6 100644 --- a/app/src/main/java/foundation/e/drive/utils/AppConstants.java +++ b/app/src/main/java/foundation/e/drive/utils/AppConstants.java @@ -28,7 +28,6 @@ public abstract class AppConstants { public static final String INITIALIZATION_HAS_BEEN_DONE = "initService_has_run"; public static final String INITIALFOLDERS_NUMBER = "initial_folder_number"; public static final String APPLICATIONS_LIST_FILE_NAME = "packages_list.csv"; - public static final String APPLICATIONS_LIST_FILE_NAME_TMP = "tmp_packages_list.csv"; public static final String SHARED_PREFERENCE_NAME = "preferences"; public static final String KEY_LAST_SYNC_TIME = "lastSyncTimestamp"; 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 be79084d..8d5ca293 100644 --- a/app/src/main/java/foundation/e/drive/work/ListAppsWorker.java +++ b/app/src/main/java/foundation/e/drive/work/ListAppsWorker.java @@ -32,9 +32,10 @@ import timber.log.Timber; * @author vincent Bourgmayer */ public class ListAppsWorker extends Worker { - private final static String PWA_PLAYER = "content://foundation.e.pwaplayer.provider/pwa"; - private final static String SEPARATOR =","; - private final static String PWA_SECTION_SEPARATOR = "\n---- PWAs ----\n"; + private static final String PWA_PLAYER = "content://foundation.e.pwaplayer.provider/pwa"; + private static final String SEPARATOR =","; + private static final String PWA_SECTION_SEPARATOR = "\n---- PWAs ----\n"; + private static final String APPLICATIONS_LIST_FILE_NAME_TMP = ".tmp_packages_list.csv"; public ListAppsWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) { super(context, workerParams); @@ -66,6 +67,7 @@ public class ListAppsWorker extends Worker { } private void listPWAs(@NonNull final Context context, @NonNull final StringBuilder stringBuilder) { + Timber.v("ListPWAs"); final Cursor cursor = context.getContentResolver().query( Uri.parse(PWA_PLAYER), null, null, null, null); @@ -73,7 +75,7 @@ public class ListAppsWorker extends Worker { stringBuilder.append(PWA_SECTION_SEPARATOR); cursor.moveToFirst(); - + Timber.v("Writing list of PWA"); do { try { final String pwaTitle = cursor.getString(cursor.getColumnIndexOrThrow("title")); @@ -95,13 +97,13 @@ public class ListAppsWorker extends Worker { } private boolean writeToFile(@NonNull final StringBuilder fileContents) { - try (final FileOutputStream tmp = getApplicationContext().openFileOutput(AppConstants.APPLICATIONS_LIST_FILE_NAME_TMP, Context.MODE_PRIVATE); + try (final FileOutputStream tmp = getApplicationContext().openFileOutput(APPLICATIONS_LIST_FILE_NAME_TMP, Context.MODE_PRIVATE); ) { tmp.write(fileContents.toString().getBytes()); final String filesDir = getApplicationContext().getFilesDir().getCanonicalPath() + PATH_SEPARATOR; - final File tmp_file = new File(filesDir+AppConstants.APPLICATIONS_LIST_FILE_NAME_TMP); - final File real_file = new File(filesDir+AppConstants.APPLICATIONS_LIST_FILE_NAME); + final File tmp_file = new File(filesDir + APPLICATIONS_LIST_FILE_NAME_TMP); + final File real_file = new File(filesDir + AppConstants.APPLICATIONS_LIST_FILE_NAME); if (tmp_file.length() != real_file.length()) { tmp_file.renameTo(real_file); -- GitLab From be09e654c8cb8e1c603377abf4885aaadb62364b Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Thu, 9 Feb 2023 08:36:34 +0000 Subject: [PATCH 4/5] Add missing space in a method's doc --- .../main/java/foundation/e/drive/work/WorkRequestFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/foundation/e/drive/work/WorkRequestFactory.java b/app/src/main/java/foundation/e/drive/work/WorkRequestFactory.java index efdf29cc..a646a82a 100644 --- a/app/src/main/java/foundation/e/drive/work/WorkRequestFactory.java +++ b/app/src/main/java/foundation/e/drive/work/WorkRequestFactory.java @@ -126,7 +126,7 @@ public class WorkRequestFactory { /** * Create a workRequest to generate file which contains list of installed apps * @param expedited if request is expedited - * @returnthe workRequest + * @return the workRequest */ private static OneTimeWorkRequest createOneTimeAppListGenerationWorkRequest() { final OneTimeWorkRequest.Builder builder= new OneTimeWorkRequest.Builder(ListAppsWorker.class); -- GitLab From a3047b75ab5e1c25c0f429459896cc7d65911e91 Mon Sep 17 00:00:00 2001 From: Hasib Prince Date: Fri, 10 Feb 2023 09:01:52 +0000 Subject: [PATCH 5/5] Apply coding style fix --- .../main/java/foundation/e/drive/work/ListAppsWorker.java | 2 +- .../java/foundation/e/drive/work/WorkRequestFactory.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) 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 8d5ca293..b04e91c5 100644 --- a/app/src/main/java/foundation/e/drive/work/ListAppsWorker.java +++ b/app/src/main/java/foundation/e/drive/work/ListAppsWorker.java @@ -33,7 +33,7 @@ import timber.log.Timber; */ public class ListAppsWorker extends Worker { private static final String PWA_PLAYER = "content://foundation.e.pwaplayer.provider/pwa"; - private static final String SEPARATOR =","; + private static final String SEPARATOR = ","; private static final String PWA_SECTION_SEPARATOR = "\n---- PWAs ----\n"; private static final String APPLICATIONS_LIST_FILE_NAME_TMP = ".tmp_packages_list.csv"; diff --git a/app/src/main/java/foundation/e/drive/work/WorkRequestFactory.java b/app/src/main/java/foundation/e/drive/work/WorkRequestFactory.java index a646a82a..52084c10 100644 --- a/app/src/main/java/foundation/e/drive/work/WorkRequestFactory.java +++ b/app/src/main/java/foundation/e/drive/work/WorkRequestFactory.java @@ -129,7 +129,7 @@ public class WorkRequestFactory { * @return the workRequest */ private static OneTimeWorkRequest createOneTimeAppListGenerationWorkRequest() { - final OneTimeWorkRequest.Builder builder= new OneTimeWorkRequest.Builder(ListAppsWorker.class); + final OneTimeWorkRequest.Builder builder = new OneTimeWorkRequest.Builder(ListAppsWorker.class); return builder.setBackoffCriteria(BackoffPolicy.LINEAR, 2, TimeUnit.MINUTES) .addTag(AppConstants.WORK_GENERIC_TAG) @@ -145,9 +145,9 @@ public class WorkRequestFactory { private static OneTimeWorkRequest createOneTimeFullScanWorkRequest() { final Constraints constraints = createUnmeteredNetworkAndHighBatteryConstraints(); - final OneTimeWorkRequest.Builder builder= new OneTimeWorkRequest.Builder(FullScanWorker.class); + final OneTimeWorkRequest.Builder builder = new OneTimeWorkRequest.Builder(FullScanWorker.class); - return builder.setBackoffCriteria(BackoffPolicy.LINEAR, 2, TimeUnit.MINUTES) + return builder.setBackoffCriteria(BackoffPolicy.LINEAR, 2, TimeUnit.MINUTES) .setConstraints(constraints) .addTag(AppConstants.WORK_GENERIC_TAG) .build(); @@ -161,7 +161,7 @@ public class WorkRequestFactory { private static OneTimeWorkRequest createOneTimeGetUserInfoWorkRequest() { final Constraints constraints = createUnmeteredNetworkAndHighBatteryConstraints(); - final OneTimeWorkRequest.Builder builder= new OneTimeWorkRequest.Builder(AccountUserInfoWorker.class); + final OneTimeWorkRequest.Builder builder = new OneTimeWorkRequest.Builder(AccountUserInfoWorker.class); return builder.setBackoffCriteria(BackoffPolicy.LINEAR, 2, TimeUnit.MINUTES) .addTag(AppConstants.WORK_GENERIC_TAG) -- GitLab