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

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

FullScanWorker doesn't send intent to ObserverService when synchronization is disabled

parent b10255e0
Loading
Loading
Loading
Loading
Loading
+19 −2
Original line number Diff line number Diff line
@@ -8,8 +8,11 @@

package foundation.e.drive.work;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;

import androidx.annotation.NonNull;
@@ -17,6 +20,8 @@ import androidx.work.Worker;
import androidx.work.WorkerParameters;

import foundation.e.drive.services.ObserverService;
import foundation.e.drive.utils.AppConstants;
import foundation.e.drive.utils.CommonUtils;

/**
 * As a first step, this class must replace foundation.e.drive.jobs.ScannerJob
@@ -39,8 +44,20 @@ public class FullScanWorker extends Worker {
    @Override
    public Result doWork() {
        Log.d(TAG, "doWork(): going to send intent to ObserverService");
        Intent observerServiceIntent = new Intent(this.getApplicationContext(), ObserverService.class);
        final SharedPreferences prefs = getApplicationContext().getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME,
                Context.MODE_PRIVATE );
        final String accountName = prefs.getString( AccountManager.KEY_ACCOUNT_NAME, "" );
        final String accountType = prefs.getString( AccountManager.KEY_ACCOUNT_TYPE, "" );

        final Account mAccount = CommonUtils.getAccount( accountName, accountType, AccountManager.get(this.getApplicationContext()) );

        if(mAccount != null && CommonUtils.isSettingsSyncEnabled(mAccount) && CommonUtils.isMediaSyncEnabled(mAccount)) {
            final Intent observerServiceIntent = new Intent(this.getApplicationContext(), ObserverService.class);
            this.getApplicationContext().startService(observerServiceIntent);
        }else{
            Log.w(TAG, "Intent for ObserverService not send : account is null or  \"settings sync\" & \"media sync\" settings are disabled");
        }

        return Result.success();
    }
}