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

Commit 82101c19 authored by vince-bourgmayer's avatar vince-bourgmayer
Browse files

update models RootFolder and related class for DB. Removed useless subclass in xxxContract class

parent b9c1ecb8
Loading
Loading
Loading
Loading
+4 −115
Original line number Diff line number Diff line
@@ -4,124 +4,13 @@
- Vincent (vincent.bourgmayer@eelo.io)
- Frank

#### Currently synchronizable contents:
- DCIM/Camera
- Pictures/Screenshots
- Ringtones
- Documents
- Music
- SoundRecords
- Movies
- Podcasts

#### How to help?
You can help by testing the app and reporting unexpected behaviour.

___But what to test?___
From second test, please clear localy and remotly file in folder you're testing.
Please use gitlab's issue functionnality to give me your issues.
For current version, you can do the following tests:

For the test you will need a internet connexion on your device, a nextcloud account (with login and password).
If you try to log with your e-mail and setup fails, please try with login such as your name. I.e I used "vincent" as login.

###### 1. Installation:

	Install the application, and go through setup until it closes.
	Expected behaviour: the app do some work (updating small text at bottom screen) then closes, meaning setup is over.

###### 2. File upload:

	Install App and run through setup.

	a. With device only: open any default app which create content (i.e: Camera) and create a new file
	
	b. add external file into device with cable.
		
	which will be store in a syncable folder.

	___Expected behaviour:___

	The file will be send to the cloud. You should get a notification telling upload succeed. And you can see your file in the cloud with any cloud's file explorer.
	
###### 3. File Download:

	This require two tests:

	a. New file Download 

	Upload a file on the cloud storage with any kind of client.
	Do not use a file which has already been synced with this device already.
	Upload it in a 'remote) folder which has been created by the app.

	b. Update an existing local file

	Download a file on your computer, from the cloud storage. The file must already be on your device too and has already been synced.

	___Common step:___

	Wait that device scan cloud storage.

	___Expected behaviour:___

	At the end of the cloud scanning by the device, the file should be downloaded or downloading on the device too.

###### 4. Local File deletion:

	1. Upload a file with your device to the cloud storage. The local file must be in one of the folder which is observed by the app.
	2. Manualy remove the file on your device.

	___Expected behaviour:___

	The file which has been deleted on device is not anymore in the cloud.

###### 5. Remote File deletion:

	1. Upload a file with your device to the cloud storage. The local file must be in one of the folder which is observed by the app.
	2. Manualy remove the file in the cloud from a any client (i.e webclient).
	3. Wait that device scan cloud storage.

	___Expected behaviour:___

	At the end of the cloud scanning by the device, the local file should have been removed from the device too.

###### 6. Remote file modification:
	
	Please, see 3.b above.

###### 7. synchronization between two phones:

	1. Install the app on two different device, using same cloud storage and account (same credentials now)
	2. Do above test 2 to 6 on one phone.
	3. Check the other phone.

	___Expected behaviour:___

	Synchronized folders should be in the same state on the cloud and on each device. By "same state" I mean that each file has same version, same relative local path, same size, ...

###### 8. Uninstall the app

	1. Go into device settings > apps (or application) > eelo Drive
	2. Clear storage datas.
	3. Uninstall app

#### TODO:
This is a list of thing to do:

+ Finish to fix random file deletion after/while upload
+ Create new Branch for settings's synchronisation and start to find how synchronize settings.
+ Synchronize settings of device for time application.
+ Prevent full scan of unchanged directory

#### Commands that helps
###### Make BOOT_COMPLETED without restarting device.
1. Connect device to computer
2. Open terminal and type:
    1. `adb root`
    2. `adb shell am broadcast -a android.intent.action.BOOT_COMPLETED`
+ Prevent failure due to service stopping, or internet connexion lost
+ Sync settings
+ code cleaning and rewriting
+ Use Eelo Account instead of raw credentials

###### Record screen of the phone
`adb shell screenrecord ./sdcard/nameOfYourVideo.mp4`
###### Get file from device
`adb pull <source> <target>`
 No newline at end of file
+2 −2
Original line number Diff line number Diff line
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="io.eelo.drive"
    android:sharedUserId="android.uid.system" >
    package="io.eelo.drive">
    <!--android:sharedUserId="android.uid.system" > -->


    <uses-permission android:name="android.permission.INTERNET" />
+15 −3
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ import io.eelo.drive.models.SyncedFileState;
 * https://vogella.developpez.com/tutoriels/android/utilisation-base-donnees-sqlite/
 */

public class DbHelper extends SQLiteOpenHelper {
public final class DbHelper extends SQLiteOpenHelper {
    final public static String TAG = DbHelper.class.getSimpleName(); //Tag for log
    public static final int DATABASE_VERSION = 8;
    public static final String DATABASE_NAME = "eelo_drive.db";
@@ -170,9 +170,14 @@ public class DbHelper extends SQLiteOpenHelper {

    /**
     * Load root path from DB
     * @param context
     * @param filter use either "SCANLOCAL" to get localy scannable folder either "SCANREMOTE"
     * to get remotly scanable folder or any other value to get "ENABLED" folder
     * @param filter_val param used in combination with filter. Allow to filter all those  which
     * match the filter (if this is true) or all those which doesn't match the filter
     * @return List<RootFolder> a list of RootFolder from DB
     */
    public static List<RootFolder> getRootFolders(Context context) {
    public static List<RootFolder> getRootFolders(Context context, String filter, boolean filter_val) {
        Log.i(TAG, "getRootFolders");

        RootFolderDAO dao = new RootFolderDAO(context );
@@ -183,7 +188,14 @@ public class DbHelper extends SQLiteOpenHelper {
            Log.e( TAG, e.toString() );
            return mRootFolder;
        }
        mRootFolder = dao.getAllRootFolders(true);

        if( filter.equals("SCANLOCAL") ){
            mRootFolder = dao.getAllRootFolders(RootFolderContract.SCANLOCAL, filter_val);
        } else if(filter.equals("SCANREMOTE")){
            mRootFolder = dao.getAllRootFolders(RootFolderContract.SCANREMOTE, filter_val);
        }else {
            mRootFolder = dao.getAllRootFolders(RootFolderContract.ENABLED, filter_val);
        }
        Log.d( TAG, "rootFolder size : "+ mRootFolder.size() );

        dao.close();
+30 −23
Original line number Diff line number Diff line
@@ -8,34 +8,41 @@ import android.provider.BaseColumns;
 * source: https://developer.android.com/training/data-storage/sqlite.html#java
 */

public final class RootFolderContract {
public final class RootFolderContract implements BaseColumns{

    /** Table Structure **/
    public static final String TABLE_NAME ="root_folder";
    public static final String CATEGORIE_LABEL ="categorie_label";
    public static final String LOCAL_PATH ="local_path";
    public static final String REMOTE_PATH ="remote_path";
    public static final String LAST_ETAG ="last_etag";
    public static final String LOCAL_LAST_MODIFIED ="last_modified";
    public static final String SCANLOCAL ="scan_local";
    public static final String SCANREMOTE ="scan_remote";
    public static final String ENABLED ="enabled";



    public static final String SQL_CREATE_TABLE_ROOTFOLDER = new StringBuilder()
            .append("CREATE TABLE ").append(RootFolderEntry.TABLE_NAME).append(" ( ")
            .append(RootFolderEntry._ID).append(" INTEGER PRIMARY KEY, ")
            .append(RootFolderEntry.CATEGORIE_LABEL).append(" TEXT, ")
            .append(RootFolderEntry.LOCAL_ROOT_FOLDER).append(" TEXT, ")
            .append(RootFolderEntry.REMOTE_ROOT_FOLDER).append(" TEXT, ")
            .append(RootFolderEntry.LAST_ETAG).append(" TEXT, ")
            .append(RootFolderEntry.LAST_MODIFIED).append(" INTEGER, ")
            .append(RootFolderEntry.ENABLED).append(" BOOLEAN, ")
            .append("CREATE TABLE ").append(TABLE_NAME).append(" ( ")
            .append(_ID).append(" INTEGER PRIMARY KEY, ")
            .append(CATEGORIE_LABEL).append(" TEXT, ")
            .append(LOCAL_PATH).append(" TEXT, ")
            .append(REMOTE_PATH).append(" TEXT, ")
            .append(LAST_ETAG).append(" TEXT, ")
            .append(LOCAL_LAST_MODIFIED).append(" INTEGER, ")
            .append(SCANLOCAL).append(" BOOLEAN, ")
            .append(SCANREMOTE).append(" BOOLEAN, ")
            .append(ENABLED).append(" BOOLEAN, ")
            .append("CONSTRAINT roots_unicity_constraint UNIQUE (")
            .append(RootFolderEntry.CATEGORIE_LABEL).append(", ")
            .append(RootFolderEntry.LOCAL_ROOT_FOLDER).append(", ")
            .append(RootFolderEntry.REMOTE_ROOT_FOLDER)
            .append(CATEGORIE_LABEL).append(", ")
            .append(LOCAL_PATH).append(", ")
            .append(REMOTE_PATH)
            .append("))")
            .toString();


    public static final String SQL_DELETE_TABLE_ROOTFOLDER = " DROP TABLE IF EXISTS "
            + RootFolderEntry.TABLE_NAME;
            + TABLE_NAME;

    public static class RootFolderEntry implements BaseColumns {
        public static final String TABLE_NAME ="root_folder";
        public static final String CATEGORIE_LABEL ="categorie_label";
        public static final String LOCAL_ROOT_FOLDER ="local_root_path";
        public static final String REMOTE_ROOT_FOLDER ="remote_root_path";
        public static final String LAST_ETAG ="last_etag";
        public static final String LAST_MODIFIED ="last_modified";
        public static final String ENABLED ="enabled";
    }
}
+37 −28
Original line number Diff line number Diff line
@@ -24,12 +24,14 @@ public class RootFolderDAO {
    final public static String TAG = RootFolderDAO.class.getSimpleName(); //Tag for log
    private SQLiteDatabase mDB;
    private DbHelper mHelper;
    private String[] allColumns = { RootFolderContract.RootFolderEntry._ID, RootFolderContract.RootFolderEntry.CATEGORIE_LABEL,
            RootFolderContract.RootFolderEntry.LOCAL_ROOT_FOLDER,
            RootFolderContract.RootFolderEntry.REMOTE_ROOT_FOLDER,
            RootFolderContract.RootFolderEntry.LAST_ETAG,
            RootFolderContract.RootFolderEntry.LAST_MODIFIED,
            RootFolderContract.RootFolderEntry.ENABLED};
    private String[] allColumns = { RootFolderContract._ID, RootFolderContract.CATEGORIE_LABEL,
            RootFolderContract.LOCAL_PATH,
            RootFolderContract.REMOTE_PATH,
            RootFolderContract.LAST_ETAG,
            RootFolderContract.LOCAL_LAST_MODIFIED,
            RootFolderContract.SCANLOCAL,
            RootFolderContract.SCANREMOTE,
            RootFolderContract.ENABLED};

    public RootFolderDAO(Context context){
        this.mHelper = new DbHelper(context);
@@ -60,13 +62,15 @@ public class RootFolderDAO {
     */
    public long insert(RootFolder folder){
        ContentValues values = new ContentValues();
        values.put(RootFolderContract.RootFolderEntry.CATEGORIE_LABEL, folder.getLibelle());
        values.put(RootFolderContract.RootFolderEntry.LOCAL_ROOT_FOLDER, folder.getLocalFolder());
        values.put(RootFolderContract.RootFolderEntry.REMOTE_ROOT_FOLDER, folder.getRemoteFolder());
        values.put(RootFolderContract.RootFolderEntry.LAST_ETAG, folder.getLastEtag() );
        values.put(RootFolderContract.RootFolderEntry.LAST_MODIFIED, folder.getLastEtag() );
        values.put(RootFolderContract.RootFolderEntry.ENABLED, folder.isEnabled() ? 1 : 0);
        long id = mDB.insertWithOnConflict(RootFolderContract.RootFolderEntry.TABLE_NAME, null, values, SQLiteDatabase.CONFLICT_IGNORE);
        values.put(RootFolderContract.CATEGORIE_LABEL, folder.getLibelle());
        values.put(RootFolderContract.LOCAL_PATH, folder.getLocalFolder());
        values.put(RootFolderContract.REMOTE_PATH, folder.getRemoteFolder());
        values.put(RootFolderContract.LAST_ETAG, folder.getLastEtag() );
        values.put(RootFolderContract.LOCAL_LAST_MODIFIED, folder.getLastEtag() );
        values.put(RootFolderContract.SCANLOCAL, folder.isEnabled() ? 1 : 0);
        values.put(RootFolderContract.SCANREMOTE, folder.isEnabled() ? 1 : 0);
        values.put(RootFolderContract.ENABLED, folder.isEnabled() ? 1 : 0);
        long id = mDB.insertWithOnConflict(RootFolderContract.TABLE_NAME, null, values, SQLiteDatabase.CONFLICT_IGNORE);
        return id;
    }

@@ -76,7 +80,7 @@ public class RootFolderDAO {
     */
    public void delete(String label) {
        Log.d(TAG, "root folder deleted with label: " + label);
        mDB.delete(RootFolderContract.RootFolderEntry.TABLE_NAME, RootFolderContract.RootFolderEntry.CATEGORIE_LABEL
        mDB.delete(RootFolderContract.TABLE_NAME, RootFolderContract.CATEGORIE_LABEL
                + " = " + label, null);
    }

@@ -85,10 +89,9 @@ public class RootFolderDAO {
     */
    public void delete() {
        Log.d(TAG, "root folder deleted " );
        mDB.delete(RootFolderContract.RootFolderEntry.TABLE_NAME, null, null);
        mDB.delete(RootFolderContract.TABLE_NAME, null, null);
    }


    /**
     * Update a specific RootFolder
     * @param folder RootFolder to update
@@ -98,17 +101,19 @@ public class RootFolderDAO {
        Log.i(TAG, "Update("+folder.getLibelle()+")");
        Log.d(TAG, "Folder id = "+folder.getId());
        ContentValues values = new ContentValues();
        values.put(RootFolderContract.RootFolderEntry.CATEGORIE_LABEL, folder.getLibelle());
        values.put(RootFolderContract.RootFolderEntry.LOCAL_ROOT_FOLDER, folder.getLocalFolder());
        values.put(RootFolderContract.RootFolderEntry.REMOTE_ROOT_FOLDER, folder.getRemoteFolder());
        values.put(RootFolderContract.RootFolderEntry.LAST_ETAG, folder.getLastEtag());
        values.put( RootFolderContract.RootFolderEntry.LAST_MODIFIED, folder.getLastModified() );
        values.put( RootFolderContract.RootFolderEntry.ENABLED, folder.isEnabled()? 1 : 0 );
        values.put(RootFolderContract.CATEGORIE_LABEL, folder.getLibelle());
        values.put(RootFolderContract.LOCAL_PATH, folder.getLocalFolder());
        values.put(RootFolderContract.REMOTE_PATH, folder.getRemoteFolder());
        values.put(RootFolderContract.LAST_ETAG, folder.getLastEtag());
        values.put( RootFolderContract.LOCAL_LAST_MODIFIED, folder.getLastModified() );
        values.put(RootFolderContract.SCANLOCAL, folder.isEnabled() ? 1 : 0);
        values.put(RootFolderContract.SCANREMOTE, folder.isEnabled() ? 1 : 0);
        values.put( RootFolderContract.ENABLED, folder.isEnabled()? 1 : 0 );
        int result = 0;

        try{
            result = mDB.update(RootFolderContract.RootFolderEntry.TABLE_NAME, values,
                    RootFolderContract.RootFolderEntry._ID+" = "+folder.getId(),
            result = mDB.update(RootFolderContract.TABLE_NAME, values,
                    RootFolderContract._ID+" = "+folder.getId(),
                    null);
        }catch(Exception e){
            Log.e(TAG, e.toString());
@@ -125,12 +130,12 @@ public class RootFolderDAO {
     * @param enabled if true, return all enabled rootFolder, if false return all disabled rootFolder
     * @return
     */
    public List<RootFolder> getAllRootFolders(boolean enabled) {
    public List<RootFolder> getAllRootFolders(String selection, boolean enabled) {
        Log.i(TAG, "getAllRootFolders("+enabled+")");
        List<RootFolder> folders = new ArrayList<RootFolder>();
        String[] args = {(enabled ? "1": "0")};
        Cursor cursor = mDB.query(RootFolderContract.RootFolderEntry.TABLE_NAME,
                allColumns, RootFolderContract.RootFolderEntry.ENABLED+" = ?",args, null, null, null);
        Cursor cursor = mDB.query(RootFolderContract.TABLE_NAME,
                allColumns, selection+" = ?",args, null, null, null);

        cursor.moveToFirst();
        while (!cursor.isAfterLast()) {
@@ -143,6 +148,8 @@ public class RootFolderDAO {
        return folders;
    }



    /**
     * Create a RootFolder object from data in cursor.
     * @param cursor
@@ -156,7 +163,9 @@ public class RootFolderDAO {
                .setRemoteFolder(cursor.getString(3) )
                .setLastEtag(cursor.getString( 4 ) )
                .setLastModified(cursor.getLong( 5 ) )
                .setEnabled( cursor.getInt(6) == 1 ? true: false); //@TODO: adapt DB to get boolean behaviour
                .setScanLocal( cursor.getInt(6) == 1 ? true: false)
                .setScanRemote( cursor.getInt(7) == 1 ? true: false)
                .setEnabled( cursor.getInt(8) == 1 ? true: false);
        return folder;
    }
}
Loading