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

Commit 42a48e45 authored by Vincent Bourgmayer's avatar Vincent Bourgmayer
Browse files

Merge branch '305-o-limitTransferTrial' into 'v1-oreo'

Limit number of file transfer

See merge request !133
parents 291fca1a 1e193c4c
Loading
Loading
Loading
Loading
Loading
+22 −14
Original line number Diff line number Diff line
@@ -11,12 +11,9 @@ package foundation.e.drive;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Application;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Environment;
import android.util.Log;

@@ -31,7 +28,6 @@ import foundation.e.drive.utils.CommonUtils;
 * It is instantiated before any other class.
 */
public class EdriveApplication extends Application {

    private static final String TAG = "EdriveApplication";
    private RecursiveFileObserver mFileObserver = null;
    private FileEventListener fileEventListener;
@@ -45,22 +41,24 @@ public class EdriveApplication extends Application {
        final String pathForObserver = Environment.getExternalStorageDirectory().getAbsolutePath();
        mFileObserver = new RecursiveFileObserver(getApplicationContext(), pathForObserver, fileEventListener);

        SharedPreferences prefs = getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE);
        final SharedPreferences prefs = getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE);
        CommonUtils.createNotificationChannel(getApplicationContext());

        if (prefs.getString(AccountManager.KEY_ACCOUNT_NAME, null) != null) {
            Log.d(TAG, "Account already registered");
            startRecursiveFileObserver();

            Intent SynchronizationServiceIntent = new Intent(getApplicationContext(), SynchronizationService.class);
            resetTransferFailureCounter();

            final Intent SynchronizationServiceIntent = new Intent(getApplicationContext(), SynchronizationService.class);
            startService(SynchronizationServiceIntent);

        } else {
            Account mAccount = CommonUtils.getAccount(getString(R.string.eelo_account_type), AccountManager.get(this));
            final Account mAccount = CommonUtils.getAccount(getString(R.string.eelo_account_type), AccountManager.get(this));
            if (mAccount == null) { return; }

            String accountName = mAccount.name;
            String accountType = mAccount.type;
            final String accountName = mAccount.name;
            final String accountType = mAccount.type;

            prefs.edit().putString(AccountManager.KEY_ACCOUNT_NAME, accountName)
                    .putString(AccountManager.KEY_ACCOUNT_TYPE, accountType)
@@ -76,8 +74,7 @@ public class EdriveApplication extends Application {
            fileEventListener.bindToSynchronizationService();
            mFileObserver.startWatching();
            Log.d(TAG, "Starting RecursiveFileObserver on root folder");
        }
        else {
        } else {
            Log.w(TAG, "RecursiveFileObserver (for media's root folder) was already running");
        }
    }
@@ -88,6 +85,17 @@ public class EdriveApplication extends Application {
        Log.d(TAG, "RecursiveFileObserver on root folder stops watching ");
    }


    /**
     * Clear sharedPreference that store failed transfer counter.
     * Doing this here, allow to restart it once a day.
     */
    private void resetTransferFailureCounter() {
        final SharedPreferences prefs = getSharedPreferences(AppConstants.FAILED_TRANSFER_PREF, Context.MODE_PRIVATE);
        prefs.edit().clear().commit();
    }


    @Override
    public void onLowMemory() {
        super.onLowMemory();
+1 −1
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ public class FileEventListener {
    private void sendSyncRequestToSynchronizationService(SyncRequest request) {
        Log.d(TAG, "Sending a SyncRequest for " + request.getSyncedFileState().getName());
        if (serviceConnection.isBoundToSynchronizationService()) {
            serviceConnection.getSynchronizationService().queueOperation(request);
            serviceConnection.getSynchronizationService().queueSyncRequest(request);
            serviceConnection.getSynchronizationService().startSynchronization();
        }else{
            Log.w(TAG, "Impossible to send SyncRequest. FileEventListener is not bound to SynchronizationService");
+4 −0
Original line number Diff line number Diff line
@@ -82,4 +82,8 @@ public class SyncWrapper {
        }
        return super.equals(obj);
    }

    public SyncRequest getRequest() {
        return request;
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -323,7 +323,7 @@ public class ObserverService extends Service implements OnRemoteOperationListene

    private void passSyncRequestsToSynchronizationService() {
        if (synchronizationServiceConnection.isBoundToSynchronizationService()) {
            synchronizationServiceConnection.getSynchronizationService().queueOperations(syncRequests.values());
            synchronizationServiceConnection.getSynchronizationService().queueSyncRequests(syncRequests.values());
            synchronizationServiceConnection.getSynchronizationService().startSynchronization();
        } else {
            Log.e(TAG, "ERROR: impossible to bind ObserverService to SynchronizationService");
+2 −0
Original line number Diff line number Diff line
@@ -92,6 +92,8 @@ public class ResetService extends Service {
                    .remove(AppConstants.KEY_LAST_SYNC_TIME)
                    .apply();
        }

        deleteSharedPreferences(AppConstants.FAILED_TRANSFER_PREF);
    }

    private void removeCachedFiles() {
Loading