CheckCurrentCredentialsOperation.java 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * ownCloud Android client application
  3. *
  4. * @author David A. Velasco
  5. * Copyright (C) 2016 ownCloud Inc.
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2,
  9. * as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. package com.owncloud.android.operations;
  21. import android.accounts.Account;
  22. import com.owncloud.android.datamodel.OCFile;
  23. import com.owncloud.android.lib.common.OwnCloudClient;
  24. import com.owncloud.android.lib.common.operations.RemoteOperation;
  25. import com.owncloud.android.lib.common.operations.RemoteOperationResult;
  26. import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation;
  27. import com.owncloud.android.operations.common.SyncOperation;
  28. import java.util.ArrayList;
  29. /**
  30. * Checks validity of currently stored credentials for a given OC account
  31. */
  32. public class CheckCurrentCredentialsOperation extends SyncOperation {
  33. private Account mAccount = null;
  34. public CheckCurrentCredentialsOperation(Account account) {
  35. if (account == null) {
  36. throw new IllegalArgumentException("NULL account");
  37. }
  38. mAccount = account;
  39. }
  40. @Override
  41. protected RemoteOperationResult run(OwnCloudClient client) {
  42. RemoteOperationResult result = null;
  43. if (!getStorageManager().getAccount().name.equals(mAccount.name)) {
  44. result = new RemoteOperationResult(new IllegalStateException(
  45. "Account to validate is not the account connected to!")
  46. );
  47. } else {
  48. RemoteOperation check = new ExistenceCheckRemoteOperation(OCFile.ROOT_PATH, false);
  49. result = check.execute(client);
  50. ArrayList<Object> data = new ArrayList<Object>();
  51. data.add(mAccount);
  52. result.setData(data);
  53. }
  54. return result;
  55. }
  56. }