FileSyncService.java 1.8 KB

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