Loading app/src/main/java/foundation/e/drive/EdriveApplication.java +22 −14 Original line number Diff line number Diff line Loading @@ -11,12 +11,9 @@ package foundation.e.drive; import android.accounts.Account; import android.accounts.AccountManager; import android.app.Application; import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.os.Build; import android.os.Environment; import android.util.Log; Loading @@ -31,7 +28,6 @@ import foundation.e.drive.utils.CommonUtils; * It is instantiated before any other class. */ public class EdriveApplication extends Application { private static final String TAG = "EdriveApplication"; private RecursiveFileObserver mFileObserver = null; private FileEventListener fileEventListener; Loading @@ -45,22 +41,24 @@ public class EdriveApplication extends Application { final String pathForObserver = Environment.getExternalStorageDirectory().getAbsolutePath(); mFileObserver = new RecursiveFileObserver(getApplicationContext(), pathForObserver, fileEventListener); SharedPreferences prefs = getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE); final SharedPreferences prefs = getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE); CommonUtils.createNotificationChannel(getApplicationContext()); if (prefs.getString(AccountManager.KEY_ACCOUNT_NAME, null) != null) { Log.d(TAG, "Account already registered"); startRecursiveFileObserver(); Intent SynchronizationServiceIntent = new Intent(getApplicationContext(), SynchronizationService.class); resetTransferFailureCounter(); final Intent SynchronizationServiceIntent = new Intent(getApplicationContext(), SynchronizationService.class); startService(SynchronizationServiceIntent); } else { Account mAccount = CommonUtils.getAccount(getString(R.string.eelo_account_type), AccountManager.get(this)); final Account mAccount = CommonUtils.getAccount(getString(R.string.eelo_account_type), AccountManager.get(this)); if (mAccount == null) { return; } String accountName = mAccount.name; String accountType = mAccount.type; final String accountName = mAccount.name; final String accountType = mAccount.type; prefs.edit().putString(AccountManager.KEY_ACCOUNT_NAME, accountName) .putString(AccountManager.KEY_ACCOUNT_TYPE, accountType) Loading @@ -76,8 +74,7 @@ public class EdriveApplication extends Application { fileEventListener.bindToSynchronizationService(); mFileObserver.startWatching(); Log.d(TAG, "Starting RecursiveFileObserver on root folder"); } else { } else { Log.w(TAG, "RecursiveFileObserver (for media's root folder) was already running"); } } Loading @@ -88,6 +85,17 @@ public class EdriveApplication extends Application { Log.d(TAG, "RecursiveFileObserver on root folder stops watching "); } /** * Clear sharedPreference that store failed transfer counter. * Doing this here, allow to restart it once a day. */ private void resetTransferFailureCounter() { final SharedPreferences prefs = getSharedPreferences(AppConstants.FAILED_TRANSFER_PREF, Context.MODE_PRIVATE); prefs.edit().clear().commit(); } @Override public void onLowMemory() { super.onLowMemory(); Loading app/src/main/java/foundation/e/drive/FileObservers/FileEventListener.java +1 −1 Original line number Diff line number Diff line Loading @@ -64,7 +64,7 @@ public class FileEventListener { private void sendSyncRequestToSynchronizationService(SyncRequest request) { Log.d(TAG, "Sending a SyncRequest for " + request.getSyncedFileState().getName()); if (serviceConnection.isBoundToSynchronizationService()) { serviceConnection.getSynchronizationService().queueOperation(request); serviceConnection.getSynchronizationService().queueSyncRequest(request); serviceConnection.getSynchronizationService().startSynchronization(); }else{ Log.w(TAG, "Impossible to send SyncRequest. FileEventListener is not bound to SynchronizationService"); Loading app/src/main/java/foundation/e/drive/models/SyncWrapper.java +4 −0 Original line number Diff line number Diff line Loading @@ -82,4 +82,8 @@ public class SyncWrapper { } return super.equals(obj); } public SyncRequest getRequest() { return request; } } app/src/main/java/foundation/e/drive/services/ObserverService.java +1 −1 Original line number Diff line number Diff line Loading @@ -323,7 +323,7 @@ public class ObserverService extends Service implements OnRemoteOperationListene private void passSyncRequestsToSynchronizationService() { if (synchronizationServiceConnection.isBoundToSynchronizationService()) { synchronizationServiceConnection.getSynchronizationService().queueOperations(syncRequests.values()); synchronizationServiceConnection.getSynchronizationService().queueSyncRequests(syncRequests.values()); synchronizationServiceConnection.getSynchronizationService().startSynchronization(); } else { Log.e(TAG, "ERROR: impossible to bind ObserverService to SynchronizationService"); Loading app/src/main/java/foundation/e/drive/services/ResetService.java +2 −0 Original line number Diff line number Diff line Loading @@ -92,6 +92,8 @@ public class ResetService extends Service { .remove(AppConstants.KEY_LAST_SYNC_TIME) .apply(); } deleteSharedPreferences(AppConstants.FAILED_TRANSFER_PREF); } private void removeCachedFiles() { Loading Loading
app/src/main/java/foundation/e/drive/EdriveApplication.java +22 −14 Original line number Diff line number Diff line Loading @@ -11,12 +11,9 @@ package foundation.e.drive; import android.accounts.Account; import android.accounts.AccountManager; import android.app.Application; import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.os.Build; import android.os.Environment; import android.util.Log; Loading @@ -31,7 +28,6 @@ import foundation.e.drive.utils.CommonUtils; * It is instantiated before any other class. */ public class EdriveApplication extends Application { private static final String TAG = "EdriveApplication"; private RecursiveFileObserver mFileObserver = null; private FileEventListener fileEventListener; Loading @@ -45,22 +41,24 @@ public class EdriveApplication extends Application { final String pathForObserver = Environment.getExternalStorageDirectory().getAbsolutePath(); mFileObserver = new RecursiveFileObserver(getApplicationContext(), pathForObserver, fileEventListener); SharedPreferences prefs = getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE); final SharedPreferences prefs = getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE); CommonUtils.createNotificationChannel(getApplicationContext()); if (prefs.getString(AccountManager.KEY_ACCOUNT_NAME, null) != null) { Log.d(TAG, "Account already registered"); startRecursiveFileObserver(); Intent SynchronizationServiceIntent = new Intent(getApplicationContext(), SynchronizationService.class); resetTransferFailureCounter(); final Intent SynchronizationServiceIntent = new Intent(getApplicationContext(), SynchronizationService.class); startService(SynchronizationServiceIntent); } else { Account mAccount = CommonUtils.getAccount(getString(R.string.eelo_account_type), AccountManager.get(this)); final Account mAccount = CommonUtils.getAccount(getString(R.string.eelo_account_type), AccountManager.get(this)); if (mAccount == null) { return; } String accountName = mAccount.name; String accountType = mAccount.type; final String accountName = mAccount.name; final String accountType = mAccount.type; prefs.edit().putString(AccountManager.KEY_ACCOUNT_NAME, accountName) .putString(AccountManager.KEY_ACCOUNT_TYPE, accountType) Loading @@ -76,8 +74,7 @@ public class EdriveApplication extends Application { fileEventListener.bindToSynchronizationService(); mFileObserver.startWatching(); Log.d(TAG, "Starting RecursiveFileObserver on root folder"); } else { } else { Log.w(TAG, "RecursiveFileObserver (for media's root folder) was already running"); } } Loading @@ -88,6 +85,17 @@ public class EdriveApplication extends Application { Log.d(TAG, "RecursiveFileObserver on root folder stops watching "); } /** * Clear sharedPreference that store failed transfer counter. * Doing this here, allow to restart it once a day. */ private void resetTransferFailureCounter() { final SharedPreferences prefs = getSharedPreferences(AppConstants.FAILED_TRANSFER_PREF, Context.MODE_PRIVATE); prefs.edit().clear().commit(); } @Override public void onLowMemory() { super.onLowMemory(); Loading
app/src/main/java/foundation/e/drive/FileObservers/FileEventListener.java +1 −1 Original line number Diff line number Diff line Loading @@ -64,7 +64,7 @@ public class FileEventListener { private void sendSyncRequestToSynchronizationService(SyncRequest request) { Log.d(TAG, "Sending a SyncRequest for " + request.getSyncedFileState().getName()); if (serviceConnection.isBoundToSynchronizationService()) { serviceConnection.getSynchronizationService().queueOperation(request); serviceConnection.getSynchronizationService().queueSyncRequest(request); serviceConnection.getSynchronizationService().startSynchronization(); }else{ Log.w(TAG, "Impossible to send SyncRequest. FileEventListener is not bound to SynchronizationService"); Loading
app/src/main/java/foundation/e/drive/models/SyncWrapper.java +4 −0 Original line number Diff line number Diff line Loading @@ -82,4 +82,8 @@ public class SyncWrapper { } return super.equals(obj); } public SyncRequest getRequest() { return request; } }
app/src/main/java/foundation/e/drive/services/ObserverService.java +1 −1 Original line number Diff line number Diff line Loading @@ -323,7 +323,7 @@ public class ObserverService extends Service implements OnRemoteOperationListene private void passSyncRequestsToSynchronizationService() { if (synchronizationServiceConnection.isBoundToSynchronizationService()) { synchronizationServiceConnection.getSynchronizationService().queueOperations(syncRequests.values()); synchronizationServiceConnection.getSynchronizationService().queueSyncRequests(syncRequests.values()); synchronizationServiceConnection.getSynchronizationService().startSynchronization(); } else { Log.e(TAG, "ERROR: impossible to bind ObserverService to SynchronizationService"); Loading
app/src/main/java/foundation/e/drive/services/ResetService.java +2 −0 Original line number Diff line number Diff line Loading @@ -92,6 +92,8 @@ public class ResetService extends Service { .remove(AppConstants.KEY_LAST_SYNC_TIME) .apply(); } deleteSharedPreferences(AppConstants.FAILED_TRANSFER_PREF); } private void removeCachedFiles() { Loading