Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fe849af6 authored by Vincent Bourgmayer's avatar Vincent Bourgmayer
Browse files

Issue 95 n

parent f18487cf
Loading
Loading
Loading
Loading
Loading
+14 −7
Original line number Diff line number Diff line
@@ -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"
@@ -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">
@@ -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">
@@ -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"/>
+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);}
            }
        }
    }
}
+17 −6
Original line number Diff line number Diff line
@@ -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;
@@ -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());
+9 −0
Original line number Diff line number Diff line
@@ -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);
    }
}