Loading app/src/main/AndroidManifest.xml +11 −3 Original line number Original line Diff line number Diff line Loading @@ -27,6 +27,7 @@ http://www.gnu.org/licenses/gpl.html android:icon="@mipmap/ic_eelo" android:icon="@mipmap/ic_eelo" android:label="@string/app_name" android:label="@string/app_name" android:roundIcon="@mipmap/ic_eelo_round"> android:roundIcon="@mipmap/ic_eelo_round"> <!-- Providers --> <provider <provider android:authorities="foundation.e.drive.providers.MediasSyncProvider" android:authorities="foundation.e.drive.providers.MediasSyncProvider" android:name=".providers.MediasSyncProvider" android:name=".providers.MediasSyncProvider" Loading @@ -40,6 +41,7 @@ http://www.gnu.org/licenses/gpl.html android:enabled="true" android:enabled="true" android:exported="true"/> android:exported="true"/> <!-- Services --> <service android:name=".services.InitializerService" <service android:name=".services.InitializerService" android:enabled="true" android:enabled="true" android:exported="true"> android:exported="true"> Loading @@ -57,10 +59,16 @@ http://www.gnu.org/licenses/gpl.html <service android:name=".jobs.ScannerJob" <service android:name=".jobs.ScannerJob" android:permission="android.permission.BIND_JOB_SERVICE" /> android:permission="android.permission.BIND_JOB_SERVICE" /> <service android:name=".services.ObserverService" <service android:name=".services.ObserverService" android:enabled="true" android:enabled="true"/> android:exported="true"> </service> <service android:name=".services.OperationManagerService"/> <service android:name=".services.OperationManagerService"/> <!-- Receivers --> <receiver android:name=".receivers.BootCompleteReceiver" android:enabled="true"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver> <receiver android:name=".receivers.BatteryStateReceiver" android:enabled="true"> <receiver android:name=".receivers.BatteryStateReceiver" android:enabled="true"> <intent-filter> <intent-filter> <action android:name="android.intent.action.BATTERY_LOW"/> <action android:name="android.intent.action.BATTERY_LOW"/> Loading app/src/main/java/foundation/e/drive/receivers/BootCompleteReceiver.java 0 → 100644 +47 −0 Original line number Original line Diff line number Diff line /* * 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.accounts.AccountManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.util.Log; import foundation.e.drive.utils.AppConstants; import foundation.e.drive.utils.JobUtils; public class BootCompleteReceiver extends BroadcastReceiver { private final static String TAG = BootCompleteReceiver.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 ( intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) { SharedPreferences prefs = context.getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE); if(prefs.getString(AccountManager.KEY_ACCOUNT_NAME, null) != null) { //If user account is registered prefs.edit().putBoolean(AppConstants.KEY_OMS_IS_WORKING, false).commit(); if ( !JobUtils.isScannerJobRegistered(context)) { //scanner job isn't registered then register it JobUtils.scheduleScannerJob(context); } } } } } app/src/main/java/foundation/e/drive/services/ResetService.java +14 −13 Original line number Original line Diff line number Diff line Loading @@ -69,12 +69,20 @@ public class ResetService extends Service { result = this.deleteDatabase(DbHelper.DATABASE_NAME); result = this.deleteDatabase(DbHelper.DATABASE_NAME); Log.d(TAG, "Remove Database: "+result); Log.d(TAG, "Remove Database: "+result); //4. clear prefs //4. preferences cleaning //Remove the prefs file. if(!this.deleteSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME)){ //If removal failed, clear all data inside prefs.edit().remove(AccountManager.KEY_ACCOUNT_NAME) prefs.edit().remove(AccountManager.KEY_ACCOUNT_NAME) .remove(AccountManager.KEY_ACCOUNT_TYPE) .remove(AccountManager.KEY_ACCOUNT_TYPE) .remove(INITIALIZATION_HAS_BEEN_DONE) .putBoolean(INITIALIZATION_HAS_BEEN_DONE, false) .remove(INITIALFOLDERS_NUMBER) .remove(INITIALFOLDERS_NUMBER) .remove(AppConstants.KEY_OMS_IS_WORKING) .remove(AppConstants.KEY_LAST_SYNC_TIME) .apply(); .apply(); } //5. Unregister screenOffReceiver //5. Unregister screenOffReceiver result = CommonUtils.unregisterScreenOff(getApplicationContext()); result = CommonUtils.unregisterScreenOff(getApplicationContext()); Loading @@ -85,13 +93,6 @@ public class ResetService extends Service { for(File f : cachedFiles){ for(File f : cachedFiles){ f.delete(); f.delete(); } } /*try{ ActivityManager activityManager = (ActivityManager) getSystemService(ActivityManager.class); Log.d(TAG, "clearApplicationUserData: "+activityManager.clearApplicationUserData()); activityManager.killBackgroundProcesses("foundation.e.drive"); }catch (Exception e){ Log.e(TAG, e.toString() ); }*/ } } } } } } Loading app/src/main/java/foundation/e/drive/utils/JobUtils.java +10 −0 Original line number Original line Diff line number Diff line Loading @@ -57,4 +57,14 @@ public abstract class JobUtils { public static void stopScheduledJob(Context context, int jobId){ public static void stopScheduledJob(Context context, int jobId){ context.getSystemService( JobScheduler.class ).cancel(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); } } } Loading
app/src/main/AndroidManifest.xml +11 −3 Original line number Original line Diff line number Diff line Loading @@ -27,6 +27,7 @@ http://www.gnu.org/licenses/gpl.html android:icon="@mipmap/ic_eelo" android:icon="@mipmap/ic_eelo" android:label="@string/app_name" android:label="@string/app_name" android:roundIcon="@mipmap/ic_eelo_round"> android:roundIcon="@mipmap/ic_eelo_round"> <!-- Providers --> <provider <provider android:authorities="foundation.e.drive.providers.MediasSyncProvider" android:authorities="foundation.e.drive.providers.MediasSyncProvider" android:name=".providers.MediasSyncProvider" android:name=".providers.MediasSyncProvider" Loading @@ -40,6 +41,7 @@ http://www.gnu.org/licenses/gpl.html android:enabled="true" android:enabled="true" android:exported="true"/> android:exported="true"/> <!-- Services --> <service android:name=".services.InitializerService" <service android:name=".services.InitializerService" android:enabled="true" android:enabled="true" android:exported="true"> android:exported="true"> Loading @@ -57,10 +59,16 @@ http://www.gnu.org/licenses/gpl.html <service android:name=".jobs.ScannerJob" <service android:name=".jobs.ScannerJob" android:permission="android.permission.BIND_JOB_SERVICE" /> android:permission="android.permission.BIND_JOB_SERVICE" /> <service android:name=".services.ObserverService" <service android:name=".services.ObserverService" android:enabled="true" android:enabled="true"/> android:exported="true"> </service> <service android:name=".services.OperationManagerService"/> <service android:name=".services.OperationManagerService"/> <!-- Receivers --> <receiver android:name=".receivers.BootCompleteReceiver" android:enabled="true"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver> <receiver android:name=".receivers.BatteryStateReceiver" android:enabled="true"> <receiver android:name=".receivers.BatteryStateReceiver" android:enabled="true"> <intent-filter> <intent-filter> <action android:name="android.intent.action.BATTERY_LOW"/> <action android:name="android.intent.action.BATTERY_LOW"/> Loading
app/src/main/java/foundation/e/drive/receivers/BootCompleteReceiver.java 0 → 100644 +47 −0 Original line number Original line Diff line number Diff line /* * 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.accounts.AccountManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.util.Log; import foundation.e.drive.utils.AppConstants; import foundation.e.drive.utils.JobUtils; public class BootCompleteReceiver extends BroadcastReceiver { private final static String TAG = BootCompleteReceiver.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 ( intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) { SharedPreferences prefs = context.getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE); if(prefs.getString(AccountManager.KEY_ACCOUNT_NAME, null) != null) { //If user account is registered prefs.edit().putBoolean(AppConstants.KEY_OMS_IS_WORKING, false).commit(); if ( !JobUtils.isScannerJobRegistered(context)) { //scanner job isn't registered then register it JobUtils.scheduleScannerJob(context); } } } } }
app/src/main/java/foundation/e/drive/services/ResetService.java +14 −13 Original line number Original line Diff line number Diff line Loading @@ -69,12 +69,20 @@ public class ResetService extends Service { result = this.deleteDatabase(DbHelper.DATABASE_NAME); result = this.deleteDatabase(DbHelper.DATABASE_NAME); Log.d(TAG, "Remove Database: "+result); Log.d(TAG, "Remove Database: "+result); //4. clear prefs //4. preferences cleaning //Remove the prefs file. if(!this.deleteSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME)){ //If removal failed, clear all data inside prefs.edit().remove(AccountManager.KEY_ACCOUNT_NAME) prefs.edit().remove(AccountManager.KEY_ACCOUNT_NAME) .remove(AccountManager.KEY_ACCOUNT_TYPE) .remove(AccountManager.KEY_ACCOUNT_TYPE) .remove(INITIALIZATION_HAS_BEEN_DONE) .putBoolean(INITIALIZATION_HAS_BEEN_DONE, false) .remove(INITIALFOLDERS_NUMBER) .remove(INITIALFOLDERS_NUMBER) .remove(AppConstants.KEY_OMS_IS_WORKING) .remove(AppConstants.KEY_LAST_SYNC_TIME) .apply(); .apply(); } //5. Unregister screenOffReceiver //5. Unregister screenOffReceiver result = CommonUtils.unregisterScreenOff(getApplicationContext()); result = CommonUtils.unregisterScreenOff(getApplicationContext()); Loading @@ -85,13 +93,6 @@ public class ResetService extends Service { for(File f : cachedFiles){ for(File f : cachedFiles){ f.delete(); f.delete(); } } /*try{ ActivityManager activityManager = (ActivityManager) getSystemService(ActivityManager.class); Log.d(TAG, "clearApplicationUserData: "+activityManager.clearApplicationUserData()); activityManager.killBackgroundProcesses("foundation.e.drive"); }catch (Exception e){ Log.e(TAG, e.toString() ); }*/ } } } } } } Loading
app/src/main/java/foundation/e/drive/utils/JobUtils.java +10 −0 Original line number Original line Diff line number Diff line Loading @@ -57,4 +57,14 @@ public abstract class JobUtils { public static void stopScheduledJob(Context context, int jobId){ public static void stopScheduledJob(Context context, int jobId){ context.getSystemService( JobScheduler.class ).cancel(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); } } }