use of com.owncloud.android.datamodel.UploadsStorageManager in project android by nextcloud.
the class AbstractOnServerIT method uploadOCUpload.
public void uploadOCUpload(OCUpload ocUpload, int localBehaviour) {
ConnectivityService connectivityServiceMock = new ConnectivityService() {
@Override
public boolean isInternetWalled() {
return false;
}
@Override
public Connectivity getConnectivity() {
return Connectivity.CONNECTED_WIFI;
}
};
PowerManagementService powerManagementServiceMock = new PowerManagementService() {
@NonNull
@Override
public BatteryStatus getBattery() {
return new BatteryStatus();
}
@Override
public boolean isPowerSavingEnabled() {
return false;
}
@Override
public boolean isPowerSavingExclusionAvailable() {
return false;
}
};
UserAccountManager accountManager = UserAccountManagerImpl.fromContext(targetContext);
UploadsStorageManager uploadsStorageManager = new UploadsStorageManager(accountManager, targetContext.getContentResolver());
UploadFileOperation newUpload = new UploadFileOperation(uploadsStorageManager, connectivityServiceMock, powerManagementServiceMock, user, null, ocUpload, NameCollisionPolicy.DEFAULT, localBehaviour, targetContext, false, false, getStorageManager());
newUpload.addRenameUploadListener(() -> {
// dummy
});
newUpload.setRemoteFolderToBeCreated();
RemoteOperationResult result = newUpload.execute(client);
assertTrue(result.getLogMessage(), result.isSuccess());
OCFile parentFolder = getStorageManager().getFileByEncryptedRemotePath(new File(ocUpload.getRemotePath()).getParent() + "/");
String uploadedFileName = new File(ocUpload.getRemotePath()).getName();
OCFile uploadedFile = getStorageManager().getFileByDecryptedRemotePath(parentFolder.getDecryptedRemotePath() + uploadedFileName);
assertNotNull(uploadedFile.getRemoteId());
if (localBehaviour == FileUploader.LOCAL_BEHAVIOUR_COPY || localBehaviour == FileUploader.LOCAL_BEHAVIOUR_MOVE) {
assertTrue(new File(uploadedFile.getStoragePath()).exists());
}
}
use of com.owncloud.android.datamodel.UploadsStorageManager in project android by owncloud.
the class UploadListActivity method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
boolean retval = true;
UploadsStorageManager storageManager = null;
UploadListFragment uploadListFragment = (UploadListFragment) getSupportFragmentManager().findFragmentByTag(TAG_UPLOAD_LIST_FRAGMENT);
switch(item.getItemId()) {
case android.R.id.home:
if (isDrawerOpen()) {
closeDrawer();
} else {
openDrawer();
}
case R.id.action_retry_uploads:
FileUploader.UploadRequester requester = new FileUploader.UploadRequester();
requester.retryFailedUploads(this, null, null);
break;
case R.id.action_clear_failed_uploads:
storageManager = new UploadsStorageManager(getContentResolver());
storageManager.clearFailedButNotDelayedForWifiUploads();
uploadListFragment.updateUploads();
break;
case R.id.action_clear_successfull_uploads:
storageManager = new UploadsStorageManager(getContentResolver());
storageManager.clearSuccessfulUploads();
uploadListFragment.updateUploads();
break;
case R.id.action_clear_finished_uploads:
storageManager = new UploadsStorageManager(getContentResolver());
storageManager.clearAllFinishedButNotDelayedForWifiUploads();
uploadListFragment.updateUploads();
break;
default:
retval = super.onOptionsItemSelected(item);
}
return retval;
}
use of com.owncloud.android.datamodel.UploadsStorageManager in project android by nextcloud.
the class FilesSyncHelper method restartJobsIfNeeded.
public static void restartJobsIfNeeded() {
final Context context = MainApp.getAppContext();
FileUploader.UploadRequester uploadRequester = new FileUploader.UploadRequester();
boolean accountExists;
UploadsStorageManager uploadsStorageManager = new UploadsStorageManager(context.getContentResolver(), context);
OCUpload[] failedUploads = uploadsStorageManager.getFailedUploads();
for (OCUpload failedUpload : failedUploads) {
accountExists = false;
// check if accounts still exists
for (Account account : AccountUtils.getAccounts(context)) {
if (account.name.equals(failedUpload.getAccountName())) {
accountExists = true;
break;
}
}
if (!accountExists) {
uploadsStorageManager.removeUpload(failedUpload);
}
}
new Thread(() -> {
if (!Device.getNetworkType(context).equals(JobRequest.NetworkType.ANY) && !ConnectivityUtils.isInternetWalled(context)) {
uploadRequester.retryFailedUploads(context, null, null);
}
}).start();
}
use of com.owncloud.android.datamodel.UploadsStorageManager in project android by nextcloud.
the class UploadListActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
uploadStorageManager = new UploadsStorageManager(getContentResolver(), getApplicationContext());
setContentView(R.layout.upload_list_layout);
unbinder = ButterKnife.bind(this);
swipeListRefreshLayout = findViewById(R.id.swipe_containing_list);
// this activity has no file really bound, it's for multiple accounts at the same time; should no inherit
// from FileActivity; moreover, some behaviours inherited from FileActivity should be delegated to Fragments;
// but that's other story
setFile(null);
// setup toolbar
setupToolbar();
// setup drawer
setupDrawer(R.id.nav_uploads);
setupContent();
if (getSupportActionBar() != null) {
getSupportActionBar().setTitle(getString(R.string.uploads_view_title));
}
BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation_view);
if (getResources().getBoolean(R.bool.bottom_toolbar_enabled)) {
bottomNavigationView.setVisibility(View.VISIBLE);
DisplayUtils.setupBottomBar(bottomNavigationView, getResources(), this, -1);
}
}
use of com.owncloud.android.datamodel.UploadsStorageManager in project android by nextcloud.
the class AccountRemovalJob method onRunJob.
@NonNull
@Override
protected Result onRunJob(Params params) {
Context context = MainApp.getAppContext();
PersistableBundleCompat bundle = params.getExtras();
Account account = AccountUtils.getOwnCloudAccountByName(context, bundle.getString(ACCOUNT, ""));
AccountManager am = (AccountManager) context.getSystemService(ACCOUNT_SERVICE);
if (account != null && am != null) {
// disable contact backup job
ContactsPreferenceActivity.cancelContactBackupJobForAccount(context, account);
if (am != null) {
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.name, PENDING_FOR_REMOVAL);
// remove synced folders set for account
SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(context.getContentResolver());
List<SyncedFolder> syncedFolders = syncedFolderProvider.getSyncedFolders();
List<Long> syncedFolderIds = new ArrayList<>();
for (SyncedFolder syncedFolder : syncedFolders) {
if (syncedFolder.getAccount().equals(account.name)) {
arbitraryDataProvider.deleteKeyForAccount(FilesSyncHelper.GLOBAL, FilesSyncHelper.SYNCEDFOLDERINITIATED + syncedFolder.getId());
syncedFolderIds.add(syncedFolder.getId());
}
}
syncedFolderProvider.deleteSyncFoldersForAccount(account);
UploadsStorageManager uploadsStorageManager = new UploadsStorageManager(context.getContentResolver(), context);
uploadsStorageManager.removeAccountUploads(account);
FilesystemDataProvider filesystemDataProvider = new FilesystemDataProvider(context.getContentResolver());
for (long syncedFolderId : syncedFolderIds) {
filesystemDataProvider.deleteAllEntriesForSyncedFolder(Long.toString(syncedFolderId));
}
// delete stored E2E keys
arbitraryDataProvider.deleteKeyForAccount(account.name, EncryptionUtils.PRIVATE_KEY);
arbitraryDataProvider.deleteKeyForAccount(account.name, EncryptionUtils.PUBLIC_KEY);
return Result.SUCCESS;
} else {
return Result.FAILURE;
}
}
Aggregations