From e7912568a5fe88ebac21e9aacfbedf906cf09970 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 2 Mar 2022 10:30:05 +0100 Subject: [PATCH 1/6] 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 2/6] 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 3/6] 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 fcf3b8172d5f467e80ea9af534607e7e5a6dc67a Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 2 Mar 2022 10:30:05 +0100 Subject: [PATCH 4/6] 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 5/6] 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 6/6] 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