FileSyncService.java 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. import com.nextcloud.client.account.UserAccountManager;
  26. import com.owncloud.android.utils.theme.ViewThemeUtils;
  27. import javax.inject.Inject;
  28. import dagger.android.AndroidInjection;
  29. /**
  30. * Background service for synchronizing remote files with their local state.
  31. *
  32. * Serves as a connector to an instance of {@link FileSyncAdapter}, as required by standard Android APIs.
  33. */
  34. public class FileSyncService extends Service {
  35. // Storage for an instance of the sync adapter
  36. private static FileSyncAdapter syncAdapter;
  37. // Object to use as a thread-safe lock
  38. private static final Object syncAdapterLock = new Object();
  39. @Inject UserAccountManager userAccountManager;
  40. @Inject ViewThemeUtils viewThemeUtils;
  41. /*
  42. * {@inheritDoc}
  43. */
  44. @Override
  45. public void onCreate() {
  46. AndroidInjection.inject(this);
  47. synchronized (syncAdapterLock) {
  48. if (syncAdapter == null) {
  49. syncAdapter = new FileSyncAdapter(getApplicationContext(), true, userAccountManager, viewThemeUtils);
  50. }
  51. }
  52. }
  53. /*
  54. * {@inheritDoc}
  55. */
  56. @Override
  57. public IBinder onBind(Intent intent) {
  58. return syncAdapter.getSyncAdapterBinder();
  59. }
  60. }