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

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

Merge branch '7-2-removeReceiver' into '7-issue-workmanagerAPI'

Remove BatteryState & ScreenOff receivers

See merge request e/apps/eDrive!75
parents 5105f600 b6d7335b
Loading
Loading
Loading
Loading
Loading
+0 −8
Original line number Diff line number Diff line
@@ -69,14 +69,6 @@ http://www.gnu.org/licenses/gpl.html
            android:enabled="true" />
        <service android:name=".services.OperationManagerService" />

        <receiver
            android:name=".receivers.BatteryStateReceiver"
            android:enabled="true">
            <intent-filter>
                <action android:name="android.intent.action.BATTERY_LOW" />
                <action android:name="android.intent.action.BATTERY_OKAY" />
            </intent-filter>
        </receiver>
        <receiver
            android:name=".receivers.PackageEventReceiver"
            android:enabled="true">
+1 −8
Original line number Diff line number Diff line
@@ -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);
@@ -46,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;
+0 −39
Original line number 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.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() );
            }
        }
    }
}
+0 −51
Original line number 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.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);
        }
    }
}
+0 −8
Original line number Diff line number Diff line
@@ -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();
    }

Loading