From 48659b570d416c90520519e419d98008a6e0f255 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 2 Mar 2022 09:28:26 +0100 Subject: [PATCH 01/40] Update compileSDK in app/build.gradle and remove dependency - updated compileSdkVersion from 28 to 31 to allow WorkManager API support - removed dependency: implementation 'com.android.support:appcompat-v7:26.1.0' because it is useless in our scope. As stated at https://developer.android.com/topic/libraries/support-library/packages#v7-appcompat it only add ActionBar relative code. But eDrive doesn't use it for a while. --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index c65b01d7..44a0e1de 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -23,7 +23,7 @@ def getTestProp(String propName) { android { - compileSdkVersion 28 + compileSdkVersion 31 defaultConfig { applicationId "foundation.e.drive" minSdkVersion 26 @@ -59,7 +59,7 @@ android { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation 'com.android.support:appcompat-v7:26.1.0' + //implementation 'com.android.support:appcompat-v7:26.1.0' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test:rules:1.0.2' -- GitLab From 042512c0032f3d1a8a298bdb0577dd16779934d8 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 2 Mar 2022 09:43:04 +0100 Subject: [PATCH 02/40] clean dependencies in app/build.gradle - replace all androidTestImplementation and testImplementation library into androidx - reorganize dependencies to make them cleaner --- app/build.gradle | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 44a0e1de..e2bfaed3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -58,27 +58,19 @@ android { dependencies { + api project(':NextcloudLib') implementation fileTree(include: ['*.jar'], dir: 'libs') - //implementation 'com.android.support:appcompat-v7:26.1.0' - - androidTestImplementation 'com.android.support.test:runner:1.0.2' - androidTestImplementation 'com.android.support.test:rules:1.0.2' - androidTestImplementation 'androidx.annotation:annotation:1.3.0' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' api 'androidx.annotation:annotation:1.3.0' - api project(':NextcloudLib') - - //start to add lib for test - 1/4/21 - //@TODO: add junit runner as lib for testImplementation + + androidTestImplementation 'androidx.test:runner:1.4.0' + androidTestImplementation 'androidx.test:rules:1.4.0 ' + androidTestImplementation 'androidx.annotation:annotation:1.3.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + androidTestImplementation 'junit:junit:4.12' - testImplementation 'com.android.support.test:runner:1.0.2' - testImplementation 'com.android.support.test:rules:1.0.2' + testImplementation 'androidx.test:runner:1.4.0' + testImplementation 'androidx.test:rules:1.4.0 ' testImplementation 'junit:junit:4.12' - //testImplementation 'org.robolectric:robolectric:4.4' //need AndroidX - testImplementation "org.robolectric:robolectric:3.8" + testImplementation 'org.robolectric:robolectric:4.4' testImplementation('org.mockito:mockito-inline:3.4.0') - - //testImplementation Libs.AndroidX.Test.archCoreTesting //TODO: replace by not android X version - //implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0' - androidTestImplementation 'junit:junit:4.12' } -- GitLab From 2af8a5bc19e24b133060ef95ff68666630f08e6e Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 2 Mar 2022 09:44:47 +0100 Subject: [PATCH 03/40] add jetpack's work dependency --- app/build.gradle | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/build.gradle b/app/build.gradle index e2bfaed3..510784e9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -61,6 +61,10 @@ dependencies { api project(':NextcloudLib') implementation fileTree(include: ['*.jar'], dir: 'libs') api 'androidx.annotation:annotation:1.3.0' + + def work_version = "2.7.1" + // (Java only) + implementation "androidx.work:work-runtime:$work_version" androidTestImplementation 'androidx.test:runner:1.4.0' androidTestImplementation 'androidx.test:rules:1.4.0 ' -- GitLab From 8cf7652674a9170f4f53457dd91d4a0ea0319f1b Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 2 Mar 2022 09:50:16 +0100 Subject: [PATCH 04/40] fix typo for 'androidx.test:rules' dependencies --- app/build.gradle | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 510784e9..018d91fd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -53,7 +53,6 @@ android { //includeAndroidResources = true } } - } @@ -65,15 +64,15 @@ dependencies { def work_version = "2.7.1" // (Java only) implementation "androidx.work:work-runtime:$work_version" - + androidTestImplementation 'androidx.test:runner:1.4.0' - androidTestImplementation 'androidx.test:rules:1.4.0 ' + androidTestImplementation 'androidx.test:rules:1.4.0' androidTestImplementation 'androidx.annotation:annotation:1.3.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' androidTestImplementation 'junit:junit:4.12' testImplementation 'androidx.test:runner:1.4.0' - testImplementation 'androidx.test:rules:1.4.0 ' + testImplementation 'androidx.test:rules:1.4.0' testImplementation 'junit:junit:4.12' testImplementation 'org.robolectric:robolectric:4.4' testImplementation('org.mockito:mockito-inline:3.4.0') -- GitLab From e7912568a5fe88ebac21e9aacfbedf906cf09970 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 2 Mar 2022 10:30:05 +0100 Subject: [PATCH 05/40] Remove BatteryStateReceiver - Removed BatteryStateReceiver.java from foundation.e.drive.receivers package - removed BatteryStateReceiver entry in AndroidManifest.xml --- app/src/main/AndroidManifest.xml | 8 ---- .../drive/receivers/BatteryStateReceiver.java | 41 ------------------- 2 files changed, 49 deletions(-) delete mode 100644 app/src/main/java/foundation/e/drive/receivers/BatteryStateReceiver.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index be871995..e07511c5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -69,14 +69,6 @@ http://www.gnu.org/licenses/gpl.html android:enabled="true" /> - - - - - - diff --git a/app/src/main/java/foundation/e/drive/receivers/BatteryStateReceiver.java b/app/src/main/java/foundation/e/drive/receivers/BatteryStateReceiver.java deleted file mode 100644 index 2fd661d1..00000000 --- a/app/src/main/java/foundation/e/drive/receivers/BatteryStateReceiver.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright © Vincent Bourgmayer (/e/ foundation). - * 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.receivers; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.util.Log; -import foundation.e.drive.utils.JobUtils; - -/** - * @author Vincent Bourgmayer - */ -public class BatteryStateReceiver extends BroadcastReceiver { - private final static String TAG = BatteryStateReceiver.class.getSimpleName(); - - @Override - public void onReceive(Context context, Intent intent) { - Log.i(TAG, "onReceive"); - - String intentAction = intent.getAction(); - if(intentAction == null) { - Log.e(TAG, "intent Action is null"); - } else if ( intentAction.equals(Intent.ACTION_BATTERY_OKAY) ) { - JobUtils.scheduleScannerJob(context); - }else if(intentAction.equals(Intent.ACTION_BATTERY_LOW)){ - JobUtils.stopScheduledJob(context, JobUtils.ScannerJobId); - try { - context.unregisterReceiver(ScreenOffReceiver.getInstance()); - }catch(Exception e){ - Log.e(TAG, e.toString() ); - } - } - } -} -- GitLab From 2b12b82d1d0ed70846391f746695778fefac1e95 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 2 Mar 2022 10:35:57 +0100 Subject: [PATCH 06/40] Remove ScreenOffReceiver - Remove ScreenOffReceiver.java in foundation.e.drive.receivers package - Remove "unregisterScreenOffReceiver()" in CommonUtils - Remove registration code for screenOffReceiver in InitializerService.java and scannerJob.java --- .../foundation/e/drive/jobs/ScannerJob.java | 8 +-- .../e/drive/receivers/ScreenOffReceiver.java | 51 ------------------- .../e/drive/services/InitializerService.java | 10 ---- .../foundation/e/drive/utils/CommonUtils.java | 20 -------- 4 files changed, 1 insertion(+), 88 deletions(-) delete mode 100644 app/src/main/java/foundation/e/drive/receivers/ScreenOffReceiver.java diff --git a/app/src/main/java/foundation/e/drive/jobs/ScannerJob.java b/app/src/main/java/foundation/e/drive/jobs/ScannerJob.java index 878f554b..50bfa641 100644 --- a/app/src/main/java/foundation/e/drive/jobs/ScannerJob.java +++ b/app/src/main/java/foundation/e/drive/jobs/ScannerJob.java @@ -11,9 +11,8 @@ package foundation.e.drive.jobs; import android.app.job.JobParameters; import android.app.job.JobService; import android.content.Intent; -import android.content.IntentFilter; import android.util.Log; -import foundation.e.drive.receivers.ScreenOffReceiver; + import foundation.e.drive.services.ObserverService; import foundation.e.drive.utils.CommonUtils; @@ -27,11 +26,6 @@ public class ScannerJob extends JobService { public boolean onStartJob(JobParameters params) { Log.i(TAG, "onStartJob()"); - Log.d(TAG, "RegisterReceiver: screenOffReceiver"); - IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON); - filter.addAction(Intent.ACTION_SCREEN_OFF); - getApplicationContext().registerReceiver(ScreenOffReceiver.getInstance(), filter); - Intent observerServiceIntent = new Intent(this, ObserverService.class); this.startService(observerServiceIntent); jobFinished(params, false); diff --git a/app/src/main/java/foundation/e/drive/receivers/ScreenOffReceiver.java b/app/src/main/java/foundation/e/drive/receivers/ScreenOffReceiver.java deleted file mode 100644 index 27d48959..00000000 --- a/app/src/main/java/foundation/e/drive/receivers/ScreenOffReceiver.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright © Vincent Bourgmayer (/e/ foundation). - * 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.receivers; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.util.Log; -import foundation.e.drive.services.ObserverService; -import foundation.e.drive.utils.CommonUtils; - -/** - * @author Vincent Bourgmayer - * This is a broadcast receiver which catch "ACTION_SCREEN_OFF" to start scanning at a moment - * where the user won't need battery or network. - */ -public class ScreenOffReceiver extends BroadcastReceiver { - private final String TAG = ScreenOffReceiver.class.getSimpleName(); - private static ScreenOffReceiver instance; - - public static ScreenOffReceiver getInstance(){ - if(instance == null) - instance = new ScreenOffReceiver(); - return instance; - } - - /** - * Private constructor - */ - private ScreenOffReceiver(){} - - @Override - public void onReceive(Context context, Intent intent) { - Log.i(TAG, "onReceive"); - String intentAction = intent.getAction(); - if(intentAction == null){ - Log.e(TAG, "intent Action is null"); - } else if ( intent.getAction().equals(Intent.ACTION_SCREEN_OFF) - && CommonUtils.haveNetworkConnexion( context ) ) { - Log.d(TAG, "onReceive: ACTION_SCREEN_OFF"); - Intent cloudIntent = new Intent(context, ObserverService.class); - context.startService(cloudIntent); - } - } -} diff --git a/app/src/main/java/foundation/e/drive/services/InitializerService.java b/app/src/main/java/foundation/e/drive/services/InitializerService.java index 289229b2..273715b5 100644 --- a/app/src/main/java/foundation/e/drive/services/InitializerService.java +++ b/app/src/main/java/foundation/e/drive/services/InitializerService.java @@ -13,7 +13,6 @@ import android.accounts.AccountManager; import android.app.Service; import android.content.Context; import android.content.Intent; -import android.content.IntentFilter; import android.content.SharedPreferences; import android.os.Build; import android.os.Environment; @@ -32,11 +31,9 @@ import java.util.List; import foundation.e.drive.models.SyncedFolder; import foundation.e.drive.operations.CreateInitialFolderRemoteOperation; -import foundation.e.drive.receivers.ScreenOffReceiver; import foundation.e.drive.utils.AppConstants; import foundation.e.drive.utils.CommonUtils; import foundation.e.drive.utils.JobUtils; -import foundation.e.drive.utils.ServiceExceptionHandler; import static com.owncloud.android.lib.resources.files.FileUtils.PATH_SEPARATOR; import static foundation.e.drive.utils.AppConstants.INITIALFOLDERS_NUMBER; @@ -288,18 +285,11 @@ public class InitializerService extends Service implements OnRemoteOperationList //JobUtils.stopScheduledJob(appContext, JobUtils.InitializerJobId); JobUtils.scheduleScannerJob(appContext); - Log.d(TAG, "RegisterReceiver: screenOffReceiver"); - IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON); - filter.addAction(Intent.ACTION_SCREEN_OFF); - getApplicationContext().registerReceiver(ScreenOffReceiver.getInstance(), filter); - //Immediatly start ObserverService to not have to wait 30 minutes. Intent observersServiceIntent = new Intent(getApplicationContext(), foundation.e.drive.services.ObserverService.class); startService(observersServiceIntent); - stopSelf(); - } @Override 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 e0f762fc..d14f1b2a 100644 --- a/app/src/main/java/foundation/e/drive/utils/CommonUtils.java +++ b/app/src/main/java/foundation/e/drive/utils/CommonUtils.java @@ -17,7 +17,6 @@ import android.content.ContentResolver; import android.content.Context; import android.media.MediaScannerConnection; import android.net.ConnectivityManager; -import android.net.Network; import android.net.NetworkInfo; import android.net.Uri; import android.util.Log; @@ -32,8 +31,6 @@ import com.owncloud.android.lib.resources.files.FileUtils; import java.io.File; -import foundation.e.drive.receivers.ScreenOffReceiver; - import static foundation.e.drive.utils.AppConstants.MEDIASYNC_PROVIDER_AUTHORITY; import static foundation.e.drive.utils.AppConstants.SETTINGSYNC_PROVIDER_AUTHORITY; @@ -64,23 +61,6 @@ public abstract class CommonUtils { } } - /** - * Unregister from screeOffReceiver component - * - * @param context app context - * @return true if unregistration was successful or false if it encounter an exception - */ - public static boolean unregisterScreenOff(Context context) { - try { - Log.d("TAG", "unregisterReceiver(screenOffReceiver)"); - context.unregisterReceiver(ScreenOffReceiver.getInstance()); - } catch (IllegalArgumentException e) { - Log.w(TAG, "Can't unregister screenOffReceiver "); - return false; - } - return true; - } - /** * This method retrieve Account corresponding to account's name and type -- GitLab From 8ecff71e1c5b15786a7d54a5e48fd7b7f52de7a6 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 2 Mar 2022 10:59:13 +0100 Subject: [PATCH 07/40] Remove remaining call of Commonutils.unregisterSceenOff() - remove call of the method in ResetService.java.onStartCommand() - remove call of the method in ScannerJob.java.onStopJob() --- app/src/main/java/foundation/e/drive/jobs/ScannerJob.java | 1 - .../main/java/foundation/e/drive/services/ResetService.java | 5 +---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/jobs/ScannerJob.java b/app/src/main/java/foundation/e/drive/jobs/ScannerJob.java index 50bfa641..b62738bb 100644 --- a/app/src/main/java/foundation/e/drive/jobs/ScannerJob.java +++ b/app/src/main/java/foundation/e/drive/jobs/ScannerJob.java @@ -40,7 +40,6 @@ public class ScannerJob extends JobService { @Override public boolean onStopJob(JobParameters params) { Log.i(TAG, "onStopJob"); - boolean unregisteredReceiver = CommonUtils.unregisterScreenOff(getApplicationContext()); Intent observerServiceIntent = new Intent(this, ObserverService.class); this.stopService(observerServiceIntent); return false; diff --git a/app/src/main/java/foundation/e/drive/services/ResetService.java b/app/src/main/java/foundation/e/drive/services/ResetService.java index dad3cb20..447ab2c8 100644 --- a/app/src/main/java/foundation/e/drive/services/ResetService.java +++ b/app/src/main/java/foundation/e/drive/services/ResetService.java @@ -86,11 +86,8 @@ public class ResetService extends Service { .apply(); } - //5. Unregister screenOffReceiver - result = CommonUtils.unregisterScreenOff(getApplicationContext()); - Log.d(TAG, "Unregistered ScreenOffReceiver: "+result); - //6. Remove Cached File + //5. Remove Cached File File[] cachedFiles = this.getApplicationContext().getExternalCacheDir().listFiles(); for(File f : cachedFiles){ f.delete(); -- GitLab From acde5516354a73bd309dc1698b3d3fd22fe285dd Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 2 Mar 2022 09:43:04 +0100 Subject: [PATCH 08/40] clean dependencies in app/build.gradle - replace all androidTestImplementation and testImplementation library into androidx - reorganize dependencies to make them cleaner fix typo for 'androidx.test:rules' dependencies --- app/build.gradle | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 44a0e1de..290ae60d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -53,32 +53,23 @@ android { //includeAndroidResources = true } } - } dependencies { + api project(':NextcloudLib') implementation fileTree(include: ['*.jar'], dir: 'libs') - //implementation 'com.android.support:appcompat-v7:26.1.0' - - androidTestImplementation 'com.android.support.test:runner:1.0.2' - androidTestImplementation 'com.android.support.test:rules:1.0.2' - androidTestImplementation 'androidx.annotation:annotation:1.3.0' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' api 'androidx.annotation:annotation:1.3.0' - api project(':NextcloudLib') - //start to add lib for test - 1/4/21 - //@TODO: add junit runner as lib for testImplementation + androidTestImplementation 'androidx.test:runner:1.4.0' + androidTestImplementation 'androidx.test:rules:1.4.0' + androidTestImplementation 'androidx.annotation:annotation:1.3.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + androidTestImplementation 'junit:junit:4.12' - testImplementation 'com.android.support.test:runner:1.0.2' - testImplementation 'com.android.support.test:rules:1.0.2' + testImplementation 'androidx.test:runner:1.4.0' + testImplementation 'androidx.test:rules:1.4.0' testImplementation 'junit:junit:4.12' - //testImplementation 'org.robolectric:robolectric:4.4' //need AndroidX - testImplementation "org.robolectric:robolectric:3.8" + testImplementation 'org.robolectric:robolectric:4.4' testImplementation('org.mockito:mockito-inline:3.4.0') - - //testImplementation Libs.AndroidX.Test.archCoreTesting //TODO: replace by not android X version - //implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0' - androidTestImplementation 'junit:junit:4.12' } -- GitLab From e3cb7f0198e68b3f24ca761a6f17dce0d9939ac3 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 2 Mar 2022 09:44:47 +0100 Subject: [PATCH 09/40] add jetpack's work dependency --- app/build.gradle | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/build.gradle b/app/build.gradle index 290ae60d..018d91fd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -61,6 +61,10 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') api 'androidx.annotation:annotation:1.3.0' + def work_version = "2.7.1" + // (Java only) + implementation "androidx.work:work-runtime:$work_version" + androidTestImplementation 'androidx.test:runner:1.4.0' androidTestImplementation 'androidx.test:rules:1.4.0' androidTestImplementation 'androidx.annotation:annotation:1.3.0' -- GitLab From 5aa1a30996708a7562d833c4f34c1810fef36535 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Thu, 3 Mar 2022 10:13:03 +0100 Subject: [PATCH 10/40] Add new foundation.e.drive.work.FullScanWorker.java - Add new class FullScanWorker.java to be used as replacement of jobs.ScannerJob --- .../e/drive/work/FullScanWorker.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 app/src/main/java/foundation/e/drive/work/FullScanWorker.java diff --git a/app/src/main/java/foundation/e/drive/work/FullScanWorker.java b/app/src/main/java/foundation/e/drive/work/FullScanWorker.java new file mode 100644 index 00000000..dd538e1e --- /dev/null +++ b/app/src/main/java/foundation/e/drive/work/FullScanWorker.java @@ -0,0 +1,45 @@ +/* + * Copyright © Vincent Bourgmayer (/e/ foundation). + * 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.work; + +import android.content.Context; +import android.content.Intent; +import android.util.Log; + +import androidx.annotation.NonNull; +import androidx.work.Worker; +import androidx.work.WorkerParameters; + +import foundation.e.drive.services.ObserverService; + +/** + * As a first step, this class must replace foundation.e.drive.jobs.ScannerJob + * in order to allow to use Jetpack Work API + * + * In further development it will be a part of Workers that will replace ObserverService + * I will update this header accordingly + * + * @author Vincent Bourgmayer + */ +public class FullScanWorker extends Worker { + final private static String TAG = FullScanWorker.class.getSimpleName(); + + public FullScanWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) { + super(context, workerParams); + } + + @NonNull + @Override + public Result doWork() { + Log.d(TAG, "doWork(): going to send intent to ObserverService"); + Intent observerServiceIntent = new Intent(this.getApplicationContext(), ObserverService.class); + this.getApplicationContext().startService(observerServiceIntent); + return Result.success(); + } +} -- GitLab From 18d4cd547caad20c7cfdaeeae254e9f98c090c30 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Thu, 3 Mar 2022 10:20:53 +0100 Subject: [PATCH 11/40] add generic tag for worker in utils.AppConstants.java --- app/src/main/java/foundation/e/drive/utils/AppConstants.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 1e180424..7506a525 100644 --- a/app/src/main/java/foundation/e/drive/utils/AppConstants.java +++ b/app/src/main/java/foundation/e/drive/utils/AppConstants.java @@ -40,7 +40,7 @@ public abstract class AppConstants { public final static String notificationChannelID ="3310"; public final static String notificationChannelName="eDrive channel"; - + public final static String WORK_GENERIC_TAG="eDrive"; public final static String USER_AGENT = "eos("+getBuildTime()+")-eDrive("+ BuildConfig.VERSION_NAME +")"; -- GitLab From 4ee407908cddfb09133922798552057c015a5920 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Thu, 3 Mar 2022 10:26:03 +0100 Subject: [PATCH 12/40] clean InitializerService.java - remove useless comment - remove useless import --- .../e/drive/services/InitializerService.java | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/services/InitializerService.java b/app/src/main/java/foundation/e/drive/services/InitializerService.java index 289229b2..89ae39f4 100644 --- a/app/src/main/java/foundation/e/drive/services/InitializerService.java +++ b/app/src/main/java/foundation/e/drive/services/InitializerService.java @@ -36,7 +36,6 @@ import foundation.e.drive.receivers.ScreenOffReceiver; import foundation.e.drive.utils.AppConstants; import foundation.e.drive.utils.CommonUtils; import foundation.e.drive.utils.JobUtils; -import foundation.e.drive.utils.ServiceExceptionHandler; import static com.owncloud.android.lib.resources.files.FileUtils.PATH_SEPARATOR; import static foundation.e.drive.utils.AppConstants.INITIALFOLDERS_NUMBER; @@ -50,9 +49,9 @@ import androidx.annotation.Nullable; */ public class InitializerService extends Service implements OnRemoteOperationListener { final private String TAG = InitializerService.class.getSimpleName(); - //Complex properties - private int existingRemoteFolderCounter; //@dev-only; Temporarily used to know if all remotePath exist - private List mSyncedFolders; //syncedFolders + + private int existingRemoteFolderCounter; //Temporarily used to know if all remotePath exist + private List mSyncedFolders; private OwnCloudClient mCloudClient; private Handler mHandler; private Account mAccount; @@ -63,7 +62,6 @@ public class InitializerService extends Service implements OnRemoteOperationList Log.i(TAG, "onCreate()"); super.onCreate(); this.existingRemoteFolderCounter = 0; - //JobUtils.scheduleInitializerJob(getApplicationContext()); } @Override @@ -86,7 +84,6 @@ public class InitializerService extends Service implements OnRemoteOperationList accountName = intent.getExtras().getString( AccountManager.KEY_ACCOUNT_NAME, "" ); accountType = intent.getExtras().getString( AccountManager.KEY_ACCOUNT_TYPE, "" ); - //If data come from intent, store them into pref because there aren't stored prefs.edit().putString( AccountManager.KEY_ACCOUNT_NAME, accountName ) .putString( AccountManager.KEY_ACCOUNT_TYPE, accountType ) .apply(); @@ -94,7 +91,6 @@ public class InitializerService extends Service implements OnRemoteOperationList if(accountName.isEmpty() ) { Log.w(TAG, "Account's name not found. Neither in shared prefs nor in intent's extras"); - //JobUtils.stopScheduledJob(getApplicationContext(), JobUtils.InitializerJobId); stopSelf(); }else{ this.mAccount = CommonUtils.getAccount( accountName, accountType, AccountManager.get(this) ); @@ -123,7 +119,6 @@ public class InitializerService extends Service implements OnRemoteOperationList return; } - //Get categories of element to sync List syncCategories = new ArrayList<>(); if (CommonUtils.isMediaSyncEnabled(mAccount)) { @@ -134,7 +129,6 @@ public class InitializerService extends Service implements OnRemoteOperationList syncCategories.addAll(Arrays.asList(SETTINGS_SYNCABLE_CATEGORIES)); } - //Get SyncedFolders getInitialSyncedFolders(syncCategories); this.existingRemoteFolderCounter = 0; @@ -213,7 +207,6 @@ public class InitializerService extends Service implements OnRemoteOperationList this.restartFolderCreationCounter = 0; if( this.mSyncedFolders == null || this.mSyncedFolders.isEmpty() ){ - //JobUtils.stopScheduledJob(getApplicationContext(), JobUtils.InitializerJobId); this.stopSelf(); } -- GitLab From fabf2ff8aa753e162d83dfb58ae49384f784e131 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Thu, 3 Mar 2022 10:27:22 +0100 Subject: [PATCH 13/40] Add usage of WorkManager to enqueue FullScanWorker in InitializerService - Instanciate Constraint for the workRequest (Battery not low, and network available) - Instanciate PeriodicWorkRequest to start FullScanWorker job every 31 minutes with 5 minutes as flex time - Enqueue the workRequest into WorkManager - Add the generic Generic work Tag into the work request - Comment "JobUtils.scheduleScannerJob()" to prevent JobScheduler to run ScannerJob periodically --- .../e/drive/services/InitializerService.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/foundation/e/drive/services/InitializerService.java b/app/src/main/java/foundation/e/drive/services/InitializerService.java index 89ae39f4..e3cd4390 100644 --- a/app/src/main/java/foundation/e/drive/services/InitializerService.java +++ b/app/src/main/java/foundation/e/drive/services/InitializerService.java @@ -29,6 +29,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.concurrent.TimeUnit; import foundation.e.drive.models.SyncedFolder; import foundation.e.drive.operations.CreateInitialFolderRemoteOperation; @@ -36,6 +37,7 @@ import foundation.e.drive.receivers.ScreenOffReceiver; import foundation.e.drive.utils.AppConstants; import foundation.e.drive.utils.CommonUtils; import foundation.e.drive.utils.JobUtils; +import foundation.e.drive.work.FullScanWorker; import static com.owncloud.android.lib.resources.files.FileUtils.PATH_SEPARATOR; import static foundation.e.drive.utils.AppConstants.INITIALFOLDERS_NUMBER; @@ -43,6 +45,11 @@ import static foundation.e.drive.utils.AppConstants.MEDIA_SYNCABLE_CATEGORIES; import static foundation.e.drive.utils.AppConstants.SETTINGS_SYNCABLE_CATEGORIES; import androidx.annotation.Nullable; +import androidx.work.Constraints; +import androidx.work.NetworkType; +import androidx.work.PeriodicWorkRequest; +import androidx.work.WorkManager; +import androidx.work.WorkRequest; /** * @author Vincent Bourgmayer @@ -277,9 +284,24 @@ public class InitializerService extends Service implements OnRemoteOperationList .putInt( INITIALFOLDERS_NUMBER, mSyncedFolders.size() ) .apply(); + Constraints constraints = new Constraints.Builder() + .setRequiredNetworkType(NetworkType.CONNECTED) + .setRequiresBatteryNotLow(true) + .build(); + + WorkRequest periodicFullScanRequest = + new PeriodicWorkRequest.Builder(FullScanWorker.class, + 31, TimeUnit.MINUTES, + 5, TimeUnit.MINUTES) + .setConstraints(constraints) + .addTag(AppConstants.WORK_GENERIC_TAG) + .build(); + + WorkManager.getInstance(this).enqueue(periodicFullScanRequest); + //all folder have been created //JobUtils.stopScheduledJob(appContext, JobUtils.InitializerJobId); - JobUtils.scheduleScannerJob(appContext); + //JobUtils.scheduleScannerJob(appContext); Log.d(TAG, "RegisterReceiver: screenOffReceiver"); IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON); -- GitLab From b10255e0ef757b04fb7f59322231bf4d57ba4a7e Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Thu, 3 Mar 2022 10:43:34 +0100 Subject: [PATCH 14/40] Cancel all Work Enqueued when user account is removed and optimize WorkRequest registration - Cancel all work enqueued using the work generic tag in ResetService.java - Add method "RegisterPeriodicFullScanWorker() in CommonUtils - Replace code in InitializerService by CommonUtils.RegisterPeriodicFullScanWorker - Remove Remove unused import --- .../e/drive/services/InitializerService.java | 28 ++++-------------- .../e/drive/services/ResetService.java | 4 +++ .../foundation/e/drive/utils/CommonUtils.java | 29 ++++++++++++++++++- .../e/drive/work/FullScanWorker.java | 1 + 4 files changed, 38 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/services/InitializerService.java b/app/src/main/java/foundation/e/drive/services/InitializerService.java index e3cd4390..11c48174 100644 --- a/app/src/main/java/foundation/e/drive/services/InitializerService.java +++ b/app/src/main/java/foundation/e/drive/services/InitializerService.java @@ -11,10 +11,12 @@ package foundation.e.drive.services; import android.accounts.Account; import android.accounts.AccountManager; import android.app.Service; +import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; +import android.net.Uri; import android.os.Build; import android.os.Environment; import android.os.Handler; @@ -26,10 +28,10 @@ import com.owncloud.android.lib.common.operations.OnRemoteOperationListener; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.concurrent.TimeUnit; import foundation.e.drive.models.SyncedFolder; import foundation.e.drive.operations.CreateInitialFolderRemoteOperation; @@ -37,7 +39,6 @@ import foundation.e.drive.receivers.ScreenOffReceiver; import foundation.e.drive.utils.AppConstants; import foundation.e.drive.utils.CommonUtils; import foundation.e.drive.utils.JobUtils; -import foundation.e.drive.work.FullScanWorker; import static com.owncloud.android.lib.resources.files.FileUtils.PATH_SEPARATOR; import static foundation.e.drive.utils.AppConstants.INITIALFOLDERS_NUMBER; @@ -45,11 +46,7 @@ import static foundation.e.drive.utils.AppConstants.MEDIA_SYNCABLE_CATEGORIES; import static foundation.e.drive.utils.AppConstants.SETTINGS_SYNCABLE_CATEGORIES; import androidx.annotation.Nullable; -import androidx.work.Constraints; -import androidx.work.NetworkType; -import androidx.work.PeriodicWorkRequest; import androidx.work.WorkManager; -import androidx.work.WorkRequest; /** * @author Vincent Bourgmayer @@ -275,8 +272,7 @@ public class InitializerService extends Service implements OnRemoteOperationList **/ private void doLastStep(){ Log.i(TAG, "doLastStep()"); - - Context appContext = getApplicationContext(); + final Context appContext = getApplicationContext(); appContext.getSharedPreferences( AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE ) .edit() @@ -284,20 +280,7 @@ public class InitializerService extends Service implements OnRemoteOperationList .putInt( INITIALFOLDERS_NUMBER, mSyncedFolders.size() ) .apply(); - Constraints constraints = new Constraints.Builder() - .setRequiredNetworkType(NetworkType.CONNECTED) - .setRequiresBatteryNotLow(true) - .build(); - - WorkRequest periodicFullScanRequest = - new PeriodicWorkRequest.Builder(FullScanWorker.class, - 31, TimeUnit.MINUTES, - 5, TimeUnit.MINUTES) - .setConstraints(constraints) - .addTag(AppConstants.WORK_GENERIC_TAG) - .build(); - - WorkManager.getInstance(this).enqueue(periodicFullScanRequest); + CommonUtils.registerPeriodicFullScanWorker(WorkManager.getInstance(appContext)); //all folder have been created //JobUtils.stopScheduledJob(appContext, JobUtils.InitializerJobId); @@ -314,7 +297,6 @@ public class InitializerService extends Service implements OnRemoteOperationList stopSelf(); - } @Override diff --git a/app/src/main/java/foundation/e/drive/services/ResetService.java b/app/src/main/java/foundation/e/drive/services/ResetService.java index dad3cb20..e0e1bb53 100644 --- a/app/src/main/java/foundation/e/drive/services/ResetService.java +++ b/app/src/main/java/foundation/e/drive/services/ResetService.java @@ -27,6 +27,7 @@ import static foundation.e.drive.utils.AppConstants.INITIALFOLDERS_NUMBER; import static foundation.e.drive.utils.AppConstants.INITIALIZATION_HAS_BEEN_DONE; import androidx.annotation.Nullable; +import androidx.work.WorkManager; /** * @author Vincent Bourgmayer @@ -67,6 +68,9 @@ public class ResetService extends Service { //2. Stop the scheduledJob JobUtils.stopScheduledJob(this, JobUtils.ScannerJobId); //JobUtils.stopScheduledJob(this, JobUtils.InitializerJobId); + + WorkManager.getInstance(this).cancelAllWorkByTag(AppConstants.WORK_GENERIC_TAG); + //3. delete DB result = this.deleteDatabase(DbHelper.DATABASE_NAME); Log.d(TAG, "Remove Database: "+result); 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 e0f762fc..59406ac8 100644 --- a/app/src/main/java/foundation/e/drive/utils/CommonUtils.java +++ b/app/src/main/java/foundation/e/drive/utils/CommonUtils.java @@ -17,7 +17,6 @@ import android.content.ContentResolver; import android.content.Context; import android.media.MediaScannerConnection; import android.net.ConnectivityManager; -import android.net.Network; import android.net.NetworkInfo; import android.net.Uri; import android.util.Log; @@ -31,13 +30,20 @@ import com.owncloud.android.lib.common.accounts.AccountUtils; import com.owncloud.android.lib.resources.files.FileUtils; import java.io.File; +import java.util.concurrent.TimeUnit; import foundation.e.drive.receivers.ScreenOffReceiver; +import foundation.e.drive.work.FullScanWorker; import static foundation.e.drive.utils.AppConstants.MEDIASYNC_PROVIDER_AUTHORITY; import static foundation.e.drive.utils.AppConstants.SETTINGSYNC_PROVIDER_AUTHORITY; import androidx.annotation.NonNull; +import androidx.work.Constraints; +import androidx.work.ExistingPeriodicWorkPolicy; +import androidx.work.NetworkType; +import androidx.work.PeriodicWorkRequest; +import androidx.work.WorkManager; /** @@ -293,4 +299,25 @@ public abstract class CommonUtils { + "\n File can be read?: " + f.canRead() + "\n File can be written?: " + f.canWrite(); } + + /** + * Enqueue a unique periodic worker to look for file to be synchronized (remote files + local files + * @param workManager the instance of workManager + */ + public static void registerPeriodicFullScanWorker(WorkManager workManager){ + final Constraints constraints = new Constraints.Builder() + .setRequiredNetworkType(NetworkType.CONNECTED) + .setRequiresBatteryNotLow(true) + .build(); + + final PeriodicWorkRequest periodicFullScanRequest = + new PeriodicWorkRequest.Builder(FullScanWorker.class, + 31, TimeUnit.MINUTES, + 5, TimeUnit.MINUTES) + .setConstraints(constraints) + .addTag(AppConstants.WORK_GENERIC_TAG) + .build(); + + workManager.enqueueUniquePeriodicWork(FullScanWorker.UNIQUE_WORK_NAME , ExistingPeriodicWorkPolicy.KEEP, periodicFullScanRequest); + } } \ No newline at end of file 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 dd538e1e..d05b7b6c 100644 --- a/app/src/main/java/foundation/e/drive/work/FullScanWorker.java +++ b/app/src/main/java/foundation/e/drive/work/FullScanWorker.java @@ -29,6 +29,7 @@ import foundation.e.drive.services.ObserverService; */ public class FullScanWorker extends Worker { final private static String TAG = FullScanWorker.class.getSimpleName(); + final public static String UNIQUE_WORK_NAME="FullScan"; public FullScanWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) { super(context, workerParams); -- GitLab From b270cfa146bc3e07e836a39e4187cf21e25a6cdc Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Thu, 3 Mar 2022 17:57:29 +0100 Subject: [PATCH 15/40] FullScanWorker doesn't send intent to ObserverService when synchronization is disabled --- .../e/drive/work/FullScanWorker.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) 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 d05b7b6c..b67151c8 100644 --- a/app/src/main/java/foundation/e/drive/work/FullScanWorker.java +++ b/app/src/main/java/foundation/e/drive/work/FullScanWorker.java @@ -8,8 +8,11 @@ package foundation.e.drive.work; +import android.accounts.Account; +import android.accounts.AccountManager; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.util.Log; import androidx.annotation.NonNull; @@ -17,6 +20,8 @@ import androidx.work.Worker; import androidx.work.WorkerParameters; import foundation.e.drive.services.ObserverService; +import foundation.e.drive.utils.AppConstants; +import foundation.e.drive.utils.CommonUtils; /** * As a first step, this class must replace foundation.e.drive.jobs.ScannerJob @@ -39,8 +44,20 @@ public class FullScanWorker extends Worker { @Override public Result doWork() { Log.d(TAG, "doWork(): going to send intent to ObserverService"); - Intent observerServiceIntent = new Intent(this.getApplicationContext(), ObserverService.class); - this.getApplicationContext().startService(observerServiceIntent); + 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{ + Log.w(TAG, "Intent for ObserverService not send : account is null or \"settings sync\" & \"media sync\" settings are disabled"); + } + return Result.success(); } } -- GitLab From 840bf519279aa532c8e8405ef6af89cf0d8d7902 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Fri, 4 Mar 2022 10:07:26 +0100 Subject: [PATCH 16/40] fix spacing in if/else statement and fix 'final' word placement --- .../e/drive/services/InitializerService.java | 38 +++++++++---------- .../foundation/e/drive/utils/CommonUtils.java | 4 +- .../e/drive/work/FullScanWorker.java | 10 ++--- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/services/InitializerService.java b/app/src/main/java/foundation/e/drive/services/InitializerService.java index 11c48174..8939223c 100644 --- a/app/src/main/java/foundation/e/drive/services/InitializerService.java +++ b/app/src/main/java/foundation/e/drive/services/InitializerService.java @@ -11,12 +11,10 @@ package foundation.e.drive.services; import android.accounts.Account; import android.accounts.AccountManager; import android.app.Service; -import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; -import android.net.Uri; import android.os.Build; import android.os.Environment; import android.os.Handler; @@ -52,7 +50,7 @@ import androidx.work.WorkManager; * @author Vincent Bourgmayer */ public class InitializerService extends Service implements OnRemoteOperationListener { - final private String TAG = InitializerService.class.getSimpleName(); + private final String TAG = InitializerService.class.getSimpleName(); private int existingRemoteFolderCounter; //Temporarily used to know if all remotePath exist private List mSyncedFolders; @@ -76,10 +74,10 @@ public class InitializerService extends Service implements OnRemoteOperationList //Get account SharedPreferences prefs = this.getSharedPreferences( AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE ); - if( prefs.getBoolean( AppConstants.INITIALIZATION_HAS_BEEN_DONE, false ) ) { + if (prefs.getBoolean( AppConstants.INITIALIZATION_HAS_BEEN_DONE, false ) ) { JobUtils.scheduleScannerJob(this); Log.w(TAG, "Initializer has already been run"); - }else{ + } else { String accountName = prefs.getString( AccountManager.KEY_ACCOUNT_NAME, "" ); String accountType = prefs.getString( AccountManager.KEY_ACCOUNT_TYPE, "" ); @@ -93,16 +91,16 @@ public class InitializerService extends Service implements OnRemoteOperationList .apply(); } - if(accountName.isEmpty() ) { + if (accountName.isEmpty() ) { Log.w(TAG, "Account's name not found. Neither in shared prefs nor in intent's extras"); stopSelf(); - }else{ + } else { this.mAccount = CommonUtils.getAccount( accountName, accountType, AccountManager.get(this) ); //Get OwnCloudlient if (this.mAccount != null) { this.mCloudClient = CommonUtils.getOwnCloudClient( this.mAccount, getApplicationContext()); start(); - }else { + } else { Log.w(TAG, "Got account is invalid."); stopSelf(); } @@ -193,7 +191,7 @@ public class InitializerService extends Service implements OnRemoteOperationList false, true, false) ); - }catch (Exception e){ Log.e(TAG, e.toString()); } + } catch (Exception e){ Log.e(TAG, e.toString()); } break; } } @@ -210,14 +208,14 @@ public class InitializerService extends Service implements OnRemoteOperationList Log.i(TAG, "createNextRemoteFolder()"); this.restartFolderCreationCounter = 0; - if( this.mSyncedFolders == null || this.mSyncedFolders.isEmpty() ){ + if (this.mSyncedFolders == null || this.mSyncedFolders.isEmpty() ){ this.stopSelf(); } //It means that there are still folders to create - if( this.existingRemoteFolderCounter < this.mSyncedFolders.size() ){ + if (this.existingRemoteFolderCounter < this.mSyncedFolders.size() ){ - if( this.mHandler == null ) this.mHandler = new Handler(); + if (this.mHandler == null ) this.mHandler = new Handler(); CreateInitialFolderRemoteOperation createFolderOperation = new CreateInitialFolderRemoteOperation( @@ -227,11 +225,11 @@ public class InitializerService extends Service implements OnRemoteOperationList createFolderOperation.execute(this.mCloudClient, this, this.mHandler); - }else if(this.existingRemoteFolderCounter == this.mSyncedFolders.size() ){ + } else if (this.existingRemoteFolderCounter == this.mSyncedFolders.size() ){ doLastStep(); - }else{ + } else { Log.e(TAG, "this.existingRemoteFolderCounter : "+this.existingRemoteFolderCounter+" > this.mSyncedFolders.size() : "+this.mSyncedFolders.size() ); this.stopSelf(); } @@ -240,26 +238,26 @@ public class InitializerService extends Service implements OnRemoteOperationList @Override public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) { Log.i(TAG, "onRemoteOperationFinish()"); - if(operation instanceof CreateInitialFolderRemoteOperation){ + if (operation instanceof CreateInitialFolderRemoteOperation){ - if(result.isSuccess() || result.getCode() == RemoteOperationResult.ResultCode.FOLDER_ALREADY_EXISTS){ + if (result.isSuccess() || result.getCode() == RemoteOperationResult.ResultCode.FOLDER_ALREADY_EXISTS){ this.existingRemoteFolderCounter+=1; CreateNextRemoteFolder(); - }else if( result.getHttpCode() == 423 || result.getHttpCode() == 409){//file locked or conflict in result + } else if (result.getHttpCode() == 423 || result.getHttpCode() == 409){//file locked or conflict in result Log.e( TAG, result.getLogMessage() ); - if( this.restartFolderCreationCounter < 3) { + if (this.restartFolderCreationCounter < 3) { Log.w( TAG, " restart operation" ); operation.execute( this.mCloudClient, this, this.mHandler ); this.restartFolderCreationCounter+=1; - }else{ + } else { Log.e(TAG, "Remote folder's creation failed due to conflict with server"); stopSelf(); } - }else{ + } else { Log.e(TAG, result.getLogMessage()+" "+result.getHttpCode() ); stopSelf(); } 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 59406ac8..5ba7a072 100644 --- a/app/src/main/java/foundation/e/drive/utils/CommonUtils.java +++ b/app/src/main/java/foundation/e/drive/utils/CommonUtils.java @@ -51,7 +51,7 @@ import androidx.work.WorkManager; */ public abstract class CommonUtils { - final private static String TAG = CommonUtils.class.getSimpleName(); + private final static String TAG = CommonUtils.class.getSimpleName(); /** * Set ServiceUncaughtExceptionHandler to be the MainThread Exception Handler @@ -169,7 +169,7 @@ public abstract class CommonUtils { oc.setCredentials(new OwnCloudBasicCredentials(account.name, AccountManager.get(context).getPassword(account))); Log.d(TAG, "user agent: "+AppConstants.USER_AGENT); - if(!AppConstants.USER_AGENT.equals(OwnCloudClientManagerFactory.getUserAgent())) { + if (!AppConstants.USER_AGENT.equals(OwnCloudClientManagerFactory.getUserAgent()) ){ OwnCloudClientManagerFactory.setUserAgent(AppConstants.USER_AGENT); } 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 b67151c8..08d5b875 100644 --- a/app/src/main/java/foundation/e/drive/work/FullScanWorker.java +++ b/app/src/main/java/foundation/e/drive/work/FullScanWorker.java @@ -33,8 +33,8 @@ import foundation.e.drive.utils.CommonUtils; * @author Vincent Bourgmayer */ public class FullScanWorker extends Worker { - final private static String TAG = FullScanWorker.class.getSimpleName(); - final public static String UNIQUE_WORK_NAME="FullScan"; + private final static String TAG = FullScanWorker.class.getSimpleName(); + public final static String UNIQUE_WORK_NAME="FullScan"; public FullScanWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) { super(context, workerParams); @@ -51,13 +51,13 @@ public class FullScanWorker extends Worker { final Account mAccount = CommonUtils.getAccount( accountName, accountType, AccountManager.get(this.getApplicationContext()) ); - if(mAccount != null && CommonUtils.isSettingsSyncEnabled(mAccount) && CommonUtils.isMediaSyncEnabled(mAccount)) { + if (mAccount != null && CommonUtils.isSettingsSyncEnabled(mAccount) && CommonUtils.isMediaSyncEnabled(mAccount)) { final Intent observerServiceIntent = new Intent(this.getApplicationContext(), ObserverService.class); this.getApplicationContext().startService(observerServiceIntent); - }else{ + } else { Log.w(TAG, "Intent for ObserverService not send : account is null or \"settings sync\" & \"media sync\" settings are disabled"); } return Result.success(); } -} +} \ No newline at end of file -- GitLab From 4d67e91938243ed3b3000888c1433348051520a2 Mon Sep 17 00:00:00 2001 From: Vincent Bourgmayer Date: Fri, 4 Mar 2022 10:05:24 +0000 Subject: [PATCH 17/40] Remove JobUtils.java --- .../foundation/e/drive/EdriveApplication.java | 10 +-- .../drive/receivers/BatteryStateReceiver.java | 4 +- .../e/drive/services/InitializerService.java | 5 +- .../e/drive/services/ObserverService.java | 2 - .../e/drive/services/ResetService.java | 5 +- .../foundation/e/drive/utils/JobUtils.java | 70 ------------------- 6 files changed, 4 insertions(+), 92 deletions(-) delete mode 100644 app/src/main/java/foundation/e/drive/utils/JobUtils.java diff --git a/app/src/main/java/foundation/e/drive/EdriveApplication.java b/app/src/main/java/foundation/e/drive/EdriveApplication.java index de7bdcf7..b6f6ae35 100644 --- a/app/src/main/java/foundation/e/drive/EdriveApplication.java +++ b/app/src/main/java/foundation/e/drive/EdriveApplication.java @@ -17,7 +17,6 @@ import android.util.Log; import foundation.e.drive.utils.AppConstants; import foundation.e.drive.utils.CommonUtils; -import foundation.e.drive.utils.JobUtils; /** * Class representing the eDrive application. @@ -36,7 +35,7 @@ public class EdriveApplication extends Application { SharedPreferences prefs = getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE); if (prefs.getString(AccountManager.KEY_ACCOUNT_NAME, null) != null) { - scheduleScannerJob(); + Log.d(TAG, "Account already registered"); } else { Account mAccount = CommonUtils.getAccount(getString(R.string.eelo_account_type), AccountManager.get(this)); if (mAccount != null) { @@ -47,17 +46,10 @@ public class EdriveApplication extends Application { .putString(AccountManager.KEY_ACCOUNT_TYPE, accountType) .apply(); - scheduleScannerJob(); } } } - private void scheduleScannerJob() { - if (!JobUtils.isScannerJobRegistered(this)) { - JobUtils.scheduleScannerJob(this); - } - } - private void resetOperationManagerSetting() { getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE).edit() .putBoolean(AppConstants.KEY_OMS_IS_WORKING, false) diff --git a/app/src/main/java/foundation/e/drive/receivers/BatteryStateReceiver.java b/app/src/main/java/foundation/e/drive/receivers/BatteryStateReceiver.java index 2fd661d1..a634635b 100644 --- a/app/src/main/java/foundation/e/drive/receivers/BatteryStateReceiver.java +++ b/app/src/main/java/foundation/e/drive/receivers/BatteryStateReceiver.java @@ -12,7 +12,6 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; -import foundation.e.drive.utils.JobUtils; /** * @author Vincent Bourgmayer @@ -28,9 +27,8 @@ public class BatteryStateReceiver extends BroadcastReceiver { if(intentAction == null) { Log.e(TAG, "intent Action is null"); } else if ( intentAction.equals(Intent.ACTION_BATTERY_OKAY) ) { - JobUtils.scheduleScannerJob(context); + Log.d(TAG, "BATTERY is Okay. Synchronization job isn't reschedule anymore. Expected behaviour"); }else if(intentAction.equals(Intent.ACTION_BATTERY_LOW)){ - JobUtils.stopScheduledJob(context, JobUtils.ScannerJobId); try { context.unregisterReceiver(ScreenOffReceiver.getInstance()); }catch(Exception e){ diff --git a/app/src/main/java/foundation/e/drive/services/InitializerService.java b/app/src/main/java/foundation/e/drive/services/InitializerService.java index 289229b2..134063f2 100644 --- a/app/src/main/java/foundation/e/drive/services/InitializerService.java +++ b/app/src/main/java/foundation/e/drive/services/InitializerService.java @@ -35,7 +35,6 @@ import foundation.e.drive.operations.CreateInitialFolderRemoteOperation; import foundation.e.drive.receivers.ScreenOffReceiver; import foundation.e.drive.utils.AppConstants; import foundation.e.drive.utils.CommonUtils; -import foundation.e.drive.utils.JobUtils; import foundation.e.drive.utils.ServiceExceptionHandler; import static com.owncloud.android.lib.resources.files.FileUtils.PATH_SEPARATOR; @@ -75,7 +74,6 @@ public class InitializerService extends Service implements OnRemoteOperationList SharedPreferences prefs = this.getSharedPreferences( AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE ); if( prefs.getBoolean( AppConstants.INITIALIZATION_HAS_BEEN_DONE, false ) ) { - JobUtils.scheduleScannerJob(this); Log.w(TAG, "Initializer has already been run"); }else{ String accountName = prefs.getString( AccountManager.KEY_ACCOUNT_NAME, "" ); @@ -285,8 +283,7 @@ public class InitializerService extends Service implements OnRemoteOperationList .apply(); //all folder have been created - //JobUtils.stopScheduledJob(appContext, JobUtils.InitializerJobId); - JobUtils.scheduleScannerJob(appContext); + Log.d(TAG, "RegisterReceiver: screenOffReceiver"); IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON); diff --git a/app/src/main/java/foundation/e/drive/services/ObserverService.java b/app/src/main/java/foundation/e/drive/services/ObserverService.java index c90b4167..a0e8c7eb 100644 --- a/app/src/main/java/foundation/e/drive/services/ObserverService.java +++ b/app/src/main/java/foundation/e/drive/services/ObserverService.java @@ -49,7 +49,6 @@ import foundation.e.drive.receivers.ForceSyncReceiver; import foundation.e.drive.utils.AppConstants; import foundation.e.drive.utils.CommonUtils; import foundation.e.drive.utils.DavClientProvider; -import foundation.e.drive.utils.JobUtils; import foundation.e.drive.utils.ServiceExceptionHandler; import static com.owncloud.android.lib.resources.files.FileUtils.PATH_SEPARATOR; @@ -95,7 +94,6 @@ public class ObserverService extends Service implements OnRemoteOperationListene // Check if account is invalid if(this.mAccount == null){ Log.w(TAG, "No account registered"); - JobUtils.stopScheduledJob(this, JobUtils.ScannerJobId); //If no account return super.onStartCommand(intent, flags, startId); } diff --git a/app/src/main/java/foundation/e/drive/services/ResetService.java b/app/src/main/java/foundation/e/drive/services/ResetService.java index dad3cb20..204f5341 100644 --- a/app/src/main/java/foundation/e/drive/services/ResetService.java +++ b/app/src/main/java/foundation/e/drive/services/ResetService.java @@ -21,7 +21,6 @@ import java.io.File; import foundation.e.drive.database.DbHelper; import foundation.e.drive.utils.AppConstants; import foundation.e.drive.utils.CommonUtils; -import foundation.e.drive.utils.JobUtils; import static foundation.e.drive.utils.AppConstants.INITIALFOLDERS_NUMBER; import static foundation.e.drive.utils.AppConstants.INITIALIZATION_HAS_BEEN_DONE; @@ -64,9 +63,7 @@ public class ResetService extends Service { result = getApplicationContext().stopService( stopperIntent ); Log.d(TAG, "stop OperationManagerService: "+result); - //2. Stop the scheduledJob - JobUtils.stopScheduledJob(this, JobUtils.ScannerJobId); - //JobUtils.stopScheduledJob(this, JobUtils.InitializerJobId); + //3. delete DB result = this.deleteDatabase(DbHelper.DATABASE_NAME); Log.d(TAG, "Remove Database: "+result); diff --git a/app/src/main/java/foundation/e/drive/utils/JobUtils.java b/app/src/main/java/foundation/e/drive/utils/JobUtils.java deleted file mode 100644 index 790427eb..00000000 --- a/app/src/main/java/foundation/e/drive/utils/JobUtils.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright © Vincent Bourgmayer (/e/ foundation). - * 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.app.job.JobInfo; -import android.app.job.JobScheduler; -import android.content.ComponentName; -import android.content.Context; -import android.util.Log; -import foundation.e.drive.jobs.ScannerJob; - - -/** - * @author Vincent Bourgmayer - */ - - -public abstract class JobUtils { - final private static String TAG = JobUtils.class.getSimpleName(); //Tag for log - public final static int ScannerJobId = 3310; - //public final static int InitializerJobId = 3311; - - /** - * Start the scheduledJob for observing remote's folder - * @param context app or service context - */ - public static void scheduleScannerJob(Context context){ - Log.i(TAG, "scheduleJob"); - /* I. Start periodic checkup */ - ComponentName jobService = new ComponentName( context, ScannerJob.class ); - - JobInfo job = new JobInfo.Builder(ScannerJobId, jobService ) - .setPeriodic(1860000, 30000) //31git minutes and 30 secondes - .setPersisted(true) - .setRequiredNetworkType( JobInfo.NETWORK_TYPE_ANY ) - .build(); - - JobScheduler jobScheduler = context.getSystemService( JobScheduler.class ); - - if ( jobScheduler.schedule( job ) == JobScheduler.RESULT_SUCCESS ) { - Log.d(TAG, "Scheduled job created"); - } else { - Log.e(TAG, "Scheduled job not created"); - } - } - - /** - * Try to stop the scheduledJob - * @param context - */ - public static void stopScheduledJob(Context context, int jobId){ - context.getSystemService( JobScheduler.class ).cancel(jobId); - } - - /** - * tell if the scannerJob is already registered or not - * @param context - * @return true if is registered, false either - */ - public static boolean isScannerJobRegistered(Context context){ - return (context.getSystemService( JobScheduler.class).getPendingJob(ScannerJobId) != null); - } - -} -- GitLab From c84bd3b8ced82c0c05b3324921579bd2df05566f Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 2 Mar 2022 09:28:26 +0100 Subject: [PATCH 18/40] Update compileSDK in app/build.gradle and remove dependency - updated compileSdkVersion from 28 to 31 to allow WorkManager API support - removed dependency: implementation 'com.android.support:appcompat-v7:26.1.0' because it is useless in our scope. As stated at https://developer.android.com/topic/libraries/support-library/packages#v7-appcompat it only add ActionBar relative code. But eDrive doesn't use it for a while. --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index c65b01d7..44a0e1de 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -23,7 +23,7 @@ def getTestProp(String propName) { android { - compileSdkVersion 28 + compileSdkVersion 31 defaultConfig { applicationId "foundation.e.drive" minSdkVersion 26 @@ -59,7 +59,7 @@ android { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation 'com.android.support:appcompat-v7:26.1.0' + //implementation 'com.android.support:appcompat-v7:26.1.0' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test:rules:1.0.2' -- GitLab From 49bbf04fa48585018c563db04e8a8bb8f8c6b2db Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 2 Mar 2022 09:43:04 +0100 Subject: [PATCH 19/40] clean dependencies in app/build.gradle - replace all androidTestImplementation and testImplementation library into androidx - reorganize dependencies to make them cleaner --- app/build.gradle | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 44a0e1de..e2bfaed3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -58,27 +58,19 @@ android { dependencies { + api project(':NextcloudLib') implementation fileTree(include: ['*.jar'], dir: 'libs') - //implementation 'com.android.support:appcompat-v7:26.1.0' - - androidTestImplementation 'com.android.support.test:runner:1.0.2' - androidTestImplementation 'com.android.support.test:rules:1.0.2' - androidTestImplementation 'androidx.annotation:annotation:1.3.0' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' api 'androidx.annotation:annotation:1.3.0' - api project(':NextcloudLib') - - //start to add lib for test - 1/4/21 - //@TODO: add junit runner as lib for testImplementation + + androidTestImplementation 'androidx.test:runner:1.4.0' + androidTestImplementation 'androidx.test:rules:1.4.0 ' + androidTestImplementation 'androidx.annotation:annotation:1.3.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + androidTestImplementation 'junit:junit:4.12' - testImplementation 'com.android.support.test:runner:1.0.2' - testImplementation 'com.android.support.test:rules:1.0.2' + testImplementation 'androidx.test:runner:1.4.0' + testImplementation 'androidx.test:rules:1.4.0 ' testImplementation 'junit:junit:4.12' - //testImplementation 'org.robolectric:robolectric:4.4' //need AndroidX - testImplementation "org.robolectric:robolectric:3.8" + testImplementation 'org.robolectric:robolectric:4.4' testImplementation('org.mockito:mockito-inline:3.4.0') - - //testImplementation Libs.AndroidX.Test.archCoreTesting //TODO: replace by not android X version - //implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0' - androidTestImplementation 'junit:junit:4.12' } -- GitLab From 8cfd1537a7392fc93150b018eb8fb5086eb66f3f Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 2 Mar 2022 09:44:47 +0100 Subject: [PATCH 20/40] add jetpack's work dependency --- app/build.gradle | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/build.gradle b/app/build.gradle index e2bfaed3..510784e9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -61,6 +61,10 @@ dependencies { api project(':NextcloudLib') implementation fileTree(include: ['*.jar'], dir: 'libs') api 'androidx.annotation:annotation:1.3.0' + + def work_version = "2.7.1" + // (Java only) + implementation "androidx.work:work-runtime:$work_version" androidTestImplementation 'androidx.test:runner:1.4.0' androidTestImplementation 'androidx.test:rules:1.4.0 ' -- GitLab From 32843030a820568f8f7a22222389a4429c025534 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 2 Mar 2022 09:50:16 +0100 Subject: [PATCH 21/40] fix typo for 'androidx.test:rules' dependencies --- app/build.gradle | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 510784e9..018d91fd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -53,7 +53,6 @@ android { //includeAndroidResources = true } } - } @@ -65,15 +64,15 @@ dependencies { def work_version = "2.7.1" // (Java only) implementation "androidx.work:work-runtime:$work_version" - + androidTestImplementation 'androidx.test:runner:1.4.0' - androidTestImplementation 'androidx.test:rules:1.4.0 ' + androidTestImplementation 'androidx.test:rules:1.4.0' androidTestImplementation 'androidx.annotation:annotation:1.3.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' androidTestImplementation 'junit:junit:4.12' testImplementation 'androidx.test:runner:1.4.0' - testImplementation 'androidx.test:rules:1.4.0 ' + testImplementation 'androidx.test:rules:1.4.0' testImplementation 'junit:junit:4.12' testImplementation 'org.robolectric:robolectric:4.4' testImplementation('org.mockito:mockito-inline:3.4.0') -- GitLab From ffa4eaa907f41cec3847c4d688202d6c05246e24 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 2 Mar 2022 09:43:04 +0100 Subject: [PATCH 22/40] clean dependencies in app/build.gradle - replace all androidTestImplementation and testImplementation library into androidx - reorganize dependencies to make them cleaner fix typo for 'androidx.test:rules' dependencies --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 018d91fd..60825e04 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -60,7 +60,7 @@ dependencies { api project(':NextcloudLib') implementation fileTree(include: ['*.jar'], dir: 'libs') api 'androidx.annotation:annotation:1.3.0' - + def work_version = "2.7.1" // (Java only) implementation "androidx.work:work-runtime:$work_version" -- GitLab From 5a537ca0e8c7f34ac98a629e5a93005895ecd651 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 2 Mar 2022 09:44:47 +0100 Subject: [PATCH 23/40] add jetpack's work dependency --- app/build.gradle | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/build.gradle b/app/build.gradle index 60825e04..63d73424 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -65,6 +65,10 @@ dependencies { // (Java only) implementation "androidx.work:work-runtime:$work_version" + def work_version = "2.7.1" + // (Java only) + implementation "androidx.work:work-runtime:$work_version" + androidTestImplementation 'androidx.test:runner:1.4.0' androidTestImplementation 'androidx.test:rules:1.4.0' androidTestImplementation 'androidx.annotation:annotation:1.3.0' -- GitLab From 01ae192b09ffcaad3a5728d783c0994c3dead7b4 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Thu, 3 Mar 2022 10:13:03 +0100 Subject: [PATCH 24/40] Add new foundation.e.drive.work.FullScanWorker.java - Add new class FullScanWorker.java to be used as replacement of jobs.ScannerJob --- .../e/drive/work/FullScanWorker.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 app/src/main/java/foundation/e/drive/work/FullScanWorker.java diff --git a/app/src/main/java/foundation/e/drive/work/FullScanWorker.java b/app/src/main/java/foundation/e/drive/work/FullScanWorker.java new file mode 100644 index 00000000..dd538e1e --- /dev/null +++ b/app/src/main/java/foundation/e/drive/work/FullScanWorker.java @@ -0,0 +1,45 @@ +/* + * Copyright © Vincent Bourgmayer (/e/ foundation). + * 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.work; + +import android.content.Context; +import android.content.Intent; +import android.util.Log; + +import androidx.annotation.NonNull; +import androidx.work.Worker; +import androidx.work.WorkerParameters; + +import foundation.e.drive.services.ObserverService; + +/** + * As a first step, this class must replace foundation.e.drive.jobs.ScannerJob + * in order to allow to use Jetpack Work API + * + * In further development it will be a part of Workers that will replace ObserverService + * I will update this header accordingly + * + * @author Vincent Bourgmayer + */ +public class FullScanWorker extends Worker { + final private static String TAG = FullScanWorker.class.getSimpleName(); + + public FullScanWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) { + super(context, workerParams); + } + + @NonNull + @Override + public Result doWork() { + Log.d(TAG, "doWork(): going to send intent to ObserverService"); + Intent observerServiceIntent = new Intent(this.getApplicationContext(), ObserverService.class); + this.getApplicationContext().startService(observerServiceIntent); + return Result.success(); + } +} -- GitLab From 6144d553c8cd075580421f6760e97b9138ecb7d3 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Thu, 3 Mar 2022 10:20:53 +0100 Subject: [PATCH 25/40] add generic tag for worker in utils.AppConstants.java --- app/src/main/java/foundation/e/drive/utils/AppConstants.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 1e180424..7506a525 100644 --- a/app/src/main/java/foundation/e/drive/utils/AppConstants.java +++ b/app/src/main/java/foundation/e/drive/utils/AppConstants.java @@ -40,7 +40,7 @@ public abstract class AppConstants { public final static String notificationChannelID ="3310"; public final static String notificationChannelName="eDrive channel"; - + public final static String WORK_GENERIC_TAG="eDrive"; public final static String USER_AGENT = "eos("+getBuildTime()+")-eDrive("+ BuildConfig.VERSION_NAME +")"; -- GitLab From 50a21cb2abf57c6a0975a0d4c3e787d634399f58 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Thu, 3 Mar 2022 10:26:03 +0100 Subject: [PATCH 26/40] clean InitializerService.java - remove useless comment - remove useless import --- .../e/drive/services/InitializerService.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/services/InitializerService.java b/app/src/main/java/foundation/e/drive/services/InitializerService.java index 134063f2..60f09fe6 100644 --- a/app/src/main/java/foundation/e/drive/services/InitializerService.java +++ b/app/src/main/java/foundation/e/drive/services/InitializerService.java @@ -49,9 +49,9 @@ import androidx.annotation.Nullable; */ public class InitializerService extends Service implements OnRemoteOperationListener { final private String TAG = InitializerService.class.getSimpleName(); - //Complex properties - private int existingRemoteFolderCounter; //@dev-only; Temporarily used to know if all remotePath exist - private List mSyncedFolders; //syncedFolders + + private int existingRemoteFolderCounter; //Temporarily used to know if all remotePath exist + private List mSyncedFolders; private OwnCloudClient mCloudClient; private Handler mHandler; private Account mAccount; @@ -62,7 +62,6 @@ public class InitializerService extends Service implements OnRemoteOperationList Log.i(TAG, "onCreate()"); super.onCreate(); this.existingRemoteFolderCounter = 0; - //JobUtils.scheduleInitializerJob(getApplicationContext()); } @Override @@ -84,7 +83,6 @@ public class InitializerService extends Service implements OnRemoteOperationList accountName = intent.getExtras().getString( AccountManager.KEY_ACCOUNT_NAME, "" ); accountType = intent.getExtras().getString( AccountManager.KEY_ACCOUNT_TYPE, "" ); - //If data come from intent, store them into pref because there aren't stored prefs.edit().putString( AccountManager.KEY_ACCOUNT_NAME, accountName ) .putString( AccountManager.KEY_ACCOUNT_TYPE, accountType ) .apply(); @@ -92,7 +90,6 @@ public class InitializerService extends Service implements OnRemoteOperationList if(accountName.isEmpty() ) { Log.w(TAG, "Account's name not found. Neither in shared prefs nor in intent's extras"); - //JobUtils.stopScheduledJob(getApplicationContext(), JobUtils.InitializerJobId); stopSelf(); }else{ this.mAccount = CommonUtils.getAccount( accountName, accountType, AccountManager.get(this) ); @@ -121,7 +118,6 @@ public class InitializerService extends Service implements OnRemoteOperationList return; } - //Get categories of element to sync List syncCategories = new ArrayList<>(); if (CommonUtils.isMediaSyncEnabled(mAccount)) { @@ -132,7 +128,6 @@ public class InitializerService extends Service implements OnRemoteOperationList syncCategories.addAll(Arrays.asList(SETTINGS_SYNCABLE_CATEGORIES)); } - //Get SyncedFolders getInitialSyncedFolders(syncCategories); this.existingRemoteFolderCounter = 0; @@ -211,7 +206,6 @@ public class InitializerService extends Service implements OnRemoteOperationList this.restartFolderCreationCounter = 0; if( this.mSyncedFolders == null || this.mSyncedFolders.isEmpty() ){ - //JobUtils.stopScheduledJob(getApplicationContext(), JobUtils.InitializerJobId); this.stopSelf(); } -- GitLab From e66b6083b874e4c2ab4aa35365fd8218421f03cb Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Thu, 3 Mar 2022 10:27:22 +0100 Subject: [PATCH 27/40] Add usage of WorkManager to enqueue FullScanWorker in InitializerService - Instanciate Constraint for the workRequest (Battery not low, and network available) - Instanciate PeriodicWorkRequest to start FullScanWorker job every 31 minutes with 5 minutes as flex time - Enqueue the workRequest into WorkManager - Add the generic Generic work Tag into the work request - Comment "JobUtils.scheduleScannerJob()" to prevent JobScheduler to run ScannerJob periodically --- .../e/drive/services/InitializerService.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/services/InitializerService.java b/app/src/main/java/foundation/e/drive/services/InitializerService.java index 60f09fe6..2235a05f 100644 --- a/app/src/main/java/foundation/e/drive/services/InitializerService.java +++ b/app/src/main/java/foundation/e/drive/services/InitializerService.java @@ -29,13 +29,15 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.concurrent.TimeUnit; import foundation.e.drive.models.SyncedFolder; import foundation.e.drive.operations.CreateInitialFolderRemoteOperation; import foundation.e.drive.receivers.ScreenOffReceiver; import foundation.e.drive.utils.AppConstants; import foundation.e.drive.utils.CommonUtils; -import foundation.e.drive.utils.ServiceExceptionHandler; + +import foundation.e.drive.work.FullScanWorker; import static com.owncloud.android.lib.resources.files.FileUtils.PATH_SEPARATOR; import static foundation.e.drive.utils.AppConstants.INITIALFOLDERS_NUMBER; @@ -43,6 +45,11 @@ import static foundation.e.drive.utils.AppConstants.MEDIA_SYNCABLE_CATEGORIES; import static foundation.e.drive.utils.AppConstants.SETTINGS_SYNCABLE_CATEGORIES; import androidx.annotation.Nullable; +import androidx.work.Constraints; +import androidx.work.NetworkType; +import androidx.work.PeriodicWorkRequest; +import androidx.work.WorkManager; +import androidx.work.WorkRequest; /** * @author Vincent Bourgmayer @@ -276,8 +283,22 @@ public class InitializerService extends Service implements OnRemoteOperationList .putInt( INITIALFOLDERS_NUMBER, mSyncedFolders.size() ) .apply(); - //all folder have been created + Constraints constraints = new Constraints.Builder() + .setRequiredNetworkType(NetworkType.CONNECTED) + .setRequiresBatteryNotLow(true) + .build(); + + WorkRequest periodicFullScanRequest = + new PeriodicWorkRequest.Builder(FullScanWorker.class, + 31, TimeUnit.MINUTES, + 5, TimeUnit.MINUTES) + .setConstraints(constraints) + .addTag(AppConstants.WORK_GENERIC_TAG) + .build(); + WorkManager.getInstance(this).enqueue(periodicFullScanRequest); + + //all folder have been created Log.d(TAG, "RegisterReceiver: screenOffReceiver"); IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON); -- GitLab From 2ed296caa21f3c99dfb9a47c8d6d37caa0b685e9 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Thu, 3 Mar 2022 10:43:34 +0100 Subject: [PATCH 28/40] Cancel all Work Enqueued when user account is removed and optimize WorkRequest registration - Cancel all work enqueued using the work generic tag in ResetService.java - Add method "RegisterPeriodicFullScanWorker() in CommonUtils - Replace code in InitializerService by CommonUtils.RegisterPeriodicFullScanWorker - Remove Remove unused import --- .../e/drive/services/InitializerService.java | 28 ++++-------------- .../e/drive/services/ResetService.java | 2 ++ .../foundation/e/drive/utils/CommonUtils.java | 29 ++++++++++++++++++- .../e/drive/work/FullScanWorker.java | 1 + 4 files changed, 36 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/services/InitializerService.java b/app/src/main/java/foundation/e/drive/services/InitializerService.java index 2235a05f..0e040150 100644 --- a/app/src/main/java/foundation/e/drive/services/InitializerService.java +++ b/app/src/main/java/foundation/e/drive/services/InitializerService.java @@ -11,10 +11,12 @@ package foundation.e.drive.services; import android.accounts.Account; import android.accounts.AccountManager; import android.app.Service; +import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; +import android.net.Uri; import android.os.Build; import android.os.Environment; import android.os.Handler; @@ -26,17 +28,16 @@ import com.owncloud.android.lib.common.operations.OnRemoteOperationListener; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.concurrent.TimeUnit; import foundation.e.drive.models.SyncedFolder; import foundation.e.drive.operations.CreateInitialFolderRemoteOperation; import foundation.e.drive.receivers.ScreenOffReceiver; import foundation.e.drive.utils.AppConstants; import foundation.e.drive.utils.CommonUtils; - import foundation.e.drive.work.FullScanWorker; import static com.owncloud.android.lib.resources.files.FileUtils.PATH_SEPARATOR; @@ -45,11 +46,7 @@ import static foundation.e.drive.utils.AppConstants.MEDIA_SYNCABLE_CATEGORIES; import static foundation.e.drive.utils.AppConstants.SETTINGS_SYNCABLE_CATEGORIES; import androidx.annotation.Nullable; -import androidx.work.Constraints; -import androidx.work.NetworkType; -import androidx.work.PeriodicWorkRequest; import androidx.work.WorkManager; -import androidx.work.WorkRequest; /** * @author Vincent Bourgmayer @@ -274,8 +271,7 @@ public class InitializerService extends Service implements OnRemoteOperationList **/ private void doLastStep(){ Log.i(TAG, "doLastStep()"); - - Context appContext = getApplicationContext(); + final Context appContext = getApplicationContext(); appContext.getSharedPreferences( AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE ) .edit() @@ -283,20 +279,7 @@ public class InitializerService extends Service implements OnRemoteOperationList .putInt( INITIALFOLDERS_NUMBER, mSyncedFolders.size() ) .apply(); - Constraints constraints = new Constraints.Builder() - .setRequiredNetworkType(NetworkType.CONNECTED) - .setRequiresBatteryNotLow(true) - .build(); - - WorkRequest periodicFullScanRequest = - new PeriodicWorkRequest.Builder(FullScanWorker.class, - 31, TimeUnit.MINUTES, - 5, TimeUnit.MINUTES) - .setConstraints(constraints) - .addTag(AppConstants.WORK_GENERIC_TAG) - .build(); - - WorkManager.getInstance(this).enqueue(periodicFullScanRequest); + CommonUtils.registerPeriodicFullScanWorker(WorkManager.getInstance(appContext)); //all folder have been created @@ -311,7 +294,6 @@ public class InitializerService extends Service implements OnRemoteOperationList stopSelf(); - } @Override diff --git a/app/src/main/java/foundation/e/drive/services/ResetService.java b/app/src/main/java/foundation/e/drive/services/ResetService.java index 204f5341..2144c935 100644 --- a/app/src/main/java/foundation/e/drive/services/ResetService.java +++ b/app/src/main/java/foundation/e/drive/services/ResetService.java @@ -26,6 +26,7 @@ import static foundation.e.drive.utils.AppConstants.INITIALFOLDERS_NUMBER; import static foundation.e.drive.utils.AppConstants.INITIALIZATION_HAS_BEEN_DONE; import androidx.annotation.Nullable; +import androidx.work.WorkManager; /** * @author Vincent Bourgmayer @@ -63,6 +64,7 @@ public class ResetService extends Service { result = getApplicationContext().stopService( stopperIntent ); Log.d(TAG, "stop OperationManagerService: "+result); + WorkManager.getInstance(this).cancelAllWorkByTag(AppConstants.WORK_GENERIC_TAG); //3. delete DB result = this.deleteDatabase(DbHelper.DATABASE_NAME); 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 e0f762fc..59406ac8 100644 --- a/app/src/main/java/foundation/e/drive/utils/CommonUtils.java +++ b/app/src/main/java/foundation/e/drive/utils/CommonUtils.java @@ -17,7 +17,6 @@ import android.content.ContentResolver; import android.content.Context; import android.media.MediaScannerConnection; import android.net.ConnectivityManager; -import android.net.Network; import android.net.NetworkInfo; import android.net.Uri; import android.util.Log; @@ -31,13 +30,20 @@ import com.owncloud.android.lib.common.accounts.AccountUtils; import com.owncloud.android.lib.resources.files.FileUtils; import java.io.File; +import java.util.concurrent.TimeUnit; import foundation.e.drive.receivers.ScreenOffReceiver; +import foundation.e.drive.work.FullScanWorker; import static foundation.e.drive.utils.AppConstants.MEDIASYNC_PROVIDER_AUTHORITY; import static foundation.e.drive.utils.AppConstants.SETTINGSYNC_PROVIDER_AUTHORITY; import androidx.annotation.NonNull; +import androidx.work.Constraints; +import androidx.work.ExistingPeriodicWorkPolicy; +import androidx.work.NetworkType; +import androidx.work.PeriodicWorkRequest; +import androidx.work.WorkManager; /** @@ -293,4 +299,25 @@ public abstract class CommonUtils { + "\n File can be read?: " + f.canRead() + "\n File can be written?: " + f.canWrite(); } + + /** + * Enqueue a unique periodic worker to look for file to be synchronized (remote files + local files + * @param workManager the instance of workManager + */ + public static void registerPeriodicFullScanWorker(WorkManager workManager){ + final Constraints constraints = new Constraints.Builder() + .setRequiredNetworkType(NetworkType.CONNECTED) + .setRequiresBatteryNotLow(true) + .build(); + + final PeriodicWorkRequest periodicFullScanRequest = + new PeriodicWorkRequest.Builder(FullScanWorker.class, + 31, TimeUnit.MINUTES, + 5, TimeUnit.MINUTES) + .setConstraints(constraints) + .addTag(AppConstants.WORK_GENERIC_TAG) + .build(); + + workManager.enqueueUniquePeriodicWork(FullScanWorker.UNIQUE_WORK_NAME , ExistingPeriodicWorkPolicy.KEEP, periodicFullScanRequest); + } } \ No newline at end of file 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 dd538e1e..d05b7b6c 100644 --- a/app/src/main/java/foundation/e/drive/work/FullScanWorker.java +++ b/app/src/main/java/foundation/e/drive/work/FullScanWorker.java @@ -29,6 +29,7 @@ import foundation.e.drive.services.ObserverService; */ public class FullScanWorker extends Worker { final private static String TAG = FullScanWorker.class.getSimpleName(); + final public static String UNIQUE_WORK_NAME="FullScan"; public FullScanWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) { super(context, workerParams); -- GitLab From 07bf89b059e288ce5cdbda5fc6d15d7b80311c77 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Thu, 3 Mar 2022 17:57:29 +0100 Subject: [PATCH 29/40] FullScanWorker doesn't send intent to ObserverService when synchronization is disabled --- .../e/drive/work/FullScanWorker.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) 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 d05b7b6c..b67151c8 100644 --- a/app/src/main/java/foundation/e/drive/work/FullScanWorker.java +++ b/app/src/main/java/foundation/e/drive/work/FullScanWorker.java @@ -8,8 +8,11 @@ package foundation.e.drive.work; +import android.accounts.Account; +import android.accounts.AccountManager; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.util.Log; import androidx.annotation.NonNull; @@ -17,6 +20,8 @@ import androidx.work.Worker; import androidx.work.WorkerParameters; import foundation.e.drive.services.ObserverService; +import foundation.e.drive.utils.AppConstants; +import foundation.e.drive.utils.CommonUtils; /** * As a first step, this class must replace foundation.e.drive.jobs.ScannerJob @@ -39,8 +44,20 @@ public class FullScanWorker extends Worker { @Override public Result doWork() { Log.d(TAG, "doWork(): going to send intent to ObserverService"); - Intent observerServiceIntent = new Intent(this.getApplicationContext(), ObserverService.class); - this.getApplicationContext().startService(observerServiceIntent); + 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{ + Log.w(TAG, "Intent for ObserverService not send : account is null or \"settings sync\" & \"media sync\" settings are disabled"); + } + return Result.success(); } } -- GitLab From 07feb40b634eaf1f619cf2c3b68d10a046700edb Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Fri, 4 Mar 2022 10:07:26 +0100 Subject: [PATCH 30/40] fix spacing in if/else statement and fix 'final' word placement --- .../e/drive/services/InitializerService.java | 40 +++++++++---------- .../foundation/e/drive/utils/CommonUtils.java | 4 +- .../e/drive/work/FullScanWorker.java | 10 ++--- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/services/InitializerService.java b/app/src/main/java/foundation/e/drive/services/InitializerService.java index 0e040150..742fa548 100644 --- a/app/src/main/java/foundation/e/drive/services/InitializerService.java +++ b/app/src/main/java/foundation/e/drive/services/InitializerService.java @@ -11,12 +11,10 @@ package foundation.e.drive.services; import android.accounts.Account; import android.accounts.AccountManager; import android.app.Service; -import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; -import android.net.Uri; import android.os.Build; import android.os.Environment; import android.os.Handler; @@ -52,7 +50,7 @@ import androidx.work.WorkManager; * @author Vincent Bourgmayer */ public class InitializerService extends Service implements OnRemoteOperationListener { - final private String TAG = InitializerService.class.getSimpleName(); + private final String TAG = InitializerService.class.getSimpleName(); private int existingRemoteFolderCounter; //Temporarily used to know if all remotePath exist private List mSyncedFolders; @@ -76,9 +74,11 @@ public class InitializerService extends Service implements OnRemoteOperationList //Get account SharedPreferences prefs = this.getSharedPreferences( AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE ); - if( prefs.getBoolean( AppConstants.INITIALIZATION_HAS_BEEN_DONE, false ) ) { + + if (prefs.getBoolean( AppConstants.INITIALIZATION_HAS_BEEN_DONE, false ) ) { + Log.w(TAG, "Initializer has already been run"); - }else{ + } else { String accountName = prefs.getString( AccountManager.KEY_ACCOUNT_NAME, "" ); String accountType = prefs.getString( AccountManager.KEY_ACCOUNT_TYPE, "" ); @@ -92,16 +92,16 @@ public class InitializerService extends Service implements OnRemoteOperationList .apply(); } - if(accountName.isEmpty() ) { + if (accountName.isEmpty() ) { Log.w(TAG, "Account's name not found. Neither in shared prefs nor in intent's extras"); stopSelf(); - }else{ + } else { this.mAccount = CommonUtils.getAccount( accountName, accountType, AccountManager.get(this) ); //Get OwnCloudlient if (this.mAccount != null) { this.mCloudClient = CommonUtils.getOwnCloudClient( this.mAccount, getApplicationContext()); start(); - }else { + } else { Log.w(TAG, "Got account is invalid."); stopSelf(); } @@ -192,7 +192,7 @@ public class InitializerService extends Service implements OnRemoteOperationList false, true, false) ); - }catch (Exception e){ Log.e(TAG, e.toString()); } + } catch (Exception e){ Log.e(TAG, e.toString()); } break; } } @@ -209,14 +209,14 @@ public class InitializerService extends Service implements OnRemoteOperationList Log.i(TAG, "createNextRemoteFolder()"); this.restartFolderCreationCounter = 0; - if( this.mSyncedFolders == null || this.mSyncedFolders.isEmpty() ){ + if (this.mSyncedFolders == null || this.mSyncedFolders.isEmpty() ){ this.stopSelf(); } //It means that there are still folders to create - if( this.existingRemoteFolderCounter < this.mSyncedFolders.size() ){ + if (this.existingRemoteFolderCounter < this.mSyncedFolders.size() ){ - if( this.mHandler == null ) this.mHandler = new Handler(); + if (this.mHandler == null ) this.mHandler = new Handler(); CreateInitialFolderRemoteOperation createFolderOperation = new CreateInitialFolderRemoteOperation( @@ -226,11 +226,11 @@ public class InitializerService extends Service implements OnRemoteOperationList createFolderOperation.execute(this.mCloudClient, this, this.mHandler); - }else if(this.existingRemoteFolderCounter == this.mSyncedFolders.size() ){ + } else if (this.existingRemoteFolderCounter == this.mSyncedFolders.size() ){ doLastStep(); - }else{ + } else { Log.e(TAG, "this.existingRemoteFolderCounter : "+this.existingRemoteFolderCounter+" > this.mSyncedFolders.size() : "+this.mSyncedFolders.size() ); this.stopSelf(); } @@ -239,26 +239,26 @@ public class InitializerService extends Service implements OnRemoteOperationList @Override public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) { Log.i(TAG, "onRemoteOperationFinish()"); - if(operation instanceof CreateInitialFolderRemoteOperation){ + if (operation instanceof CreateInitialFolderRemoteOperation){ - if(result.isSuccess() || result.getCode() == RemoteOperationResult.ResultCode.FOLDER_ALREADY_EXISTS){ + if (result.isSuccess() || result.getCode() == RemoteOperationResult.ResultCode.FOLDER_ALREADY_EXISTS){ this.existingRemoteFolderCounter+=1; CreateNextRemoteFolder(); - }else if( result.getHttpCode() == 423 || result.getHttpCode() == 409){//file locked or conflict in result + } else if (result.getHttpCode() == 423 || result.getHttpCode() == 409){//file locked or conflict in result Log.e( TAG, result.getLogMessage() ); - if( this.restartFolderCreationCounter < 3) { + if (this.restartFolderCreationCounter < 3) { Log.w( TAG, " restart operation" ); operation.execute( this.mCloudClient, this, this.mHandler ); this.restartFolderCreationCounter+=1; - }else{ + } else { Log.e(TAG, "Remote folder's creation failed due to conflict with server"); stopSelf(); } - }else{ + } else { Log.e(TAG, result.getLogMessage()+" "+result.getHttpCode() ); stopSelf(); } 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 59406ac8..5ba7a072 100644 --- a/app/src/main/java/foundation/e/drive/utils/CommonUtils.java +++ b/app/src/main/java/foundation/e/drive/utils/CommonUtils.java @@ -51,7 +51,7 @@ import androidx.work.WorkManager; */ public abstract class CommonUtils { - final private static String TAG = CommonUtils.class.getSimpleName(); + private final static String TAG = CommonUtils.class.getSimpleName(); /** * Set ServiceUncaughtExceptionHandler to be the MainThread Exception Handler @@ -169,7 +169,7 @@ public abstract class CommonUtils { oc.setCredentials(new OwnCloudBasicCredentials(account.name, AccountManager.get(context).getPassword(account))); Log.d(TAG, "user agent: "+AppConstants.USER_AGENT); - if(!AppConstants.USER_AGENT.equals(OwnCloudClientManagerFactory.getUserAgent())) { + if (!AppConstants.USER_AGENT.equals(OwnCloudClientManagerFactory.getUserAgent()) ){ OwnCloudClientManagerFactory.setUserAgent(AppConstants.USER_AGENT); } 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 b67151c8..08d5b875 100644 --- a/app/src/main/java/foundation/e/drive/work/FullScanWorker.java +++ b/app/src/main/java/foundation/e/drive/work/FullScanWorker.java @@ -33,8 +33,8 @@ import foundation.e.drive.utils.CommonUtils; * @author Vincent Bourgmayer */ public class FullScanWorker extends Worker { - final private static String TAG = FullScanWorker.class.getSimpleName(); - final public static String UNIQUE_WORK_NAME="FullScan"; + private final static String TAG = FullScanWorker.class.getSimpleName(); + public final static String UNIQUE_WORK_NAME="FullScan"; public FullScanWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) { super(context, workerParams); @@ -51,13 +51,13 @@ public class FullScanWorker extends Worker { final Account mAccount = CommonUtils.getAccount( accountName, accountType, AccountManager.get(this.getApplicationContext()) ); - if(mAccount != null && CommonUtils.isSettingsSyncEnabled(mAccount) && CommonUtils.isMediaSyncEnabled(mAccount)) { + if (mAccount != null && CommonUtils.isSettingsSyncEnabled(mAccount) && CommonUtils.isMediaSyncEnabled(mAccount)) { final Intent observerServiceIntent = new Intent(this.getApplicationContext(), ObserverService.class); this.getApplicationContext().startService(observerServiceIntent); - }else{ + } else { Log.w(TAG, "Intent for ObserverService not send : account is null or \"settings sync\" & \"media sync\" settings are disabled"); } return Result.success(); } -} +} \ No newline at end of file -- GitLab From fcf3b8172d5f467e80ea9af534607e7e5a6dc67a Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 2 Mar 2022 10:30:05 +0100 Subject: [PATCH 31/40] Remove BatteryStateReceiver - Removed BatteryStateReceiver.java from foundation.e.drive.receivers package - removed BatteryStateReceiver entry in AndroidManifest.xml --- app/src/main/AndroidManifest.xml | 8 ---- .../drive/receivers/BatteryStateReceiver.java | 39 ------------------- 2 files changed, 47 deletions(-) delete mode 100644 app/src/main/java/foundation/e/drive/receivers/BatteryStateReceiver.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index be871995..e07511c5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -69,14 +69,6 @@ http://www.gnu.org/licenses/gpl.html android:enabled="true" /> - - - - - - diff --git a/app/src/main/java/foundation/e/drive/receivers/BatteryStateReceiver.java b/app/src/main/java/foundation/e/drive/receivers/BatteryStateReceiver.java deleted file mode 100644 index a634635b..00000000 --- a/app/src/main/java/foundation/e/drive/receivers/BatteryStateReceiver.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright © Vincent Bourgmayer (/e/ foundation). - * 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.receivers; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.util.Log; - -/** - * @author Vincent Bourgmayer - */ -public class BatteryStateReceiver extends BroadcastReceiver { - private final static String TAG = BatteryStateReceiver.class.getSimpleName(); - - @Override - public void onReceive(Context context, Intent intent) { - Log.i(TAG, "onReceive"); - - String intentAction = intent.getAction(); - if(intentAction == null) { - Log.e(TAG, "intent Action is null"); - } else if ( intentAction.equals(Intent.ACTION_BATTERY_OKAY) ) { - Log.d(TAG, "BATTERY is Okay. Synchronization job isn't reschedule anymore. Expected behaviour"); - }else if(intentAction.equals(Intent.ACTION_BATTERY_LOW)){ - try { - context.unregisterReceiver(ScreenOffReceiver.getInstance()); - }catch(Exception e){ - Log.e(TAG, e.toString() ); - } - } - } -} -- GitLab From a5a5ff6ad5a625b97ff11077e55ff10289928d7a Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 2 Mar 2022 10:35:57 +0100 Subject: [PATCH 32/40] Remove ScreenOffReceiver - Remove ScreenOffReceiver.java in foundation.e.drive.receivers package - Remove "unregisterScreenOffReceiver()" in CommonUtils - Remove registration code for screenOffReceiver in InitializerService.java and scannerJob.java --- .../foundation/e/drive/jobs/ScannerJob.java | 8 +-- .../e/drive/receivers/ScreenOffReceiver.java | 51 ------------------- .../e/drive/services/InitializerService.java | 8 --- .../foundation/e/drive/utils/CommonUtils.java | 19 +------ 4 files changed, 2 insertions(+), 84 deletions(-) delete mode 100644 app/src/main/java/foundation/e/drive/receivers/ScreenOffReceiver.java diff --git a/app/src/main/java/foundation/e/drive/jobs/ScannerJob.java b/app/src/main/java/foundation/e/drive/jobs/ScannerJob.java index 878f554b..50bfa641 100644 --- a/app/src/main/java/foundation/e/drive/jobs/ScannerJob.java +++ b/app/src/main/java/foundation/e/drive/jobs/ScannerJob.java @@ -11,9 +11,8 @@ package foundation.e.drive.jobs; import android.app.job.JobParameters; import android.app.job.JobService; import android.content.Intent; -import android.content.IntentFilter; import android.util.Log; -import foundation.e.drive.receivers.ScreenOffReceiver; + import foundation.e.drive.services.ObserverService; import foundation.e.drive.utils.CommonUtils; @@ -27,11 +26,6 @@ public class ScannerJob extends JobService { public boolean onStartJob(JobParameters params) { Log.i(TAG, "onStartJob()"); - Log.d(TAG, "RegisterReceiver: screenOffReceiver"); - IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON); - filter.addAction(Intent.ACTION_SCREEN_OFF); - getApplicationContext().registerReceiver(ScreenOffReceiver.getInstance(), filter); - Intent observerServiceIntent = new Intent(this, ObserverService.class); this.startService(observerServiceIntent); jobFinished(params, false); diff --git a/app/src/main/java/foundation/e/drive/receivers/ScreenOffReceiver.java b/app/src/main/java/foundation/e/drive/receivers/ScreenOffReceiver.java deleted file mode 100644 index 27d48959..00000000 --- a/app/src/main/java/foundation/e/drive/receivers/ScreenOffReceiver.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright © Vincent Bourgmayer (/e/ foundation). - * 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.receivers; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.util.Log; -import foundation.e.drive.services.ObserverService; -import foundation.e.drive.utils.CommonUtils; - -/** - * @author Vincent Bourgmayer - * This is a broadcast receiver which catch "ACTION_SCREEN_OFF" to start scanning at a moment - * where the user won't need battery or network. - */ -public class ScreenOffReceiver extends BroadcastReceiver { - private final String TAG = ScreenOffReceiver.class.getSimpleName(); - private static ScreenOffReceiver instance; - - public static ScreenOffReceiver getInstance(){ - if(instance == null) - instance = new ScreenOffReceiver(); - return instance; - } - - /** - * Private constructor - */ - private ScreenOffReceiver(){} - - @Override - public void onReceive(Context context, Intent intent) { - Log.i(TAG, "onReceive"); - String intentAction = intent.getAction(); - if(intentAction == null){ - Log.e(TAG, "intent Action is null"); - } else if ( intent.getAction().equals(Intent.ACTION_SCREEN_OFF) - && CommonUtils.haveNetworkConnexion( context ) ) { - Log.d(TAG, "onReceive: ACTION_SCREEN_OFF"); - Intent cloudIntent = new Intent(context, ObserverService.class); - context.startService(cloudIntent); - } - } -} diff --git a/app/src/main/java/foundation/e/drive/services/InitializerService.java b/app/src/main/java/foundation/e/drive/services/InitializerService.java index aad54992..ad682250 100644 --- a/app/src/main/java/foundation/e/drive/services/InitializerService.java +++ b/app/src/main/java/foundation/e/drive/services/InitializerService.java @@ -13,7 +13,6 @@ import android.accounts.AccountManager; import android.app.Service; import android.content.Context; import android.content.Intent; -import android.content.IntentFilter; import android.content.SharedPreferences; import android.os.Build; import android.os.Environment; @@ -33,7 +32,6 @@ import java.util.List; import foundation.e.drive.models.SyncedFolder; import foundation.e.drive.operations.CreateInitialFolderRemoteOperation; -import foundation.e.drive.receivers.ScreenOffReceiver; import foundation.e.drive.utils.AppConstants; import foundation.e.drive.utils.CommonUtils; @@ -284,16 +282,10 @@ public class InitializerService extends Service implements OnRemoteOperationList //all folder have been created - Log.d(TAG, "RegisterReceiver: screenOffReceiver"); - IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON); - filter.addAction(Intent.ACTION_SCREEN_OFF); - getApplicationContext().registerReceiver(ScreenOffReceiver.getInstance(), filter); - //Immediatly start ObserverService to not have to wait 30 minutes. Intent observersServiceIntent = new Intent(getApplicationContext(), foundation.e.drive.services.ObserverService.class); startService(observersServiceIntent); - stopSelf(); } 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 5ba7a072..6cfb785a 100644 --- a/app/src/main/java/foundation/e/drive/utils/CommonUtils.java +++ b/app/src/main/java/foundation/e/drive/utils/CommonUtils.java @@ -32,7 +32,7 @@ import com.owncloud.android.lib.resources.files.FileUtils; import java.io.File; import java.util.concurrent.TimeUnit; -import foundation.e.drive.receivers.ScreenOffReceiver; + import foundation.e.drive.work.FullScanWorker; import static foundation.e.drive.utils.AppConstants.MEDIASYNC_PROVIDER_AUTHORITY; @@ -70,23 +70,6 @@ public abstract class CommonUtils { } } - /** - * Unregister from screeOffReceiver component - * - * @param context app context - * @return true if unregistration was successful or false if it encounter an exception - */ - public static boolean unregisterScreenOff(Context context) { - try { - Log.d("TAG", "unregisterReceiver(screenOffReceiver)"); - context.unregisterReceiver(ScreenOffReceiver.getInstance()); - } catch (IllegalArgumentException e) { - Log.w(TAG, "Can't unregister screenOffReceiver "); - return false; - } - return true; - } - /** * This method retrieve Account corresponding to account's name and type -- GitLab From 138ca83ed90f42f63721b6ce18adcfaa226f869d Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 2 Mar 2022 10:59:13 +0100 Subject: [PATCH 33/40] Remove remaining call of Commonutils.unregisterSceenOff() - remove call of the method in ResetService.java.onStartCommand() - remove call of the method in ScannerJob.java.onStopJob() --- app/src/main/java/foundation/e/drive/jobs/ScannerJob.java | 1 - .../main/java/foundation/e/drive/services/ResetService.java | 5 +---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/jobs/ScannerJob.java b/app/src/main/java/foundation/e/drive/jobs/ScannerJob.java index 50bfa641..b62738bb 100644 --- a/app/src/main/java/foundation/e/drive/jobs/ScannerJob.java +++ b/app/src/main/java/foundation/e/drive/jobs/ScannerJob.java @@ -40,7 +40,6 @@ public class ScannerJob extends JobService { @Override public boolean onStopJob(JobParameters params) { Log.i(TAG, "onStopJob"); - boolean unregisteredReceiver = CommonUtils.unregisterScreenOff(getApplicationContext()); Intent observerServiceIntent = new Intent(this, ObserverService.class); this.stopService(observerServiceIntent); return false; diff --git a/app/src/main/java/foundation/e/drive/services/ResetService.java b/app/src/main/java/foundation/e/drive/services/ResetService.java index 2144c935..7b7c9d4e 100644 --- a/app/src/main/java/foundation/e/drive/services/ResetService.java +++ b/app/src/main/java/foundation/e/drive/services/ResetService.java @@ -85,11 +85,8 @@ public class ResetService extends Service { .apply(); } - //5. Unregister screenOffReceiver - result = CommonUtils.unregisterScreenOff(getApplicationContext()); - Log.d(TAG, "Unregistered ScreenOffReceiver: "+result); - //6. Remove Cached File + //5. Remove Cached File File[] cachedFiles = this.getApplicationContext().getExternalCacheDir().listFiles(); for(File f : cachedFiles){ f.delete(); -- GitLab From 389ee9c408e2e284620675a7a9fff22287027b1f Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Fri, 4 Mar 2022 17:36:19 +0100 Subject: [PATCH 34/40] Remove ScannerJob.java - Remove foundation.e.drive.job.ScannerJob.java - Remove entry in AndroidManifest.xml about Service for ScannerJob - Remove job package in foundation.e.drive --- app/src/main/AndroidManifest.xml | 3 -- .../foundation/e/drive/jobs/ScannerJob.java | 47 ------------------- 2 files changed, 50 deletions(-) delete mode 100644 app/src/main/java/foundation/e/drive/jobs/ScannerJob.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e07511c5..7337a890 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -61,9 +61,6 @@ http://www.gnu.org/licenses/gpl.html - diff --git a/app/src/main/java/foundation/e/drive/jobs/ScannerJob.java b/app/src/main/java/foundation/e/drive/jobs/ScannerJob.java deleted file mode 100644 index b62738bb..00000000 --- a/app/src/main/java/foundation/e/drive/jobs/ScannerJob.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright © Vincent Bourgmayer (/e/ foundation). - * 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.jobs; - -import android.app.job.JobParameters; -import android.app.job.JobService; -import android.content.Intent; -import android.util.Log; - -import foundation.e.drive.services.ObserverService; -import foundation.e.drive.utils.CommonUtils; - -/** - * @author Vincent Bourgmayer - */ -public class ScannerJob extends JobService { - final private String TAG = ScannerJob.class.getSimpleName(); //Tag for log - - @Override - public boolean onStartJob(JobParameters params) { - Log.i(TAG, "onStartJob()"); - - Intent observerServiceIntent = new Intent(this, ObserverService.class); - this.startService(observerServiceIntent); - jobFinished(params, false); - return true; - } - - /** - * - * @param params - * @return default return... ? - */ - @Override - public boolean onStopJob(JobParameters params) { - Log.i(TAG, "onStopJob"); - Intent observerServiceIntent = new Intent(this, ObserverService.class); - this.stopService(observerServiceIntent); - return false; - } -} -- GitLab From 8b4368988766feaa94d7b9e7ec2f80ae2348f17b Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Mon, 7 Mar 2022 18:41:33 +0100 Subject: [PATCH 35/40] Add DeviceIdle constraint to start FullScan (ObserverService) --- app/src/main/java/foundation/e/drive/utils/CommonUtils.java | 1 + 1 file changed, 1 insertion(+) 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 6cfb785a..6cffadcc 100644 --- a/app/src/main/java/foundation/e/drive/utils/CommonUtils.java +++ b/app/src/main/java/foundation/e/drive/utils/CommonUtils.java @@ -291,6 +291,7 @@ public abstract class CommonUtils { final Constraints constraints = new Constraints.Builder() .setRequiredNetworkType(NetworkType.CONNECTED) .setRequiresBatteryNotLow(true) + .setRequiresDeviceIdle(true) .build(); final PeriodicWorkRequest periodicFullScanRequest = -- GitLab From 69fdbeea99d9c4d251d242872ee0ef322e685c6e Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Mon, 7 Mar 2022 18:41:33 +0100 Subject: [PATCH 36/40] Add DeviceIdle constraint to start FullScan (ObserverService) --- app/src/main/java/foundation/e/drive/utils/CommonUtils.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 6cfb785a..7c1896c5 100644 --- a/app/src/main/java/foundation/e/drive/utils/CommonUtils.java +++ b/app/src/main/java/foundation/e/drive/utils/CommonUtils.java @@ -291,6 +291,7 @@ public abstract class CommonUtils { final Constraints constraints = new Constraints.Builder() .setRequiredNetworkType(NetworkType.CONNECTED) .setRequiresBatteryNotLow(true) + .setRequiresDeviceIdle(true) .build(); final PeriodicWorkRequest periodicFullScanRequest = @@ -301,6 +302,6 @@ public abstract class CommonUtils { .addTag(AppConstants.WORK_GENERIC_TAG) .build(); - workManager.enqueueUniquePeriodicWork(FullScanWorker.UNIQUE_WORK_NAME , ExistingPeriodicWorkPolicy.KEEP, periodicFullScanRequest); + workManager.enqueueUniquePeriodicWork(FullScanWorker.UNIQUE_WORK_NAME, ExistingPeriodicWorkPolicy.KEEP, periodicFullScanRequest); } } \ No newline at end of file -- GitLab From 9e8dd34fdf4973a706aad2e609026d1c3f7d4aaa Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 9 Mar 2022 09:21:23 +0100 Subject: [PATCH 37/40] fixed coding style according to suggestion --- .../java/foundation/e/drive/work/FullScanWorker.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 08d5b875..a2424a07 100644 --- a/app/src/main/java/foundation/e/drive/work/FullScanWorker.java +++ b/app/src/main/java/foundation/e/drive/work/FullScanWorker.java @@ -34,7 +34,7 @@ import foundation.e.drive.utils.CommonUtils; */ public class FullScanWorker extends Worker { private final static String TAG = FullScanWorker.class.getSimpleName(); - public final static String UNIQUE_WORK_NAME="FullScan"; + public final static String UNIQUE_WORK_NAME = "FullScan"; public FullScanWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) { super(context, workerParams); @@ -45,11 +45,11 @@ public class FullScanWorker extends Worker { public Result doWork() { Log.d(TAG, "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, "" ); + 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()) ); + 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); -- GitLab From ce8d8f7397d5865342aeb5fa3856465b0407939f Mon Sep 17 00:00:00 2001 From: Vincent Bourgmayer Date: Wed, 9 Mar 2022 10:04:56 +0000 Subject: [PATCH 38/40] Update .gitlab-ci.yml --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d475c315..18dd3f0e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,4 @@ -image: "registry.gitlab.e.foundation:5000/e/apps/docker-android-apps-cicd:latest" +image: "registry.gitlab.e.foundation:5000/e/os/docker-android-apps-cicd:latest" stages: - test -- GitLab From 09a63c5ae3935e2bea2f9beefddad2d5252152f6 Mon Sep 17 00:00:00 2001 From: Vincent Bourgmayer Date: Wed, 9 Mar 2022 10:06:37 +0000 Subject: [PATCH 39/40] Update .gitlab-ci.yml --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 18dd3f0e..30859edd 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,4 @@ -image: "registry.gitlab.e.foundation:5000/e/os/docker-android-apps-cicd:latest" +image: "registry.gitlab.e.foundation/e/os/docker-android-apps-cicd:latest" stages: - test -- GitLab From e67fd6fbe9a3f80732d3f3270be3ec1448f64153 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Thu, 10 Mar 2022 17:58:38 +0100 Subject: [PATCH 40/40] Disable DeviceIdle constraint for FullScanWorker scheduling This is done accordingly to Product owner's decision because FullScanWorker won't be scheduled often enough with this constraint. --- app/src/main/java/foundation/e/drive/utils/CommonUtils.java | 1 - 1 file changed, 1 deletion(-) 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 7c1896c5..21c2099b 100644 --- a/app/src/main/java/foundation/e/drive/utils/CommonUtils.java +++ b/app/src/main/java/foundation/e/drive/utils/CommonUtils.java @@ -291,7 +291,6 @@ public abstract class CommonUtils { final Constraints constraints = new Constraints.Builder() .setRequiredNetworkType(NetworkType.CONNECTED) .setRequiresBatteryNotLow(true) - .setRequiresDeviceIdle(true) .build(); final PeriodicWorkRequest periodicFullScanRequest = -- GitLab