CheckRemoteWipeTask.java 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. *
  3. * * Nextcloud Android client application
  4. * *
  5. * * @author Tobias Kaminsky
  6. * * Copyright (C) 2019 Tobias Kaminsky
  7. * * Copyright (C) 2019 Nextcloud GmbH
  8. * *
  9. * * This program is free software: you can redistribute it and/or modify
  10. * * it under the terms of the GNU Affero General Public License as published by
  11. * * the Free Software Foundation, either version 3 of the License, or
  12. * * (at your option) any later version.
  13. * *
  14. * * This program is distributed in the hope that it will be useful,
  15. * * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * * GNU Affero General Public License for more details.
  18. * *
  19. * * You should have received a copy of the GNU Affero General Public License
  20. * * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. *
  22. */
  23. package com.owncloud.android.ui.asynctasks;
  24. import android.accounts.Account;
  25. import android.os.AsyncTask;
  26. import com.nextcloud.client.jobs.BackgroundJobManager;
  27. import com.owncloud.android.lib.common.operations.RemoteOperationResult;
  28. import com.owncloud.android.lib.common.utils.Log_OC;
  29. import com.owncloud.android.lib.resources.users.CheckRemoteWipeRemoteOperation;
  30. import com.owncloud.android.ui.activity.FileActivity;
  31. import java.lang.ref.WeakReference;
  32. public class CheckRemoteWipeTask extends AsyncTask<Void, Void, Boolean> {
  33. private BackgroundJobManager backgroundJobManager;
  34. private Account account;
  35. private WeakReference<FileActivity> fileActivityWeakReference;
  36. public CheckRemoteWipeTask(BackgroundJobManager backgroundJobManager,
  37. Account account,
  38. WeakReference<FileActivity> fileActivityWeakReference) {
  39. this.backgroundJobManager = backgroundJobManager;
  40. this.account = account;
  41. this.fileActivityWeakReference = fileActivityWeakReference;
  42. }
  43. @Override
  44. protected Boolean doInBackground(Void... voids) {
  45. final FileActivity fileActivity = fileActivityWeakReference.get();
  46. if (fileActivity == null) {
  47. Log_OC.e(this, "Check for remote wipe: no context available");
  48. return Boolean.FALSE;
  49. }
  50. RemoteOperationResult checkWipeResult = new CheckRemoteWipeRemoteOperation().execute(account, fileActivity);
  51. if (checkWipeResult.isSuccess()) {
  52. backgroundJobManager.startAccountRemovalJob(account.name, true);
  53. } else {
  54. Log_OC.e(this, "Check for remote wipe not needed -> update credentials");
  55. fileActivity.performCredentialsUpdate(account, fileActivity);
  56. }
  57. return Boolean.TRUE;
  58. }
  59. }