-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- strike out the account name (aka, you can't click it)
- switch to other acc if it exists, if not show login screen - run a job with all the delete magic - prevent adding the same account while there is pending delete for that account
- Loading branch information
1 parent
8fef61e
commit 87ae252
Showing
10 changed files
with
344 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/main/java/com/owncloud/android/services/AccountRemovalJob.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Nextcloud Android client application | ||
* | ||
* @author Tobias Kaminsky | ||
* Copyright (C) 2017 Tobias Kaminsky | ||
* Copyright (C) 2017 Nextcloud GmbH. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.owncloud.android.services; | ||
|
||
import android.accounts.Account; | ||
import android.accounts.AccountManager; | ||
import android.accounts.AccountManagerCallback; | ||
import android.accounts.AccountManagerFuture; | ||
import android.content.Context; | ||
import android.support.annotation.NonNull; | ||
|
||
import com.evernote.android.job.Job; | ||
import com.evernote.android.job.util.support.PersistableBundleCompat; | ||
import com.owncloud.android.MainApp; | ||
import com.owncloud.android.authentication.AccountUtils; | ||
import com.owncloud.android.datamodel.ArbitraryDataProvider; | ||
import com.owncloud.android.datamodel.FileDataStorageManager; | ||
import com.owncloud.android.ui.events.AccountRemovedEvent; | ||
import com.owncloud.android.utils.FileStorageUtils; | ||
|
||
import org.greenrobot.eventbus.EventBus; | ||
|
||
import java.io.File; | ||
|
||
import static android.content.Context.ACCOUNT_SERVICE; | ||
import static com.owncloud.android.ui.activity.ManageAccountsActivity.PENDING_FOR_REMOVAL; | ||
|
||
/** | ||
* Removes account and all local files | ||
*/ | ||
|
||
public class AccountRemovalJob extends Job implements AccountManagerCallback<Boolean> { | ||
public static final String TAG = "AccountRemovalJob"; | ||
public static final String ACCOUNT = "account"; | ||
|
||
@NonNull | ||
@Override | ||
protected Result onRunJob(Params params) { | ||
Context context = MainApp.getAppContext(); | ||
PersistableBundleCompat bundle = params.getExtras(); | ||
Account account = AccountUtils.getOwnCloudAccountByName(context, bundle.getString(ACCOUNT, "")); | ||
|
||
if (account != null ) { | ||
AccountManager am = (AccountManager) context.getSystemService(ACCOUNT_SERVICE); | ||
am.removeAccount(account, this, null); | ||
|
||
FileDataStorageManager storageManager = new FileDataStorageManager(account, context.getContentResolver()); | ||
|
||
File tempDir = new File(FileStorageUtils.getTemporalPath(account.name)); | ||
File saveDir = new File(FileStorageUtils.getSavePath(account.name)); | ||
|
||
FileStorageUtils.deleteRecursively(tempDir, storageManager); | ||
FileStorageUtils.deleteRecursively(saveDir, storageManager); | ||
|
||
// delete all database entries | ||
storageManager.deleteAllFiles(); | ||
|
||
// remove pending account removal | ||
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(context.getContentResolver()); | ||
arbitraryDataProvider.deleteKeyForAccount(account, PENDING_FOR_REMOVAL); | ||
|
||
return Result.SUCCESS; | ||
} else { | ||
return Result.FAILURE; | ||
} | ||
} | ||
|
||
@Override | ||
public void run(AccountManagerFuture<Boolean> future) { | ||
if (future.isDone()) { | ||
EventBus.getDefault().post(new AccountRemovedEvent()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.