FileSyncService.java 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * ownCloud Android client application
  3. *
  4. * @author Bartek Przybylski
  5. * @author David A. Velasco
  6. * Copyright (C) 2011 Bartek Przybylski
  7. * Copyright (C) 2015 ownCloud Inc.
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. package com.owncloud.android.syncadapter;
  22. import android.app.Service;
  23. import android.content.Intent;
  24. import android.os.IBinder;
  25. /**
  26. * Background service for synchronizing remote files with their local state.
  27. *
  28. * Serves as a connector to an instance of {@link FileSyncAdapter}, as required by standard Android APIs.
  29. */
  30. public class FileSyncService extends Service {
  31. // Storage for an instance of the sync adapter
  32. private static FileSyncAdapter syncAdapter;
  33. // Object to use as a thread-safe lock
  34. private static final Object syncAdapterLock = new Object();
  35. /*
  36. * {@inheritDoc}
  37. */
  38. @Override
  39. public void onCreate() {
  40. synchronized (syncAdapterLock) {
  41. if (syncAdapter == null) {
  42. syncAdapter = new FileSyncAdapter(getApplicationContext(), true);
  43. }
  44. }
  45. }
  46. /*
  47. * {@inheritDoc}
  48. */
  49. @Override
  50. public IBinder onBind(Intent intent) {
  51. return syncAdapter.getSyncAdapterBinder();
  52. }
  53. }