Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1c9d100b04 |
No files matched your search
@@ -1,3 +1,4 @@
|
||||
firstPRMergeComment: >
|
||||
Thanks for your first pull request and welcome to the community!
|
||||
Feel free to keep them coming! If you are looking for issues to tackle then have a look at this selection: https://github.com/nextcloud/android/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22
|
||||
Most developers hang out on IRC. So join \#nextcloud-mobile on Freenode for a chat!
|
||||
@@ -1,11 +0,0 @@
|
||||
name: Auto approve
|
||||
on: pull_request
|
||||
|
||||
jobs:
|
||||
auto-approve:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: hmarr/[email protected]
|
||||
if: github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]'
|
||||
with:
|
||||
github-token: "${{ secrets.DEPENDABOT_AUTOMERGE_TOKEN }}"
|
||||
@@ -56,16 +56,7 @@
|
||||
<JetCodeStyleSettings>
|
||||
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
|
||||
<value>
|
||||
<package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="PACKAGES_IMPORT_LAYOUT">
|
||||
<value>
|
||||
<package name="" alias="false" withSubpackages="true" />
|
||||
<package name="java" alias="false" withSubpackages="true" />
|
||||
<package name="javax" alias="false" withSubpackages="true" />
|
||||
<package name="kotlin" alias="false" withSubpackages="true" />
|
||||
<package name="" alias="true" withSubpackages="true" />
|
||||
<package name="kotlinx.android.synthetic" withSubpackages="true" static="false" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="NAME_COUNT_TO_USE_STAR_IMPORT" value="2147483647" />
|
||||
|
||||
@@ -1,24 +1,3 @@
|
||||
## 3.13.1 (September, 15, 2020)
|
||||
|
||||
- bugfix release
|
||||
- auto upload obey metered network
|
||||
- fix adding account via qrCode
|
||||
- fix deleting password on share
|
||||
- fix conflict handling on auto upload
|
||||
- lots more
|
||||
|
||||
For a full list, please see https://github.com/nextcloud/android/milestone/51
|
||||
|
||||
## 3.13.0 (August, 18, 2020)
|
||||
|
||||
- new UI overhaul @Shagequi @JorisBodin
|
||||
- E2EE beta support
|
||||
- dark mode enhancement @AndyScherzinger
|
||||
- warn on outdated NC16 server
|
||||
- requires Android 4.3 or newer
|
||||
|
||||
For a full list, please see https://github.com/nextcloud/android/milestone/48
|
||||
|
||||
## 3.12.1 (July, 07, 2020)
|
||||
|
||||
- UI does not hang when changing auto upload
|
||||
|
||||
@@ -445,7 +445,7 @@ Examples for different versions:
|
||||
* 8.12.2 ```80120200```
|
||||
* 9.8.4-rc18 ```90080418```
|
||||
|
||||
beware, that beta releases for an upcoming version will always use the minor and hotfix version of the release they are targeting. So to make sure the version code of the upcoming stable release will always be higher stable releases set the 2 beta digits to '99' as seen above in the examples. For major versions, as we're not a library and thus 'incompatible API changes' is not something that happens, decisions are essentially marketing-based. If we deem a release to be very impactful, we might increase the major version number.
|
||||
beware, that beta releases for an upcoming version will always use the minor and hotfix version of the release they are targeting. So to make sure the version code of the upcoming stable release will always be higher stable releases set the 2 beta digits to '99' as seen above in the examples.
|
||||
|
||||
### Dev
|
||||
For dev the version name is in format YYYYMMDD. It is mainly as a reference for reporting bugs and is not related to stable/release candidates as it is an independent app.
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.1</version>
|
||||
<version>4.11</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.seleniumhq.selenium</groupId>
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.github.spotbugs.snom.SpotBugsTask
|
||||
// its root folder, another one for the app module in subfolder of root.
|
||||
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.4.10'
|
||||
ext.kotlin_version = '1.3.72'
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
@@ -21,13 +21,13 @@ buildscript {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:4.1.0'
|
||||
classpath 'com.android.tools.build:gradle:4.0.1'
|
||||
classpath('com.hiya:jacoco-android:0.2')
|
||||
classpath 'gradle.plugin.com.github.spotbugs.snom:spotbugs-gradle-plugin:4.5.1'
|
||||
classpath 'gradle.plugin.com.github.spotbugs.snom:spotbugs-gradle-plugin:4.5.0'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.14.1"
|
||||
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.11.0"
|
||||
classpath "commons-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2
|
||||
classpath 'com.karumi:shot:4.4.0'
|
||||
classpath 'com.karumi:shot:4.3.0'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,9 @@ configurations {
|
||||
ktlint
|
||||
|
||||
all {
|
||||
exclude group: 'com.google.firebase', module: 'firebase-core'
|
||||
exclude group: 'com.google.firebase', module: 'firebase-analytics'
|
||||
exclude group: 'com.google.firebase', module: 'firebase-measurement-connector'
|
||||
exclude group: 'org.jetbrains', module: 'annotations-java5' // via prism4j, already using annotations explicitly
|
||||
|
||||
// check for updates every build
|
||||
@@ -56,15 +59,11 @@ configurations {
|
||||
|
||||
ext {
|
||||
jacocoVersion = "0.8.2"
|
||||
daggerVersion = "2.29.1"
|
||||
markwonVersion = "4.6.0"
|
||||
daggerVersion = "2.28.3"
|
||||
markwonVersion = "4.5.0"
|
||||
prismVersion = "2.0.0"
|
||||
butterknifeVersion = "10.2.3"
|
||||
androidLibraryVersion ="dc1a7cc51964bc1b00d1d78942a3523d04487ce1"
|
||||
mockitoVersion = "3.5.13"
|
||||
mockkVersion = "1.10.2"
|
||||
byteBuddyVersion = "1.10.17"
|
||||
espressoVersion = "3.3.0"
|
||||
androidLibraryVersion = "master-SNAPSHOT"
|
||||
|
||||
travisBuild = System.getenv("TRAVIS") == "true"
|
||||
|
||||
@@ -85,7 +84,7 @@ repositories {
|
||||
|
||||
// semantic versioning for version code
|
||||
def versionMajor = 3
|
||||
def versionMinor = 14
|
||||
def versionMinor = 13
|
||||
def versionPatch = 0
|
||||
def versionBuild = 0 // 0-50=Alpha / 51-98=RC / 90-99=stable
|
||||
|
||||
@@ -125,7 +124,7 @@ android {
|
||||
compileSdkVersion 29
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 19
|
||||
minSdkVersion 18
|
||||
targetSdkVersion 29
|
||||
|
||||
// arguments to be passed to functional tests
|
||||
@@ -173,8 +172,8 @@ android {
|
||||
versionDev {
|
||||
applicationId "com.nextcloud.android.beta"
|
||||
dimension "default"
|
||||
versionCode 20201014
|
||||
versionName "20201014"
|
||||
versionCode 20200129
|
||||
versionName "20200129"
|
||||
}
|
||||
|
||||
qa {
|
||||
@@ -287,20 +286,20 @@ dependencies {
|
||||
compileOnly 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2' // remove after entire switch to lib v2
|
||||
implementation "commons-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2
|
||||
implementation 'org.apache.jackrabbit:jackrabbit-webdav:2.13.1' // remove after entire switch to lib v2
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||
implementation 'com.google.android.material:material:1.2.1'
|
||||
implementation 'com.google.android.material:material:1.2.0'
|
||||
implementation 'com.jakewharton:disklrucache:2.0.2'
|
||||
implementation 'androidx.appcompat:appcompat:1.2.0-rc01'
|
||||
implementation 'androidx.cardview:cardview:1.0.0'
|
||||
implementation 'androidx.exifinterface:exifinterface:1.3.0'
|
||||
implementation 'androidx.exifinterface:exifinterface:1.2.0'
|
||||
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
|
||||
implementation "androidx.work:work-runtime:2.4.0"
|
||||
implementation "androidx.work:work-runtime-ktx:2.4.0"
|
||||
implementation "androidx.fragment:fragment:1.2.5"
|
||||
implementation 'com.github.albfernandez:juniversalchardet:2.0.3' // need this version for Android <7
|
||||
compileOnly 'com.google.code.findbugs:annotations:2.0.1'
|
||||
implementation 'commons-io:commons-io:2.8.0'
|
||||
implementation 'commons-io:commons-io:2.7'
|
||||
implementation "com.jakewharton:butterknife:$butterknifeVersion"
|
||||
kapt "com.jakewharton:butterknife-compiler:$butterknifeVersion"
|
||||
implementation 'org.greenrobot:eventbus:3.2.0'
|
||||
@@ -310,7 +309,7 @@ dependencies {
|
||||
implementation 'com.google.code.gson:gson:2.8.6'
|
||||
implementation 'com.afollestad:sectioned-recyclerview:0.5.0'
|
||||
implementation 'com.github.chrisbanes:PhotoView:2.3.0'
|
||||
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.21'
|
||||
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.20'
|
||||
implementation 'com.github.tobiaskaminsky:qrcodescanner:0.1.2.2' // 'com.github.blikoon:QRCodeScanner:0.1.2'
|
||||
implementation 'com.google.android:flexbox:2.0.1'
|
||||
implementation 'org.parceler:parceler-api:1.1.13'
|
||||
@@ -334,8 +333,8 @@ dependencies {
|
||||
kapt "com.google.dagger:dagger-compiler:$daggerVersion"
|
||||
kapt "com.google.dagger:dagger-android-processor:$daggerVersion"
|
||||
|
||||
ktlint "com.pinterest:ktlint:0.39.0"
|
||||
implementation 'org.conscrypt:conscrypt-android:2.5.1'
|
||||
ktlint "com.pinterest:ktlint:0.37.2"
|
||||
implementation 'org.conscrypt:conscrypt-android:2.4.0'
|
||||
|
||||
// Shimmer animation
|
||||
implementation 'com.elyeproj.libraries:loaderviewlibrary:2.0.0'
|
||||
@@ -352,40 +351,40 @@ dependencies {
|
||||
kapt "io.noties:prism4j-bundler:$prismVersion"
|
||||
|
||||
// dependencies for local unit tests
|
||||
testImplementation 'junit:junit:4.13.1'
|
||||
testImplementation "org.mockito:mockito-core:$mockitoVersion"
|
||||
testImplementation 'androidx.test:core:1.3.0'
|
||||
testImplementation 'junit:junit:4.13'
|
||||
testImplementation 'org.mockito:mockito-core:3.4.6'
|
||||
testImplementation 'androidx.test:core:1.2.0'
|
||||
testImplementation 'org.powermock:powermock-core:2.0.7'
|
||||
testImplementation 'org.powermock:powermock-module-junit4:2.0.7'
|
||||
testImplementation 'org.powermock:powermock-api-mockito2:2.0.7'
|
||||
testImplementation 'org.json:json:20200518'
|
||||
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
|
||||
testImplementation 'androidx.arch.core:core-testing:2.1.0'
|
||||
testImplementation "io.mockk:mockk:$mockkVersion"
|
||||
testImplementation "io.mockk:mockk-android:$mockkVersion"
|
||||
testImplementation 'io.mockk:mockk:1.10.0'
|
||||
testImplementation 'io.mockk:mockk-android:1.10.0'
|
||||
|
||||
// dependencies for instrumented tests
|
||||
// JUnit4 Rules
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
||||
androidTestImplementation 'androidx.test:rules:1.3.0'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||
androidTestImplementation 'androidx.test:rules:1.2.0'
|
||||
// Android JUnit Runner
|
||||
androidTestImplementation 'androidx.test:runner:1.3.0'
|
||||
androidTestUtil 'androidx.test:orchestrator:1.3.0'
|
||||
androidTestImplementation 'androidx.test:runner:1.2.0'
|
||||
androidTestUtil 'androidx.test:orchestrator:1.2.0'
|
||||
|
||||
// Espresso core
|
||||
androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
|
||||
androidTestImplementation "androidx.test.espresso:espresso-contrib:$espressoVersion"
|
||||
androidTestImplementation "androidx.test.espresso:espresso-web:$espressoVersion"
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.2.0'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-web:3.2.0'
|
||||
|
||||
// Mocking support
|
||||
androidTestImplementation 'com.github.tmurakami:dexopener:2.0.5' // required to allow mocking on API 27 and older
|
||||
androidTestImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
|
||||
androidTestImplementation "org.mockito:mockito-core:$mockitoVersion"
|
||||
androidTestImplementation("org.mockito:mockito-android:$mockitoVersion") {
|
||||
androidTestImplementation 'org.mockito:mockito-core:3.4.4'
|
||||
androidTestImplementation("org.mockito:mockito-android:3.4.6") {
|
||||
exclude group: "net.bytebuddy", module: "byte-buddy-android"
|
||||
}
|
||||
androidTestImplementation "net.bytebuddy:byte-buddy:$byteBuddyVersion"
|
||||
androidTestImplementation "net.bytebuddy:byte-buddy-android:$byteBuddyVersion"
|
||||
androidTestImplementation 'net.bytebuddy:byte-buddy:1.10.14'
|
||||
androidTestImplementation "net.bytebuddy:byte-buddy-android:1.10.14"
|
||||
androidTestImplementation "io.mockk:mockk-android:1.10.0"
|
||||
androidTestImplementation 'androidx.arch.core:core-testing:2.0.1'
|
||||
|
||||
@@ -413,11 +412,7 @@ spotbugs {
|
||||
}
|
||||
|
||||
configurations.all {
|
||||
resolutionStrategy{
|
||||
cacheChangingModulesFor 0, 'seconds'
|
||||
force 'org.objenesis:objenesis:2.6'
|
||||
}
|
||||
|
||||
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
|
||||
}
|
||||
|
||||
tasks.withType(Test) {
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
dependencies {
|
||||
implementation "com.google.firebase:firebase-messaging:20.2.4"
|
||||
implementation "com.google.firebase:firebase-messaging:20.1.3"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
#Tue Oct 13 09:09:22 CEST 2020
|
||||
#Fri May 29 07:39:21 CEST 2020
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
|
||||
@@ -60,8 +60,7 @@
|
||||
<ignore path="**/fragment-1.2.5/**/lint.jar" />
|
||||
<ignore path="**/work-runtime-2.**/**/lint.jar" />
|
||||
<ignore path="**/jetified-butterknife-runtime-10.**/**/lint.jar" />
|
||||
<ignore path="**/jetified-dagger-lint-aar-2.29.**/**/lint.jar" />
|
||||
<ignore path="**/jetified-dagger-lint-aar-2.28.**/**/lint.jar" />
|
||||
<ignore path="**/jetified-annotation-experimental-1.**/**/lint.jar" />
|
||||
<ignore path="**/jetified-firebase-installations**/**/lint.jar" />
|
||||
</issue>
|
||||
</lint>
|
||||
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 9.5 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 33 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 4.9 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 9.0 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 4.8 KiB |
|
Before Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 9.2 KiB |
|
Before Width: | Height: | Size: 3.7 KiB |
|
Before Width: | Height: | Size: 39 KiB |
|
Before Width: | Height: | Size: 39 KiB |
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
@@ -1 +1 @@
|
||||
319
|
||||
329
|
||||
@@ -1,2 +1,2 @@
|
||||
DO NOT TOUCH; GENERATED BY DRONE
|
||||
<span class="mdl-layout-title">Lint Report: 356 warnings</span>
|
||||
<span class="mdl-layout-title">Lint Report: 81 warnings</span>
|
||||
@@ -10,6 +10,10 @@ if [ $# -lt 2 ]; then
|
||||
exit
|
||||
fi
|
||||
|
||||
sed -i s'#<bool name="is_beta">false</bool>#<bool name="is_beta">true</bool>#'g src/main/res/values/setup.xml
|
||||
|
||||
emulator -writable-system -avd uiComparison -no-snapshot -gpu swiftshader_indirect -no-audio -skin 500x833 &
|
||||
|
||||
cd src/androidTest/java
|
||||
|
||||
class=$(find | grep $2 | grep -E "java$|kt$" | head -n1|sed s'/\//\./'g | sed s'#^\.\.##' | sed s'#\.java##'| sed s'#\.kt##')
|
||||
@@ -45,10 +49,6 @@ else
|
||||
darkMode="-Pandroid.testInstrumentationRunnerArguments.DARKMODE=$4"
|
||||
fi
|
||||
|
||||
sed -i s'#<bool name="is_beta">false</bool>#<bool name="is_beta">true</bool>#'g src/main/res/values/setup.xml
|
||||
|
||||
emulator -writable-system -avd uiComparison -no-snapshot -gpu swiftshader_indirect -no-audio -skin 500x833 &
|
||||
|
||||
if [ -e $5 ] ; then
|
||||
color=""
|
||||
else
|
||||
|
||||
@@ -87,6 +87,4 @@ else
|
||||
BRANCH_TYPE=$BRANCH-$TYPE
|
||||
upload "build/reports/shot/verification"
|
||||
fi
|
||||
|
||||
exit 1 # always fail
|
||||
fi
|
||||
@@ -25,8 +25,10 @@
|
||||
the normal release/debug builds.
|
||||
-->
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<manifest xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="${applicationId}.test"
|
||||
android:sharedUserId="${applicationId}.uid">
|
||||
|
||||
<uses-sdk tools:overrideLibrary="android_libs.ub_uiautomator, tools.fastlane.screengrab" />
|
||||
</manifest>
|
||||
@@ -97,7 +97,7 @@ public class FileDisplayActivityIT extends AbstractOnServerIT {
|
||||
"users",
|
||||
false,
|
||||
"",
|
||||
OCShare.NO_PERMISSION)
|
||||
OCShare.DEFAULT_PERMISSION)
|
||||
.execute(client).isSuccess());
|
||||
|
||||
// share folder to circle
|
||||
|
||||
@@ -54,9 +54,7 @@ public class FileDisplayActivityScreenshotIT extends AbstractIT {
|
||||
FileDisplayActivity sut = activityRule.launchActivity(null);
|
||||
|
||||
sut.getListOfFilesFragment().setFabEnabled(false);
|
||||
sut.getListOfFilesFragment().setEmptyListLoadingMessage(false);
|
||||
sut.getListOfFilesFragment().setLoading(false);
|
||||
waitForIdleSync();
|
||||
sut.getListOfFilesFragment().setEmptyListLoadingMessage();
|
||||
|
||||
screenshot(sut);
|
||||
}
|
||||
@@ -69,9 +67,7 @@ public class FileDisplayActivityScreenshotIT extends AbstractIT {
|
||||
onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());
|
||||
|
||||
sut.getListOfFilesFragment().setFabEnabled(false);
|
||||
sut.getListOfFilesFragment().setEmptyListLoadingMessage(false);
|
||||
sut.getListOfFilesFragment().setLoading(false);
|
||||
waitForIdleSync();
|
||||
sut.getListOfFilesFragment().setEmptyListLoadingMessage();
|
||||
|
||||
screenshot(sut);
|
||||
}
|
||||
|
||||
@@ -24,14 +24,9 @@ package com.nextcloud.client;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Looper;
|
||||
|
||||
import com.owncloud.android.AbstractIT;
|
||||
import com.owncloud.android.datamodel.ArbitraryDataProvider;
|
||||
import com.owncloud.android.ui.activity.RequestCredentialsActivity;
|
||||
import com.owncloud.android.ui.activity.SettingsActivity;
|
||||
import com.owncloud.android.utils.EncryptionUtils;
|
||||
import com.owncloud.android.utils.ScreenshotTest;
|
||||
|
||||
import org.junit.Rule;
|
||||
@@ -40,8 +35,6 @@ import org.junit.Test;
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule;
|
||||
import androidx.test.rule.GrantPermissionRule;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
||||
public class SettingsActivityIT extends AbstractIT {
|
||||
@Rule public IntentsTestRule<SettingsActivity> activityRule = new IntentsTestRule<>(SettingsActivity.class,
|
||||
@@ -59,33 +52,4 @@ public class SettingsActivityIT extends AbstractIT {
|
||||
|
||||
screenshot(sut);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ScreenshotTest
|
||||
public void showMnemonic_Error() {
|
||||
SettingsActivity sut = activityRule.launchActivity(null);
|
||||
sut.handleMnemonicRequest(null);
|
||||
shortSleep();
|
||||
waitForIdleSync();
|
||||
|
||||
screenshot(sut);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void showMnemonic() {
|
||||
if (Looper.myLooper() == null) {
|
||||
Looper.prepare();
|
||||
}
|
||||
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(RequestCredentialsActivity.KEY_CHECK_RESULT, RequestCredentialsActivity.KEY_CHECK_RESULT_TRUE);
|
||||
|
||||
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(targetContext.getContentResolver());
|
||||
arbitraryDataProvider.storeOrUpdateKeyValue(user.getAccountName(), EncryptionUtils.MNEMONIC, "Secret mnemonic");
|
||||
|
||||
SettingsActivity sut = activityRule.launchActivity(null);
|
||||
sut.handleMnemonicRequest(intent);
|
||||
|
||||
assertTrue(true); // if we reach this, everything is ok
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.owncloud.android;
|
||||
|
||||
import android.Manifest;
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.accounts.AuthenticatorException;
|
||||
@@ -42,7 +41,6 @@ import junit.framework.TestCase;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
@@ -54,14 +52,12 @@ import androidx.annotation.NonNull;
|
||||
import androidx.test.espresso.contrib.DrawerActions;
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule;
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
import androidx.test.rule.GrantPermissionRule;
|
||||
import androidx.test.runner.lifecycle.ActivityLifecycleMonitorRegistry;
|
||||
import androidx.test.runner.lifecycle.Stage;
|
||||
|
||||
import static androidx.test.InstrumentationRegistry.getInstrumentation;
|
||||
import static androidx.test.espresso.Espresso.onView;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withId;
|
||||
import static com.owncloud.android.lib.common.accounts.AccountUtils.Constants.KEY_USER_ID;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
||||
@@ -70,9 +66,7 @@ import static org.junit.Assert.assertTrue;
|
||||
*/
|
||||
|
||||
public abstract class AbstractIT {
|
||||
@Rule
|
||||
public final GrantPermissionRule permissionRule = GrantPermissionRule.grant(
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
//@Rule public RetryTestRule retryTestRule = new RetryTestRule();
|
||||
|
||||
protected static OwnCloudClient client;
|
||||
protected static Account account;
|
||||
@@ -102,7 +96,7 @@ public abstract class AbstractIT {
|
||||
Account temp = new Account("test@https://server.com", MainApp.getAccountType(targetContext));
|
||||
platformAccountManager.addAccountExplicitly(temp, "password", null);
|
||||
platformAccountManager.setUserData(temp, AccountUtils.Constants.KEY_OC_BASE_URL, "https://server.com");
|
||||
platformAccountManager.setUserData(temp, KEY_USER_ID, "test");
|
||||
platformAccountManager.setUserData(temp, AccountUtils.Constants.KEY_USER_ID, "test");
|
||||
|
||||
final UserAccountManager userAccountManager = UserAccountManagerImpl.fromContext(targetContext);
|
||||
account = userAccountManager.getAccountByName("test@https://server.com");
|
||||
@@ -387,8 +381,4 @@ public abstract class AbstractIT {
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
public static String getUserId(User user) {
|
||||
return AccountManager.get(targetContext).getUserData(user.toPlatformAccount(), KEY_USER_ID);
|
||||
}
|
||||
}
|
||||
@@ -215,7 +215,6 @@ public class UploadIT extends AbstractOnServerIT {
|
||||
|
||||
uploadOCUpload(ocUpload);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUploadOnChargingOnlyButNotCharging() {
|
||||
OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt",
|
||||
@@ -242,7 +241,6 @@ public class UploadIT extends AbstractOnServerIT {
|
||||
|
||||
RemoteOperationResult result = newUpload.execute(client, getStorageManager());
|
||||
assertFalse(result.toString(), result.isSuccess());
|
||||
assertEquals(RemoteOperationResult.ResultCode.DELAYED_FOR_CHARGING, result.getCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -328,7 +326,6 @@ public class UploadIT extends AbstractOnServerIT {
|
||||
|
||||
RemoteOperationResult result = newUpload.execute(client, getStorageManager());
|
||||
assertFalse(result.toString(), result.isSuccess());
|
||||
assertEquals(RemoteOperationResult.ResultCode.DELAYED_FOR_WIFI, result.getCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -367,47 +364,6 @@ public class UploadIT extends AbstractOnServerIT {
|
||||
.execute(client, getStorageManager());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUploadOnWifiOnlyButMeteredWifi() {
|
||||
ConnectivityService connectivityServiceMock = new ConnectivityService() {
|
||||
@Override
|
||||
public boolean isInternetWalled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connectivity getConnectivity() {
|
||||
return new Connectivity(true, true, true, true);
|
||||
}
|
||||
};
|
||||
OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt",
|
||||
FOLDER + "noWifi.txt",
|
||||
account.name);
|
||||
ocUpload.setUseWifiOnly(true);
|
||||
|
||||
UploadFileOperation newUpload = new UploadFileOperation(
|
||||
uploadsStorageManager,
|
||||
connectivityServiceMock,
|
||||
powerManagementServiceMock,
|
||||
user,
|
||||
null,
|
||||
ocUpload,
|
||||
FileUploader.NameCollisionPolicy.DEFAULT,
|
||||
FileUploader.LOCAL_BEHAVIOUR_COPY,
|
||||
targetContext,
|
||||
true,
|
||||
false
|
||||
);
|
||||
newUpload.setRemoteFolderToBeCreated();
|
||||
newUpload.addRenameUploadListener(() -> {
|
||||
// dummy
|
||||
});
|
||||
|
||||
RemoteOperationResult result = newUpload.execute(client, getStorageManager());
|
||||
assertFalse(result.toString(), result.isSuccess());
|
||||
assertEquals(RemoteOperationResult.ResultCode.DELAYED_FOR_WIFI, result.getCode());
|
||||
}
|
||||
|
||||
private void verifyStoragePath(OCFile file) {
|
||||
assertEquals(FileStorageUtils.getSavePath(account.name) + FOLDER + file.getDecryptedFileName(),
|
||||
file.getStoragePath());
|
||||
|
||||
@@ -32,7 +32,6 @@ class AuthenticatorActivityIT {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Suppress("TooGenericExceptionCaught")
|
||||
fun tryCatch() {
|
||||
val color = try {
|
||||
Color.parseColor("1")
|
||||
@@ -44,7 +43,6 @@ class AuthenticatorActivityIT {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Suppress("TooGenericExceptionCaught")
|
||||
fun tryCatch2() {
|
||||
val color = try {
|
||||
Color.parseColor("")
|
||||
@@ -56,7 +54,6 @@ class AuthenticatorActivityIT {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Suppress("TooGenericExceptionCaught")
|
||||
fun tryCatch3() {
|
||||
val color = try {
|
||||
Color.parseColor(null)
|
||||
@@ -68,7 +65,6 @@ class AuthenticatorActivityIT {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Suppress("TooGenericExceptionCaught")
|
||||
fun tryCatch4() {
|
||||
val color = try {
|
||||
Color.parseColor("abc")
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2020 Tobias Kaminsky
|
||||
* Copyright (C) 2020 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.datamodel
|
||||
|
||||
import com.owncloud.android.AbstractIT
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class ArbitraryDataProviderIT : AbstractIT() {
|
||||
private val arbitraryDataProvider = ArbitraryDataProvider(targetContext.contentResolver)
|
||||
|
||||
@Test
|
||||
fun testNull() {
|
||||
val key = "DUMMY_KEY"
|
||||
arbitraryDataProvider.storeOrUpdateKeyValue(user.accountName, key, null)
|
||||
|
||||
assertEquals("", arbitraryDataProvider.getValue(user.accountName, key))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testString() {
|
||||
val key = "DUMMY_KEY"
|
||||
var value = "123"
|
||||
arbitraryDataProvider.storeOrUpdateKeyValue(user.accountName, key, value)
|
||||
assertEquals(value, arbitraryDataProvider.getValue(user.accountName, key))
|
||||
|
||||
value = ""
|
||||
arbitraryDataProvider.storeOrUpdateKeyValue(user.accountName, key, value)
|
||||
assertEquals(value, arbitraryDataProvider.getValue(user.accountName, key))
|
||||
|
||||
value = "-1"
|
||||
arbitraryDataProvider.storeOrUpdateKeyValue(user.accountName, key, value)
|
||||
assertEquals(value, arbitraryDataProvider.getValue(user.accountName, key))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testBoolean() {
|
||||
val key = "DUMMY_KEY"
|
||||
var value = true
|
||||
arbitraryDataProvider.storeOrUpdateKeyValue(user.accountName, key, value.toString())
|
||||
assertEquals(value, arbitraryDataProvider.getBooleanValue(user.accountName, key))
|
||||
|
||||
value = false
|
||||
arbitraryDataProvider.storeOrUpdateKeyValue(user.accountName, key, value.toString())
|
||||
assertEquals(value, arbitraryDataProvider.getBooleanValue(user.accountName, key))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testInteger() {
|
||||
val key = "DUMMY_KEY"
|
||||
var value = 1
|
||||
arbitraryDataProvider.storeOrUpdateKeyValue(user.accountName, key, value.toString())
|
||||
assertEquals(value, arbitraryDataProvider.getIntegerValue(user.accountName, key))
|
||||
|
||||
value = -1
|
||||
arbitraryDataProvider.storeOrUpdateKeyValue(user.accountName, key, value.toString())
|
||||
assertEquals(value, arbitraryDataProvider.getIntegerValue(user.accountName, key))
|
||||
}
|
||||
}
|
||||
@@ -88,6 +88,7 @@ public class OCFileUnitTest {
|
||||
mFile.setEtag(ETAG);
|
||||
mFile.setSharedViaLink(true);
|
||||
mFile.setSharedWithSharee(true);
|
||||
mFile.setPublicLink(PUBLIC_LINK);
|
||||
mFile.setPermissions(PERMISSIONS);
|
||||
mFile.setRemoteId(REMOTE_ID);
|
||||
mFile.setUpdateThumbnailNeeded(true);
|
||||
@@ -121,6 +122,7 @@ public class OCFileUnitTest {
|
||||
assertThat(fileReadFromParcel.getEtag(), is(ETAG));
|
||||
assertThat(fileReadFromParcel.isSharedViaLink(), is(true));
|
||||
assertThat(fileReadFromParcel.isSharedWithSharee(), is(true));
|
||||
assertThat(fileReadFromParcel.getPublicLink(), is(PUBLIC_LINK));
|
||||
assertThat(fileReadFromParcel.getPermissions(), is(PERMISSIONS));
|
||||
assertThat(fileReadFromParcel.getRemoteId(), is(REMOTE_ID));
|
||||
assertThat(fileReadFromParcel.isUpdateThumbnailNeeded(), is(true));
|
||||
|
||||
@@ -32,7 +32,6 @@ import com.owncloud.android.AbstractOnServerIT
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import com.owncloud.android.datamodel.UploadsStorageManager
|
||||
import com.owncloud.android.db.OCUpload
|
||||
import com.owncloud.android.lib.common.operations.OperationCancelledException
|
||||
import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation
|
||||
import com.owncloud.android.lib.resources.files.model.RemoteFile
|
||||
import com.owncloud.android.operations.UploadFileOperation
|
||||
@@ -398,109 +397,4 @@ class FileUploaderIT : AbstractOnServerIT() {
|
||||
|
||||
assertEquals(file.length(), (result2.data[0] as RemoteFile).length)
|
||||
}
|
||||
|
||||
/**
|
||||
* uploads a file with "skip if exists" option set, so do nothing if file exists
|
||||
*/
|
||||
@Test
|
||||
fun testCancelServer() {
|
||||
val file = getDummyFile("/chunkedFile.txt")
|
||||
val ocUpload = OCUpload(file.absolutePath, "/testFile.txt", account.name)
|
||||
|
||||
assertTrue(
|
||||
UploadFileOperation(
|
||||
uploadsStorageManager,
|
||||
connectivityServiceMock,
|
||||
powerManagementServiceMock,
|
||||
user,
|
||||
null,
|
||||
ocUpload,
|
||||
FileUploader.NameCollisionPolicy.CANCEL,
|
||||
FileUploader.LOCAL_BEHAVIOUR_COPY,
|
||||
targetContext,
|
||||
false,
|
||||
false
|
||||
)
|
||||
.setRemoteFolderToBeCreated()
|
||||
.execute(client, storageManager)
|
||||
.isSuccess
|
||||
)
|
||||
|
||||
val result = ReadFileRemoteOperation("/testFile.txt").execute(client)
|
||||
assertTrue(result.isSuccess)
|
||||
|
||||
assertEquals(file.length(), (result.data[0] as RemoteFile).length)
|
||||
|
||||
val ocUpload2 = OCUpload(getDummyFile("/empty.txt").absolutePath, "/testFile.txt", account.name)
|
||||
|
||||
val uploadResult = UploadFileOperation(
|
||||
uploadsStorageManager,
|
||||
connectivityServiceMock,
|
||||
powerManagementServiceMock,
|
||||
user,
|
||||
null,
|
||||
ocUpload2,
|
||||
FileUploader.NameCollisionPolicy.CANCEL,
|
||||
FileUploader.LOCAL_BEHAVIOUR_COPY,
|
||||
targetContext,
|
||||
false,
|
||||
false
|
||||
)
|
||||
.execute(client, storageManager)
|
||||
|
||||
assertFalse(uploadResult.isSuccess)
|
||||
assertTrue(uploadResult.exception is OperationCancelledException)
|
||||
|
||||
val result2 = ReadFileRemoteOperation("/testFile.txt").execute(client)
|
||||
assertTrue(result2.isSuccess)
|
||||
|
||||
assertEquals(file.length(), (result2.data[0] as RemoteFile).length)
|
||||
}
|
||||
|
||||
/**
|
||||
* uploads a file with "skip if exists" option set, so do nothing if file exists
|
||||
*/
|
||||
@Test
|
||||
fun testKeepCancelStatic() {
|
||||
val file = getDummyFile("/chunkedFile.txt")
|
||||
|
||||
FileUploader.uploadNewFile(
|
||||
targetContext,
|
||||
account,
|
||||
file.absolutePath,
|
||||
"/testFile.txt",
|
||||
FileUploader.LOCAL_BEHAVIOUR_COPY,
|
||||
null,
|
||||
true,
|
||||
UploadFileOperation.CREATED_BY_USER,
|
||||
false,
|
||||
false,
|
||||
FileUploader.NameCollisionPolicy.DEFAULT
|
||||
)
|
||||
|
||||
longSleep()
|
||||
|
||||
val result = ReadFileRemoteOperation("/testFile.txt").execute(client)
|
||||
assertTrue(result.isSuccess)
|
||||
|
||||
assertEquals(file.length(), (result.data[0] as RemoteFile).length)
|
||||
|
||||
val ocFile2 = OCFile("/testFile.txt")
|
||||
ocFile2.setStoragePath(getDummyFile("/empty.txt").absolutePath)
|
||||
|
||||
FileUploader.uploadUpdateFile(
|
||||
targetContext,
|
||||
account,
|
||||
ocFile2,
|
||||
FileUploader.LOCAL_BEHAVIOUR_COPY,
|
||||
FileUploader.NameCollisionPolicy.CANCEL
|
||||
)
|
||||
|
||||
shortSleep()
|
||||
|
||||
val result2 = ReadFileRemoteOperation("/testFile.txt").execute(client)
|
||||
assertTrue(result2.isSuccess)
|
||||
|
||||
assertEquals(file.length(), (result2.data[0] as RemoteFile).length)
|
||||
}
|
||||
}
|
||||
@@ -1,198 +0,0 @@
|
||||
package com.owncloud.android.providers
|
||||
|
||||
import android.content.Context
|
||||
import android.database.ContentObserver
|
||||
import android.database.Cursor
|
||||
import android.net.Uri
|
||||
import android.provider.DocumentsContract.Document.COLUMN_DOCUMENT_ID
|
||||
import android.provider.DocumentsContract.Document.COLUMN_MIME_TYPE
|
||||
import android.provider.DocumentsContract.Document.MIME_TYPE_DIR
|
||||
import android.provider.DocumentsContract.EXTRA_LOADING
|
||||
import android.provider.DocumentsContract.buildChildDocumentsUriUsingTree
|
||||
import android.provider.DocumentsContract.buildDocumentUriUsingTree
|
||||
import android.provider.DocumentsContract.buildTreeDocumentUri
|
||||
import android.provider.DocumentsContract.getDocumentId
|
||||
import android.util.Log
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import com.owncloud.android.lib.common.OwnCloudClient
|
||||
import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation
|
||||
import com.owncloud.android.providers.DocumentsStorageProvider.DOCUMENTID_SEPARATOR
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.TimeoutCancellationException
|
||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlinx.coroutines.withTimeout
|
||||
import org.junit.Assert.assertArrayEquals
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import kotlin.coroutines.resume
|
||||
|
||||
// Uploads can sometimes take a bit of time, so 15sec is still considered recent enough
|
||||
private const val RECENT_MILLISECONDS = 15_000
|
||||
|
||||
object DocumentsProviderUtils {
|
||||
|
||||
internal fun DocumentFile.getOCFile(storageManager: FileDataStorageManager): OCFile? {
|
||||
val id = getDocumentId(uri)
|
||||
val separated: List<String> = id.split(DOCUMENTID_SEPARATOR.toRegex())
|
||||
return storageManager.getFileById(separated[1].toLong())
|
||||
}
|
||||
|
||||
internal fun DocumentFile.assertRegularFile(
|
||||
name: String? = null,
|
||||
size: Long? = null,
|
||||
mimeType: String? = null,
|
||||
parent: DocumentFile? = null
|
||||
) {
|
||||
name?.let { assertEquals(it, this.name) }
|
||||
assertTrue(exists())
|
||||
assertTrue(isFile)
|
||||
assertFalse(isDirectory)
|
||||
assertFalse(isVirtual)
|
||||
size?.let { assertEquals(it, length()) }
|
||||
mimeType?.let { assertEquals(it, type) }
|
||||
parent?.let { assertEquals(it.uri.toString(), parentFile!!.uri.toString()) }
|
||||
}
|
||||
|
||||
internal fun DocumentFile.assertRegularFolder(name: String? = null, parent: DocumentFile? = null) {
|
||||
name?.let { assertEquals(it, this.name) }
|
||||
assertTrue(exists())
|
||||
assertFalse(isFile)
|
||||
assertTrue(isDirectory)
|
||||
assertFalse(isVirtual)
|
||||
parent?.let { assertEquals(it.uri.toString(), parentFile!!.uri.toString()) }
|
||||
}
|
||||
|
||||
internal fun DocumentFile.assertRecentlyModified() {
|
||||
val diff = System.currentTimeMillis() - lastModified()
|
||||
assertTrue("File $name older than expected: $diff", diff < RECENT_MILLISECONDS)
|
||||
}
|
||||
|
||||
internal fun assertExistsOnServer(client: OwnCloudClient, remotePath: String, shouldExit: Boolean) {
|
||||
val result = ExistenceCheckRemoteOperation(remotePath, !shouldExit).execute(client)
|
||||
assertTrue("$result", result.isSuccess)
|
||||
}
|
||||
|
||||
internal fun assertListFilesEquals(expected: Collection<DocumentFile>, actual: Collection<DocumentFile>) {
|
||||
// assertEquals(
|
||||
// "Actual: ${actual.map { it.name.toString() }}",
|
||||
// expected.map { it.uri.toString() }.apply { sorted() },
|
||||
// actual.map { it.uri.toString() }.apply { sorted() },
|
||||
// )
|
||||
// FIXME replace with commented out stronger assertion above
|
||||
// when parallel [UploadFileOperation]s don't bring back deleted files
|
||||
val expectedSet = HashSet<String>(expected.map { it.uri.toString() })
|
||||
val actualSet = HashSet<String>(actual.map { it.uri.toString() })
|
||||
assertTrue(actualSet.containsAll(expectedSet))
|
||||
actualSet.removeAll(expectedSet)
|
||||
actualSet.forEach {
|
||||
Log.e("TEST", "Error: Found unexpected file: $it")
|
||||
}
|
||||
}
|
||||
|
||||
internal fun assertReadEquals(data: ByteArray, inputStream: InputStream?) {
|
||||
assertNotNull(inputStream)
|
||||
inputStream!!.use {
|
||||
assertArrayEquals(data, it.readBytes())
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as [DocumentFile.findFile] only that it re-queries when the first result was stale.
|
||||
*
|
||||
* Most documents providers including Nextcloud are listing the full directory content
|
||||
* when querying for a specific file in a directory,
|
||||
* so there is no point in trying to optimize the query by not listing all children.
|
||||
*/
|
||||
suspend fun DocumentFile.findFileBlocking(context: Context, displayName: String): DocumentFile? {
|
||||
val files = listFilesBlocking(context)
|
||||
for (doc in files) {
|
||||
if (displayName == doc.name) return doc
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Works like [DocumentFile.listFiles] except that it waits until the DocumentProvider has a result.
|
||||
* This prevents getting an empty list even though there are children to be listed.
|
||||
*/
|
||||
suspend fun DocumentFile.listFilesBlocking(context: Context) = withContext(Dispatchers.IO) {
|
||||
val resolver = context.contentResolver
|
||||
val childrenUri = buildChildDocumentsUriUsingTree(uri, getDocumentId(uri))
|
||||
val projection = arrayOf(COLUMN_DOCUMENT_ID, COLUMN_MIME_TYPE)
|
||||
val result = ArrayList<DocumentFile>()
|
||||
|
||||
try {
|
||||
getLoadedCursor {
|
||||
resolver.query(childrenUri, projection, null, null, null)
|
||||
}
|
||||
} catch (e: TimeoutCancellationException) {
|
||||
throw IOException(e)
|
||||
}.use { cursor ->
|
||||
while (cursor.moveToNext()) {
|
||||
val documentId = cursor.getString(0)
|
||||
val isDirectory = cursor.getString(1) == MIME_TYPE_DIR
|
||||
val file = if (isDirectory) {
|
||||
val treeUri = buildTreeDocumentUri(uri.authority, documentId)
|
||||
DocumentFile.fromTreeUri(context, treeUri)!!
|
||||
} else {
|
||||
val documentUri = buildDocumentUriUsingTree(uri, documentId)
|
||||
DocumentFile.fromSingleUri(context, documentUri)!!
|
||||
}
|
||||
result.add(file)
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a cursor for the given query while ensuring that the cursor was loaded.
|
||||
*
|
||||
* When the SAF backend is a cloud storage provider (e.g. Nextcloud),
|
||||
* it can happen that the query returns an outdated (e.g. empty) cursor
|
||||
* which will only be updated in response to this query.
|
||||
*
|
||||
* See: https://commonsware.com/blog/2019/12/14/scoped-storage-stories-listfiles-woe.html
|
||||
*
|
||||
* This method uses a [suspendCancellableCoroutine] to wait for the result of a [ContentObserver]
|
||||
* registered on the cursor in case the cursor is still loading ([EXTRA_LOADING]).
|
||||
* If the cursor is not loading, it will be returned right away.
|
||||
*
|
||||
* @param timeout an optional time-out in milliseconds
|
||||
* @throws TimeoutCancellationException if there was no result before the time-out
|
||||
* @throws IOException if the query returns null
|
||||
*/
|
||||
@Suppress("EXPERIMENTAL_API_USAGE")
|
||||
@VisibleForTesting
|
||||
internal suspend fun getLoadedCursor(timeout: Long = 15_000, query: () -> Cursor?) =
|
||||
withTimeout(timeout) {
|
||||
suspendCancellableCoroutine<Cursor> { cont ->
|
||||
val cursor = query() ?: throw IOException("Initial query returned no results")
|
||||
cont.invokeOnCancellation { cursor.close() }
|
||||
val loading = cursor.extras.getBoolean(EXTRA_LOADING, false)
|
||||
if (loading) {
|
||||
Log.e("TEST", "Cursor was loading, wait for update...")
|
||||
cursor.registerContentObserver(
|
||||
object : ContentObserver(null) {
|
||||
override fun onChange(selfChange: Boolean, uri: Uri?) {
|
||||
cursor.close()
|
||||
val newCursor = query()
|
||||
if (newCursor == null) cont.cancel(IOException("Re-query returned no results"))
|
||||
else cont.resume(newCursor)
|
||||
}
|
||||
}
|
||||
)
|
||||
} else {
|
||||
// not loading, return cursor right away
|
||||
cont.resume(cursor)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,207 +0,0 @@
|
||||
package com.owncloud.android.providers
|
||||
|
||||
import android.provider.DocumentsContract
|
||||
import android.util.Log
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import com.owncloud.android.AbstractOnServerIT
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.datamodel.OCFile.ROOT_PATH
|
||||
import com.owncloud.android.lib.common.network.WebdavUtils
|
||||
import com.owncloud.android.providers.DocumentsProviderUtils.assertExistsOnServer
|
||||
import com.owncloud.android.providers.DocumentsProviderUtils.assertListFilesEquals
|
||||
import com.owncloud.android.providers.DocumentsProviderUtils.assertReadEquals
|
||||
import com.owncloud.android.providers.DocumentsProviderUtils.assertRecentlyModified
|
||||
import com.owncloud.android.providers.DocumentsProviderUtils.assertRegularFile
|
||||
import com.owncloud.android.providers.DocumentsProviderUtils.assertRegularFolder
|
||||
import com.owncloud.android.providers.DocumentsProviderUtils.findFileBlocking
|
||||
import com.owncloud.android.providers.DocumentsProviderUtils.getOCFile
|
||||
import com.owncloud.android.providers.DocumentsProviderUtils.listFilesBlocking
|
||||
import com.owncloud.android.providers.DocumentsStorageProvider.DOCUMENTID_SEPARATOR
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import net.bytebuddy.utility.RandomString
|
||||
import org.apache.commons.httpclient.HttpStatus
|
||||
import org.apache.commons.httpclient.methods.ByteArrayRequestEntity
|
||||
import org.apache.commons.httpclient.methods.PutMethod
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import kotlin.random.Random
|
||||
|
||||
private const val MAX_FILE_NAME_LENGTH = 225
|
||||
|
||||
class DocumentsStorageProviderIT : AbstractOnServerIT() {
|
||||
|
||||
private val context = targetContext
|
||||
private val contentResolver = context.contentResolver
|
||||
private val authority = context.getString(R.string.document_provider_authority)
|
||||
|
||||
private val rootFileId = storageManager.getFileByEncryptedRemotePath(ROOT_PATH).fileId
|
||||
private val documentId = "${account.hashCode()}${DOCUMENTID_SEPARATOR}$rootFileId"
|
||||
private val uri = DocumentsContract.buildTreeDocumentUri(authority, documentId)
|
||||
private val rootDir get() = DocumentFile.fromTreeUri(context, uri)!!
|
||||
|
||||
@Before
|
||||
fun before() {
|
||||
// DocumentsProvider#onCreate() is called when the application is started
|
||||
// which is *after* AbstractOnServerIT adds the accounts (when the app is freshly installed).
|
||||
// So we need to query our roots here to ensure that the internal storage map is initialized.
|
||||
contentResolver.query(DocumentsContract.buildRootsUri(authority), null, null, null)
|
||||
assertTrue("Storage root does not exist", rootDir.exists())
|
||||
assertTrue(rootDir.isDirectory)
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all files in [rootDir] after each test.
|
||||
*
|
||||
* We can't use [AbstractOnServerIT.after] as this is only deleting remote files.
|
||||
*/
|
||||
@After
|
||||
override fun after() = runBlocking {
|
||||
rootDir.listFilesBlocking(context).forEach {
|
||||
Log.e("TEST", "Deleting ${it.name}...")
|
||||
it.delete()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCreateDeleteFiles() = runBlocking {
|
||||
// no files in root initially
|
||||
assertListFilesEquals(emptyList(), rootDir.listFilesBlocking(context))
|
||||
|
||||
// create first file
|
||||
val name1 = RandomString.make()
|
||||
val type1 = "text/html"
|
||||
val file1 = rootDir.createFile(type1, name1)!!
|
||||
|
||||
// check assumptions
|
||||
@Suppress("ForbiddenComment")
|
||||
file1.assertRegularFile(name1, 0L, null/* FIXME: type1 */, rootDir)
|
||||
file1.assertRecentlyModified()
|
||||
|
||||
// file1 is found in root
|
||||
assertListFilesEquals(listOf(file1), rootDir.listFilesBlocking(context).toList())
|
||||
|
||||
// file1 was uploaded
|
||||
val ocFile1 = file1.getOCFile(storageManager)!!
|
||||
assertExistsOnServer(client, ocFile1.remotePath, true)
|
||||
|
||||
// create second long file with long file name
|
||||
val name2 = RandomString.make(MAX_FILE_NAME_LENGTH)
|
||||
val type2 = "application/octet-stream"
|
||||
val file2 = rootDir.createFile(type2, name2)!!
|
||||
|
||||
// file2 was uploaded
|
||||
val ocFile2 = file2.getOCFile(storageManager)!!
|
||||
assertExistsOnServer(client, ocFile2.remotePath, true)
|
||||
|
||||
// check assumptions
|
||||
file2.assertRegularFile(name2, 0L, type2, rootDir)
|
||||
file2.assertRecentlyModified()
|
||||
|
||||
// both files get listed in root
|
||||
assertListFilesEquals(listOf(file1, file2), rootDir.listFiles().toList())
|
||||
|
||||
// delete first file
|
||||
assertTrue(file1.delete())
|
||||
assertFalse(file1.exists())
|
||||
assertExistsOnServer(client, ocFile1.remotePath, false)
|
||||
|
||||
// only second file gets listed in root
|
||||
assertListFilesEquals(listOf(file2), rootDir.listFiles().toList())
|
||||
|
||||
// delete also second file
|
||||
assertTrue(file2.delete())
|
||||
assertFalse(file2.exists())
|
||||
assertExistsOnServer(client, ocFile2.remotePath, false)
|
||||
|
||||
// no more files in root
|
||||
assertListFilesEquals(emptyList(), rootDir.listFilesBlocking(context))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testReadWriteFiles() {
|
||||
// create random file
|
||||
val file1 = rootDir.createFile("application/octet-stream", RandomString.make())!!
|
||||
file1.assertRegularFile(size = 0L)
|
||||
|
||||
// write random bytes to file
|
||||
@Suppress("MagicNumber")
|
||||
val dataSize = Random.nextInt(1, 99) * 1024
|
||||
val data1 = Random.nextBytes(dataSize)
|
||||
contentResolver.openOutputStream(file1.uri, "wt").use {
|
||||
it!!.write(data1)
|
||||
}
|
||||
|
||||
// read back random bytes
|
||||
assertReadEquals(data1, contentResolver.openInputStream(file1.uri))
|
||||
|
||||
// file size was updated correctly
|
||||
file1.assertRegularFile(size = data1.size.toLong())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCreateDeleteFolders() = runBlocking {
|
||||
// create a new folder
|
||||
val dirName1 = RandomString.make()
|
||||
val dir1 = rootDir.createDirectory(dirName1)!!
|
||||
dir1.assertRegularFolder(dirName1, rootDir)
|
||||
// FIXME about a minute gets lost somewhere after CFO sets the correct time
|
||||
@Suppress("MagicNumber")
|
||||
assertTrue(System.currentTimeMillis() - dir1.lastModified() < 60_000)
|
||||
// dir1.assertRecentlyModified()
|
||||
|
||||
// ensure folder was uploaded to server
|
||||
val ocDir1 = dir1.getOCFile(storageManager)!!
|
||||
assertExistsOnServer(client, ocDir1.remotePath, true)
|
||||
|
||||
// create file in folder
|
||||
val file1 = dir1.createFile("text/html", RandomString.make())!!
|
||||
file1.assertRegularFile(parent = dir1)
|
||||
val ocFile1 = file1.getOCFile(storageManager)!!
|
||||
assertExistsOnServer(client, ocFile1.remotePath, true)
|
||||
|
||||
// we find the new file in the created folder and get it in the list
|
||||
assertEquals(file1.uri.toString(), dir1.findFileBlocking(context, file1.name!!)!!.uri.toString())
|
||||
assertListFilesEquals(listOf(file1), dir1.listFilesBlocking(context))
|
||||
|
||||
// delete folder
|
||||
dir1.delete()
|
||||
assertFalse(dir1.exists())
|
||||
assertExistsOnServer(client, ocDir1.remotePath, false)
|
||||
|
||||
// ensure file got deleted with it
|
||||
assertFalse(file1.exists())
|
||||
assertExistsOnServer(client, ocFile1.remotePath, false)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testServerChangedFileContent() {
|
||||
// create random file
|
||||
val file1 = rootDir.createFile("text/plain", RandomString.make())!!
|
||||
file1.assertRegularFile(size = 0L)
|
||||
|
||||
val content1 = "initial content".toByteArray()
|
||||
|
||||
// write content bytes to file
|
||||
contentResolver.openOutputStream(file1.uri, "wt").use {
|
||||
it!!.write(content1)
|
||||
}
|
||||
|
||||
val remotePath = file1.getOCFile(storageManager)!!.remotePath
|
||||
|
||||
val content2 = "new content".toByteArray()
|
||||
|
||||
// modify content on server side
|
||||
val putMethod = PutMethod(client.webdavUri.toString() + WebdavUtils.encodePath(remotePath))
|
||||
putMethod.setRequestEntity(ByteArrayRequestEntity(content2))
|
||||
assertEquals(HttpStatus.SC_NO_CONTENT, client.executeMethod(putMethod))
|
||||
client.exhaustResponse(putMethod.responseBodyAsStream)
|
||||
putMethod.releaseConnection() // let the connection available for other methods
|
||||
|
||||
// read back content bytes
|
||||
assertReadEquals(content2, contentResolver.openInputStream(file1.uri))
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2020 Tobias Kaminsky
|
||||
* Copyright (C) 2020 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.ui.dialog
|
||||
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.nextcloud.client.TestActivity
|
||||
import com.owncloud.android.AbstractIT
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import com.owncloud.android.utils.ScreenshotTest
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
||||
class SendFilesDialogTest : AbstractIT() {
|
||||
@get:Rule
|
||||
val testActivityRule = IntentsTestRule(TestActivity::class.java, true, false)
|
||||
|
||||
@Test
|
||||
@ScreenshotTest
|
||||
fun showDialog() {
|
||||
val activity = testActivityRule.launchActivity(null)
|
||||
|
||||
val fm: FragmentManager = activity.supportFragmentManager
|
||||
val ft = fm.beginTransaction()
|
||||
ft.addToBackStack(null)
|
||||
|
||||
val files = setOf(
|
||||
OCFile("/1.jpg").apply {
|
||||
mimeType = "image/jpg"
|
||||
},
|
||||
OCFile("/2.jpg").apply {
|
||||
mimeType = "image/jpg"
|
||||
}
|
||||
)
|
||||
|
||||
val sut = SendFilesDialog.newInstance(files)
|
||||
sut.show(ft, "TAG_SEND_SHARE_DIALOG")
|
||||
|
||||
InstrumentationRegistry.getInstrumentation().waitForIdleSync()
|
||||
shortSleep()
|
||||
|
||||
sut.requireDialog().window?.decorView.let { screenshot(it) }
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2020 Tobias Kaminsky
|
||||
* Copyright (C) 2020 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.ui.dialog
|
||||
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.nextcloud.client.TestActivity
|
||||
import com.owncloud.android.AbstractIT
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import com.owncloud.android.lib.resources.status.OCCapability
|
||||
import com.owncloud.android.utils.ScreenshotTest
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
||||
class SendShareDialogTest : AbstractIT() {
|
||||
@get:Rule
|
||||
val testActivityRule = IntentsTestRule(TestActivity::class.java, true, false)
|
||||
|
||||
@Test
|
||||
@ScreenshotTest
|
||||
fun showDialog() {
|
||||
val activity = testActivityRule.launchActivity(null)
|
||||
|
||||
val fm: FragmentManager = activity.supportFragmentManager
|
||||
val ft = fm.beginTransaction()
|
||||
ft.addToBackStack(null)
|
||||
|
||||
val file = OCFile("/1.jpg").apply {
|
||||
mimeType = "image/jpg"
|
||||
}
|
||||
|
||||
val sut = SendShareDialog.newInstance(file, false, OCCapability())
|
||||
sut.show(ft, "TAG_SEND_SHARE_DIALOG")
|
||||
|
||||
InstrumentationRegistry.getInstrumentation().waitForIdleSync()
|
||||
shortSleep()
|
||||
|
||||
sut.requireDialog().window?.decorView.let { screenshot(it) }
|
||||
}
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2020 Tobias Kaminsky
|
||||
* Copyright (C) 2020 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.ui.dialog
|
||||
|
||||
import android.view.Window
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule
|
||||
import androidx.test.internal.runner.junit4.statement.UiThreadStatement
|
||||
import com.nextcloud.client.TestActivity
|
||||
import com.owncloud.android.AbstractIT
|
||||
import com.owncloud.android.utils.ScreenshotTest
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import java.util.Objects
|
||||
|
||||
class SetupEncryptionDialogFragmentIT : AbstractIT() {
|
||||
@get:Rule
|
||||
val testActivityRule = IntentsTestRule(TestActivity::class.java, true, false)
|
||||
|
||||
@Test
|
||||
@ScreenshotTest
|
||||
fun showMnemonic() {
|
||||
val activity = testActivityRule.launchActivity(null)
|
||||
|
||||
val sut = SetupEncryptionDialogFragment.newInstance(user, 0)
|
||||
|
||||
sut.show(activity.supportFragmentManager, "1")
|
||||
|
||||
val keyWords = listOf(
|
||||
"ability",
|
||||
"able",
|
||||
"about",
|
||||
"above",
|
||||
"absent",
|
||||
"absorb",
|
||||
"abstract",
|
||||
"absurd",
|
||||
"abuse",
|
||||
"access",
|
||||
"accident",
|
||||
"account",
|
||||
"accuse"
|
||||
)
|
||||
|
||||
sut.setMnemonic(keyWords)
|
||||
|
||||
UiThreadStatement.runOnUiThread {
|
||||
sut.showMnemonicInfo()
|
||||
}
|
||||
|
||||
waitForIdleSync()
|
||||
|
||||
screenshot(Objects.requireNonNull<Window>(sut.requireDialog().window).decorView)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ScreenshotTest
|
||||
fun error() {
|
||||
val activity = testActivityRule.launchActivity(null)
|
||||
|
||||
val sut = SetupEncryptionDialogFragment.newInstance(user, 0)
|
||||
|
||||
sut.show(activity.supportFragmentManager, "1")
|
||||
|
||||
UiThreadStatement.runOnUiThread {
|
||||
sut.errorSavingKeys()
|
||||
}
|
||||
|
||||
waitForIdleSync()
|
||||
|
||||
screenshot(Objects.requireNonNull<Window>(sut.requireDialog().window).decorView)
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,8 @@
|
||||
|
||||
package com.owncloud.android.ui.dialog;
|
||||
|
||||
import android.Manifest;
|
||||
|
||||
import com.owncloud.android.AbstractIT;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.ui.activity.FileDisplayActivity;
|
||||
@@ -32,6 +34,7 @@ import org.junit.Test;
|
||||
import java.util.Objects;
|
||||
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule;
|
||||
import androidx.test.rule.GrantPermissionRule;
|
||||
|
||||
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
|
||||
|
||||
@@ -40,6 +43,11 @@ public class SyncFileNotEnoughSpaceDialogFragmentTest extends AbstractIT {
|
||||
true,
|
||||
false);
|
||||
|
||||
@Rule
|
||||
public final GrantPermissionRule permissionRule = GrantPermissionRule.grant(
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
|
||||
|
||||
@Test
|
||||
public void showNotEnoughSpaceDialogForFolder() {
|
||||
FileDisplayActivity test = activityRule.launchActivity(null);
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2020 Tobias Kaminsky
|
||||
* Copyright (C) 2020 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.owncloud.android.ui.fragment
|
||||
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule
|
||||
import androidx.test.internal.runner.junit4.statement.UiThreadStatement.runOnUiThread
|
||||
import com.nextcloud.client.TestActivity
|
||||
import com.owncloud.android.AbstractIT
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.utils.DisplayUtils
|
||||
import com.owncloud.android.utils.ScreenshotTest
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
||||
class AvatarIT : AbstractIT() {
|
||||
@get:Rule
|
||||
val testActivityRule = IntentsTestRule(TestActivity::class.java, true, false)
|
||||
|
||||
@Test
|
||||
@ScreenshotTest
|
||||
fun showAvatars() {
|
||||
val avatarRadius = targetContext.resources.getDimension(R.dimen.list_item_avatar_icon_radius)
|
||||
val width = DisplayUtils.convertDpToPixel(2 * avatarRadius, targetContext)
|
||||
val sut = testActivityRule.launchActivity(null)
|
||||
val fragment = AvatarTestFragment()
|
||||
|
||||
sut.addFragment(fragment)
|
||||
|
||||
runOnUiThread {
|
||||
fragment.addAvatar("Admin", avatarRadius, width, targetContext)
|
||||
fragment.addAvatar("Test Server Admin", avatarRadius, width, targetContext)
|
||||
fragment.addAvatar("Cormier Paulette", avatarRadius, width, targetContext)
|
||||
fragment.addAvatar("winston brent", avatarRadius, width, targetContext)
|
||||
fragment.addAvatar("Baker James Lorena", avatarRadius, width, targetContext)
|
||||
fragment.addAvatar("Baker James Lorena", avatarRadius, width, targetContext)
|
||||
fragment.addAvatar("[email protected]", avatarRadius, width, targetContext)
|
||||
}
|
||||
|
||||
shortSleep()
|
||||
waitForIdleSync()
|
||||
screenshot(sut)
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2020 Tobias Kaminsky
|
||||
* Copyright (C) 2020 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.ui.fragment
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.RelativeLayout
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.ui.TextDrawable
|
||||
|
||||
internal class AvatarTestFragment : Fragment() {
|
||||
lateinit var list: LinearLayout
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
val view: View = inflater.inflate(R.layout.avatar_fragment, null)
|
||||
|
||||
list = view.findViewById(R.id.avatar_list)
|
||||
|
||||
return view
|
||||
}
|
||||
|
||||
fun addAvatar(name: String, avatarRadius: Float, width: Int, targetContext: Context) {
|
||||
val margin = padding
|
||||
val imageView = ImageView(targetContext)
|
||||
imageView.setImageDrawable(TextDrawable.createNamedAvatar(name, avatarRadius))
|
||||
|
||||
val layoutParams: RelativeLayout.LayoutParams = RelativeLayout.LayoutParams(width, width)
|
||||
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT)
|
||||
layoutParams.setMargins(margin, margin, margin, margin)
|
||||
imageView.layoutParams = layoutParams
|
||||
|
||||
list.addView(imageView)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val padding = 10
|
||||
}
|
||||
}
|
||||
@@ -1,182 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2020 Tobias Kaminsky
|
||||
* Copyright (C) 2020 Nextcloud GmbH
|
||||
* Copyright (C) 2020 Chris Narkiewicz <[email protected]>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.ui.fragment
|
||||
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule
|
||||
import com.nextcloud.client.TestActivity
|
||||
import com.owncloud.android.AbstractIT
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import com.owncloud.android.lib.resources.activities.model.Activity
|
||||
import com.owncloud.android.lib.resources.activities.model.RichElement
|
||||
import com.owncloud.android.lib.resources.activities.model.RichObject
|
||||
import com.owncloud.android.lib.resources.activities.models.PreviewObject
|
||||
import com.owncloud.android.utils.ScreenshotTest
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import java.util.GregorianCalendar
|
||||
|
||||
class FileDetailFragmentStaticServerIT : AbstractIT() {
|
||||
@get:Rule
|
||||
val testActivityRule = IntentsTestRule(TestActivity::class.java, true, false)
|
||||
|
||||
val file = OCFile("/", "00000001")
|
||||
|
||||
@Test
|
||||
@ScreenshotTest
|
||||
fun showFileDetailActivitiesFragment() {
|
||||
val sut = testActivityRule.launchActivity(null)
|
||||
sut.addFragment(FileDetailActivitiesFragment.newInstance(file, user))
|
||||
|
||||
waitForIdleSync()
|
||||
screenshot(sut)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ScreenshotTest
|
||||
fun showFileDetailSharingFragment() {
|
||||
val sut = testActivityRule.launchActivity(null)
|
||||
sut.addFragment(FileDetailSharingFragment.newInstance(file, user))
|
||||
|
||||
waitForIdleSync()
|
||||
screenshot(sut)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ScreenshotTest
|
||||
@Suppress("MagicNumber")
|
||||
fun showDetailsActivities() {
|
||||
val activity = testActivityRule.launchActivity(null)
|
||||
val sut = FileDetailFragment.newInstance(file, user, 0)
|
||||
activity.addFragment(sut)
|
||||
|
||||
waitForIdleSync()
|
||||
|
||||
val date = GregorianCalendar()
|
||||
date.set(2005, 4, 17, 10, 35, 30) // random date
|
||||
|
||||
val richObjectList: ArrayList<RichObject> = ArrayList()
|
||||
richObjectList.add(RichObject("file", "abc", "text.txt", "/text.txt", "link", "tag"))
|
||||
richObjectList.add(RichObject("file", "1", "text.txt", "/text.txt", "link", "tag"))
|
||||
|
||||
val previewObjectList1: ArrayList<PreviewObject> = ArrayList()
|
||||
previewObjectList1.add(PreviewObject(1, "source", "link", true, "text/plain", "view"))
|
||||
|
||||
val richObjectList2: ArrayList<RichObject> = ArrayList()
|
||||
richObjectList2.add(RichObject("user", "admin", "Admin", "", "", ""))
|
||||
|
||||
val activities = mutableListOf(
|
||||
Activity(
|
||||
1,
|
||||
date.time,
|
||||
date.time,
|
||||
"files",
|
||||
"file_changed",
|
||||
"user1",
|
||||
"user1",
|
||||
"You changed text.txt",
|
||||
"",
|
||||
"icon",
|
||||
"link",
|
||||
"files",
|
||||
"1",
|
||||
"/text.txt",
|
||||
previewObjectList1,
|
||||
RichElement("", richObjectList)
|
||||
),
|
||||
Activity(
|
||||
2,
|
||||
date.time,
|
||||
date.time,
|
||||
"comments",
|
||||
"comments",
|
||||
"user1",
|
||||
"user1",
|
||||
"admin commented",
|
||||
"test2",
|
||||
"icon",
|
||||
"link",
|
||||
"files",
|
||||
"1",
|
||||
"/text.txt",
|
||||
null,
|
||||
null
|
||||
)
|
||||
)
|
||||
|
||||
activity.runOnUiThread {
|
||||
sut.fileDetailActivitiesFragment.populateList(activities as List<Any>?, true)
|
||||
}
|
||||
|
||||
screenshot(activity)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ScreenshotTest
|
||||
fun showDetailsActivitiesNone() {
|
||||
val activity = testActivityRule.launchActivity(null)
|
||||
val sut = FileDetailFragment.newInstance(file, user, 0)
|
||||
activity.addFragment(sut)
|
||||
|
||||
waitForIdleSync()
|
||||
|
||||
activity.runOnUiThread {
|
||||
sut.fileDetailActivitiesFragment.populateList(emptyList(), true)
|
||||
}
|
||||
|
||||
shortSleep()
|
||||
|
||||
screenshot(activity)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ScreenshotTest
|
||||
fun showDetailsActivitiesError() {
|
||||
val activity = testActivityRule.launchActivity(null)
|
||||
val sut = FileDetailFragment.newInstance(file, user, 0)
|
||||
activity.addFragment(sut)
|
||||
|
||||
waitForIdleSync()
|
||||
|
||||
activity.runOnUiThread {
|
||||
sut
|
||||
.fileDetailActivitiesFragment
|
||||
.setErrorContent(targetContext.resources.getString(R.string.file_detail_activity_error))
|
||||
}
|
||||
|
||||
shortSleep()
|
||||
shortSleep()
|
||||
|
||||
screenshot(activity)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ScreenshotTest
|
||||
fun showDetailsSharing() {
|
||||
val sut = testActivityRule.launchActivity(null)
|
||||
sut.addFragment(FileDetailFragment.newInstance(file, user, 1))
|
||||
|
||||
waitForIdleSync()
|
||||
screenshot(sut)
|
||||
}
|
||||
}
|
||||
@@ -1,630 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2020 Tobias Kaminsky
|
||||
* Copyright (C) 2020 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.ui.fragment
|
||||
|
||||
import android.Manifest
|
||||
import android.widget.ImageView
|
||||
import androidx.appcompat.widget.PopupMenu
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule
|
||||
import androidx.test.rule.GrantPermissionRule
|
||||
import com.nextcloud.client.TestActivity
|
||||
import com.owncloud.android.AbstractIT
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import com.owncloud.android.lib.resources.shares.OCShare
|
||||
import com.owncloud.android.lib.resources.shares.OCShare.CREATE_PERMISSION_FLAG
|
||||
import com.owncloud.android.lib.resources.shares.OCShare.DELETE_PERMISSION_FLAG
|
||||
import com.owncloud.android.lib.resources.shares.OCShare.MAXIMUM_PERMISSIONS_FOR_FILE
|
||||
import com.owncloud.android.lib.resources.shares.OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER
|
||||
import com.owncloud.android.lib.resources.shares.OCShare.NO_PERMISSION
|
||||
import com.owncloud.android.lib.resources.shares.OCShare.READ_PERMISSION_FLAG
|
||||
import com.owncloud.android.lib.resources.shares.OCShare.SHARE_PERMISSION_FLAG
|
||||
import com.owncloud.android.lib.resources.shares.ShareType
|
||||
import com.owncloud.android.utils.ScreenshotTest
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
||||
class FileDetailSharingFragmentIT : AbstractIT() {
|
||||
@get:Rule
|
||||
val testActivityRule = IntentsTestRule(TestActivity::class.java, true, false)
|
||||
|
||||
@get:Rule
|
||||
val permissionRule: GrantPermissionRule = GrantPermissionRule.grant(Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
|
||||
lateinit var file: OCFile
|
||||
lateinit var folder: OCFile
|
||||
lateinit var activity: TestActivity
|
||||
|
||||
@Before
|
||||
fun before() {
|
||||
activity = testActivityRule.launchActivity(null)
|
||||
file = OCFile("/test.md").apply {
|
||||
parentId = activity.storageManager.getFileByEncryptedRemotePath("/").fileId
|
||||
permissions = OCFile.PERMISSION_CAN_RESHARE
|
||||
}
|
||||
|
||||
folder = OCFile("/test").apply {
|
||||
setFolder()
|
||||
parentId = activity.storageManager.getFileByEncryptedRemotePath("/").fileId
|
||||
permissions = OCFile.PERMISSION_CAN_RESHARE
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@ScreenshotTest
|
||||
fun listSharesFileNone() {
|
||||
show(file)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ScreenshotTest
|
||||
fun listSharesFileResharingNotAllowed() {
|
||||
file.permissions = ""
|
||||
|
||||
show(file)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ScreenshotTest
|
||||
@Suppress("MagicNumber")
|
||||
fun listSharesFileAllShareTypes() {
|
||||
OCShare(file.decryptedRemotePath).apply {
|
||||
remoteId = 1
|
||||
shareType = ShareType.USER
|
||||
sharedWithDisplayName = "Admin"
|
||||
permissions = MAXIMUM_PERMISSIONS_FOR_FILE
|
||||
userId = getUserId(user)
|
||||
activity.storageManager.saveShare(this)
|
||||
}
|
||||
|
||||
OCShare(file.decryptedRemotePath).apply {
|
||||
remoteId = 2
|
||||
shareType = ShareType.GROUP
|
||||
sharedWithDisplayName = "Group"
|
||||
permissions = MAXIMUM_PERMISSIONS_FOR_FILE
|
||||
userId = getUserId(user)
|
||||
activity.storageManager.saveShare(this)
|
||||
}
|
||||
|
||||
OCShare(file.decryptedRemotePath).apply {
|
||||
remoteId = 3
|
||||
shareType = ShareType.EMAIL
|
||||
sharedWithDisplayName = "[email protected]"
|
||||
userId = getUserId(user)
|
||||
activity.storageManager.saveShare(this)
|
||||
}
|
||||
|
||||
OCShare(file.decryptedRemotePath).apply {
|
||||
remoteId = 4
|
||||
shareType = ShareType.PUBLIC_LINK
|
||||
sharedWithDisplayName = "Customer"
|
||||
activity.storageManager.saveShare(this)
|
||||
}
|
||||
|
||||
OCShare(file.decryptedRemotePath).apply {
|
||||
remoteId = 5
|
||||
shareType = ShareType.PUBLIC_LINK
|
||||
sharedWithDisplayName = "Colleagues"
|
||||
activity.storageManager.saveShare(this)
|
||||
}
|
||||
|
||||
OCShare(file.decryptedRemotePath).apply {
|
||||
remoteId = 6
|
||||
shareType = ShareType.FEDERATED
|
||||
sharedWithDisplayName = "[email protected]"
|
||||
permissions = OCShare.FEDERATED_PERMISSIONS_FOR_FILE
|
||||
userId = getUserId(user)
|
||||
activity.storageManager.saveShare(this)
|
||||
}
|
||||
|
||||
OCShare(file.decryptedRemotePath).apply {
|
||||
remoteId = 7
|
||||
shareType = ShareType.CIRCLE
|
||||
sharedWithDisplayName = "Private circle"
|
||||
permissions = SHARE_PERMISSION_FLAG
|
||||
userId = getUserId(user)
|
||||
activity.storageManager.saveShare(this)
|
||||
}
|
||||
|
||||
OCShare(file.decryptedRemotePath).apply {
|
||||
remoteId = 8
|
||||
shareType = ShareType.ROOM
|
||||
sharedWithDisplayName = "Meeting"
|
||||
permissions = SHARE_PERMISSION_FLAG
|
||||
userId = getUserId(user)
|
||||
activity.storageManager.saveShare(this)
|
||||
}
|
||||
|
||||
show(file)
|
||||
}
|
||||
|
||||
private fun show(file: OCFile) {
|
||||
val fragment = FileDetailSharingFragment.newInstance(file, user)
|
||||
|
||||
activity.addFragment(fragment)
|
||||
|
||||
waitForIdleSync()
|
||||
|
||||
screenshot(activity)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Suppress("MagicNumber")
|
||||
// public link and email are handled the same way
|
||||
fun publicLinkOptionMenuFolder() {
|
||||
val sut = FileDetailSharingFragment.newInstance(file, user)
|
||||
activity.addFragment(sut)
|
||||
shortSleep()
|
||||
sut.refreshCapabilitiesFromDB()
|
||||
|
||||
val overflowMenuShareLink = ImageView(targetContext)
|
||||
val popup = PopupMenu(targetContext, overflowMenuShareLink)
|
||||
popup.inflate(R.menu.fragment_file_detail_sharing_public_link)
|
||||
val publicShare = OCShare().apply {
|
||||
isFolder = true
|
||||
shareType = ShareType.PUBLIC_LINK
|
||||
permissions = 17
|
||||
}
|
||||
|
||||
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
|
||||
|
||||
// check if items are visible
|
||||
assertTrue(popup.menu.findItem(R.id.action_hide_file_download).isVisible)
|
||||
assertTrue(popup.menu.findItem(R.id.action_password).isVisible)
|
||||
assertTrue(popup.menu.findItem(R.id.action_share_expiration_date).isVisible)
|
||||
assertTrue(popup.menu.findItem(R.id.action_share_send_link).isVisible)
|
||||
assertTrue(popup.menu.findItem(R.id.action_share_send_note).isVisible)
|
||||
assertTrue(popup.menu.findItem(R.id.action_edit_label).isVisible)
|
||||
assertTrue(popup.menu.findItem(R.id.action_unshare).isVisible)
|
||||
assertTrue(popup.menu.findItem(R.id.action_add_another_public_share_link).isVisible)
|
||||
|
||||
// read-only
|
||||
assertTrue(popup.menu.findItem(R.id.link_share_read_only).isChecked)
|
||||
assertFalse(popup.menu.findItem(R.id.link_share_allow_upload_and_editing).isChecked)
|
||||
assertFalse(popup.menu.findItem(R.id.link_share_file_drop).isChecked)
|
||||
|
||||
// upload and editing
|
||||
publicShare.permissions = MAXIMUM_PERMISSIONS_FOR_FOLDER
|
||||
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
|
||||
assertFalse(popup.menu.findItem(R.id.link_share_read_only).isChecked)
|
||||
assertTrue(popup.menu.findItem(R.id.link_share_allow_upload_and_editing).isChecked)
|
||||
assertFalse(popup.menu.findItem(R.id.link_share_file_drop).isChecked)
|
||||
|
||||
// file drop
|
||||
publicShare.permissions = 4
|
||||
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
|
||||
assertFalse(popup.menu.findItem(R.id.link_share_read_only).isChecked)
|
||||
assertFalse(popup.menu.findItem(R.id.link_share_allow_upload_and_editing).isChecked)
|
||||
assertTrue(popup.menu.findItem(R.id.link_share_file_drop).isChecked)
|
||||
|
||||
// password protection
|
||||
publicShare.shareWith = "someValue"
|
||||
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
|
||||
assertTrue(
|
||||
popup.menu.findItem(R.id.action_password).title == targetContext.getString(R.string.share_password_title)
|
||||
)
|
||||
|
||||
publicShare.shareWith = ""
|
||||
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
|
||||
assertTrue(
|
||||
popup.menu.findItem(R.id.action_password).title == targetContext.getString(R.string.share_no_password_title)
|
||||
)
|
||||
|
||||
// hide download
|
||||
publicShare.isHideFileDownload = true
|
||||
publicShare.permissions = MAXIMUM_PERMISSIONS_FOR_FOLDER
|
||||
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
|
||||
assertTrue(popup.menu.findItem(R.id.action_hide_file_download).isChecked)
|
||||
|
||||
publicShare.isHideFileDownload = false
|
||||
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
|
||||
assertFalse(popup.menu.findItem(R.id.action_hide_file_download).isChecked)
|
||||
|
||||
publicShare.expirationDate = 1582019340000
|
||||
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
|
||||
assertTrue(
|
||||
popup.menu.findItem(R.id.action_share_expiration_date).title
|
||||
.startsWith(targetContext.getString(R.string.share_expiration_date_label).split(" ")[0])
|
||||
)
|
||||
|
||||
publicShare.expirationDate = 0
|
||||
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
|
||||
assertTrue(
|
||||
popup.menu.findItem(R.id.action_share_expiration_date).title ==
|
||||
targetContext.getString(R.string.share_no_expiration_date_label)
|
||||
)
|
||||
|
||||
// file
|
||||
publicShare.isFolder = false
|
||||
publicShare.permissions = READ_PERMISSION_FLAG
|
||||
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
|
||||
// check if items are visible
|
||||
assertTrue(popup.menu.findItem(R.id.action_hide_file_download).isVisible)
|
||||
assertTrue(popup.menu.findItem(R.id.action_password).isVisible)
|
||||
assertTrue(popup.menu.findItem(R.id.action_share_expiration_date).isVisible)
|
||||
assertTrue(popup.menu.findItem(R.id.action_share_send_link).isVisible)
|
||||
assertTrue(popup.menu.findItem(R.id.action_share_send_note).isVisible)
|
||||
assertTrue(popup.menu.findItem(R.id.action_edit_label).isVisible)
|
||||
assertTrue(popup.menu.findItem(R.id.action_unshare).isVisible)
|
||||
assertTrue(popup.menu.findItem(R.id.action_add_another_public_share_link).isVisible)
|
||||
|
||||
assertFalse(popup.menu.findItem(R.id.link_share_read_only).isVisible)
|
||||
assertFalse(popup.menu.findItem(R.id.link_share_allow_upload_and_editing).isVisible)
|
||||
assertFalse(popup.menu.findItem(R.id.link_share_file_drop).isVisible)
|
||||
assertTrue(popup.menu.findItem(R.id.allow_editing).isVisible)
|
||||
|
||||
// allow editing
|
||||
publicShare.permissions = 17 // from server
|
||||
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
|
||||
assertFalse(popup.menu.findItem(R.id.allow_editing).isChecked)
|
||||
|
||||
publicShare.permissions = 19 // from server
|
||||
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
|
||||
assertTrue(popup.menu.findItem(R.id.allow_editing).isChecked)
|
||||
|
||||
// hide download
|
||||
publicShare.isHideFileDownload = true
|
||||
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
|
||||
assertTrue(popup.menu.findItem(R.id.action_hide_file_download).isChecked)
|
||||
|
||||
publicShare.isHideFileDownload = false
|
||||
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
|
||||
assertFalse(popup.menu.findItem(R.id.action_hide_file_download).isChecked)
|
||||
|
||||
// password protection
|
||||
publicShare.isPasswordProtected = true
|
||||
publicShare.shareWith = "someValue"
|
||||
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
|
||||
assertTrue(
|
||||
popup.menu.findItem(R.id.action_password).title == targetContext.getString(R.string.share_password_title)
|
||||
)
|
||||
|
||||
publicShare.isPasswordProtected = false
|
||||
publicShare.shareWith = ""
|
||||
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
|
||||
assertTrue(
|
||||
popup.menu.findItem(R.id.action_password).title == targetContext.getString(R.string.share_no_password_title)
|
||||
)
|
||||
|
||||
// expires
|
||||
publicShare.expirationDate = 1582019340
|
||||
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
|
||||
assertTrue(
|
||||
popup.menu.findItem(R.id.action_share_expiration_date).title
|
||||
.startsWith(targetContext.getString(R.string.share_expiration_date_label).split(" ")[0])
|
||||
)
|
||||
|
||||
publicShare.expirationDate = 0
|
||||
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
|
||||
assertTrue(
|
||||
popup.menu.findItem(R.id.action_share_expiration_date).title ==
|
||||
targetContext.getString(R.string.share_no_expiration_date_label)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Suppress("MagicNumber")
|
||||
// public link and email are handled the same way
|
||||
fun publicLinkOptionMenuFile() {
|
||||
val sut = FileDetailSharingFragment.newInstance(file, user)
|
||||
activity.addFragment(sut)
|
||||
shortSleep()
|
||||
sut.refreshCapabilitiesFromDB()
|
||||
|
||||
val overflowMenuShareLink = ImageView(targetContext)
|
||||
val popup = PopupMenu(targetContext, overflowMenuShareLink)
|
||||
popup.inflate(R.menu.fragment_file_detail_sharing_public_link)
|
||||
val publicShare = OCShare().apply {
|
||||
isFolder = false
|
||||
shareType = ShareType.PUBLIC_LINK
|
||||
permissions = 17
|
||||
}
|
||||
|
||||
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
|
||||
|
||||
// check if items are visible
|
||||
assertTrue(popup.menu.findItem(R.id.action_hide_file_download).isVisible)
|
||||
assertTrue(popup.menu.findItem(R.id.action_password).isVisible)
|
||||
assertTrue(popup.menu.findItem(R.id.action_share_expiration_date).isVisible)
|
||||
assertTrue(popup.menu.findItem(R.id.action_share_send_link).isVisible)
|
||||
assertTrue(popup.menu.findItem(R.id.action_share_send_note).isVisible)
|
||||
assertTrue(popup.menu.findItem(R.id.action_edit_label).isVisible)
|
||||
assertTrue(popup.menu.findItem(R.id.action_unshare).isVisible)
|
||||
assertTrue(popup.menu.findItem(R.id.action_add_another_public_share_link).isVisible)
|
||||
|
||||
assertFalse(popup.menu.findItem(R.id.link_share_read_only).isVisible)
|
||||
assertFalse(popup.menu.findItem(R.id.link_share_allow_upload_and_editing).isVisible)
|
||||
assertFalse(popup.menu.findItem(R.id.link_share_file_drop).isVisible)
|
||||
assertTrue(popup.menu.findItem(R.id.allow_editing).isVisible)
|
||||
|
||||
// password protection
|
||||
publicShare.shareWith = "someValue"
|
||||
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
|
||||
assertTrue(
|
||||
popup.menu.findItem(R.id.action_password).title == targetContext.getString(R.string.share_password_title)
|
||||
)
|
||||
|
||||
publicShare.shareWith = ""
|
||||
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
|
||||
assertTrue(
|
||||
popup.menu.findItem(R.id.action_password).title == targetContext.getString(R.string.share_no_password_title)
|
||||
)
|
||||
|
||||
// hide download
|
||||
publicShare.isHideFileDownload = true
|
||||
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
|
||||
assertTrue(popup.menu.findItem(R.id.action_hide_file_download).isChecked)
|
||||
|
||||
publicShare.isHideFileDownload = false
|
||||
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
|
||||
assertFalse(popup.menu.findItem(R.id.action_hide_file_download).isChecked)
|
||||
|
||||
// expiration date
|
||||
publicShare.expirationDate = 1582019340000
|
||||
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
|
||||
assertTrue(
|
||||
popup.menu.findItem(R.id.action_share_expiration_date).title
|
||||
.startsWith(targetContext.getString(R.string.share_expiration_date_label).split(" ")[0])
|
||||
)
|
||||
|
||||
publicShare.expirationDate = 0
|
||||
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
|
||||
assertTrue(
|
||||
popup.menu.findItem(R.id.action_share_expiration_date).title ==
|
||||
targetContext.getString(R.string.share_no_expiration_date_label)
|
||||
)
|
||||
|
||||
publicShare.isFolder = false
|
||||
publicShare.permissions = READ_PERMISSION_FLAG
|
||||
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
|
||||
|
||||
// allow editing
|
||||
publicShare.permissions = 17 // from server
|
||||
assertFalse(popup.menu.findItem(R.id.allow_editing).isChecked)
|
||||
|
||||
publicShare.permissions = 19 // from server
|
||||
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
|
||||
assertTrue(popup.menu.findItem(R.id.allow_editing).isChecked)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Suppress("MagicNumber")
|
||||
// also applies for
|
||||
// group
|
||||
// conversation
|
||||
// circle
|
||||
// federated share
|
||||
fun userOptionMenuFile() {
|
||||
val sut = FileDetailSharingFragment.newInstance(file, user)
|
||||
activity.addFragment(sut)
|
||||
shortSleep()
|
||||
sut.refreshCapabilitiesFromDB()
|
||||
|
||||
val overflowMenuShareLink = ImageView(targetContext)
|
||||
val popup = PopupMenu(targetContext, overflowMenuShareLink)
|
||||
popup.inflate(R.menu.item_user_sharing_settings)
|
||||
val userShare = OCShare().apply {
|
||||
isFolder = false
|
||||
shareType = ShareType.USER
|
||||
permissions = 17
|
||||
}
|
||||
|
||||
sut.prepareUserOptionsMenu(popup.menu, userShare)
|
||||
assertFalse(popup.menu.findItem(R.id.allow_creating).isVisible)
|
||||
assertFalse(popup.menu.findItem(R.id.allow_deleting).isVisible)
|
||||
|
||||
// allow editing
|
||||
userShare.permissions = 17 // from server
|
||||
assertFalse(popup.menu.findItem(R.id.allow_editing).isChecked)
|
||||
|
||||
userShare.permissions = 19 // from server
|
||||
sut.prepareUserOptionsMenu(popup.menu, userShare)
|
||||
assertTrue(popup.menu.findItem(R.id.allow_editing).isChecked)
|
||||
|
||||
// allow reshare
|
||||
userShare.permissions = 1 // from server
|
||||
sut.prepareUserOptionsMenu(popup.menu, userShare)
|
||||
assertFalse(popup.menu.findItem(R.id.allow_resharing).isChecked)
|
||||
|
||||
userShare.permissions = 17 // from server
|
||||
sut.prepareUserOptionsMenu(popup.menu, userShare)
|
||||
assertTrue(popup.menu.findItem(R.id.allow_resharing).isChecked)
|
||||
|
||||
// set expiration date
|
||||
userShare.expirationDate = 1582019340000
|
||||
sut.prepareUserOptionsMenu(popup.menu, userShare)
|
||||
assertTrue(
|
||||
popup.menu.findItem(R.id.action_expiration_date).title
|
||||
.startsWith(targetContext.getString(R.string.share_expiration_date_label).split(" ")[0])
|
||||
)
|
||||
|
||||
userShare.expirationDate = 0
|
||||
sut.prepareUserOptionsMenu(popup.menu, userShare)
|
||||
assertTrue(
|
||||
popup.menu.findItem(R.id.action_expiration_date).title ==
|
||||
targetContext.getString(R.string.share_no_expiration_date_label)
|
||||
)
|
||||
|
||||
// note
|
||||
assertTrue(popup.menu.findItem(R.id.action_share_send_note).isVisible)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Suppress("MagicNumber")
|
||||
// also applies for
|
||||
// group
|
||||
// conversation
|
||||
// circle
|
||||
// federated share
|
||||
fun userOptionMenuFolder() {
|
||||
val sut = FileDetailSharingFragment.newInstance(file, user)
|
||||
activity.addFragment(sut)
|
||||
shortSleep()
|
||||
sut.refreshCapabilitiesFromDB()
|
||||
|
||||
val overflowMenuShareLink = ImageView(targetContext)
|
||||
val popup = PopupMenu(targetContext, overflowMenuShareLink)
|
||||
popup.inflate(R.menu.item_user_sharing_settings)
|
||||
val userShare = OCShare().apply {
|
||||
isFolder = true
|
||||
shareType = ShareType.USER
|
||||
permissions = 17
|
||||
}
|
||||
|
||||
sut.prepareUserOptionsMenu(popup.menu, userShare)
|
||||
assertTrue(popup.menu.findItem(R.id.allow_creating).isVisible)
|
||||
assertTrue(popup.menu.findItem(R.id.allow_deleting).isVisible)
|
||||
|
||||
// allow editing
|
||||
userShare.permissions = 17 // from server
|
||||
assertFalse(popup.menu.findItem(R.id.allow_editing).isChecked)
|
||||
|
||||
userShare.permissions = 19 // from server
|
||||
sut.prepareUserOptionsMenu(popup.menu, userShare)
|
||||
assertTrue(popup.menu.findItem(R.id.allow_editing).isChecked)
|
||||
|
||||
// allow reshare
|
||||
userShare.permissions = 1 // from server
|
||||
sut.prepareUserOptionsMenu(popup.menu, userShare)
|
||||
assertFalse(popup.menu.findItem(R.id.allow_resharing).isChecked)
|
||||
|
||||
userShare.permissions = 17 // from server
|
||||
sut.prepareUserOptionsMenu(popup.menu, userShare)
|
||||
assertTrue(popup.menu.findItem(R.id.allow_resharing).isChecked)
|
||||
|
||||
// set expiration date
|
||||
userShare.expirationDate = 1582019340000
|
||||
sut.prepareUserOptionsMenu(popup.menu, userShare)
|
||||
assertTrue(
|
||||
popup.menu.findItem(R.id.action_expiration_date).title
|
||||
.startsWith(targetContext.getString(R.string.share_expiration_date_label).split(" ")[0])
|
||||
)
|
||||
|
||||
userShare.expirationDate = 0
|
||||
sut.prepareUserOptionsMenu(popup.menu, userShare)
|
||||
assertTrue(
|
||||
popup.menu.findItem(R.id.action_expiration_date).title ==
|
||||
targetContext.getString(R.string.share_no_expiration_date_label)
|
||||
)
|
||||
|
||||
// note
|
||||
assertTrue(popup.menu.findItem(R.id.action_share_send_note).isVisible)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testUploadAndEditingSharePermissions() {
|
||||
val sut = FileDetailSharingFragment()
|
||||
|
||||
val share = OCShare().apply {
|
||||
permissions = MAXIMUM_PERMISSIONS_FOR_FOLDER
|
||||
}
|
||||
assertTrue(sut.isUploadAndEditingAllowed(share))
|
||||
|
||||
share.permissions = NO_PERMISSION
|
||||
assertFalse(sut.isUploadAndEditingAllowed(share))
|
||||
|
||||
share.permissions = READ_PERMISSION_FLAG
|
||||
assertFalse(sut.isUploadAndEditingAllowed(share))
|
||||
|
||||
share.permissions = CREATE_PERMISSION_FLAG
|
||||
assertFalse(sut.isUploadAndEditingAllowed(share))
|
||||
|
||||
share.permissions = DELETE_PERMISSION_FLAG
|
||||
assertFalse(sut.isUploadAndEditingAllowed(share))
|
||||
|
||||
share.permissions = SHARE_PERMISSION_FLAG
|
||||
assertFalse(sut.isUploadAndEditingAllowed(share))
|
||||
}
|
||||
|
||||
@Test
|
||||
@Suppress("MagicNumber")
|
||||
fun testReadOnlySharePermissions() {
|
||||
val sut = FileDetailSharingFragment()
|
||||
|
||||
val share = OCShare().apply {
|
||||
permissions = 17
|
||||
}
|
||||
assertTrue(sut.isReadOnly(share))
|
||||
|
||||
share.permissions = NO_PERMISSION
|
||||
assertFalse(sut.isReadOnly(share))
|
||||
|
||||
share.permissions = READ_PERMISSION_FLAG
|
||||
assertTrue(sut.isReadOnly(share))
|
||||
|
||||
share.permissions = CREATE_PERMISSION_FLAG
|
||||
assertFalse(sut.isReadOnly(share))
|
||||
|
||||
share.permissions = DELETE_PERMISSION_FLAG
|
||||
assertFalse(sut.isReadOnly(share))
|
||||
|
||||
share.permissions = SHARE_PERMISSION_FLAG
|
||||
assertFalse(sut.isReadOnly(share))
|
||||
|
||||
share.permissions = MAXIMUM_PERMISSIONS_FOR_FOLDER
|
||||
assertFalse(sut.isReadOnly(share))
|
||||
|
||||
share.permissions = MAXIMUM_PERMISSIONS_FOR_FILE
|
||||
assertFalse(sut.isReadOnly(share))
|
||||
}
|
||||
|
||||
@Test
|
||||
@Suppress("MagicNumber")
|
||||
fun testFileDropSharePermissions() {
|
||||
val sut = FileDetailSharingFragment()
|
||||
|
||||
val share = OCShare().apply {
|
||||
permissions = 4
|
||||
}
|
||||
assertTrue(sut.isFileDrop(share))
|
||||
|
||||
share.permissions = NO_PERMISSION
|
||||
assertFalse(sut.isFileDrop(share))
|
||||
|
||||
share.permissions = READ_PERMISSION_FLAG
|
||||
assertFalse(sut.isFileDrop(share))
|
||||
|
||||
share.permissions = CREATE_PERMISSION_FLAG
|
||||
assertTrue(sut.isFileDrop(share))
|
||||
|
||||
share.permissions = DELETE_PERMISSION_FLAG
|
||||
assertFalse(sut.isFileDrop(share))
|
||||
|
||||
share.permissions = SHARE_PERMISSION_FLAG
|
||||
assertFalse(sut.isFileDrop(share))
|
||||
|
||||
share.permissions = MAXIMUM_PERMISSIONS_FOR_FOLDER
|
||||
assertFalse(sut.isFileDrop(share))
|
||||
|
||||
share.permissions = MAXIMUM_PERMISSIONS_FOR_FILE
|
||||
assertFalse(sut.isFileDrop(share))
|
||||
}
|
||||
|
||||
@After
|
||||
fun after() {
|
||||
activity.storageManager.cleanShares()
|
||||
}
|
||||
}
|
||||
@@ -23,20 +23,34 @@
|
||||
package com.owncloud.android.ui.fragment
|
||||
|
||||
import android.Manifest
|
||||
import androidx.test.core.app.ActivityScenario
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.rule.GrantPermissionRule
|
||||
import com.nextcloud.client.account.UserAccountManagerImpl
|
||||
import com.nextcloud.client.device.BatteryStatus
|
||||
import com.nextcloud.client.device.PowerManagementService
|
||||
import com.nextcloud.client.network.Connectivity
|
||||
import com.nextcloud.client.network.ConnectivityService
|
||||
import com.nextcloud.client.preferences.AppPreferences
|
||||
import com.nextcloud.client.preferences.AppPreferencesImpl
|
||||
import com.nextcloud.client.preferences.DarkMode
|
||||
import com.owncloud.android.AbstractOnServerIT
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import com.owncloud.android.MainApp
|
||||
import com.owncloud.android.datamodel.UploadsStorageManager
|
||||
import com.owncloud.android.db.OCUpload
|
||||
import com.owncloud.android.files.services.FileUploader
|
||||
import com.owncloud.android.lib.resources.shares.CreateShareRemoteOperation
|
||||
import com.owncloud.android.lib.resources.shares.OCShare
|
||||
import com.owncloud.android.lib.resources.shares.ShareType
|
||||
import com.owncloud.android.operations.CreateFolderOperation
|
||||
import com.owncloud.android.operations.RefreshFolderOperation
|
||||
import com.owncloud.android.operations.UploadFileOperation
|
||||
import com.owncloud.android.ui.activity.FileDisplayActivity
|
||||
import org.junit.Assert.assertFalse
|
||||
import junit.framework.TestCase
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
|
||||
class OCFileListFragmentIT : AbstractOnServerIT() {
|
||||
companion object {
|
||||
@@ -72,113 +86,216 @@ class OCFileListFragmentIT : AbstractOnServerIT() {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("MagicNumber")
|
||||
fun testEnoughSpaceWithoutLocalFile() {
|
||||
val sut = OCFileListFragment()
|
||||
val ocFile = OCFile("/test.txt")
|
||||
val file = File("/sdcard/test.txt")
|
||||
file.createNewFile()
|
||||
// @ScreenshotTest // todo run without real server
|
||||
fun showRichWorkspace() {
|
||||
assertTrue(CreateFolderOperation("/test/", user, targetContext).execute(client, storageManager).isSuccess)
|
||||
|
||||
ocFile.storagePath = file.absolutePath
|
||||
val ocUpload = OCUpload(
|
||||
getDummyFile("/nonEmpty.txt").absolutePath,
|
||||
"/test/Readme.md",
|
||||
account.name
|
||||
)
|
||||
val newUpload = UploadFileOperation(
|
||||
UploadsStorageManager(UserAccountManagerImpl.fromContext(targetContext), targetContext.contentResolver),
|
||||
connectivityServiceMock,
|
||||
powerManagementServiceMock,
|
||||
user,
|
||||
null,
|
||||
ocUpload,
|
||||
FileUploader.NameCollisionPolicy.DEFAULT,
|
||||
FileUploader.LOCAL_BEHAVIOUR_COPY,
|
||||
targetContext,
|
||||
false,
|
||||
false
|
||||
)
|
||||
|
||||
ocFile.fileLength = 100
|
||||
assertTrue(sut.checkIfEnoughSpace(200L, ocFile))
|
||||
newUpload.addRenameUploadListener {}
|
||||
newUpload.setRemoteFolderToBeCreated()
|
||||
|
||||
ocFile.fileLength = 0
|
||||
assertTrue(sut.checkIfEnoughSpace(200L, ocFile))
|
||||
assertTrue(newUpload.execute(client, storageManager).isSuccess)
|
||||
|
||||
ocFile.fileLength = 100
|
||||
assertFalse(sut.checkIfEnoughSpace(50L, ocFile))
|
||||
assertTrue(
|
||||
RefreshFolderOperation(
|
||||
storageManager.getFileByPath("/test/"),
|
||||
System.currentTimeMillis() / SECOND_IN_MILLIS,
|
||||
false,
|
||||
true,
|
||||
storageManager,
|
||||
account,
|
||||
targetContext
|
||||
)
|
||||
.execute(client)
|
||||
.isSuccess
|
||||
)
|
||||
|
||||
ocFile.fileLength = 100
|
||||
assertFalse(sut.checkIfEnoughSpace(100L, ocFile))
|
||||
val sut = ActivityScenario.launch(FileDisplayActivity::class.java)
|
||||
shortSleep()
|
||||
sut.onActivity { activity -> activity.onBrowsedDownTo(storageManager.getFileByPath("/test/")) }
|
||||
|
||||
shortSleep()
|
||||
shortSleep()
|
||||
|
||||
// sut.onActivity { activity ->
|
||||
// Screenshot.snapActivity(activity).setName("richworkspaces_light").record()
|
||||
// }
|
||||
|
||||
val preferences: AppPreferences = AppPreferencesImpl.fromContext(targetContext)
|
||||
preferences.darkThemeMode = DarkMode.DARK
|
||||
|
||||
sut.onActivity { activity ->
|
||||
MainApp.setAppTheme(DarkMode.DARK)
|
||||
}
|
||||
|
||||
shortSleep()
|
||||
sut.onActivity { activity -> activity.onBackPressed() }
|
||||
|
||||
shortSleep()
|
||||
|
||||
sut.recreate()
|
||||
|
||||
sut.onActivity { activity -> activity.onBrowsedDownTo(storageManager.getFileByPath("/test/")) }
|
||||
|
||||
shortSleep()
|
||||
shortSleep()
|
||||
|
||||
// sut.onActivity { activity ->
|
||||
// Screenshot.snapActivity(activity).setName("richworkspaces_dark").record()
|
||||
// }
|
||||
|
||||
// switch back to light mode
|
||||
preferences.darkThemeMode = DarkMode.LIGHT
|
||||
sut.onActivity { MainApp.setAppTheme(DarkMode.LIGHT) }
|
||||
|
||||
shortSleep()
|
||||
sut.onActivity { activity -> activity.onBackPressed() }
|
||||
|
||||
sut.recreate()
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("MagicNumber")
|
||||
fun testEnoughSpaceWithLocalFile() {
|
||||
val sut = OCFileListFragment()
|
||||
val ocFile = OCFile("/test.txt")
|
||||
val file = File("/sdcard/test.txt")
|
||||
file.writeText("123123")
|
||||
// @ScreenshotTest // todo run without real server
|
||||
fun createAndShowShareToUser() {
|
||||
val path = "/shareToAdmin/"
|
||||
TestCase.assertTrue(
|
||||
CreateFolderOperation(path, user, targetContext)
|
||||
.execute(client, storageManager)
|
||||
.isSuccess
|
||||
)
|
||||
|
||||
ocFile.storagePath = file.absolutePath
|
||||
// share folder to user "admin"
|
||||
TestCase.assertTrue(
|
||||
CreateShareRemoteOperation(
|
||||
path,
|
||||
ShareType.USER,
|
||||
"admin",
|
||||
false,
|
||||
"",
|
||||
OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER
|
||||
)
|
||||
.execute(client).isSuccess
|
||||
)
|
||||
|
||||
ocFile.fileLength = 100
|
||||
assertTrue(sut.checkIfEnoughSpace(200L, ocFile))
|
||||
val sut: FileDisplayActivity = activityRule.launchActivity(null)
|
||||
sut.startSyncFolderOperation(storageManager.getFileByPath("/"), true)
|
||||
|
||||
ocFile.fileLength = 0
|
||||
assertTrue(sut.checkIfEnoughSpace(200L, ocFile))
|
||||
|
||||
ocFile.fileLength = 100
|
||||
assertFalse(sut.checkIfEnoughSpace(50L, ocFile))
|
||||
|
||||
ocFile.fileLength = 100
|
||||
assertFalse(sut.checkIfEnoughSpace(100L, ocFile))
|
||||
shortSleep()
|
||||
InstrumentationRegistry.getInstrumentation().waitForIdleSync()
|
||||
// Screenshot.snapActivity(sut).record()
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("MagicNumber")
|
||||
fun testEnoughSpaceWithoutLocalFolder() {
|
||||
val sut = OCFileListFragment()
|
||||
val ocFile = OCFile("/test/")
|
||||
val file = File("/sdcard/test/")
|
||||
File("/sdcard/test/1.txt").writeText("123123")
|
||||
// @ScreenshotTest // todo run without real server
|
||||
fun createAndShowShareToGroup() {
|
||||
val path = "/shareToGroup/"
|
||||
TestCase.assertTrue(
|
||||
CreateFolderOperation(path, user, targetContext)
|
||||
.execute(client, storageManager)
|
||||
.isSuccess
|
||||
)
|
||||
|
||||
ocFile.storagePath = file.absolutePath
|
||||
// share folder to group
|
||||
assertTrue(
|
||||
CreateShareRemoteOperation(
|
||||
"/shareToGroup/",
|
||||
ShareType.GROUP,
|
||||
"users",
|
||||
false,
|
||||
"",
|
||||
OCShare.DEFAULT_PERMISSION
|
||||
)
|
||||
.execute(client)
|
||||
.isSuccess
|
||||
)
|
||||
|
||||
ocFile.fileLength = 100
|
||||
assertTrue(sut.checkIfEnoughSpace(200L, ocFile))
|
||||
val sut: FileDisplayActivity = activityRule.launchActivity(null)
|
||||
sut.startSyncFolderOperation(storageManager.getFileByPath("/"), true)
|
||||
|
||||
ocFile.fileLength = 0
|
||||
assertTrue(sut.checkIfEnoughSpace(200L, ocFile))
|
||||
|
||||
ocFile.fileLength = 100
|
||||
assertFalse(sut.checkIfEnoughSpace(50L, ocFile))
|
||||
|
||||
ocFile.fileLength = 100
|
||||
assertFalse(sut.checkIfEnoughSpace(100L, ocFile))
|
||||
shortSleep()
|
||||
InstrumentationRegistry.getInstrumentation().waitForIdleSync()
|
||||
// Screenshot.snapActivity(sut).record()
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("MagicNumber")
|
||||
fun testEnoughSpaceWithLocalFolder() {
|
||||
val sut = OCFileListFragment()
|
||||
val ocFile = OCFile("/test/")
|
||||
val folder = File("/sdcard/test/")
|
||||
folder.mkdirs()
|
||||
val file = File("/sdcard/test/1.txt")
|
||||
file.createNewFile()
|
||||
file.writeText("123123")
|
||||
|
||||
ocFile.storagePath = folder.absolutePath
|
||||
ocFile.mimeType = "DIR"
|
||||
|
||||
ocFile.fileLength = 100
|
||||
assertTrue(sut.checkIfEnoughSpace(200L, ocFile))
|
||||
|
||||
ocFile.fileLength = 0
|
||||
assertTrue(sut.checkIfEnoughSpace(200L, ocFile))
|
||||
|
||||
ocFile.fileLength = 100
|
||||
assertFalse(sut.checkIfEnoughSpace(50L, ocFile))
|
||||
|
||||
ocFile.fileLength = 44
|
||||
assertTrue(sut.checkIfEnoughSpace(50L, ocFile))
|
||||
|
||||
ocFile.fileLength = 100
|
||||
assertTrue(sut.checkIfEnoughSpace(100L, ocFile))
|
||||
}
|
||||
// @Test
|
||||
// @ScreenshotTest
|
||||
// fun createAndShowShareToCircle() {
|
||||
// val path = "/shareToCircle/"
|
||||
// TestCase.assertTrue(CreateFolderOperation(path, account, targetContext)
|
||||
// .execute(client, storageManager)
|
||||
// .isSuccess)
|
||||
//
|
||||
// // share folder to circle
|
||||
// // get circleId
|
||||
// val searchResult = GetShareesRemoteOperation("publicCircle", 1, RESULT_PER_PAGE).execute(client)
|
||||
// assertTrue(searchResult.logMessage, searchResult.isSuccess)
|
||||
//
|
||||
// val resultJson: JSONObject = searchResult.data[0] as JSONObject
|
||||
// val circleId: String = resultJson.getJSONObject("value").getString("shareWith")
|
||||
//
|
||||
// assertTrue(CreateShareRemoteOperation("/shareToCircle/",
|
||||
// ShareType.CIRCLE,
|
||||
// circleId,
|
||||
// false,
|
||||
// "",
|
||||
// OCShare.DEFAULT_PERMISSION)
|
||||
// .execute(client).isSuccess)
|
||||
//
|
||||
// val sut: FileDisplayActivity = activityRule.launchActivity(null)
|
||||
// sut.startSyncFolderOperation(storageManager.getFileByPath("/"), true)
|
||||
//
|
||||
// shortSleep()
|
||||
// InstrumentationRegistry.getInstrumentation().waitForIdleSync()
|
||||
// Screenshot.snapActivity(sut).record()
|
||||
// }
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("MagicNumber")
|
||||
fun testEnoughSpaceWithNoLocalFolder() {
|
||||
val sut = OCFileListFragment()
|
||||
val ocFile = OCFile("/test/")
|
||||
// @ScreenshotTest // todo run without real server
|
||||
fun createAndShowShareViaLink() {
|
||||
val path = "/shareViaLink/"
|
||||
TestCase.assertTrue(
|
||||
CreateFolderOperation(path, user, targetContext)
|
||||
.execute(client, storageManager)
|
||||
.isSuccess
|
||||
)
|
||||
|
||||
ocFile.mimeType = "DIR"
|
||||
// share folder via public link
|
||||
TestCase.assertTrue(
|
||||
CreateShareRemoteOperation(
|
||||
"/shareViaLink/",
|
||||
ShareType.PUBLIC_LINK,
|
||||
"",
|
||||
true,
|
||||
"",
|
||||
OCShare.READ_PERMISSION_FLAG
|
||||
)
|
||||
.execute(client)
|
||||
.isSuccess
|
||||
)
|
||||
|
||||
ocFile.fileLength = 100
|
||||
assertTrue(sut.checkIfEnoughSpace(200L, ocFile))
|
||||
val sut: FileDisplayActivity = activityRule.launchActivity(null)
|
||||
sut.startSyncFolderOperation(storageManager.getFileByPath("/"), true)
|
||||
|
||||
shortSleep()
|
||||
InstrumentationRegistry.getInstrumentation().waitForIdleSync()
|
||||
// Screenshot.snapActivity(sut).record()
|
||||
}
|
||||
}
|
||||
@@ -1,203 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2020 Tobias Kaminsky
|
||||
* Copyright (C) 2020 Nextcloud GmbH
|
||||
* Copyright (C) 2020 Chris Narkiewicz <[email protected]>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.ui.fragment
|
||||
|
||||
import android.Manifest
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule
|
||||
import androidx.test.rule.GrantPermissionRule
|
||||
import com.nextcloud.client.TestActivity
|
||||
import com.owncloud.android.AbstractIT
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import com.owncloud.android.lib.resources.shares.ShareType
|
||||
import com.owncloud.android.lib.resources.shares.ShareeUser
|
||||
import com.owncloud.android.utils.ScreenshotTest
|
||||
import org.junit.After
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
||||
class OCFileListFragmentStaticServerIT : AbstractIT() {
|
||||
@get:Rule
|
||||
val testActivityRule = IntentsTestRule(TestActivity::class.java, true, false)
|
||||
|
||||
@get:Rule
|
||||
val permissionRule = GrantPermissionRule.grant(Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
|
||||
@Test
|
||||
@ScreenshotTest
|
||||
@Suppress("MagicNumber")
|
||||
fun showFiles() {
|
||||
val sut = testActivityRule.launchActivity(null)
|
||||
|
||||
val textFile = OCFile("/1.md", "00000001")
|
||||
textFile.mimeType = "text/markdown"
|
||||
textFile.fileLength = 1024000
|
||||
textFile.modificationTimestamp = 1188206955000
|
||||
textFile.parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
|
||||
sut.storageManager.saveFile(textFile)
|
||||
|
||||
val imageFile = OCFile("/image.png", "00000002")
|
||||
imageFile.mimeType = "image/png"
|
||||
imageFile.isPreviewAvailable = false
|
||||
imageFile.fileLength = 3072000
|
||||
imageFile.modificationTimestamp = 746443755000
|
||||
imageFile.parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
|
||||
sut.storageManager.saveFile(imageFile)
|
||||
|
||||
sut.addFragment(OCFileListFragment())
|
||||
|
||||
val fragment = (sut.fragment as OCFileListFragment)
|
||||
val root = sut.storageManager.getFileByEncryptedRemotePath("/")
|
||||
|
||||
shortSleep()
|
||||
|
||||
sut.runOnUiThread { fragment.listDirectory(root, false, false) }
|
||||
|
||||
waitForIdleSync()
|
||||
|
||||
screenshot(sut)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ScreenshotTest
|
||||
fun showSharedFiles() {
|
||||
val sut = testActivityRule.launchActivity(null)
|
||||
val fragment = OCFileListFragment()
|
||||
|
||||
val groupShare = OCFile("/sharedToGroup.jpg").apply {
|
||||
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
|
||||
isSharedWithSharee = true
|
||||
sharees = listOf(ShareeUser("group", "Group", ShareType.GROUP))
|
||||
}
|
||||
sut.storageManager.saveFile(groupShare)
|
||||
|
||||
val roomShare = OCFile("/sharedToRoom.jpg").apply {
|
||||
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
|
||||
isSharedWithSharee = true
|
||||
sharees = listOf(ShareeUser("Conversation", "Meeting", ShareType.ROOM))
|
||||
}
|
||||
sut.storageManager.saveFile(roomShare)
|
||||
|
||||
val circleShare = OCFile("/sharedToCircle.jpg").apply {
|
||||
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
|
||||
isSharedWithSharee = true
|
||||
sharees = listOf(ShareeUser("circle", "Circle (Public circle)", ShareType.CIRCLE))
|
||||
}
|
||||
sut.storageManager.saveFile(circleShare)
|
||||
|
||||
val userShare = OCFile("/sharedToUser.jpg").apply {
|
||||
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
|
||||
isSharedWithSharee = true
|
||||
sharees = listOf(ShareeUser("Admin", "Server Admin", ShareType.USER))
|
||||
}
|
||||
sut.storageManager.saveFile(userShare)
|
||||
|
||||
val federatedUserShare = OCFile("/sharedToFederatedUser.jpg").apply {
|
||||
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
|
||||
isSharedWithSharee = true
|
||||
sharees = listOf(
|
||||
ShareeUser("[email protected]", "[email protected] (remote)", ShareType.FEDERATED)
|
||||
)
|
||||
}
|
||||
sut.storageManager.saveFile(federatedUserShare)
|
||||
|
||||
val emailShare = OCFile("/sharedToEmail.jpg").apply {
|
||||
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
|
||||
isSharedWithSharee = true
|
||||
sharees = listOf(ShareeUser("[email protected]", "[email protected]", ShareType.EMAIL))
|
||||
}
|
||||
sut.storageManager.saveFile(emailShare)
|
||||
|
||||
val publicLink = OCFile("/publicLink.jpg").apply {
|
||||
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
|
||||
isSharedViaLink = true
|
||||
}
|
||||
sut.storageManager.saveFile(publicLink)
|
||||
|
||||
val noShare = OCFile("/notShared.jpg").apply {
|
||||
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
|
||||
}
|
||||
sut.storageManager.saveFile(noShare)
|
||||
|
||||
val usersShare = OCFile("/sharedToUser.jpg").apply {
|
||||
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
|
||||
isSharedWithSharee = true
|
||||
sharees = listOf(
|
||||
ShareeUser("Admin", "Server Admin", ShareType.USER),
|
||||
ShareeUser("User", "User", ShareType.USER),
|
||||
ShareeUser("Christine", "Christine Scott", ShareType.USER)
|
||||
)
|
||||
}
|
||||
sut.storageManager.saveFile(usersShare)
|
||||
|
||||
sut.addFragment(fragment)
|
||||
|
||||
shortSleep()
|
||||
|
||||
val root = sut.storageManager.getFileByEncryptedRemotePath("/")
|
||||
|
||||
sut.runOnUiThread {
|
||||
fragment.listDirectory(root, false, false)
|
||||
fragment.adapter.setShowShareAvatar(true)
|
||||
}
|
||||
|
||||
waitForIdleSync()
|
||||
shortSleep()
|
||||
shortSleep()
|
||||
shortSleep()
|
||||
|
||||
screenshot(sut)
|
||||
}
|
||||
|
||||
@After
|
||||
fun after() {
|
||||
fileDataStorageManager.deleteAllFiles()
|
||||
}
|
||||
|
||||
@Test
|
||||
@ScreenshotTest
|
||||
@Suppress("MagicNumber")
|
||||
fun showRichWorkspace() {
|
||||
val sut = testActivityRule.launchActivity(null)
|
||||
val fragment = OCFileListFragment()
|
||||
|
||||
val folder = OCFile("/test/")
|
||||
folder.setFolder()
|
||||
sut.storageManager.saveFile(folder)
|
||||
|
||||
val textFile = OCFile("/test/Readme.md", "00000001")
|
||||
textFile.mimeType = "text/markdown"
|
||||
textFile.fileLength = 1024000
|
||||
textFile.modificationTimestamp = 1188206955000
|
||||
textFile.parentId = sut.storageManager.getFileByEncryptedRemotePath("/test/").fileId
|
||||
textFile.storagePath = getFile("java.md").absolutePath
|
||||
sut.storageManager.saveFile(textFile)
|
||||
|
||||
sut.addFragment(fragment)
|
||||
val testFolder: OCFile = sut.storageManager.getFileByEncryptedRemotePath("/test/")
|
||||
testFolder.richWorkspace = getFile("java.md").readText()
|
||||
|
||||
sut.runOnUiThread { fragment.listDirectory(testFolder, false, false) }
|
||||
|
||||
screenshot(sut)
|
||||
}
|
||||
}
|
||||
@@ -63,10 +63,9 @@ class TrashbinActivityIT : AbstractIT() {
|
||||
|
||||
sut.runOnUiThread { sut.loadFolder() }
|
||||
|
||||
waitForIdleSync()
|
||||
shortSleep()
|
||||
|
||||
screenshot(sut)
|
||||
Screenshot.snapActivity(sut).record()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
package com.owncloud.android.util;
|
||||
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
@@ -49,9 +50,9 @@ import java.security.SecureRandom;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import static androidx.test.InstrumentationRegistry.getInstrumentation;
|
||||
@@ -70,7 +71,6 @@ import static com.owncloud.android.utils.EncryptionUtils.generateKey;
|
||||
import static com.owncloud.android.utils.EncryptionUtils.generateSHA512;
|
||||
import static com.owncloud.android.utils.EncryptionUtils.getMD5Sum;
|
||||
import static com.owncloud.android.utils.EncryptionUtils.ivDelimiter;
|
||||
import static com.owncloud.android.utils.EncryptionUtils.ivDelimiterOld;
|
||||
import static com.owncloud.android.utils.EncryptionUtils.ivLength;
|
||||
import static com.owncloud.android.utils.EncryptionUtils.randomBytes;
|
||||
import static com.owncloud.android.utils.EncryptionUtils.saltLength;
|
||||
@@ -80,6 +80,7 @@ import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class EncryptionTestIT {
|
||||
private String privateKey = "MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAo" +
|
||||
@@ -151,17 +152,7 @@ public class EncryptionTestIT {
|
||||
Log_OC.d("EncryptionTestIT", i + " of " + max);
|
||||
byte[] key = generateKey();
|
||||
|
||||
String encryptedString;
|
||||
if (new Random().nextBoolean()) {
|
||||
encryptedString = EncryptionUtils.encryptStringSymmetric(privateKey, key);
|
||||
} else {
|
||||
encryptedString = EncryptionUtils.encryptStringSymmetricOld(privateKey, key);
|
||||
|
||||
if (encryptedString.indexOf(ivDelimiterOld) != encryptedString.lastIndexOf(ivDelimiterOld)) {
|
||||
Log_OC.d("EncryptionTestIT", "skip due to duplicated iv (old system) -> ignoring");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
String encryptedString = EncryptionUtils.encryptStringSymmetric(privateKey, key);
|
||||
String decryptedString = decryptStringSymmetric(encryptedString, key);
|
||||
|
||||
assertEquals(privateKey, decryptedString);
|
||||
@@ -201,29 +192,19 @@ public class EncryptionTestIT {
|
||||
|
||||
@Test
|
||||
public void encryptPrivateKey() throws Exception {
|
||||
int max = 10;
|
||||
for (int i = 0; i < max; i++) {
|
||||
Log_OC.d("EncryptionTestIT", i + " of " + max);
|
||||
|
||||
String keyPhrase = "moreovertelevisionfactorytendencyindependenceinternationalintellectualimpress" +
|
||||
String keyPhrase = "moreovertelevisionfactorytendencyindependenceinternationalintellectualimpress" +
|
||||
"interestvolunteer";
|
||||
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
|
||||
keyGen.initialize(4096, new SecureRandom());
|
||||
KeyPair keyPair = keyGen.generateKeyPair();
|
||||
PrivateKey privateKey = keyPair.getPrivate();
|
||||
byte[] privateKeyBytes = privateKey.getEncoded();
|
||||
String privateKeyString = encodeBytesToBase64String(privateKeyBytes);
|
||||
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
|
||||
keyGen.initialize(4096, new SecureRandom());
|
||||
KeyPair keyPair = keyGen.generateKeyPair();
|
||||
PrivateKey privateKey = keyPair.getPrivate();
|
||||
byte[] privateKeyBytes = privateKey.getEncoded();
|
||||
String privateKeyString = encodeBytesToBase64String(privateKeyBytes);
|
||||
|
||||
String encryptedString;
|
||||
if (new Random().nextBoolean()) {
|
||||
encryptedString = EncryptionUtils.encryptPrivateKey(privateKeyString, keyPhrase);
|
||||
} else {
|
||||
encryptedString = EncryptionUtils.encryptPrivateKeyOld(privateKeyString, keyPhrase);
|
||||
}
|
||||
String decryptedString = decryptPrivateKey(encryptedString, keyPhrase);
|
||||
String encryptedString = EncryptionUtils.encryptPrivateKey(privateKeyString, keyPhrase);
|
||||
String decryptedString = decryptPrivateKey(encryptedString, keyPhrase);
|
||||
|
||||
assertEquals(privateKeyString, decryptedString);
|
||||
}
|
||||
assertEquals(privateKeyString, decryptedString);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2020 Tobias Kaminsky
|
||||
* Copyright (C) 2020 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.utils
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotEquals
|
||||
import org.junit.Test
|
||||
|
||||
class BitmapUtilsIT {
|
||||
@Test
|
||||
@Suppress("MagicNumber")
|
||||
fun usernameToColor() {
|
||||
assertEquals(BitmapUtils.Color(0, 0, 0), BitmapUtils.Color(0, 0, 0))
|
||||
assertEquals(BitmapUtils.Color(221, 203, 85), BitmapUtils.usernameToColor("User"))
|
||||
assertEquals(BitmapUtils.Color(208, 158, 109), BitmapUtils.usernameToColor("Admin"))
|
||||
assertEquals(BitmapUtils.Color(0, 130, 201), BitmapUtils.usernameToColor(""))
|
||||
assertEquals(BitmapUtils.Color(201, 136, 121), BitmapUtils.usernameToColor("68b329da9893e34099c7d8ad5cb9c940"))
|
||||
|
||||
// tests from server
|
||||
assertEquals(BitmapUtils.Color(208, 158, 109), BitmapUtils.usernameToColor("Alishia Ann Lowry"))
|
||||
assertEquals(BitmapUtils.Color(0, 130, 201), BitmapUtils.usernameToColor("Arham Johnson"))
|
||||
assertEquals(BitmapUtils.Color(208, 158, 109), BitmapUtils.usernameToColor("Brayden Truong"))
|
||||
assertEquals(BitmapUtils.Color(151, 80, 164), BitmapUtils.usernameToColor("Daphne Roy"))
|
||||
assertEquals(BitmapUtils.Color(195, 114, 133), BitmapUtils.usernameToColor("Ellena Wright Frederic Conway"))
|
||||
assertEquals(BitmapUtils.Color(214, 180, 97), BitmapUtils.usernameToColor("Gianluca Hills"))
|
||||
assertEquals(BitmapUtils.Color(214, 180, 97), BitmapUtils.usernameToColor("Haseeb Stephens"))
|
||||
assertEquals(BitmapUtils.Color(151, 80, 164), BitmapUtils.usernameToColor("Idris Mac"))
|
||||
assertEquals(BitmapUtils.Color(0, 130, 201), BitmapUtils.usernameToColor("Kristi Fisher"))
|
||||
assertEquals(BitmapUtils.Color(188, 92, 145), BitmapUtils.usernameToColor("Lillian Wall"))
|
||||
assertEquals(BitmapUtils.Color(221, 203, 85), BitmapUtils.usernameToColor("Lorelai Taylor"))
|
||||
assertEquals(BitmapUtils.Color(151, 80, 164), BitmapUtils.usernameToColor("Madina Knight"))
|
||||
assertEquals(BitmapUtils.Color(121, 90, 171), BitmapUtils.usernameToColor("Rae Hope"))
|
||||
assertEquals(BitmapUtils.Color(188, 92, 145), BitmapUtils.usernameToColor("Santiago Singleton"))
|
||||
assertEquals(BitmapUtils.Color(208, 158, 109), BitmapUtils.usernameToColor("Sid Combs"))
|
||||
assertEquals(BitmapUtils.Color(30, 120, 193), BitmapUtils.usernameToColor("Vivienne Jacobs"))
|
||||
assertEquals(BitmapUtils.Color(110, 166, 143), BitmapUtils.usernameToColor("Zaki Cortes"))
|
||||
assertEquals(BitmapUtils.Color(91, 100, 179), BitmapUtils.usernameToColor("a user"))
|
||||
assertEquals(BitmapUtils.Color(208, 158, 109), BitmapUtils.usernameToColor("admin"))
|
||||
assertEquals(BitmapUtils.Color(151, 80, 164), BitmapUtils.usernameToColor("[email protected]"))
|
||||
assertEquals(BitmapUtils.Color(221, 203, 85), BitmapUtils.usernameToColor("another user"))
|
||||
assertEquals(BitmapUtils.Color(36, 142, 181), BitmapUtils.usernameToColor("asd"))
|
||||
assertEquals(BitmapUtils.Color(0, 130, 201), BitmapUtils.usernameToColor("bar"))
|
||||
assertEquals(BitmapUtils.Color(208, 158, 109), BitmapUtils.usernameToColor("foo"))
|
||||
assertEquals(BitmapUtils.Color(182, 70, 157), BitmapUtils.usernameToColor("wasd"))
|
||||
}
|
||||
|
||||
@Test
|
||||
@Suppress("MagicNumber")
|
||||
fun checkEqual() {
|
||||
assertEquals(BitmapUtils.Color(208, 158, 109), BitmapUtils.Color(208, 158, 109))
|
||||
assertNotEquals(BitmapUtils.Color(208, 158, 109), BitmapUtils.Color(208, 158, 100))
|
||||
}
|
||||
|
||||
@Test
|
||||
@Suppress("MagicNumber")
|
||||
fun checkHashCode() {
|
||||
assertEquals(BitmapUtils.Color(208, 158, 109).hashCode(), BitmapUtils.Color(208, 158, 109).hashCode())
|
||||
assertNotEquals(BitmapUtils.Color(208, 158, 109).hashCode(), BitmapUtils.Color(208, 158, 100).hashCode())
|
||||
}
|
||||
}
|
||||
@@ -14,8 +14,5 @@
|
||||
|
||||
<application
|
||||
android:testOnly="false"
|
||||
tools:ignore="GoogleAppIndexingWarning">
|
||||
|
||||
<activity android:name="com.nextcloud.client.TestActivity" />
|
||||
</application>
|
||||
tools:ignore="GoogleAppIndexingWarning"/>
|
||||
</manifest>
|
||||
@@ -1,134 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2020 Tobias Kaminsky
|
||||
* Copyright (C) 2020 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.nextcloud.client
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
import com.nextcloud.client.network.Connectivity
|
||||
import com.nextcloud.client.network.ConnectivityService
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import com.owncloud.android.files.services.FileDownloader
|
||||
import com.owncloud.android.files.services.FileUploader
|
||||
import com.owncloud.android.lib.resources.status.OCCapability
|
||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion
|
||||
import com.owncloud.android.services.OperationsService
|
||||
import com.owncloud.android.ui.activity.FileActivity
|
||||
import com.owncloud.android.ui.activity.OnEnforceableRefreshListener
|
||||
import com.owncloud.android.ui.fragment.FileFragment
|
||||
import com.owncloud.android.ui.helpers.FileOperationsHelper
|
||||
|
||||
class TestActivity :
|
||||
FileActivity(),
|
||||
FileFragment.ContainerActivity,
|
||||
SwipeRefreshLayout.OnRefreshListener,
|
||||
OnEnforceableRefreshListener {
|
||||
lateinit var fragment: Fragment
|
||||
private lateinit var storage: FileDataStorageManager
|
||||
private lateinit var fileOperation: FileOperationsHelper
|
||||
|
||||
private val connectivityServiceMock: ConnectivityService = object : ConnectivityService {
|
||||
override fun isInternetWalled(): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun getConnectivity(): Connectivity {
|
||||
return Connectivity.CONNECTED_WIFI
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
setContentView(R.layout.test_layout)
|
||||
}
|
||||
|
||||
fun addFragment(fragment: Fragment) {
|
||||
this.fragment = fragment
|
||||
val transaction = supportFragmentManager.beginTransaction()
|
||||
transaction.replace(R.id.root, fragment)
|
||||
transaction.commit()
|
||||
}
|
||||
|
||||
override fun onBrowsedDownTo(folder: OCFile?) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun getOperationsServiceBinder(): OperationsService.OperationsServiceBinder? {
|
||||
return null
|
||||
}
|
||||
|
||||
override fun showSortListGroup(show: Boolean) {
|
||||
// not needed
|
||||
}
|
||||
|
||||
override fun showDetails(file: OCFile?) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun showDetails(file: OCFile?, activeTab: Int) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun getFileUploaderBinder(): FileUploader.FileUploaderBinder? {
|
||||
return null
|
||||
}
|
||||
|
||||
override fun getFileDownloaderBinder(): FileDownloader.FileDownloaderBinder? {
|
||||
return null
|
||||
}
|
||||
|
||||
override fun getStorageManager(): FileDataStorageManager {
|
||||
if (!this::storage.isInitialized) {
|
||||
storage = FileDataStorageManager(account, contentResolver)
|
||||
|
||||
val ocCapability = OCCapability()
|
||||
ocCapability.versionMayor = OwnCloudVersion.nextcloud_20.majorVersionNumber
|
||||
storage.saveCapabilities(ocCapability)
|
||||
}
|
||||
|
||||
return storage
|
||||
}
|
||||
|
||||
override fun getFileOperationsHelper(): FileOperationsHelper {
|
||||
if (!this::fileOperation.isInitialized) {
|
||||
fileOperation = FileOperationsHelper(this, userAccountManager, connectivityServiceMock)
|
||||
}
|
||||
|
||||
return fileOperation
|
||||
}
|
||||
|
||||
override fun onTransferStateChanged(file: OCFile?, downloading: Boolean, uploading: Boolean) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun onRefresh(enforced: Boolean) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun onRefresh() {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2020 Tobias Kaminsky
|
||||
* Copyright (C) 2020 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.nextcloud.client.di;
|
||||
|
||||
import com.nextcloud.client.TestActivity;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.android.ContributesAndroidInjector;
|
||||
|
||||
/**
|
||||
* Register classes that require dependency injection. This class is used by Dagger compiler only.
|
||||
*/
|
||||
@Module
|
||||
abstract class BuildTypeComponentsModule {
|
||||
@ContributesAndroidInjector
|
||||
abstract TestActivity testActivity();
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
Nextcloud Android client application
|
||||
|
||||
@author Tobias Kaminsky
|
||||
Copyright (C) 2020 Tobias Kaminsky
|
||||
Copyright (C) 2020 Nextcloud GmbH
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/avatar_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
</LinearLayout>
|
||||
@@ -1,19 +0,0 @@
|
||||
منصة الإنتاجية ذاتية الاستضافة التي تبقيك تحت السيطرة.
|
||||
|
||||
المميزات:
|
||||
* واجهة سهلة وحديثة ومناسبة لموضوع الخادم الخاص بك
|
||||
* رفع الملفات إلى خادم Nextcloud الخاص بك
|
||||
* شاركها مع الآخرين
|
||||
* حافظ على مزامنة ملفاتك ومجلداتك المفضلة
|
||||
* البحث في جميع المجلدات في خادمك
|
||||
* الرفع التلقائي للصور ومقاطع الفيديو التي يلتقطها جهازك
|
||||
* مواكبة مع الإشعارات
|
||||
* دعم لحسابات متعددة
|
||||
* وصول آمن إلى بياناتك باستخدام بصمة الإصبع أو رمز PIN
|
||||
* التكامل مع DAVx5 (المعروف سابقًا باسم DAVdroid) لسهولة إعداد التقويم ومزامنة جهات الاتصال
|
||||
|
||||
الرجاء الإبلاغ عن جميع المشاكل على https://github.com/nextcloud/android/issues وناقش هذا التطبيق على https://help.nextcloud.com/c/clients/android
|
||||
|
||||
جديد في Nextcloud؟ Nextcloud هو خادم خاص لمزامنة الملفات ومشاركتها واتصالاتها. إنه برنامج حر ، ويمكنك استضافته بنفسك أو الدفع لشركة للقيام بذلك نيابة عنك. بهذه الطريقة ، يمكنك التحكم في صورك والتقويم وبيانات الاتصال والمستندات وكل شيء آخر.
|
||||
|
||||
تحقق من Nextcloud في https://nextcloud.com
|
||||
@@ -30,13 +30,10 @@
|
||||
|
||||
<meta-data
|
||||
android:name="firebase_analytics_collection_deactivated"
|
||||
android:value="true" />
|
||||
android:value="true"/>
|
||||
<meta-data
|
||||
android:name="google_analytics_adid_collection_enabled"
|
||||
android:value="false" />
|
||||
<meta-data
|
||||
android:name="google_analytics_ssaid_collection_enabled"
|
||||
android:value="false" />
|
||||
android:value="false"/>
|
||||
|
||||
<activity
|
||||
android:name=".authentication.ModifiedAuthenticatorActivity"
|
||||
|
||||
@@ -60,6 +60,7 @@
|
||||
<uses-permission android:name="android.permission.READ_SYNC_STATS" />
|
||||
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
|
||||
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
|
||||
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
@@ -71,6 +72,8 @@
|
||||
must request the FOREGROUND_SERVICE permission -->
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
|
||||
|
||||
<uses-sdk tools:overrideLibrary="com.blikoon.qrcodescanner, io.noties.markwon.ext.latex, io.noties.markwon.ext.strikethrough, io.noties.markwon.ext.tables, io.noties.markwon.ext.tasklist, io.noties.markwon.html, io.noties.markwon.linkify, io.noties.markwon.syntax, io.noties.markwon, ru.noties.jlatexmath.android" />
|
||||
|
||||
<!-- Some Chromebooks don't support touch. Although not essential,
|
||||
it's a good idea to explicitly include this declaration. -->
|
||||
<uses-feature
|
||||
@@ -255,7 +258,7 @@
|
||||
android:exported="true"
|
||||
android:grantUriPermissions="true"
|
||||
android:permission="android.permission.MANAGE_DOCUMENTS"
|
||||
android:enabled="true">
|
||||
android:enabled="@bool/atLeastKitKat">
|
||||
<intent-filter>
|
||||
<action android:name="android.content.action.DOCUMENTS_PROVIDER" />
|
||||
</intent-filter>
|
||||
|
||||
@@ -20,15 +20,12 @@
|
||||
package com.nextcloud.client.account;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.nextcloud.java.util.Optional;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.lib.common.OwnCloudAccount;
|
||||
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
||||
|
||||
import java.util.List;
|
||||
@@ -157,14 +154,13 @@ public interface UserAccountManager extends CurrentAccountProvider {
|
||||
|
||||
/**
|
||||
* Extract username from account.
|
||||
* <p>
|
||||
*
|
||||
* Full account name is in form of "[email protected]".
|
||||
*
|
||||
* @param account Account instance
|
||||
* @return User name (without domain) or null, if name cannot be extracted.
|
||||
*/
|
||||
static @Nullable
|
||||
String getUsername(Account account) {
|
||||
static String getUsername(Account account) {
|
||||
if (account != null && account.name != null) {
|
||||
return account.name.substring(0, account.name.lastIndexOf('@'));
|
||||
} else {
|
||||
@@ -172,15 +168,9 @@ public interface UserAccountManager extends CurrentAccountProvider {
|
||||
}
|
||||
}
|
||||
|
||||
static @Nullable
|
||||
String getDisplayName(Account account) {
|
||||
return AccountManager.get(MainApp.getAppContext()).getUserData(account,
|
||||
AccountUtils.Constants.KEY_DISPLAY_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch account registration activity.
|
||||
* <p>
|
||||
*
|
||||
* This method returns immediately. Authenticator activity will be launched asynchronously.
|
||||
*
|
||||
* @param activity Activity used to launch authenticator flow via {@link Activity#startActivity(Intent)}
|
||||
|
||||
@@ -68,11 +68,10 @@ import java.io.File;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
@Module(includes = {ComponentsModule.class, VariantComponentsModule.class, BuildTypeComponentsModule.class})
|
||||
@Module(includes = {ComponentsModule.class, VariantComponentsModule.class})
|
||||
class AppModule {
|
||||
|
||||
@Provides
|
||||
@@ -218,9 +217,4 @@ class AppModule {
|
||||
AppNotificationManager notificationsManager(Context context, NotificationManager platformNotificationsManager) {
|
||||
return new AppNotificationManagerImpl(context, context.getResources(), platformNotificationsManager);
|
||||
}
|
||||
|
||||
@Provides
|
||||
LocalBroadcastManager localBroadcastManager(Context context) {
|
||||
return LocalBroadcastManager.getInstance(context);
|
||||
}
|
||||
}
|
||||
@@ -21,8 +21,8 @@
|
||||
package com.nextcloud.client.di;
|
||||
|
||||
import com.nextcloud.client.etm.EtmActivity;
|
||||
import com.nextcloud.client.files.downloader.DownloaderService;
|
||||
import com.nextcloud.client.jobs.NotificationWork;
|
||||
import com.nextcloud.client.files.downloader.DownloaderService;
|
||||
import com.nextcloud.client.logger.ui.LogsActivity;
|
||||
import com.nextcloud.client.media.PlayerService;
|
||||
import com.nextcloud.client.onboarding.FirstRunActivity;
|
||||
@@ -169,7 +169,5 @@ abstract class ComponentsModule {
|
||||
@ContributesAndroidInjector abstract AccountManagerService accountManagerService();
|
||||
@ContributesAndroidInjector abstract OperationsService operationsService();
|
||||
@ContributesAndroidInjector abstract PlayerService playerService();
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract DownloaderService fileDownloaderService();
|
||||
@ContributesAndroidInjector abstract DownloaderService fileDownloaderService();
|
||||
}
|
||||
@@ -49,8 +49,7 @@ class ShowErrorActivity : AppCompatActivity() {
|
||||
|
||||
val snackbar = DisplayUtils.createSnackbar(
|
||||
error_page_container,
|
||||
R.string.error_report_issue_text,
|
||||
Snackbar.LENGTH_INDEFINITE
|
||||
R.string.error_report_issue_text, Snackbar.LENGTH_INDEFINITE
|
||||
)
|
||||
.setAction(R.string.error_report_issue_action) { reportIssue() }
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@ package com.nextcloud.client.jobs
|
||||
|
||||
import android.accounts.Account
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.provider.DocumentsContract
|
||||
import android.text.TextUtils
|
||||
import androidx.work.Worker
|
||||
import androidx.work.WorkerParameters
|
||||
@@ -46,7 +48,6 @@ import com.owncloud.android.lib.common.OwnCloudClient
|
||||
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory
|
||||
import com.owncloud.android.lib.common.utils.Log_OC
|
||||
import com.owncloud.android.lib.resources.users.RemoteWipeSuccessRemoteOperation
|
||||
import com.owncloud.android.providers.DocumentsStorageProvider
|
||||
import com.owncloud.android.ui.activity.ContactsPreferenceActivity
|
||||
import com.owncloud.android.ui.activity.ManageAccountsActivity
|
||||
import com.owncloud.android.ui.events.AccountRemovedEvent
|
||||
@@ -126,7 +127,11 @@ class AccountRemovalWork(
|
||||
}
|
||||
}
|
||||
// notify Document Provider
|
||||
DocumentsStorageProvider.notifyRootsChanged(context)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
val authority = context.resources.getString(R.string.document_provider_authority)
|
||||
val rootsUri = DocumentsContract.buildRootsUri(authority)
|
||||
context.contentResolver.notifyChange(rootsUri, null)
|
||||
}
|
||||
return Result.success()
|
||||
}
|
||||
|
||||
@@ -145,8 +150,7 @@ class AccountRemovalWork(
|
||||
)
|
||||
pushArbitraryData.isShouldBeDeleted = true
|
||||
arbitraryDataProvider.storeOrUpdateKeyValue(
|
||||
user.accountName,
|
||||
PushUtils.KEY_PUSH,
|
||||
user.accountName, PushUtils.KEY_PUSH,
|
||||
gson.toJson(pushArbitraryData)
|
||||
)
|
||||
PushUtils.pushRegistrationToServer(userAccountManager, pushArbitraryData.getPushToken())
|
||||
|
||||
@@ -142,7 +142,8 @@ class BackgroundJobFactory @Inject constructor(
|
||||
uploadsStorageManager = uploadsStorageManager,
|
||||
connectivityService = connectivityService,
|
||||
powerManagementService = powerManagementService,
|
||||
clock = clock
|
||||
clock = clock,
|
||||
backgroundJobManager = backgroundJobManager.get()
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -124,11 +124,8 @@ class ContactsBackupWork(
|
||||
private fun backupContact(user: User, backupFolder: String) {
|
||||
val vCard = ArrayList<String>()
|
||||
val cursor = contentResolver.query(
|
||||
ContactsContract.Contacts.CONTENT_URI,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
ContactsContract.Contacts.CONTENT_URI, null,
|
||||
null, null, null
|
||||
)
|
||||
if (cursor != null && cursor.count > 0) {
|
||||
cursor.moveToFirst()
|
||||
|
||||
@@ -70,7 +70,8 @@ class FilesSyncWork(
|
||||
private val uploadsStorageManager: UploadsStorageManager,
|
||||
private val connectivityService: ConnectivityService,
|
||||
private val powerManagementService: PowerManagementService,
|
||||
private val clock: Clock
|
||||
private val clock: Clock,
|
||||
private val backgroundJobManager: BackgroundJobManager
|
||||
) : Worker(context, params) {
|
||||
|
||||
companion object {
|
||||
@@ -117,12 +118,7 @@ class FilesSyncWork(
|
||||
for (syncedFolder in syncedFolderProvider.syncedFolders) {
|
||||
if (syncedFolder.isEnabled && (!skipCustom || MediaFolderType.CUSTOM != syncedFolder.type)) {
|
||||
syncFolder(
|
||||
context,
|
||||
resources,
|
||||
lightVersion,
|
||||
filesystemDataProvider,
|
||||
currentLocale,
|
||||
dateFormat,
|
||||
context, resources, lightVersion, filesystemDataProvider, currentLocale, dateFormat,
|
||||
syncedFolder
|
||||
)
|
||||
}
|
||||
@@ -201,7 +197,7 @@ class FilesSyncWork(
|
||||
UploadFileOperation.CREATED_AS_INSTANT_PICTURE,
|
||||
needsWifi,
|
||||
needsCharging,
|
||||
syncedFolder.nameCollisionPolicy
|
||||
FileUploader.NameCollisionPolicy.ASK_USER
|
||||
)
|
||||
filesystemDataProvider.updateFilesystemFileAsSentForUpload(
|
||||
path,
|
||||
|
||||
@@ -49,7 +49,7 @@ import com.owncloud.android.datamodel.MediaFoldersModel
|
||||
import com.owncloud.android.datamodel.MediaProvider
|
||||
import com.owncloud.android.datamodel.SyncedFolderProvider
|
||||
import com.owncloud.android.lib.common.utils.Log_OC
|
||||
import com.owncloud.android.ui.activity.ManageAccountsActivity.PENDING_FOR_REMOVAL
|
||||
import com.owncloud.android.ui.activity.ManageAccountsActivity
|
||||
import com.owncloud.android.ui.activity.SyncedFoldersActivity
|
||||
import com.owncloud.android.ui.notifications.NotificationUtils
|
||||
import com.owncloud.android.utils.ThemeUtils
|
||||
@@ -123,7 +123,10 @@ class MediaFoldersDetectionWork constructor(
|
||||
val allUsers = userAccountManager.allUsers
|
||||
val activeUsers: MutableList<User> = ArrayList()
|
||||
for (account in allUsers) {
|
||||
if (!arbitraryDataProvider.getBooleanValue(account.toPlatformAccount(), PENDING_FOR_REMOVAL)
|
||||
if (!arbitraryDataProvider.getBooleanValue(
|
||||
account.toPlatformAccount(),
|
||||
ManageAccountsActivity.PENDING_FOR_REMOVAL
|
||||
)
|
||||
) {
|
||||
activeUsers.add(account)
|
||||
}
|
||||
@@ -173,8 +176,7 @@ class MediaFoldersDetectionWork constructor(
|
||||
} else {
|
||||
mediaFoldersModel = MediaFoldersModel(imageMediaFolderPaths, videoMediaFolderPaths)
|
||||
arbitraryDataProvider.storeOrUpdateKeyValue(
|
||||
ACCOUNT_NAME_GLOBAL,
|
||||
KEY_MEDIA_FOLDERS,
|
||||
ACCOUNT_NAME_GLOBAL, KEY_MEDIA_FOLDERS,
|
||||
gson.toJson(mediaFoldersModel)
|
||||
)
|
||||
}
|
||||
@@ -193,8 +195,7 @@ class MediaFoldersDetectionWork constructor(
|
||||
intent.putExtra(SyncedFoldersActivity.EXTRA_SHOW_SIDEBAR, true)
|
||||
val pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT)
|
||||
val notificationBuilder = NotificationCompat.Builder(
|
||||
context,
|
||||
NotificationUtils.NOTIFICATION_CHANNEL_GENERAL
|
||||
context, NotificationUtils.NOTIFICATION_CHANNEL_GENERAL
|
||||
)
|
||||
.setSmallIcon(R.drawable.notification_icon)
|
||||
.setLargeIcon(BitmapFactory.decodeResource(context.resources, R.drawable.notification_icon))
|
||||
|
||||
@@ -179,16 +179,13 @@ class NotificationWork constructor(
|
||||
disableDetection.putExtra(PUSH_NOTIFICATION_ID, pushNotificationId)
|
||||
disableDetection.putExtra(KEY_NOTIFICATION_ACCOUNT, user.accountName)
|
||||
val disableIntent = PendingIntent.getBroadcast(
|
||||
context,
|
||||
pushNotificationId,
|
||||
disableDetection,
|
||||
context, pushNotificationId, disableDetection,
|
||||
PendingIntent.FLAG_CANCEL_CURRENT
|
||||
)
|
||||
notificationBuilder.addAction(
|
||||
NotificationCompat.Action(
|
||||
R.drawable.ic_close,
|
||||
context.getString(R.string.remove_push_notification),
|
||||
disableIntent
|
||||
context.getString(R.string.remove_push_notification), disableIntent
|
||||
)
|
||||
)
|
||||
} else { // Actions
|
||||
@@ -200,8 +197,7 @@ class NotificationWork constructor(
|
||||
actionIntent.putExtra(KEY_NOTIFICATION_ACTION_LINK, action.link)
|
||||
actionIntent.putExtra(KEY_NOTIFICATION_ACTION_TYPE, action.type)
|
||||
val actionPendingIntent = PendingIntent.getBroadcast(
|
||||
context,
|
||||
randomId.nextInt(),
|
||||
context, randomId.nextInt(),
|
||||
actionIntent,
|
||||
PendingIntent.FLAG_CANCEL_CURRENT
|
||||
)
|
||||
|
||||
@@ -23,7 +23,6 @@ import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.ServiceConnection
|
||||
import android.os.Build
|
||||
import android.os.IBinder
|
||||
import android.widget.MediaController
|
||||
import com.nextcloud.client.account.User
|
||||
@@ -57,20 +56,20 @@ class PlayerServiceConnection(private val context: Context) : MediaController.Me
|
||||
i.putExtra(PlayerService.EXTRA_AUTO_PLAY, playImmediately)
|
||||
i.putExtra(PlayerService.EXTRA_START_POSITION_MS, position)
|
||||
i.action = PlayerService.ACTION_PLAY
|
||||
startForegroundService(i)
|
||||
context.startService(i)
|
||||
}
|
||||
|
||||
fun stop(file: OCFile) {
|
||||
val i = Intent(context, PlayerService::class.java)
|
||||
i.putExtra(PlayerService.EXTRA_FILE, file)
|
||||
i.action = PlayerService.ACTION_STOP_FILE
|
||||
startForegroundService(i)
|
||||
context.startService(i)
|
||||
}
|
||||
|
||||
fun stop() {
|
||||
val i = Intent(context, PlayerService::class.java)
|
||||
i.action = PlayerService.ACTION_STOP
|
||||
startForegroundService(i)
|
||||
context.startService(i)
|
||||
}
|
||||
|
||||
private val connection = object : ServiceConnection {
|
||||
@@ -132,12 +131,4 @@ class PlayerServiceConnection(private val context: Context) : MediaController.Me
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
private fun startForegroundService(i: Intent) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
context.startForegroundService(i)
|
||||
} else {
|
||||
context.startService(i)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -61,6 +61,7 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AndroidRuntimeException;
|
||||
import android.view.KeyEvent;
|
||||
@@ -113,7 +114,6 @@ import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
||||
import com.owncloud.android.lib.resources.users.GetUserInfoRemoteOperation;
|
||||
import com.owncloud.android.operations.DetectAuthenticationMethodOperation.AuthenticationMethod;
|
||||
import com.owncloud.android.operations.GetServerInfoOperation;
|
||||
import com.owncloud.android.providers.DocumentsStorageProvider;
|
||||
import com.owncloud.android.services.OperationsService;
|
||||
import com.owncloud.android.services.OperationsService.OperationsServiceBinder;
|
||||
import com.owncloud.android.ui.activity.FileDisplayActivity;
|
||||
@@ -262,7 +262,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
||||
onboarding.launchFirstRunIfNeeded(this);
|
||||
}
|
||||
|
||||
onlyAdd = getIntent().getBooleanExtra(KEY_ONLY_ADD, false) || checkIfViaSSO(getIntent());
|
||||
onlyAdd = getIntent().getBooleanExtra(KEY_ONLY_ADD, false);
|
||||
|
||||
// delete cookies for webView
|
||||
deleteCookies();
|
||||
@@ -676,7 +676,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
||||
super.finish();
|
||||
}
|
||||
|
||||
onlyAdd = intent.getBooleanExtra(KEY_ONLY_ADD, false) || checkIfViaSSO(intent);
|
||||
onlyAdd = intent.getBooleanExtra(KEY_ONLY_ADD, false);
|
||||
|
||||
// Passcode
|
||||
PassCodeManager passCodeManager = new PassCodeManager(preferences);
|
||||
@@ -702,15 +702,6 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkIfViaSSO(Intent intent) {
|
||||
Bundle extras = intent.getExtras();
|
||||
if (extras == null) {
|
||||
return false;
|
||||
} else {
|
||||
return extras.getParcelable("accountAuthenticatorResponse") != null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The redirection triggered by the OAuth authentication server as response to the GET AUTHORIZATION, and deferred
|
||||
@@ -1133,9 +1124,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
||||
|
||||
if (success) {
|
||||
accountManager.setCurrentOwnCloudAccount(mAccount.name);
|
||||
if (onlyAdd) {
|
||||
finish();
|
||||
} else {
|
||||
if (!onlyAdd) {
|
||||
Intent i = new Intent(this, FileDisplayActivity.class);
|
||||
i.setAction(FileDisplayActivity.RESTART);
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
@@ -1143,9 +1132,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
||||
}
|
||||
} else {
|
||||
// init webView again
|
||||
if (mLoginWebView != null) {
|
||||
mLoginWebView.setVisibility(View.GONE);
|
||||
}
|
||||
mLoginWebView.setVisibility(View.GONE);
|
||||
setContentView(R.layout.account_setup);
|
||||
initOverallUi();
|
||||
|
||||
@@ -1298,7 +1285,11 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
||||
setResult(RESULT_OK, intent);
|
||||
|
||||
// notify Document Provider
|
||||
DocumentsStorageProvider.notifyRootsChanged(this);
|
||||
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
String authority = getResources().getString(R.string.document_provider_authority);
|
||||
Uri rootsUri = DocumentsContract.buildRootsUri(authority);
|
||||
getContentResolver().notifyChange(rootsUri, null);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public final class PassCodeManager {
|
||||
this.preferences = preferences;
|
||||
}
|
||||
|
||||
private void setSecureFlag(Activity activity) {
|
||||
public void onActivityCreated(Activity activity) {
|
||||
Window window = activity.getWindow();
|
||||
if (window != null) {
|
||||
if (isPassCodeEnabled() || deviceCredentialsAreEnabled(activity)) {
|
||||
@@ -81,8 +81,6 @@ public final class PassCodeManager {
|
||||
boolean askedForPin = false;
|
||||
Long timestamp = AppPreferencesImpl.fromContext(activity).getLockTimestamp();
|
||||
|
||||
setSecureFlag(activity);
|
||||
|
||||
if (!exemptOfPasscodeActivities.contains(activity.getClass()) && passCodeShouldBeRequested(timestamp)) {
|
||||
askedForPin = true;
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@ import com.owncloud.android.db.ProviderMeta;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Database provider for handling the persistence aspects of arbitrary data table.
|
||||
@@ -53,51 +52,40 @@ public class ArbitraryDataProvider {
|
||||
|
||||
public int deleteKeyForAccount(String account, String key) {
|
||||
return contentResolver.delete(
|
||||
ProviderMeta.ProviderTableMeta.CONTENT_URI_ARBITRARY_DATA,
|
||||
ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_CLOUD_ID + " = ? AND " +
|
||||
ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_KEY + "= ?",
|
||||
new String[]{account, key}
|
||||
);
|
||||
ProviderMeta.ProviderTableMeta.CONTENT_URI_ARBITRARY_DATA,
|
||||
ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_CLOUD_ID + " = ? AND " +
|
||||
ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_KEY + "= ?",
|
||||
new String[]{account, key}
|
||||
);
|
||||
}
|
||||
|
||||
public void storeOrUpdateKeyValue(String accountName, String key, long newValue) {
|
||||
storeOrUpdateKeyValue(accountName, key, String.valueOf(newValue));
|
||||
}
|
||||
|
||||
public void storeOrUpdateKeyValue(@NonNull String accountName,
|
||||
@NonNull String key,
|
||||
@Nullable String newValue) {
|
||||
public void storeOrUpdateKeyValue(String accountName, String key, String newValue) {
|
||||
ArbitraryDataSet data = getArbitraryDataSet(accountName, key);
|
||||
|
||||
String value;
|
||||
if (newValue == null) {
|
||||
value = "";
|
||||
} else {
|
||||
value = newValue;
|
||||
}
|
||||
|
||||
if (data == null) {
|
||||
Log_OC.v(TAG, "Adding arbitrary data with cloud id: " + accountName + " key: " + key
|
||||
+ " value: " + value);
|
||||
|
||||
+ " value: " + newValue);
|
||||
ContentValues cv = new ContentValues();
|
||||
cv.put(ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_CLOUD_ID, accountName);
|
||||
cv.put(ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_KEY, key);
|
||||
cv.put(ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_VALUE, value);
|
||||
cv.put(ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_VALUE, newValue);
|
||||
|
||||
Uri result = contentResolver.insert(ProviderMeta.ProviderTableMeta.CONTENT_URI_ARBITRARY_DATA, cv);
|
||||
|
||||
if (result == null) {
|
||||
Log_OC.v(TAG, "Failed to store arbitrary data with cloud id: " + accountName + " key: " + key
|
||||
+ " value: " + value);
|
||||
+ " value: " + newValue);
|
||||
}
|
||||
} else {
|
||||
Log_OC.v(TAG, "Updating arbitrary data with cloud id: " + accountName + " key: " + key
|
||||
+ " value: " + value);
|
||||
+ " value: " + newValue);
|
||||
ContentValues cv = new ContentValues();
|
||||
cv.put(ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_CLOUD_ID, data.getCloudId());
|
||||
cv.put(ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_KEY, data.getKey());
|
||||
cv.put(ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_VALUE, value);
|
||||
cv.put(ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_VALUE, newValue);
|
||||
|
||||
int result = contentResolver.update(
|
||||
ProviderMeta.ProviderTableMeta.CONTENT_URI_ARBITRARY_DATA,
|
||||
@@ -108,7 +96,7 @@ public class ArbitraryDataProvider {
|
||||
|
||||
if (result == 0) {
|
||||
Log_OC.v(TAG, "Failed to update arbitrary data with cloud id: " + accountName + " key: " + key
|
||||
+ " value: " + value);
|
||||
+ " value: " + newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -216,9 +204,6 @@ public class ArbitraryDataProvider {
|
||||
if (id == -1) {
|
||||
Log_OC.e(TAG, "Arbitrary value could not be created from cursor");
|
||||
} else {
|
||||
if (dbValue == null) {
|
||||
dbValue = "";
|
||||
}
|
||||
dataSet = new ArbitraryDataSet(id, dbAccount, dbKey, dbValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,6 @@ import java.util.Set;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
|
||||
public class FileDataStorageManager {
|
||||
@@ -231,6 +230,7 @@ public class FileDataStorageManager {
|
||||
cv.put(ProviderTableMeta.FILE_ETAG_ON_SERVER, ocFile.getEtagOnServer());
|
||||
cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, ocFile.isSharedViaLink() ? 1 : 0);
|
||||
cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, ocFile.isSharedWithSharee() ? 1 : 0);
|
||||
cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, ocFile.getPublicLink());
|
||||
cv.put(ProviderTableMeta.FILE_PERMISSIONS, ocFile.getPermissions());
|
||||
cv.put(ProviderTableMeta.FILE_REMOTE_ID, ocFile.getRemoteId());
|
||||
cv.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, ocFile.isUpdateThumbnailNeeded());
|
||||
@@ -242,7 +242,6 @@ public class FileDataStorageManager {
|
||||
cv.put(ProviderTableMeta.FILE_NOTE, ocFile.getNote());
|
||||
cv.put(ProviderTableMeta.FILE_SHAREES, new Gson().toJson(ocFile.getSharees()));
|
||||
cv.put(ProviderTableMeta.FILE_RICH_WORKSPACE, ocFile.getRichWorkspace());
|
||||
cv.put(ProviderTableMeta.FILE_HAS_PREVIEW, ocFile.isPreviewAvailable() ? 1 : 0);
|
||||
|
||||
boolean sameRemotePath = fileExists(ocFile.getRemotePath());
|
||||
if (sameRemotePath ||
|
||||
@@ -485,6 +484,7 @@ public class FileDataStorageManager {
|
||||
cv.put(ProviderTableMeta.FILE_ETAG_ON_SERVER, folder.getEtagOnServer());
|
||||
cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, folder.isSharedViaLink() ? 1 : 0);
|
||||
cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, folder.isSharedWithSharee() ? 1 : 0);
|
||||
cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, folder.getPublicLink());
|
||||
cv.put(ProviderTableMeta.FILE_PERMISSIONS, folder.getPermissions());
|
||||
cv.put(ProviderTableMeta.FILE_REMOTE_ID, folder.getRemoteId());
|
||||
cv.put(ProviderTableMeta.FILE_FAVORITE, folder.isFavorite());
|
||||
@@ -519,6 +519,7 @@ public class FileDataStorageManager {
|
||||
cv.put(ProviderTableMeta.FILE_ETAG_ON_SERVER, file.getEtagOnServer());
|
||||
cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, file.isSharedViaLink() ? 1 : 0);
|
||||
cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, file.isSharedWithSharee() ? 1 : 0);
|
||||
cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, file.getPublicLink());
|
||||
cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions());
|
||||
cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId());
|
||||
cv.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, file.isUpdateThumbnailNeeded());
|
||||
@@ -1004,6 +1005,7 @@ public class FileDataStorageManager {
|
||||
ocFile.setEtagOnServer(cursor.getString(cursor.getColumnIndex(ProviderTableMeta.FILE_ETAG_ON_SERVER)));
|
||||
ocFile.setSharedViaLink(cursor.getInt(cursor.getColumnIndex(ProviderTableMeta.FILE_SHARED_VIA_LINK)) == 1);
|
||||
ocFile.setSharedWithSharee(cursor.getInt(cursor.getColumnIndex(ProviderTableMeta.FILE_SHARED_WITH_SHAREE)) == 1);
|
||||
ocFile.setPublicLink(cursor.getString(cursor.getColumnIndex(ProviderTableMeta.FILE_PUBLIC_LINK)));
|
||||
ocFile.setPermissions(cursor.getString(cursor.getColumnIndex(ProviderTableMeta.FILE_PERMISSIONS)));
|
||||
ocFile.setRemoteId(cursor.getString(cursor.getColumnIndex(ProviderTableMeta.FILE_REMOTE_ID)));
|
||||
ocFile.setUpdateThumbnailNeeded(cursor.getInt(cursor.getColumnIndex(ProviderTableMeta.FILE_UPDATE_THUMBNAIL)) == 1);
|
||||
@@ -1293,6 +1295,7 @@ public class FileDataStorageManager {
|
||||
ContentValues cv = new ContentValues();
|
||||
cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, Boolean.FALSE);
|
||||
cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, Boolean.FALSE);
|
||||
cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, "");
|
||||
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?";
|
||||
String[] whereArgs = new String[]{account.name};
|
||||
|
||||
@@ -1312,6 +1315,7 @@ public class FileDataStorageManager {
|
||||
ContentValues contentValues = new ContentValues();
|
||||
contentValues.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, Boolean.FALSE);
|
||||
contentValues.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, Boolean.FALSE);
|
||||
contentValues.put(ProviderTableMeta.FILE_PUBLIC_LINK, "");
|
||||
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + AND + ProviderTableMeta.FILE_PARENT + " = ?";
|
||||
String[] whereArgs = new String[]{account.name, String.valueOf(folder.getFileId())};
|
||||
|
||||
@@ -1331,6 +1335,7 @@ public class FileDataStorageManager {
|
||||
ContentValues contentValues = new ContentValues();
|
||||
contentValues.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, Boolean.FALSE);
|
||||
contentValues.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, Boolean.FALSE);
|
||||
contentValues.put(ProviderTableMeta.FILE_PUBLIC_LINK, "");
|
||||
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + AND + ProviderTableMeta.FILE_PATH + " = ?";
|
||||
String[] whereArgs = new String[]{account.name, filePath};
|
||||
|
||||
@@ -1346,8 +1351,7 @@ public class FileDataStorageManager {
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void cleanShares() {
|
||||
private void cleanShares() {
|
||||
String where = ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?";
|
||||
String[] whereArgs = new String[]{account.name};
|
||||
|
||||
@@ -1442,6 +1446,7 @@ public class FileDataStorageManager {
|
||||
cv.put(ProviderTableMeta.FILE_ETAG_ON_SERVER, file.getEtagOnServer());
|
||||
cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, file.isSharedViaLink() ? 1 : 0);
|
||||
cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, file.isSharedWithSharee() ? 1 : 0);
|
||||
cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, file.getPublicLink());
|
||||
cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions());
|
||||
cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId());
|
||||
cv.put(ProviderTableMeta.FILE_FAVORITE, file.isFavorite());
|
||||
@@ -1712,7 +1717,7 @@ public class FileDataStorageManager {
|
||||
if (path != null) {
|
||||
ContentValues values = new ContentValues();
|
||||
ContentResolver contentResolver = MainApp.getAppContext().getContentResolver();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && !TextUtils.isEmpty(path)) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
if (file != null) {
|
||||
values.put(MediaStore.Images.Media.MIME_TYPE, file.getMimeType());
|
||||
values.put(MediaStore.Images.Media.TITLE, file.getFileName());
|
||||
|
||||
@@ -41,14 +41,12 @@ import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.core.content.FileProvider;
|
||||
import third_parties.daveKoeller.AlphanumComparator;
|
||||
|
||||
public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterface {
|
||||
private final static String PERMISSION_SHARED_WITH_ME = "S";
|
||||
@VisibleForTesting
|
||||
public final static String PERMISSION_CAN_RESHARE = "R";
|
||||
private final static String PERMISSION_CAN_RESHARE = "R";
|
||||
private final static String PERMISSION_CAN_WRITE = "CK";
|
||||
|
||||
public static final String PATH_SEPARATOR = "/";
|
||||
@@ -76,6 +74,7 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
|
||||
private String etag;
|
||||
private String etagOnServer;
|
||||
private boolean sharedViaLink;
|
||||
private String publicLink;
|
||||
private String permissions;
|
||||
private String remoteId; // The fileid namespaced by the instance fileId, globally unique
|
||||
private boolean updateThumbnailNeeded;
|
||||
@@ -122,12 +121,6 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
|
||||
remotePath = path;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public OCFile(String path, String remoteId) {
|
||||
this(path);
|
||||
this.remoteId = remoteId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reconstruct from parcel
|
||||
*
|
||||
@@ -150,6 +143,7 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
|
||||
etag = source.readString();
|
||||
etagOnServer = source.readString();
|
||||
sharedViaLink = source.readInt() == 1;
|
||||
publicLink = source.readString();
|
||||
permissions = source.readString();
|
||||
remoteId = source.readString();
|
||||
updateThumbnailNeeded = source.readInt() == 1;
|
||||
@@ -183,6 +177,7 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
|
||||
dest.writeString(etag);
|
||||
dest.writeString(etagOnServer);
|
||||
dest.writeInt(sharedViaLink ? 1 : 0);
|
||||
dest.writeString(publicLink);
|
||||
dest.writeString(permissions);
|
||||
dest.writeString(remoteId);
|
||||
dest.writeInt(updateThumbnailNeeded ? 1 : 0);
|
||||
@@ -220,12 +215,7 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
|
||||
return decryptedRemotePath + PATH_SEPARATOR;
|
||||
}
|
||||
} else {
|
||||
if (decryptedRemotePath == null) {
|
||||
// last fallback
|
||||
return remotePath;
|
||||
} else {
|
||||
return decryptedRemotePath;
|
||||
}
|
||||
return decryptedRemotePath;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -448,6 +438,7 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
|
||||
etag = null;
|
||||
etagOnServer = null;
|
||||
sharedViaLink = false;
|
||||
publicLink = null;
|
||||
permissions = null;
|
||||
remoteId = null;
|
||||
updateThumbnailNeeded = false;
|
||||
@@ -643,6 +634,10 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
|
||||
return this.sharedViaLink;
|
||||
}
|
||||
|
||||
public String getPublicLink() {
|
||||
return this.publicLink;
|
||||
}
|
||||
|
||||
public String getPermissions() {
|
||||
return this.permissions;
|
||||
}
|
||||
@@ -751,6 +746,10 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
|
||||
this.sharedViaLink = sharedViaLink;
|
||||
}
|
||||
|
||||
public void setPublicLink(String publicLink) {
|
||||
this.publicLink = publicLink;
|
||||
}
|
||||
|
||||
public void setPermissions(String permissions) {
|
||||
this.permissions = permissions;
|
||||
}
|
||||
|
||||
@@ -21,8 +21,6 @@
|
||||
|
||||
package com.owncloud.android.datamodel;
|
||||
|
||||
import com.owncloud.android.files.services.FileUploader;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
@@ -180,14 +178,10 @@ public class SyncedFolder implements Serializable, Cloneable {
|
||||
return this.uploadAction;
|
||||
}
|
||||
|
||||
public int getNameCollisionPolicyInt() {
|
||||
public int getNameCollisionPolicy() {
|
||||
return this.nameCollisionPolicy;
|
||||
}
|
||||
|
||||
public FileUploader.NameCollisionPolicy getNameCollisionPolicy() {
|
||||
return FileUploader.NameCollisionPolicy.deserialize(nameCollisionPolicy);
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
@@ -399,7 +399,7 @@ public class SyncedFolderProvider extends Observable {
|
||||
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ACCOUNT, syncedFolder.getAccount());
|
||||
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_UPLOAD_ACTION, syncedFolder.getUploadAction());
|
||||
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_NAME_COLLISION_POLICY,
|
||||
syncedFolder.getNameCollisionPolicyInt());
|
||||
syncedFolder.getNameCollisionPolicy());
|
||||
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_TYPE, syncedFolder.getType().getId());
|
||||
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_HIDDEN, syncedFolder.isHidden());
|
||||
|
||||
|
||||
@@ -83,8 +83,6 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
* Manager for concurrent access to thumbnails cache.
|
||||
*/
|
||||
public final class ThumbnailsCacheManager {
|
||||
private static final int READ_TIMEOUT = 40000;
|
||||
private static final int CONNECTION_TIMEOUT = 5000;
|
||||
|
||||
public static final String PREFIX_RESIZED_IMAGE = "r";
|
||||
public static final String PREFIX_THUMBNAIL = "t";
|
||||
@@ -516,9 +514,15 @@ public final class ThumbnailsCacheManager {
|
||||
|
||||
} catch(OutOfMemoryError oome) {
|
||||
Log_OC.e(TAG, "Out of memory");
|
||||
isError = true;
|
||||
} catch (Throwable t) {
|
||||
// the app should never break due to a problem with thumbnails
|
||||
Log_OC.e(TAG, "Generation of thumbnail for " + mFile + " failed", t);
|
||||
isError = true;
|
||||
} finally {
|
||||
if (isError && mListener != null){
|
||||
mListener.onError();
|
||||
}
|
||||
}
|
||||
|
||||
return thumbnail;
|
||||
@@ -528,7 +532,6 @@ public final class ThumbnailsCacheManager {
|
||||
if (bitmap != null && mImageViewReference != null) {
|
||||
final ImageView imageView = mImageViewReference.get();
|
||||
final ThumbnailGenerationTask bitmapWorkerTask = getBitmapWorkerTask(imageView);
|
||||
|
||||
if (this == bitmapWorkerTask) {
|
||||
String tagId = "";
|
||||
if (mFile instanceof OCFile) {
|
||||
@@ -539,21 +542,17 @@ public final class ThumbnailsCacheManager {
|
||||
tagId = String.valueOf(((TrashbinFile) mFile).getRemoteId());
|
||||
}
|
||||
if (String.valueOf(imageView.getTag()).equals(tagId)) {
|
||||
if (gridViewEnabled) {
|
||||
if (gridViewEnabled){
|
||||
BitmapUtils.setRoundedBitmapForGridMode(bitmap, imageView);
|
||||
} else {
|
||||
BitmapUtils.setRoundedBitmap(bitmap, imageView);
|
||||
BitmapUtils.setRoundedBitmap(bitmap, imageView);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mListener != null) {
|
||||
mListener.onSuccess();
|
||||
}
|
||||
} else {
|
||||
if (mListener != null) {
|
||||
mListener.onError();
|
||||
}
|
||||
if (mListener !=null){
|
||||
mListener.onSuccess();
|
||||
}
|
||||
|
||||
if (mAsyncTasks != null) {
|
||||
@@ -634,7 +633,7 @@ public final class ThumbnailsCacheManager {
|
||||
getMethod.setRequestHeader(RemoteOperation.OCS_API_HEADER,
|
||||
RemoteOperation.OCS_API_HEADER_VALUE);
|
||||
|
||||
int status = mClient.executeMethod(getMethod, READ_TIMEOUT, CONNECTION_TIMEOUT);
|
||||
int status = mClient.executeMethod(getMethod);
|
||||
if (status == HttpStatus.SC_OK) {
|
||||
InputStream inputStream = getMethod.getResponseBodyAsStream();
|
||||
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
|
||||
@@ -1138,10 +1137,13 @@ public final class ThumbnailsCacheManager {
|
||||
}
|
||||
|
||||
public static class AsyncMediaThumbnailDrawable extends BitmapDrawable {
|
||||
private final WeakReference<MediaThumbnailGenerationTask> bitmapWorkerTaskReference;
|
||||
|
||||
public AsyncMediaThumbnailDrawable(Resources res, Bitmap bitmap) {
|
||||
public AsyncMediaThumbnailDrawable(Resources res, Bitmap bitmap,
|
||||
MediaThumbnailGenerationTask bitmapWorkerTask) {
|
||||
|
||||
super(res, bitmap);
|
||||
bitmapWorkerTaskReference = new WeakReference<>(bitmapWorkerTask);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -102,6 +102,7 @@ public class ProviderMeta {
|
||||
public static final String FILE_ETAG_ON_SERVER = "etag_on_server";
|
||||
public static final String FILE_SHARED_VIA_LINK = "share_by_link";
|
||||
public static final String FILE_SHARED_WITH_SHAREE = "shared_via_users";
|
||||
public static final String FILE_PUBLIC_LINK = "public_link";
|
||||
public static final String FILE_PERMISSIONS = "permissions";
|
||||
public static final String FILE_REMOTE_ID = "remote_id";
|
||||
public static final String FILE_UPDATE_THUMBNAIL = "update_thumbnail";
|
||||
@@ -136,6 +137,7 @@ public class ProviderMeta {
|
||||
FILE_ETAG_ON_SERVER,
|
||||
FILE_SHARED_VIA_LINK,
|
||||
FILE_SHARED_WITH_SHAREE,
|
||||
FILE_PUBLIC_LINK,
|
||||
FILE_PERMISSIONS,
|
||||
FILE_REMOTE_ID,
|
||||
FILE_UPDATE_THUMBNAIL,
|
||||
|
||||
@@ -58,7 +58,6 @@ import androidx.annotation.Nullable;
|
||||
public class FileMenuFilter {
|
||||
|
||||
private static final int SINGLE_SELECT_ITEMS = 1;
|
||||
public static final String SEND_OFF = "off";
|
||||
|
||||
private int numberOfAllFiles;
|
||||
private Collection<OCFile> files;
|
||||
@@ -204,7 +203,6 @@ public class FileMenuFilter {
|
||||
filterCancelSync(toShow, toHide, synchronizing);
|
||||
filterSync(toShow, toHide, synchronizing);
|
||||
filterShareFile(toShow, toHide, capability);
|
||||
filterSendFiles(toShow, toHide);
|
||||
filterDetails(toShow, toHide);
|
||||
filterFavorite(toShow, toHide, synchronizing);
|
||||
filterUnfavorite(toShow, toHide, synchronizing);
|
||||
@@ -224,15 +222,6 @@ public class FileMenuFilter {
|
||||
}
|
||||
}
|
||||
|
||||
private void filterSendFiles(List<Integer> toShow, List<Integer> toHide) {
|
||||
if (containsEncryptedFile() || isSingleSelection() || overflowMenu || !anyFileDown() ||
|
||||
SEND_OFF.equalsIgnoreCase(context.getString(R.string.send_files_to_other_apps))) {
|
||||
toHide.add(R.id.action_send_file);
|
||||
} else {
|
||||
toShow.add(R.id.action_send_file);
|
||||
}
|
||||
}
|
||||
|
||||
private void filterDetails(Collection<Integer> toShow, Collection<Integer> toHide) {
|
||||
if (isSingleSelection()) {
|
||||
toShow.add(R.id.action_see_details);
|
||||
|
||||
@@ -40,7 +40,6 @@ import android.util.Pair;
|
||||
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.files.downloader.DownloadTask;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.authentication.AuthenticatorActivity;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
@@ -56,7 +55,6 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCo
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.lib.resources.files.FileUtils;
|
||||
import com.owncloud.android.operations.DownloadFileOperation;
|
||||
import com.owncloud.android.providers.DocumentsStorageProvider;
|
||||
import com.owncloud.android.ui.activity.FileActivity;
|
||||
import com.owncloud.android.ui.activity.FileDisplayActivity;
|
||||
import com.owncloud.android.ui.dialog.SendShareDialog;
|
||||
@@ -78,7 +76,6 @@ import java.util.Vector;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
import dagger.android.AndroidInjection;
|
||||
|
||||
public class FileDownloader extends Service
|
||||
@@ -120,7 +117,6 @@ public class FileDownloader extends Service
|
||||
|
||||
@Inject UserAccountManager accountManager;
|
||||
@Inject UploadsStorageManager uploadsStorageManager;
|
||||
@Inject LocalBroadcastManager localBroadcastManager;
|
||||
|
||||
public static String getDownloadAddedMessage() {
|
||||
return FileDownloader.class.getName() + DOWNLOAD_ADDED_MESSAGE;
|
||||
@@ -499,7 +495,6 @@ public class FileDownloader extends Service
|
||||
* Updates the OC File after a successful download.
|
||||
*
|
||||
* TODO move to DownloadFileOperation
|
||||
* unify with code from {@link DocumentsStorageProvider} and {@link DownloadTask}.
|
||||
*/
|
||||
private void saveDownloadedFile() {
|
||||
OCFile file = mStorageManager.getFileById(mCurrentDownload.getFile().getFileId());
|
||||
@@ -696,7 +691,7 @@ public class FileDownloader extends Service
|
||||
end.putExtra(EXTRA_LINKED_TO_PATH, unlinkedFromRemotePath);
|
||||
}
|
||||
end.setPackage(getPackageName());
|
||||
localBroadcastManager.sendBroadcast(end);
|
||||
sendStickyBroadcast(end);
|
||||
}
|
||||
|
||||
|
||||
@@ -713,7 +708,7 @@ public class FileDownloader extends Service
|
||||
added.putExtra(EXTRA_REMOTE_PATH, download.getRemotePath());
|
||||
added.putExtra(EXTRA_LINKED_TO_PATH, linkedToRemotePath);
|
||||
added.setPackage(getPackageName());
|
||||
localBroadcastManager.sendBroadcast(added);
|
||||
sendStickyBroadcast(added);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -90,7 +90,6 @@ import javax.inject.Inject;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
import dagger.android.AndroidInjection;
|
||||
|
||||
/**
|
||||
@@ -167,11 +166,6 @@ public class FileUploader extends Service
|
||||
|
||||
public static final String KEY_LOCAL_BEHAVIOUR = "BEHAVIOUR";
|
||||
|
||||
/**
|
||||
* Set to true if the HTTP library should disable automatic retries of uploads.
|
||||
*/
|
||||
public static final String KEY_DISABLE_RETRIES = "DISABLE_RETRIES";
|
||||
|
||||
public static final int LOCAL_BEHAVIOUR_COPY = 0;
|
||||
public static final int LOCAL_BEHAVIOUR_MOVE = 1;
|
||||
public static final int LOCAL_BEHAVIOUR_FORGET = 2;
|
||||
@@ -190,7 +184,6 @@ public class FileUploader extends Service
|
||||
@Inject UploadsStorageManager mUploadsStorageManager;
|
||||
@Inject ConnectivityService connectivityService;
|
||||
@Inject PowerManagementService powerManagementService;
|
||||
@Inject LocalBroadcastManager localBroadcastManager;
|
||||
|
||||
private IndexedForest<UploadFileOperation> mPendingUploads = new IndexedForest<>();
|
||||
|
||||
@@ -255,7 +248,7 @@ public class FileUploader extends Service
|
||||
*/
|
||||
private void resurrection() {
|
||||
// remove stucked notification
|
||||
mNotificationManager.cancel(FOREGROUND_SERVICE_ID);
|
||||
mNotificationManager.cancel(R.string.uploader_upload_in_progress_ticker);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -269,9 +262,6 @@ public class FileUploader extends Service
|
||||
mServiceHandler = null;
|
||||
mServiceLooper.quit();
|
||||
mServiceLooper = null;
|
||||
if (mNotificationManager != null) {
|
||||
mNotificationManager.cancel(FOREGROUND_SERVICE_ID);
|
||||
}
|
||||
mNotificationManager = null;
|
||||
|
||||
// remove AccountsUpdatedListener
|
||||
@@ -415,7 +405,6 @@ public class FileUploader extends Service
|
||||
int localAction = intent.getIntExtra(KEY_LOCAL_BEHAVIOUR, LOCAL_BEHAVIOUR_FORGET);
|
||||
boolean isCreateRemoteFolder = intent.getBooleanExtra(KEY_CREATE_REMOTE_FOLDER, false);
|
||||
int createdBy = intent.getIntExtra(KEY_CREATED_BY, UploadFileOperation.CREATED_BY_USER);
|
||||
boolean disableRetries = intent.getBooleanExtra(KEY_DISABLE_RETRIES, true);
|
||||
try {
|
||||
for (OCFile file : files) {
|
||||
startNewUpload(
|
||||
@@ -427,9 +416,8 @@ public class FileUploader extends Service
|
||||
localAction,
|
||||
isCreateRemoteFolder,
|
||||
createdBy,
|
||||
file,
|
||||
disableRetries
|
||||
);
|
||||
file
|
||||
);
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log_OC.e(TAG, "Not enough information provided in intent: " + e.getMessage());
|
||||
@@ -456,9 +444,8 @@ public class FileUploader extends Service
|
||||
int localAction,
|
||||
boolean isCreateRemoteFolder,
|
||||
int createdBy,
|
||||
OCFile file,
|
||||
boolean disableRetries
|
||||
) {
|
||||
OCFile file
|
||||
) {
|
||||
OCUpload ocUpload = new OCUpload(file, user.toPlatformAccount());
|
||||
ocUpload.setFileSize(file.getFileLength());
|
||||
ocUpload.setNameCollisionPolicy(nameCollisionPolicy);
|
||||
@@ -480,8 +467,7 @@ public class FileUploader extends Service
|
||||
localAction,
|
||||
this,
|
||||
onWifiOnly,
|
||||
whileChargingOnly,
|
||||
disableRetries
|
||||
whileChargingOnly
|
||||
);
|
||||
newUpload.setCreatedBy(createdBy);
|
||||
if (isCreateRemoteFolder) {
|
||||
@@ -529,8 +515,7 @@ public class FileUploader extends Service
|
||||
upload.getLocalAction(),
|
||||
this,
|
||||
onWifiOnly,
|
||||
whileChargingOnly,
|
||||
true
|
||||
whileChargingOnly
|
||||
);
|
||||
|
||||
newUpload.addDataTransferProgressListener(this);
|
||||
@@ -708,7 +693,7 @@ public class FileUploader extends Service
|
||||
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
}
|
||||
|
||||
mNotificationManager.notify(FOREGROUND_SERVICE_ID, mNotificationBuilder.build());
|
||||
mNotificationManager.notify(R.string.uploader_upload_in_progress_ticker, mNotificationBuilder.build());
|
||||
} // else wait until the upload really start (onTransferProgress is called), so that if it's discarded
|
||||
// due to lack of Wifi, no notification is shown
|
||||
// TODO generalize for automated uploads
|
||||
@@ -730,10 +715,7 @@ public class FileUploader extends Service
|
||||
String fileName = filePath.substring(filePath.lastIndexOf(FileUtils.PATH_SEPARATOR) + 1);
|
||||
String text = String.format(getString(R.string.uploader_upload_in_progress_content), percent, fileName);
|
||||
mNotificationBuilder.setContentText(text);
|
||||
if (mNotificationManager == null) {
|
||||
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
}
|
||||
mNotificationManager.notify(FOREGROUND_SERVICE_ID, mNotificationBuilder.build());
|
||||
mNotificationManager.notify(R.string.uploader_upload_in_progress_ticker, mNotificationBuilder.build());
|
||||
}
|
||||
mLastPercent = percent;
|
||||
}
|
||||
@@ -751,6 +733,8 @@ public class FileUploader extends Service
|
||||
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
}
|
||||
|
||||
mNotificationManager.cancel(R.string.uploader_upload_in_progress_ticker);
|
||||
|
||||
// Only notify if the upload fails
|
||||
if (!uploadResult.isCancelled() &&
|
||||
!uploadResult.isSuccess() &&
|
||||
@@ -836,7 +820,7 @@ public class FileUploader extends Service
|
||||
Intent start = new Intent(getUploadsAddedMessage());
|
||||
// nothing else needed right now
|
||||
start.setPackage(getPackageName());
|
||||
localBroadcastManager.sendBroadcast(start);
|
||||
sendStickyBroadcast(start);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -853,7 +837,7 @@ public class FileUploader extends Service
|
||||
start.putExtra(ACCOUNT_NAME, upload.getAccount().name);
|
||||
|
||||
start.setPackage(getPackageName());
|
||||
localBroadcastManager.sendBroadcast(start);
|
||||
sendStickyBroadcast(start);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -886,7 +870,7 @@ public class FileUploader extends Service
|
||||
end.putExtra(EXTRA_LINKED_TO_PATH, unlinkedFromRemotePath);
|
||||
}
|
||||
end.setPackage(getPackageName());
|
||||
localBroadcastManager.sendBroadcast(end);
|
||||
sendStickyBroadcast(end);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -967,19 +951,6 @@ public class FileUploader extends Service
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload and overwrite an already uploaded file with disabled retries
|
||||
*/
|
||||
public static void uploadUpdateFile(
|
||||
Context context,
|
||||
Account account,
|
||||
OCFile existingFile,
|
||||
Integer behaviour,
|
||||
NameCollisionPolicy nameCollisionPolicy
|
||||
) {
|
||||
uploadUpdateFile(context, account, new OCFile[]{existingFile}, behaviour, nameCollisionPolicy, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload and overwrite an already uploaded file
|
||||
*/
|
||||
@@ -988,10 +959,9 @@ public class FileUploader extends Service
|
||||
Account account,
|
||||
OCFile existingFile,
|
||||
Integer behaviour,
|
||||
NameCollisionPolicy nameCollisionPolicy,
|
||||
boolean disableRetries
|
||||
) {
|
||||
uploadUpdateFile(context, account, new OCFile[]{existingFile}, behaviour, nameCollisionPolicy, disableRetries);
|
||||
NameCollisionPolicy nameCollisionPolicy
|
||||
) {
|
||||
uploadUpdateFile(context, account, new OCFile[]{existingFile}, behaviour, nameCollisionPolicy);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1002,16 +972,14 @@ public class FileUploader extends Service
|
||||
Account account,
|
||||
OCFile[] existingFiles,
|
||||
Integer behaviour,
|
||||
NameCollisionPolicy nameCollisionPolicy,
|
||||
boolean disableRetries
|
||||
) {
|
||||
NameCollisionPolicy nameCollisionPolicy
|
||||
) {
|
||||
Intent intent = new Intent(context, FileUploader.class);
|
||||
|
||||
intent.putExtra(FileUploader.KEY_ACCOUNT, account);
|
||||
intent.putExtra(FileUploader.KEY_FILE, existingFiles);
|
||||
intent.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, behaviour);
|
||||
intent.putExtra(FileUploader.KEY_NAME_COLLISION_POLICY, nameCollisionPolicy);
|
||||
intent.putExtra(FileUploader.KEY_DISABLE_RETRIES, disableRetries);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
context.startForegroundService(intent);
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
package com.owncloud.android.operations;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.util.Pair;
|
||||
|
||||
import com.nextcloud.client.account.User;
|
||||
@@ -46,6 +47,8 @@ import com.owncloud.android.utils.MimeType;
|
||||
import java.io.File;
|
||||
import java.util.UUID;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
||||
import static com.owncloud.android.datamodel.OCFile.PATH_SEPARATOR;
|
||||
import static com.owncloud.android.datamodel.OCFile.ROOT_PATH;
|
||||
|
||||
@@ -95,12 +98,18 @@ public class CreateFolderOperation extends SyncOperation implements OnRemoteOper
|
||||
boolean encryptedAncestor = FileStorageUtils.checkEncryptionStatus(parent, getStorageManager());
|
||||
|
||||
if (encryptedAncestor) {
|
||||
return encryptedCreate(parent, remoteParentPath, client);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
return encryptedCreate(parent, remoteParentPath, client);
|
||||
} else {
|
||||
Log_OC.e(TAG, "Encrypted upload on old Android API");
|
||||
return new RemoteOperationResult(RemoteOperationResult.ResultCode.OLD_ANDROID_API);
|
||||
}
|
||||
} else {
|
||||
return normalCreate(client);
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
||||
private RemoteOperationResult encryptedCreate(OCFile parent, String remoteParentPath, OwnCloudClient client) {
|
||||
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(context.getContentResolver());
|
||||
String privateKey = arbitraryDataProvider.getValue(user.getAccountName(), EncryptionUtils.PRIVATE_KEY);
|
||||
|
||||