diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index c60fad306dd258e5849567c4b98479ee6a5e8dcf..cdb53b009103ca116c19ba4611ba2048f05f6dda 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,20 +1,18 @@
image: "registry.gitlab.e.foundation/e/os/docker-android-apps-cicd:latest"
stages:
-- test
-- build
+ - test
+ - build
before_script:
-- git submodule sync
-- git submodule update --init --recursive
-- export GRADLE_USER_HOME=$(pwd)/.gradle
-- chmod +x ./gradlew
+ - export GRADLE_USER_HOME=$(pwd)/.gradle
+ - chmod +x ./gradlew
cache:
key: ${CI_PROJECT_ID}
paths:
- - .gradle/
+ - .gradle/
test:
@@ -35,9 +33,9 @@ test:
build:
stage: build
script:
- - ./gradlew assemble
+ - ./gradlew assemble
artifacts:
paths:
- - app/build/outputs/apk/
+ - app/build/outputs/apk/
expire_in: 4 weeks
diff --git a/.gitmodules b/.gitmodules
deleted file mode 100644
index 34e74166112d7eca22fde53420986cd1f42474bb..0000000000000000000000000000000000000000
--- a/.gitmodules
+++ /dev/null
@@ -1,3 +0,0 @@
-[submodule "nextcloud-android-lib"]
- path = nextcloud-android-lib
- url = ../nextcloud-android-lib.git
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
index 0bda024227adbb6b814b990cd47dad42e43e78be..35eb1ddfbbc029bcab630581847471d7f238ec53 100644
--- a/.idea/vcs.xml
+++ b/.idea/vcs.xml
@@ -2,6 +2,5 @@
-
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 12df8d963a55c16b57401d8f69f1acbb2f1f8272..bbcd73a2dbd9bc491415c03228ca914ccfa080ef 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,16 +1,19 @@
+plugins {
+ id 'com.android.application'
+}
+
-import java.text.SimpleDateFormat;
-apply plugin: 'com.android.application'
def versionMajor = 1
-def versionMinor = 0
-def versionPatch = 1
+def versionMinor = 1
+def versionPatch = 0
+
def getTestProp(String propName) {
def result = ""
- if(project.hasProperty(propName)){
+ if (project.hasProperty(propName)) {
result =project.property(propName).toString()
- }else if(project.rootProject.file('local.properties').exists()){
+ } else if(project.rootProject.file('local.properties').exists()) {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newReader())
result = properties.getProperty(propName)
@@ -20,13 +23,15 @@ def getTestProp(String propName) {
android {
- compileSdkVersion 31
+ compileSdk 31
defaultConfig {
applicationId "foundation.e.drive"
- minSdkVersion 26
+ minSdk 26
+ targetSdk 31
versionCode versionMajor * 1000000 + versionMinor * 1000 + versionPatch
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
setProperty("archivesBaseName", "eDrive-$versionName")
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
@@ -35,10 +40,6 @@ android {
}
}
- lintOptions {
- abortOnError false
- }
-
testOptions {
unitTests {
@@ -55,37 +56,38 @@ android {
viewBinding true
}
compileOptions {
- sourceCompatibility JavaVersion.VERSION_1_8
- targetCompatibility JavaVersion.VERSION_1_8
+ sourceCompatibility JavaVersion.VERSION_11
+ targetCompatibility JavaVersion.VERSION_11
}
}
dependencies {
- api project(':NextcloudLib')
+ implementation 'com.github.nextcloud:android-library:2.10.1'
+ implementation "commons-httpclient:commons-httpclient:3.1@jar"
implementation fileTree(include: ['*.jar'], dir: 'libs')
api 'androidx.annotation:annotation:1.3.0'
- implementation 'androidx.core:core:1.6.0'
- implementation 'androidx.appcompat:appcompat:1.0.2'
+ implementation 'androidx.core:core:1.7.0'
+ implementation 'androidx.appcompat:appcompat:1.4.1'
implementation "androidx.constraintlayout:constraintlayout:2.1.3"
- implementation 'com.google.android.material:material:1.5.0'
+ implementation 'com.google.android.material:material:1.6.0'
implementation 'com.github.bumptech.glide:glide:4.13.1'
-
- def work_version = "2.7.1"
- // (Java only)
- implementation "androidx.work:work-runtime:$work_version"
+ implementation "androidx.work:work-runtime:2.7.1"
+ implementation 'androidx.test:core:1.4.0'
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test:rules:1.4.0'
androidTestImplementation 'androidx.annotation:annotation:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
- androidTestImplementation 'junit:junit:4.12'
+ androidTestImplementation 'junit:junit:4.13.2'
testImplementation 'androidx.test:runner:1.4.0'
testImplementation 'androidx.test:rules:1.4.0'
- testImplementation 'junit:junit:4.12'
- testImplementation 'org.robolectric:robolectric:4.8.1'
- testImplementation 'org.mockito:mockito-inline:3.4.0'
- testImplementation "androidx.work:work-testing:$work_version"
+
+ testImplementation 'junit:junit:4.13.2'
+ testImplementation 'org.robolectric:robolectric:4.4'
+ testImplementation 'org.mockito:mockito-core:3.4.0'
+ //testImplementation 'org.mockito:mockito-inline:3.4.0'
+ testImplementation 'androidx.work:work-testing:2.7.1'
}
diff --git a/app/src/androidTest/java/foundation/e/drive/services/ObserverServiceInstrumentedTest.java b/app/src/androidTest/java/foundation/e/drive/services/ObserverServiceInstrumentedTest.java
deleted file mode 100644
index bd5fe22cd23116c10c5b0b339b4a18eb8ba736dc..0000000000000000000000000000000000000000
--- a/app/src/androidTest/java/foundation/e/drive/services/ObserverServiceInstrumentedTest.java
+++ /dev/null
@@ -1,100 +0,0 @@
-package foundation.e.drive.services;
-
-import android.accounts.Account;
-import android.accounts.AccountManager;
-import android.app.Service;
-import android.content.Context;
-import android.content.Intent;
-import android.os.Environment;
-import android.support.test.InstrumentationRegistry;
-import android.support.test.rule.ServiceTestRule;
-import android.support.test.runner.AndroidJUnit4;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.concurrent.TimeoutException;
-
-import static android.support.test.InstrumentationRegistry.getContext;
-import static org.junit.Assert.*;
-
-
-
-
-/**
- * Instrumented test, which will execute on an Android device.
- *
- * @see Testing documentation
- */
-@RunWith(AndroidJUnit4.class)
-public class ObserverServiceInstrumentedTest {
- private final static String NEW_SMALL_FILE_PATH = Environment.getExternalStorageDirectory() + File.separator + Environment.DIRECTORY_DOCUMENTS+File.separator+"test-small-file.txt";
- private final static String ACCOUNT_NAME= "";
- private final static String ACCOUNT_PASS="";
- private final static String ACCOUNT_TYPE="";
-
-
- @Rule
- public final ServiceTestRule mServiceRule = new ServiceTestRule();
-
-
- @Before
- public void RegisterAccount() throws Exception {
- final Account account = new Account(ACCOUNT_NAME, ACCOUNT_TYPE);
- AccountManager.get(getContext()).addAccountExplicitly(account, ACCOUNT_PASS, null);
-
- }
-
-
- /**
- * Souldn't it be more for a unit test ?
- * @throws IOException
- */
- @Before
- public void createLocalSmallFile() throws IOException {
-
- File file = new File(NEW_SMALL_FILE_PATH);
- file.createNewFile();
- String content = "this a very small content";
-//write the bytes in file
- if(file.exists())
- {
- OutputStream fo = new FileOutputStream(file);
- fo.write(content.getBytes());
- fo.close();
- System.out.println("file created: "+file);
- }
- }
-
-
- @After
- public void deleteLocalSmallFile(){
- File file = new File(NEW_SMALL_FILE_PATH);
- //deleting the file
- file.delete();
- }
-
-
- @Test
- public void testWithStartedService() throws TimeoutException {
- mServiceRule.startService(
- new Intent(InstrumentationRegistry.getTargetContext(), ObserverService.class));
- //do something
- }
-
- @Test
- public void useAppContext() throws Exception {
- // Context of the app under test.
- Context appContext = InstrumentationRegistry.getTargetContext();
-
-
- assertEquals("foundation.e.drive", appContext.getPackageName());
- }
-}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index dc5d04a4bcefec9387e03ddc06f33a33cb681765..4b674380f3f5881c8de08b6fb4b42f9827ae901b 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -1,17 +1,21 @@
+
-
+
+ android:roundIcon="@mipmap/ic_eelo_round"
+ android:requestLegacyExternalStorage="true">
+ android:exported="true"
+ android:label="@string/app_widget_description">
@@ -92,14 +97,16 @@
+ android:enabled="true"
+ android:exported="true">
+ android:enabled="true"
+ android:exported="true">
diff --git a/app/src/main/java/foundation/e/drive/activity/AccountsActivity.java b/app/src/main/java/foundation/e/drive/activity/AccountsActivity.java
index f40413ca15dfecd4bee2b826a77ccacfa80b8817..109936ae769337ef37abbda1013e8bee2b3985e9 100644
--- a/app/src/main/java/foundation/e/drive/activity/AccountsActivity.java
+++ b/app/src/main/java/foundation/e/drive/activity/AccountsActivity.java
@@ -36,6 +36,7 @@ import com.owncloud.android.lib.common.OwnCloudClient;
import foundation.e.drive.R;
import foundation.e.drive.databinding.ActivityAccountsBinding;
import foundation.e.drive.utils.CommonUtils;
+import foundation.e.drive.utils.DavClientProvider;
import foundation.e.drive.widgets.EDriveWidget;
public class AccountsActivity extends AppCompatActivity {
@@ -70,7 +71,7 @@ public class AccountsActivity extends AppCompatActivity {
final AccountManager accountManager = AccountManager.get(this);
final Account account = CommonUtils.getAccount(getString(R.string.eelo_account_type),
accountManager);
- final OwnCloudClient client = CommonUtils.getOwnCloudClient(account, this);
+ final OwnCloudClient client = DavClientProvider.getInstance().getClientInstance(account, this);
final String usedQuota = accountManager.getUserData(account, ACCOUNT_DATA_USED_QUOTA_KEY);
final String totalQuota = accountManager.getUserData(account, ACCOUNT_DATA_TOTAL_QUOTA_KEY);
diff --git a/app/src/main/java/foundation/e/drive/models/SyncWrapper.java b/app/src/main/java/foundation/e/drive/models/SyncWrapper.java
index 598f518246129a9f5175288ee3f25b88c6a90efd..f6bc93133ed9ee74bcd0d5de499b9d4ae60c676b 100644
--- a/app/src/main/java/foundation/e/drive/models/SyncWrapper.java
+++ b/app/src/main/java/foundation/e/drive/models/SyncWrapper.java
@@ -7,6 +7,7 @@
*/
package foundation.e.drive.models;
+import android.accounts.Account;
import android.content.Context;
import com.owncloud.android.lib.common.operations.RemoteOperation;
@@ -29,9 +30,9 @@ public class SyncWrapper {
* @param request SyncRequest at origin of the file transfer
* @param context Application context, used to create RemoteOperation to run
*/
- public SyncWrapper(SyncRequest request, Context context) {
+ public SyncWrapper(final SyncRequest request, final Account account, final Context context) {
this.request = request;
- remoteOperation = createRemoteOperation(request, context);
+ remoteOperation = createRemoteOperation(request, account, context);
isRunning = true;
}
@@ -53,12 +54,12 @@ public class SyncWrapper {
* @param context App context to be passed to RemoteOperation's contructor
* @return RemoteOperation for Upload/Download request or null
*/
- private static RemoteOperation createRemoteOperation(SyncRequest request, Context context) {
+ private static RemoteOperation createRemoteOperation(final SyncRequest request, final Account account, final Context context) {
final RemoteOperation operation;
switch (request.getOperationType()) {
case UPLOAD:
final SyncedFileState sfs = request.getSyncedFileState();
- operation = new UploadFileOperation(sfs, context);
+ operation = new UploadFileOperation(sfs, account, context);
break;
case DOWNLOAD:
final DownloadRequest downloadRequest = (DownloadRequest) request;
diff --git a/app/src/main/java/foundation/e/drive/operations/DownloadFileOperation.java b/app/src/main/java/foundation/e/drive/operations/DownloadFileOperation.java
index 5d8892d30495ef2a1abca1b61c5d68f41be600ab..cc4115ee99c173b676222c190353159dae129f99 100644
--- a/app/src/main/java/foundation/e/drive/operations/DownloadFileOperation.java
+++ b/app/src/main/java/foundation/e/drive/operations/DownloadFileOperation.java
@@ -14,6 +14,7 @@ import android.util.Log;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
+import com.owncloud.android.lib.resources.files.DownloadFileRemoteOperation;
import com.owncloud.android.lib.resources.files.FileUtils;
import com.owncloud.android.lib.resources.files.model.RemoteFile;
import java.io.File;
@@ -24,16 +25,17 @@ import foundation.e.drive.utils.CommonUtils;
/**
* @author Vincent Bourgmayer
* Encapsulate a global download process for a file
+ * /!\ Doesn't require NextcloudClient yet
*/
public class DownloadFileOperation extends RemoteOperation {
private final static String TAG = DownloadFileOperation.class.getSimpleName();
private final RemoteFile remoteFile;
- private Context context;
- private String targetPath;
+ private final Context context;
+ private final String targetPath;
private int restartCounter =0;
- private SyncedFileState syncedFileState;
- private String previousEtag;
+ private final SyncedFileState syncedFileState;
+ private final String previousEtag;
/**
* COnstructor of download operation where syncedFileState is already known
@@ -50,76 +52,68 @@ public class DownloadFileOperation extends RemoteOperation {
@Override
protected RemoteOperationResult run(OwnCloudClient ownCloudClient) {
- Log.i(TAG, "run(ownCloudClient)");
-
- //get or build synced file equivalent of this.mFile
- if (syncedFileState == null || targetPath == null || targetPath.isEmpty()) {
- Log.e(TAG, "syncedFileState or targetPath is empty or null. Can't Download in those conditions");
- return new RemoteOperationResult(RemoteOperationResult.ResultCode.FORBIDDEN);
- } else if (syncedFileState.getId() == -1) {
+ Log.i(TAG, "run(client) for "+remoteFile.getRemotePath());
+ if (syncedFileState.getId() == -1) {
this.syncedFileState.setId(DbHelper.manageSyncedFileStateDB(this.syncedFileState, "INSERT", context));
}
- if (syncedFileState.getLastETAG().equals(remoteFile.getEtag()) && syncedFileState.getLocalLastModified() > 0L) {
- //Same etag and localLastModified not null mean the file is up to date
+ if (syncedFileState.getLastETAG().equals(remoteFile.getEtag())
+ && syncedFileState.getLocalLastModified() > 0L) {
+ //file is up to date
Log.w(TAG, "File already up-to-date");
return new RemoteOperationResult(RemoteOperationResult.ResultCode.ETAG_UNCHANGED);
}
-
- final String tmpTargetPath = context.getExternalCacheDir()+ FileUtils.PATH_SEPARATOR+ syncedFileState.getName();
+
+ final String tmpTargetFolderPath = context.getExternalCacheDir().getAbsolutePath();
final DownloadFileRemoteOperation downloadOperation = new DownloadFileRemoteOperation(remoteFile.getRemotePath(),
- tmpTargetPath);
+ tmpTargetFolderPath);
final RemoteOperationResult downloadResult = downloadOperation.execute(ownCloudClient);
RemoteOperationResult.ResultCode resultCode;
boolean mustRestart = true;
+
if (downloadResult.isSuccess()) {
- final File tmpLocalFile = new File(tmpTargetPath);
- if (!tmpLocalFile.exists()) {
+ final String tmpFilePath = tmpTargetFolderPath+remoteFile.getRemotePath();
+ final File tmpFile = new File(tmpFilePath);
+
+ if (!tmpFile.exists()) {
Log.e(TAG, "Downloaded file doesn't exist or is null");
resultCode = RemoteOperationResult.ResultCode.FILE_NOT_FOUND;
- } else if (tmpLocalFile.length() != remoteFile.getLength()) {
-
- Log.e(TAG, "Local and remote file doesn't have the same size.");
+ } else if (tmpFile.length() != remoteFile.getLength()) {
+ Log.e(TAG, "Local and remote file doesn't have the same size");
resultCode = RemoteOperationResult.ResultCode.INVALID_OVERWRITE;
- tmpLocalFile.delete();
+ tmpFile.delete();
+ } else { //file has been correctly download.
- } else {
- //file has been correctly download.
final File localFile = new File(targetPath);
- if (localFile.exists()) {
+ if (!localFile.getParentFile().exists()) {
+ localFile.getParentFile().mkdirs();
+ } else if (localFile.exists()) {
localFile.delete();
}
- //Check parentFolder existence and create if needed
- final String parentFoldersPath = localFile.getParent();
- final File localParentFile = new File(parentFoldersPath);
- if (!localParentFile.exists()) {
- if (localParentFile.mkdirs())
- Log.d(TAG, "Created folders: "+parentFoldersPath);
- else
- Log.d(TAG, "Can't create folders: "+parentFoldersPath);
- }
- boolean renameResult = tmpLocalFile.renameTo(localFile);
- if (!renameResult)
- Log.d(TAG, "File hasn't been successfully moved at its place");
+ if (!tmpFile.renameTo(localFile)) {
+ Log.d(TAG, "failed to move " + tmpFile.getAbsolutePath() + " to " + targetPath);
+ return new RemoteOperationResult(RemoteOperationResult.ResultCode.FORBIDDEN);
+ }
+ Log.d(TAG, "File moved to: "+localFile.getAbsolutePath());
syncedFileState.setLocalLastModified(localFile.lastModified())
.setLastETAG(remoteFile.getEtag());
+
mustRestart = false;
resultCode = RemoteOperationResult.ResultCode.OK;
//needed to make Gallery show new image
CommonUtils.doActionMediaScannerConnexionScanFile(context, syncedFileState.getLocalPath());
}
- } else {
- //If download failed
+ } else { //If download failed
Log.e(TAG, "Download failed: "+downloadResult.getLogMessage());
resultCode = RemoteOperationResult.ResultCode.UNKNOWN_ERROR;
}
if (mustRestart) {
- Log.w(TAG, restartCounter+" unsuccessfull trial.s of downloading file "
+ Log.w(TAG, restartCounter+" unsuccessfull trial.s of downloading"
+ remoteFile.getRemotePath());
syncedFileState.setLastETAG(this.previousEtag);
if (this.restartCounter < 3) {
diff --git a/app/src/main/java/foundation/e/drive/operations/DownloadFileRemoteOperation.java b/app/src/main/java/foundation/e/drive/operations/DownloadFileRemoteOperation.java
deleted file mode 100644
index 107b6ff1862fee9d400e6a5780c9ce14fa0464b0..0000000000000000000000000000000000000000
--- a/app/src/main/java/foundation/e/drive/operations/DownloadFileRemoteOperation.java
+++ /dev/null
@@ -1,188 +0,0 @@
-/* ownCloud Android Library is available under MIT license
- * Copyright (C) 2015 ownCloud Inc.
- * Copyright © CLEUS SAS 2018-2019.
- * Copyright © ECORP SAS 2022.
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-package foundation.e.drive.operations;
-
-import android.util.Log;
-
-import com.owncloud.android.lib.common.OwnCloudClient;
-import com.owncloud.android.lib.common.network.WebdavUtils;
-import com.owncloud.android.lib.common.operations.OperationCancelledException;
-import com.owncloud.android.lib.common.operations.RemoteOperation;
-import com.owncloud.android.lib.common.operations.RemoteOperationResult;
-import com.owncloud.android.lib.common.utils.Log_OC;
-import org.apache.commons.httpclient.Header;
-import org.apache.commons.httpclient.HttpStatus;
-import org.apache.commons.httpclient.methods.GetMethod;
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.Date;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-/**
- * Remote operation performing the download of a remote file in the ownCloud server.
- *
- * @author David A. Velasco
- * @author masensio
- * @author Vincent Bourgmayer
- */
-class DownloadFileRemoteOperation extends RemoteOperation {
- private static final String TAG = DownloadFileRemoteOperation.class.getSimpleName();
-
- private final AtomicBoolean mCancellationRequested = new AtomicBoolean(false);
- private long mModificationTimestamp = 0;
- private String mEtag = "";
- private GetMethod mGet;
- private final String mRemotePath;
- private final String mLocalFolderPath;
-
- /**
- * Constructor
- * @param remotePath Path of file on the server
- * @param localFolderPath Path of file on the device
- */
- public DownloadFileRemoteOperation(String remotePath, String localFolderPath) {
- mRemotePath = remotePath;
- mLocalFolderPath = localFolderPath;
- }
-
- @Override
- protected RemoteOperationResult run(OwnCloudClient client) {
- RemoteOperationResult result = null;
- /// download will be performed to a temporal file, then moved to the final location
- File tmpFile = new File(getTmpPath());
- /// perform the download
- try {
- File parentFile = tmpFile.getParentFile();
- if (parentFile == null) {
- Log.e(TAG, "getParentFile() returned null. Returning to prevent a NPE");
- return new RemoteOperationResult(RemoteOperationResult.ResultCode.UNKNOWN_ERROR);
- }
-
- parentFile.mkdirs();
- int status = downloadFile(client, tmpFile);
- result = new RemoteOperationResult(isSuccess(status), mGet);
- Log_OC.i(TAG, "Download of " + mRemotePath + " to " + getTmpPath() + ": " +
- result.getLogMessage());
-
- } catch (Exception e) {
- result = new RemoteOperationResult(e);
- Log_OC.e(TAG, "Download of " + mRemotePath + " to " + getTmpPath() + ": " +
- result.getLogMessage(), e);
- }
-
- return result;
- }
-
- private int downloadFile(OwnCloudClient client, File targetFile) throws IOException, OperationCancelledException {
- int status = -1;
- boolean savedFile = false;
- mGet = new GetMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath));
-
- FileOutputStream fos = null;
- try {
- status = client.executeMethod(mGet);
- if (isSuccess(status)) {
- targetFile.createNewFile();
- BufferedInputStream bis = new BufferedInputStream(mGet.getResponseBodyAsStream());
- fos = new FileOutputStream(targetFile);
- long transferred = 0;
-
- Header contentLength = mGet.getResponseHeader("Content-Length");
- long totalToTransfer = (contentLength != null &&
- contentLength.getValue().length() > 0) ?
- Long.parseLong(contentLength.getValue()) : 0;
-
- byte[] bytes = new byte[4096];
- int readResult = 0;
- while ((readResult = bis.read(bytes)) != -1) {
- synchronized (mCancellationRequested) {
- if (mCancellationRequested.get()) {
- mGet.abort();
- throw new OperationCancelledException();
- }
- }
- fos.write(bytes, 0, readResult);
- transferred += readResult;
- }
- // Check if the file is completed
- // if transfer-encoding: chunked we cannot check if the file is complete
- Header transferEncodingHeader = mGet.getResponseHeader("Transfer-Encoding");
- boolean transferEncoding = false;
-
- if (transferEncodingHeader != null) {
- transferEncoding = transferEncodingHeader.getValue().equals("chunked");
- }
-
- if (transferred == totalToTransfer || transferEncoding) {
- savedFile = true;
- Header modificationTime = mGet.getResponseHeader("Last-Modified");
- if (modificationTime == null) {
- modificationTime = mGet.getResponseHeader("last-modified");
- }
- if (modificationTime != null) {
- Date d = WebdavUtils.parseResponseDate(modificationTime.getValue());
- mModificationTimestamp = (d != null) ? d.getTime() : 0;
- } else {
- Log_OC.e(TAG, "Could not read modification time from response downloading " + mRemotePath);
- }
-
- mEtag = WebdavUtils.getEtagFromResponse(mGet);
- if (mEtag.length() == 0) {
- Log_OC.e(TAG, "Could not read eTag from response downloading " + mRemotePath);
- }
-
- } else {
- client.exhaustResponse(mGet.getResponseBodyAsStream());
- // TODO some kind of error control!
- }
- } else {
- client.exhaustResponse(mGet.getResponseBodyAsStream());
- }
- } catch (Exception e) {
- Log_OC.e(TAG, e.getMessage());
- } finally {
- if (fos != null) fos.close();
- if (!savedFile && targetFile.exists()) {
- targetFile.delete();
- }
- mGet.releaseConnection(); // let the connection available for other methods
- }
- return status;
- }
-
- private boolean isSuccess(int status) {
- return (status == HttpStatus.SC_OK);
- }
-
- /**
- * IMPLEMENTATION DIFFER FROM NC IMPLEMENTATION
- * @return
- */
- private String getTmpPath() {
- return mLocalFolderPath;
- }
-}
diff --git a/app/src/main/java/foundation/e/drive/operations/GetAliasOperation.java b/app/src/main/java/foundation/e/drive/operations/GetAliasOperation.java
index 23139360b4c22faf5f12a03a61d254ee690fe73b..c73473d076e443cf28b05907aa0021adabca18f7 100644
--- a/app/src/main/java/foundation/e/drive/operations/GetAliasOperation.java
+++ b/app/src/main/java/foundation/e/drive/operations/GetAliasOperation.java
@@ -17,12 +17,14 @@ import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import org.json.JSONArray;
+import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
/**
* @author TheScarastic
+ * /!\ Doesn't require NextcloudClient yet
*/
public class GetAliasOperation extends RemoteOperation {
@@ -34,7 +36,6 @@ public class GetAliasOperation extends RemoteOperation {
private static final String NODE_OCS = "ocs";
private static final String NODE_DATA = "data";
private static final String NODE_ALIASES = "aliases";
-
private final String mID;
private boolean isSuccess(int status) {
@@ -46,8 +47,8 @@ public class GetAliasOperation extends RemoteOperation {
}
@Override
- protected RemoteOperationResult run(OwnCloudClient client) {
- RemoteOperationResult result;
+ protected RemoteOperationResult> run(OwnCloudClient client) {
+ RemoteOperationResult> result;
GetMethod get = null;
final String uri = client.getBaseUri() + ALIAS_PATH + mID;
@@ -57,25 +58,26 @@ public class GetAliasOperation extends RemoteOperation {
get.setQueryString(new NameValuePair[]{new NameValuePair("format", "json")});
if (isSuccess(client.executeMethod(get))) {
- String response = get.getResponseBodyAsString();
+ final String response = get.getResponseBodyAsString();
// parse
- final JSONArray aliases = new JSONObject(response).getJSONObject(NODE_OCS)
- .getJSONObject(NODE_DATA).getJSONArray(NODE_ALIASES);
- final ArrayList