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

Commit e4f55a47 authored by vince-bourgmayer's avatar vince-bourgmayer
Browse files

fix account deletion reaction

parent 091ea628
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ import io.eelo.drive.models.SyncedFileState;
public final class DbHelper extends SQLiteOpenHelper {
    final private static String TAG = DbHelper.class.getSimpleName(); //Tag for log
    private static final int DATABASE_VERSION = 14;
    private static final String DATABASE_NAME = "eelo_drive.db";
    public static final String DATABASE_NAME = "eelo_drive.db";

    /**
     * Constructor of the helper
+7 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ import android.util.Log;

import io.eelo.drive.receivers.ScreenOffReceiver;
import io.eelo.drive.services.ObserverService;
import io.eelo.drive.utils.CommonUtils;

/**
 * @author Vincent Bourgmayer
@@ -38,10 +39,15 @@ public class ScannerJob extends JobService {
        return true;
    }

    /**
     *
     * @param params
     * @return default return... ?
     */
    @Override
    public boolean onStopJob(JobParameters params) {
        Log.i(TAG, "onStopJob");
        this.unregisterReceiver(ScreenOffReceiver.getInstance());
        boolean unregisteredReceiver = CommonUtils.unregisterScreenOff(getApplicationContext());
        Intent observerServiceIntent = new Intent(this, ObserverService.class);
        this.stopService(observerServiceIntent);
        return false;
+15 −29
Original line number Diff line number Diff line
@@ -15,7 +15,6 @@ import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.files.CreateRemoteFolderOperation;
import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation;

import java.io.File;

@@ -32,15 +31,13 @@ public class CreateInitialRemoteFolderOperation extends RemoteOperation {
    private SyncedFolder mSyncedFolder;
    private String mRemotePath;
    private boolean mCreateFullPath;//should recreate parent path if not exist or not
    private boolean mUseNextcloudAgent;
    private final Context mContext;

    public CreateInitialRemoteFolderOperation(SyncedFolder root, boolean createFullPath, boolean useNextcloudAgent, Context context) {
    public CreateInitialRemoteFolderOperation(SyncedFolder root, boolean createFullPath, Context context) {
        super();
        this.mSyncedFolder = root;
        this.mRemotePath = root.getRemoteFolder();
        this.mCreateFullPath = createFullPath;
        this.mUseNextcloudAgent = useNextcloudAgent;
        this.mContext = context;
    }

@@ -51,31 +48,20 @@ public class CreateInitialRemoteFolderOperation extends RemoteOperation {
            Log.e(TAG, "Local folder doesn't exist, so create it");
            folder.mkdirs();
        }
        /*ExistenceCheckRemoteOperation presenceCheckOperation = new ExistenceCheckRemoteOperation(mRemotePath, false);
        RemoteOperationResult presenceCheckResult = presenceCheckOperation.execute(client, mUseNextcloudAgent);
        if(!presenceCheckResult.isSuccess()){*/

        CreateRemoteFolderOperation createFolderOperation = new CreateRemoteFolderOperation(mRemotePath, mCreateFullPath);
            RemoteOperationResult createOperationResult = createFolderOperation.execute(client, true);

        RemoteOperationResult createOperationResult;
        try {
             createOperationResult = createFolderOperation.execute(client, true);
        }catch (Exception e){
            createOperationResult = new RemoteOperationResult(e);
        }
        if(createOperationResult.isSuccess() || createOperationResult.getCode() == RemoteOperationResult.ResultCode.FOLDER_ALREADY_EXISTS ){
                /*ExistenceCheckRemoteOperation existenceCheckOperation = new ExistenceCheckRemoteOperation(mRemotePath, false);
                RemoteOperationResult ExistenceCheckResult = existenceCheckOperation.execute(client, mUseNextcloudAgent);
                if(ExistenceCheckResult.isSuccess() ){*/
                    //Save in DB;
                if(DbHelper.insertSyncedFolder(mSyncedFolder, mContext) >= 0 )
                    return createOperationResult;
                else
            if(DbHelper.insertSyncedFolder(mSyncedFolder, mContext) >= 0 ) {
                return new RemoteOperationResult(RemoteOperationResult.ResultCode.OK);
            }else
                return new RemoteOperationResult(RemoteOperationResult.ResultCode.CANCELLED);
               /* }
                return ExistenceCheckResult;*/

        }
        return createOperationResult;

        /*} else {
            Log.e(TAG, mRemotePath + " Already exist");
            DbHelper.insertSyncedFolder(mSyncedFolder, mContext);
            return presenceCheckResult;
        }*/
    }
}
+5 −5
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import io.eelo.drive.database.DbHelper;
import io.eelo.drive.models.SyncedFolder;
import io.eelo.drive.operations.CreateInitialRemoteFolderOperation;
import io.eelo.drive.utils.AppConstants;
@@ -146,7 +147,6 @@ public class InitializerService extends Service implements OnRemoteOperationList
    /**
     * Return a list of SyncedFolder
     * @param categories categories indicating which syncedFolder to create
     * @return list des synced Folders
     */
    private void getInitialSyncedFolders( List<String> categories){
        Log.i(TAG, "getInitialSyncedFolders");
@@ -155,6 +155,8 @@ public class InitializerService extends Service implements OnRemoteOperationList
            final String DEVICE_SPECIFIC_PATH = PATH_SEPARATOR+"Devices"+PATH_SEPARATOR+ Build.BRAND+"_"+ Build.MODEL+"_"
                    + Build.SERIAL;
            switch (categories.get(i)){
                case "Medias":
                    break;
                case "Images":
                    mSyncedFolders.add( new SyncedFolder(categories.get(i), getExternalFolder(Environment.DIRECTORY_DCIM),
                            "/Photos/" ) );
@@ -217,7 +219,7 @@ public class InitializerService extends Service implements OnRemoteOperationList
        }
    }
    private String getExternalFolder(String directory){
        return Environment.getExternalStoragePublicDirectory(directory).getAbsolutePath()+ PATH_SEPARATOR;
        return CommonUtils.getLocalPath(Environment.getExternalStoragePublicDirectory(directory))+ PATH_SEPARATOR;
    }

    /**
@@ -228,7 +230,7 @@ public class InitializerService extends Service implements OnRemoteOperationList
        if(currentRemoteFolderIndex >= this.mSyncedFolders.size() || mSyncedFolders.isEmpty() ){
            Log.e(TAG, "startFolderCreation, currentRemoteFolderIndex >= mSyncedFolders.size || mSyncedFolders is empty");
        }else {
            CreateInitialRemoteFolderOperation initializeRemoteFolderOperation = new CreateInitialRemoteFolderOperation(mSyncedFolders.get(currentRemoteFolderIndex), true, true, this);
            CreateInitialRemoteFolderOperation initializeRemoteFolderOperation = new CreateInitialRemoteFolderOperation(mSyncedFolders.get(currentRemoteFolderIndex),  true, this);
            initializeRemoteFolderOperation.execute(this.mCloudClient, this, mHandler);
        }
    }
@@ -249,8 +251,6 @@ public class InitializerService extends Service implements OnRemoteOperationList
                }else{
                    Log.w(TAG, "Remote folder's creation failed due to conflict with server");
                }
            }else{

            }
        }
    }
+30 −9
Original line number Diff line number Diff line
@@ -35,7 +35,6 @@ import java.io.File;
import java.io.FileFilter;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.ListIterator;

@@ -48,13 +47,15 @@ import io.eelo.drive.operations.DownloadFileOperation;
import io.eelo.drive.operations.ListRemoteFileOperation;
import io.eelo.drive.operations.RemoveFileOperation;
import io.eelo.drive.operations.UploadFileOperation;
import io.eelo.drive.receivers.ScreenOffReceiver;
import io.eelo.drive.utils.AppConstants;
import io.eelo.drive.utils.CommonUtils;
import io.eelo.drive.utils.IGetOCClient;
import io.eelo.drive.utils.JobUtils;
import io.fabric.sdk.android.Fabric;

import static io.eelo.drive.utils.AppConstants.MEDIASYNC_PROVIDER_AUTHORITY;
import static io.eelo.drive.utils.AppConstants.SETTINGSYNC_PROVIDER_AUTHORITY;
import static io.eelo.drive.utils.AppConstants.INITIALIZERSERVICE_HAS_RUN;


/**
 * @author Vincent Bourgmayer
@@ -124,12 +125,35 @@ public class ObserverService extends Service implements OnRemoteOperationListene
        //if A scan isn't already in progress
        SharedPreferences prefs = this.getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE);

        if (prefs.getBoolean(AppConstants.INITIALIZERSERVICE_HAS_RUN, false)) {
        if (prefs.getBoolean(INITIALIZERSERVICE_HAS_RUN, false)) {

            String accountName = prefs.getString(AccountManager.KEY_ACCOUNT_NAME, "");
            String accountType = prefs.getString(AccountManager.KEY_ACCOUNT_TYPE, "");
            Account mAccount = CommonUtils.getAccount(accountName, accountType, AccountManager.get(this));
            if (mAccount != null && CommonUtils.isMediaSyncEnabled(mAccount) && CommonUtils.isSettingsSyncEnabled(mAccount)) {


            //There is no account set
            if(mAccount == null){
                final String CURRENTTAG = TAG+"_onStartCOmmand/ no Account";
                Log.d(CURRENTTAG, "Account is null, so start to clear prefs.");
                //clear prefs
                prefs.edit().putString(AccountManager.KEY_ACCOUNT_NAME, "")
                        .putString(AccountManager.KEY_ACCOUNT_TYPE, "")
                        .putBoolean(INITIALIZERSERVICE_HAS_RUN, false)
                        .apply();

                //clear DB
                boolean result = this.deleteDatabase(DbHelper.DATABASE_NAME);
                Log.d(CURRENTTAG, "Remove Database: "+result);
                //Disable scheduledJob
                JobUtils.stopScheduledJob(this);
                //Stop operationManagerService
                if(mBoundToOperationManager)
                    mOperationManagerService.stopSelf();
                boolean unregisteredReceiver = CommonUtils.unregisterScreenOff(getApplicationContext());
                Log.d(CURRENTTAG, "ScreenOffReceiver unregistered : "+unregisteredReceiver);

            }else if (CommonUtils.isMediaSyncEnabled(mAccount) && CommonUtils.isSettingsSyncEnabled(mAccount)) {
                if (mClient == null) //background task
                    CommonUtils.getOwnCloudClient(mAccount, getApplicationContext(), this);
                else
@@ -400,10 +424,10 @@ public class ObserverService extends Service implements OnRemoteOperationListene
                    int rowAffected = getContentResolver().delete(MediaStore.Files.getContentUri("external"),
                            MediaStore.Files.FileColumns.DATA + "=?",
                            new String[]{file.getAbsolutePath()});

                    //if delete failed, try another methods
                    if (rowAffected < 1) {
                        fileExists = !file.delete();

                    }else
                        fileExists = false;
                }
@@ -473,8 +497,6 @@ public class ObserverService extends Service implements OnRemoteOperationListene
                    }
                }
                if( syncedFolder.getId() > 0){
                    //equivalent du listRemoteFileOperation
                    //Objectif: obtenir la liste des fichiers à analyser et les éventuels nouveaux répertoirs
                    File folder = new File(syncedFolder.getLocalFolder()); //Obtention du fichier local
                    Log.d(TAG+"_scanLocalFiles()", syncedFolder.getId()+", syncedFolder : "+syncedFolder.getLocalFolder()+", "+syncedFolder.getLastModified()+", "+folder.lastModified()+", "+folder.exists() );
                    if(folder.exists() && folder.lastModified() > syncedFolder.getLastModified() ){
@@ -577,7 +599,6 @@ public class ObserverService extends Service implements OnRemoteOperationListene
            if( !correspondant_found ){
                //Extract parent path from knownPath
                final String parentOfKnownPath = filePath.substring(0, filePath.lastIndexOf(FileUtils.PATH_SEPARATOR) + 1);
                //@todo: look if I can simply use localFile.getParent.getAbsolutePath
                //look into synced folders if folder path exist
                for (int j = -1, syncedFolderSize = this.mSyncedFolders.size(); ++j < syncedFolderSize;) {
                    final SyncedFolder syncedFolder = mSyncedFolders.get(j);
Loading