Loading app/src/main/AndroidManifest.xml +14 −7 Original line number Diff line number Diff line Loading @@ -22,8 +22,9 @@ http://www.gnu.org/licenses/gpl.html android:allowBackup="true" android:icon="@mipmap/ic_eelo" android:label="@string/app_name" android:roundIcon="@mipmap/ic_eelo_round" android:supportsRtl="true"> android:roundIcon="@mipmap/ic_eelo_round"> <!-- Provider --> <provider android:authorities="foundation.e.drive.providers.MediasSyncProvider" android:name=".providers.MediasSyncProvider" Loading @@ -36,6 +37,8 @@ http://www.gnu.org/licenses/gpl.html android:label="Application settings" android:enabled="true" android:exported="true"/> <!-- Services --> <service android:name=".services.InitializerService" android:enabled="true" android:exported="true"> Loading @@ -43,7 +46,6 @@ http://www.gnu.org/licenses/gpl.html <action android:name="drive.services.InitializerService" /> </intent-filter> </service> <service android:name=".services.ResetService" android:enabled="true" android:exported="true"> Loading @@ -54,11 +56,16 @@ http://www.gnu.org/licenses/gpl.html <service android:name=".jobs.ScannerJob" android:permission="android.permission.BIND_JOB_SERVICE" /> <service android:name=".services.ObserverService" android:enabled="true" android:exported="true"> </service> android:enabled="true"/> <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"> <intent-filter> <action android:name="android.intent.action.BATTERY_LOW"/> Loading app/src/main/java/foundation/e/drive/receivers/BootCompleteReceiver.java 0 → 100644 +39 −0 Original line number Diff line number Diff line 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.services.ObserverService; import foundation.e.drive.utils.AppConstants; import foundation.e.drive.utils.CommonUtils; 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 +17 −6 Original line number Diff line number Diff line Loading @@ -16,6 +16,9 @@ import android.content.SharedPreferences; import android.os.IBinder; import android.support.annotation.Nullable; import android.util.Log; import com.owncloud.android.lib.common.accounts.AccountUtils; import java.io.File; import foundation.e.drive.database.DbHelper; import foundation.e.drive.utils.AppConstants; Loading Loading @@ -64,12 +67,20 @@ public class ResetService extends Service { result = this.deleteDatabase(DbHelper.DATABASE_NAME); 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) .remove(AccountManager.KEY_ACCOUNT_TYPE) .putBoolean(INITIALIZATION_HAS_BEEN_DONE, false) .remove(INITIALFOLDERS_NUMBER) .remove(AppConstants.KEY_OMS_IS_WORKING) .remove(AppConstants.KEY_LAST_SYNC_TIME) .apply(); } //5. Unregister screenOffReceiver result = CommonUtils.unregisterScreenOff(getApplicationContext()); Loading app/src/main/java/foundation/e/drive/utils/JobUtils.java +9 −0 Original line number Diff line number Diff line Loading @@ -54,4 +54,13 @@ public abstract class JobUtils { 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); } } Loading
app/src/main/AndroidManifest.xml +14 −7 Original line number Diff line number Diff line Loading @@ -22,8 +22,9 @@ http://www.gnu.org/licenses/gpl.html android:allowBackup="true" android:icon="@mipmap/ic_eelo" android:label="@string/app_name" android:roundIcon="@mipmap/ic_eelo_round" android:supportsRtl="true"> android:roundIcon="@mipmap/ic_eelo_round"> <!-- Provider --> <provider android:authorities="foundation.e.drive.providers.MediasSyncProvider" android:name=".providers.MediasSyncProvider" Loading @@ -36,6 +37,8 @@ http://www.gnu.org/licenses/gpl.html android:label="Application settings" android:enabled="true" android:exported="true"/> <!-- Services --> <service android:name=".services.InitializerService" android:enabled="true" android:exported="true"> Loading @@ -43,7 +46,6 @@ http://www.gnu.org/licenses/gpl.html <action android:name="drive.services.InitializerService" /> </intent-filter> </service> <service android:name=".services.ResetService" android:enabled="true" android:exported="true"> Loading @@ -54,11 +56,16 @@ http://www.gnu.org/licenses/gpl.html <service android:name=".jobs.ScannerJob" android:permission="android.permission.BIND_JOB_SERVICE" /> <service android:name=".services.ObserverService" android:enabled="true" android:exported="true"> </service> android:enabled="true"/> <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"> <intent-filter> <action android:name="android.intent.action.BATTERY_LOW"/> Loading
app/src/main/java/foundation/e/drive/receivers/BootCompleteReceiver.java 0 → 100644 +39 −0 Original line number Diff line number Diff line 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.services.ObserverService; import foundation.e.drive.utils.AppConstants; import foundation.e.drive.utils.CommonUtils; 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 +17 −6 Original line number Diff line number Diff line Loading @@ -16,6 +16,9 @@ import android.content.SharedPreferences; import android.os.IBinder; import android.support.annotation.Nullable; import android.util.Log; import com.owncloud.android.lib.common.accounts.AccountUtils; import java.io.File; import foundation.e.drive.database.DbHelper; import foundation.e.drive.utils.AppConstants; Loading Loading @@ -64,12 +67,20 @@ public class ResetService extends Service { result = this.deleteDatabase(DbHelper.DATABASE_NAME); 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) .remove(AccountManager.KEY_ACCOUNT_TYPE) .putBoolean(INITIALIZATION_HAS_BEEN_DONE, false) .remove(INITIALFOLDERS_NUMBER) .remove(AppConstants.KEY_OMS_IS_WORKING) .remove(AppConstants.KEY_LAST_SYNC_TIME) .apply(); } //5. Unregister screenOffReceiver result = CommonUtils.unregisterScreenOff(getApplicationContext()); Loading
app/src/main/java/foundation/e/drive/utils/JobUtils.java +9 −0 Original line number Diff line number Diff line Loading @@ -54,4 +54,13 @@ public abstract class JobUtils { 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); } }