Commit 394d3604 authored by Vincent Bourgmayer's avatar Vincent Bourgmayer 🎼
Browse files

Issue 95 o

parent ca607968
Pipeline #31803 passed with stage
in 2 minutes and 1 second
......@@ -27,6 +27,7 @@ http://www.gnu.org/licenses/gpl.html
android:icon="@mipmap/ic_eelo"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_eelo_round">
<!-- Providers -->
<provider
android:authorities="foundation.e.drive.providers.MediasSyncProvider"
android:name=".providers.MediasSyncProvider"
......@@ -40,6 +41,7 @@ http://www.gnu.org/licenses/gpl.html
android:enabled="true"
android:exported="true"/>
<!-- Services -->
<service android:name=".services.InitializerService"
android:enabled="true"
android:exported="true">
......@@ -57,10 +59,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"/>
......
/*
* 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);
}
}
}
}
}
......@@ -69,12 +69,20 @@ public class ResetService extends Service {
result = this.deleteDatabase(DbHelper.DATABASE_NAME);
Log.d(TAG, "Remove Database: "+result);
//4. clear prefs
prefs.edit().remove(AccountManager.KEY_ACCOUNT_NAME)
.remove(AccountManager.KEY_ACCOUNT_TYPE)
.remove(INITIALIZATION_HAS_BEEN_DONE)
.remove(INITIALFOLDERS_NUMBER)
.apply();
//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());
......@@ -85,13 +93,6 @@ public class ResetService extends Service {
for(File f : cachedFiles){
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() );
}*/
}
}
}
......
......@@ -57,4 +57,14 @@ 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);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment