mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-30 19:26:24 +00:00
Compare commits
No commits in common. "8c2c76c747e0273189b16ea9ae917cff02d4d9ae" and "346fd7355a5f92b073c9cc21f3e56cfc0d5a7cec" have entirely different histories.
8c2c76c747
...
346fd7355a
@ -6,5 +6,5 @@ jobs:
|
|||||||
name: "Validation"
|
name: "Validation"
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- uses: gradle/wrapper-validation-action@v1
|
- uses: gradle/wrapper-validation-action@v1
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
buildscript {
|
buildscript {
|
||||||
ext {
|
ext {
|
||||||
kotlinVersion = '1.6.21'
|
kotlinVersion = '1.5.21'
|
||||||
moshiVersion = "1.13.0"
|
moshiVersion = "1.12.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
@ -10,8 +10,8 @@ buildscript {
|
|||||||
maven { url "https://plugins.gradle.org/m2/" }
|
maven { url "https://plugins.gradle.org/m2/" }
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath "org.jlleitschuh.gradle:ktlint-gradle:10.3.0"
|
classpath "org.jlleitschuh.gradle:ktlint-gradle:10.2.0"
|
||||||
classpath 'com.android.tools.build:gradle:7.1.3'
|
classpath 'com.android.tools.build:gradle:4.2.2'
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
check_license_in_file() {
|
|
||||||
if ! head -n 20 $FILE | grep -q "Permission is hereby granted, free of charge, to any person obtaining a copy"
|
|
||||||
then
|
|
||||||
echo "$FILE does not contain a current copyright header"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
for FILE in $(find owncloudComLibrary/src -name "*.java" -o -name "*.kt")
|
|
||||||
do
|
|
||||||
check_license_in_file
|
|
||||||
done
|
|
||||||
|
|
||||||
./gradlew ktlintFormat
|
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
257
gradlew
vendored
257
gradlew
vendored
@ -1,7 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
#
|
#
|
||||||
# Copyright © 2015-2021 the original authors.
|
# Copyright 2015 the original author or authors.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
@ -17,101 +17,67 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
##
|
||||||
# Gradle start up script for POSIX generated by Gradle.
|
## Gradle start up script for UN*X
|
||||||
#
|
##
|
||||||
# Important for running:
|
|
||||||
#
|
|
||||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
|
||||||
# noncompliant, but you have some other compliant shell such as ksh or
|
|
||||||
# bash, then to run this script, type that shell name before the whole
|
|
||||||
# command line, like:
|
|
||||||
#
|
|
||||||
# ksh Gradle
|
|
||||||
#
|
|
||||||
# Busybox and similar reduced shells will NOT work, because this script
|
|
||||||
# requires all of these POSIX shell features:
|
|
||||||
# * functions;
|
|
||||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
|
||||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
|
||||||
# * compound commands having a testable exit status, especially «case»;
|
|
||||||
# * various built-in commands including «command», «set», and «ulimit».
|
|
||||||
#
|
|
||||||
# Important for patching:
|
|
||||||
#
|
|
||||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
|
||||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
|
||||||
#
|
|
||||||
# The "traditional" practice of packing multiple parameters into a
|
|
||||||
# space-separated string is a well documented source of bugs and security
|
|
||||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
|
||||||
# options in "$@", and eventually passing that to Java.
|
|
||||||
#
|
|
||||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
|
||||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
|
||||||
# see the in-line comments for details.
|
|
||||||
#
|
|
||||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
|
||||||
# Darwin, MinGW, and NonStop.
|
|
||||||
#
|
|
||||||
# (3) This script is generated from the Groovy template
|
|
||||||
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
|
||||||
# within the Gradle project.
|
|
||||||
#
|
|
||||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
|
||||||
#
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
# Attempt to set APP_HOME
|
# Attempt to set APP_HOME
|
||||||
|
|
||||||
# Resolve links: $0 may be a link
|
# Resolve links: $0 may be a link
|
||||||
app_path=$0
|
PRG="$0"
|
||||||
|
# Need this for relative symlinks.
|
||||||
# Need this for daisy-chained symlinks.
|
while [ -h "$PRG" ] ; do
|
||||||
while
|
ls=`ls -ld "$PRG"`
|
||||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||||
[ -h "$app_path" ]
|
if expr "$link" : '/.*' > /dev/null; then
|
||||||
do
|
PRG="$link"
|
||||||
ls=$( ls -ld "$app_path" )
|
else
|
||||||
link=${ls#*' -> '}
|
PRG=`dirname "$PRG"`"/$link"
|
||||||
case $link in #(
|
fi
|
||||||
/*) app_path=$link ;; #(
|
|
||||||
*) app_path=$APP_HOME$link ;;
|
|
||||||
esac
|
|
||||||
done
|
done
|
||||||
|
SAVED="`pwd`"
|
||||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||||
|
APP_HOME="`pwd -P`"
|
||||||
|
cd "$SAVED" >/dev/null
|
||||||
|
|
||||||
APP_NAME="Gradle"
|
APP_NAME="Gradle"
|
||||||
APP_BASE_NAME=${0##*/}
|
APP_BASE_NAME=`basename "$0"`
|
||||||
|
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD=maximum
|
MAX_FD="maximum"
|
||||||
|
|
||||||
warn () {
|
warn () {
|
||||||
echo "$*"
|
echo "$*"
|
||||||
} >&2
|
}
|
||||||
|
|
||||||
die () {
|
die () {
|
||||||
echo
|
echo
|
||||||
echo "$*"
|
echo "$*"
|
||||||
echo
|
echo
|
||||||
exit 1
|
exit 1
|
||||||
} >&2
|
}
|
||||||
|
|
||||||
# OS specific support (must be 'true' or 'false').
|
# OS specific support (must be 'true' or 'false').
|
||||||
cygwin=false
|
cygwin=false
|
||||||
msys=false
|
msys=false
|
||||||
darwin=false
|
darwin=false
|
||||||
nonstop=false
|
nonstop=false
|
||||||
case "$( uname )" in #(
|
case "`uname`" in
|
||||||
CYGWIN* ) cygwin=true ;; #(
|
CYGWIN* )
|
||||||
Darwin* ) darwin=true ;; #(
|
cygwin=true
|
||||||
MSYS* | MINGW* ) msys=true ;; #(
|
;;
|
||||||
NONSTOP* ) nonstop=true ;;
|
Darwin* )
|
||||||
|
darwin=true
|
||||||
|
;;
|
||||||
|
MINGW* )
|
||||||
|
msys=true
|
||||||
|
;;
|
||||||
|
NONSTOP* )
|
||||||
|
nonstop=true
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||||
@ -121,9 +87,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
|||||||
if [ -n "$JAVA_HOME" ] ; then
|
if [ -n "$JAVA_HOME" ] ; then
|
||||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||||
# IBM's JDK on AIX uses strange locations for the executables
|
# IBM's JDK on AIX uses strange locations for the executables
|
||||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||||
else
|
else
|
||||||
JAVACMD=$JAVA_HOME/bin/java
|
JAVACMD="$JAVA_HOME/bin/java"
|
||||||
fi
|
fi
|
||||||
if [ ! -x "$JAVACMD" ] ; then
|
if [ ! -x "$JAVACMD" ] ; then
|
||||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||||
@ -132,7 +98,7 @@ Please set the JAVA_HOME variable in your environment to match the
|
|||||||
location of your Java installation."
|
location of your Java installation."
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
JAVACMD=java
|
JAVACMD="java"
|
||||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
@ -140,95 +106,80 @@ location of your Java installation."
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Increase the maximum file descriptors if we can.
|
# Increase the maximum file descriptors if we can.
|
||||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||||
case $MAX_FD in #(
|
MAX_FD_LIMIT=`ulimit -H -n`
|
||||||
max*)
|
if [ $? -eq 0 ] ; then
|
||||||
MAX_FD=$( ulimit -H -n ) ||
|
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||||
warn "Could not query maximum file descriptor limit"
|
MAX_FD="$MAX_FD_LIMIT"
|
||||||
esac
|
fi
|
||||||
case $MAX_FD in #(
|
ulimit -n $MAX_FD
|
||||||
'' | soft) :;; #(
|
if [ $? -ne 0 ] ; then
|
||||||
*)
|
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||||
ulimit -n "$MAX_FD" ||
|
fi
|
||||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
else
|
||||||
esac
|
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Collect all arguments for the java command, stacking in reverse order:
|
# For Darwin, add options to specify how the application appears in the dock
|
||||||
# * args from the command line
|
if $darwin; then
|
||||||
# * the main class name
|
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||||
# * -classpath
|
fi
|
||||||
# * -D...appname settings
|
|
||||||
# * --module-path (only if needed)
|
|
||||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
|
||||||
|
|
||||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||||
if "$cygwin" || "$msys" ; then
|
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
||||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||||
|
|
||||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||||
|
|
||||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
# We build the pattern for arguments to be converted via cygpath
|
||||||
for arg do
|
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||||
if
|
SEP=""
|
||||||
case $arg in #(
|
for dir in $ROOTDIRSRAW ; do
|
||||||
-*) false ;; # don't mess with options #(
|
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
SEP="|"
|
||||||
[ -e "$t" ] ;; #(
|
|
||||||
*) false ;;
|
|
||||||
esac
|
|
||||||
then
|
|
||||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
|
||||||
fi
|
|
||||||
# Roll the args list around exactly as many times as the number of
|
|
||||||
# args, so each arg winds up back in the position where it started, but
|
|
||||||
# possibly modified.
|
|
||||||
#
|
|
||||||
# NB: a `for` loop captures its iteration list before it begins, so
|
|
||||||
# changing the positional parameters here affects neither the number of
|
|
||||||
# iterations, nor the values presented in `arg`.
|
|
||||||
shift # remove old arg
|
|
||||||
set -- "$@" "$arg" # push replacement arg
|
|
||||||
done
|
done
|
||||||
|
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||||
|
# Add a user-defined pattern to the cygpath arguments
|
||||||
|
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||||
|
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||||
|
fi
|
||||||
|
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||||
|
i=0
|
||||||
|
for arg in "$@" ; do
|
||||||
|
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||||
|
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||||
|
|
||||||
|
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||||
|
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||||
|
else
|
||||||
|
eval `echo args$i`="\"$arg\""
|
||||||
|
fi
|
||||||
|
i=`expr $i + 1`
|
||||||
|
done
|
||||||
|
case $i in
|
||||||
|
0) set -- ;;
|
||||||
|
1) set -- "$args0" ;;
|
||||||
|
2) set -- "$args0" "$args1" ;;
|
||||||
|
3) set -- "$args0" "$args1" "$args2" ;;
|
||||||
|
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||||
|
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||||
|
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||||
|
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||||
|
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||||
|
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||||
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Collect all arguments for the java command;
|
# Escape application args
|
||||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
save () {
|
||||||
# shell script including quotes and variable substitutions, so put them in
|
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||||
# double quotes to make sure that they get re-expanded; and
|
echo " "
|
||||||
# * put everything else in single quotes, so that it's not re-expanded.
|
}
|
||||||
|
APP_ARGS=`save "$@"`
|
||||||
|
|
||||||
set -- \
|
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||||
-classpath "$CLASSPATH" \
|
|
||||||
org.gradle.wrapper.GradleWrapperMain \
|
|
||||||
"$@"
|
|
||||||
|
|
||||||
# Use "xargs" to parse quoted args.
|
|
||||||
#
|
|
||||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
|
||||||
#
|
|
||||||
# In Bash we could simply go:
|
|
||||||
#
|
|
||||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
|
||||||
# set -- "${ARGS[@]}" "$@"
|
|
||||||
#
|
|
||||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
|
||||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
|
||||||
# character that might be a shell metacharacter, then use eval to reverse
|
|
||||||
# that process (while maintaining the separation between arguments), and wrap
|
|
||||||
# the whole thing up as a single "set" statement.
|
|
||||||
#
|
|
||||||
# This will of course break if any of these variables contains a newline or
|
|
||||||
# an unmatched quote.
|
|
||||||
#
|
|
||||||
|
|
||||||
eval "set -- $(
|
|
||||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
|
||||||
xargs -n1 |
|
|
||||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
|
||||||
tr '\n' ' '
|
|
||||||
)" '"$@"'
|
|
||||||
|
|
||||||
exec "$JAVACMD" "$@"
|
exec "$JAVACMD" "$@"
|
||||||
|
@ -12,27 +12,33 @@ dependencies {
|
|||||||
implementation("com.squareup.moshi:moshi-kotlin:$moshiVersion") {
|
implementation("com.squareup.moshi:moshi-kotlin:$moshiVersion") {
|
||||||
exclude module: "kotlin-reflect"
|
exclude module: "kotlin-reflect"
|
||||||
}
|
}
|
||||||
implementation 'org.apache.commons:commons-lang3:3.12.0'
|
|
||||||
kapt "com.squareup.moshi:moshi-kotlin-codegen:$moshiVersion"
|
kapt "com.squareup.moshi:moshi-kotlin-codegen:$moshiVersion"
|
||||||
|
|
||||||
testImplementation 'junit:junit:4.13.2'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
testImplementation 'org.robolectric:robolectric:4.8.1'
|
testImplementation 'org.robolectric:robolectric:4.5.1'
|
||||||
debugImplementation 'com.facebook.stetho:stetho-okhttp3:1.6.0'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 31
|
compileSdkVersion 30
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 31
|
targetSdkVersion 30
|
||||||
|
|
||||||
|
versionCode = 10001300
|
||||||
|
versionName = "1.0.13"
|
||||||
}
|
}
|
||||||
|
|
||||||
lint {
|
lintOptions {
|
||||||
abortOnError false
|
abortOnError false
|
||||||
ignoreWarnings true
|
ignoreWarnings true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
compileOptions {
|
||||||
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
|
targetCompatibility JavaVersion.VERSION_1_8
|
||||||
|
}
|
||||||
|
|
||||||
testOptions {
|
testOptions {
|
||||||
unitTests {
|
unitTests {
|
||||||
includeAndroidResources = true
|
includeAndroidResources = true
|
||||||
|
@ -1,215 +0,0 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
|
||||||
* Copyright (C) 2016 ownCloud GmbH.
|
|
||||||
*
|
|
||||||
* 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 com.owncloud.android.lib.common
|
|
||||||
|
|
||||||
import android.accounts.AccountManager
|
|
||||||
import android.accounts.AccountsException
|
|
||||||
import android.content.Context
|
|
||||||
import com.owncloud.android.lib.common.authentication.OwnCloudCredentials
|
|
||||||
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials
|
|
||||||
import com.owncloud.android.lib.common.http.HttpConstants
|
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
|
||||||
import com.owncloud.android.lib.resources.files.CheckPathExistenceRemoteOperation
|
|
||||||
import com.owncloud.android.lib.resources.status.GetRemoteStatusOperation
|
|
||||||
import com.owncloud.android.lib.resources.status.RemoteServerInfo
|
|
||||||
import org.apache.commons.lang3.exception.ExceptionUtils
|
|
||||||
import timber.log.Timber
|
|
||||||
import java.io.IOException
|
|
||||||
import java.lang.Exception
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ConnectionValidator
|
|
||||||
*
|
|
||||||
* @author Christian Schabesberger
|
|
||||||
*/
|
|
||||||
class ConnectionValidator(
|
|
||||||
val context: Context,
|
|
||||||
val clearCookiesOnValidation: Boolean
|
|
||||||
) {
|
|
||||||
fun validate(baseClient: OwnCloudClient, singleSessionManager: SingleSessionManager, context: Context): Boolean {
|
|
||||||
try {
|
|
||||||
var validationRetryCount = 0
|
|
||||||
val client = OwnCloudClient(baseClient.baseUri, null, false, singleSessionManager, context)
|
|
||||||
if (clearCookiesOnValidation) {
|
|
||||||
client.clearCookies()
|
|
||||||
} else {
|
|
||||||
client.cookiesForBaseUri = baseClient.cookiesForBaseUri
|
|
||||||
}
|
|
||||||
|
|
||||||
client.account = baseClient.account
|
|
||||||
client.credentials = baseClient.credentials
|
|
||||||
while (validationRetryCount < VALIDATION_RETRY_COUNT) {
|
|
||||||
Timber.d("validationRetryCout %d", validationRetryCount)
|
|
||||||
var successCounter = 0
|
|
||||||
var failCounter = 0
|
|
||||||
|
|
||||||
client.setFollowRedirects(true)
|
|
||||||
if (isOnwCloudStatusOk(client)) {
|
|
||||||
successCounter++
|
|
||||||
} else {
|
|
||||||
failCounter++
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip the part where we try to check if we can access the parts where we have to be logged in... if we are not logged in
|
|
||||||
if (baseClient.credentials !is OwnCloudAnonymousCredentials) {
|
|
||||||
client.setFollowRedirects(false)
|
|
||||||
val contentReply = canAccessRootFolder(client)
|
|
||||||
if (contentReply.httpCode == HttpConstants.HTTP_OK) {
|
|
||||||
if (contentReply.data == true) { //if data is true it means that the content reply was ok
|
|
||||||
successCounter++
|
|
||||||
} else {
|
|
||||||
failCounter++
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
failCounter++
|
|
||||||
if (contentReply.httpCode == HttpConstants.HTTP_UNAUTHORIZED) {
|
|
||||||
checkUnauthorizedAccess(client, singleSessionManager, contentReply.httpCode)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (successCounter >= failCounter) {
|
|
||||||
baseClient.credentials = client.credentials
|
|
||||||
baseClient.cookiesForBaseUri = client.cookiesForBaseUri
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
validationRetryCount++
|
|
||||||
}
|
|
||||||
Timber.d("Could not authenticate or get valid data from owncloud")
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Timber.d(ExceptionUtils.getStackTrace(e))
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun isOnwCloudStatusOk(client: OwnCloudClient): Boolean {
|
|
||||||
val reply = getOwnCloudStatus(client)
|
|
||||||
// dont check status code. It currently relais on the broken redirect code of the owncloud client
|
|
||||||
// TODO: Use okhttp redirect and add this check again
|
|
||||||
// return reply.httpCode == HttpConstants.HTTP_OK &&
|
|
||||||
return !reply.isException &&
|
|
||||||
reply.data != null
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getOwnCloudStatus(client: OwnCloudClient): RemoteOperationResult<RemoteServerInfo> {
|
|
||||||
val remoteStatusOperation = GetRemoteStatusOperation()
|
|
||||||
return remoteStatusOperation.execute(client)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun canAccessRootFolder(client: OwnCloudClient): RemoteOperationResult<Boolean> {
|
|
||||||
val checkPathExistenceRemoteOperation = CheckPathExistenceRemoteOperation("/", true)
|
|
||||||
return checkPathExistenceRemoteOperation.execute(client)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines if credentials should be invalidated according the to the HTTPS status
|
|
||||||
* of a network request just performed.
|
|
||||||
*
|
|
||||||
* @param httpStatusCode Result of the last request ran with the 'credentials' belows.
|
|
||||||
* @return 'True' if credentials should and might be invalidated, 'false' if shouldn't or
|
|
||||||
* cannot be invalidated with the given arguments.
|
|
||||||
*/
|
|
||||||
private fun shouldInvalidateAccountCredentials(credentials: OwnCloudCredentials, account: OwnCloudAccount, httpStatusCode: Int): Boolean {
|
|
||||||
var shouldInvalidateAccountCredentials = httpStatusCode == HttpConstants.HTTP_UNAUTHORIZED
|
|
||||||
shouldInvalidateAccountCredentials = shouldInvalidateAccountCredentials and // real credentials
|
|
||||||
(credentials !is OwnCloudAnonymousCredentials)
|
|
||||||
|
|
||||||
// test if have all the needed to effectively invalidate ...
|
|
||||||
shouldInvalidateAccountCredentials =
|
|
||||||
shouldInvalidateAccountCredentials and (account.savedAccount != null)
|
|
||||||
return shouldInvalidateAccountCredentials
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Invalidates credentials stored for the given account in the system [AccountManager] and in
|
|
||||||
* current [SingleSessionManager.getDefaultSingleton] instance.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* [.shouldInvalidateAccountCredentials] should be called first.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private fun invalidateAccountCredentials(account: OwnCloudAccount, credentials: OwnCloudCredentials) {
|
|
||||||
val am = AccountManager.get(context)
|
|
||||||
am.invalidateAuthToken(
|
|
||||||
account.savedAccount.type,
|
|
||||||
credentials.authToken
|
|
||||||
)
|
|
||||||
am.clearPassword(account.savedAccount) // being strict, only needed for Basic Auth credentials
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks the status code of an execution and decides if should be repeated with fresh credentials.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* Invalidates current credentials if the request failed as anauthorized.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* Refresh current credentials if possible, and marks a retry.
|
|
||||||
*
|
|
||||||
* @param status
|
|
||||||
* @param repeatCounter
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private fun checkUnauthorizedAccess(client: OwnCloudClient, singleSessionManager: SingleSessionManager, status: Int): Boolean {
|
|
||||||
var credentialsWereRefreshed = false
|
|
||||||
val account = client.account
|
|
||||||
val credentials = account.credentials
|
|
||||||
if (shouldInvalidateAccountCredentials(credentials, account, status)) {
|
|
||||||
invalidateAccountCredentials(account, credentials)
|
|
||||||
|
|
||||||
if (credentials.authTokenCanBeRefreshed()) {
|
|
||||||
try {
|
|
||||||
// This command does the actual refresh
|
|
||||||
account.loadCredentials(context)
|
|
||||||
// if mAccount.getCredentials().length() == 0 --> refresh failed
|
|
||||||
client.credentials = account.credentials
|
|
||||||
credentialsWereRefreshed = true
|
|
||||||
} catch (e: AccountsException) {
|
|
||||||
Timber.e(
|
|
||||||
e, "Error while trying to refresh auth token for %s\ntrace: %s",
|
|
||||||
account.savedAccount.name,
|
|
||||||
ExceptionUtils.getStackTrace(e)
|
|
||||||
)
|
|
||||||
} catch (e: IOException) {
|
|
||||||
Timber.e(
|
|
||||||
e, "Error while trying to refresh auth token for %s\ntrace: %s",
|
|
||||||
account.savedAccount.name,
|
|
||||||
ExceptionUtils.getStackTrace(e)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if (!credentialsWereRefreshed) {
|
|
||||||
// if credentials are not refreshed, client must be removed
|
|
||||||
// from the OwnCloudClientManager to prevent it is reused once and again
|
|
||||||
singleSessionManager.removeClientFor(account)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// else: onExecute will finish with status 401
|
|
||||||
}
|
|
||||||
return credentialsWereRefreshed
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
private val VALIDATION_RETRY_COUNT = 3
|
|
||||||
}
|
|
||||||
}
|
|
@ -25,9 +25,11 @@
|
|||||||
|
|
||||||
package com.owncloud.android.lib.common;
|
package com.owncloud.android.lib.common;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.accounts.AccountManager;
|
||||||
|
import android.accounts.AccountsException;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
|
import at.bitfire.dav4jvm.exception.HttpException;
|
||||||
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
||||||
import com.owncloud.android.lib.common.authentication.OwnCloudCredentials;
|
import com.owncloud.android.lib.common.authentication.OwnCloudCredentials;
|
||||||
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory;
|
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory;
|
||||||
@ -35,6 +37,7 @@ import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory
|
|||||||
import com.owncloud.android.lib.common.http.HttpClient;
|
import com.owncloud.android.lib.common.http.HttpClient;
|
||||||
import com.owncloud.android.lib.common.http.HttpConstants;
|
import com.owncloud.android.lib.common.http.HttpConstants;
|
||||||
import com.owncloud.android.lib.common.http.methods.HttpBaseMethod;
|
import com.owncloud.android.lib.common.http.methods.HttpBaseMethod;
|
||||||
|
import com.owncloud.android.lib.common.network.RedirectionPath;
|
||||||
import com.owncloud.android.lib.common.utils.RandomUtils;
|
import com.owncloud.android.lib.common.utils.RandomUtils;
|
||||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
||||||
import okhttp3.Cookie;
|
import okhttp3.Cookie;
|
||||||
@ -46,54 +49,40 @@ import java.io.InputStream;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.owncloud.android.lib.common.http.HttpConstants.AUTHORIZATION_HEADER;
|
import static com.owncloud.android.lib.common.http.HttpConstants.AUTHORIZATION_HEADER;
|
||||||
import static com.owncloud.android.lib.common.http.HttpConstants.HTTP_MOVED_PERMANENTLY;
|
import static com.owncloud.android.lib.common.http.HttpConstants.OC_X_REQUEST_ID;
|
||||||
|
|
||||||
public class OwnCloudClient extends HttpClient {
|
public class OwnCloudClient extends HttpClient {
|
||||||
|
|
||||||
public static final String WEBDAV_FILES_PATH_4_0 = "/remote.php/dav/files/";
|
public static final String WEBDAV_FILES_PATH_4_0 = "/remote.php/dav/files/";
|
||||||
|
public static final String WEBDAV_PATH_4_0_AND_LATER = "/remote.php/dav";
|
||||||
public static final String STATUS_PATH = "/status.php";
|
public static final String STATUS_PATH = "/status.php";
|
||||||
private static final String WEBDAV_UPLOADS_PATH_4_0 = "/remote.php/dav/uploads/";
|
private static final String WEBDAV_UPLOADS_PATH_4_0 = "/remote.php/dav/uploads/";
|
||||||
private static final int MAX_RETRY_COUNT = 2;
|
private static final int MAX_REDIRECTIONS_COUNT = 3;
|
||||||
|
private static final int MAX_REPEAT_COUNT_WITH_FRESH_CREDENTIALS = 1;
|
||||||
|
|
||||||
|
private static byte[] sExhaustBuffer = new byte[1024];
|
||||||
private static int sIntanceCounter = 0;
|
private static int sIntanceCounter = 0;
|
||||||
private OwnCloudCredentials mCredentials = null;
|
private OwnCloudCredentials mCredentials = null;
|
||||||
private int mInstanceNumber;
|
private int mInstanceNumber;
|
||||||
private Uri mBaseUri;
|
private Uri mBaseUri;
|
||||||
private OwnCloudVersion mVersion = null;
|
private OwnCloudVersion mVersion = null;
|
||||||
private OwnCloudAccount mAccount;
|
private OwnCloudAccount mAccount;
|
||||||
private final ConnectionValidator mConnectionValidator;
|
|
||||||
private Object mRequestMutex = new Object();
|
|
||||||
|
|
||||||
// If set to true a mutex will be used to prevent parallel execution of the execute() method
|
|
||||||
// if false the execute() method can be called even though the mutex is already aquired.
|
|
||||||
// This is used for the ConnectionValidator, which has to be able to execute OperationsWhile all "normal" operations net
|
|
||||||
// to be set on hold.
|
|
||||||
private final Boolean mSynchronizeRequests;
|
|
||||||
|
|
||||||
private SingleSessionManager mSingleSessionManager = null;
|
private SingleSessionManager mSingleSessionManager = null;
|
||||||
|
|
||||||
private boolean mFollowRedirects = false;
|
private boolean mFollowRedirects;
|
||||||
|
|
||||||
public OwnCloudClient(Uri baseUri,
|
|
||||||
ConnectionValidator connectionValidator,
|
|
||||||
boolean synchronizeRequests,
|
|
||||||
SingleSessionManager singleSessionManager,
|
|
||||||
Context context) {
|
|
||||||
super(context);
|
|
||||||
|
|
||||||
|
public OwnCloudClient(Uri baseUri) {
|
||||||
if (baseUri == null) {
|
if (baseUri == null) {
|
||||||
throw new IllegalArgumentException("Parameter 'baseUri' cannot be NULL");
|
throw new IllegalArgumentException("Parameter 'baseUri' cannot be NULL");
|
||||||
}
|
}
|
||||||
mBaseUri = baseUri;
|
mBaseUri = baseUri;
|
||||||
mSynchronizeRequests = synchronizeRequests;
|
|
||||||
mSingleSessionManager = singleSessionManager;
|
|
||||||
|
|
||||||
mInstanceNumber = sIntanceCounter++;
|
mInstanceNumber = sIntanceCounter++;
|
||||||
Timber.d("#" + mInstanceNumber + "Creating OwnCloudClient");
|
Timber.d("#" + mInstanceNumber + "Creating OwnCloudClient");
|
||||||
|
|
||||||
clearCredentials();
|
clearCredentials();
|
||||||
clearCookies();
|
clearCookies();
|
||||||
mConnectionValidator = connectionValidator;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearCredentials() {
|
public void clearCredentials() {
|
||||||
@ -103,27 +92,11 @@ public class OwnCloudClient extends HttpClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int executeHttpMethod(HttpBaseMethod method) throws Exception {
|
public int executeHttpMethod(HttpBaseMethod method) throws Exception {
|
||||||
if (mSynchronizeRequests) {
|
boolean repeatWithFreshCredentials;
|
||||||
synchronized (mRequestMutex) {
|
|
||||||
return saveExecuteHttpMethod(method);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return saveExecuteHttpMethod(method);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private int saveExecuteHttpMethod(HttpBaseMethod method) throws Exception {
|
|
||||||
int repeatCounter = 0;
|
int repeatCounter = 0;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
if (mFollowRedirects) {
|
|
||||||
method.setFollowRedirects(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean retry;
|
|
||||||
do {
|
do {
|
||||||
repeatCounter++;
|
|
||||||
retry = false;
|
|
||||||
String requestId = RandomUtils.generateRandomUUID();
|
String requestId = RandomUtils.generateRandomUUID();
|
||||||
|
|
||||||
// Header to allow tracing requests in apache and ownCloud logs
|
// Header to allow tracing requests in apache and ownCloud logs
|
||||||
@ -131,34 +104,105 @@ public class OwnCloudClient extends HttpClient {
|
|||||||
method.setRequestHeader(HttpConstants.OC_X_REQUEST_ID, requestId);
|
method.setRequestHeader(HttpConstants.OC_X_REQUEST_ID, requestId);
|
||||||
method.setRequestHeader(HttpConstants.USER_AGENT_HEADER, SingleSessionManager.getUserAgent());
|
method.setRequestHeader(HttpConstants.USER_AGENT_HEADER, SingleSessionManager.getUserAgent());
|
||||||
method.setRequestHeader(HttpConstants.ACCEPT_ENCODING_HEADER, HttpConstants.ACCEPT_ENCODING_IDENTITY);
|
method.setRequestHeader(HttpConstants.ACCEPT_ENCODING_HEADER, HttpConstants.ACCEPT_ENCODING_IDENTITY);
|
||||||
if (mCredentials.getHeaderAuth() != null && !mCredentials.getHeaderAuth().isEmpty()) {
|
if (mCredentials.getHeaderAuth() != null && method.getRequestHeader(AUTHORIZATION_HEADER) == null) {
|
||||||
method.setRequestHeader(AUTHORIZATION_HEADER, mCredentials.getHeaderAuth());
|
method.setRequestHeader(AUTHORIZATION_HEADER, mCredentials.getHeaderAuth());
|
||||||
}
|
}
|
||||||
|
status = method.execute();
|
||||||
|
|
||||||
status = method.execute(this);
|
if (mFollowRedirects) {
|
||||||
|
status = followRedirection(method).getLastStatus();
|
||||||
if (shouldConnectionValidatorBeCalled(method, status)) {
|
|
||||||
retry = mConnectionValidator.validate(this, mSingleSessionManager, getContext()); // retry on success fail on no success
|
|
||||||
} else if (method.getFollowPermanentRedirects() && status == HTTP_MOVED_PERMANENTLY) {
|
|
||||||
retry = true;
|
|
||||||
method.setFollowRedirects(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} while (retry && repeatCounter < MAX_RETRY_COUNT);
|
repeatWithFreshCredentials = checkUnauthorizedAccess(status, repeatCounter);
|
||||||
|
if (repeatWithFreshCredentials) {
|
||||||
|
repeatCounter++;
|
||||||
|
}
|
||||||
|
} while (repeatWithFreshCredentials);
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean shouldConnectionValidatorBeCalled(HttpBaseMethod method, int status) {
|
private int executeRedirectedHttpMethod(HttpBaseMethod method) throws Exception {
|
||||||
|
boolean repeatWithFreshCredentials;
|
||||||
|
int repeatCounter = 0;
|
||||||
|
int status;
|
||||||
|
|
||||||
return mConnectionValidator != null && (
|
do {
|
||||||
(!(mCredentials instanceof OwnCloudAnonymousCredentials) &&
|
String requestId = RandomUtils.generateRandomUUID();
|
||||||
status == HttpConstants.HTTP_UNAUTHORIZED
|
|
||||||
) || (!mFollowRedirects &&
|
// Header to allow tracing requests in apache and ownCloud logs
|
||||||
!method.getFollowRedirects() &&
|
Timber.d("Executing in request with id %s", requestId);
|
||||||
status == HttpConstants.HTTP_MOVED_TEMPORARILY
|
method.setRequestHeader(OC_X_REQUEST_ID, requestId);
|
||||||
)
|
method.setRequestHeader(HttpConstants.USER_AGENT_HEADER, SingleSessionManager.getUserAgent());
|
||||||
);
|
method.setRequestHeader(HttpConstants.ACCEPT_ENCODING_HEADER, HttpConstants.ACCEPT_ENCODING_IDENTITY);
|
||||||
|
if (mCredentials.getHeaderAuth() != null) {
|
||||||
|
method.setRequestHeader(AUTHORIZATION_HEADER, mCredentials.getHeaderAuth());
|
||||||
|
}
|
||||||
|
status = method.execute();
|
||||||
|
|
||||||
|
repeatWithFreshCredentials = checkUnauthorizedAccess(status, repeatCounter);
|
||||||
|
if (repeatWithFreshCredentials) {
|
||||||
|
repeatCounter++;
|
||||||
|
}
|
||||||
|
} while (repeatWithFreshCredentials);
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RedirectionPath followRedirection(HttpBaseMethod method) throws Exception {
|
||||||
|
int redirectionsCount = 0;
|
||||||
|
int status = method.getStatusCode();
|
||||||
|
RedirectionPath redirectionPath = new RedirectionPath(status, MAX_REDIRECTIONS_COUNT);
|
||||||
|
|
||||||
|
while (redirectionsCount < MAX_REDIRECTIONS_COUNT &&
|
||||||
|
(status == HttpConstants.HTTP_MOVED_PERMANENTLY ||
|
||||||
|
status == HttpConstants.HTTP_MOVED_TEMPORARILY ||
|
||||||
|
status == HttpConstants.HTTP_TEMPORARY_REDIRECT)
|
||||||
|
) {
|
||||||
|
|
||||||
|
final String location = method.getResponseHeader(HttpConstants.LOCATION_HEADER) != null
|
||||||
|
? method.getResponseHeader(HttpConstants.LOCATION_HEADER)
|
||||||
|
: method.getResponseHeader(HttpConstants.LOCATION_HEADER_LOWER);
|
||||||
|
|
||||||
|
if (location != null) {
|
||||||
|
Timber.d("#" + mInstanceNumber + "Location to redirect: " + location);
|
||||||
|
|
||||||
|
redirectionPath.addLocation(location);
|
||||||
|
|
||||||
|
// Release the connection to avoid reach the max number of connections per host
|
||||||
|
// due to it will be set a different url
|
||||||
|
exhaustResponse(method.getResponseBodyAsStream());
|
||||||
|
|
||||||
|
method.setUrl(HttpUrl.parse(location));
|
||||||
|
final String destination = method.getRequestHeader("Destination") != null
|
||||||
|
? method.getRequestHeader("Destination")
|
||||||
|
: method.getRequestHeader("destination");
|
||||||
|
|
||||||
|
if (destination != null) {
|
||||||
|
final int suffixIndex = location.lastIndexOf(getUserFilesWebDavUri().toString());
|
||||||
|
final String redirectionBase = location.substring(0, suffixIndex);
|
||||||
|
final String destinationPath = destination.substring(mBaseUri.toString().length());
|
||||||
|
|
||||||
|
method.setRequestHeader("destination", redirectionBase + destinationPath);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
status = executeRedirectedHttpMethod(method);
|
||||||
|
} catch (HttpException e) {
|
||||||
|
if (e.getMessage().contains(Integer.toString(HttpConstants.HTTP_MOVED_TEMPORARILY))) {
|
||||||
|
status = HttpConstants.HTTP_MOVED_TEMPORARILY;
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
redirectionPath.addStatus(status);
|
||||||
|
redirectionsCount++;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
Timber.d(" #" + mInstanceNumber + "No location to redirect!");
|
||||||
|
status = HttpConstants.HTTP_NOT_FOUND;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return redirectionPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -229,16 +273,24 @@ public class OwnCloudClient extends HttpClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCookiesForBaseUri(List<Cookie> cookies) {
|
public String getCookiesString() {
|
||||||
getOkHttpClient().cookieJar().saveFromResponse(
|
StringBuilder cookiesString = new StringBuilder();
|
||||||
HttpUrl.parse(mBaseUri.toString()),
|
List<Cookie> cookieList = getCookiesFromUrl(HttpUrl.parse(mBaseUri.toString()));
|
||||||
cookies
|
|
||||||
);
|
if (cookieList != null) {
|
||||||
|
for (Cookie cookie : cookieList) {
|
||||||
|
cookiesString.append(cookie.toString()).append(";");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return cookiesString.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Cookie> getCookiesForBaseUri() {
|
public void setCookiesForCurrentAccount(List<Cookie> cookies) {
|
||||||
return getOkHttpClient().cookieJar().loadForRequest(
|
getOkHttpClient().cookieJar().saveFromResponse(
|
||||||
HttpUrl.parse(mBaseUri.toString()));
|
HttpUrl.parse(getAccount().getBaseUri().toString()),
|
||||||
|
cookies
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public OwnCloudVersion getOwnCloudVersion() {
|
public OwnCloudVersion getOwnCloudVersion() {
|
||||||
@ -257,7 +309,95 @@ public class OwnCloudClient extends HttpClient {
|
|||||||
this.mAccount = account;
|
this.mAccount = account;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks the status code of an execution and decides if should be repeated with fresh credentials.
|
||||||
|
* <p>
|
||||||
|
* Invalidates current credentials if the request failed as anauthorized.
|
||||||
|
* <p>
|
||||||
|
* Refresh current credentials if possible, and marks a retry.
|
||||||
|
*
|
||||||
|
* @param status
|
||||||
|
* @param repeatCounter
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean checkUnauthorizedAccess(int status, int repeatCounter) {
|
||||||
|
boolean credentialsWereRefreshed = false;
|
||||||
|
|
||||||
|
if (shouldInvalidateAccountCredentials(status)) {
|
||||||
|
boolean invalidated = invalidateAccountCredentials();
|
||||||
|
|
||||||
|
if (invalidated) {
|
||||||
|
if (getCredentials().authTokenCanBeRefreshed() &&
|
||||||
|
repeatCounter < MAX_REPEAT_COUNT_WITH_FRESH_CREDENTIALS) {
|
||||||
|
try {
|
||||||
|
mAccount.loadCredentials(getContext());
|
||||||
|
// if mAccount.getCredentials().length() == 0 --> refresh failed
|
||||||
|
setCredentials(mAccount.getCredentials());
|
||||||
|
credentialsWereRefreshed = true;
|
||||||
|
|
||||||
|
} catch (AccountsException | IOException e) {
|
||||||
|
Timber.e(e, "Error while trying to refresh auth token for %s",
|
||||||
|
mAccount.getSavedAccount().name
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!credentialsWereRefreshed && mSingleSessionManager != null) {
|
||||||
|
// if credentials are not refreshed, client must be removed
|
||||||
|
// from the OwnCloudClientManager to prevent it is reused once and again
|
||||||
|
mSingleSessionManager.removeClientFor(mAccount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// else: onExecute will finish with status 401
|
||||||
|
}
|
||||||
|
|
||||||
|
return credentialsWereRefreshed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if credentials should be invalidated according the to the HTTPS status
|
||||||
|
* of a network request just performed.
|
||||||
|
*
|
||||||
|
* @param httpStatusCode Result of the last request ran with the 'credentials' belows.
|
||||||
|
* @return 'True' if credentials should and might be invalidated, 'false' if shouldn't or
|
||||||
|
* cannot be invalidated with the given arguments.
|
||||||
|
*/
|
||||||
|
private boolean shouldInvalidateAccountCredentials(int httpStatusCode) {
|
||||||
|
boolean shouldInvalidateAccountCredentials =
|
||||||
|
(httpStatusCode == HttpConstants.HTTP_UNAUTHORIZED);
|
||||||
|
|
||||||
|
shouldInvalidateAccountCredentials &= (mCredentials != null && // real credentials
|
||||||
|
!(mCredentials instanceof OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials));
|
||||||
|
|
||||||
|
// test if have all the needed to effectively invalidate ...
|
||||||
|
shouldInvalidateAccountCredentials &= (mAccount != null && mAccount.getSavedAccount() != null && getContext() != null);
|
||||||
|
|
||||||
|
return shouldInvalidateAccountCredentials;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invalidates credentials stored for the given account in the system {@link AccountManager} and in
|
||||||
|
* current {@link SingleSessionManager#getDefaultSingleton()} instance.
|
||||||
|
* <p>
|
||||||
|
* {@link #shouldInvalidateAccountCredentials(int)} should be called first.
|
||||||
|
*
|
||||||
|
* @return 'True' if invalidation was successful, 'false' otherwise.
|
||||||
|
*/
|
||||||
|
private boolean invalidateAccountCredentials() {
|
||||||
|
AccountManager am = AccountManager.get(getContext());
|
||||||
|
am.invalidateAuthToken(
|
||||||
|
mAccount.getSavedAccount().type,
|
||||||
|
mCredentials.getAuthToken()
|
||||||
|
);
|
||||||
|
am.clearPassword(mAccount.getSavedAccount()); // being strict, only needed for Basic Auth credentials
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean followRedirects() {
|
||||||
|
return mFollowRedirects;
|
||||||
|
}
|
||||||
|
|
||||||
public void setFollowRedirects(boolean followRedirects) {
|
public void setFollowRedirects(boolean followRedirects) {
|
||||||
this.mFollowRedirects = followRedirects;
|
this.mFollowRedirects = followRedirects;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,12 +19,40 @@
|
|||||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.owncloud.android.lib.common.http
|
package com.owncloud.android.lib.common;
|
||||||
|
|
||||||
import com.facebook.stetho.okhttp3.StethoInterceptor
|
import android.content.Context;
|
||||||
|
import android.net.Uri;
|
||||||
|
|
||||||
object DebugInterceptorFactory {
|
import com.owncloud.android.lib.common.http.HttpClient;
|
||||||
fun getInterceptor() = StethoInterceptor()
|
import com.owncloud.android.lib.resources.status.GetRemoteStatusOperation;
|
||||||
|
|
||||||
|
public class OwnCloudClientFactory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a OwnCloudClient to access a URL and sets the desired parameters for ownCloud
|
||||||
|
* client connections.
|
||||||
|
*
|
||||||
|
* @param uri URL to the ownCloud server; BASE ENTRY POINT, not WebDavPATH
|
||||||
|
* @param context Android context where the OwnCloudClient is being created.
|
||||||
|
* @return A OwnCloudClient object ready to be used
|
||||||
|
*/
|
||||||
|
public static OwnCloudClient createOwnCloudClient(Uri uri, Context context, boolean followRedirects) {
|
||||||
|
OwnCloudClient client = new OwnCloudClient(uri);
|
||||||
|
|
||||||
|
client.setFollowRedirects(followRedirects);
|
||||||
|
|
||||||
|
HttpClient.setContext(context);
|
||||||
|
retrieveCookiesFromMiddleware(client);
|
||||||
|
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void retrieveCookiesFromMiddleware(OwnCloudClient client) {
|
||||||
|
final GetRemoteStatusOperation statusOperation = new GetRemoteStatusOperation();
|
||||||
|
statusOperation.run(client);
|
||||||
|
}
|
||||||
}
|
}
|
@ -49,7 +49,6 @@ public class SingleSessionManager {
|
|||||||
|
|
||||||
private static SingleSessionManager sDefaultSingleton;
|
private static SingleSessionManager sDefaultSingleton;
|
||||||
private static String sUserAgent;
|
private static String sUserAgent;
|
||||||
private static ConnectionValidator sConnectionValidator;
|
|
||||||
|
|
||||||
private ConcurrentMap<String, OwnCloudClient> mClientsWithKnownUsername = new ConcurrentHashMap<>();
|
private ConcurrentMap<String, OwnCloudClient> mClientsWithKnownUsername = new ConcurrentHashMap<>();
|
||||||
private ConcurrentMap<String, OwnCloudClient> mClientsWithUnknownUsername = new ConcurrentHashMap<>();
|
private ConcurrentMap<String, OwnCloudClient> mClientsWithUnknownUsername = new ConcurrentHashMap<>();
|
||||||
@ -61,14 +60,6 @@ public class SingleSessionManager {
|
|||||||
return sDefaultSingleton;
|
return sDefaultSingleton;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setConnectionValidator(ConnectionValidator connectionValidator) {
|
|
||||||
sConnectionValidator = connectionValidator;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ConnectionValidator getConnectionValidator() {
|
|
||||||
return sConnectionValidator;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getUserAgent() {
|
public static String getUserAgent() {
|
||||||
return sUserAgent;
|
return sUserAgent;
|
||||||
}
|
}
|
||||||
@ -77,23 +68,7 @@ public class SingleSessionManager {
|
|||||||
sUserAgent = userAgent;
|
sUserAgent = userAgent;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static OwnCloudClient createOwnCloudClient(Uri uri,
|
public OwnCloudClient getClientFor(OwnCloudAccount account, Context context) throws OperationCanceledException,
|
||||||
Context context,
|
|
||||||
ConnectionValidator connectionValidator,
|
|
||||||
SingleSessionManager singleSessionManager) {
|
|
||||||
OwnCloudClient client = new OwnCloudClient(uri, connectionValidator, true, singleSessionManager, context);
|
|
||||||
return client;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OwnCloudClient getClientFor(OwnCloudAccount account,
|
|
||||||
Context context) throws OperationCanceledException,
|
|
||||||
AuthenticatorException, IOException {
|
|
||||||
return getClientFor(account, context, getConnectionValidator());
|
|
||||||
}
|
|
||||||
|
|
||||||
public OwnCloudClient getClientFor(OwnCloudAccount account,
|
|
||||||
Context context,
|
|
||||||
ConnectionValidator connectionValidator) throws OperationCanceledException,
|
|
||||||
AuthenticatorException, IOException {
|
AuthenticatorException, IOException {
|
||||||
|
|
||||||
Timber.d("getClientFor starting ");
|
Timber.d("getClientFor starting ");
|
||||||
@ -129,11 +104,10 @@ public class SingleSessionManager {
|
|||||||
|
|
||||||
if (client == null) {
|
if (client == null) {
|
||||||
// no client to reuse - create a new one
|
// no client to reuse - create a new one
|
||||||
client = createOwnCloudClient(
|
client = OwnCloudClientFactory.createOwnCloudClient(
|
||||||
account.getBaseUri(),
|
account.getBaseUri(),
|
||||||
context,
|
context.getApplicationContext(),
|
||||||
connectionValidator,
|
true); // TODO remove dependency on OwnCloudClientFactory
|
||||||
this); // TODO remove dependency on OwnCloudClientFactory
|
|
||||||
|
|
||||||
//the next two lines are a hack because okHttpclient is used as a singleton instead of being an
|
//the next two lines are a hack because okHttpclient is used as a singleton instead of being an
|
||||||
//injected instance that can be deleted when required
|
//injected instance that can be deleted when required
|
||||||
@ -141,6 +115,7 @@ public class SingleSessionManager {
|
|||||||
client.clearCredentials();
|
client.clearCredentials();
|
||||||
|
|
||||||
client.setAccount(account);
|
client.setAccount(account);
|
||||||
|
HttpClient.setContext(context);
|
||||||
|
|
||||||
account.loadCredentials(context);
|
account.loadCredentials(context);
|
||||||
client.setCredentials(account.getCredentials());
|
client.setCredentials(account.getCredentials());
|
||||||
|
@ -28,7 +28,7 @@ import okhttp3.CookieJar
|
|||||||
import okhttp3.HttpUrl
|
import okhttp3.HttpUrl
|
||||||
|
|
||||||
class CookieJarImpl(
|
class CookieJarImpl(
|
||||||
private val cookieStore: HashMap<String, List<Cookie>>
|
private val sCookieStore: HashMap<String, List<Cookie>>
|
||||||
) : CookieJar {
|
) : CookieJar {
|
||||||
|
|
||||||
fun containsCookieWithName(cookies: List<Cookie>, name: String): Boolean {
|
fun containsCookieWithName(cookies: List<Cookie>, name: String): Boolean {
|
||||||
@ -52,11 +52,12 @@ class CookieJarImpl(
|
|||||||
|
|
||||||
override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) {
|
override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) {
|
||||||
// Avoid duplicated cookies but update
|
// Avoid duplicated cookies but update
|
||||||
val currentCookies: List<Cookie> = cookieStore[url.host] ?: ArrayList()
|
val currentCookies: List<Cookie> = sCookieStore[url.host] ?: ArrayList()
|
||||||
val updatedCookies: List<Cookie> = getUpdatedCookies(currentCookies, cookies)
|
val updatedCookies: List<Cookie> = getUpdatedCookies(currentCookies, cookies)
|
||||||
cookieStore[url.host] = updatedCookies
|
sCookieStore[url.host] = updatedCookies
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun loadForRequest(url: HttpUrl) =
|
override fun loadForRequest(url: HttpUrl) =
|
||||||
cookieStore[url.host] ?: ArrayList()
|
sCookieStore[url.host] ?: ArrayList()
|
||||||
}
|
|
||||||
|
}
|
||||||
|
@ -40,6 +40,7 @@ import javax.net.ssl.SSLContext;
|
|||||||
import javax.net.ssl.SSLSocketFactory;
|
import javax.net.ssl.SSLSocketFactory;
|
||||||
import javax.net.ssl.TrustManager;
|
import javax.net.ssl.TrustManager;
|
||||||
import javax.net.ssl.X509TrustManager;
|
import javax.net.ssl.X509TrustManager;
|
||||||
|
import java.security.KeyManagementException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -53,46 +54,32 @@ import java.util.concurrent.TimeUnit;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public class HttpClient {
|
public class HttpClient {
|
||||||
private Context mContext;
|
private static OkHttpClient sOkHttpClient;
|
||||||
private HashMap<String, List<Cookie>> mCookieStore = new HashMap<>();
|
private static Context sContext;
|
||||||
private LogInterceptor mLogInterceptor = new LogInterceptor();
|
private static HashMap<String, List<Cookie>> sCookieStore = new HashMap<>();
|
||||||
|
private static LogInterceptor sLogInterceptor;
|
||||||
|
|
||||||
private OkHttpClient mOkHttpClient = null;
|
public static OkHttpClient getOkHttpClient() {
|
||||||
|
if (sOkHttpClient == null) {
|
||||||
protected HttpClient(Context context) {
|
|
||||||
if (context == null) {
|
|
||||||
Timber.e("Context may not be NULL!");
|
|
||||||
throw new NullPointerException("Context may not be NULL!");
|
|
||||||
}
|
|
||||||
mContext = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OkHttpClient getOkHttpClient() {
|
|
||||||
if (mOkHttpClient == null) {
|
|
||||||
try {
|
try {
|
||||||
final X509TrustManager trustManager = new AdvancedX509TrustManager(
|
final X509TrustManager trustManager = new AdvancedX509TrustManager(
|
||||||
NetworkUtils.getKnownServersStore(mContext));
|
NetworkUtils.getKnownServersStore(sContext));
|
||||||
|
final SSLSocketFactory sslSocketFactory = getNewSslSocketFactory(trustManager);
|
||||||
final SSLContext sslContext = buildSSLContext();
|
|
||||||
sslContext.init(null, new TrustManager[]{trustManager}, null);
|
|
||||||
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
|
|
||||||
|
|
||||||
// Automatic cookie handling, NOT PERSISTENT
|
// Automatic cookie handling, NOT PERSISTENT
|
||||||
final CookieJar cookieJar = new CookieJarImpl(mCookieStore);
|
final CookieJar cookieJar = new CookieJarImpl(sCookieStore);
|
||||||
mOkHttpClient = buildNewOkHttpClient(sslSocketFactory, trustManager, cookieJar);
|
|
||||||
|
// TODO: Not verifying the hostname against certificate. ask owncloud security human if this is ok.
|
||||||
|
//.hostnameVerifier(new BrowserCompatHostnameVerifier());
|
||||||
|
sOkHttpClient = buildNewOkHttpClient(sslSocketFactory, trustManager, cookieJar);
|
||||||
|
|
||||||
} catch (NoSuchAlgorithmException nsae) {
|
|
||||||
Timber.e(nsae, "Could not setup SSL system.");
|
|
||||||
throw new RuntimeException("Could not setup okHttp client.", nsae);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Timber.e(e, "Could not setup okHttp client.");
|
Timber.e(e, "Could not setup SSL system.");
|
||||||
throw new RuntimeException("Could not setup okHttp client.", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return mOkHttpClient;
|
return sOkHttpClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SSLContext buildSSLContext() throws NoSuchAlgorithmException {
|
private static SSLContext getSslContext() throws NoSuchAlgorithmException {
|
||||||
try {
|
try {
|
||||||
return SSLContext.getInstance(TlsVersion.TLS_1_3.javaName());
|
return SSLContext.getInstance(TlsVersion.TLS_1_3.javaName());
|
||||||
} catch (NoSuchAlgorithmException tlsv13Exception) {
|
} catch (NoSuchAlgorithmException tlsv13Exception) {
|
||||||
@ -113,11 +100,17 @@ public class HttpClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private OkHttpClient buildNewOkHttpClient(SSLSocketFactory sslSocketFactory, X509TrustManager trustManager,
|
private static SSLSocketFactory getNewSslSocketFactory(X509TrustManager trustManager)
|
||||||
CookieJar cookieJar) {
|
throws NoSuchAlgorithmException, KeyManagementException {
|
||||||
|
final SSLContext sslContext = getSslContext();
|
||||||
|
sslContext.init(null, new TrustManager[]{trustManager}, null);
|
||||||
|
return sslContext.getSocketFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static OkHttpClient buildNewOkHttpClient(SSLSocketFactory sslSocketFactory, X509TrustManager trustManager,
|
||||||
|
CookieJar cookieJar) {
|
||||||
return new OkHttpClient.Builder()
|
return new OkHttpClient.Builder()
|
||||||
.addNetworkInterceptor(getLogInterceptor())
|
.addNetworkInterceptor(getLogInterceptor())
|
||||||
.addNetworkInterceptor(DebugInterceptorFactory.INSTANCE.getInterceptor())
|
|
||||||
.protocols(Collections.singletonList(Protocol.HTTP_1_1))
|
.protocols(Collections.singletonList(Protocol.HTTP_1_1))
|
||||||
.readTimeout(HttpConstants.DEFAULT_DATA_TIMEOUT, TimeUnit.MILLISECONDS)
|
.readTimeout(HttpConstants.DEFAULT_DATA_TIMEOUT, TimeUnit.MILLISECONDS)
|
||||||
.writeTimeout(HttpConstants.DEFAULT_DATA_TIMEOUT, TimeUnit.MILLISECONDS)
|
.writeTimeout(HttpConstants.DEFAULT_DATA_TIMEOUT, TimeUnit.MILLISECONDS)
|
||||||
@ -129,19 +122,26 @@ public class HttpClient {
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static LogInterceptor getLogInterceptor() {
|
||||||
|
if (sLogInterceptor == null) {
|
||||||
|
sLogInterceptor = new LogInterceptor();
|
||||||
|
}
|
||||||
|
return sLogInterceptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Cookie> getCookiesFromUrl(HttpUrl httpUrl) {
|
||||||
|
return sCookieStore.get(httpUrl.host());
|
||||||
|
}
|
||||||
|
|
||||||
public Context getContext() {
|
public Context getContext() {
|
||||||
return mContext;
|
return sContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LogInterceptor getLogInterceptor() {
|
public static void setContext(Context context) {
|
||||||
return mLogInterceptor;
|
sContext = context;
|
||||||
}
|
|
||||||
|
|
||||||
public List<Cookie> getCookiesFromUrl(HttpUrl httpUrl) {
|
|
||||||
return mCookieStore.get(httpUrl.host());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearCookies() {
|
public void clearCookies() {
|
||||||
mCookieStore.clear();
|
sCookieStore.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,13 +41,13 @@ object LogBuilder {
|
|||||||
enum class NetworkPetition {
|
enum class NetworkPetition {
|
||||||
REQUEST, RESPONSE;
|
REQUEST, RESPONSE;
|
||||||
|
|
||||||
override fun toString(): String = super.toString().lowercase(Locale.ROOT)
|
override fun toString(): String = super.toString().toLowerCase(Locale.ROOT)
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class NetworkNode {
|
enum class NetworkNode {
|
||||||
INFO, HEADER, BODY;
|
INFO, HEADER, BODY;
|
||||||
|
|
||||||
override fun toString(): String = super.toString().lowercase(Locale.ROOT)
|
override fun toString(): String = super.toString().toLowerCase(Locale.ROOT)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,27 +1,3 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
|
||||||
* Copyright (C) 2022 ownCloud GmbH.
|
|
||||||
*
|
|
||||||
* 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 com.owncloud.android.lib.common.http.methods
|
package com.owncloud.android.lib.common.http.methods
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.http.HttpClient
|
import com.owncloud.android.lib.common.http.HttpClient
|
||||||
@ -38,41 +14,23 @@ import java.net.URL
|
|||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
abstract class HttpBaseMethod constructor(url: URL) {
|
abstract class HttpBaseMethod constructor(url: URL) {
|
||||||
|
var okHttpClient: OkHttpClient
|
||||||
var httpUrl: HttpUrl = url.toHttpUrlOrNull() ?: throw MalformedURLException()
|
var httpUrl: HttpUrl = url.toHttpUrlOrNull() ?: throw MalformedURLException()
|
||||||
var request: Request
|
var request: Request
|
||||||
var followPermanentRedirects = false
|
|
||||||
abstract var response: Response
|
abstract var response: Response
|
||||||
|
|
||||||
var call: Call? = null
|
var call: Call? = null
|
||||||
|
|
||||||
var followRedirects: Boolean = true
|
|
||||||
var retryOnConnectionFailure: Boolean = true
|
|
||||||
var connectionTimeoutVal: Long? = null
|
|
||||||
var connectionTimeoutUnit: TimeUnit? = null
|
|
||||||
var readTimeoutVal: Long? = null
|
|
||||||
private set
|
|
||||||
var readTimeoutUnit: TimeUnit? = null
|
|
||||||
private set
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
okHttpClient = HttpClient.getOkHttpClient()
|
||||||
request = Request.Builder()
|
request = Request.Builder()
|
||||||
.url(httpUrl)
|
.url(httpUrl)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
open fun execute(httpClient: HttpClient): Int {
|
open fun execute(): Int {
|
||||||
val okHttpClient = httpClient.okHttpClient.newBuilder().apply {
|
return onExecute()
|
||||||
retryOnConnectionFailure(retryOnConnectionFailure)
|
|
||||||
followRedirects(followRedirects)
|
|
||||||
readTimeoutUnit?.let { unit ->
|
|
||||||
readTimeoutVal?.let { readTimeout(it, unit) }
|
|
||||||
}
|
|
||||||
connectionTimeoutUnit?.let { unit ->
|
|
||||||
connectionTimeoutVal?.let { connectTimeout(it, unit) }
|
|
||||||
}
|
|
||||||
}.build()
|
|
||||||
|
|
||||||
return onExecute(okHttpClient)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun setUrl(url: HttpUrl) {
|
open fun setUrl(url: HttpUrl) {
|
||||||
@ -141,11 +99,6 @@ abstract class HttpBaseMethod constructor(url: URL) {
|
|||||||
return response.body?.byteStream()
|
return response.body?.byteStream()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* returns the final url after following the last redirect.
|
|
||||||
*/
|
|
||||||
open fun getFinalUrl() = response.request.url
|
|
||||||
|
|
||||||
/*************************
|
/*************************
|
||||||
*** Connection Params ***
|
*** Connection Params ***
|
||||||
*************************/
|
*************************/
|
||||||
@ -154,19 +107,31 @@ abstract class HttpBaseMethod constructor(url: URL) {
|
|||||||
// Setter
|
// Setter
|
||||||
//////////////////////////////
|
//////////////////////////////
|
||||||
// Connection parameters
|
// Connection parameters
|
||||||
|
open fun setRetryOnConnectionFailure(retryOnConnectionFailure: Boolean) {
|
||||||
|
okHttpClient = okHttpClient.newBuilder()
|
||||||
|
.retryOnConnectionFailure(retryOnConnectionFailure)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
open fun setReadTimeout(readTimeout: Long, timeUnit: TimeUnit) {
|
open fun setReadTimeout(readTimeout: Long, timeUnit: TimeUnit) {
|
||||||
readTimeoutVal = readTimeout
|
okHttpClient = okHttpClient.newBuilder()
|
||||||
readTimeoutUnit = timeUnit
|
.readTimeout(readTimeout, timeUnit)
|
||||||
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun setConnectionTimeout(
|
open fun setConnectionTimeout(
|
||||||
connectionTimeout: Long,
|
connectionTimeout: Long,
|
||||||
timeUnit: TimeUnit
|
timeUnit: TimeUnit
|
||||||
) {
|
) {
|
||||||
connectionTimeoutVal = connectionTimeout
|
okHttpClient = okHttpClient.newBuilder()
|
||||||
connectionTimeoutUnit = timeUnit
|
.readTimeout(connectionTimeout, timeUnit)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
open fun setFollowRedirects(followRedirects: Boolean) {
|
||||||
|
okHttpClient = okHttpClient.newBuilder()
|
||||||
|
.followRedirects(followRedirects)
|
||||||
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
/************
|
/************
|
||||||
@ -183,5 +148,5 @@ abstract class HttpBaseMethod constructor(url: URL) {
|
|||||||
// For override
|
// For override
|
||||||
//////////////////////////////
|
//////////////////////////////
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
protected abstract fun onExecute(okHttpClient: OkHttpClient): Int
|
protected abstract fun onExecute(): Int
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.owncloud.android.lib.common.http.methods.nonwebdav
|
package com.owncloud.android.lib.common.http.methods.nonwebdav
|
||||||
|
|
||||||
import okhttp3.OkHttpClient
|
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
|
||||||
@ -34,10 +33,10 @@ import java.net.URL
|
|||||||
*/
|
*/
|
||||||
class DeleteMethod(url: URL) : HttpMethod(url) {
|
class DeleteMethod(url: URL) : HttpMethod(url) {
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
override fun onExecute(okHttpClient: OkHttpClient): Int {
|
override fun onExecute(): Int {
|
||||||
request = request.newBuilder()
|
request = request.newBuilder()
|
||||||
.delete()
|
.delete()
|
||||||
.build()
|
.build()
|
||||||
return super.onExecute(okHttpClient)
|
return super.onExecute()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.owncloud.android.lib.common.http.methods.nonwebdav
|
package com.owncloud.android.lib.common.http.methods.nonwebdav
|
||||||
|
|
||||||
import okhttp3.OkHttpClient
|
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
|
||||||
@ -34,10 +33,10 @@ import java.net.URL
|
|||||||
*/
|
*/
|
||||||
class GetMethod(url: URL) : HttpMethod(url) {
|
class GetMethod(url: URL) : HttpMethod(url) {
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
override fun onExecute(okHttpClient: OkHttpClient): Int {
|
override fun onExecute(): Int {
|
||||||
request = request.newBuilder()
|
request = request.newBuilder()
|
||||||
.get()
|
.get()
|
||||||
.build()
|
.build()
|
||||||
return super.onExecute(okHttpClient)
|
return super.onExecute()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
package com.owncloud.android.lib.common.http.methods.nonwebdav
|
package com.owncloud.android.lib.common.http.methods.nonwebdav
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.http.methods.HttpBaseMethod
|
import com.owncloud.android.lib.common.http.methods.HttpBaseMethod
|
||||||
import okhttp3.OkHttpClient
|
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
|
||||||
@ -39,7 +38,7 @@ abstract class HttpMethod(
|
|||||||
|
|
||||||
override lateinit var response: Response
|
override lateinit var response: Response
|
||||||
|
|
||||||
public override fun onExecute(okHttpClient: OkHttpClient): Int {
|
public override fun onExecute(): Int {
|
||||||
call = okHttpClient.newCall(request)
|
call = okHttpClient.newCall(request)
|
||||||
call?.let { response = it.execute() }
|
call?.let { response = it.execute() }
|
||||||
return super.statusCode
|
return super.statusCode
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.owncloud.android.lib.common.http.methods.nonwebdav
|
package com.owncloud.android.lib.common.http.methods.nonwebdav
|
||||||
|
|
||||||
import okhttp3.OkHttpClient
|
|
||||||
import okhttp3.RequestBody
|
import okhttp3.RequestBody
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
@ -38,10 +37,10 @@ class PostMethod(
|
|||||||
private val postRequestBody: RequestBody
|
private val postRequestBody: RequestBody
|
||||||
) : HttpMethod(url) {
|
) : HttpMethod(url) {
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
override fun onExecute(okHttpClient: OkHttpClient): Int {
|
override fun onExecute(): Int {
|
||||||
request = request.newBuilder()
|
request = request.newBuilder()
|
||||||
.post(postRequestBody)
|
.post(postRequestBody)
|
||||||
.build()
|
.build()
|
||||||
return super.onExecute(okHttpClient)
|
return super.onExecute()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.owncloud.android.lib.common.http.methods.nonwebdav
|
package com.owncloud.android.lib.common.http.methods.nonwebdav
|
||||||
|
|
||||||
import okhttp3.OkHttpClient
|
|
||||||
import okhttp3.RequestBody
|
import okhttp3.RequestBody
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
@ -38,10 +37,10 @@ class PutMethod(
|
|||||||
private val putRequestBody: RequestBody
|
private val putRequestBody: RequestBody
|
||||||
) : HttpMethod(url) {
|
) : HttpMethod(url) {
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
override fun onExecute(okHttpClient: OkHttpClient): Int {
|
override fun onExecute(): Int {
|
||||||
request = request.newBuilder()
|
request = request.newBuilder()
|
||||||
.put(putRequestBody)
|
.put(putRequestBody)
|
||||||
.build()
|
.build()
|
||||||
return super.onExecute(okHttpClient)
|
return super.onExecute()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.owncloud.android.lib.common.http.methods.webdav
|
package com.owncloud.android.lib.common.http.methods.webdav
|
||||||
|
|
||||||
import at.bitfire.dav4jvm.DavOCResource
|
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
|
||||||
@ -39,7 +38,7 @@ class CopyMethod(
|
|||||||
private val forceOverride: Boolean
|
private val forceOverride: Boolean
|
||||||
) : DavMethod(url) {
|
) : DavMethod(url) {
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
public override fun onDavExecute(davResource: DavOCResource): Int {
|
public override fun onExecute(): Int {
|
||||||
davResource.copy(
|
davResource.copy(
|
||||||
destinationUrl,
|
destinationUrl,
|
||||||
forceOverride,
|
forceOverride,
|
||||||
|
@ -29,11 +29,14 @@ import at.bitfire.dav4jvm.exception.HttpException
|
|||||||
import at.bitfire.dav4jvm.exception.RedirectException
|
import at.bitfire.dav4jvm.exception.RedirectException
|
||||||
import com.owncloud.android.lib.common.http.HttpConstants
|
import com.owncloud.android.lib.common.http.HttpConstants
|
||||||
import com.owncloud.android.lib.common.http.methods.HttpBaseMethod
|
import com.owncloud.android.lib.common.http.methods.HttpBaseMethod
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.HttpUrl
|
||||||
|
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
||||||
import okhttp3.Protocol
|
import okhttp3.Protocol
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import okhttp3.ResponseBody.Companion.toResponseBody
|
import okhttp3.ResponseBody.Companion.toResponseBody
|
||||||
|
import java.net.MalformedURLException
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper to perform WebDAV (dav4android) calls
|
* Wrapper to perform WebDAV (dav4android) calls
|
||||||
@ -41,25 +44,27 @@ import java.net.URL
|
|||||||
* @author David González Verdugo
|
* @author David González Verdugo
|
||||||
*/
|
*/
|
||||||
abstract class DavMethod protected constructor(url: URL) : HttpBaseMethod(url) {
|
abstract class DavMethod protected constructor(url: URL) : HttpBaseMethod(url) {
|
||||||
override lateinit var response: Response
|
protected var davResource: DavOCResource
|
||||||
private var davResource: DavOCResource? = null
|
|
||||||
|
|
||||||
override fun abort() {
|
override lateinit var response: Response
|
||||||
davResource?.cancelCall()
|
|
||||||
|
init {
|
||||||
|
val httpUrl = url.toHttpUrlOrNull() ?: throw MalformedURLException()
|
||||||
|
davResource = DavOCResource(
|
||||||
|
okHttpClient,
|
||||||
|
httpUrl,
|
||||||
|
log
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract fun onDavExecute(davResource: DavOCResource): Int
|
override fun abort() {
|
||||||
|
davResource.cancelCall()
|
||||||
|
}
|
||||||
|
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
override fun onExecute(okHttpClient: OkHttpClient): Int {
|
override fun execute(): Int {
|
||||||
return try {
|
return try {
|
||||||
davResource = DavOCResource(
|
onExecute()
|
||||||
okHttpClient.newBuilder().followRedirects(false).build(),
|
|
||||||
httpUrl,
|
|
||||||
log
|
|
||||||
)
|
|
||||||
|
|
||||||
onDavExecute(davResource!!)
|
|
||||||
} catch (httpException: HttpException) {
|
} catch (httpException: HttpException) {
|
||||||
// Modify responses with information gathered from exceptions
|
// Modify responses with information gathered from exceptions
|
||||||
if (httpException is RedirectException) {
|
if (httpException is RedirectException) {
|
||||||
@ -86,12 +91,71 @@ abstract class DavMethod protected constructor(url: URL) : HttpBaseMethod(url) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//////////////////////////////
|
||||||
|
// Setter
|
||||||
|
//////////////////////////////
|
||||||
|
// Connection parameters
|
||||||
|
override fun setReadTimeout(readTimeout: Long, timeUnit: TimeUnit) {
|
||||||
|
super.setReadTimeout(readTimeout, timeUnit)
|
||||||
|
davResource = DavOCResource(
|
||||||
|
okHttpClient,
|
||||||
|
request.url,
|
||||||
|
log
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setConnectionTimeout(
|
||||||
|
connectionTimeout: Long,
|
||||||
|
timeUnit: TimeUnit
|
||||||
|
) {
|
||||||
|
super.setConnectionTimeout(connectionTimeout, timeUnit)
|
||||||
|
davResource = DavOCResource(
|
||||||
|
okHttpClient,
|
||||||
|
request.url,
|
||||||
|
log
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setFollowRedirects(followRedirects: Boolean) {
|
||||||
|
super.setFollowRedirects(followRedirects)
|
||||||
|
davResource = DavOCResource(
|
||||||
|
okHttpClient,
|
||||||
|
request.url,
|
||||||
|
log
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setUrl(url: HttpUrl) {
|
||||||
|
super.setUrl(url)
|
||||||
|
davResource = DavOCResource(
|
||||||
|
okHttpClient,
|
||||||
|
request.url,
|
||||||
|
log
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setRequestHeader(name: String, value: String) {
|
||||||
|
super.setRequestHeader(name, value)
|
||||||
|
davResource = DavOCResource(
|
||||||
|
okHttpClient,
|
||||||
|
request.url,
|
||||||
|
log
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
//////////////////////////////
|
//////////////////////////////
|
||||||
// Getter
|
// Getter
|
||||||
//////////////////////////////
|
//////////////////////////////
|
||||||
|
override fun setRetryOnConnectionFailure(retryOnConnectionFailure: Boolean) {
|
||||||
|
super.setRetryOnConnectionFailure(retryOnConnectionFailure)
|
||||||
|
davResource = DavOCResource(
|
||||||
|
okHttpClient,
|
||||||
|
request.url,
|
||||||
|
log
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
override val isAborted: Boolean
|
override val isAborted: Boolean
|
||||||
get() = davResource?.isCallAborted() ?: false
|
get() = davResource.isCallAborted()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.owncloud.android.lib.common.http.methods.webdav
|
package com.owncloud.android.lib.common.http.methods.webdav
|
||||||
|
|
||||||
import at.bitfire.dav4jvm.DavOCResource
|
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
|
||||||
@ -35,7 +34,7 @@ import java.net.URL
|
|||||||
*/
|
*/
|
||||||
class MkColMethod(url: URL) : DavMethod(url) {
|
class MkColMethod(url: URL) : DavMethod(url) {
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
public override fun onDavExecute(davResource: DavOCResource): Int {
|
public override fun onExecute(): Int {
|
||||||
davResource.mkCol(
|
davResource.mkCol(
|
||||||
xmlBody = null,
|
xmlBody = null,
|
||||||
listOfHeaders = super.getRequestHeadersAsHashMap()
|
listOfHeaders = super.getRequestHeadersAsHashMap()
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.owncloud.android.lib.common.http.methods.webdav
|
package com.owncloud.android.lib.common.http.methods.webdav
|
||||||
|
|
||||||
import at.bitfire.dav4jvm.DavOCResource
|
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
|
||||||
@ -39,7 +38,7 @@ class MoveMethod(
|
|||||||
private val forceOverride: Boolean
|
private val forceOverride: Boolean
|
||||||
) : DavMethod(url) {
|
) : DavMethod(url) {
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
override fun onDavExecute(davResource: DavOCResource): Int {
|
public override fun onExecute(): Int {
|
||||||
davResource.move(
|
davResource.move(
|
||||||
destinationUrl,
|
destinationUrl,
|
||||||
forceOverride,
|
forceOverride,
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.owncloud.android.lib.common.http.methods.webdav
|
package com.owncloud.android.lib.common.http.methods.webdav
|
||||||
|
|
||||||
import at.bitfire.dav4jvm.DavOCResource
|
|
||||||
import at.bitfire.dav4jvm.Property
|
import at.bitfire.dav4jvm.Property
|
||||||
import at.bitfire.dav4jvm.Response
|
import at.bitfire.dav4jvm.Response
|
||||||
import at.bitfire.dav4jvm.Response.HrefRelation
|
import at.bitfire.dav4jvm.Response.HrefRelation
|
||||||
@ -48,10 +47,10 @@ class PropfindMethod(
|
|||||||
private set
|
private set
|
||||||
|
|
||||||
@Throws(IOException::class, DavException::class)
|
@Throws(IOException::class, DavException::class)
|
||||||
public override fun onDavExecute(davResource: DavOCResource): Int {
|
public override fun onExecute(): Int {
|
||||||
davResource.propfind(
|
davResource.propfind(
|
||||||
depth = depth,
|
depth = depth,
|
||||||
reqProp = propertiesToRequest,
|
reqProp = *propertiesToRequest,
|
||||||
listOfHeaders = super.getRequestHeadersAsHashMap(),
|
listOfHeaders = super.getRequestHeadersAsHashMap(),
|
||||||
callback = { response: Response, hrefRelation: HrefRelation? ->
|
callback = { response: Response, hrefRelation: HrefRelation? ->
|
||||||
when (hrefRelation) {
|
when (hrefRelation) {
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.owncloud.android.lib.common.http.methods.webdav
|
package com.owncloud.android.lib.common.http.methods.webdav
|
||||||
|
|
||||||
import at.bitfire.dav4jvm.DavOCResource
|
|
||||||
import at.bitfire.dav4jvm.exception.HttpException
|
import at.bitfire.dav4jvm.exception.HttpException
|
||||||
import com.owncloud.android.lib.common.http.HttpConstants
|
import com.owncloud.android.lib.common.http.HttpConstants
|
||||||
import okhttp3.RequestBody
|
import okhttp3.RequestBody
|
||||||
@ -40,7 +39,7 @@ class PutMethod(
|
|||||||
private val putRequestBody: RequestBody
|
private val putRequestBody: RequestBody
|
||||||
) : DavMethod(url) {
|
) : DavMethod(url) {
|
||||||
@Throws(IOException::class, HttpException::class)
|
@Throws(IOException::class, HttpException::class)
|
||||||
public override fun onDavExecute(davResource: DavOCResource): Int {
|
public override fun onExecute(): Int {
|
||||||
davResource.put(
|
davResource.put(
|
||||||
putRequestBody,
|
putRequestBody,
|
||||||
super.getRequestHeader(HttpConstants.IF_MATCH_HEADER),
|
super.getRequestHeader(HttpConstants.IF_MATCH_HEADER),
|
||||||
|
@ -1,27 +1,3 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
|
||||||
* Copyright (C) 2022 ownCloud GmbH.
|
|
||||||
*
|
|
||||||
* 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 com.owncloud.android.lib.common.operations;
|
package com.owncloud.android.lib.common.operations;
|
||||||
|
|
||||||
import android.accounts.Account;
|
import android.accounts.Account;
|
||||||
@ -159,7 +135,7 @@ public abstract class RemoteOperation<T> implements Runnable {
|
|||||||
if (mAccount != null && mContext != null) {
|
if (mAccount != null && mContext != null) {
|
||||||
OwnCloudAccount ocAccount = new OwnCloudAccount(mAccount, mContext);
|
OwnCloudAccount ocAccount = new OwnCloudAccount(mAccount, mContext);
|
||||||
mClient = SingleSessionManager.getDefaultSingleton().
|
mClient = SingleSessionManager.getDefaultSingleton().
|
||||||
getClientFor(ocAccount, mContext, SingleSessionManager.getConnectionValidator());
|
getClientFor(ocAccount, mContext);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException("Trying to run a remote operation " +
|
throw new IllegalStateException("Trying to run a remote operation " +
|
||||||
"asynchronously with no client and no chance to create one (no account)");
|
"asynchronously with no client and no chance to create one (no account)");
|
||||||
@ -289,4 +265,4 @@ public abstract class RemoteOperation<T> implements Runnable {
|
|||||||
mListener.onRemoteOperationFinish(RemoteOperation.this, resultToSend);
|
mListener.onRemoteOperationFinish(RemoteOperation.this, resultToSend);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,5 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
/* ownCloud Android Library is available under MIT license
|
||||||
* Copyright (C) 2022 ownCloud GmbH.
|
* Copyright (C) 2020 ownCloud GmbH.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -34,7 +34,6 @@ import com.owncloud.android.lib.common.http.HttpConstants;
|
|||||||
import com.owncloud.android.lib.common.http.methods.HttpBaseMethod;
|
import com.owncloud.android.lib.common.http.methods.HttpBaseMethod;
|
||||||
import com.owncloud.android.lib.common.network.CertificateCombinedException;
|
import com.owncloud.android.lib.common.network.CertificateCombinedException;
|
||||||
import okhttp3.Headers;
|
import okhttp3.Headers;
|
||||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
@ -60,15 +59,13 @@ public class RemoteOperationResult<T>
|
|||||||
* Generated - should be refreshed every time the class changes!!
|
* Generated - should be refreshed every time the class changes!!
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 4968939884332372230L;
|
private static final long serialVersionUID = 4968939884332372230L;
|
||||||
private static final String LOCATION = "location";
|
|
||||||
private static final String WWW_AUTHENTICATE = "www-authenticate";
|
|
||||||
|
|
||||||
private boolean mSuccess = false;
|
private boolean mSuccess = false;
|
||||||
private int mHttpCode = -1;
|
private int mHttpCode = -1;
|
||||||
private String mHttpPhrase = null;
|
private String mHttpPhrase = null;
|
||||||
private Exception mException = null;
|
private Exception mException = null;
|
||||||
private ResultCode mCode = ResultCode.UNKNOWN_ERROR;
|
private ResultCode mCode = ResultCode.UNKNOWN_ERROR;
|
||||||
private String mRedirectedLocation = "";
|
private String mRedirectedLocation;
|
||||||
private List<String> mAuthenticate = new ArrayList<>();
|
private List<String> mAuthenticate = new ArrayList<>();
|
||||||
private String mLastPermanentLocation = null;
|
private String mLastPermanentLocation = null;
|
||||||
private T mData = null;
|
private T mData = null;
|
||||||
@ -115,14 +112,6 @@ public class RemoteOperationResult<T>
|
|||||||
*/
|
*/
|
||||||
public RemoteOperationResult(Exception e) {
|
public RemoteOperationResult(Exception e) {
|
||||||
mException = e;
|
mException = e;
|
||||||
//TODO: Do propper exception handling and remove this
|
|
||||||
Timber.e("---------------------------------" +
|
|
||||||
"\nCreate RemoteOperationResult from exception." +
|
|
||||||
"\n Message: %s" +
|
|
||||||
"\n Stacktrace: %s" +
|
|
||||||
"\n---------------------------------",
|
|
||||||
ExceptionUtils.getMessage(e),
|
|
||||||
ExceptionUtils.getStackTrace(e));
|
|
||||||
|
|
||||||
if (e instanceof OperationCancelledException) {
|
if (e instanceof OperationCancelledException) {
|
||||||
mCode = ResultCode.CANCELLED;
|
mCode = ResultCode.CANCELLED;
|
||||||
@ -259,11 +248,11 @@ public class RemoteOperationResult<T>
|
|||||||
this(httpCode, httpPhrase);
|
this(httpCode, httpPhrase);
|
||||||
if (headers != null) {
|
if (headers != null) {
|
||||||
for (Map.Entry<String, List<String>> header : headers.toMultimap().entrySet()) {
|
for (Map.Entry<String, List<String>> header : headers.toMultimap().entrySet()) {
|
||||||
if (LOCATION.equalsIgnoreCase(header.getKey())) {
|
if ("location".equals(header.getKey().toLowerCase())) {
|
||||||
mRedirectedLocation = header.getValue().get(0);
|
mRedirectedLocation = header.getValue().get(0);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (WWW_AUTHENTICATE.equalsIgnoreCase(header.getKey())) {
|
if ("www-authenticate".equals(header.getKey().toLowerCase())) {
|
||||||
for (String value: header.getValue()) {
|
for (String value: header.getValue()) {
|
||||||
mAuthenticate.add(value.toLowerCase());
|
mAuthenticate.add(value.toLowerCase());
|
||||||
}
|
}
|
||||||
@ -332,7 +321,7 @@ public class RemoteOperationResult<T>
|
|||||||
mHttpPhrase = errorMessage;
|
mHttpPhrase = errorMessage;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Timber.w("Error reading exception from server: %s\nTrace: %s", e.getMessage(), ExceptionUtils.getStackTrace(e));
|
Timber.w("Error reading exception from server: %s", e.getMessage());
|
||||||
// mCode stays as set in this(success, httpCode, headers)
|
// mCode stays as set in this(success, httpCode, headers)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,27 +1,3 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
|
||||||
* Copyright (C) 2022 ownCloud GmbH.
|
|
||||||
*
|
|
||||||
* 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 com.owncloud.android.lib.common.utils
|
package com.owncloud.android.lib.common.utils
|
||||||
|
|
||||||
import info.hannes.timber.FileLoggingTree
|
import info.hannes.timber.FileLoggingTree
|
||||||
|
@ -1,27 +1,21 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
/**
|
||||||
* Copyright (C) 2022 ownCloud GmbH.
|
* ownCloud Android client application
|
||||||
*
|
*
|
||||||
* @author David González Verdugo
|
* @author David González Verdugo
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Copyright (C) 2020 ownCloud GmbH.
|
||||||
* 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
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* all copies or substantial portions of the Software.
|
* it under the terms of the GNU General Public License version 2,
|
||||||
*
|
* as published by the Free Software Foundation.
|
||||||
* 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.
|
|
||||||
*
|
*
|
||||||
|
* 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 General Public License for more details.
|
||||||
|
* <p>
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.owncloud.android.lib.resources
|
package com.owncloud.android.lib.resources
|
||||||
|
@ -27,6 +27,7 @@ import com.owncloud.android.lib.common.OwnCloudClient
|
|||||||
import com.owncloud.android.lib.common.http.HttpConstants
|
import com.owncloud.android.lib.common.http.HttpConstants
|
||||||
import com.owncloud.android.lib.common.http.methods.webdav.DavUtils.allPropset
|
import com.owncloud.android.lib.common.http.methods.webdav.DavUtils.allPropset
|
||||||
import com.owncloud.android.lib.common.http.methods.webdav.PropfindMethod
|
import com.owncloud.android.lib.common.http.methods.webdav.PropfindMethod
|
||||||
|
import com.owncloud.android.lib.common.network.RedirectionPath
|
||||||
import com.owncloud.android.lib.common.network.WebdavUtils
|
import com.owncloud.android.lib.common.network.WebdavUtils
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperation
|
import com.owncloud.android.lib.common.operations.RemoteOperation
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
||||||
@ -43,18 +44,26 @@ import java.util.concurrent.TimeUnit
|
|||||||
* @author Abel García de Prada
|
* @author Abel García de Prada
|
||||||
*
|
*
|
||||||
* @param remotePath Path to append to the URL owned by the client instance.
|
* @param remotePath Path to append to the URL owned by the client instance.
|
||||||
* @param isUserLoggedIn When `true`, the username won't be added at the end of the PROPFIND url since is not
|
* @param isUserLogged When `true`, the username won't be added at the end of the PROPFIND url since is not
|
||||||
* needed to check user credentials
|
* needed to check user credentials
|
||||||
*/
|
*/
|
||||||
class CheckPathExistenceRemoteOperation(
|
class CheckPathExistenceRemoteOperation(
|
||||||
val remotePath: String? = "",
|
val remotePath: String? = "",
|
||||||
val isUserLoggedIn: Boolean
|
val isUserLogged: Boolean
|
||||||
) : RemoteOperation<Boolean>() {
|
) : RemoteOperation<Boolean>() {
|
||||||
|
/**
|
||||||
|
* Gets the sequence of redirections followed during the execution of the operation.
|
||||||
|
*
|
||||||
|
* @return Sequence of redirections followed, if any, or NULL if the operation was not executed.
|
||||||
|
*/
|
||||||
|
var redirectionPath: RedirectionPath? = null
|
||||||
|
private set
|
||||||
|
|
||||||
override fun run(client: OwnCloudClient): RemoteOperationResult<Boolean> {
|
override fun run(client: OwnCloudClient): RemoteOperationResult<Boolean> {
|
||||||
|
val previousFollowRedirects = client.followRedirects()
|
||||||
return try {
|
return try {
|
||||||
val stringUrl =
|
val stringUrl =
|
||||||
if (isUserLoggedIn) client.baseFilesWebDavUri.toString()
|
if (isUserLogged) client.baseFilesWebDavUri.toString()
|
||||||
else client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(remotePath)
|
else client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(remotePath)
|
||||||
|
|
||||||
val propFindMethod = PropfindMethod(URL(stringUrl), 0, allPropset).apply {
|
val propFindMethod = PropfindMethod(URL(stringUrl), 0, allPropset).apply {
|
||||||
@ -62,7 +71,12 @@ class CheckPathExistenceRemoteOperation(
|
|||||||
setConnectionTimeout(TIMEOUT.toLong(), TimeUnit.SECONDS)
|
setConnectionTimeout(TIMEOUT.toLong(), TimeUnit.SECONDS)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
client.setFollowRedirects(false)
|
||||||
var status = client.executeHttpMethod(propFindMethod)
|
var status = client.executeHttpMethod(propFindMethod)
|
||||||
|
if (previousFollowRedirects) {
|
||||||
|
redirectionPath = client.followRedirection(propFindMethod)
|
||||||
|
status = redirectionPath?.lastStatus!!
|
||||||
|
}
|
||||||
/* PROPFIND method
|
/* PROPFIND method
|
||||||
* 404 NOT FOUND: path doesn't exist,
|
* 404 NOT FOUND: path doesn't exist,
|
||||||
* 207 MULTI_STATUS: path exists.
|
* 207 MULTI_STATUS: path exists.
|
||||||
@ -80,9 +94,16 @@ class CheckPathExistenceRemoteOperation(
|
|||||||
"Existence check for ${client.userFilesWebDavUri}${WebdavUtils.encodePath(remotePath)} : ${result.logMessage}"
|
"Existence check for ${client.userFilesWebDavUri}${WebdavUtils.encodePath(remotePath)} : ${result.logMessage}"
|
||||||
)
|
)
|
||||||
result
|
result
|
||||||
|
} finally {
|
||||||
|
client.setFollowRedirects(previousFollowRedirects)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return 'True' if the operation was executed and at least one redirection was followed.
|
||||||
|
*/
|
||||||
|
fun wasRedirected() = redirectionPath?.redirectionsCount ?: 0 > 0
|
||||||
|
|
||||||
private fun isSuccess(status: Int) = status == HttpConstants.HTTP_OK || status == HttpConstants.HTTP_MULTI_STATUS
|
private fun isSuccess(status: Int) = status == HttpConstants.HTTP_OK || status == HttpConstants.HTTP_MULTI_STATUS
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -92,8 +92,7 @@ public class CopyRemoteFileOperation extends RemoteOperation<String> {
|
|||||||
RemoteOperationResult result;
|
RemoteOperationResult result;
|
||||||
try {
|
try {
|
||||||
CopyMethod copyMethod =
|
CopyMethod copyMethod =
|
||||||
new CopyMethod(
|
new CopyMethod(new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mSrcRemotePath)),
|
||||||
new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mSrcRemotePath)),
|
|
||||||
client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mTargetRemotePath),
|
client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mTargetRemotePath),
|
||||||
mOverwrite);
|
mOverwrite);
|
||||||
|
|
||||||
|
@ -87,8 +87,7 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
|
|||||||
RemoteOperationResult result;
|
RemoteOperationResult result;
|
||||||
try {
|
try {
|
||||||
Uri webDavUri = createChunksFolder ? client.getUploadsWebDavUri() : client.getUserFilesWebDavUri();
|
Uri webDavUri = createChunksFolder ? client.getUploadsWebDavUri() : client.getUserFilesWebDavUri();
|
||||||
final MkColMethod mkcol = new MkColMethod(
|
final MkColMethod mkcol = new MkColMethod(new URL(webDavUri + WebdavUtils.encodePath(mRemotePath)));
|
||||||
new URL(webDavUri + WebdavUtils.encodePath(mRemotePath)));
|
|
||||||
mkcol.setReadTimeout(READ_TIMEOUT, TimeUnit.SECONDS);
|
mkcol.setReadTimeout(READ_TIMEOUT, TimeUnit.SECONDS);
|
||||||
mkcol.setConnectionTimeout(CONNECTION_TIMEOUT, TimeUnit.SECONDS);
|
mkcol.setConnectionTimeout(CONNECTION_TIMEOUT, TimeUnit.SECONDS);
|
||||||
final int status = client.executeHttpMethod(mkcol);
|
final int status = client.executeHttpMethod(mkcol);
|
||||||
|
@ -1,77 +0,0 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
|
||||||
* Copyright (C) 2022 ownCloud GmbH.
|
|
||||||
*
|
|
||||||
* 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 com.owncloud.android.lib.resources.files
|
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient
|
|
||||||
import com.owncloud.android.lib.common.http.HttpConstants
|
|
||||||
import com.owncloud.android.lib.common.http.methods.webdav.DavUtils
|
|
||||||
import com.owncloud.android.lib.common.http.methods.webdav.PropfindMethod
|
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperation
|
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
|
||||||
import timber.log.Timber
|
|
||||||
import java.net.URL
|
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Operation to get the base url, which might differ in case of a redirect.
|
|
||||||
*
|
|
||||||
* @author Christian Schabesberger
|
|
||||||
*/
|
|
||||||
|
|
||||||
class GetBaseUrlRemoteOperation : RemoteOperation<String?>() {
|
|
||||||
override fun run(client: OwnCloudClient): RemoteOperationResult<String?> {
|
|
||||||
return try {
|
|
||||||
val stringUrl = client.baseFilesWebDavUri.toString()
|
|
||||||
|
|
||||||
val propFindMethod = PropfindMethod(URL(stringUrl), 0, DavUtils.allPropset).apply {
|
|
||||||
setReadTimeout(TIMEOUT, TimeUnit.SECONDS)
|
|
||||||
setConnectionTimeout(TIMEOUT, TimeUnit.SECONDS)
|
|
||||||
}
|
|
||||||
|
|
||||||
val status = client.executeHttpMethod(propFindMethod)
|
|
||||||
|
|
||||||
if (isSuccess(status)) {
|
|
||||||
RemoteOperationResult<String?>(RemoteOperationResult.ResultCode.OK).apply {
|
|
||||||
data = propFindMethod.getFinalUrl().toString()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
RemoteOperationResult<String?>(propFindMethod).apply {
|
|
||||||
data = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Timber.e(e, "Could not get actuall (or redirected) base URL from base url (/).")
|
|
||||||
RemoteOperationResult<String?>(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun isSuccess(status: Int) = status == HttpConstants.HTTP_OK || status == HttpConstants.HTTP_MULTI_STATUS
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
/**
|
|
||||||
* Maximum time to wait for a response from the server in milliseconds.
|
|
||||||
*/
|
|
||||||
private const val TIMEOUT = 10_000L
|
|
||||||
}
|
|
||||||
}
|
|
@ -76,8 +76,7 @@ public class ReadRemoteFileOperation extends RemoteOperation<RemoteFile> {
|
|||||||
/// take the duty of check the server for the current state of the file there
|
/// take the duty of check the server for the current state of the file there
|
||||||
try {
|
try {
|
||||||
// remote request
|
// remote request
|
||||||
propfind = new PropfindMethod(
|
propfind = new PropfindMethod(new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath)),
|
||||||
new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath)),
|
|
||||||
DEPTH_0,
|
DEPTH_0,
|
||||||
DavUtils.getAllPropset());
|
DavUtils.getAllPropset());
|
||||||
|
|
||||||
|
@ -77,6 +77,8 @@ public class ReadRemoteFolderOperation extends RemoteOperation<ArrayList<RemoteF
|
|||||||
DavConstants.DEPTH_1,
|
DavConstants.DEPTH_1,
|
||||||
DavUtils.getAllPropset());
|
DavUtils.getAllPropset());
|
||||||
|
|
||||||
|
client.setFollowRedirects(true);
|
||||||
|
|
||||||
int status = client.executeHttpMethod(propfindMethod);
|
int status = client.executeHttpMethod(propfindMethod);
|
||||||
|
|
||||||
if (isSuccess(status)) {
|
if (isSuccess(status)) {
|
||||||
|
@ -91,8 +91,7 @@ public class RenameRemoteFileOperation extends RemoteOperation {
|
|||||||
return new RemoteOperationResult<>(ResultCode.INVALID_OVERWRITE);
|
return new RemoteOperationResult<>(ResultCode.INVALID_OVERWRITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
final MoveMethod move = new MoveMethod(
|
final MoveMethod move = new MoveMethod(new URL(client.getUserFilesWebDavUri() +
|
||||||
new URL(client.getUserFilesWebDavUri() +
|
|
||||||
WebdavUtils.encodePath(mOldRemotePath)),
|
WebdavUtils.encodePath(mOldRemotePath)),
|
||||||
client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mNewRemotePath), false);
|
client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mNewRemotePath), false);
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ class UploadFileFromContentUriOperation(
|
|||||||
|
|
||||||
override fun run(client: OwnCloudClient): RemoteOperationResult<Unit> {
|
override fun run(client: OwnCloudClient): RemoteOperationResult<Unit> {
|
||||||
val putMethod = PutMethod(URL(client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(uploadPath)), requestBody).apply {
|
val putMethod = PutMethod(URL(client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(uploadPath)), requestBody).apply {
|
||||||
retryOnConnectionFailure = false
|
setRetryOnConnectionFailure(false)
|
||||||
addRequestHeader(HttpConstants.OC_TOTAL_LENGTH_HEADER, requestBody.contentLength().toString())
|
addRequestHeader(HttpConstants.OC_TOTAL_LENGTH_HEADER, requestBody.contentLength().toString())
|
||||||
addRequestHeader(HttpConstants.OC_X_OC_MTIME_HEADER, lastModified)
|
addRequestHeader(HttpConstants.OC_X_OC_MTIME_HEADER, lastModified)
|
||||||
}
|
}
|
||||||
|
@ -92,8 +92,7 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation
|
|||||||
result = new RemoteOperationResult<>(new OperationCancelledException());
|
result = new RemoteOperationResult<>(new OperationCancelledException());
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
mPutMethod = new PutMethod(
|
mPutMethod = new PutMethod(new URL(uriPrefix + File.separator + chunkIndex), mFileRequestBody);
|
||||||
new URL(uriPrefix + File.separator + chunkIndex), mFileRequestBody);
|
|
||||||
|
|
||||||
if (chunkIndex == chunkCount - 1) {
|
if (chunkIndex == chunkCount - 1) {
|
||||||
// Added a high timeout to the last chunk due to when the last chunk
|
// Added a high timeout to the last chunk due to when the last chunk
|
||||||
|
@ -1,26 +1,22 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
/**
|
||||||
* Copyright (C) 2022 ownCloud GmbH.
|
* ownCloud Android client application
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* @author Abel García de Prada
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* Copyright (C) 2020 ownCloud GmbH.
|
||||||
* 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
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* all copies or substantial portions of the Software.
|
* it under the terms of the GNU General Public License version 2,
|
||||||
|
* as published by the Free Software Foundation.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
* GNU General Public License for more details.
|
||||||
* 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.
|
|
||||||
*
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.owncloud.android.lib.resources.files.services.implementation
|
package com.owncloud.android.lib.resources.files.services.implementation
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient
|
import com.owncloud.android.lib.common.OwnCloudClient
|
||||||
@ -33,6 +29,6 @@ class OCFileService(override val client: OwnCloudClient) :
|
|||||||
override fun checkPathExistence(path: String, isUserLogged: Boolean): RemoteOperationResult<Boolean> =
|
override fun checkPathExistence(path: String, isUserLogged: Boolean): RemoteOperationResult<Boolean> =
|
||||||
CheckPathExistenceRemoteOperation(
|
CheckPathExistenceRemoteOperation(
|
||||||
remotePath = path,
|
remotePath = path,
|
||||||
isUserLoggedIn = isUserLogged
|
isUserLogged = isUserLogged
|
||||||
).execute(client)
|
).execute(client)
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,6 @@ class GetOIDCDiscoveryRemoteOperation : RemoteOperation<OIDCDiscoveryResponse>()
|
|||||||
addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)
|
addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)
|
||||||
}
|
}
|
||||||
|
|
||||||
getMethod.followRedirects = true
|
|
||||||
val status = client.executeHttpMethod(getMethod)
|
val status = client.executeHttpMethod(getMethod)
|
||||||
|
|
||||||
val responseBody = getMethod.getResponseBodyAsString()
|
val responseBody = getMethod.getResponseBodyAsString()
|
||||||
|
@ -138,6 +138,7 @@ class CreateRemoteShareOperation(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun createFormBody(): FormBody {
|
private fun createFormBody(): FormBody {
|
||||||
|
|
||||||
val formBodyBuilder = FormBody.Builder()
|
val formBodyBuilder = FormBody.Builder()
|
||||||
.add(PARAM_PATH, remoteFilePath)
|
.add(PARAM_PATH, remoteFilePath)
|
||||||
.add(PARAM_SHARE_TYPE, shareType.value.toString())
|
.add(PARAM_SHARE_TYPE, shareType.value.toString())
|
||||||
|
@ -104,7 +104,6 @@ class RemoveRemoteShareOperation(private val remoteShareId: String) : RemoteOper
|
|||||||
|
|
||||||
override fun run(client: OwnCloudClient): RemoteOperationResult<ShareResponse> {
|
override fun run(client: OwnCloudClient): RemoteOperationResult<ShareResponse> {
|
||||||
|
|
||||||
|
|
||||||
val requestUri = buildRequestUri(client.baseUri)
|
val requestUri = buildRequestUri(client.baseUri)
|
||||||
|
|
||||||
val deleteMethod = DeleteMethod(URL(requestUri.toString())).apply {
|
val deleteMethod = DeleteMethod(URL(requestUri.toString())).apply {
|
||||||
|
@ -195,7 +195,6 @@ class UpdateRemoteShareOperation
|
|||||||
return formBodyBuilder
|
return formBodyBuilder
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun run(client: OwnCloudClient): RemoteOperationResult<ShareResponse> {
|
override fun run(client: OwnCloudClient): RemoteOperationResult<ShareResponse> {
|
||||||
val requestUri = buildRequestUri(client.baseUri)
|
val requestUri = buildRequestUri(client.baseUri)
|
||||||
|
|
||||||
@ -206,6 +205,7 @@ class UpdateRemoteShareOperation
|
|||||||
addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)
|
addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
val status = client.executeHttpMethod(putMethod)
|
val status = client.executeHttpMethod(putMethod)
|
||||||
val response = putMethod.getResponseBodyAsString()
|
val response = putMethod.getResponseBodyAsString()
|
||||||
|
@ -1,27 +1,21 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
/**
|
||||||
* Copyright (C) 2022 ownCloud GmbH.
|
* ownCloud Android client application
|
||||||
*
|
*
|
||||||
* @author David González Verdugo
|
* @author David González Verdugo
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Copyright (C) 2020 ownCloud GmbH.
|
||||||
* 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
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* all copies or substantial portions of the Software.
|
* it under the terms of the GNU General Public License version 2,
|
||||||
|
* as published by the Free Software Foundation.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
* GNU General Public License for more details.
|
||||||
* 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.
|
|
||||||
*
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.owncloud.android.lib.resources.shares.services
|
package com.owncloud.android.lib.resources.shares.services
|
||||||
|
@ -1,28 +1,22 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
/**
|
||||||
* Copyright (C) 2022 ownCloud GmbH.
|
* ownCloud Android client application
|
||||||
*
|
*
|
||||||
* @author Christian Schabesberger
|
* @author Christian Schabesberger
|
||||||
* @author David González Verdugo
|
* @author David González Verdugo
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Copyright (C) 2020 ownCloud GmbH.
|
||||||
* 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
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* all copies or substantial portions of the Software.
|
* it under the terms of the GNU General Public License version 2,
|
||||||
|
* as published by the Free Software Foundation.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
* GNU General Public License for more details.
|
||||||
* 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.
|
|
||||||
*
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.owncloud.android.lib.resources.shares.services
|
package com.owncloud.android.lib.resources.shares.services
|
||||||
|
@ -1,27 +1,21 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
/**
|
||||||
* Copyright (C) 2022 ownCloud GmbH.
|
* ownCloud Android client application
|
||||||
*
|
*
|
||||||
* @author David González Verdugo
|
* @author David González Verdugo
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Copyright (C) 2020 ownCloud GmbH.
|
||||||
* 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
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* all copies or substantial portions of the Software.
|
* it under the terms of the GNU General Public License version 2,
|
||||||
*
|
* as published by the Free Software Foundation.
|
||||||
* 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.
|
|
||||||
*
|
*
|
||||||
|
* 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 General Public License for more details.
|
||||||
|
* <p>
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.owncloud.android.lib.resources.shares.services.implementation
|
package com.owncloud.android.lib.resources.shares.services.implementation
|
||||||
|
@ -1,26 +1,21 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
/**
|
||||||
* Copyright (C) 2022 ownCloud GmbH.
|
* ownCloud Android client application
|
||||||
*
|
*
|
||||||
* @author David González Verdugo
|
* @author David González Verdugo
|
||||||
* 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
|
* Copyright (C) 2020 ownCloud GmbH.
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
* it under the terms of the GNU General Public License version 2,
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
* as published by the Free Software Foundation.
|
||||||
* 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.
|
|
||||||
*
|
*
|
||||||
|
* 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 General Public License for more details.
|
||||||
|
* <p>
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.owncloud.android.lib.resources.shares.services.implementation
|
package com.owncloud.android.lib.resources.shares.services.implementation
|
||||||
|
@ -74,7 +74,7 @@ class GetRemoteCapabilitiesOperation : RemoteOperation<RemoteCapability>() {
|
|||||||
val moshi: Moshi = Moshi.Builder().build()
|
val moshi: Moshi = Moshi.Builder().build()
|
||||||
val type: Type = Types.newParameterizedType(CommonOcsResponse::class.java, CapabilityResponse::class.java)
|
val type: Type = Types.newParameterizedType(CommonOcsResponse::class.java, CapabilityResponse::class.java)
|
||||||
val adapter: JsonAdapter<CommonOcsResponse<CapabilityResponse>> = moshi.adapter(type)
|
val adapter: JsonAdapter<CommonOcsResponse<CapabilityResponse>> = moshi.adapter(type)
|
||||||
val commonResponse: CommonOcsResponse<CapabilityResponse>? = response?.let { adapter.fromJson(it) }
|
val commonResponse: CommonOcsResponse<CapabilityResponse>? = adapter.fromJson(response)
|
||||||
|
|
||||||
result = RemoteOperationResult(OK)
|
result = RemoteOperationResult(OK)
|
||||||
result.data = commonResponse?.ocs?.data?.toRemoteCapability()
|
result.data = commonResponse?.ocs?.data?.toRemoteCapability()
|
||||||
|
@ -30,7 +30,9 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
|||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode
|
||||||
import com.owncloud.android.lib.resources.status.HttpScheme.HTTPS_PREFIX
|
import com.owncloud.android.lib.resources.status.HttpScheme.HTTPS_PREFIX
|
||||||
import com.owncloud.android.lib.resources.status.HttpScheme.HTTP_PREFIX
|
import com.owncloud.android.lib.resources.status.HttpScheme.HTTP_PREFIX
|
||||||
|
import com.owncloud.android.lib.resources.status.HttpScheme.HTTP_SCHEME
|
||||||
import org.json.JSONException
|
import org.json.JSONException
|
||||||
|
import timber.log.Timber
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the server is valid
|
* Checks if the server is valid
|
||||||
@ -43,25 +45,27 @@ import org.json.JSONException
|
|||||||
class GetRemoteStatusOperation : RemoteOperation<RemoteServerInfo>() {
|
class GetRemoteStatusOperation : RemoteOperation<RemoteServerInfo>() {
|
||||||
|
|
||||||
public override fun run(client: OwnCloudClient): RemoteOperationResult<RemoteServerInfo> {
|
public override fun run(client: OwnCloudClient): RemoteOperationResult<RemoteServerInfo> {
|
||||||
if (!usesHttpOrHttps(client.baseUri)) {
|
client.baseUri = buildFullHttpsUrl(client.baseUri)
|
||||||
client.baseUri = buildFullHttpsUrl(client.baseUri)
|
|
||||||
|
var result = tryToConnect(client)
|
||||||
|
if (!(result.code == ResultCode.OK || result.code == ResultCode.OK_SSL) && !result.isSslRecoverableException) {
|
||||||
|
Timber.d("Establishing secure connection failed, trying non secure connection")
|
||||||
|
client.baseUri = client.baseUri.buildUpon().scheme(HTTP_SCHEME).build()
|
||||||
|
result = tryToConnect(client)
|
||||||
}
|
}
|
||||||
return tryToConnect(client)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun updateClientBaseUrl(client: OwnCloudClient, newBaseUrl: String) {
|
return result
|
||||||
client.baseUri = Uri.parse(newBaseUrl)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun tryToConnect(client: OwnCloudClient): RemoteOperationResult<RemoteServerInfo> {
|
private fun tryToConnect(client: OwnCloudClient): RemoteOperationResult<RemoteServerInfo> {
|
||||||
val baseUrl = client.baseUri.toString()
|
val baseUrl = client.baseUri.toString()
|
||||||
|
client.setFollowRedirects(false)
|
||||||
return try {
|
return try {
|
||||||
val requester = StatusRequester()
|
val requester = StatusRequester()
|
||||||
val requestResult = requester.request(baseUrl, client)
|
val requestResult = requester.requestAndFollowRedirects(baseUrl, client)
|
||||||
val result = requester.handleRequestResult(requestResult, baseUrl)
|
requester.handleRequestResult(requestResult, baseUrl).also {
|
||||||
updateClientBaseUrl(client, result.data.baseUrl)
|
client.baseUri = Uri.parse(it.data.baseUrl)
|
||||||
return result
|
}
|
||||||
} catch (e: JSONException) {
|
} catch (e: JSONException) {
|
||||||
RemoteOperationResult(ResultCode.INSTANCE_NOT_CONFIGURED)
|
RemoteOperationResult(ResultCode.INSTANCE_NOT_CONFIGURED)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
@ -61,7 +61,6 @@ data class RemoteCapability(
|
|||||||
var filesSharingResharing: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
|
var filesSharingResharing: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
|
||||||
var filesSharingFederationOutgoing: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
|
var filesSharingFederationOutgoing: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
|
||||||
var filesSharingFederationIncoming: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
|
var filesSharingFederationIncoming: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
|
||||||
var filesSharingUserProfilePicture: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
|
|
||||||
|
|
||||||
// Files
|
// Files
|
||||||
var filesBigFileChunking: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
|
var filesBigFileChunking: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
|
||||||
|
@ -47,7 +47,7 @@ internal class StatusRequester {
|
|||||||
redirectedUrl: String
|
redirectedUrl: String
|
||||||
) = redirectedToNonSecureLocationBefore ||
|
) = redirectedToNonSecureLocationBefore ||
|
||||||
(baseUrl.startsWith(HTTPS_SCHEME) &&
|
(baseUrl.startsWith(HTTPS_SCHEME) &&
|
||||||
!redirectedUrl.startsWith(HTTPS_SCHEME))
|
!redirectedUrl.startsWith(HTTPS_SCHEME))
|
||||||
|
|
||||||
fun updateLocationWithRedirectPath(oldLocation: String, redirectedLocation: String): String {
|
fun updateLocationWithRedirectPath(oldLocation: String, redirectedLocation: String): String {
|
||||||
/** Redirection with different endpoint.
|
/** Redirection with different endpoint.
|
||||||
@ -73,18 +73,36 @@ internal class StatusRequester {
|
|||||||
data class RequestResult(
|
data class RequestResult(
|
||||||
val getMethod: GetMethod,
|
val getMethod: GetMethod,
|
||||||
val status: Int,
|
val status: Int,
|
||||||
|
val redirectedToUnsecureLocation: Boolean,
|
||||||
val lastLocation: String
|
val lastLocation: String
|
||||||
)
|
)
|
||||||
|
|
||||||
fun request(baseLocation: String, client: OwnCloudClient): RequestResult {
|
fun requestAndFollowRedirects(baseLocation: String, client: OwnCloudClient): RequestResult {
|
||||||
val currentLocation = baseLocation + OwnCloudClient.STATUS_PATH
|
var currentLocation = baseLocation + OwnCloudClient.STATUS_PATH
|
||||||
|
var redirectedToUnsecureLocation = false
|
||||||
var status: Int
|
var status: Int
|
||||||
val getMethod = getGetMethod(currentLocation)
|
|
||||||
|
|
||||||
getMethod.followPermanentRedirects = true
|
while (true) {
|
||||||
status = client.executeHttpMethod(getMethod)
|
val getMethod = getGetMethod(currentLocation)
|
||||||
|
|
||||||
return RequestResult(getMethod, status, getMethod.getFinalUrl().toString())
|
status = client.executeHttpMethod(getMethod)
|
||||||
|
val result =
|
||||||
|
if (status.isSuccess()) RemoteOperationResult<OwnCloudVersion>(RemoteOperationResult.ResultCode.OK)
|
||||||
|
else RemoteOperationResult(getMethod)
|
||||||
|
|
||||||
|
if (result.redirectedLocation.isNullOrEmpty() || result.isSuccess) {
|
||||||
|
return RequestResult(getMethod, status, redirectedToUnsecureLocation, currentLocation)
|
||||||
|
} else {
|
||||||
|
val nextLocation = updateLocationWithRedirectPath(currentLocation, result.redirectedLocation)
|
||||||
|
redirectedToUnsecureLocation =
|
||||||
|
isRedirectedToNonSecureConnection(
|
||||||
|
redirectedToUnsecureLocation,
|
||||||
|
currentLocation,
|
||||||
|
nextLocation
|
||||||
|
)
|
||||||
|
currentLocation = nextLocation
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Int.isSuccess() = this == HttpConstants.HTTP_OK
|
private fun Int.isSuccess() = this == HttpConstants.HTTP_OK
|
||||||
@ -104,8 +122,12 @@ internal class StatusRequester {
|
|||||||
// the version object will be returned even if the version is invalid, no error code;
|
// the version object will be returned even if the version is invalid, no error code;
|
||||||
// every app will decide how to act if (ocVersion.isVersionValid() == false)
|
// every app will decide how to act if (ocVersion.isVersionValid() == false)
|
||||||
val result: RemoteOperationResult<RemoteServerInfo> =
|
val result: RemoteOperationResult<RemoteServerInfo> =
|
||||||
if (baseUrl.startsWith(HTTPS_SCHEME)) RemoteOperationResult(RemoteOperationResult.ResultCode.OK_SSL)
|
if (requestResult.redirectedToUnsecureLocation) {
|
||||||
else RemoteOperationResult(RemoteOperationResult.ResultCode.OK_NO_SSL)
|
RemoteOperationResult(RemoteOperationResult.ResultCode.OK_REDIRECT_TO_NON_SECURE_CONNECTION)
|
||||||
|
} else {
|
||||||
|
if (baseUrl.startsWith(HTTPS_SCHEME)) RemoteOperationResult(RemoteOperationResult.ResultCode.OK_SSL)
|
||||||
|
else RemoteOperationResult(RemoteOperationResult.ResultCode.OK_NO_SSL)
|
||||||
|
}
|
||||||
val finalUrl = URL(requestResult.lastLocation)
|
val finalUrl = URL(requestResult.lastLocation)
|
||||||
val finalBaseUrl = URL(
|
val finalBaseUrl = URL(
|
||||||
finalUrl.protocol,
|
finalUrl.protocol,
|
||||||
|
@ -69,8 +69,7 @@ data class CapabilityResponse(
|
|||||||
filesUndelete = CapabilityBooleanType.fromBooleanValue(capabilities?.fileCapabilities?.undelete),
|
filesUndelete = CapabilityBooleanType.fromBooleanValue(capabilities?.fileCapabilities?.undelete),
|
||||||
filesVersioning = CapabilityBooleanType.fromBooleanValue(capabilities?.fileCapabilities?.versioning),
|
filesVersioning = CapabilityBooleanType.fromBooleanValue(capabilities?.fileCapabilities?.versioning),
|
||||||
filesSharingFederationIncoming = CapabilityBooleanType.fromBooleanValue(capabilities?.fileSharingCapabilities?.fileSharingFederation?.incoming),
|
filesSharingFederationIncoming = CapabilityBooleanType.fromBooleanValue(capabilities?.fileSharingCapabilities?.fileSharingFederation?.incoming),
|
||||||
filesSharingFederationOutgoing = CapabilityBooleanType.fromBooleanValue(capabilities?.fileSharingCapabilities?.fileSharingFederation?.outgoing),
|
filesSharingFederationOutgoing = CapabilityBooleanType.fromBooleanValue(capabilities?.fileSharingCapabilities?.fileSharingFederation?.outgoing)
|
||||||
filesSharingUserProfilePicture = CapabilityBooleanType.fromBooleanValue(capabilities?.fileSharingCapabilities?.fileSharingUser?.profilePicture),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,9 +99,7 @@ data class FileSharingCapabilities(
|
|||||||
@Json(name = "resharing")
|
@Json(name = "resharing")
|
||||||
val fileSharingReSharing: Boolean?,
|
val fileSharingReSharing: Boolean?,
|
||||||
@Json(name = "federation")
|
@Json(name = "federation")
|
||||||
val fileSharingFederation: FileSharingFederation?,
|
val fileSharingFederation: FileSharingFederation?
|
||||||
@Json(name = "user")
|
|
||||||
val fileSharingUser: FileSharingUser?,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
@ -150,12 +147,6 @@ data class FileSharingFederation(
|
|||||||
val outgoing: Boolean?
|
val outgoing: Boolean?
|
||||||
)
|
)
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
|
||||||
data class FileSharingUser(
|
|
||||||
@Json(name = "profile_picture")
|
|
||||||
val profilePicture: Boolean?,
|
|
||||||
)
|
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class FileCapabilities(
|
data class FileCapabilities(
|
||||||
val bigfilechunking: Boolean?,
|
val bigfilechunking: Boolean?,
|
||||||
|
@ -1,27 +1,21 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
/**
|
||||||
* Copyright (C) 2022 ownCloud GmbH.
|
* ownCloud Android client application
|
||||||
*
|
*
|
||||||
* @author David González Verdugo
|
* @author David González Verdugo
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Copyright (C) 2020 ownCloud GmbH.
|
||||||
* 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
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* all copies or substantial portions of the Software.
|
* it under the terms of the GNU General Public License version 2,
|
||||||
|
* as published by the Free Software Foundation.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
* GNU General Public License for more details.
|
||||||
* 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.
|
|
||||||
*
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.owncloud.android.lib.resources.status.services
|
package com.owncloud.android.lib.resources.status.services
|
||||||
|
@ -23,13 +23,12 @@
|
|||||||
*/
|
*/
|
||||||
package com.owncloud.android.lib.resources.status.services
|
package com.owncloud.android.lib.resources.status.services
|
||||||
|
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient
|
import com.owncloud.android.lib.common.OwnCloudClient
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
||||||
import com.owncloud.android.lib.resources.status.RemoteServerInfo
|
import com.owncloud.android.lib.resources.status.RemoteServerInfo
|
||||||
|
|
||||||
interface ServerInfoService {
|
interface ServerInfoService {
|
||||||
fun checkPathExistence(path: String, isUserLoggedIn: Boolean, client: OwnCloudClient): RemoteOperationResult<Boolean>
|
fun checkPathExistence(path: String, isUserLogged: Boolean, client: OwnCloudClient): RemoteOperationResult<Boolean>
|
||||||
|
|
||||||
fun getRemoteStatus(path: String, client: OwnCloudClient): RemoteOperationResult<RemoteServerInfo>
|
fun getRemoteStatus(path: String, client: OwnCloudClient): RemoteOperationResult<RemoteServerInfo>
|
||||||
}
|
}
|
||||||
|
@ -1,27 +1,21 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
/**
|
||||||
* Copyright (C) 2022 ownCloud GmbH.
|
* ownCloud Android client application
|
||||||
*
|
*
|
||||||
* @author David González Verdugo
|
* @author David González Verdugo
|
||||||
*
|
|
||||||
* 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
|
* Copyright (C) 2020 ownCloud GmbH.
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
* it under the terms of the GNU General Public License version 2,
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
* as published by the Free Software Foundation.
|
||||||
* 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.
|
|
||||||
*
|
*
|
||||||
|
* 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.owncloud.android.lib.resources.status.services.implementation
|
package com.owncloud.android.lib.resources.status.services.implementation
|
||||||
|
@ -1,32 +1,24 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
/**
|
||||||
* Copyright (C) 2022 ownCloud GmbH.
|
* ownCloud Android client application
|
||||||
*
|
*
|
||||||
* @author Abel García de Prada
|
* @author Abel García de Prada
|
||||||
|
* Copyright (C) 2020 ownCloud GmbH.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* it under the terms of the GNU General Public License version 2,
|
||||||
* in the Software without restriction, including without limitation the rights
|
* as published by the Free Software Foundation.
|
||||||
* 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
|
* This program is distributed in the hope that it will be useful,
|
||||||
* all copies or substantial portions of the Software.
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
*
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
* GNU General Public License for more details.
|
||||||
* 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.
|
|
||||||
*
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.owncloud.android.lib.resources.status.services.implementation
|
package com.owncloud.android.lib.resources.status.services.implementation
|
||||||
|
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient
|
import com.owncloud.android.lib.common.OwnCloudClient
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
||||||
import com.owncloud.android.lib.resources.files.CheckPathExistenceRemoteOperation
|
import com.owncloud.android.lib.resources.files.CheckPathExistenceRemoteOperation
|
||||||
@ -38,12 +30,12 @@ class OCServerInfoService : ServerInfoService {
|
|||||||
|
|
||||||
override fun checkPathExistence(
|
override fun checkPathExistence(
|
||||||
path: String,
|
path: String,
|
||||||
isUserLoggedIn: Boolean,
|
isUserLogged: Boolean,
|
||||||
client: OwnCloudClient
|
client: OwnCloudClient
|
||||||
): RemoteOperationResult<Boolean> =
|
): RemoteOperationResult<Boolean> =
|
||||||
CheckPathExistenceRemoteOperation(
|
CheckPathExistenceRemoteOperation(
|
||||||
remotePath = path,
|
remotePath = path,
|
||||||
isUserLoggedIn = true
|
isUserLogged = true
|
||||||
).execute(client)
|
).execute(client)
|
||||||
|
|
||||||
override fun getRemoteStatus(
|
override fun getRemoteStatus(
|
||||||
|
@ -1,27 +1,20 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
/**
|
||||||
* Copyright (C) 2022 ownCloud GmbH.
|
* ownCloud Android client application
|
||||||
*
|
*
|
||||||
* @author Abel García de Prada
|
* @author Abel García de Prada
|
||||||
|
* Copyright (C) 2020 ownCloud GmbH.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* it under the terms of the GNU General Public License version 2,
|
||||||
* in the Software without restriction, including without limitation the rights
|
* as published by the Free Software Foundation.
|
||||||
* 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.
|
|
||||||
*
|
*
|
||||||
|
* 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 General Public License for more details.
|
||||||
|
* <p>
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.owncloud.android.lib.resources.users.services.implementation
|
package com.owncloud.android.lib.resources.users.services.implementation
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
|
||||||
* Copyright (C) 2020 ownCloud GmbH.
|
|
||||||
*
|
|
||||||
* 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 com.owncloud.android.lib.common.http
|
|
||||||
|
|
||||||
object DebugInterceptorFactory {
|
|
||||||
fun getInterceptor() = DummyInterceptor()
|
|
||||||
}
|
|
31
sample_client/build.gradle
Normal file
31
sample_client/build.gradle
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
apply plugin: 'com.android.application'
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation project(':owncloudComLibrary')
|
||||||
|
}
|
||||||
|
|
||||||
|
android {
|
||||||
|
compileSdkVersion 29
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
minSdkVersion 21
|
||||||
|
targetSdkVersion 29
|
||||||
|
|
||||||
|
// This is pretty ugly but manifest placeholders don't seem to work very well when using different modules
|
||||||
|
// See https://github.com/openid/AppAuth-Android/issues/325
|
||||||
|
manifestPlaceholders = [appAuthRedirectScheme: '']
|
||||||
|
}
|
||||||
|
|
||||||
|
lintOptions {
|
||||||
|
abortOnError false
|
||||||
|
}
|
||||||
|
|
||||||
|
packagingOptions {
|
||||||
|
exclude 'META-INF/LICENSE.txt'
|
||||||
|
}
|
||||||
|
|
||||||
|
compileOptions {
|
||||||
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
|
targetCompatibility JavaVersion.VERSION_1_8
|
||||||
|
}
|
||||||
|
}
|
BIN
sample_client/src/assets/oc_sample.png
Normal file
BIN
sample_client/src/assets/oc_sample.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 MiB |
1
sample_client/src/assets/oc_sample.txt
Normal file
1
sample_client/src/assets/oc_sample.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
Testing ownCloud uploads
|
47
sample_client/src/main/AndroidManifest.xml
Normal file
47
sample_client/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- ownCloud Android Library is available under MIT license
|
||||||
|
Copyright (C) 2016 ownCloud GmbH.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
-->
|
||||||
|
|
||||||
|
<manifest package="com.owncloud.android.lib.sampleclient"
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:versionCode="1"
|
||||||
|
android:versionName="1.0">
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
<application
|
||||||
|
android:icon="@drawable/ic_launcher"
|
||||||
|
android:label="@string/app_name">
|
||||||
|
<activity
|
||||||
|
android:name="MainActivity"
|
||||||
|
android:configChanges="orientation|keyboardHidden"
|
||||||
|
android:label="@string/app_name"
|
||||||
|
android:screenOrientation="portrait"
|
||||||
|
>
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
</application>
|
||||||
|
</manifest>
|
@ -21,11 +21,26 @@
|
|||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
package com.owncloud.android.lib.sampleclient;
|
||||||
|
|
||||||
package com.owncloud.android.lib.common.http
|
import android.content.Context;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import okhttp3.Interceptor
|
import com.owncloud.android.lib.resources.files.RemoteFile;
|
||||||
|
|
||||||
|
public class FilesArrayAdapter extends ArrayAdapter<RemoteFile> {
|
||||||
|
|
||||||
|
public FilesArrayAdapter(Context context, int resource) {
|
||||||
|
super(context, resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
|
TextView textView = (TextView) super.getView(position, convertView, parent);
|
||||||
|
textView.setText(getItem(position).getRemotePath());
|
||||||
|
return textView;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class DummyInterceptor : Interceptor {
|
|
||||||
override fun intercept(chain: Interceptor.Chain) = chain.proceed(chain.request())
|
|
||||||
}
|
|
@ -0,0 +1,300 @@
|
|||||||
|
/* ownCloud Android Library is available under MIT license
|
||||||
|
* Copyright (C) 2020 ownCloud GmbH.
|
||||||
|
*
|
||||||
|
* 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 com.owncloud.android.lib.sampleclient;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.pm.PackageInfo;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.res.AssetManager;
|
||||||
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.ListView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
|
import com.owncloud.android.lib.common.OwnCloudClientFactory;
|
||||||
|
import com.owncloud.android.lib.common.SingleSessionManager;
|
||||||
|
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory;
|
||||||
|
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
|
||||||
|
import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;
|
||||||
|
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||||
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
|
import com.owncloud.android.lib.resources.files.DownloadRemoteFileOperation;
|
||||||
|
import com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation;
|
||||||
|
import com.owncloud.android.lib.resources.files.RemoteFile;
|
||||||
|
import com.owncloud.android.lib.resources.files.RemoveRemoteFileOperation;
|
||||||
|
import com.owncloud.android.lib.resources.files.UploadRemoteFileOperation;
|
||||||
|
import info.hannes.timber.DebugTree;
|
||||||
|
import timber.log.Timber;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MainActivity extends Activity implements OnRemoteOperationListener, OnDatatransferProgressListener {
|
||||||
|
|
||||||
|
private Handler mHandler;
|
||||||
|
private OwnCloudClient mClient;
|
||||||
|
private FilesArrayAdapter mFilesAdapter;
|
||||||
|
private View mFrame;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the activity is first created.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.main);
|
||||||
|
|
||||||
|
Timber.plant(new DebugTree());
|
||||||
|
mHandler = new Handler();
|
||||||
|
|
||||||
|
final Uri serverUri = Uri.parse(getString(R.string.server_base_url));
|
||||||
|
|
||||||
|
SingleSessionManager.setUserAgent(getUserAgent());
|
||||||
|
mClient = OwnCloudClientFactory.createOwnCloudClient(serverUri, this, true);
|
||||||
|
|
||||||
|
mClient.setCredentials(
|
||||||
|
OwnCloudCredentialsFactory.newBasicCredentials(
|
||||||
|
getString(R.string.username),
|
||||||
|
getString(R.string.password)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
mFilesAdapter = new FilesArrayAdapter(this, R.layout.file_in_list);
|
||||||
|
((ListView) findViewById(R.id.list_view)).setAdapter(mFilesAdapter);
|
||||||
|
|
||||||
|
// TODO move to background thread or task
|
||||||
|
AssetManager assets = getAssets();
|
||||||
|
try {
|
||||||
|
String sampleFileName = getString(R.string.sample_file_name);
|
||||||
|
File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path));
|
||||||
|
upFolder.mkdir();
|
||||||
|
File upFile = new File(upFolder, sampleFileName);
|
||||||
|
FileOutputStream fos = new FileOutputStream(upFile);
|
||||||
|
InputStream is = assets.open(sampleFileName);
|
||||||
|
int count;
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
while ((count = is.read(buffer, 0, buffer.length)) >= 0) {
|
||||||
|
fos.write(buffer, 0, count);
|
||||||
|
}
|
||||||
|
is.close();
|
||||||
|
fos.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
Toast.makeText(this, R.string.error_copying_sample_file, Toast.LENGTH_SHORT).show();
|
||||||
|
Timber.e(e, getString(R.string.error_copying_sample_file));
|
||||||
|
}
|
||||||
|
|
||||||
|
mFrame = findViewById(R.id.frame);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path));
|
||||||
|
File upFile = upFolder.listFiles()[0];
|
||||||
|
upFile.delete();
|
||||||
|
upFolder.delete();
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onClickHandler(View button) {
|
||||||
|
switch (button.getId()) {
|
||||||
|
case R.id.button_refresh:
|
||||||
|
startRefresh();
|
||||||
|
break;
|
||||||
|
case R.id.button_upload:
|
||||||
|
startUpload();
|
||||||
|
break;
|
||||||
|
case R.id.button_delete_remote:
|
||||||
|
startRemoteDeletion();
|
||||||
|
break;
|
||||||
|
case R.id.button_download:
|
||||||
|
startDownload();
|
||||||
|
break;
|
||||||
|
case R.id.button_delete_local:
|
||||||
|
startLocalDeletion();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Toast.makeText(this, R.string.youre_doing_it_wrong, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startRefresh() {
|
||||||
|
ReadRemoteFolderOperation refreshOperation = new ReadRemoteFolderOperation(File.separator);
|
||||||
|
refreshOperation.execute(mClient, this, mHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startUpload() {
|
||||||
|
File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path));
|
||||||
|
File fileToUpload = upFolder.listFiles()[0];
|
||||||
|
String remotePath = File.separator + fileToUpload.getName();
|
||||||
|
String mimeType = getString(R.string.sample_file_mimetype);
|
||||||
|
|
||||||
|
// Get the last modification date of the file from the file system
|
||||||
|
long timeStampLong = fileToUpload.lastModified() / 1000;
|
||||||
|
String timeStamp = Long.toString(timeStampLong);
|
||||||
|
|
||||||
|
UploadRemoteFileOperation uploadOperation = new UploadRemoteFileOperation(fileToUpload.getAbsolutePath(),
|
||||||
|
remotePath, mimeType, timeStamp);
|
||||||
|
uploadOperation.addDatatransferProgressListener(this);
|
||||||
|
uploadOperation.execute(mClient, this, mHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startRemoteDeletion() {
|
||||||
|
File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path));
|
||||||
|
File fileToUpload = upFolder.listFiles()[0];
|
||||||
|
String remotePath = File.separator + fileToUpload.getName();
|
||||||
|
|
||||||
|
RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath);
|
||||||
|
removeOperation.execute(mClient, this, mHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startDownload() {
|
||||||
|
File downFolder = new File(getCacheDir(), getString(R.string.download_folder_path));
|
||||||
|
downFolder.mkdir();
|
||||||
|
File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path));
|
||||||
|
File fileToUpload = upFolder.listFiles()[0];
|
||||||
|
String remotePath = File.separator + fileToUpload.getName();
|
||||||
|
|
||||||
|
DownloadRemoteFileOperation downloadOperation = new DownloadRemoteFileOperation(remotePath,
|
||||||
|
downFolder.getAbsolutePath());
|
||||||
|
downloadOperation.addDatatransferProgressListener(this);
|
||||||
|
downloadOperation.execute(mClient, this, mHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startLocalDeletion() {
|
||||||
|
File downFolder = new File(getCacheDir(), getString(R.string.download_folder_path));
|
||||||
|
File downloadedFile = downFolder.listFiles()[0];
|
||||||
|
if (!downloadedFile.delete() && downloadedFile.exists()) {
|
||||||
|
Toast.makeText(this, R.string.error_deleting_local_file, Toast.LENGTH_SHORT).show();
|
||||||
|
} else {
|
||||||
|
((TextView) findViewById(R.id.download_progress)).setText("0%");
|
||||||
|
findViewById(R.id.frame).setBackgroundDrawable(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
|
||||||
|
if (!result.isSuccess()) {
|
||||||
|
Toast.makeText(this, R.string.todo_operation_finished_in_fail, Toast.LENGTH_SHORT).show();
|
||||||
|
Timber.e(result.getException(), result.getLogMessage());
|
||||||
|
|
||||||
|
} else if (operation instanceof ReadRemoteFolderOperation) {
|
||||||
|
onSuccessfulRefresh(result);
|
||||||
|
|
||||||
|
} else if (operation instanceof com.owncloud.android.lib.resources.files.UploadRemoteFileOperation) {
|
||||||
|
onSuccessfulUpload();
|
||||||
|
|
||||||
|
} else if (operation instanceof RemoveRemoteFileOperation) {
|
||||||
|
onSuccessfulRemoteDeletion();
|
||||||
|
|
||||||
|
} else if (operation instanceof DownloadRemoteFileOperation) {
|
||||||
|
onSuccessfulDownload();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
Toast.makeText(this, R.string.todo_operation_finished_in_success, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onSuccessfulRefresh(RemoteOperationResult result) {
|
||||||
|
mFilesAdapter.clear();
|
||||||
|
List<RemoteFile> files = new ArrayList<>();
|
||||||
|
for (RemoteFile remoteFile : (List<RemoteFile>) result.getData()) {
|
||||||
|
files.add(remoteFile);
|
||||||
|
}
|
||||||
|
for (RemoteFile file : files) {
|
||||||
|
mFilesAdapter.add(file);
|
||||||
|
}
|
||||||
|
mFilesAdapter.remove(mFilesAdapter.getItem(0));
|
||||||
|
mFilesAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onSuccessfulUpload() {
|
||||||
|
startRefresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onSuccessfulRemoteDeletion() {
|
||||||
|
startRefresh();
|
||||||
|
TextView progressView = findViewById(R.id.upload_progress);
|
||||||
|
if (progressView != null) {
|
||||||
|
progressView.setText("0%");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onSuccessfulDownload() {
|
||||||
|
File downFolder = new File(getCacheDir(), getString(R.string.download_folder_path));
|
||||||
|
File downloadedFile = downFolder.listFiles()[0];
|
||||||
|
BitmapDrawable bDraw = new BitmapDrawable(getResources(), downloadedFile.getAbsolutePath());
|
||||||
|
mFrame.setBackgroundDrawable(bDraw);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("SetTextI18n")
|
||||||
|
@Override
|
||||||
|
public void onTransferProgress(long progressRate, long totalTransferredSoFar, long totalToTransfer, String fileName) {
|
||||||
|
final long percentage = (totalToTransfer > 0 ? totalTransferredSoFar * 100 / totalToTransfer : 0);
|
||||||
|
final boolean upload = fileName.contains(getString(R.string.upload_folder_path));
|
||||||
|
Timber.d("progressRate %s", percentage);
|
||||||
|
mHandler.post(() -> {
|
||||||
|
TextView progressView;
|
||||||
|
if (upload) {
|
||||||
|
progressView = findViewById(R.id.upload_progress);
|
||||||
|
} else {
|
||||||
|
progressView = findViewById(R.id.download_progress);
|
||||||
|
}
|
||||||
|
if (progressView != null) {
|
||||||
|
progressView.setText(percentage + "%");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// user agent
|
||||||
|
@SuppressLint("StringFormatInvalid")
|
||||||
|
private String getUserAgent() {
|
||||||
|
String appString = getResources().getString(R.string.user_agent);
|
||||||
|
String packageName = getPackageName();
|
||||||
|
String version = "";
|
||||||
|
|
||||||
|
PackageInfo pInfo;
|
||||||
|
try {
|
||||||
|
pInfo = getPackageManager().getPackageInfo(packageName, 0);
|
||||||
|
if (pInfo != null) {
|
||||||
|
version = pInfo.versionName;
|
||||||
|
}
|
||||||
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
|
Timber.e(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mozilla/5.0 (Android) ownCloud-android/1.7.0
|
||||||
|
return String.format(appString, version);
|
||||||
|
}
|
||||||
|
}
|
BIN
sample_client/src/main/res/drawable-hdpi/ic_launcher.png
Normal file
BIN
sample_client/src/main/res/drawable-hdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.3 KiB |
BIN
sample_client/src/main/res/drawable-ldpi/ic_launcher.png
Normal file
BIN
sample_client/src/main/res/drawable-ldpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.6 KiB |
BIN
sample_client/src/main/res/drawable-mdpi/ic_launcher.png
Normal file
BIN
sample_client/src/main/res/drawable-mdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.8 KiB |
29
sample_client/src/main/res/layout/file_in_list.xml
Normal file
29
sample_client/src/main/res/layout/file_in_list.xml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- ownCloud Android Library is available under MIT license
|
||||||
|
Copyright (C) 2016 ownCloud GmbH.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
-->
|
||||||
|
|
||||||
|
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
/>
|
122
sample_client/src/main/res/layout/main.xml
Normal file
122
sample_client/src/main/res/layout/main.xml
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- ownCloud Android Library is available under MIT license
|
||||||
|
Copyright (C) 2016 ownCloud GmbH.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
-->
|
||||||
|
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/button_refresh"
|
||||||
|
style="@style/ButtonStyle"
|
||||||
|
android:layout_alignParentLeft="true"
|
||||||
|
android:layout_alignParentTop="true"
|
||||||
|
android:onClick="onClickHandler"
|
||||||
|
android:text="@string/refresh"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<ListView
|
||||||
|
android:id="@+id/list_view"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_above="@+id/button_upload"
|
||||||
|
android:layout_alignParentLeft="true"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:layout_below="@+id/button_refresh"
|
||||||
|
>
|
||||||
|
</ListView>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/button_upload"
|
||||||
|
style="@style/ButtonStyle"
|
||||||
|
android:layout_above="@+id/frame"
|
||||||
|
android:layout_alignParentLeft="true"
|
||||||
|
android:onClick="onClickHandler"
|
||||||
|
android:text="@string/upload"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/upload_progress"
|
||||||
|
style="@style/ProgressStyle"
|
||||||
|
android:layout_above="@id/frame"
|
||||||
|
android:layout_below="@id/list_view"
|
||||||
|
android:layout_toLeftOf="@+id/button_delete_remote"
|
||||||
|
android:layout_toRightOf="@id/button_upload"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="0%"
|
||||||
|
android:textSize="14sp"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@id/button_delete_remote"
|
||||||
|
style="@style/ButtonStyle"
|
||||||
|
android:layout_above="@id/frame"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:onClick="onClickHandler"
|
||||||
|
android:text="@string/delete_remote_file"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:id="@id/frame"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="@dimen/frame_height"
|
||||||
|
android:layout_above="@+id/button_download"
|
||||||
|
android:layout_alignParentLeft="true"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
>
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@id/button_download"
|
||||||
|
style="@style/ButtonStyle"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
|
android:layout_alignParentLeft="true"
|
||||||
|
android:onClick="onClickHandler"
|
||||||
|
android:text="@string/download"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/download_progress"
|
||||||
|
style="@style/ProgressStyle"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
|
android:layout_below="@id/frame"
|
||||||
|
android:layout_toLeftOf="@+id/button_delete_local"
|
||||||
|
android:layout_toRightOf="@id/button_download"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="0%"
|
||||||
|
android:textSize="14sp"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@id/button_delete_local"
|
||||||
|
style="@style/ButtonStyle"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:onClick="onClickHandler"
|
||||||
|
android:text="@string/delete_local_file"
|
||||||
|
/>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
|
|
39
sample_client/src/main/res/values-v11/styles.xml
Normal file
39
sample_client/src/main/res/values-v11/styles.xml
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- ownCloud Android Library is available under MIT license
|
||||||
|
Copyright (C) 2016 ownCloud GmbH.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
-->
|
||||||
|
|
||||||
|
<resources xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<style name="ButtonStyle" parent="@android:style/Widget.Holo.Button">
|
||||||
|
<item name="android:layout_width">120dp</item>
|
||||||
|
<item name="android:layout_height">wrap_content</item>
|
||||||
|
<item name="android:textSize">12sp</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style name="ProgressStyle" parent="@android:style/Widget.Holo.TextView">
|
||||||
|
<item name="android:layout_width">wrap_content</item>
|
||||||
|
<item name="android:layout_height">wrap_content</item>
|
||||||
|
<item name="android:textSize">12sp</item>
|
||||||
|
</style>
|
||||||
|
</resources>
|
28
sample_client/src/main/res/values/dimensions.xml
Normal file
28
sample_client/src/main/res/values/dimensions.xml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- ownCloud Android Library is available under MIT license
|
||||||
|
Copyright (C) 2016 ownCloud GmbH.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
-->
|
||||||
|
|
||||||
|
<resources>
|
||||||
|
<dimen name="frame_height">120dp</dimen>
|
||||||
|
</resources>
|
30
sample_client/src/main/res/values/setup.xml
Normal file
30
sample_client/src/main/res/values/setup.xml
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- ownCloud Android Library is available under MIT license
|
||||||
|
Copyright (C) 2020 ownCloud GmbH.
|
||||||
|
|
||||||
|
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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<resources>
|
||||||
|
<string name="server_base_url"></string>
|
||||||
|
<string name="username"></string>
|
||||||
|
<string name="password"></string>
|
||||||
|
<string name="user_agent">Mozilla/5.0 (Android) ownCloud sample </string>
|
||||||
|
</resources>
|
47
sample_client/src/main/res/values/strings.xml
Normal file
47
sample_client/src/main/res/values/strings.xml
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- ownCloud Android Library is available under MIT license
|
||||||
|
Copyright (C) 2016 ownCloud GmbH.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
-->
|
||||||
|
|
||||||
|
<resources>
|
||||||
|
<string name="app_name">ownCloud Sample Client</string>
|
||||||
|
<string name="refresh">Refresh</string>
|
||||||
|
<string name="upload">Upload</string>
|
||||||
|
<string name="delete_remote_file">Delete remote file</string>
|
||||||
|
<string name="download">Download</string>
|
||||||
|
<string name="delete_local_file">Delete local file</string>
|
||||||
|
<string name="youre_doing_it_wrong">You\'re doing it wrong</string>
|
||||||
|
<string name="todo_start_refresh">TODO: start refresh</string>
|
||||||
|
<string name="todo_start_upload">TODO: start upload</string>
|
||||||
|
<string name="todo_start_remote_deletion">TODO: start remote deletion</string>
|
||||||
|
<string name="todo_start_download">TODO: start download</string>
|
||||||
|
<string name="todo_start_local_deletion">TODO: start local deletion</string>
|
||||||
|
<string name="todo_operation_finished_in_success">TODO: operation finished in success</string>
|
||||||
|
<string name="todo_operation_finished_in_fail">TODO: operation finished in fail</string>
|
||||||
|
<string name="upload_folder_path">to_upload</string>
|
||||||
|
<string name="download_folder_path">downloaded</string>
|
||||||
|
<string name="error_copying_sample_file">Sample file could not be saved in temporal folder; upload will not work</string>
|
||||||
|
<string name="sample_file_name">oc_sample.png</string>
|
||||||
|
<string name="sample_file_mimetype">image/png</string>
|
||||||
|
<string name="error_deleting_local_file">Downloaded file could not be deleted</string>
|
||||||
|
</resources>
|
39
sample_client/src/main/res/values/styles.xml
Normal file
39
sample_client/src/main/res/values/styles.xml
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- ownCloud Android Library is available under MIT license
|
||||||
|
Copyright (C) 2016 ownCloud GmbH.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
-->
|
||||||
|
|
||||||
|
<resources xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<style name="ButtonStyle" parent="@android:style/Widget.Button">
|
||||||
|
<item name="android:layout_width">120dp</item>
|
||||||
|
<item name="android:layout_height">wrap_content</item>
|
||||||
|
<item name="android:textSize">12sp</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style name="ProgressStyle" parent="@android:style/Widget.TextView">
|
||||||
|
<item name="android:layout_width">wrap_content</item>
|
||||||
|
<item name="android:layout_height">wrap_content</item>
|
||||||
|
<item name="android:textSize">12sp</item>
|
||||||
|
</style>
|
||||||
|
</resources>
|
@ -1 +1,2 @@
|
|||||||
include ':owncloudComLibrary'
|
include ':owncloudComLibrary'
|
||||||
|
include ':sample_client'
|
Loading…
x
Reference in New Issue
Block a user