Commit c3973fd7 authored by Vincent Bourgmayer's avatar Vincent Bourgmayer 🎼
Browse files

Remove get client async task n

parent 6fa0ac9a
Pipeline #17256 passed with stage
in 2 minutes and 1 second
......@@ -12,21 +12,16 @@ import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import java.util.ArrayList;
import java.util.List;
import foundation.e.drive.models.SyncedFolder;
import foundation.e.drive.models.SyncedFileState;
/**
* @author Vincent Bourgmayer
* source: https://developer.android.com/training/data-storage/sqlite.html#java
* https://vogella.developpez.com/tutoriels/android/utilisation-base-donnees-sqlite/
*
*/
public final class DbHelper extends SQLiteOpenHelper {
final private static String TAG = DbHelper.class.getSimpleName(); //Tag for log
private static final int DATABASE_VERSION = 19; //20/09/2018
......
......@@ -59,5 +59,4 @@ class SyncedFileStateContract implements BaseColumns{
static final String UPDATE_SETTINGS_DATA_TO_VERSION_19 = "UPDATE "+TABLE_NAME+
" SET "+IS_MEDIA_TYPE+" = 0 WHERE "+REMOTE_PATH+" LIKE \"/Devices/%\";";
}
......@@ -13,12 +13,9 @@ import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import java.util.ArrayList;
import java.util.List;
import foundation.e.drive.models.SyncedFileState;
import static foundation.e.drive.database.SyncedFileStateContract.TABLE_NAME;
import static foundation.e.drive.database.SyncedFileStateContract.FILE_NAME;
......@@ -29,7 +26,6 @@ import static foundation.e.drive.database.SyncedFileStateContract.LOCAL_PATH;
import static foundation.e.drive.database.SyncedFileStateContract.REMOTE_PATH;
import static foundation.e.drive.database.SyncedFileStateContract.SYNCEDFOLDER_ID;
/**
* @author Vincent Bourgmayer
* Offers Query to CRUD operation for SyncedFIleState Object
......
......@@ -16,7 +16,6 @@ import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import java.util.ArrayList;
import java.util.List;
import foundation.e.drive.models.SyncedFolder;
import static foundation.e.drive.database.SyncedFolderContract.CATEGORIE_LABEL;
import static foundation.e.drive.database.SyncedFolderContract.ENABLED;
......@@ -191,6 +190,5 @@ class SyncedFolderDAO {
.setId(cursor.getInt(0) )
.setLastEtag(cursor.getString( 4 ) )
.setLastModified(cursor.getLong( 5 ) );
}
}
......@@ -11,7 +11,6 @@ package foundation.e.drive.fileFilters;
import java.io.File;
import java.io.FileFilter;
/**
* @author Vincent Bourgmayer
* FileFilter for application Settings
......@@ -22,6 +21,5 @@ class AppSettingsFileFilter implements FileFilter {
return pathname.isFile()
|| (pathname.isDirectory()
&& !pathname.getName().toLowerCase().contains("cache"));
}
}
......@@ -10,7 +10,6 @@ package foundation.e.drive.fileFilters;
import java.io.File;
import java.io.FileFilter;
import foundation.e.drive.utils.AppConstants;
/**
......
......@@ -13,7 +13,6 @@ 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;
......@@ -40,7 +39,6 @@ public class ScannerJob extends JobService {
}
/**
*
* @param params
* @return default return... ?
*/
......
......@@ -15,7 +15,6 @@ package foundation.e.drive.models;
public class SyncedFileState {
protected SyncedFileState(){}; //@ToRemove. Test Only. It's to allow to make a mock SyncedFileState Class in test.
private int id;
private String name; //name of the file
......@@ -126,5 +125,4 @@ public class SyncedFileState {
+"\nSyncedFolderId: "+this.syncedFolderId
+"\nisMediaType: "+this.isMediaType;
}
}
......@@ -16,7 +16,6 @@ import android.os.Parcelable;
* This class encapsulates the representation of a synced or syncable folder.
* It stores data about remote and local real folder.
*/
public class SyncedFolder implements Parcelable {
private int id;
private String libelle;
......
......@@ -27,8 +27,4 @@ public interface ComparableOperation {
* @return RemoteOperation this instance
*/
public RemoteOperation toRemoteOperation();
}
......@@ -10,14 +10,11 @@ package foundation.e.drive.operations;
import android.content.Context;
import android.util.Log;
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.CreateFolderRemoteOperation;
import java.io.File;
import foundation.e.drive.database.DbHelper;
import foundation.e.drive.models.SyncedFolder;
......
......@@ -30,11 +30,9 @@ import com.owncloud.android.lib.common.operations.OperationCancelledException;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
......@@ -49,7 +47,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
* @author masensio
* @author Vincent Bourgmayer
*/
class DownloadFileRemoteOperation extends RemoteOperation {
private static final String TAG = DownloadFileRemoteOperation.class.getSimpleName();
......@@ -57,11 +54,9 @@ import java.util.concurrent.atomic.AtomicBoolean;
private long mModificationTimestamp = 0;
private String mEtag = "";
private GetMethod mGet;
private final String mRemotePath;
private final String mLocalFolderPath;
/**
* Constructor
* @param remotePath Path of file on the server
......@@ -90,7 +85,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
Log_OC.e(TAG, "Download of " + mRemotePath + " to " + getTmpPath() + ": " +
result.getLogMessage(), e);
}
return result;
}
......@@ -125,7 +119,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
}
fos.write(bytes, 0, readResult);
transferred += readResult;
}
// Check if the file is completed
// if transfer-encoding: chunked we cannot check if the file is complete
......@@ -135,7 +128,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
if (transferEncodingHeader != null) {
transferEncoding = transferEncodingHeader.getValue().equals("chunked");
}
if (transferred == totalToTransfer || transferEncoding) {
savedFile = true;
Header modificationTime = mGet.getResponseHeader("Last-Modified");
......@@ -153,16 +145,13 @@ import java.util.concurrent.atomic.AtomicBoolean;
if (mEtag.length() == 0) {
Log_OC.e(TAG, "Could not read eTag from response downloading " + mRemotePath);
}
} else {
client.exhaustResponse(mGet.getResponseBodyAsStream());
// TODO some kind of error control!
}
} else {
client.exhaustResponse(mGet.getResponseBodyAsStream());
}
} catch (Exception e) {
Log_OC.e(TAG, e.getMessage());
} finally {
......
......@@ -10,21 +10,17 @@ package foundation.e.drive.operations;
import android.content.Context;
import android.util.Log;
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.LightReadFolderRemoteOperation;
import com.owncloud.android.lib.resources.files.model.RemoteFile;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import foundation.e.drive.database.DbHelper;
import foundation.e.drive.models.SyncedFolder;
import static org.apache.jackrabbit.webdav.DavConstants.DEPTH_1;
/**
......@@ -32,7 +28,6 @@ import static org.apache.jackrabbit.webdav.DavConstants.DEPTH_1;
* @author Vincent Bourgmayer
* Created by Vincent on 04/05/2018.
*/
public class ListFileRemoteOperation extends RemoteOperation {
private final String TAG = ListFileRemoteOperation.class.getSimpleName();
......
......@@ -10,7 +10,6 @@ package foundation.e.drive.operations;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.resources.files.RemoveFileRemoteOperation;
import foundation.e.drive.models.SyncedFileState;
/**
......
......@@ -12,7 +12,6 @@ import android.content.Context;
import android.util.Log;
import java.io.File;
import java.util.ArrayList;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.UserInfo;
import com.owncloud.android.lib.common.operations.RemoteOperation;
......@@ -22,7 +21,6 @@ import com.owncloud.android.lib.resources.files.FileUtils;
import com.owncloud.android.lib.resources.files.UploadFileRemoteOperation;
import com.owncloud.android.lib.resources.users.GetRemoteUserInfoOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import foundation.e.drive.database.DbHelper;
import foundation.e.drive.models.SyncedFileState;
import foundation.e.drive.utils.CommonUtils;
......@@ -34,16 +32,13 @@ import foundation.e.drive.utils.CommonUtils;
public class UploadFileOperation extends RemoteOperation implements ComparableOperation{
private final static String TAG = UploadFileOperation.class.getSimpleName();
private int restartCounter =0;
private long previousLastModified; //get to restore real value if all trials fails
private boolean checkEtag;
private String mTargetPath;
private final File mFile;
private final Context mContext;
private SyncedFileState mSyncedState;
private long availableQuota = -1;
@Override
......@@ -78,7 +73,6 @@ public class UploadFileOperation extends RemoteOperation implements ComparableOp
"",
0,
syncedFolderId, syncedFolderIsMediaType);
}
Log.v(TAG, ""+mSyncedState.getLocalLastModified() );
this.previousLastModified = mSyncedState.getLocalLastModified();
......@@ -138,8 +132,6 @@ public class UploadFileOperation extends RemoteOperation implements ComparableOp
UploadFileRemoteOperation uploadOperation = buildUploadOperation();
// Execute UploadFileOperation
RemoteOperationResult uploadResult = uploadOperation.execute( client );
ResultCode mResultCode;
......@@ -169,18 +161,14 @@ public class UploadFileOperation extends RemoteOperation implements ComparableOp
mustRestart = false;
mSyncedState.setLocalLastModified( this.previousLastModified);
}
}catch(Exception e){
Log.e(TAG, e.toString() );
mSyncedState.setLocalLastModified( this.previousLastModified);
mustRestart = false;
}
}else if(uploadResult.getCode() == ResultCode.QUOTA_EXCEEDED){
mResultCode = ResultCode.QUOTA_EXCEEDED;
mustRestart = false;
}else{
//Upload failed
Log.e(TAG, "UploadFileRemoteOperation for : " + mFile.getName() + " failed => code: " + uploadResult.getCode());
......@@ -249,8 +237,6 @@ public class UploadFileOperation extends RemoteOperation implements ComparableOp
}
}
/**
* Return the file that should be uploading
* @return File given to this operation
......
......@@ -15,7 +15,6 @@ import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
/**
*
* @author Vincent Bourgmayer
......
......@@ -12,14 +12,11 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import foundation.e.drive.utils.JobUtils;
/**
* @author Vincent Bourgmayer
*/
public class BatteryStateReceiver extends BroadcastReceiver {
private final static String TAG = BatteryStateReceiver.class.getSimpleName();
......@@ -32,16 +29,13 @@ public class BatteryStateReceiver extends BroadcastReceiver {
Log.e(TAG, "intent Action is null");
} else if ( intentAction.equals(Intent.ACTION_BATTERY_OKAY) ) {
JobUtils.scheduleScannerJob(context);
//Note: ScreenOffReciever is register in ScannerJob. So no need to register it here.
}else if(intentAction.equals(Intent.ACTION_BATTERY_LOW)){
JobUtils.stopScheduledJob(context, JobUtils.ScannerJobId);
//JobUtils.stopScheduledJob(context, JobUtils.InitializerJobId);
try {
context.unregisterReceiver(ScreenOffReceiver.getInstance());
}catch(Exception e){
Log.e(TAG, e.toString() );
}
}
}
}
......@@ -13,7 +13,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;
import foundation.e.drive.database.DbHelper;
import foundation.e.drive.services.InitializerService;
import foundation.e.drive.utils.AppConstants;
......@@ -34,15 +33,6 @@ public class PackageEventReceiver extends BroadcastReceiver {
DbHelper dbHelper = new DbHelper(context);
dbHelper.getWritableDatabase().close(); //Force upgrade of db.
/*if (!pref.getBoolean(AppConstants.INITIALIZATION_HAS_BEEN_DONE, false)) {
context.startService(new Intent(context, InitializerService.class));
} else if(CommonUtils.getAccount( pref.getString(AccountManager.KEY_ACCOUNT_NAME,""),
pref.getString(AccountManager.KEY_ACCOUNT_TYPE, ""),
AccountManager.get(context) ) != null){
JobUtils.scheduleScannerJob(context, 120000);
}*/
}
}
}
......@@ -12,7 +12,6 @@ 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;
......@@ -21,7 +20,6 @@ import foundation.e.drive.utils.CommonUtils;
* 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();
......
......@@ -21,24 +21,19 @@ import android.os.Handler;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.util.Log;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import java.util.ArrayList;
import java.util.Arrays;
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;
import foundation.e.drive.utils.IGetOCClient;
import foundation.e.drive.utils.JobUtils;
import static com.owncloud.android.lib.resources.files.FileUtils.PATH_SEPARATOR;
import static foundation.e.drive.utils.AppConstants.INITIALFOLDERS_NUMBER;
import static foundation.e.drive.utils.AppConstants.MEDIA_SYNCABLE_CATEGORIES;
......@@ -47,7 +42,7 @@ import static foundation.e.drive.utils.AppConstants.SETTINGS_SYNCABLE_CATEGORIES
/**
* @author Vincent Bourgmayer
*/
public class InitializerService extends Service implements OnRemoteOperationListener, IGetOCClient {
public class InitializerService extends Service implements OnRemoteOperationListener {
final private String TAG = InitializerService.class.getSimpleName();
//Complex properties
private int existingRemoteFolderCounter; //@dev-only; Temporarily used to know if all remotePath exist
......@@ -96,7 +91,8 @@ public class InitializerService extends Service implements OnRemoteOperationList
this.mAccount = CommonUtils.getAccount( accountName, accountType, AccountManager.get(this) );
//Get OwnCloudlient
if (this.mAccount != null) {
CommonUtils.getOwnCloudClient( this.mAccount, getApplicationContext(), this);
this.mCloudClient = CommonUtils.getOwnCloudClient( this.mAccount, getApplicationContext());
start();
}else {
Log.w(TAG, "Got account is invalid.");
stopSelf();
......@@ -108,35 +104,30 @@ public class InitializerService extends Service implements OnRemoteOperationList
/**
* Got DAV's client
* @param result
* start to do its job
*/
@Override
public void onOCClientReceived(Object result) {
Log.i(TAG, "ocOCClientReceived");
try {
this.mCloudClient = (OwnCloudClient) result;
}catch(Exception e){
Log.e(TAG, e.toString() );
public void start() {
Log.i(TAG, "start");
if (mCloudClient == null){
stopSelf();
return;
}
Log.d(TAG, mCloudClient.getBaseUri().toString());
//Get categories of element to sync
List<String> mSyncCategories = new ArrayList<>();
List<String> syncCategories = new ArrayList<>();
if (CommonUtils.isMediaSyncEnabled(mAccount)) {
mSyncCategories.addAll(Arrays.asList(MEDIA_SYNCABLE_CATEGORIES));
syncCategories.addAll(Arrays.asList(MEDIA_SYNCABLE_CATEGORIES));
}
if (CommonUtils.isSettingsSyncEnabled(mAccount)) {
mSyncCategories.addAll(Arrays.asList(SETTINGS_SYNCABLE_CATEGORIES));
syncCategories.addAll(Arrays.asList(SETTINGS_SYNCABLE_CATEGORIES));
}
//Get SyncedFolders
getInitialSyncedFolders(mSyncCategories);
getInitialSyncedFolders(syncCategories);
this.existingRemoteFolderCounter = 0;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment