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
......@@ -22,21 +22,18 @@ import android.os.IBinder;
import android.provider.MediaStore;
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 com.owncloud.android.lib.resources.files.FileUtils;
import com.owncloud.android.lib.resources.files.model.RemoteFile;
import java.io.File;
import java.io.FileFilter;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import foundation.e.drive.database.DbHelper;
import foundation.e.drive.fileFilters.FileFilterFactory;
import foundation.e.drive.fileFilters.OnlyFileFilter;
......@@ -48,8 +45,6 @@ import foundation.e.drive.operations.RemoveFileOperation;
import foundation.e.drive.operations.UploadFileOperation;
import foundation.e.drive.utils.AppConstants;
import foundation.e.drive.utils.CommonUtils;
import foundation.e.drive.utils.IGetOCClient;
import static com.owncloud.android.lib.resources.files.FileUtils.PATH_SEPARATOR;
import static foundation.e.drive.utils.AppConstants.INITIALIZATION_HAS_BEEN_DONE;
import foundation.e.drive.utils.JobUtils;
......@@ -58,7 +53,7 @@ import foundation.e.drive.utils.JobUtils;
* @author Vincent Bourgmayer
* This service look for remote or looale file to synchronize
*/
public class ObserverService extends Service implements OnRemoteOperationListener, IGetOCClient {
public class ObserverService extends Service implements OnRemoteOperationListener {
private final static String TAG = ObserverService.class.getSimpleName();
private OwnCloudClient mClient;
private List<SyncedFolder> mSyncedFolders; //List of synced folder
......@@ -131,8 +126,6 @@ public class ObserverService extends Service implements OnRemoteOperationListene
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i(TAG, "onStartCommand");
SharedPreferences prefs = this.getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE);
if (prefs.getBoolean(INITIALIZATION_HAS_BEEN_DONE, false)) {
......@@ -144,10 +137,14 @@ public class ObserverService extends Service implements OnRemoteOperationListene
if (this.mAccount != null ){
if ( CommonUtils.isMediaSyncEnabled(this.mAccount) || CommonUtils.isSettingsSyncEnabled(this.mAccount) ) {
if (mClient == null) //background task
CommonUtils.getOwnCloudClient(this.mAccount, getApplicationContext(), this);
else
this.mClient = CommonUtils.getOwnCloudClient(this.mAccount, getApplicationContext());
if (mClient != null) //background task
begin();
else {
Log.e(TAG, "mClient is null");
this.stopSelf();
}
}else{
this.stopSelf();
}
......@@ -193,23 +190,6 @@ public class ObserverService extends Service implements OnRemoteOperationListene
}
}
/**
* To receive the response from CommonUtils.getOwncloudClient()
* @param result OwnCloudClient
*/
@Override
public void onOCClientReceived(Object result) {
Log.i(TAG, "onOCClientReceived()");
if(result != null){
this.mClient = ( OwnCloudClient ) result;
begin();
}else{
//End of the service
Log.e(TAG, "onOCClientReceived(...) return null");
this.stopSelf();
}
}
/**
* Clear cached file unused:
* remove each cached file which isn't in OperationManagerService.lockedSyncedFileState();
......@@ -253,7 +233,6 @@ public class ObserverService extends Service implements OnRemoteOperationListene
}
Log.v(TAG, logFolderList);
if (!mSyncedFolders.isEmpty()) {
if (remote) {
try {
......@@ -275,7 +254,7 @@ public class ObserverService extends Service implements OnRemoteOperationListene
/**
* Get list of synced folder depending of if media and setting sync are enabled.
* @return
* @return List<SyncedFolder> instance
*/
private List<SyncedFolder> loadSyncedFolders(){
boolean mediaSyncEnabled = CommonUtils.isMediaSyncEnabled(mAccount);
......@@ -585,7 +564,6 @@ public class ObserverService extends Service implements OnRemoteOperationListene
Log.v(TAG, "subfile " + subElt.getAbsolutePath() + " is a file added to list of file to sync");
fileList.add(subElt);
}
}
}
}else{ //Folder doesn't exist
......@@ -594,12 +572,9 @@ public class ObserverService extends Service implements OnRemoteOperationListene
contentToSyncFound = true;
folderIdList.add( (long) syncedFolder.getId() );
}
}else{ //folder has no id.
iterator.remove();
Log.v(TAG, "syncedFolder "+syncedFolder.getLocalFolder()+" remove iterator because it hasn't been registered in DB or already stored");
}
}else{ //syncedFolder isn't scanLocal
iterator.remove();
......@@ -631,7 +606,6 @@ public class ObserverService extends Service implements OnRemoteOperationListene
//Loop through local files
for(int i =-1, localFilesSize = localFileList.size(); ++i < localFilesSize;){
File localFile = localFileList.get(i);
String filePath = CommonUtils.getLocalPath( localFile );
......@@ -729,6 +703,5 @@ public class ObserverService extends Service implements OnRemoteOperationListene
}
}
}
/* end of methods related to device Scanning */
}
......@@ -22,19 +22,15 @@ import android.os.IBinder;
import android.os.Message;
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.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.concurrent.ConcurrentLinkedDeque;
import foundation.e.drive.database.DbHelper;
import foundation.e.drive.operations.ComparableOperation;
import foundation.e.drive.operations.DownloadFileOperation;
......@@ -42,14 +38,12 @@ import foundation.e.drive.operations.RemoveFileOperation;
import foundation.e.drive.operations.UploadFileOperation;
import foundation.e.drive.utils.AppConstants;
import foundation.e.drive.utils.CommonUtils;
import foundation.e.drive.utils.IGetOCClient;
/**
* @author Vincent Bourgmayer
* Service to do upload, remove and download operation.
*/
public class OperationManagerService extends Service implements OnRemoteOperationListener, IGetOCClient{
public class OperationManagerService extends Service implements OnRemoteOperationListener{
private final static String TAG = OperationManagerService.class.getSimpleName();
// Binder given to clients
private final IBinder mBinder = new OperationManagerBinder();
......@@ -109,11 +103,16 @@ public class OperationManagerService extends Service implements OnRemoteOperatio
AccountManager.get(this));
if(this.mAccount != null)
CommonUtils.getOwnCloudClient(this.mAccount, getApplicationContext(), this);
mClient = CommonUtils.getOwnCloudClient(this.mAccount, getApplicationContext());
if(mClient != null) {
startAllThreads();
}else {
Log.e(TAG, "No Client, Can't Work!");
stopSelf();
}
}
/**
* Start to run all threads
*/
......@@ -244,28 +243,6 @@ public class OperationManagerService extends Service implements OnRemoteOperatio
this.lockedfilePath.remove( ((ComparableOperation) operation ).getLocalPath() );
}
/**
* Function called when client instance is build
* @param result OwnCloudClient's instance
*/
@Override
public void onOCClientReceived(Object result) {
try{
this.mClient = (OwnCloudClient) result;
}catch(Exception e){
Log.e(TAG, e.toString() );
this.mClient = null;
}
if(this.mClient != null) {
Log.d(TAG, "Client defined");
startAllThreads();
}else {
Log.e(TAG, "No Client, Can't Work!");
stopSelf();
}
}
/**
* Binder for the class
*/
......
......@@ -16,14 +16,11 @@ import android.content.SharedPreferences;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.util.Log;
import java.io.File;
import foundation.e.drive.database.DbHelper;
import foundation.e.drive.utils.AppConstants;
import foundation.e.drive.utils.CommonUtils;
import foundation.e.drive.utils.JobUtils;
import static foundation.e.drive.utils.AppConstants.INITIALFOLDERS_NUMBER;
import static foundation.e.drive.utils.AppConstants.INITIALIZATION_HAS_BEEN_DONE;
/**
......@@ -57,7 +54,6 @@ public class ResetService extends Service {
stopperIntent = new Intent(getApplicationContext(), OperationManagerService.class); //@todo try to replace it by stopperIntent.setClassName(getApplicationContext, OperationManagerService.class)
result = getApplicationContext().stopService( stopperIntent );
Log.d(TAG, "stop OperationManagerService: "+result);
......@@ -84,7 +80,6 @@ public class ResetService extends Service {
for(File f : cachedFiles){
f.delete();
}
}
}
}
......
......@@ -6,10 +6,8 @@
* http://www.gnu.org/licenses/gpl.html
*/
package foundation.e.drive.utils;
/**
* @author Vincent Bourgmayer
*/
......@@ -28,23 +26,4 @@ public abstract class AppConstants {
public static final String[] MEDIA_SYNCABLE_CATEGORIES = new String[]{"Images", "Movies", "Music", "Ringtones", "Documents", "Podcasts"};
public static final String[] SETTINGS_SYNCABLE_CATEGORIES = new String[] {"Rom settings"};
/*public static final int FLAG_SCANREMOTE = 1; // 0001 scan remote & settings & inactive
public static final int FLAG_SCANLOCAL = 2; // 0010 scan local & settings & inactive
//0x3 = SCANBOTH & Settings & inactive
public static final int FLAG_MEDIA_SYNCABLE = 4; // 0100
//0x5 = SCANREMOTE & Media & inactive
//0x6 = SCANLOCAL & Media & inactive
//0x7 = SCANBOTH & Media & inactive
public static final int FLAG_ACTIVE = 8; // 1000
//0x9 = 1001 : scan remote, settings and active
//0xA = 1010: active, settings and scan local
//0xB = 1011: active, scan both & settings
//0xC = 1100 : active, media, noscan
//0xD = 1101: active, media, scanRemote
//0xE = 1110: active, media, scanLocal
//0xF = 1111: active, media, scanBoth */
}
......@@ -7,7 +7,6 @@
* http://www.gnu.org/licenses/gpl.html
*/
package foundation.e.drive.utils;
import android.accounts.Account;
......@@ -24,13 +23,13 @@ import android.support.annotation.NonNull;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import android.webkit.MimeTypeMap;
import com.owncloud.android.lib.common.OwnCloudBasicCredentials;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientFactory;
import com.owncloud.android.lib.common.accounts.AccountUtils;
import com.owncloud.android.lib.resources.files.FileUtils;
import java.io.File;
import foundation.e.drive.receivers.ScreenOffReceiver;
import static foundation.e.drive.utils.AppConstants.MEDIASYNC_PROVIDER_AUTHORITY;
import static foundation.e.drive.utils.AppConstants.SETTINGSYNC_PROVIDER_AUTHORITY;
......@@ -38,11 +37,9 @@ import static foundation.e.drive.utils.AppConstants.SETTINGSYNC_PROVIDER_AUTHORI
/**
* @author Vincent Bourgmayer
*/
public abstract class CommonUtils {
final private static String TAG = CommonUtils.class.getSimpleName();
/**
* Unregister from screeOffReceiver component
* @param context app context
......@@ -132,15 +129,23 @@ public abstract class CommonUtils {
/**
* @param context app context
* @param caller Service or activity which asks for OwnCloudClient
* @return boolean true if Task could have been launch
*/
public static void getOwnCloudClient( Account account, Context context, IGetOCClient caller) {
public static OwnCloudClient getOwnCloudClient( Account account, Context context) {
Log.i(TAG, "getOwnCloudClient()");
if ( isMediaSyncEnabled(account) || isSettingsSyncEnabled(account) ) {
GetOCClientTask getOCClientTask = new GetOCClientTask( caller);
getOCClientTask.execute(context, account);
Uri serverUri;
OwnCloudClient oc;
try {
serverUri = Uri.parse(AccountUtils.getBaseUrlForAccount(context, account));
oc = OwnCloudClientFactory.createOwnCloudClient(serverUri, context, true);
oc.setCredentials(new OwnCloudBasicCredentials(account.name, AccountManager.get(context).getPassword(account) ) );
}catch (Exception e){
Log.e(TAG, "Can\'t parse serverPath to Uri : "+e.toString() );
oc = null;
}
return oc;
}
/** methods relative to file **/
......
/*
* Copyright © Vincent Bourgmayer (/e/ foundation).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*/
package foundation.e.drive.utils;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.Context;
import android.net.Uri;
import android.os.AsyncTask;
import android.util.Log;
import com.owncloud.android.lib.common.OwnCloudBasicCredentials;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientFactory;
import com.owncloud.android.lib.common.accounts.AccountUtils;
/**
* @author Vincent Bourgmayer
* AsyncTask to build client
*/
public class GetOCClientTask extends AsyncTask<Object, Void, OwnCloudClient> {
private final static String TAG = GetOCClientTask.class.getSimpleName();
private final IGetOCClient caller;
/**
* Constructor for AsyncTask which has goal to obtain an OwnCloudClient
* @param caller The service/Service which ask for client
*/
public GetOCClientTask( IGetOCClient caller){
this.caller = caller;
}
@Override
protected OwnCloudClient doInBackground(Object[] objects) {
Log.d(TAG, "doInBackground(...)");
final Context context = (Context) objects[0];
final Account account = (Account) objects[1];
Uri serverUri;
try {
serverUri = Uri.parse(AccountUtils.getBaseUrlForAccount(context, account));
}catch (Exception e){
Log.e(TAG, "Can\'t parse serverPath to Uri : "+e.toString() );
return null;
}
OwnCloudClient oc = OwnCloudClientFactory.createOwnCloudClient(serverUri, context, true);
oc.setCredentials(new OwnCloudBasicCredentials(account.name, AccountManager.get(context).getPassword(account) ) );
return oc;
}
@Override
protected void onPostExecute(OwnCloudClient o) {
super.onPostExecute(o);
caller.onOCClientReceived(o);
}
}
/*
* Copyright © Vincent Bourgmayer (/e/ foundation).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*/
package foundation.e.drive.utils;
/**
* @author Vincent Bourgmayer
*/
public interface IGetOCClient {
void onOCClientReceived(Object result);
}
......@@ -15,12 +15,9 @@ import android.content.Context;
import android.util.Log;
import foundation.e.drive.jobs.ScannerJob;
/**
* @author Vincent Bourgmayer
*/
public abstract class JobUtils {
final private static String TAG = JobUtils.class.getSimpleName(); //Tag for log
public final static int ScannerJobId = 3310;
......
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