diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 7337a890ac65106bb8dcaeac04f4eb87f89869c3..29b9ba121d55c864aa4496b16dfe80dff8b48ab3 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -64,7 +64,7 @@ http://www.gnu.org/licenses/gpl.html
-
+
operationsForIntent;
- /* Lifecycle Methods */
+ private HashMap syncRequests; //integer is SyncedFileState id; Parcelable is the operation
+
+ private SynchronizationService synchronizationService;
+ private boolean boundToSynchronizationService = false;
+ private ServiceConnection SynchronizationServiceConnection = new ServiceConnection() {
+ @Override
+ public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
+ SynchronizationService.SynchronizationBinder binder = (SynchronizationService.SynchronizationBinder) iBinder;
+ synchronizationService = binder.getService();
+ boundToSynchronizationService = true;
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName componentName) {
+ Log.e(TAG, "onServiceDisconnected");
+ boundToSynchronizationService = false;
+ }
+ };
+
+ /* Lifecycle Methods */
@Override
public void onDestroy(){
Log.i(TAG, "onDestroy()");
@@ -92,13 +110,13 @@ public class ObserverService extends Service implements OnRemoteOperationListene
initialFolderCounter = prefs.getInt(AppConstants.INITIALFOLDERS_NUMBER, 0);
// Check if account is invalid
- if(this.mAccount == null){
+ if (this.mAccount == null){
Log.w(TAG, "No account registered");
return super.onStartCommand(intent, flags, startId);
}
//check if user have disable eDrive's sync in account's settings
- if(!CommonUtils.isMediaSyncEnabled(mAccount) && !CommonUtils.isSettingsSyncEnabled(mAccount) ){
+ if (!CommonUtils.isMediaSyncEnabled(mAccount) && !CommonUtils.isSettingsSyncEnabled(mAccount) ){
Log.w(TAG, "eDrive syncing has been disabled in /e/ account's settings");
return super.onStartCommand(intent, flags, startId);
}
@@ -112,13 +130,13 @@ public class ObserverService extends Service implements OnRemoteOperationListene
}
//Check this service isn't already working
- if(isWorking){
+ if (isWorking){
Log.w(TAG, "ObserverService is already working");
return super.onStartCommand(intent,flags,startId);
}
//check OperationManagerService isn't working
- if(prefs.getBoolean(AppConstants.KEY_OMS_IS_WORKING, false)){
+ if (prefs.getBoolean(AppConstants.KEY_OMS_IS_WORKING, false)){
Log.w(TAG, "OperationManagerService is still performing some operation");
return super.onStartCommand(intent,flags, startId);
}
@@ -142,7 +160,11 @@ public class ObserverService extends Service implements OnRemoteOperationListene
Log.w(TAG, "There is no Internet connexion.");
return super.onStartCommand( intent, flags, startId );
}
- this.operationsForIntent = new HashMap<>();
+ this.syncRequests = new HashMap<>();
+
+ Intent SynchronizationServiceIntent = new Intent(this.getApplicationContext(), SynchronizationService.class);
+ bindService(SynchronizationServiceIntent, SynchronizationServiceConnection, Context.BIND_AUTO_CREATE);
+
begin();
return super.onStartCommand( intent, flags, startId );
}
@@ -191,7 +213,7 @@ public class ObserverService extends Service implements OnRemoteOperationListene
Log.i(TAG, "clearCachedFile()");
//Load subfiles into external cache file
File[] fileArray = this.getApplicationContext().getExternalCacheDir().listFiles(new OnlyFileFilter() );
- if(fileArray != null) {
+ if (fileArray != null) {
boolean toRemove;
for (int i = -1, size = fileArray.length; ++i < size; ) {
toRemove = true;
@@ -200,7 +222,7 @@ public class ObserverService extends Service implements OnRemoteOperationListene
Log.v(TAG+"_handleCachedFile()", "Deletion of cached file: " + deleteResult);
}
}
- }else{
+ } else {
Log.e(TAG+"_handleCachedFile()", "Array of cached file is null");
}
}
@@ -215,7 +237,7 @@ public class ObserverService extends Service implements OnRemoteOperationListene
Log.i(TAG, "startScan("+remote+")");
this.mSyncedFolders = loadSyncedFolders();
- if(mSyncedFolders.isEmpty() ){
+ if (mSyncedFolders.isEmpty() ){
Log.w(TAG, "List of synced folders is empty");
this.stopSelf();
return;
@@ -238,7 +260,7 @@ public class ObserverService extends Service implements OnRemoteOperationListene
} catch (IllegalArgumentException e){
Log.e(TAG, e.toString() );
}
- }else{
+ } else {
Log.w(TAG, "OwnCloudClient is null");
return;
}
@@ -256,22 +278,17 @@ public class ObserverService extends Service implements OnRemoteOperationListene
boolean mediaSyncEnabled = CommonUtils.isMediaSyncEnabled(mAccount);
boolean settingsSyncedEnabled = CommonUtils.isSettingsSyncEnabled(mAccount);
- if(mediaSyncEnabled && settingsSyncedEnabled){
+ if (mediaSyncEnabled && settingsSyncedEnabled){
return DbHelper.getAllSyncedFolders(this);
- }else if(mediaSyncEnabled){
+ } else if (mediaSyncEnabled){
return DbHelper.getSyncedFolderList(this, true);
- }else if(settingsSyncedEnabled){
+ } else if (settingsSyncedEnabled){
return DbHelper.getSyncedFolderList(this, false);
- }else{
+ } else {
return new ArrayList();
}
}
-
-
-
-
-
/**
* Handle end of remote Operation
* @param operation The RemoteOperation which ends and call this methods
@@ -280,7 +297,7 @@ public class ObserverService extends Service implements OnRemoteOperationListene
@Override
public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result ) {
Log.i( TAG, "onRemoteOperationFinish()" );
- if( operation instanceof ListFileRemoteOperation) {
+ if ( operation instanceof ListFileRemoteOperation) {
if (result.isSuccess()) {
List