Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
e
os
AccountManager
Commits
231e54db
Commit
231e54db
authored
Sep 29, 2021
by
Ricki Hirner
Browse files
Lint
parent
6e502ae8
Changes
8
Hide whitespace changes
Inline
Side-by-side
app/build.gradle
View file @
231e54db
...
...
@@ -19,7 +19,7 @@ android {
defaultConfig
{
applicationId
"at.bitfire.davdroid"
versionCode
40000000
0
versionCode
40000000
1
buildConfigField
"long"
,
"buildTime"
,
System
.
currentTimeMillis
()
+
"L"
minSdkVersion
21
// Android 5
...
...
app/src/main/java/at/bitfire/davdroid/ui/webdav/WebdavMountsActivity.kt
View file @
231e54db
...
...
@@ -106,10 +106,10 @@ class WebdavMountsActivity: AppCompatActivity() {
if
(
info
.
rootDocument
?.
quotaUsed
!=
null
||
info
.
rootDocument
?.
quotaAvailable
!=
null
)
{
binding
.
quota
.
visibility
=
View
.
VISIBLE
binding
.
quota
.
text
=
context
.
getString
(
R
.
string
.
webdav_mounts_quota_used_available
,
info
.
rootDocument
.
quota
Available
?.
let
{
info
.
rootDocument
.
quota
Used
?.
let
{
FileUtils
.
byteCountToDisplaySize
(
it
)
}
?:
"?"
,
info
.
rootDocument
.
quota
Used
?.
let
{
info
.
rootDocument
.
quota
Available
?.
let
{
FileUtils
.
byteCountToDisplaySize
(
it
)
}
?:
"?"
)
...
...
app/src/main/java/at/bitfire/davdroid/webdav/DavDocumentsProvider.kt
View file @
231e54db
...
...
@@ -22,7 +22,6 @@ import android.webkit.MimeTypeMap
import
androidx.annotation.WorkerThread
import
androidx.core.content.ContextCompat
import
androidx.lifecycle.Observer
import
at.bitfire.cert4android.CertUtils
import
at.bitfire.dav4jvm.DavCollection
import
at.bitfire.dav4jvm.DavResource
import
at.bitfire.dav4jvm.Response
...
...
@@ -41,8 +40,6 @@ import okhttp3.logging.HttpLoggingInterceptor
import
java.io.ByteArrayOutputStream
import
java.io.FileNotFoundException
import
java.net.HttpURLConnection
import
java.security.MessageDigest
import
java.security.spec.MGF1ParameterSpec.SHA1
import
java.util.*
import
java.util.concurrent.*
import
java.util.logging.Level
...
...
@@ -312,32 +309,33 @@ class DavDocumentsProvider: DocumentsProvider() {
override
fun
copyDocument
(
sourceDocumentId
:
String
,
targetParentDocumentId
:
String
):
String
{
Logger
.
log
.
fine
(
"WebDAV copyDocument $sourceDocumentId $targetParentDocumentId"
)
val
srcDoc
=
documentDao
.
get
(
sourceDocumentId
.
toLong
())
?:
throw
FileNotFoundException
()
val
dst
Doc
=
documentDao
.
get
(
targetParentDocumentId
.
toLong
())
?:
throw
FileNotFoundException
()
val
dst
Folder
=
documentDao
.
get
(
targetParentDocumentId
.
toLong
())
?:
throw
FileNotFoundException
()
val
name
=
srcDoc
.
name
if
(
srcDoc
.
mountId
!=
dst
Doc
.
mountId
)
if
(
srcDoc
.
mountId
!=
dst
Folder
.
mountId
)
throw
UnsupportedOperationException
(
"Can't COPY between WebDAV servers"
)
va
r
dstDocId
=
sourceDocumentId
va
l
dstDocId
:
String
httpClient
(
srcDoc
.
mountId
).
use
{
client
->
val
dav
=
DavResource
(
client
.
okHttpClient
,
srcDoc
.
toHttpUrl
(
db
))
try
{
val
dstUrl
=
dst
Doc
.
toHttpUrl
(
db
).
newBuilder
()
val
dstUrl
=
dst
Folder
.
toHttpUrl
(
db
).
newBuilder
()
.
addPathSegment
(
name
)
.
build
()
dav
.
copy
(
dstUrl
,
false
)
{
// successfully copied
dstDocId
=
documentDao
.
insertOrReplace
(
WebDavDocument
(
mountId
=
dstDoc
.
mountId
,
parentId
=
dstDoc
.
id
,
name
=
name
,
isDirectory
=
srcDoc
.
isDirectory
,
displayName
=
srcDoc
.
displayName
,
mimeType
=
srcDoc
.
mimeType
,
size
=
srcDoc
.
size
)).
toString
()
}
dstDocId
=
documentDao
.
insertOrReplace
(
WebDavDocument
(
mountId
=
dstFolder
.
mountId
,
parentId
=
dstFolder
.
id
,
name
=
name
,
isDirectory
=
srcDoc
.
isDirectory
,
displayName
=
srcDoc
.
displayName
,
mimeType
=
srcDoc
.
mimeType
,
size
=
srcDoc
.
size
)).
toString
()
notifyFolderChanged
(
targetParentDocumentId
)
}
catch
(
e
:
HttpException
)
{
if
(
e
.
code
==
HttpURLConnection
.
HTTP_NOT_FOUND
)
...
...
@@ -428,10 +426,11 @@ class DavDocumentsProvider: DocumentsProvider() {
try
{
dav
.
move
(
newLocation
,
false
)
{
// successfully moved
doc
.
parentId
=
dstParent
.
id
documentDao
.
update
(
doc
)
}
doc
.
parentId
=
dstParent
.
id
documentDao
.
update
(
doc
)
notifyFolderChanged
(
sourceParentDocumentId
)
notifyFolderChanged
(
targetParentDocumentId
)
}
catch
(
e
:
HttpException
)
{
...
...
@@ -521,7 +520,11 @@ class DavDocumentsProvider: DocumentsProvider() {
val
accessor
=
RandomAccessCallback
(
context
!!
,
client
,
url
,
doc
.
mimeType
,
fileInfo
,
signal
)
storageManager
.
openProxyFileDescriptor
(
modeFlags
,
accessor
,
accessor
.
workerHandler
)
}
else
{
val
fd
=
StreamingFileDescriptor
(
context
!!
,
client
,
url
,
doc
.
mimeType
,
signal
)
val
fd
=
StreamingFileDescriptor
(
context
!!
,
client
,
url
,
doc
.
mimeType
,
signal
)
{
// called when transfer is finished
notifyFolderChanged
(
doc
.
parentId
)
}
if
(
readOnly
)
fd
.
download
()
else
...
...
@@ -555,7 +558,7 @@ class DavDocumentsProvider: DocumentsProvider() {
BitmapFactory
.
decodeStream
(
data
)
?.
let
{
bitmap
->
val
thumb
=
ThumbnailUtils
.
extractThumbnail
(
bitmap
,
sizeHint
.
x
,
sizeHint
.
y
)
val
baos
=
ByteArrayOutputStream
()
thumb
.
compress
(
Bitmap
.
CompressFormat
.
JPEG
,
9
2
,
baos
)
thumb
.
compress
(
Bitmap
.
CompressFormat
.
JPEG
,
9
5
,
baos
)
result
=
baos
.
toByteArray
()
}
}
...
...
@@ -616,26 +619,25 @@ class DavDocumentsProvider: DocumentsProvider() {
context
!!
.
contentResolver
.
notifyChange
(
buildChildDocumentsUri
(
authority
,
parentDocumentId
),
null
)
}
private
fun
sha1
(
s
:
String
):
String
{
val
md
=
MessageDigest
.
getInstance
(
SHA1
.
digestAlgorithm
)
return
CertUtils
.
hexString
(
md
.
digest
(
s
.
toByteArray
()))
}
private
fun
HttpException
.
throwForDocumentProvider
(
ignorePreconditionFailed
:
Boolean
=
false
)
{
when
(
code
)
{
HttpURLConnection
.
HTTP_UNAUTHORIZED
->
{
// TODO edit mount
val
intent
=
Intent
(
context
!!
,
WebdavMountsActivity
::
class
.
java
)
throw
AuthenticationRequiredException
(
this
,
PendingIntent
.
getActivity
(
context
!!
,
0
,
intent
,
PendingIntent
.
FLAG_UPDATE_CURRENT
or
PendingIntent
.
FLAG_IMMUTABLE
))
if
(
Build
.
VERSION
.
SDK_INT
>=
26
)
{
// TODO edit mount
val
intent
=
Intent
(
context
!!
,
WebdavMountsActivity
::
class
.
java
)
throw
AuthenticationRequiredException
(
this
,
PendingIntent
.
getActivity
(
context
!!
,
0
,
intent
,
PendingIntent
.
FLAG_UPDATE_CURRENT
or
PendingIntent
.
FLAG_IMMUTABLE
))
}
}
HttpURLConnection
.
HTTP_NOT_FOUND
->
throw
FileNotFoundException
()
HttpURLConnection
.
HTTP_NOT_FOUND
->
throw
FileNotFoundException
()
HttpURLConnection
.
HTTP_PRECON_FAILED
->
if
(!
ignorePreconditionFailed
)
throw
this
else
->
throw
this
if
(
ignorePreconditionFailed
)
return
}
// re-throw
throw
this
}
}
\ No newline at end of file
app/src/main/java/at/bitfire/davdroid/webdav/PageCache.kt
View file @
231e54db
package
at.bitfire.davdroid.webdav
import
android.content.Context
import
android.os.Build
import
android.os.storage.StorageManager
import
androidx.annotation.WorkerThread
import
androidx.core.content.ContextCompat
import
at.bitfire.davdroid.AndroidSingleton
import
at.bitfire.davdroid.log.Logger
import
okhttp3.HttpUrl
import
org.apache.commons.io.FileUtils
import
java.io.File
@WorkerThread
class
PageCache
(
context
:
Context
)
{
...
...
@@ -30,8 +34,11 @@ class PageCache(
init
{
val
storageManager
=
ContextCompat
.
getSystemService
(
context
,
StorageManager
::
class
.
java
)
!!
val
cacheDir
=
File
(
context
.
cacheDir
,
"webdav/page"
)
val
maxBytes
=
storageManager
.
getCacheQuotaBytes
(
storageManager
.
getUuidForPath
(
cacheDir
))
/
2
Logger
.
log
.
info
(
"Initializing WebDAV page cache in $cacheDir"
)
val
maxBytes
=
if
(
Build
.
VERSION
.
SDK_INT
>=
26
)
storageManager
.
getCacheQuotaBytes
(
storageManager
.
getUuidForPath
(
cacheDir
))
/
2
else
50
*
FileUtils
.
ONE_MB
Logger
.
log
.
info
(
"Initializing WebDAV page cache in $cacheDir with ${FileUtils.byteCountToDisplaySize(maxBytes)}"
)
cache
=
DiskCache
(
cacheDir
,
maxBytes
)
}
...
...
app/src/main/java/at/bitfire/davdroid/webdav/RandomAccessCallback.kt
View file @
231e54db
package
at.bitfire.davdroid.webdav
import
android.annotation.TargetApi
import
android.content.Context
import
android.os.CancellationSignal
import
android.os.Handler
...
...
@@ -7,6 +8,7 @@ import android.os.HandlerThread
import
android.os.ProxyFileDescriptorCallback
import
android.system.ErrnoException
import
android.system.OsConstants
import
androidx.annotation.RequiresApi
import
at.bitfire.dav4jvm.DavResource
import
at.bitfire.dav4jvm.HttpUtils
import
at.bitfire.dav4jvm.exception.HttpException
...
...
@@ -20,6 +22,7 @@ import java.io.InterruptedIOException
import
java.net.HttpURLConnection
import
java.util.logging.Level
@TargetApi
(
26
)
class
RandomAccessCallback
(
val
context
:
Context
,
val
httpClient
:
HttpClient
,
...
...
app/src/main/java/at/bitfire/davdroid/webdav/StreamingFileDescriptor.kt
View file @
231e54db
...
...
@@ -24,7 +24,8 @@ class StreamingFileDescriptor(
val
client
:
HttpClient
,
val
url
:
HttpUrl
,
val
mimeType
:
String
?,
val
cancellationSignal
:
CancellationSignal
?
val
cancellationSignal
:
CancellationSignal
?,
val
finishedCallback
:
()
->
Unit
)
{
companion
object
{
...
...
@@ -57,6 +58,8 @@ class StreamingFileDescriptor(
readFd
.
close
()
writeFd
.
close
()
}
catch
(
ignored
:
IOException
)
{}
finishedCallback
()
}
cancellationSignal
?.
setOnCancelListener
{
...
...
app/src/main/java/at/bitfire/davdroid/webdav/ThumbnailCache.kt
View file @
231e54db
...
...
@@ -2,13 +2,17 @@ package at.bitfire.davdroid.webdav
import
android.content.Context
import
android.graphics.Point
import
android.os.Build
import
android.os.storage.StorageManager
import
androidx.annotation.WorkerThread
import
androidx.core.content.ContextCompat
import
at.bitfire.davdroid.log.Logger
import
at.bitfire.davdroid.model.WebDavDocument
import
org.apache.commons.io.FileUtils
import
java.io.File
import
java.util.*
@WorkerThread
class
ThumbnailCache
(
context
:
Context
)
{
val
cache
:
DiskCache
...
...
@@ -16,8 +20,11 @@ class ThumbnailCache(context: Context) {
init
{
val
storageManager
=
ContextCompat
.
getSystemService
(
context
,
StorageManager
::
class
.
java
)
!!
val
cacheDir
=
File
(
context
.
cacheDir
,
"webdav/thumbnail"
)
val
maxBytes
=
storageManager
.
getCacheQuotaBytes
(
storageManager
.
getUuidForPath
(
cacheDir
))
/
2
Logger
.
log
.
info
(
"Initializing WebDAV thumbnail cache with ${maxBytes/1024/1024} MB"
)
val
maxBytes
=
if
(
Build
.
VERSION
.
SDK_INT
>=
26
)
storageManager
.
getCacheQuotaBytes
(
storageManager
.
getUuidForPath
(
cacheDir
))
/
2
else
50
*
FileUtils
.
ONE_MB
Logger
.
log
.
info
(
"Initializing WebDAV thumbnail cache with ${FileUtils.byteCountToDisplaySize(maxBytes)}"
)
cache
=
DiskCache
(
cacheDir
,
maxBytes
)
}
...
...
app/src/main/res/values/strings.xml
View file @
231e54db
...
...
@@ -428,7 +428,7 @@
<!-- WebDAV accounts -->
<string
name=
"webdav_authority"
>
at.bitfire.davdroid.webdav
</string>
<string
name=
"webdav_mounts_title"
>
WebDAV mounts
</string>
<string
name=
"webdav_mounts_quota_used_available"
>
Quota used: %s / available: %s
</string>
<string
name=
"webdav_mounts_quota_used_available"
>
Quota used: %
1$
s / available: %
2$
s
</string>
<string
name=
"webdav_mounts_share_content"
>
Share content
</string>
<string
name=
"webdav_mounts_unmount"
>
Unmount
</string>
<string
name=
"webdav_add_mount_title"
>
Add WebDAV mount
</string>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment