Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
61fe75e981 | ||
|
|
2a01aca904 | ||
|
|
87855c1335 | ||
|
|
0f54b71716 | ||
|
|
4ce14abb2c | ||
|
|
bff8068f2b | ||
|
|
0960d08321 | ||
|
|
b17373cddf | ||
|
|
0d6114283d | ||
|
|
d7122e70e4 | ||
|
|
f47fa94046 | ||
|
|
f303cd0dab | ||
|
|
56f8b3befc | ||
|
|
65acb834ef | ||
|
|
f7c8bf2f4c | ||
|
|
2b69892694 | ||
|
|
af606603de | ||
|
|
f22b386cc5 | ||
|
|
724147d272 | ||
|
|
235ca28bc6 | ||
|
|
1c19846711 | ||
|
|
87a8ab5f07 | ||
|
|
339770fa92 | ||
|
|
068ff229a7 | ||
|
|
aa11e9b1ee | ||
|
|
2ff6d73470 |
No files matched your search
@@ -67,7 +67,6 @@ steps:
|
||||
commands:
|
||||
- scripts/checkIfRunDrone.sh $GIT_USERNAME $GIT_TOKEN $DRONE_PULL_REQUEST || exit 0
|
||||
- emulator-headless -avd android-27 -no-snapshot -gpu swiftshader_indirect -no-window -no-audio -skin 500x833 &
|
||||
- sed -i s'#<bool name="is_beta">false</bool>#<bool name="is_beta">true</bool>#'g src/main/res/values/setup.xml
|
||||
- ./gradlew assembleGplay
|
||||
- ./gradlew assembleGplayDebug
|
||||
- scripts/wait_for_emulator.sh
|
||||
@@ -102,21 +101,7 @@ steps:
|
||||
|
||||
services:
|
||||
- name: server
|
||||
image: nextcloudci/server:server-17 # also change in updateScreenshots.sh
|
||||
commands:
|
||||
- /usr/local/bin/initnc.sh
|
||||
- su www-data -c "OC_PASS=user1 php /var/www/html/occ user:add --password-from-env --display-name='User One' user1"
|
||||
- su www-data -c "OC_PASS=user2 php /var/www/html/occ user:add --password-from-env --display-name='User Two' user2"
|
||||
- su www-data -c "OC_PASS=user3 php /var/www/html/occ user:add --password-from-env --display-name='User Three' user3"
|
||||
- su www-data -c "php /var/www/html/occ user:setting user2 files quota 1G"
|
||||
- su www-data -c "php /var/www/html/occ group:add users"
|
||||
- su www-data -c "php /var/www/html/occ group:adduser users user1"
|
||||
- su www-data -c "php /var/www/html/occ group:adduser users user2"
|
||||
- su www-data -c "git clone -b master https://github.com/nextcloud/activity.git /var/www/html/apps/activity/"
|
||||
- su www-data -c "php /var/www/html/occ app:enable activity"
|
||||
- su www-data -c "git clone -b master https://github.com/nextcloud/text.git /var/www/html/apps/text/"
|
||||
- su www-data -c "php /var/www/html/occ app:enable text"
|
||||
- /usr/local/bin/run.sh
|
||||
image: nextcloudci/server:server-3
|
||||
|
||||
trigger:
|
||||
branch:
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
### Testing
|
||||
Writing tests is very important. Please try to write some tests for your PR.
|
||||
|
||||
If you need help, please do not hesitate to ask in this PR for help.
|
||||
|
||||
- [ ] [unit tests](https://github.com/nextcloud/android/blob/master/CONTRIBUTING.md#unit-tests)
|
||||
- [ ] [instrumented tests](https://github.com/nextcloud/android/blob/master/CONTRIBUTING.md#instrumented-tests)
|
||||
- [ ] [UI tests](https://github.com/nextcloud/android/blob/master/CONTRIBUTING.md#ui-tests)
|
||||
@@ -2,17 +2,19 @@
|
||||
daysUntilStale: 28
|
||||
# Number of days of inactivity before a stale issue is closed
|
||||
daysUntilClose: 14
|
||||
# Only issues or pull requests with all of these labels are check if stale. Defaults to `[]` (disabled)
|
||||
onlyLabels:
|
||||
- bug
|
||||
- "needs info/discussion"
|
||||
# Issues with these labels will never be considered stale
|
||||
exemptLabels: []
|
||||
exemptLabels:
|
||||
- 1. developing
|
||||
- 2. to review
|
||||
- 3. to release
|
||||
- approved
|
||||
- enhancement
|
||||
- overview
|
||||
# Label to use when marking an issue as stale
|
||||
staleLabel: stale
|
||||
# Comment to post when marking an issue as stale. Set to `false` to disable
|
||||
markComment: >
|
||||
This bug report did not receive an update in the last 4 weeks.
|
||||
This request did not receive an update in the last 4 weeks.
|
||||
Please take a look again and update the issue with new details,
|
||||
otherwise the issue will be automatically closed in 2 weeks. Thank you!
|
||||
# Comment to post when closing a stale issue. Set to `false` to disable
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
name: "Validate Gradle Wrapper"
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
validation:
|
||||
name: "Validation"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: gradle/wrapper-validation-action@v1
|
||||
@@ -29,6 +29,9 @@
|
||||
</option>
|
||||
<option name="RIGHT_MARGIN" value="120" />
|
||||
<option name="WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN" value="true" />
|
||||
<AndroidXmlCodeStyleSettings>
|
||||
<option name="ARRANGEMENT_SETTINGS_MIGRATED_TO_191" value="true" />
|
||||
</AndroidXmlCodeStyleSettings>
|
||||
<JavaCodeStyleSettings>
|
||||
<option name="IMPORT_LAYOUT_TABLE">
|
||||
<value>
|
||||
@@ -70,7 +73,6 @@
|
||||
</XML>
|
||||
<codeStyleSettings language="JAVA">
|
||||
<option name="ALIGN_MULTILINE_PARAMETERS_IN_CALLS" value="true" />
|
||||
<option name="ALIGN_MULTILINE_METHOD_BRACKETS" value="true" />
|
||||
<option name="WRAP_COMMENTS" value="true" />
|
||||
<option name="IF_BRACE_FORCE" value="3" />
|
||||
<option name="DOWHILE_BRACE_FORCE" value="3" />
|
||||
@@ -78,9 +80,6 @@
|
||||
<option name="FOR_BRACE_FORCE" value="3" />
|
||||
<option name="FIELD_ANNOTATION_WRAP" value="0" />
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="Markdown">
|
||||
<option name="RIGHT_MARGIN" value="120" />
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="XML">
|
||||
<indentOptions>
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="4" />
|
||||
@@ -193,8 +192,5 @@
|
||||
</rules>
|
||||
</arrangement>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="kotlin">
|
||||
<option name="ALIGN_MULTILINE_METHOD_BRACKETS" value="true" />
|
||||
</codeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
||||
@@ -1,39 +1,17 @@
|
||||
## 3.10.1 (February, 05, 2020)
|
||||
|
||||
- fix crash on self-signed certificates
|
||||
- fix openOffice open files with special chars
|
||||
|
||||
For a full list, please see https://github.com/nextcloud/android/milestone/45
|
||||
|
||||
## 3.10.0 (January, 17, 2020)
|
||||
|
||||
- Dark theme (@dan0xii, @AndyScherzinger)
|
||||
- Rich workspace (NC18+)
|
||||
- collaborative text editor (NC18+)
|
||||
- links in Markdown previews clickable (@AndyScherzinger)
|
||||
- Show/Hide auto upload list items (@AndyScherzinger)
|
||||
- drop 4.0.x support
|
||||
- outdated server warning set to NC15
|
||||
- latest supported version NC13
|
||||
|
||||
For a full list, please see https://github.com/nextcloud/android/milestone/40
|
||||
|
||||
## 3.9.2 (December, 05, 2019)
|
||||
3.9.2 (December, 05, 2019)
|
||||
|
||||
- HOTFIX: fix login loop
|
||||
- Fix crash on opening png images
|
||||
- Translation updates
|
||||
|
||||
For a full list, please see https://github.com/nextcloud/android/milestone/44
|
||||
|
||||
## 3.9.1 (December, 04, 2019)
|
||||
3.9.1 (December, 04, 2019)
|
||||
|
||||
- Fix crash on opening png images
|
||||
- Translation updates
|
||||
|
||||
For a full list, please see https://github.com/nextcloud/android/milestone/43
|
||||
|
||||
## 3.9.0 (November, 12, 2019)
|
||||
3.9.0 (November, 12, 2019)
|
||||
|
||||
- preview Markdown with syntax highlighting @AndyScherzinger
|
||||
- improved DavX5 integration @bitfireAT
|
||||
|
||||
@@ -5,46 +5,40 @@
|
||||
|
||||
|
||||
# Index
|
||||
1. [Guidelines](#guidelines)
|
||||
1. [Issue reporting](#issue-reporting)
|
||||
1. [Labels](#labels)
|
||||
1. [Pull request](#pull-request)
|
||||
1. [Issue](#issue)
|
||||
1. [Bug workflow](#bug-workflow)
|
||||
1. [Contributing to Source Code](#contributing-to-source-code)
|
||||
1. [Developing process](#developing-process)
|
||||
1. [Branching model](#branching-model)
|
||||
1. [Android Studio formatter setup](#android-studio-formatter-setup)
|
||||
1. [Build variants](#build-variants)
|
||||
1. [Contribution process](#contribution-process)
|
||||
1. [Fork and download android repository](#fork-and-download-android-repository)
|
||||
1. [Create pull request](#create-pull-request)
|
||||
1. [Create another pull request](#create-another-pull-request)
|
||||
1. [Backport pull request](#backport-pull-request)
|
||||
1. [Pull requests that also need changes on library](#pull-requests-that-also-need-changes-on-library)
|
||||
1. [Adding new files](#adding-new-files)
|
||||
1. [Testing](#testing)
|
||||
1. [File naming](#file-naming)
|
||||
1. [Menu files](#menu-files)
|
||||
1. [Translations](#translations)
|
||||
1. [Engineering practices](#engineering-practices)
|
||||
1. [Approach to technical debt](#approach-to-technical-debt)
|
||||
1. [Dependency injection](#dependency-injection)
|
||||
1. [Custom platform APIs](#custom-platform-apis)
|
||||
1. [Testing](#testing)
|
||||
1. [Releases](#releases)
|
||||
1. [Types](#types)
|
||||
1. [Stable](#stable)
|
||||
1. [Release Candidate](#release-candidate)
|
||||
1. [Dev](#dev)
|
||||
1. [Version Name and number](#version-name-and-number)
|
||||
1. [Stable / Release candidate](#stable-release-candidate)
|
||||
1. [Dev](#dev)
|
||||
1. [Release cycle](#release-cycle)
|
||||
1. [Release Process](#release-process)
|
||||
1. [Stable Release](#stable-release)
|
||||
1. [Release Candidate Release](#release-candidate-release)
|
||||
1. [Development Dev](#development-dev)
|
||||
1. Guidelines
|
||||
1. Issue reporting
|
||||
1. Labels
|
||||
1. Pull request (PR)
|
||||
1. Issue
|
||||
1. Bug workflow
|
||||
1. Contributing to Source Code
|
||||
1. Developing process
|
||||
1. Branching model
|
||||
1. Android Studio formatter setup
|
||||
1. Build variants
|
||||
1. Contribution process
|
||||
1. Fork and download android/master repository
|
||||
1. Create pull request
|
||||
1. Create another pull request
|
||||
1. Backport pull request
|
||||
1. Pull requests that also need changes on library
|
||||
1. Adding new files
|
||||
1. File naming
|
||||
1. Menu files
|
||||
1. Translations
|
||||
1. Releases
|
||||
1. Types
|
||||
1. Stable
|
||||
1. Release Candidate
|
||||
1. Dev
|
||||
1. Version Name and number
|
||||
1. Stable / Release candidate
|
||||
1. Dev
|
||||
1. Release cycle
|
||||
1. Release Process
|
||||
1. Stable Release
|
||||
1. Release Candidate Release
|
||||
1. Development Dev
|
||||
|
||||
|
||||
# Guidelines
|
||||
@@ -72,7 +66,6 @@ If your issue appears to be a bug, and hasn't been reported, open a new issue.
|
||||
|
||||
|
||||
### Bug workflow
|
||||
Every bug should be triaged in approved/needs info in a given time.
|
||||
* approved: at least one other is able to reproduce it
|
||||
* needs info: something unclear, or not able to reproduce
|
||||
* if no response within 1 months, bug will be closed
|
||||
@@ -124,18 +117,18 @@ There are three build variants
|
||||
* For your first contribution start a pull request on master.
|
||||
|
||||
|
||||
### Fork and download android repository:
|
||||
### 1. Fork and download android/master repository:
|
||||
* Please follow [SETUP.md](https://github.com/nextcloud/android/blob/master/SETUP.md) to setup Nextcloud Android app work environment.
|
||||
|
||||
|
||||
### Create pull request:
|
||||
### 2. Create pull request:
|
||||
* Commit your changes locally: ```git commit -a```
|
||||
* Push your changes to your GitHub repo: ```git push```
|
||||
* Browse to <https://github.com/YOURGITHUBNAME/android/pulls> and issue pull request
|
||||
* Enter description and send pull request.
|
||||
|
||||
|
||||
### Create another pull request:
|
||||
### 3. Create another pull request:
|
||||
To make sure your new pull request does not contain commits which are already contained in previous PRs, create a new branch which is a clone of upstream/master.
|
||||
|
||||
* ```git fetch upstream```
|
||||
@@ -144,12 +137,12 @@ To make sure your new pull request does not contain commits which are already co
|
||||
* Push branch to server: ```git push -u origin name_of_local_master_branch```
|
||||
* Use GitHub to issue PR
|
||||
|
||||
### Backport pull request:
|
||||
### 4. Backport pull request:
|
||||
Use backport-bot via "/backport to stable-version", e.g. "/backport to stable-3.7".
|
||||
This will automatically add "backport-request" label to PR and bot will create a new PR to targeted branch once the base PR is merged.
|
||||
If automatic backport fails, it will create a comment.
|
||||
|
||||
### Pull requests that also need changes on library
|
||||
### 5. Pull requests that also need changes on library
|
||||
For speeding up developing, we do use a master snapshot of nextcloud-library, provided by jitpack.io.
|
||||
This means that if a breaking change is merged on library, master branch of the app will fail.
|
||||
To limit this risk please follow this approach:
|
||||
@@ -163,7 +156,7 @@ Once both PRs are reviewed and ready to merge:
|
||||
|
||||
With this approach the "downtime" of not building master is limited to the timestamp between merge lib PR and merging app PR, which is only limited by CI.
|
||||
|
||||
### Adding new files
|
||||
### 6. Adding new files
|
||||
If you create a new file it needs to contain a license header. We encourage you to use the same license (AGPL3+) as we do.
|
||||
Copyright of Nextcloud GmbH is optional.
|
||||
|
||||
@@ -245,52 +238,6 @@ Source code of app:
|
||||
-->
|
||||
```
|
||||
|
||||
### Testing
|
||||
- testing is very important, but is lacking a lot on this project. Starting with 2020 we aim to write tests for every
|
||||
new pull request.
|
||||
- Code coverage can be found [here](https://codecov.io/gh/nextcloud/android).
|
||||
|
||||
#### Unit tests
|
||||
- small, isolated tests, with no need of Android SDK
|
||||
- code coverage can be directly shown via right click on test and select "Run Test with Coverage"
|
||||
|
||||
#### Instrumented tests
|
||||
- tests to see larger code working in correct way
|
||||
- tests that require parts of Android SDK
|
||||
- best to avoid server communication, see https://github.com/nextcloud/android/pull/3624
|
||||
|
||||
- run all tests ```./gradlew createGplayDebugCoverageReport -Pcoverage=true```
|
||||
- run selective test class: ```./gradlew createGplayDebugCoverageReport -Pcoverage=true
|
||||
-Pandroid.testInstrumentationRunnerArguments.class=com.owncloud.android.datamodel.FileDataStorageManagerTest```
|
||||
- run multiple test classes:
|
||||
- separate by ","
|
||||
- ```./gradlew createGplayDebugCoverageReport -Pcoverage=true -Pandroid.testInstrumentationRunnerArguments.class=com.owncloud.android.datamodel.FileDataStorageManagerTest,com.nextcloud.client.FileDisplayActivityIT```
|
||||
- run one test in class: ```./gradlew createGplayDebugCoverageReport -Pcoverage=true
|
||||
-Pandroid.testInstrumentationRunnerArguments.class=com.owncloud.android.datamodel.FileDataStorageManagerTest#saveNewFile```
|
||||
- JaCoCo results are shown as html: firefox ./build/reports/coverage/gplay/debug/index.html
|
||||
|
||||
|
||||
#### UI tests
|
||||
We use [shot](https://github.com/Karumi/Shot) for taking screenshots and compare them
|
||||
- check screenshots: ```./gradlew executeScreenshotTests ```
|
||||
- update/generate new screenshots: ```scripts/updateScreenshots.sh ```
|
||||
- in this script are samples how to only execute a given class/test
|
||||
- this will fire up docker & emulator to ensure that screenshots look the same
|
||||
- creating own UI comparision tests:
|
||||
- add IntentsTestRule for launching activity directly:
|
||||
```java
|
||||
@Rule public IntentsTestRule<SettingsActivity> activityRule = new IntentsTestRule<>(SettingsActivity.class,
|
||||
true,
|
||||
false);
|
||||
```
|
||||
- in test method:
|
||||
```java
|
||||
Activity activity = activityRule.launchActivity(null);
|
||||
…do something, e.g. navigate, create folder, etc. …
|
||||
Screenshot.snapActivity(activity).record();
|
||||
```
|
||||
- best practise is to first create test with emulator too see behaviour and then create screenshots
|
||||
|
||||
## File naming
|
||||
|
||||
The file naming patterns are inspired and based on [Ribot's Android Project And Code Guidelines](https://github.com/ribot/android-guidelines/blob/c1d8c9c904eb31bf01fe24aadb963b74281fe79a/project_and_code_guidelines.md).
|
||||
@@ -310,95 +257,12 @@ Similar to layout files, menu files should match the name of the component. For
|
||||
A good practice is to not include the word `menu` as part of the name because these files are already located in the `menu` directory. In case a component uses several menus in different places (via popup menus) then the resource name would be extended. For example, if the user profile activity has two popup menus for configuring the users settings and one for the handling group assignments then the file names for the menus would be: `activity_user_profile_user_settings.xml` and `activity_user_profile_group_assignments.xml`.
|
||||
|
||||
## Translations
|
||||
|
||||
We manage translations via [Transifex](https://www.transifex.com/nextcloud/nextcloud/android/). So just request joining the translation team for Android on the site and start translating. All translations will then be automatically pushed to this repository, there is no need for any pull request for translations.
|
||||
|
||||
If you need to change a translation, do not change it, but give it new key. This way the translation stays backward compatible as we automatically backport translated strings to last versions.
|
||||
|
||||
When submitting PRs with changed translations, please only submit changes to values/strings.xml and not changes to translated files. These will be overwritten by next merge of transifex-but and increase PR review.
|
||||
|
||||
## Engineering practices
|
||||
|
||||
This section contains some general guideliens for new contributors, based on common issues flagged during code review.
|
||||
|
||||
### Approach to technical debt
|
||||
|
||||
TL;DR Non-Stop Litter Picking Party!
|
||||
|
||||
We recognize the importance of technical debt that can slow down development, make bufixing difficult and
|
||||
discourage future contributors.
|
||||
|
||||
We are mindful of the [Broken Windows Theory](https://en.wikipedia.org/wiki/Broken_windows_theory) and we'd like
|
||||
actively promote and encourage contributors to apply The Scout's Rule: *"Always leave the campground cleaner than
|
||||
you found it"*. Simple, little improvements will sum up and will be very appreciated by Nextcloud team.
|
||||
|
||||
We also promise to actively support and mentor contributors that help us to improve code quality, as we understand
|
||||
that this process is challenging and requires deep understanding of the application codebase.
|
||||
|
||||
### Dependency injection
|
||||
|
||||
TL;DR Avoid calling constructors inside constructors.
|
||||
|
||||
In effort to modernize the codebase we are applying [Dependency Injection](https://en.wikipedia.org/wiki/Dependency_injection)
|
||||
whenever possible. We use 2 approaches: automatic and manual.
|
||||
|
||||
We are using [Dagger 2](https://dagger.dev/) to inject dependencies into major Android components only:
|
||||
|
||||
* `Activity`
|
||||
* `Fragment`
|
||||
* `Service`
|
||||
* `BroadcastReceiver`
|
||||
* `ContentProvider`
|
||||
|
||||
This process is fairly automatic, with `@Inject` annotation being sufficient to supply properly initialized
|
||||
objects. Android lifecycle callbacks allow us to do most of the work without effort.
|
||||
|
||||
For other application sub-components we prefer to use constructor injection and manually provide required dependencies.
|
||||
|
||||
This combination allows us to benefit from automation when it provides most value, does not tie rest of the code
|
||||
to any specific framework and stimulates continuous code modernization through iterative refactoring of all minor
|
||||
elements.
|
||||
|
||||
### Custom platform APIs
|
||||
|
||||
TL;DR Avoid Android platform APIs.
|
||||
|
||||
Nextcloud Android application provides some replacements for native Android APIs to facilitate testing
|
||||
and expose higher-level, business-specific APIs.
|
||||
|
||||
Generally, whenever you need:
|
||||
|
||||
* account management
|
||||
* application preferences
|
||||
* background task scheduling
|
||||
* device hardware information
|
||||
* media playback
|
||||
* networking
|
||||
* logging
|
||||
|
||||
we have something more suitable.
|
||||
|
||||
Our transition to new APIs is a continuous process. Contributors might be asked by code reviewers to
|
||||
refrain from using specific Android APIs considered problematic and to use Nextcloud APIs instead.
|
||||
In extreme cases we might decide to put specific features on hold until we provide platform API
|
||||
replacement.
|
||||
|
||||
If in doubt, ask Nextcloud developers. App undergoes a process of intense refactoring and situation
|
||||
changes frequently.
|
||||
|
||||
### Testing
|
||||
|
||||
TL;DR If we can't write a test for it, it's not good.
|
||||
|
||||
Test automation is challenging in mobile applications in general. We try to improve in this area
|
||||
and thereof we'd ask contributors to be mindful of their code testability:
|
||||
|
||||
1. new code submitted to Nextcloud project should be provided with automatic tests
|
||||
2. contributions to existing code that is currently not covered by automatic tests
|
||||
should at least not make future efforts more challenging
|
||||
3. whenever possible, testability should be improved even if the code is not covered by tests
|
||||
|
||||
|
||||
# Releases
|
||||
At the moment we are releasing the app in two app stores:
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
import com.github.spotbugs.SpotBugsTask
|
||||
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.3.70'
|
||||
ext.kotlin_version = '1.3.61'
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
@@ -20,13 +20,13 @@ buildscript {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.6.1'
|
||||
classpath 'com.android.tools.build:gradle:3.5.3'
|
||||
classpath('com.dicedmelon.gradle:jacoco-android:0.1.4') {
|
||||
exclude group: 'org.codehaus.groovy', module: 'groovy-all'
|
||||
}
|
||||
classpath 'gradle.plugin.com.github.spotbugs:spotbugs-gradle-plugin:1.6.6'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.6.0"
|
||||
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.3.0"
|
||||
classpath "commons-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2
|
||||
classpath 'com.karumi:shot:3.1.0'
|
||||
}
|
||||
@@ -60,8 +60,8 @@ configurations {
|
||||
|
||||
ext {
|
||||
jacocoVersion = "0.8.2"
|
||||
daggerVersion = "2.26"
|
||||
markwonVersion = "4.2.2"
|
||||
daggerVersion = "2.25.4"
|
||||
markwonVersion = "4.2.0"
|
||||
prismVersion = "2.0.0"
|
||||
androidLibraryVersion = "master-SNAPSHOT"
|
||||
|
||||
@@ -91,7 +91,7 @@ def versionBuild = 0 // 0-50=Alpha / 51-98=RC / 90-99=stable
|
||||
for (TaskExecutionRequest tr : getGradle().getStartParameter().getTaskRequests()) {
|
||||
for (String arg : tr.args) {
|
||||
// any gplay, but only exact "build", as e.g. buildGeneric shall not apply gplay.grade
|
||||
if (arg.contains("Gplay") || arg.contains("lint") || arg.contains("executeScreenshot") || arg == "build") {
|
||||
if (arg.contains("Gplay") || arg.contains("lint") || arg == "build") {
|
||||
apply from: 'gplay.gradle'
|
||||
System.console().println("Applying gplay.gradle")
|
||||
break
|
||||
@@ -105,7 +105,7 @@ spotbugs {
|
||||
|
||||
shot {
|
||||
appId = 'com.nextcloud.client'
|
||||
instrumentationTestTask = 'connectedGplayDebugAndroidTest'
|
||||
instrumentationTestTask = 'connectedGenericDebugAndroidTest'
|
||||
}
|
||||
|
||||
android {
|
||||
@@ -129,7 +129,7 @@ android {
|
||||
compileSdkVersion 29
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 17
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 29
|
||||
|
||||
// arguments to be passed to functional tests
|
||||
@@ -158,7 +158,7 @@ android {
|
||||
|
||||
buildTypes {
|
||||
debug {
|
||||
testCoverageEnabled (project.hasProperty('coverage'))
|
||||
testCoverageEnabled true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,8 +177,8 @@ android {
|
||||
versionDev {
|
||||
applicationId "com.nextcloud.android.beta"
|
||||
dimension "default"
|
||||
versionCode 20200129
|
||||
versionName "20200129"
|
||||
versionCode 20200115
|
||||
versionName "20200115"
|
||||
}
|
||||
|
||||
qa {
|
||||
@@ -192,7 +192,6 @@ android {
|
||||
testOptions {
|
||||
unitTests.returnDefaultValues = true
|
||||
execution 'ANDROIDX_TEST_ORCHESTRATOR'
|
||||
animationsDisabled true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -274,10 +273,6 @@ android {
|
||||
dataBinding {
|
||||
enabled true
|
||||
}
|
||||
|
||||
viewBinding {
|
||||
enabled true
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -293,32 +288,32 @@ dependencies {
|
||||
implementation 'org.apache.jackrabbit:jackrabbit-webdav:2.13.1' // remove after entire switch to lib v2
|
||||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||
implementation 'com.google.android.material:material:1.1.0'
|
||||
implementation 'com.google.android.material:material:1.1.0-beta02'
|
||||
implementation 'com.jakewharton:disklrucache:2.0.2'
|
||||
implementation 'androidx.appcompat:appcompat:1.2.0-alpha03'
|
||||
implementation 'androidx.appcompat:appcompat:1.1.0'
|
||||
implementation 'androidx.cardview:cardview:1.0.0'
|
||||
implementation 'androidx.exifinterface:exifinterface:1.1.0'
|
||||
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
|
||||
implementation "androidx.work:work-runtime:2.3.3"
|
||||
implementation "androidx.work:work-runtime-ktx:2.3.3"
|
||||
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0"
|
||||
implementation "androidx.work:work-runtime:2.2.0"
|
||||
implementation "androidx.work:work-runtime-ktx:2.2.0"
|
||||
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.6'
|
||||
implementation 'com.github.tobiaskaminsky:android-job:v1.2.6.1' // 'com.github.evernote:android-job:v1.2.5'
|
||||
implementation 'com.jakewharton:butterknife:10.2.1'
|
||||
kapt 'com.jakewharton:butterknife-compiler:10.2.1'
|
||||
implementation 'org.greenrobot:eventbus:3.2.0'
|
||||
implementation 'org.greenrobot:eventbus:3.1.1'
|
||||
implementation 'com.googlecode.ez-vcard:ez-vcard:0.10.5'
|
||||
implementation 'org.lukhnos:nnio:0.2'
|
||||
implementation 'com.madgag.spongycastle:pkix:1.54.0.0'
|
||||
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.19'
|
||||
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.15'
|
||||
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'
|
||||
kapt 'org.parceler:parceler:1.1.13'
|
||||
implementation 'com.google.android:flexbox:2.0.0'
|
||||
implementation 'org.parceler:parceler-api:1.1.12'
|
||||
kapt 'org.parceler:parceler:1.1.12'
|
||||
implementation('com.github.bumptech.glide:glide:3.8.0') {
|
||||
exclude group: "com.android.support"
|
||||
}
|
||||
@@ -337,6 +332,9 @@ dependencies {
|
||||
kapt "com.google.dagger:dagger-compiler:$daggerVersion"
|
||||
kapt "com.google.dagger:dagger-android-processor:$daggerVersion"
|
||||
|
||||
compileOnly "org.projectlombok:lombok:1.18.10"
|
||||
annotationProcessor "org.projectlombok:lombok:1.18.10"
|
||||
|
||||
ktlint "com.pinterest:ktlint:0.36.0"
|
||||
implementation 'org.conscrypt:conscrypt-android:2.2.1'
|
||||
|
||||
@@ -353,11 +351,11 @@ dependencies {
|
||||
|
||||
// dependencies for local unit tests
|
||||
testImplementation 'junit:junit:4.13'
|
||||
testImplementation 'org.mockito:mockito-core:3.3.1'
|
||||
testImplementation 'org.mockito:mockito-core:3.2.4'
|
||||
testImplementation 'androidx.test:core:1.2.0'
|
||||
testImplementation 'org.powermock:powermock-core:2.0.5'
|
||||
testImplementation 'org.powermock:powermock-module-junit4:2.0.5'
|
||||
testImplementation 'org.powermock:powermock-api-mockito2:2.0.5'
|
||||
testImplementation 'org.powermock:powermock-core:2.0.4'
|
||||
testImplementation 'org.powermock:powermock-module-junit4:2.0.4'
|
||||
testImplementation 'org.powermock:powermock-api-mockito2:2.0.4'
|
||||
testImplementation 'org.json:json:20190722'
|
||||
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
|
||||
testImplementation "androidx.arch.core:core-testing:2.1.0"
|
||||
@@ -373,14 +371,14 @@ dependencies {
|
||||
// Espresso core
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.2.0'
|
||||
androidTestImplementation 'org.mockito:mockito-core:3.3.1'
|
||||
androidTestImplementation 'org.mockito:mockito-core:3.2.4'
|
||||
// UIAutomator - for cross-app UI tests, and to grant screen is turned on in Espresso tests
|
||||
// androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
|
||||
// fix conflict in dependencies; see http://g.co/androidstudio/app-test-app-conflict for details
|
||||
//androidTestImplementation "com.android.support:support-annotations:${supportLibraryVersion}"
|
||||
androidTestImplementation 'tools.fastlane:screengrab:2.0.0'
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
androidTestImplementation('com.android.support.test.espresso:espresso-intents:3.0.2')
|
||||
androidTestCompile('com.android.support.test.espresso:espresso-intents:3.0.2')
|
||||
|
||||
// jacocoAnt "org.jacoco:org.jacoco.ant:${jacocoVersion}"
|
||||
// jacocoAgent "org.jacoco:org.jacoco.agent:${jacocoVersion}"
|
||||
@@ -391,8 +389,6 @@ dependencies {
|
||||
// androidJacocoAnt "org.jacoco:org.jacoco.agent:${jacocoVersion}"
|
||||
|
||||
implementation "com.github.stateless4j:stateless4j:2.6.0"
|
||||
androidTestImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
|
||||
androidTestImplementation "org.mockito:mockito-android:3.3.1"
|
||||
}
|
||||
|
||||
configurations.all {
|
||||
|
||||
@@ -1,3 +1,30 @@
|
||||
autoCorrect: true
|
||||
|
||||
test-pattern: # Configure exclusions for test sources
|
||||
active: true
|
||||
patterns: # Test file regexes
|
||||
- '.*/test/.*'
|
||||
- '.*/androidTest/.*'
|
||||
- '.*Test.kt'
|
||||
- '.*Spec.kt'
|
||||
- '.*Spek.kt'
|
||||
exclude-rule-sets:
|
||||
- 'comments'
|
||||
exclude-rules:
|
||||
- 'NamingRules'
|
||||
- 'WildcardImport'
|
||||
- 'MagicNumber'
|
||||
- 'MaxLineLength'
|
||||
- 'LateinitUsage'
|
||||
- 'StringLiteralDuplication'
|
||||
- 'SpreadOperator'
|
||||
- 'TooManyFunctions'
|
||||
- 'ForEachOnRange'
|
||||
- 'FunctionMaxLength'
|
||||
- 'TooGenericExceptionCaught'
|
||||
- 'TooGenericExceptionThrown'
|
||||
- 'InstanceOfCheckForException'
|
||||
|
||||
build:
|
||||
maxIssues: 10
|
||||
weights:
|
||||
@@ -111,7 +138,7 @@ empty-blocks:
|
||||
active: true
|
||||
EmptyFunctionBlock:
|
||||
active: true
|
||||
ignoreOverridden: false
|
||||
ignoreOverriddenFunctions: false
|
||||
EmptyIfBlock:
|
||||
active: true
|
||||
EmptyInitBlock:
|
||||
@@ -175,18 +202,23 @@ exceptions:
|
||||
formatting:
|
||||
active: true
|
||||
android: false
|
||||
autoCorrect: true
|
||||
ChainWrapping:
|
||||
active: true
|
||||
autoCorrect: true
|
||||
CommentSpacing:
|
||||
active: true
|
||||
autoCorrect: true
|
||||
Filename:
|
||||
active: true
|
||||
FinalNewline:
|
||||
active: true
|
||||
autoCorrect: true
|
||||
ImportOrdering:
|
||||
active: false
|
||||
Indentation:
|
||||
active: true
|
||||
autoCorrect: true
|
||||
indentSize: 4
|
||||
continuationIndentSize: 4
|
||||
MaximumLineLength:
|
||||
@@ -194,49 +226,73 @@ formatting:
|
||||
maxLineLength: 120
|
||||
ModifierOrdering:
|
||||
active: true
|
||||
autoCorrect: true
|
||||
NoBlankLineBeforeRbrace:
|
||||
active: true
|
||||
autoCorrect: true
|
||||
NoConsecutiveBlankLines:
|
||||
active: true
|
||||
autoCorrect: true
|
||||
NoEmptyClassBody:
|
||||
active: true
|
||||
autoCorrect: true
|
||||
NoItParamInMultilineLambda:
|
||||
active: false
|
||||
NoLineBreakAfterElse:
|
||||
active: true
|
||||
autoCorrect: true
|
||||
NoLineBreakBeforeAssignment:
|
||||
active: true
|
||||
autoCorrect: true
|
||||
NoMultipleSpaces:
|
||||
active: true
|
||||
autoCorrect: true
|
||||
NoSemicolons:
|
||||
active: true
|
||||
autoCorrect: true
|
||||
NoTrailingSpaces:
|
||||
active: true
|
||||
autoCorrect: true
|
||||
NoUnitReturn:
|
||||
active: true
|
||||
autoCorrect: true
|
||||
NoUnusedImports:
|
||||
active: true
|
||||
autoCorrect: true
|
||||
NoWildcardImports:
|
||||
active: true
|
||||
autoCorrect: true
|
||||
PackageName:
|
||||
active: true
|
||||
autoCorrect: true
|
||||
ParameterListWrapping:
|
||||
active: true
|
||||
autoCorrect: true
|
||||
indentSize: 4
|
||||
SpacingAroundColon:
|
||||
active: true
|
||||
autoCorrect: true
|
||||
SpacingAroundComma:
|
||||
active: true
|
||||
autoCorrect: true
|
||||
SpacingAroundCurly:
|
||||
active: true
|
||||
autoCorrect: true
|
||||
SpacingAroundKeyword:
|
||||
active: true
|
||||
autoCorrect: true
|
||||
SpacingAroundOperators:
|
||||
active: true
|
||||
autoCorrect: true
|
||||
SpacingAroundParens:
|
||||
active: true
|
||||
autoCorrect: true
|
||||
SpacingAroundRangeOperator:
|
||||
active: true
|
||||
autoCorrect: true
|
||||
StringTemplate:
|
||||
active: true
|
||||
autoCorrect: true
|
||||
|
||||
naming:
|
||||
active: true
|
||||
@@ -265,17 +321,16 @@ naming:
|
||||
functionPattern: '^([a-z$][a-zA-Z$0-9]*)|(`.*`)$'
|
||||
excludeClassPattern: '$^'
|
||||
ignoreOverridden: true
|
||||
excludes: "**/*Test.kt"
|
||||
FunctionParameterNaming:
|
||||
active: true
|
||||
parameterPattern: '[a-z][A-Za-z0-9]*'
|
||||
excludeClassPattern: '$^'
|
||||
ignoreOverridden: true
|
||||
ignoreOverriddenFunctions: true
|
||||
MatchingDeclarationName:
|
||||
active: true
|
||||
MemberNameEqualsClassName:
|
||||
active: false
|
||||
ignoreOverridden: true
|
||||
ignoreOverriddenFunction: true
|
||||
ObjectPropertyNaming:
|
||||
active: true
|
||||
constantPattern: '[A-Za-z][_A-Za-z0-9]*'
|
||||
@@ -387,7 +442,6 @@ style:
|
||||
ignoreAnnotation: false
|
||||
ignoreNamedArgument: true
|
||||
ignoreEnums: false
|
||||
excludes: "**/*Test.kt"
|
||||
MandatoryBracesIfStatements:
|
||||
active: false
|
||||
MaxLineLength:
|
||||
|
||||
@@ -5,3 +5,4 @@ NC_TEST_SERVER_PASSWORD=test
|
||||
android.enableJetifier=true
|
||||
android.useAndroidX=true
|
||||
android.debug.obsoleteApi=true
|
||||
|
||||
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
|
||||
|
Before Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 40 KiB |
|
Before Width: | Height: | Size: 37 KiB |
|
Before Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 9.4 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 41 KiB |
|
Before Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 34 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 17 KiB |
@@ -1 +1 @@
|
||||
385
|
||||
413
|
||||
@@ -1,2 +1,2 @@
|
||||
DO NOT TOUCH; GENERATED BY DRONE
|
||||
<span class="mdl-layout-title">Lint Report: 96 warnings</span>
|
||||
<span class="mdl-layout-title">Lint Report: 76 warnings</span>
|
||||
@@ -1,15 +1,10 @@
|
||||
#!/bin/bash
|
||||
date=$(date +%Y%m%d)
|
||||
oldLibraryCommit=$(grep "androidLibraryVersion\ =" build.gradle)
|
||||
libraryCommit=$(curl https://api.github.com/repos/nextcloud/android-library/commits/master | jq .sha | sed s'/\"//g')
|
||||
|
||||
# use current date for version code/name
|
||||
sed -i "/versionDev/,/\}/ s/versionCode .*/versionCode $date/" build.gradle
|
||||
sed -i "/versionDev/,/\}/ s/versionName .*/versionName \"$date\"/" build.gradle
|
||||
|
||||
# change library
|
||||
sed -i s"#androidLibraryVersion\ =.*#androidLibraryVersion =\"$libraryCommit\"#" build.gradle
|
||||
|
||||
# build signed apk
|
||||
./gradlew assembleVersionDevRelease >> /tmp/dev.log 2>&1
|
||||
|
||||
@@ -38,35 +33,19 @@ mv latest.apk ~/apks/
|
||||
/bin/ls -t ~/apks/*.apk | awk 'NR>6' | xargs rm -f
|
||||
|
||||
lastBuildTime=$(date --date="$(git log -1 --format=%ai $(git tag | grep dev | tail -n1))" +%s)
|
||||
# Show only the commit subject in the changelog and filter out:
|
||||
# * Merges
|
||||
# * Dependabot commits
|
||||
# * Commits touching only non-user-facing stuff like tests
|
||||
# * Version bump commits
|
||||
changelog=$(git log --no-merges --after=$lastBuildTime --invert-grep --author=dependabot --pretty='format:%s' -- ':!src/androidTest' ':!.*' ':!scripts/analysis' | grep -vE '^daily dev [[:digit:]]{8}$')
|
||||
# Make Transifex updates have a nicer description
|
||||
if echo "$changelog" | grep -q 'tx-robot'; then
|
||||
changelog=$(echo "$changelog" | grep -v 'tx-robot')
|
||||
# This is a funky bashism - preceding a single-quote string with $ lets you put escape chars in it
|
||||
changelog="${changelog}"$'\nUpdate translations'
|
||||
fi
|
||||
changelog=$(git log --after=$lastBuildTime --pretty=oneline --abbrev-commit)
|
||||
|
||||
# Check if the library was updated
|
||||
if ! echo $oldLibraryCommit | grep -q $libraryCommit; then
|
||||
changelog="${changelog}"$'\nUpdate Nextcloud Android library'
|
||||
fi
|
||||
|
||||
# Collapse dependency updates into a single "Update dependencies" entry
|
||||
if git log --after=$lastBuildTime --pretty='format:%an' | grep -q dependabot; then
|
||||
changelog="${changelog}"$'\nUpdate 3rd-party dependencies'
|
||||
fi
|
||||
|
||||
# changelog
|
||||
echo "$changelog" > src/versionDev/fastlane/metadata/android/en-US/changelogs/$date.txt
|
||||
echo "library commit: $(curl https://api.github.com/repos/nextcloud/android-library/commits/master | jq .sha | sed s'/\"//g')" >> src/versionDev/fastlane/metadata/android/en-US/changelogs/$date.txt
|
||||
|
||||
git add .
|
||||
git add build.gradle
|
||||
git add src/versionDev/fastlane/metadata/android/en-US/changelogs/$date.txt
|
||||
git commit -m "daily dev $date" -m "$changelog"
|
||||
git push
|
||||
|
||||
git tag dev-$date
|
||||
git push origin dev-$date
|
||||
|
||||
# remove all but the latest 5 tags
|
||||
git tag|grep dev | sort -r | awk 'NR>5' | xargs -n 1 git push --delete origin
|
||||
git tag|grep dev | sort -r | awk 'NR>5' | xargs -n 1 git tag -d
|
||||
@@ -1,13 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
if ( [[ $(grep NC_TEST_SERVER_BASEURL ~/.gradle/gradle.properties | grep -v "#" -c) -gt 0 ]] ); then
|
||||
echo "This will not use server in docker. Please comment in .gradle/gradle.properties. Aborting!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
## emulator
|
||||
if ( [[ ! $(emulator -list-avds | grep uiComparison -c) -eq 0 ]] ); then
|
||||
avdmanager delete avd -n uiComparison
|
||||
if ( [[ $(emulator -list-avds | grep uiComparison -c) -eq 0 ]] ); then
|
||||
(sleep 5; echo "no") | avdmanager create avd -n uiComparison -c 100M -k "system-images;android-27;google_apis;x86" --abi "google_apis/x86"
|
||||
fi
|
||||
|
||||
@@ -15,7 +9,7 @@ emulator -avd uiComparison -no-snapshot -gpu swiftshader_indirect -no-window -no
|
||||
PID=$(echo $!)
|
||||
|
||||
## server
|
||||
docker run --name=uiComparison nextcloudci/server:server-17 1>/dev/null &
|
||||
docker run --name=uiComparison nextcloudci/server:server-3 1>/dev/null &
|
||||
sleep 5
|
||||
IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' uiComparison)
|
||||
|
||||
@@ -28,35 +22,8 @@ fi
|
||||
cp gradle.properties gradle.properties_
|
||||
sed -i s"/server/$IP/" gradle.properties
|
||||
scripts/wait_for_emulator.sh
|
||||
|
||||
# setup test server
|
||||
docker exec uiComparison /bin/sh -c "/usr/local/bin/initnc.sh"
|
||||
docker exec uiComparison /bin/sh -c "su www-data -c \"OC_PASS=user1 php /var/www/html/occ user:add --password-from-env --display-name='User One' user1\""
|
||||
docker exec uiComparison /bin/sh -c "su www-data -c \"OC_PASS=user2 php /var/www/html/occ user:add --password-from-env --display-name='User Two' user2\""
|
||||
docker exec uiComparison /bin/sh -c "su www-data -c \"OC_PASS=user3 php /var/www/html/occ user:add --password-from-env --display-name='User Three' user3\""
|
||||
docker exec uiComparison /bin/sh -c "su www-data -c \"php /var/www/html/occ user:setting user2 files quota 1G\""
|
||||
docker exec uiComparison /bin/sh -c "su www-data -c \"php /var/www/html/occ group:add users\""
|
||||
docker exec uiComparison /bin/sh -c "su www-data -c \"php /var/www/html/occ group:adduser users user1\""
|
||||
docker exec uiComparison /bin/sh -c "su www-data -c \"php /var/www/html/occ group:adduser users user2\""
|
||||
docker exec uiComparison /bin/sh -c "su www-data -c \"git clone -b master https://github.com/nextcloud/text.git /var/www/html/apps/text/\""
|
||||
docker exec uiComparison /bin/sh -c "su www-data -c \"php /var/www/html/occ app:enable text\""
|
||||
docker exec uiComparison /bin/sh -c "/usr/local/bin/run.sh"
|
||||
|
||||
## update/create all screenshots
|
||||
scripts/wait_for_server.sh ${IP}
|
||||
./gradlew executeScreenshotTests -Precord
|
||||
|
||||
## update screenshots in a class
|
||||
#./gradlew executeScreenshotTests \
|
||||
#-Precord \
|
||||
#-Pandroid.testInstrumentationRunnerArguments.class=\
|
||||
#com.owncloud.android.ui.dialog.SyncFileNotEnoughSpaceDialogFragmentTest
|
||||
|
||||
## update single screenshot within a class
|
||||
#./gradlew executeScreenshotTests \
|
||||
#-Precord \
|
||||
#-Pandroid.testInstrumentationRunnerArguments.class=\
|
||||
#com.owncloud.android.ui.dialog.SyncFileNotEnoughSpaceDialogFragmentTest#showNotEnoughSpaceDialogForFile
|
||||
|
||||
mv gradle.properties_ gradle.properties
|
||||
|
||||
# tidy up
|
||||
|
||||
@@ -1,19 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
upload() {
|
||||
cd $1
|
||||
|
||||
find . -type d -exec curl -u $USER:$PASS -X MKCOL $URL/$REMOTE_FOLDER/$(echo {} | sed s#\./##) \;
|
||||
find . -type f -exec curl -u $USER:$PASS -X PUT $URL/$REMOTE_FOLDER/$(echo {} | sed s#\./##) --upload-file {} \;
|
||||
|
||||
echo "Uploaded failing tests to https://www.kaminsky.me/nc-dev/android-integrationTests/$REMOTE_FOLDER"
|
||||
|
||||
curl -u $GITHUB_USER:$GITHUB_PASSWORD -X POST https://api.github.com/repos/nextcloud/android/issues/$PR/comments \
|
||||
-d "{ \"body\" : \"$TYPE test failed: https://www.kaminsky.me/nc-dev/android-integrationTests/$REMOTE_FOLDER \" }"
|
||||
|
||||
exit 1
|
||||
}
|
||||
|
||||
#1: LOG_USERNAME
|
||||
#2: LOG_PASSWORD
|
||||
#3: DRONE_BUILD_NUMBER
|
||||
@@ -27,42 +13,23 @@ ID=$3
|
||||
USER=$1
|
||||
PASS=$2
|
||||
TYPE=$4
|
||||
PR=$5
|
||||
GITHUB_USER=$6
|
||||
GITHUB_PASSWORD=$7
|
||||
REMOTE_FOLDER=$ID-$TYPE
|
||||
FOLDER=$ID-$TYPE
|
||||
|
||||
set -e
|
||||
|
||||
if [ $TYPE = "IT" ]; then
|
||||
FOLDER=build/reports/androidTests/connected/flavors/GPLAY
|
||||
cd build/reports/androidTests/connected/flavors/GPLAY
|
||||
elif [ $TYPE = "Unit" ]; then
|
||||
FOLDER=build/reports/tests/testGplayDebugUnitTest
|
||||
cd build/reports/tests/testGplayDebugUnitTest
|
||||
else
|
||||
FOLDER=build/reports/shot/verification
|
||||
cd build/reports/shot/verification/
|
||||
fi
|
||||
|
||||
if [ -e $FOLDER ]; then
|
||||
upload $FOLDER
|
||||
else
|
||||
echo "$TYPE test failed, but no output was generated. Maybe a preliminary stage failed."
|
||||
find . -type d -exec curl -u $USER:$PASS -X MKCOL $URL/$FOLDER/$(echo {} | sed s#\./##) \;
|
||||
find . -type f -exec curl -u $USER:$PASS -X PUT $URL/$FOLDER/$(echo {} | sed s#\./##) --upload-file {} \;
|
||||
|
||||
curl -u $GITHUB_USER:$GITHUB_PASSWORD \
|
||||
-X POST https://api.github.com/repos/nextcloud/android/issues/$PR/comments \
|
||||
-d "{ \"body\" : \"$TYPE test failed, but no output was generated. Maybe a preliminary stage failed. \" }"
|
||||
echo "Uploaded failing tests to https://www.kaminsky.me/nc-dev/android-integrationTests/$FOLDER"
|
||||
|
||||
if [ -e build/reports/androidTests/connected/flavors/GPLAY ] ; then
|
||||
TYPE="IT"
|
||||
upload "build/reports/androidTests/connected/flavors/GPLAY"
|
||||
fi
|
||||
curl -u $6:$7 -X POST https://api.github.com/repos/nextcloud/android/issues/$5/comments -d "{ \"body\" : \"$TYPE test failed: https://www.kaminsky.me/nc-dev/android-integrationTests/$FOLDER \" }"
|
||||
|
||||
if [ -e build/reports/tests/testGplayDebugUnitTest ] ; then
|
||||
TYPE="Unit"
|
||||
upload "build/reports/tests/testGplayDebugUnitTest"
|
||||
fi
|
||||
|
||||
if [ -e build/reports/shot/verification ] ; then
|
||||
TYPE="Screenshot"
|
||||
upload "build/reports/shot/verification"
|
||||
fi
|
||||
fi
|
||||
exit 1
|
||||
@@ -8,7 +8,7 @@ until [[ $status = "false" ]]; do
|
||||
|
||||
if [[ "$status" =~ "false" || "$status" = "" ]]; then
|
||||
let "counter += 1"
|
||||
if [[ $counter -gt 10 ]]; then
|
||||
if [[ $counter -gt 2 ]]; then
|
||||
echo "Failed to wait for server"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
Before Width: | Height: | Size: 73 KiB |
@@ -1,23 +0,0 @@
|
||||
Java:
|
||||
|
||||
```java
|
||||
private String getAppProcessName() {
|
||||
String processName = "";
|
||||
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
|
||||
ActivityManager manager = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
final int ownPid = android.os.Process.myPid();
|
||||
final List<ActivityManager.RunningAppProcessInfo> processes = manager.getRunningAppProcesses();
|
||||
if (processes != null) {
|
||||
for (ActivityManager.RunningAppProcessInfo info : processes) {
|
||||
if (info.pid == ownPid) {
|
||||
processName = info.processName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
processName = Application.getProcessName();
|
||||
}
|
||||
return processName;
|
||||
}
|
||||
```
|
||||
@@ -1,50 +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.Manifest;
|
||||
|
||||
import com.owncloud.android.AbstractIT;
|
||||
import com.owncloud.android.ui.activities.ActivitiesActivity;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule;
|
||||
import androidx.test.rule.GrantPermissionRule;
|
||||
|
||||
|
||||
public class ActivitiesActivityIT extends AbstractIT {
|
||||
@Rule public IntentsTestRule<ActivitiesActivity> activityRule = new IntentsTestRule<>(ActivitiesActivity.class,
|
||||
true,
|
||||
false);
|
||||
|
||||
@Rule
|
||||
public final GrantPermissionRule permissionRule = GrantPermissionRule.grant(
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
|
||||
@Test
|
||||
public void openDrawer() throws InterruptedException {
|
||||
super.openDrawer(activityRule);
|
||||
}
|
||||
}
|
||||
@@ -28,33 +28,18 @@ import android.app.Activity;
|
||||
import com.facebook.testing.screenshot.Screenshot;
|
||||
import com.owncloud.android.AbstractIT;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.lib.resources.files.CreateFolderRemoteOperation;
|
||||
import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation;
|
||||
import com.owncloud.android.lib.resources.files.SearchRemoteOperation;
|
||||
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.ui.activity.FileDisplayActivity;
|
||||
import com.owncloud.android.ui.events.SearchEvent;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import androidx.test.espresso.contrib.DrawerActions;
|
||||
import androidx.test.espresso.contrib.NavigationViewActions;
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule;
|
||||
import androidx.test.rule.GrantPermissionRule;
|
||||
|
||||
import static androidx.test.espresso.Espresso.onView;
|
||||
import static androidx.test.espresso.action.ViewActions.click;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withId;
|
||||
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
|
||||
|
||||
public class FileDisplayActivityIT extends AbstractIT {
|
||||
@@ -84,53 +69,6 @@ public class FileDisplayActivityIT extends AbstractIT {
|
||||
Screenshot.snapActivity(sut).record();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void showShares() {
|
||||
assertTrue(new ExistenceCheckRemoteOperation("/shareToAdmin/", true).execute(client).isSuccess());
|
||||
assertTrue(new CreateFolderRemoteOperation("/shareToAdmin/", true).execute(client).isSuccess());
|
||||
assertTrue(new CreateFolderRemoteOperation("/shareToGroup/", true).execute(client).isSuccess());
|
||||
assertTrue(new CreateFolderRemoteOperation("/shareViaLink/", true).execute(client).isSuccess());
|
||||
assertTrue(new CreateFolderRemoteOperation("/noShare/", true).execute(client).isSuccess());
|
||||
|
||||
// share folder to user "admin"
|
||||
assertTrue(new CreateShareRemoteOperation("/shareToAdmin/",
|
||||
ShareType.USER,
|
||||
"admin",
|
||||
false,
|
||||
"",
|
||||
OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER)
|
||||
.execute(client).isSuccess());
|
||||
|
||||
// share folder via public link
|
||||
assertTrue(new CreateShareRemoteOperation("/shareViaLink/",
|
||||
ShareType.PUBLIC_LINK,
|
||||
"",
|
||||
true,
|
||||
"",
|
||||
OCShare.READ_PERMISSION_FLAG)
|
||||
.execute(client).isSuccess());
|
||||
|
||||
// share folder to group
|
||||
Assert.assertTrue(new CreateShareRemoteOperation("/shareToGroup/",
|
||||
ShareType.GROUP,
|
||||
"users",
|
||||
false,
|
||||
"",
|
||||
OCShare.DEFAULT_PERMISSION)
|
||||
.execute(client).isSuccess());
|
||||
|
||||
Activity sut = activityRule.launchActivity(null);
|
||||
|
||||
getInstrumentation().waitForIdleSync();
|
||||
|
||||
EventBus.getDefault().post(new SearchEvent("",
|
||||
SearchRemoteOperation.SearchType.SHARED_FILTER));
|
||||
|
||||
getInstrumentation().waitForIdleSync();
|
||||
|
||||
Screenshot.snapActivity(sut).record();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void showAccounts() {
|
||||
Activity sut = activityRule.launchActivity(null);
|
||||
@@ -140,35 +78,4 @@ public class FileDisplayActivityIT extends AbstractIT {
|
||||
|
||||
Screenshot.snapActivity(sut).record();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allFiles() throws InterruptedException {
|
||||
// ActivityScenario<FileDisplayActivity> sut = ActivityScenario.launch(FileDisplayActivity.class);
|
||||
FileDisplayActivity sut = activityRule.launchActivity(null);
|
||||
|
||||
// given test folder
|
||||
assertTrue(new CreateFolderOperation("/test/", true).execute(client, getStorageManager()).isSuccess());
|
||||
|
||||
// navigate into it
|
||||
// sut.onActivity(activity -> activity.onBrowsedDownTo(getStorageManager().getFileByPath("/test/")));
|
||||
//sut.onBrowsedDownTo(getStorageManager().getFileByPath("/test/"));
|
||||
OCFile test = getStorageManager().getFileByPath("/test/");
|
||||
sut.setFile(test);
|
||||
sut.startSyncFolderOperation(test, false);
|
||||
|
||||
assertEquals(getStorageManager().getFileByPath("/test/"), sut.getCurrentDir());
|
||||
|
||||
// open drawer
|
||||
onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());
|
||||
|
||||
// click "all files"
|
||||
onView(withId(R.id.nav_view))
|
||||
.perform(NavigationViewActions.navigateTo(R.id.nav_all_files));
|
||||
|
||||
// then should be in root again
|
||||
Thread.sleep(2000);
|
||||
assertEquals(getStorageManager().getFileByPath("/"), sut.getCurrentDir());
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,50 +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.Manifest;
|
||||
|
||||
import com.owncloud.android.AbstractIT;
|
||||
import com.owncloud.android.ui.activity.NotificationsActivity;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule;
|
||||
import androidx.test.rule.GrantPermissionRule;
|
||||
|
||||
|
||||
public class NotificationsActivityIT extends AbstractIT {
|
||||
@Rule public IntentsTestRule<NotificationsActivity> activityRule = new IntentsTestRule<>(NotificationsActivity.class,
|
||||
true,
|
||||
false);
|
||||
|
||||
@Rule
|
||||
public final GrantPermissionRule permissionRule = GrantPermissionRule.grant(
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
|
||||
@Test
|
||||
public void openDrawer() throws InterruptedException {
|
||||
super.openDrawer(activityRule);
|
||||
}
|
||||
}
|
||||
@@ -1,50 +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.Manifest;
|
||||
|
||||
import com.owncloud.android.AbstractIT;
|
||||
import com.owncloud.android.ui.activity.SyncedFoldersActivity;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule;
|
||||
import androidx.test.rule.GrantPermissionRule;
|
||||
|
||||
|
||||
public class SyncedFoldersActivityIT extends AbstractIT {
|
||||
@Rule public IntentsTestRule<SyncedFoldersActivity> activityRule = new IntentsTestRule<>(SyncedFoldersActivity.class,
|
||||
true,
|
||||
false);
|
||||
|
||||
@Rule
|
||||
public final GrantPermissionRule permissionRule = GrantPermissionRule.grant(
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
|
||||
@Test
|
||||
public void openDrawer() throws InterruptedException {
|
||||
super.openDrawer(activityRule);
|
||||
}
|
||||
}
|
||||
@@ -1,50 +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.Manifest;
|
||||
|
||||
import com.owncloud.android.AbstractIT;
|
||||
import com.owncloud.android.ui.activity.UploadListActivity;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule;
|
||||
import androidx.test.rule.GrantPermissionRule;
|
||||
|
||||
|
||||
public class UploadListActivityActivityIT extends AbstractIT {
|
||||
@Rule public IntentsTestRule<UploadListActivity> activityRule = new IntentsTestRule<>(UploadListActivity.class,
|
||||
true,
|
||||
false);
|
||||
|
||||
@Rule
|
||||
public final GrantPermissionRule permissionRule = GrantPermissionRule.grant(
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
|
||||
@Test
|
||||
public void openDrawer() throws InterruptedException {
|
||||
super.openDrawer(activityRule);
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Chris Narkiewicz <[email protected]>
|
||||
* Copyright (C) 2020 Chris Narkiewicz
|
||||
* 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.account
|
||||
|
||||
import android.os.Parcel
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class AnonymousUserTest {
|
||||
@Test
|
||||
fun anonymousUserImplementsParcelable() {
|
||||
// GIVEN
|
||||
// anonymous user instance
|
||||
val original = AnonymousUser("test_account")
|
||||
|
||||
// WHEN
|
||||
// instance is serialized into Parcel
|
||||
// instance is retrieved from Parcel
|
||||
val parcel = Parcel.obtain()
|
||||
parcel.setDataPosition(0)
|
||||
parcel.writeParcelable(original, 0)
|
||||
parcel.setDataPosition(0)
|
||||
val retrieved = parcel.readParcelable<User>(User::class.java.classLoader)
|
||||
|
||||
// THEN
|
||||
// retrieved instance in distinct
|
||||
// instances are equal
|
||||
Assert.assertNotSame(original, retrieved)
|
||||
Assert.assertTrue(retrieved is AnonymousUser)
|
||||
Assert.assertEquals(original, retrieved)
|
||||
}
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Chris Narkiewicz <[email protected]>
|
||||
* Copyright (C) 2020 Chris Narkiewicz
|
||||
* 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.account
|
||||
|
||||
import android.accounts.Account
|
||||
import android.net.Uri
|
||||
import android.os.Parcel
|
||||
import com.owncloud.android.lib.common.OwnCloudAccount
|
||||
import com.owncloud.android.lib.common.OwnCloudBasicCredentials
|
||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNotSame
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import java.net.URI
|
||||
|
||||
class RegisteredUserTest {
|
||||
|
||||
private companion object {
|
||||
fun buildTestUser(accountName: String): RegisteredUser {
|
||||
val uri = Uri.parse("https://nextcloud.localhost.localdomain")
|
||||
val credentials = OwnCloudBasicCredentials("user", "pass")
|
||||
val account = Account(accountName, "test-type")
|
||||
val ownCloudAccount = OwnCloudAccount(uri, credentials)
|
||||
val server = Server(
|
||||
uri = URI(uri.toString()),
|
||||
version = OwnCloudVersion.nextcloud_17
|
||||
)
|
||||
return RegisteredUser(
|
||||
account = account,
|
||||
ownCloudAccount = ownCloudAccount,
|
||||
server = server
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private lateinit var user: RegisteredUser
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
user = buildTestUser("[email protected]")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun registeredUserImplementsParcelable() {
|
||||
// GIVEN
|
||||
// registered user instance
|
||||
|
||||
// WHEN
|
||||
// instance is serialized into Parcel
|
||||
// instance is retrieved from Parcel
|
||||
val parcel = Parcel.obtain()
|
||||
parcel.setDataPosition(0)
|
||||
parcel.writeParcelable(user, 0)
|
||||
parcel.setDataPosition(0)
|
||||
val deserialized = parcel.readParcelable<User>(User::class.java.classLoader)
|
||||
|
||||
// THEN
|
||||
// retrieved instance in distinct
|
||||
// instances are equal
|
||||
assertNotSame(user, deserialized)
|
||||
assertTrue(deserialized is RegisteredUser)
|
||||
assertEquals(user, deserialized)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun accountNamesEquality() {
|
||||
// GIVEN
|
||||
// registered user instance with lower-case account name
|
||||
// registered user instance with mixed-case account name
|
||||
val user1 = buildTestUser("account_name")
|
||||
val user2 = buildTestUser("Account_Name")
|
||||
|
||||
// WHEN
|
||||
// account names are checked for equality
|
||||
val equal = user1.nameEquals(user2)
|
||||
|
||||
// THEN
|
||||
// account names are equal
|
||||
assertTrue(equal)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun accountNamesEqualityCheckIsNullSafe() {
|
||||
// GIVEN
|
||||
// registered user instance with lower-case account name
|
||||
// null account
|
||||
val user1 = buildTestUser("account_name")
|
||||
val user2: User? = null
|
||||
|
||||
// WHEN
|
||||
// account names are checked for equality against null
|
||||
val equal = user1.nameEquals(user2)
|
||||
|
||||
// THEN
|
||||
// account names are not equal
|
||||
assertFalse(equal)
|
||||
}
|
||||
}
|
||||
@@ -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.nextcloud.client.etm
|
||||
|
||||
import android.app.Activity
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule
|
||||
import androidx.test.internal.runner.junit4.statement.UiThreadStatement
|
||||
import com.facebook.testing.screenshot.Screenshot
|
||||
import com.owncloud.android.AbstractIT
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
||||
class EtmActivityTest : AbstractIT() {
|
||||
@get:Rule
|
||||
var activityRule = IntentsTestRule(EtmActivity::class.java, true, false)
|
||||
|
||||
@Test
|
||||
fun overview() {
|
||||
val sut: Activity = activityRule.launchActivity(null)
|
||||
|
||||
waitForIdleSync()
|
||||
|
||||
Screenshot.snapActivity(sut).record()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun preferences() {
|
||||
val sut: EtmActivity = activityRule.launchActivity(null)
|
||||
|
||||
UiThreadStatement.runOnUiThread { sut.vm.onPageSelected(0) }
|
||||
|
||||
Screenshot.snapActivity(sut).record()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun accounts() {
|
||||
val sut: EtmActivity = activityRule.launchActivity(null)
|
||||
|
||||
UiThreadStatement.runOnUiThread { sut.vm.onPageSelected(1) }
|
||||
|
||||
Screenshot.snapActivity(sut).record()
|
||||
}
|
||||
}
|
||||
@@ -1,288 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Chris Narkiewicz
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.nextcloud.client.migrations
|
||||
|
||||
import androidx.test.annotation.UiThreadTest
|
||||
import com.nextcloud.client.account.UserAccountManager
|
||||
import com.nextcloud.client.appinfo.AppInfo
|
||||
import com.nextcloud.client.core.ManualAsyncRunner
|
||||
import com.nhaarman.mockitokotlin2.mock
|
||||
import com.nhaarman.mockitokotlin2.never
|
||||
import com.nhaarman.mockitokotlin2.verify
|
||||
import com.nhaarman.mockitokotlin2.whenever
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.Mock
|
||||
import org.mockito.MockitoAnnotations
|
||||
import java.lang.RuntimeException
|
||||
import java.util.LinkedHashSet
|
||||
|
||||
class MigrationsManagerTest {
|
||||
|
||||
companion object {
|
||||
const val OLD_APP_VERSION = 41
|
||||
const val NEW_APP_VERSION = 42
|
||||
}
|
||||
|
||||
lateinit var migrations: List<Migrations.Step>
|
||||
|
||||
@Mock
|
||||
lateinit var appInfo: AppInfo
|
||||
|
||||
lateinit var migrationsDb: MockSharedPreferences
|
||||
|
||||
@Mock
|
||||
lateinit var userAccountManager: UserAccountManager
|
||||
|
||||
lateinit var asyncRunner: ManualAsyncRunner
|
||||
|
||||
internal lateinit var migrationsManager: MigrationsManagerImpl
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
val migrationStep1: Runnable = mock()
|
||||
val migrationStep2: Runnable = mock()
|
||||
val migrationStep3: Runnable = mock()
|
||||
migrations = listOf(
|
||||
Migrations.Step(0, "first migration", migrationStep1, true),
|
||||
Migrations.Step(1, "second migration", migrationStep2, true),
|
||||
Migrations.Step(2, "third optional migration", migrationStep3, false)
|
||||
)
|
||||
asyncRunner = ManualAsyncRunner()
|
||||
migrationsDb = MockSharedPreferences()
|
||||
whenever(appInfo.versionCode).thenReturn(NEW_APP_VERSION)
|
||||
migrationsManager = MigrationsManagerImpl(
|
||||
appInfo = appInfo,
|
||||
migrationsDb = migrationsDb,
|
||||
asyncRunner = asyncRunner,
|
||||
migrations = migrations
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun inital_status_is_unknown() {
|
||||
// GIVEN
|
||||
// migration manager has not been used yets
|
||||
|
||||
// THEN
|
||||
// status is not set
|
||||
assertEquals(MigrationsManager.Status.UNKNOWN, migrationsManager.status.value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun applied_migrations_are_returned_in_order() {
|
||||
// GIVEN
|
||||
// some migrations are marked as applied
|
||||
// migration ids are stored in random order
|
||||
val storedMigrationIds = LinkedHashSet<String>()
|
||||
storedMigrationIds.apply {
|
||||
add("3")
|
||||
add("0")
|
||||
add("2")
|
||||
add("1")
|
||||
}
|
||||
migrationsDb.store.put(MigrationsManagerImpl.DB_KEY_APPLIED_MIGRATIONS, storedMigrationIds)
|
||||
|
||||
// WHEN
|
||||
// applied migration ids are retrieved
|
||||
val ids = migrationsManager.getAppliedMigrations()
|
||||
|
||||
// THEN
|
||||
// returned list is sorted
|
||||
assertEquals(ids, ids.sorted())
|
||||
}
|
||||
|
||||
@Test
|
||||
@Suppress("MagicNumber")
|
||||
fun registering_new_applied_migration_preserves_old_ids() {
|
||||
// WHEN
|
||||
// some applied migrations are registered
|
||||
val appliedMigrationIds = setOf("0", "1", "2")
|
||||
migrationsDb.store.put(MigrationsManagerImpl.DB_KEY_APPLIED_MIGRATIONS, appliedMigrationIds)
|
||||
|
||||
// WHEN
|
||||
// new set of migration ids are registered
|
||||
// some ids are added again
|
||||
migrationsManager.addAppliedMigration(2, 3, 4)
|
||||
|
||||
// THEN
|
||||
// new ids are appended to set of existing ids
|
||||
val expectedIds = setOf("0", "1", "2", "3", "4")
|
||||
assertEquals(expectedIds, migrationsDb.store.get(MigrationsManagerImpl.DB_KEY_APPLIED_MIGRATIONS))
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
fun migrations_are_scheduled_on_background_thread() {
|
||||
// GIVEN
|
||||
// migrations can be applied
|
||||
assertEquals(0, migrationsManager.getAppliedMigrations().size)
|
||||
|
||||
// WHEN
|
||||
// migration is started
|
||||
val count = migrationsManager.startMigration()
|
||||
|
||||
// THEN
|
||||
// all migrations are scheduled on background thread
|
||||
// single task is scheduled
|
||||
assertEquals(migrations.size, count)
|
||||
assertEquals(1, asyncRunner.size)
|
||||
assertEquals(MigrationsManager.Status.RUNNING, migrationsManager.status.value)
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
fun applied_migrations_are_recorded() {
|
||||
// GIVEN
|
||||
// no migrations are applied yet
|
||||
// current app version is newer then last recorded migrated version
|
||||
whenever(appInfo.versionCode).thenReturn(NEW_APP_VERSION)
|
||||
migrationsDb.store.put(MigrationsManagerImpl.DB_KEY_LAST_MIGRATED_VERSION, OLD_APP_VERSION)
|
||||
|
||||
// WHEN
|
||||
// migration is run
|
||||
whenever(userAccountManager.migrateUserId()).thenReturn(true)
|
||||
val count = migrationsManager.startMigration()
|
||||
assertTrue(asyncRunner.runOne())
|
||||
|
||||
// THEN
|
||||
// total migrations count is returned
|
||||
// migration functions are called
|
||||
// applied migrations are recorded
|
||||
// new app version code is recorded
|
||||
assertEquals(migrations.size, count)
|
||||
val allAppliedIds = migrations.map { it.id.toString() }.toSet()
|
||||
assertEquals(allAppliedIds, migrationsDb.store.get(MigrationsManagerImpl.DB_KEY_APPLIED_MIGRATIONS))
|
||||
assertEquals(NEW_APP_VERSION, migrationsDb.store.get(MigrationsManagerImpl.DB_KEY_LAST_MIGRATED_VERSION))
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
fun migration_error_is_recorded() {
|
||||
// GIVEN
|
||||
// no migrations applied yet
|
||||
|
||||
// WHEN
|
||||
// migrations are applied
|
||||
// one migration throws
|
||||
val lastMigration = migrations.findLast { it.mandatory } ?: throw IllegalStateException("Test fixture error")
|
||||
val errorMessage = "error message"
|
||||
whenever(lastMigration.function.run()).thenThrow(RuntimeException(errorMessage))
|
||||
migrationsManager.startMigration()
|
||||
assertTrue(asyncRunner.runOne())
|
||||
|
||||
// THEN
|
||||
// failure is marked in the migration db
|
||||
// failure message is recorded
|
||||
// failed migration id is recorded
|
||||
assertEquals(MigrationsManager.Status.FAILED, migrationsManager.status.value)
|
||||
assertTrue(migrationsDb.getBoolean(MigrationsManagerImpl.DB_KEY_FAILED, false))
|
||||
assertEquals(
|
||||
errorMessage,
|
||||
migrationsDb.getString(MigrationsManagerImpl.DB_KEY_FAILED_MIGRATION_ERROR_MESSAGE, "")
|
||||
)
|
||||
assertEquals(
|
||||
lastMigration.id,
|
||||
migrationsDb.getInt(MigrationsManagerImpl.DB_KEY_FAILED_MIGRATION_ID, -1)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
fun migrations_are_not_run_if_already_run_for_an_app_version() {
|
||||
// GIVEN
|
||||
// migrations were already run for the current app version
|
||||
whenever(appInfo.versionCode).thenReturn(NEW_APP_VERSION)
|
||||
migrationsDb.store.put(MigrationsManagerImpl.DB_KEY_LAST_MIGRATED_VERSION, NEW_APP_VERSION)
|
||||
|
||||
// WHEN
|
||||
// app is migrated again
|
||||
val migrationCount = migrationsManager.startMigration()
|
||||
|
||||
// THEN
|
||||
// migration processing is skipped entirely
|
||||
// status is set to applied
|
||||
assertEquals(0, migrationCount)
|
||||
migrations.forEach {
|
||||
verify(it.function, never()).run()
|
||||
}
|
||||
assertEquals(MigrationsManager.Status.APPLIED, migrationsManager.status.value)
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
fun new_app_version_is_marked_as_migrated_if_no_new_migrations_are_available() {
|
||||
// GIVEN
|
||||
// migrations were applied in previous version
|
||||
// new version has no new migrations
|
||||
whenever(appInfo.versionCode).thenReturn(NEW_APP_VERSION)
|
||||
migrationsDb.store.put(MigrationsManagerImpl.DB_KEY_LAST_MIGRATED_VERSION, OLD_APP_VERSION)
|
||||
val applied = migrations.map { it.id.toString() }.toSet()
|
||||
migrationsDb.store.put(MigrationsManagerImpl.DB_KEY_APPLIED_MIGRATIONS, applied)
|
||||
|
||||
// WHEN
|
||||
// migration is started
|
||||
val startedCount = migrationsManager.startMigration()
|
||||
|
||||
// THEN
|
||||
// no new migrations are run
|
||||
// new version is marked as migrated
|
||||
assertEquals(0, startedCount)
|
||||
assertEquals(
|
||||
NEW_APP_VERSION,
|
||||
migrationsDb.getInt(MigrationsManagerImpl.DB_KEY_LAST_MIGRATED_VERSION, -1)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
fun optional_migration_failure_does_not_trigger_a_migration_failure() {
|
||||
// GIVEN
|
||||
// pending migrations
|
||||
// mandatory migrations are passing
|
||||
// one migration is optional and fails
|
||||
val optionalFailingMigration = migrations.first { !it.mandatory }
|
||||
whenever(optionalFailingMigration.function.run()).thenThrow(RuntimeException())
|
||||
|
||||
// WHEN
|
||||
// migration is started
|
||||
val startedCount = migrationsManager.startMigration()
|
||||
asyncRunner.runOne()
|
||||
assertEquals(migrations.size, startedCount)
|
||||
|
||||
// THEN
|
||||
// mandatory migrations are marked as applied
|
||||
// optional failed migration is not marked
|
||||
// no error
|
||||
// status is applied
|
||||
// failed migration is available during next migration
|
||||
val appliedMigrations = migrations.filter { it.mandatory }
|
||||
.map { it.id.toString() }
|
||||
.toSet()
|
||||
assertTrue("Fixture error", appliedMigrations.isNotEmpty())
|
||||
assertEquals(appliedMigrations, migrationsDb.store.get(MigrationsManagerImpl.DB_KEY_APPLIED_MIGRATIONS))
|
||||
assertFalse(migrationsDb.getBoolean(MigrationsManagerImpl.DB_KEY_FAILED, false))
|
||||
assertEquals(MigrationsManager.Status.APPLIED, migrationsManager.status.value)
|
||||
}
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Chris Narkiewicz
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.nextcloud.client.migrations
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import java.lang.UnsupportedOperationException
|
||||
import java.util.TreeMap
|
||||
|
||||
@Suppress("TooManyFunctions")
|
||||
class MockSharedPreferences : SharedPreferences {
|
||||
|
||||
class MockEditor(val store: MutableMap<String?, Any?>) : SharedPreferences.Editor {
|
||||
|
||||
val editorStore: MutableMap<String?, Any?> = TreeMap()
|
||||
|
||||
override fun clear(): SharedPreferences.Editor = throw UnsupportedOperationException()
|
||||
|
||||
override fun putLong(key: String?, value: Long): SharedPreferences.Editor =
|
||||
throw UnsupportedOperationException()
|
||||
|
||||
override fun putInt(key: String?, value: Int): SharedPreferences.Editor {
|
||||
editorStore.put(key, value)
|
||||
return this
|
||||
}
|
||||
|
||||
override fun remove(key: String?): SharedPreferences.Editor = throw UnsupportedOperationException()
|
||||
|
||||
override fun putBoolean(key: String?, value: Boolean): SharedPreferences.Editor {
|
||||
editorStore.put(key, value)
|
||||
return this
|
||||
}
|
||||
|
||||
override fun putStringSet(key: String?, values: MutableSet<String>?): SharedPreferences.Editor {
|
||||
editorStore.put(key, values?.toMutableSet())
|
||||
return this
|
||||
}
|
||||
|
||||
override fun commit(): Boolean = true
|
||||
|
||||
override fun putFloat(key: String?, value: Float): SharedPreferences.Editor =
|
||||
throw UnsupportedOperationException()
|
||||
|
||||
override fun apply() = store.putAll(editorStore)
|
||||
|
||||
override fun putString(key: String?, value: String?): SharedPreferences.Editor {
|
||||
editorStore.put(key, value)
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
val store: MutableMap<String?, Any?> = TreeMap()
|
||||
|
||||
override fun contains(key: String?): Boolean = store.containsKey(key)
|
||||
override fun getBoolean(key: String?, defValue: Boolean): Boolean = store.getOrDefault(key, defValue) as Boolean
|
||||
|
||||
override fun unregisterOnSharedPreferenceChangeListener(
|
||||
listener: SharedPreferences.OnSharedPreferenceChangeListener?
|
||||
) = throw UnsupportedOperationException()
|
||||
|
||||
override fun getInt(key: String?, defValue: Int): Int = store.getOrDefault(key, defValue) as Int
|
||||
|
||||
override fun getAll(): MutableMap<String, *> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun edit(): SharedPreferences.Editor {
|
||||
return MockEditor(store)
|
||||
}
|
||||
|
||||
override fun getLong(key: String?, defValue: Long): Long {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun getFloat(key: String?, defValue: Float): Float {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun getStringSet(key: String?, defValues: MutableSet<String>?): MutableSet<String>? {
|
||||
return store.getOrDefault(key, defValues) as MutableSet<String>?
|
||||
}
|
||||
|
||||
override fun registerOnSharedPreferenceChangeListener(
|
||||
listener: SharedPreferences.OnSharedPreferenceChangeListener?
|
||||
) = throw UnsupportedOperationException()
|
||||
|
||||
override fun getString(key: String?, defValue: String?): String? = store.getOrDefault(key, defValue) as String?
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Chris Narkiewicz
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.nextcloud.client.migrations
|
||||
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNotSame
|
||||
import org.junit.Assert.assertTrue
|
||||
|
||||
@Suppress("MagicNumber")
|
||||
class MockSharedPreferencesTest {
|
||||
|
||||
private lateinit var mock: MockSharedPreferences
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
mock = MockSharedPreferences()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getSetStringSet() {
|
||||
val value = setOf("alpha", "bravo", "charlie")
|
||||
mock.edit().putStringSet("key", value).apply()
|
||||
val copy = mock.getStringSet("key", mutableSetOf())
|
||||
assertNotSame(value, copy)
|
||||
assertEquals(value, copy)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getSetInt() {
|
||||
val value = 42
|
||||
val editor = mock.edit()
|
||||
editor.putInt("key", value)
|
||||
assertEquals(100, mock.getInt("key", 100))
|
||||
editor.apply()
|
||||
assertEquals(42, mock.getInt("key", 100))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getSetBoolean() {
|
||||
val value = true
|
||||
val editor = mock.edit()
|
||||
editor.putBoolean("key", value)
|
||||
assertFalse(mock.getBoolean("key", false))
|
||||
editor.apply()
|
||||
assertTrue(mock.getBoolean("key", false))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getSetString() {
|
||||
val value = "a value"
|
||||
val editor = mock.edit()
|
||||
editor.putString("key", value)
|
||||
assertEquals("default", mock.getString("key", "default"))
|
||||
editor.apply()
|
||||
assertEquals("a value", mock.getString("key", "default"))
|
||||
}
|
||||
}
|
||||
@@ -4,29 +4,21 @@ import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.accounts.AuthenticatorException;
|
||||
import android.accounts.OperationCanceledException;
|
||||
import android.app.Activity;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.facebook.testing.screenshot.Screenshot;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.account.UserAccountManagerImpl;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.OwnCloudClientFactory;
|
||||
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.resources.files.ReadFolderRemoteOperation;
|
||||
import com.owncloud.android.lib.resources.files.RemoveFileRemoteOperation;
|
||||
import com.owncloud.android.lib.resources.files.model.RemoteFile;
|
||||
import com.owncloud.android.utils.FileStorageUtils;
|
||||
|
||||
import org.apache.commons.httpclient.HttpStatus;
|
||||
import org.apache.commons.httpclient.methods.GetMethod;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -34,20 +26,9 @@ import org.junit.runner.RunWith;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collection;
|
||||
|
||||
import androidx.test.espresso.contrib.DrawerActions;
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
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 org.junit.Assert.assertTrue;
|
||||
|
||||
|
||||
/**
|
||||
@@ -58,11 +39,9 @@ import static org.junit.Assert.assertTrue;
|
||||
public abstract class AbstractIT {
|
||||
|
||||
protected static OwnCloudClient client;
|
||||
protected static Account account;
|
||||
static Account account;
|
||||
protected static Context targetContext;
|
||||
|
||||
private Activity currentActivity;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeAll() {
|
||||
try {
|
||||
@@ -108,23 +87,7 @@ public abstract class AbstractIT {
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
RemoteOperationResult result = new ReadFolderRemoteOperation("/").execute(client);
|
||||
assertTrue(result.getLogMessage(), result.isSuccess());
|
||||
|
||||
for (Object object : result.getData()) {
|
||||
RemoteFile remoteFile = (RemoteFile) object;
|
||||
|
||||
if (!remoteFile.getRemotePath().equals("/")) {
|
||||
assertTrue(new RemoveFileRemoteOperation(remoteFile.getRemotePath())
|
||||
.execute(client).isSuccess());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected FileDataStorageManager getStorageManager() {
|
||||
FileDataStorageManager getStorageManager() {
|
||||
return new FileDataStorageManager(account, targetContext.getContentResolver());
|
||||
}
|
||||
|
||||
@@ -170,42 +133,4 @@ public abstract class AbstractIT {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected File getFile(String filename) throws IOException {
|
||||
InputStream inputStream = getInstrumentation().getContext().getAssets().open(filename);
|
||||
File temp = File.createTempFile("file", "file");
|
||||
FileUtils.copyInputStreamToFile(inputStream, temp);
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
protected void waitForIdleSync() {
|
||||
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
|
||||
}
|
||||
|
||||
protected void openDrawer(IntentsTestRule activityRule) throws InterruptedException {
|
||||
Activity sut = activityRule.launchActivity(null);
|
||||
|
||||
Thread.sleep(3000);
|
||||
|
||||
onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());
|
||||
|
||||
waitForIdleSync();
|
||||
|
||||
Screenshot.snapActivity(sut).record();
|
||||
}
|
||||
|
||||
protected Activity getCurrentActivity() {
|
||||
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
|
||||
Collection<Activity> resumedActivities = ActivityLifecycleMonitorRegistry
|
||||
.getInstance()
|
||||
.getActivitiesInStage(Stage.RESUMED);
|
||||
|
||||
if (resumedActivities.iterator().hasNext()) {
|
||||
currentActivity = resumedActivities.iterator().next();
|
||||
}
|
||||
});
|
||||
|
||||
return currentActivity;
|
||||
}
|
||||
}
|
||||
@@ -120,7 +120,7 @@ public class UploadIT extends AbstractIT {
|
||||
account,
|
||||
null,
|
||||
ocUpload,
|
||||
FileUploader.NameCollisionPolicy.DEFAULT,
|
||||
false,
|
||||
FileUploader.LOCAL_BEHAVIOUR_COPY,
|
||||
targetContext,
|
||||
false,
|
||||
@@ -140,17 +140,17 @@ public class UploadIT extends AbstractIT {
|
||||
OCUpload ocUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/empty.txt",
|
||||
"/testUpload/2/3/4/1.txt", account.name);
|
||||
UploadFileOperation newUpload = new UploadFileOperation(
|
||||
storageManager,
|
||||
connectivityServiceMock,
|
||||
powerManagementServiceMock,
|
||||
account,
|
||||
null,
|
||||
ocUpload,
|
||||
FileUploader.NameCollisionPolicy.DEFAULT,
|
||||
FileUploader.LOCAL_BEHAVIOUR_COPY,
|
||||
targetContext,
|
||||
false,
|
||||
false
|
||||
storageManager,
|
||||
connectivityServiceMock,
|
||||
powerManagementServiceMock,
|
||||
account,
|
||||
null,
|
||||
ocUpload,
|
||||
false,
|
||||
FileUploader.LOCAL_BEHAVIOUR_COPY,
|
||||
targetContext,
|
||||
false,
|
||||
false
|
||||
);
|
||||
newUpload.addRenameUploadListener(() -> {
|
||||
// dummy
|
||||
|
||||
@@ -1,383 +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.files.services
|
||||
|
||||
import com.evernote.android.job.JobRequest
|
||||
import com.nextcloud.client.account.UserAccountManager
|
||||
import com.nextcloud.client.account.UserAccountManagerImpl
|
||||
import com.nextcloud.client.device.PowerManagementService
|
||||
import com.nextcloud.client.network.ConnectivityService
|
||||
import com.owncloud.android.AbstractIT
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import com.owncloud.android.datamodel.UploadsStorageManager
|
||||
import com.owncloud.android.db.OCUpload
|
||||
import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation
|
||||
import com.owncloud.android.lib.resources.files.model.RemoteFile
|
||||
import com.owncloud.android.operations.UploadFileOperation
|
||||
import com.owncloud.android.utils.FileStorageUtils.getSavePath
|
||||
import junit.framework.Assert.assertEquals
|
||||
import junit.framework.Assert.assertFalse
|
||||
import junit.framework.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
|
||||
class FileUploaderIT : AbstractIT() {
|
||||
val SHORT_WAIT: Long = 5000
|
||||
val LONG_WAIT: Long = 20000
|
||||
|
||||
var uploadsStorageManager: UploadsStorageManager? = null
|
||||
|
||||
val connectivityServiceMock: ConnectivityService = object : ConnectivityService {
|
||||
override fun isInternetWalled(): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun isOnlineWithWifi(): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun getActiveNetworkType(): JobRequest.NetworkType {
|
||||
return JobRequest.NetworkType.ANY
|
||||
}
|
||||
}
|
||||
|
||||
private val powerManagementServiceMock: PowerManagementService = object : PowerManagementService {
|
||||
override val isPowerSavingEnabled: Boolean
|
||||
get() = false
|
||||
|
||||
override val isPowerSavingExclusionAvailable: Boolean
|
||||
get() = false
|
||||
|
||||
override val isBatteryCharging: Boolean
|
||||
get() = false
|
||||
}
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
val contentResolver = targetContext.contentResolver
|
||||
val accountManager: UserAccountManager = UserAccountManagerImpl.fromContext(targetContext)
|
||||
uploadsStorageManager = UploadsStorageManager(accountManager, contentResolver)
|
||||
}
|
||||
|
||||
/**
|
||||
* uploads a file, overwrites it with an empty one, check if overwritten
|
||||
*/
|
||||
@Test
|
||||
fun testKeepLocalAndOverwriteRemote() {
|
||||
val file = File(getSavePath(account.name) + "/chunkedFile.txt")
|
||||
val ocUpload = OCUpload(file.absolutePath, "/testFile.txt", account.name)
|
||||
|
||||
assertTrue(UploadFileOperation(
|
||||
uploadsStorageManager,
|
||||
connectivityServiceMock,
|
||||
powerManagementServiceMock,
|
||||
account,
|
||||
null,
|
||||
ocUpload,
|
||||
FileUploader.NameCollisionPolicy.DEFAULT,
|
||||
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(getSavePath(account.name) + "/empty.txt", "/testFile.txt", account.name)
|
||||
|
||||
assertTrue(UploadFileOperation(
|
||||
uploadsStorageManager,
|
||||
connectivityServiceMock,
|
||||
powerManagementServiceMock,
|
||||
account,
|
||||
null,
|
||||
ocUpload2,
|
||||
FileUploader.NameCollisionPolicy.OVERWRITE,
|
||||
FileUploader.LOCAL_BEHAVIOUR_COPY,
|
||||
targetContext,
|
||||
false,
|
||||
false)
|
||||
.execute(client, storageManager).isSuccess)
|
||||
|
||||
val result2 = ReadFileRemoteOperation("/testFile.txt").execute(client)
|
||||
assertTrue(result2.isSuccess)
|
||||
|
||||
assertEquals(0, (result2.data[0] as RemoteFile).length)
|
||||
}
|
||||
|
||||
/**
|
||||
* uploads a file, overwrites it with an empty one, check if overwritten
|
||||
*/
|
||||
@Test
|
||||
fun testKeepLocalAndOverwriteRemoteStatic() {
|
||||
val file = File(getSavePath(account.name) + "/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)
|
||||
|
||||
Thread.sleep(LONG_WAIT)
|
||||
|
||||
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(getSavePath(account.name) + "/empty.txt")
|
||||
|
||||
FileUploader.uploadUpdateFile(
|
||||
targetContext,
|
||||
account,
|
||||
ocFile2,
|
||||
FileUploader.LOCAL_BEHAVIOUR_COPY,
|
||||
FileUploader.NameCollisionPolicy.OVERWRITE)
|
||||
|
||||
Thread.sleep(SHORT_WAIT)
|
||||
|
||||
val result2 = ReadFileRemoteOperation("/testFile.txt").execute(client)
|
||||
assertTrue(result2.isSuccess)
|
||||
|
||||
assertEquals(0, (result2.data[0] as RemoteFile).length)
|
||||
}
|
||||
|
||||
/**
|
||||
* uploads a file, uploads another one with automatically (2) added, check
|
||||
*/
|
||||
@Test
|
||||
fun testKeepBoth() {
|
||||
var renameListenerWasTriggered = false
|
||||
|
||||
val file = File(getSavePath(account.name) + "/chunkedFile.txt")
|
||||
val ocUpload = OCUpload(file.absolutePath, "/testFile.txt", account.name)
|
||||
|
||||
assertTrue(UploadFileOperation(
|
||||
uploadsStorageManager,
|
||||
connectivityServiceMock,
|
||||
powerManagementServiceMock,
|
||||
account,
|
||||
null,
|
||||
ocUpload,
|
||||
FileUploader.NameCollisionPolicy.DEFAULT,
|
||||
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 file2 = File(getSavePath(account.name) + "/empty.txt")
|
||||
val ocUpload2 = OCUpload(file2.absolutePath, "/testFile.txt", account.name)
|
||||
|
||||
assertTrue(UploadFileOperation(
|
||||
uploadsStorageManager,
|
||||
connectivityServiceMock,
|
||||
powerManagementServiceMock,
|
||||
account,
|
||||
null,
|
||||
ocUpload2,
|
||||
FileUploader.NameCollisionPolicy.RENAME,
|
||||
FileUploader.LOCAL_BEHAVIOUR_COPY,
|
||||
targetContext,
|
||||
false,
|
||||
false)
|
||||
.addRenameUploadListener {
|
||||
renameListenerWasTriggered = true
|
||||
}
|
||||
.execute(client, storageManager).isSuccess)
|
||||
|
||||
val result2 = ReadFileRemoteOperation("/testFile.txt").execute(client)
|
||||
assertTrue(result2.isSuccess)
|
||||
|
||||
assertEquals(file.length(), (result2.data[0] as RemoteFile).length)
|
||||
|
||||
val result3 = ReadFileRemoteOperation("/testFile (2).txt").execute(client)
|
||||
assertTrue(result3.isSuccess)
|
||||
|
||||
assertEquals(file2.length(), (result3.data[0] as RemoteFile).length)
|
||||
assertTrue(renameListenerWasTriggered)
|
||||
}
|
||||
|
||||
/**
|
||||
* uploads a file, uploads another one with automatically (2) added, check
|
||||
*/
|
||||
@Test
|
||||
fun testKeepBothStatic() {
|
||||
val file = File(getSavePath(account.name) + "/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)
|
||||
|
||||
Thread.sleep(LONG_WAIT)
|
||||
|
||||
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(getSavePath(account.name) + "/empty.txt")
|
||||
|
||||
FileUploader.uploadUpdateFile(
|
||||
targetContext,
|
||||
account,
|
||||
ocFile2,
|
||||
FileUploader.LOCAL_BEHAVIOUR_COPY,
|
||||
FileUploader.NameCollisionPolicy.RENAME)
|
||||
|
||||
Thread.sleep(SHORT_WAIT)
|
||||
|
||||
val result2 = ReadFileRemoteOperation("/testFile.txt").execute(client)
|
||||
assertTrue(result2.isSuccess)
|
||||
|
||||
assertEquals(file.length(), (result2.data[0] as RemoteFile).length)
|
||||
|
||||
val result3 = ReadFileRemoteOperation("/testFile (2).txt").execute(client)
|
||||
assertTrue(result3.isSuccess)
|
||||
|
||||
assertEquals(ocFile2.fileLength, (result3.data[0] as RemoteFile).length)
|
||||
}
|
||||
|
||||
/**
|
||||
* uploads a file with "keep server" option set, so do nothing
|
||||
*/
|
||||
@Test
|
||||
fun testKeepServer() {
|
||||
val file = File(getSavePath(account.name) + "/chunkedFile.txt")
|
||||
val ocUpload = OCUpload(file.absolutePath, "/testFile.txt", account.name)
|
||||
|
||||
assertTrue(UploadFileOperation(
|
||||
uploadsStorageManager,
|
||||
connectivityServiceMock,
|
||||
powerManagementServiceMock,
|
||||
account,
|
||||
null,
|
||||
ocUpload,
|
||||
FileUploader.NameCollisionPolicy.DEFAULT,
|
||||
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(getSavePath(account.name) + "/empty.txt", "/testFile.txt", account.name)
|
||||
|
||||
assertFalse(UploadFileOperation(
|
||||
uploadsStorageManager,
|
||||
connectivityServiceMock,
|
||||
powerManagementServiceMock,
|
||||
account,
|
||||
null,
|
||||
ocUpload2,
|
||||
FileUploader.NameCollisionPolicy.CANCEL,
|
||||
FileUploader.LOCAL_BEHAVIOUR_COPY,
|
||||
targetContext,
|
||||
false,
|
||||
false)
|
||||
.execute(client, storageManager).isSuccess)
|
||||
|
||||
val result2 = ReadFileRemoteOperation("/testFile.txt").execute(client)
|
||||
assertTrue(result2.isSuccess)
|
||||
|
||||
assertEquals(file.length(), (result2.data[0] as RemoteFile).length)
|
||||
}
|
||||
|
||||
/**
|
||||
* uploads a file with "keep server" option set, so do nothing
|
||||
*/
|
||||
@Test
|
||||
fun testKeepServerStatic() {
|
||||
val file = File(getSavePath(account.name) + "/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)
|
||||
|
||||
Thread.sleep(LONG_WAIT)
|
||||
|
||||
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(getSavePath(account.name) + "/empty.txt")
|
||||
|
||||
FileUploader.uploadUpdateFile(
|
||||
targetContext,
|
||||
account,
|
||||
ocFile2,
|
||||
FileUploader.LOCAL_BEHAVIOUR_COPY,
|
||||
FileUploader.NameCollisionPolicy.CANCEL)
|
||||
|
||||
Thread.sleep(SHORT_WAIT)
|
||||
|
||||
val result2 = ReadFileRemoteOperation("/testFile.txt").execute(client)
|
||||
assertTrue(result2.isSuccess)
|
||||
|
||||
assertEquals(file.length(), (result2.data[0] as RemoteFile).length)
|
||||
}
|
||||
}
|
||||
@@ -1,290 +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.activity;
|
||||
|
||||
import android.content.Intent;
|
||||
|
||||
import com.facebook.testing.screenshot.Screenshot;
|
||||
import com.nextcloud.client.account.UserAccountManagerImpl;
|
||||
import com.owncloud.android.AbstractIT;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.db.OCUpload;
|
||||
import com.owncloud.android.lib.resources.files.UploadFileRemoteOperation;
|
||||
import com.owncloud.android.operations.RefreshFolderOperation;
|
||||
import com.owncloud.android.ui.dialog.ConflictsResolveDialog;
|
||||
import com.owncloud.android.utils.FileStorageUtils;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule;
|
||||
|
||||
import static androidx.test.espresso.Espresso.onView;
|
||||
import static androidx.test.espresso.action.ViewActions.click;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withId;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withText;
|
||||
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class ConflictsResolveActivityIT extends AbstractIT {
|
||||
@Rule public IntentsTestRule<ConflictsResolveActivity> activityRule =
|
||||
new IntentsTestRule<>(ConflictsResolveActivity.class, true, false);
|
||||
private boolean returnCode;
|
||||
|
||||
@Test
|
||||
public void screenshotTextFiles() throws InterruptedException {
|
||||
OCUpload newUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt",
|
||||
"/newFile.txt",
|
||||
account.name);
|
||||
|
||||
OCFile existingFile = new OCFile("/newFile.txt");
|
||||
existingFile.setFileLength(1024000);
|
||||
existingFile.setModificationTimestamp(1582019340);
|
||||
|
||||
FileDataStorageManager storageManager = new FileDataStorageManager(account, targetContext.getContentResolver());
|
||||
storageManager.saveNewFile(existingFile);
|
||||
|
||||
Intent intent = new Intent(targetContext, ConflictsResolveActivity.class);
|
||||
intent.putExtra(ConflictsResolveActivity.EXTRA_FILE, existingFile);
|
||||
intent.putExtra(ConflictsResolveActivity.EXTRA_CONFLICT_UPLOAD, newUpload);
|
||||
|
||||
ConflictsResolveActivity sut = activityRule.launchActivity(intent);
|
||||
|
||||
ConflictsResolveDialog dialog = ConflictsResolveDialog.newInstance(existingFile,
|
||||
newUpload,
|
||||
UserAccountManagerImpl
|
||||
.fromContext(targetContext)
|
||||
.getUser()
|
||||
);
|
||||
dialog.showDialog(sut);
|
||||
|
||||
getInstrumentation().waitForIdleSync();
|
||||
|
||||
Thread.sleep(2000);
|
||||
|
||||
Screenshot.snap(dialog.getDialog().getWindow().getDecorView()).record();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void screenshotImages() throws InterruptedException, IOException {
|
||||
FileDataStorageManager storageManager = new FileDataStorageManager(account,
|
||||
targetContext.getContentResolver());
|
||||
|
||||
OCUpload newUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt",
|
||||
"/newFile.txt", account.name);
|
||||
|
||||
File image = getFile("image.jpg");
|
||||
|
||||
assertTrue(new UploadFileRemoteOperation(image.getAbsolutePath(),
|
||||
"/image.jpg",
|
||||
"image/jpg",
|
||||
"10000000").execute(client).isSuccess());
|
||||
|
||||
assertTrue(new RefreshFolderOperation(storageManager.getFileByPath("/"),
|
||||
System.currentTimeMillis(),
|
||||
false,
|
||||
true,
|
||||
storageManager,
|
||||
account,
|
||||
targetContext
|
||||
).execute(client).isSuccess());
|
||||
|
||||
OCFile existingFile = storageManager.getFileByPath("/image.jpg");
|
||||
|
||||
Intent intent = new Intent(targetContext, ConflictsResolveActivity.class);
|
||||
intent.putExtra(ConflictsResolveActivity.EXTRA_FILE, existingFile);
|
||||
intent.putExtra(ConflictsResolveActivity.EXTRA_CONFLICT_UPLOAD, newUpload);
|
||||
|
||||
ConflictsResolveActivity sut = activityRule.launchActivity(intent);
|
||||
|
||||
ConflictsResolveDialog.OnConflictDecisionMadeListener listener = decision -> {
|
||||
|
||||
};
|
||||
|
||||
ConflictsResolveDialog dialog = ConflictsResolveDialog.newInstance(existingFile,
|
||||
newUpload,
|
||||
UserAccountManagerImpl
|
||||
.fromContext(targetContext)
|
||||
.getUser()
|
||||
);
|
||||
dialog.showDialog(sut);
|
||||
dialog.listener = listener;
|
||||
|
||||
getInstrumentation().waitForIdleSync();
|
||||
Thread.sleep(2000);
|
||||
|
||||
Screenshot.snap(dialog.getDialog().getWindow().getDecorView()).record();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cancel() throws InterruptedException {
|
||||
returnCode = false;
|
||||
|
||||
OCUpload newUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt",
|
||||
"/newFile.txt",
|
||||
account.name);
|
||||
OCFile existingFile = new OCFile("/newFile.txt");
|
||||
existingFile.setFileLength(1024000);
|
||||
existingFile.setModificationTimestamp(1582019340);
|
||||
|
||||
FileDataStorageManager storageManager = new FileDataStorageManager(account, targetContext.getContentResolver());
|
||||
storageManager.saveNewFile(existingFile);
|
||||
|
||||
Intent intent = new Intent(targetContext, ConflictsResolveActivity.class);
|
||||
intent.putExtra(ConflictsResolveActivity.EXTRA_FILE, existingFile);
|
||||
intent.putExtra(ConflictsResolveActivity.EXTRA_CONFLICT_UPLOAD, newUpload);
|
||||
|
||||
ConflictsResolveActivity sut = activityRule.launchActivity(intent);
|
||||
|
||||
sut.listener = decision -> {
|
||||
assertEquals(decision, ConflictsResolveDialog.Decision.CANCEL);
|
||||
returnCode = true;
|
||||
};
|
||||
|
||||
getInstrumentation().waitForIdleSync();
|
||||
Thread.sleep(2000);
|
||||
|
||||
onView(withText("Cancel")).perform(click());
|
||||
|
||||
assertTrue(returnCode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void keepExisting() {
|
||||
returnCode = false;
|
||||
|
||||
OCUpload newUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt",
|
||||
"/newFile.txt",
|
||||
account.name);
|
||||
OCFile existingFile = new OCFile("/newFile.txt");
|
||||
existingFile.setFileLength(1024000);
|
||||
existingFile.setModificationTimestamp(1582019340);
|
||||
|
||||
FileDataStorageManager storageManager = new FileDataStorageManager(account, targetContext.getContentResolver());
|
||||
storageManager.saveNewFile(existingFile);
|
||||
|
||||
Intent intent = new Intent(targetContext, ConflictsResolveActivity.class);
|
||||
intent.putExtra(ConflictsResolveActivity.EXTRA_FILE, existingFile);
|
||||
intent.putExtra(ConflictsResolveActivity.EXTRA_CONFLICT_UPLOAD, newUpload);
|
||||
|
||||
ConflictsResolveActivity sut = activityRule.launchActivity(intent);
|
||||
|
||||
sut.listener = decision -> {
|
||||
assertEquals(decision, ConflictsResolveDialog.Decision.KEEP_SERVER);
|
||||
returnCode = true;
|
||||
};
|
||||
|
||||
getInstrumentation().waitForIdleSync();
|
||||
|
||||
onView(withId(R.id.existing_checkbox)).perform(click());
|
||||
|
||||
DialogFragment dialog = (DialogFragment) sut.getSupportFragmentManager().findFragmentByTag("conflictDialog");
|
||||
Screenshot.snap(dialog.getDialog().getWindow().getDecorView()).record();
|
||||
|
||||
onView(withText("OK")).perform(click());
|
||||
|
||||
assertTrue(returnCode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void keepNew() {
|
||||
returnCode = false;
|
||||
|
||||
OCUpload newUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt",
|
||||
"/newFile.txt",
|
||||
account.name);
|
||||
OCFile existingFile = new OCFile("/newFile.txt");
|
||||
existingFile.setFileLength(1024000);
|
||||
existingFile.setModificationTimestamp(1582019340);
|
||||
|
||||
FileDataStorageManager storageManager = new FileDataStorageManager(account, targetContext.getContentResolver());
|
||||
storageManager.saveNewFile(existingFile);
|
||||
|
||||
Intent intent = new Intent(targetContext, ConflictsResolveActivity.class);
|
||||
intent.putExtra(ConflictsResolveActivity.EXTRA_FILE, existingFile);
|
||||
intent.putExtra(ConflictsResolveActivity.EXTRA_CONFLICT_UPLOAD, newUpload);
|
||||
|
||||
ConflictsResolveActivity sut = activityRule.launchActivity(intent);
|
||||
|
||||
sut.listener = decision -> {
|
||||
assertEquals(decision, ConflictsResolveDialog.Decision.KEEP_SERVER);
|
||||
returnCode = true;
|
||||
};
|
||||
|
||||
getInstrumentation().waitForIdleSync();
|
||||
|
||||
onView(withId(R.id.new_checkbox)).perform(click());
|
||||
|
||||
DialogFragment dialog = (DialogFragment) sut.getSupportFragmentManager().findFragmentByTag("conflictDialog");
|
||||
Screenshot.snap(dialog.getDialog().getWindow().getDecorView()).record();
|
||||
|
||||
onView(withText("OK")).perform(click());
|
||||
|
||||
assertTrue(returnCode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void keepBoth() {
|
||||
returnCode = false;
|
||||
|
||||
OCUpload newUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt",
|
||||
"/newFile.txt",
|
||||
account.name);
|
||||
OCFile existingFile = new OCFile("/newFile.txt");
|
||||
existingFile.setFileLength(1024000);
|
||||
existingFile.setModificationTimestamp(1582019340);
|
||||
|
||||
FileDataStorageManager storageManager = new FileDataStorageManager(account, targetContext.getContentResolver());
|
||||
storageManager.saveNewFile(existingFile);
|
||||
|
||||
Intent intent = new Intent(targetContext, ConflictsResolveActivity.class);
|
||||
intent.putExtra(ConflictsResolveActivity.EXTRA_FILE, existingFile);
|
||||
intent.putExtra(ConflictsResolveActivity.EXTRA_CONFLICT_UPLOAD, newUpload);
|
||||
|
||||
ConflictsResolveActivity sut = activityRule.launchActivity(intent);
|
||||
|
||||
sut.listener = decision -> {
|
||||
assertEquals(decision, ConflictsResolveDialog.Decision.KEEP_SERVER);
|
||||
returnCode = true;
|
||||
};
|
||||
|
||||
getInstrumentation().waitForIdleSync();
|
||||
|
||||
onView(withId(R.id.existing_checkbox)).perform(click());
|
||||
onView(withId(R.id.new_checkbox)).perform(click());
|
||||
|
||||
DialogFragment dialog = (DialogFragment) sut.getSupportFragmentManager().findFragmentByTag("conflictDialog");
|
||||
Screenshot.snap(dialog.getDialog().getWindow().getDecorView()).record();
|
||||
|
||||
onView(withText("OK")).perform(click());
|
||||
|
||||
assertTrue(returnCode);
|
||||
}
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
package com.owncloud.android.ui.activity;
|
||||
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Kilian Périsset
|
||||
* Copyright (C) 2019 Kilian Périsset (Infomaniak Network SA)
|
||||
* Copyright (C) 2019 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/>.
|
||||
*/
|
||||
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import androidx.test.filters.LargeTest;
|
||||
import androidx.test.rule.ActivityTestRule;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@LargeTest
|
||||
public class FolderPickerActivityIT {
|
||||
@Rule
|
||||
public ActivityTestRule<FolderPickerActivity> activityRule =
|
||||
new ActivityTestRule<>(FolderPickerActivity.class);
|
||||
|
||||
@Test
|
||||
public void getActivityFile() {
|
||||
// Arrange
|
||||
FolderPickerActivity targetActivity = activityRule.getActivity();
|
||||
OCFile origin = new OCFile("/test/file.test");
|
||||
origin.setRemotePath("/remotePath/test");
|
||||
|
||||
// Act
|
||||
targetActivity.setFile(origin);
|
||||
OCFile target = targetActivity.getFile();
|
||||
|
||||
// Assert
|
||||
Assert.assertEquals(origin, target);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getParentFolder_isNotRootFolder() {
|
||||
// Arrange
|
||||
FolderPickerActivity targetActivity = activityRule.getActivity();
|
||||
OCFile origin = new OCFile("/test/");
|
||||
origin.setFileId(1);
|
||||
origin.setRemotePath("/test/");
|
||||
origin.setStoragePath("/test/");
|
||||
origin.setFolder();
|
||||
|
||||
// Act
|
||||
targetActivity.setFile(origin);
|
||||
OCFile target = targetActivity.getCurrentFolder();
|
||||
|
||||
// Assert
|
||||
Assert.assertEquals(origin, target);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getParentFolder_isRootFolder() {
|
||||
// Arrange
|
||||
FolderPickerActivity targetActivity = activityRule.getActivity();
|
||||
OCFile origin = new OCFile("/");
|
||||
origin.setFileId(1);
|
||||
origin.setRemotePath("/");
|
||||
origin.setStoragePath("/");
|
||||
origin.setFolder();
|
||||
|
||||
// Act
|
||||
targetActivity.setFile(origin);
|
||||
OCFile target = targetActivity.getCurrentFolder();
|
||||
|
||||
// Assert
|
||||
Assert.assertEquals(origin, target);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullFile() {
|
||||
// Arrange
|
||||
FolderPickerActivity targetActivity = activityRule.getActivity();
|
||||
OCFile rootFolder = targetActivity.getStorageManager().getFileByPath(OCFile.ROOT_PATH);
|
||||
|
||||
// Act
|
||||
targetActivity.setFile(null);
|
||||
OCFile target = targetActivity.getCurrentFolder();
|
||||
|
||||
// Assert
|
||||
Assert.assertEquals(rootFolder, target);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getParentFolder() {
|
||||
// Arrange
|
||||
FolderPickerActivity targetActivity = activityRule.getActivity();
|
||||
OCFile origin = new OCFile("/test/file.test");
|
||||
origin.setRemotePath("/test/file.test");
|
||||
|
||||
OCFile target = new OCFile("/test/");
|
||||
|
||||
// Act
|
||||
targetActivity.setFile(origin);
|
||||
|
||||
// Assert
|
||||
Assert.assertEquals(origin, target);
|
||||
}
|
||||
}
|
||||
@@ -1,62 +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.activity;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import com.facebook.testing.screenshot.Screenshot;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.owncloud.android.AbstractIT;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule;
|
||||
|
||||
public class ManageAccountsActivityIT extends AbstractIT {
|
||||
@Rule
|
||||
public IntentsTestRule<ManageAccountsActivity> activityRule = new IntentsTestRule<>(ManageAccountsActivity.class,
|
||||
true,
|
||||
false);
|
||||
|
||||
@Test
|
||||
public void open() throws InterruptedException {
|
||||
Activity sut = activityRule.launchActivity(null);
|
||||
|
||||
Thread.sleep(2000);
|
||||
|
||||
Screenshot.snapActivity(sut).record();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void userInfoDetail() throws InterruptedException {
|
||||
ManageAccountsActivity sut = activityRule.launchActivity(null);
|
||||
|
||||
User user = sut.accountManager.getUser();
|
||||
sut.onClick(user);
|
||||
|
||||
Thread.sleep(2000);
|
||||
|
||||
Screenshot.snapActivity(getCurrentActivity()).record();
|
||||
}
|
||||
}
|
||||
@@ -1,77 +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.Manifest;
|
||||
|
||||
import com.facebook.testing.screenshot.Screenshot;
|
||||
import com.owncloud.android.AbstractIT;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.ui.activity.FileDisplayActivity;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule;
|
||||
import androidx.test.rule.GrantPermissionRule;
|
||||
|
||||
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
|
||||
|
||||
public class SyncFileNotEnoughSpaceDialogFragmentTest extends AbstractIT {
|
||||
@Rule public IntentsTestRule<FileDisplayActivity> activityRule = new IntentsTestRule<>(FileDisplayActivity.class,
|
||||
true,
|
||||
false);
|
||||
|
||||
@Rule
|
||||
public final GrantPermissionRule permissionRule = GrantPermissionRule.grant(
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
|
||||
|
||||
@Test
|
||||
public void showNotEnoughSpaceDialogForFolder() {
|
||||
FileDisplayActivity test = activityRule.launchActivity(null);
|
||||
OCFile ocFile = new OCFile("/Document/");
|
||||
ocFile.setFileLength(5000000);
|
||||
|
||||
SyncFileNotEnoughSpaceDialogFragment dialog = SyncFileNotEnoughSpaceDialogFragment.newInstance(ocFile, 1000);
|
||||
dialog.show(test.getListOfFilesFragment().getFragmentManager(), "1");
|
||||
|
||||
getInstrumentation().waitForIdleSync();
|
||||
|
||||
Screenshot.snap(dialog.getDialog().getWindow().getDecorView()).record();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void showNotEnoughSpaceDialogForFile() {
|
||||
FileDisplayActivity test = activityRule.launchActivity(null);
|
||||
OCFile ocFile = new OCFile("/Video.mp4");
|
||||
ocFile.setFileLength(1000000);
|
||||
|
||||
SyncFileNotEnoughSpaceDialogFragment dialog = SyncFileNotEnoughSpaceDialogFragment.newInstance(ocFile, 2000);
|
||||
dialog.show(test.getListOfFilesFragment().getFragmentManager(), "2");
|
||||
|
||||
getInstrumentation().waitForIdleSync();
|
||||
|
||||
Screenshot.snap(dialog.getDialog().getWindow().getDecorView()).record();
|
||||
}
|
||||
}
|
||||
@@ -1,144 +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 androidx.test.core.app.ActivityScenario
|
||||
import androidx.test.rule.GrantPermissionRule
|
||||
import com.evernote.android.job.JobRequest
|
||||
import com.nextcloud.client.account.UserAccountManagerImpl
|
||||
import com.nextcloud.client.device.PowerManagementService
|
||||
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.AbstractIT
|
||||
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.operations.CreateFolderOperation
|
||||
import com.owncloud.android.operations.RefreshFolderOperation
|
||||
import com.owncloud.android.operations.UploadFileOperation
|
||||
import com.owncloud.android.ui.activity.FileDisplayActivity
|
||||
import com.owncloud.android.utils.FileStorageUtils
|
||||
import junit.framework.Assert.assertTrue
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
||||
class OCFileListFragmentIT : AbstractIT() {
|
||||
@get:Rule
|
||||
val permissionRule = GrantPermissionRule.grant(Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
|
||||
private val connectivityServiceMock: ConnectivityService = object : ConnectivityService {
|
||||
override fun isInternetWalled(): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun isOnlineWithWifi(): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun getActiveNetworkType(): JobRequest.NetworkType {
|
||||
return JobRequest.NetworkType.ANY
|
||||
}
|
||||
}
|
||||
|
||||
private val powerManagementServiceMock: PowerManagementService = object : PowerManagementService {
|
||||
override val isPowerSavingEnabled: Boolean
|
||||
get() = false
|
||||
|
||||
override val isPowerSavingExclusionAvailable: Boolean
|
||||
get() = false
|
||||
|
||||
override val isBatteryCharging: Boolean
|
||||
get() = false
|
||||
}
|
||||
|
||||
@Test
|
||||
fun showRichWorkspace() {
|
||||
assertTrue(CreateFolderOperation("/test/", true).execute(client, storageManager).isSuccess)
|
||||
|
||||
val ocUpload = OCUpload(FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt",
|
||||
"/test/Readme.md",
|
||||
account.name)
|
||||
val newUpload = UploadFileOperation(
|
||||
UploadsStorageManager(UserAccountManagerImpl.fromContext(targetContext), targetContext.contentResolver),
|
||||
connectivityServiceMock,
|
||||
powerManagementServiceMock,
|
||||
account,
|
||||
null,
|
||||
ocUpload,
|
||||
FileUploader.NameCollisionPolicy.DEFAULT,
|
||||
FileUploader.LOCAL_BEHAVIOUR_COPY,
|
||||
targetContext,
|
||||
false,
|
||||
false
|
||||
)
|
||||
newUpload.addRenameUploadListener {}
|
||||
|
||||
newUpload.setRemoteFolderToBeCreated()
|
||||
|
||||
assertTrue(newUpload.execute(client, storageManager).isSuccess)
|
||||
|
||||
assertTrue(RefreshFolderOperation(storageManager.getFileByPath("/test/"),
|
||||
System.currentTimeMillis() / 1000,
|
||||
false,
|
||||
true,
|
||||
storageManager,
|
||||
account,
|
||||
targetContext).execute(client).isSuccess)
|
||||
|
||||
val sut = ActivityScenario.launch(FileDisplayActivity::class.java)
|
||||
sut.onActivity { activity -> activity.onBrowsedDownTo(storageManager.getFileByPath("/test/")) }
|
||||
|
||||
Thread.sleep(2000)
|
||||
|
||||
sut.onActivity { activity ->
|
||||
com.facebook.testing.screenshot.Screenshot.snapActivity(activity).setName("richworkspaces_light").record()
|
||||
}
|
||||
|
||||
val preferences: AppPreferences = AppPreferencesImpl.fromContext(targetContext)
|
||||
preferences.darkThemeMode = DarkMode.DARK
|
||||
MainApp.setAppTheme(DarkMode.DARK)
|
||||
|
||||
sut.onActivity { activity -> activity.onBackPressed() }
|
||||
|
||||
sut.recreate()
|
||||
|
||||
sut.onActivity { activity -> activity.onBrowsedDownTo(storageManager.getFileByPath("/test/")) }
|
||||
|
||||
Thread.sleep(2000)
|
||||
|
||||
sut.onActivity { activity ->
|
||||
com.facebook.testing.screenshot.Screenshot.snapActivity(activity).setName("richworkspaces_dark").record()
|
||||
}
|
||||
|
||||
// switch back to light mode
|
||||
preferences.darkThemeMode = DarkMode.LIGHT
|
||||
MainApp.setAppTheme(DarkMode.LIGHT)
|
||||
|
||||
sut.onActivity { activity -> activity.onBackPressed() }
|
||||
|
||||
sut.recreate()
|
||||
}
|
||||
}
|
||||
@@ -1,85 +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.preview;
|
||||
|
||||
import android.Manifest;
|
||||
|
||||
import com.facebook.testing.screenshot.Screenshot;
|
||||
import com.owncloud.android.AbstractIT;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.ui.activity.FileDisplayActivity;
|
||||
import com.owncloud.android.utils.FileStorageUtils;
|
||||
import com.owncloud.android.utils.MimeTypeUtil;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule;
|
||||
import androidx.test.rule.GrantPermissionRule;
|
||||
|
||||
public class PreviewTextFileFragmentTest extends AbstractIT {
|
||||
@Rule public IntentsTestRule<FileDisplayActivity> activityRule = new IntentsTestRule<>(FileDisplayActivity.class,
|
||||
true,
|
||||
false);
|
||||
|
||||
@Rule
|
||||
public final GrantPermissionRule permissionRule = GrantPermissionRule.grant(
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
|
||||
@Test
|
||||
public void displaySimpleTextFile() throws InterruptedException {
|
||||
FileDisplayActivity sut = activityRule.launchActivity(null);
|
||||
|
||||
Thread.sleep(3000);
|
||||
|
||||
File file = new File(FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt");
|
||||
OCFile test = new OCFile("/text.md");
|
||||
test.setMimeType(MimeTypeUtil.MIMETYPE_TEXT_MARKDOWN);
|
||||
test.setStoragePath(file.getAbsolutePath());
|
||||
sut.startTextPreview(test, false);
|
||||
|
||||
Thread.sleep(3000);
|
||||
|
||||
Screenshot.snapActivity(sut).record();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayJavaSnippetFile() throws IOException, InterruptedException {
|
||||
FileDisplayActivity sut = activityRule.launchActivity(null);
|
||||
|
||||
Thread.sleep(3000);
|
||||
|
||||
File file = getFile("java.md");
|
||||
OCFile test = new OCFile("/java.md");
|
||||
test.setMimeType(MimeTypeUtil.MIMETYPE_TEXT_MARKDOWN);
|
||||
test.setStoragePath(file.getAbsolutePath());
|
||||
sut.startTextPreview(test, false);
|
||||
|
||||
Thread.sleep(3000);
|
||||
|
||||
Screenshot.snapActivity(sut).record();
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,17 @@
|
||||
U vás hostovaná platforma pro produktivitu, která ponechává kontrolu vám
|
||||
|
||||
Software, který můžete nasadit na vlastní server a ten organizuje ukládání a synchronizaci souborů. Díky doplňkům jde o kompletní groupwarové řešení.
|
||||
Funkce:
|
||||
* Snadno použitelné moderní rozhraní, s motivem vzhledu sladěným s tím nastaveným na serveru
|
||||
* Nahrávání souborů na vámi využívaný Nextcloud server
|
||||
* Jejich sdílení s ostatními
|
||||
* Udržování vašich oblíbených souborů a složek synchronizovaných
|
||||
* Vyhledávání napříč všemi složkami na vámi využívaném serveru
|
||||
* Automatické nahrávání fotek a videí pořízených vaším zařízením
|
||||
* Budete v obraze díky upozorněním
|
||||
* Podpora vícero účtů
|
||||
* Zabezpečení přístupu k vašim datům otiskem prstu nebo PIN kódem
|
||||
* Propojení s aplikací DAVx5 (dříve známé jako DAVdroid) pro snadné nastavení synchronizace kalendáře a kontaktů
|
||||
* Soubory nahrané do nexcloudu lze snadno sdílet s ostatními.
|
||||
* Přístup odkudkoli přes webové a mobilní rozhraní.
|
||||
* Synchronizace s počítačem umožňující offline práci.
|
||||
* Vaše data jsou na vašem serveru a máte nad nimi plnou kontrolu.
|
||||
* Jde o svobodný software, který snadno můžete sami hostovat a volně si ho přizplsobit. V případě potřeby je ale k dispozici komerční podpora.
|
||||
* Vyhledávání napříč soubory.
|
||||
* Synchronizace kontaktů a zpráv.
|
||||
* Sdílení kalendářů do mobilu (DAVx5/DAVdroid)
|
||||
* Neomezený počet uživatelů, autoupload fotek přímo z mobilu, oznámení,
|
||||
* Klienti pro WIndows, MacOS, iOS, Android, web.
|
||||
* Mnoho dalších doplňků s dalšími funkcemi.
|
||||
|
||||
Díky Nextcloudu budete mít kompletní privátní řešení pro všechy vaše soubory, fotky, kalendáře a kontakty.
|
||||
|
||||
Veškeré problémy prosíme hlaste na https://github.com/nextcloud/android/issues, diskutovat lze na https://help.nextcloud.com/c/clients/android
|
||||
|
||||
Ještě Nextcloud neznáte? Je to server pro komunikaci, synchronizaci a sdílení vašich dat. Jedná se o svobodný software, který můžete provozovat sami, nebo si jako službu koupit u jiné společnosti. Díky tomu máte kontrolu nad svými fotkami, kalendářem, kontakty i dokumenty a vším ostatním.
|
||||
|
||||
Další informace o Nextcloud naleznete na https://nextcloud.com
|
||||
Připomínky zasílejte na https://github.com/nextcloud/android/issues, diskutovat lze na https://help.nextcloud.com/c/clients a vše ostatní najdete na https://nextcloud.com
|
||||
@@ -15,7 +15,7 @@ Eigenschaften:
|
||||
* Bleiben Sie auf dem Laufenden durch Benachrichtigungen
|
||||
* Mehrere Konten gleichzeitig
|
||||
* Geschützter Zugriff durch Fingerabdruck oder PIN
|
||||
* Integration mit DAVx5 (ehemals DAVdroid) für einfaches Konfigurieren der Kalender- & Kontakte-Synchronisierung
|
||||
* Integration mit DAVx5 (ehemals DAVdroid) für einfaches Konfigurieren der Kalender- & Kontakte-Synchronisation
|
||||
|
||||
Bitte melden Sie alle Probleme unter https://github.com/nextcloud/android/issues oder diskutieren Sie über die App auf https://help.nextcloud.com/c/clients/android
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
بستر تولیدی خود میزبان که شما را کنترل می کند. \ n \ n ویژگی ها: \ n * رابط کاربری آسان و مدرن ،
|
||||
@@ -1 +0,0 @@
|
||||
بستر تولیدی خود میزبان که شما را کنترل می کند
|
||||
@@ -1 +0,0 @@
|
||||
Nextcloud
|
||||
@@ -1,4 +1,4 @@
|
||||
Oprogramowanie biurowe uruchamiane na własnym hostingu, który zapewnia kontrolę.
|
||||
Samo-hostująca platforma produkcyjna, która zapewnia kontrolę.
|
||||
|
||||
Funkcje:
|
||||
* Łatwy, nowoczesny interfejs, dostosowany do wyglądu Twojego serwera
|
||||
|
||||
@@ -1 +1 @@
|
||||
Oprogramowanie biurowe uruchamiane na własnym hostingu, który zapewnia kontrolę
|
||||
Samo-hostująca platforma produkcyjna, która zapewnia kontrolę
|
||||
@@ -1 +0,0 @@
|
||||
Samo-gostujoče produkcijsko okolje pod vašim nadzorom.
|
||||
@@ -1 +0,0 @@
|
||||
Nextcloud
|
||||
@@ -117,19 +117,6 @@
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEARCH" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<data android:scheme="http"
|
||||
android:host="*"
|
||||
android:pathPattern="/.*index.php/f/.*"
|
||||
/>
|
||||
<data android:scheme="https"
|
||||
android:host="*"
|
||||
android:pathPattern="/.*index.php/f/.*"
|
||||
/>
|
||||
</intent-filter>
|
||||
<meta-data android:name="android.app.searchable"
|
||||
android:resource="@xml/users_and_groups_searchable"/>
|
||||
</activity>
|
||||
|
||||
|
Before Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 44 KiB |
@@ -50,7 +50,6 @@ import org.apache.commons.httpclient.HttpState;
|
||||
import org.apache.commons.httpclient.NameValuePair;
|
||||
import org.apache.commons.httpclient.methods.DeleteMethod;
|
||||
import org.apache.commons.httpclient.methods.GetMethod;
|
||||
import org.apache.commons.httpclient.methods.HeadMethod;
|
||||
import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
|
||||
import org.apache.commons.httpclient.methods.PostMethod;
|
||||
import org.apache.commons.httpclient.methods.PutMethod;
|
||||
@@ -298,10 +297,6 @@ public class InputStreamBinder extends IInputStreamService.Stub {
|
||||
method = new MkColMethod(requestUrl);
|
||||
break;
|
||||
|
||||
case "HEAD":
|
||||
method = new HeadMethod(requestUrl);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new UnsupportedOperationException(EXCEPTION_UNSUPPORTED_METHOD);
|
||||
|
||||
|
||||
@@ -27,10 +27,14 @@ import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
public class PlainHeader implements Serializable {
|
||||
private static final long serialVersionUID = 3284979177401282512L;
|
||||
|
||||
@Getter
|
||||
private String name;
|
||||
@Getter
|
||||
private String value;
|
||||
|
||||
PlainHeader(String name, String value) {
|
||||
@@ -47,12 +51,4 @@ public class PlainHeader implements Serializable {
|
||||
name = (String) in.readObject();
|
||||
value = (String) in.readObject();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,10 @@ import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
public class Response {
|
||||
@Getter
|
||||
private InputStream body;
|
||||
private Header[] headers;
|
||||
|
||||
@@ -59,8 +62,4 @@ public class Response {
|
||||
Gson gson = new Gson();
|
||||
return gson.toJson(arrayList);
|
||||
}
|
||||
|
||||
public InputStream getBody() {
|
||||
return this.body;
|
||||
}
|
||||
}
|
||||
@@ -23,8 +23,6 @@ package com.nextcloud.client.account
|
||||
import android.accounts.Account
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.owncloud.android.MainApp
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.lib.common.OwnCloudAccount
|
||||
@@ -36,7 +34,7 @@ import java.net.URI
|
||||
* It serves as a semantically correct "empty value", allowing simplification of logic
|
||||
* in various components requiring user data, such as DB queries.
|
||||
*/
|
||||
internal data class AnonymousUser(private val accountType: String) : User, Parcelable {
|
||||
internal class AnonymousUser(private val accountType: String) : User {
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
@@ -44,19 +42,9 @@ internal data class AnonymousUser(private val accountType: String) : User, Parce
|
||||
val type = context.getString(R.string.account_type)
|
||||
return AnonymousUser(type)
|
||||
}
|
||||
|
||||
@JvmField
|
||||
val CREATOR: Parcelable.Creator<AnonymousUser> = object : Parcelable.Creator<AnonymousUser> {
|
||||
override fun createFromParcel(source: Parcel): AnonymousUser = AnonymousUser(source)
|
||||
override fun newArray(size: Int): Array<AnonymousUser?> = arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
|
||||
private constructor(source: Parcel) : this(
|
||||
source.readString() as String
|
||||
)
|
||||
|
||||
override val accountName: String = "anonymous@nohost"
|
||||
override val accountName: String = "anonymous"
|
||||
override val server = Server(URI.create(""), MainApp.MINIMUM_SUPPORTED_SERVER_VERSION)
|
||||
override val isAnonymous = true
|
||||
|
||||
@@ -67,14 +55,4 @@ internal data class AnonymousUser(private val accountType: String) : User, Parce
|
||||
override fun toOwnCloudAccount(): OwnCloudAccount {
|
||||
return OwnCloudAccount(Uri.EMPTY, OwnCloudBasicCredentials("", ""))
|
||||
}
|
||||
|
||||
override fun nameEquals(user: User?): Boolean {
|
||||
return user?.accountName.equals(accountName, true)
|
||||
}
|
||||
|
||||
override fun describeContents() = 0
|
||||
|
||||
override fun writeToParcel(dest: Parcel, flags: Int) = with(dest) {
|
||||
writeString(accountType)
|
||||
}
|
||||
}
|
||||
@@ -21,33 +21,16 @@
|
||||
package com.nextcloud.client.account
|
||||
|
||||
import android.accounts.Account
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.owncloud.android.lib.common.OwnCloudAccount
|
||||
|
||||
/**
|
||||
* This class represents normal user logged into the Nextcloud server.
|
||||
*/
|
||||
internal data class RegisteredUser(
|
||||
internal class RegisteredUser(
|
||||
private val account: Account,
|
||||
private val ownCloudAccount: OwnCloudAccount,
|
||||
override val server: Server
|
||||
) : User {
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
val CREATOR: Parcelable.Creator<RegisteredUser> = object : Parcelable.Creator<RegisteredUser> {
|
||||
override fun createFromParcel(source: Parcel): RegisteredUser = RegisteredUser(source)
|
||||
override fun newArray(size: Int): Array<RegisteredUser?> = arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
|
||||
private constructor(source: Parcel) : this(
|
||||
source.readParcelable<Account>(Account::class.java.classLoader) as Account,
|
||||
source.readParcelable<OwnCloudAccount>(OwnCloudAccount::class.java.classLoader) as OwnCloudAccount,
|
||||
source.readParcelable<Server>(Server::class.java.classLoader) as Server
|
||||
)
|
||||
|
||||
override val isAnonymous = false
|
||||
|
||||
override val accountName: String get() {
|
||||
@@ -61,16 +44,4 @@ internal data class RegisteredUser(
|
||||
override fun toOwnCloudAccount(): OwnCloudAccount {
|
||||
return ownCloudAccount
|
||||
}
|
||||
|
||||
override fun nameEquals(user: User?): Boolean {
|
||||
return user?.accountName.equals(accountName, true)
|
||||
}
|
||||
|
||||
override fun describeContents() = 0
|
||||
|
||||
override fun writeToParcel(dest: Parcel, flags: Int) = with(dest) {
|
||||
writeParcelable(account, 0)
|
||||
writeParcelable(ownCloudAccount, 0)
|
||||
writeParcelable(server, 0)
|
||||
}
|
||||
}
|
||||
@@ -20,8 +20,6 @@
|
||||
*/
|
||||
package com.nextcloud.client.account
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion
|
||||
import java.net.URI
|
||||
|
||||
@@ -29,25 +27,4 @@ import java.net.URI
|
||||
* This object provides all information necessary to interact
|
||||
* with backend server.
|
||||
*/
|
||||
data class Server(val uri: URI, val version: OwnCloudVersion) : Parcelable {
|
||||
|
||||
constructor(source: Parcel) : this(
|
||||
source.readSerializable() as URI,
|
||||
source.readParcelable<Parcelable>(OwnCloudVersion::class.java.classLoader) as OwnCloudVersion
|
||||
)
|
||||
|
||||
override fun describeContents() = 0
|
||||
|
||||
override fun writeToParcel(dest: Parcel, flags: Int) = with(dest) {
|
||||
writeSerializable(uri)
|
||||
writeParcelable(version, 0)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
val CREATOR: Parcelable.Creator<Server> = object : Parcelable.Creator<Server> {
|
||||
override fun createFromParcel(source: Parcel): Server = Server(source)
|
||||
override fun newArray(size: Int): Array<Server?> = arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
}
|
||||
data class Server(val uri: URI, val version: OwnCloudVersion)
|
||||
@@ -21,10 +21,9 @@
|
||||
package com.nextcloud.client.account
|
||||
|
||||
import android.accounts.Account
|
||||
import android.os.Parcelable
|
||||
import com.owncloud.android.lib.common.OwnCloudAccount
|
||||
|
||||
interface User : Parcelable {
|
||||
interface User {
|
||||
val accountName: String
|
||||
val server: Server
|
||||
val isAnonymous: Boolean
|
||||
@@ -52,11 +51,4 @@ interface User : Parcelable {
|
||||
*/
|
||||
@Deprecated("Temporary workaround")
|
||||
fun toOwnCloudAccount(): OwnCloudAccount
|
||||
|
||||
/**
|
||||
* Compare account names, case insensitive.
|
||||
*
|
||||
* @return true if account names are same, false otherwise
|
||||
*/
|
||||
fun nameEquals(user: User?): Boolean
|
||||
}
|
||||
@@ -20,8 +20,6 @@
|
||||
package com.nextcloud.client.account;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.nextcloud.java.util.Optional;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
@@ -48,14 +46,6 @@ public interface UserAccountManager extends CurrentAccountProvider {
|
||||
*/
|
||||
void removeAllAccounts();
|
||||
|
||||
/**
|
||||
* Remove registered user.
|
||||
*
|
||||
* @param user user to remove
|
||||
* @return true if account was removed successfully, false otherwise
|
||||
*/
|
||||
boolean removeUser(User user);
|
||||
|
||||
/**
|
||||
* Get configured NextCloud's user accounts.
|
||||
*
|
||||
@@ -89,11 +79,7 @@ public interface UserAccountManager extends CurrentAccountProvider {
|
||||
boolean exists(Account account);
|
||||
|
||||
/**
|
||||
* Verifies that every account has userId set and sets the user id if not.
|
||||
* This migration is idempotent and can be run multiple times until
|
||||
* all accounts are migrated.
|
||||
*
|
||||
* @return true if migration was successful, false if any account failed to be migrated
|
||||
* Verifies that every account has userId set
|
||||
*/
|
||||
boolean migrateUserId();
|
||||
|
||||
@@ -155,12 +141,4 @@ public interface UserAccountManager extends CurrentAccountProvider {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch account registration activity.
|
||||
*
|
||||
* This method returns immediately. Authenticator activity will be launched asynchronously.
|
||||
*
|
||||
* @param activity Activity used to launch authenticator flow via {@link Activity#startActivity(Intent)}
|
||||
*/
|
||||
void startAccountCreation(Activity activity);
|
||||
}
|
||||
@@ -22,10 +22,6 @@ package com.nextcloud.client.account;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.app.Activity;
|
||||
import android.accounts.AccountManagerFuture;
|
||||
import android.accounts.AuthenticatorException;
|
||||
import android.accounts.OperationCanceledException;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
@@ -46,7 +42,6 @@ import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
||||
import com.owncloud.android.lib.resources.users.GetUserInfoRemoteOperation;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -85,18 +80,6 @@ public class UserAccountManagerImpl implements UserAccountManager {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeUser(User user) {
|
||||
try {
|
||||
AccountManagerFuture<Boolean> result = accountManager.removeAccount(user.toPlatformAccount(),
|
||||
null,
|
||||
null);
|
||||
return result.getResult();
|
||||
} catch (OperationCanceledException| AuthenticatorException| IOException ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public Account[] getAccounts() {
|
||||
@@ -342,11 +325,12 @@ public class UserAccountManagerImpl implements UserAccountManager {
|
||||
}
|
||||
|
||||
public boolean migrateUserId() {
|
||||
boolean success = false;
|
||||
Account[] ocAccounts = accountManager.getAccountsByType(MainApp.getAccountType(context));
|
||||
String userId;
|
||||
String displayName;
|
||||
GetUserInfoRemoteOperation remoteUserNameOperation = new GetUserInfoRemoteOperation();
|
||||
int failed = 0;
|
||||
|
||||
for (Account account : ocAccounts) {
|
||||
String storedUserId = accountManager.getUserData(account, com.owncloud.android.lib.common.accounts.AccountUtils.Constants.KEY_USER_ID);
|
||||
|
||||
@@ -369,12 +353,10 @@ public class UserAccountManagerImpl implements UserAccountManager {
|
||||
} else {
|
||||
// skip account, try it next time
|
||||
Log_OC.e(TAG, "Error while getting username for account: " + account.name);
|
||||
failed++;
|
||||
continue;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log_OC.e(TAG, "Error while getting username: " + e.getMessage());
|
||||
failed++;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -384,23 +366,14 @@ public class UserAccountManagerImpl implements UserAccountManager {
|
||||
accountManager.setUserData(account,
|
||||
com.owncloud.android.lib.common.accounts.AccountUtils.Constants.KEY_USER_ID,
|
||||
userId);
|
||||
|
||||
success = true;
|
||||
}
|
||||
|
||||
return failed == 0;
|
||||
return success;
|
||||
}
|
||||
|
||||
private String getAccountType() {
|
||||
return context.getString(R.string.account_type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startAccountCreation(final Activity activity) {
|
||||
accountManager.addAccount(getAccountType(),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
activity,
|
||||
null,
|
||||
null);
|
||||
}
|
||||
}
|
||||
@@ -36,8 +36,6 @@ public interface AppInfo {
|
||||
*/
|
||||
String getFormattedVersionCode();
|
||||
|
||||
int getVersionCode();
|
||||
|
||||
boolean isDebugBuild();
|
||||
|
||||
String getAppVersion(Context context);
|
||||
|
||||
@@ -33,11 +33,6 @@ class AppInfoImpl implements AppInfo {
|
||||
return Integer.toString(BuildConfig.VERSION_CODE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getVersionCode() {
|
||||
return BuildConfig.VERSION_CODE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugBuild() {
|
||||
return BuildConfig.DEBUG;
|
||||
|
||||
@@ -28,14 +28,5 @@ typealias OnErrorCallback = (Throwable) -> Unit
|
||||
* It is provided as an alternative for heavy, platform specific and virtually untestable [android.os.AsyncTask]
|
||||
*/
|
||||
interface AsyncRunner {
|
||||
|
||||
/**
|
||||
* Post a background task and return immediately returning task cancellation interface.
|
||||
*
|
||||
* @param task Task function returning result T; error shall be signalled by throwing an exception.
|
||||
* @param onResult Callback called when task function returns a result
|
||||
* @param onError Callback called when task function throws an exception
|
||||
* @return Cancellable interface, allowing to cancel running task.
|
||||
*/
|
||||
fun <T> post(task: () -> T, onResult: OnResultCallback<T>? = null, onError: OnErrorCallback? = null): Cancellable
|
||||
}
|
||||
@@ -19,20 +19,6 @@
|
||||
*/
|
||||
package com.nextcloud.client.core
|
||||
|
||||
/**
|
||||
* Interface allowing cancellation of a running task.
|
||||
* Once must be careful when cancelling a non-idempotent task,
|
||||
* as cancellation does not guarantee a task termination.
|
||||
* One trivial case would be a task finished and cancelled
|
||||
* before result delivery.
|
||||
*
|
||||
* @see [com.nextcloud.client.core.AsyncRunner]
|
||||
*/
|
||||
interface Cancellable {
|
||||
|
||||
/**
|
||||
* Cancel running task. Task termination is not guaranteed, but the result
|
||||
* shall not be delivered.
|
||||
*/
|
||||
fun cancel()
|
||||
}
|
||||
@@ -23,6 +23,7 @@ package com.nextcloud.client.di;
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import dagger.android.AndroidInjection;
|
||||
@@ -71,3 +72,4 @@ public class ActivityInjector implements Application.ActivityLifecycleCallbacks
|
||||
// not needed
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import android.app.Application;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Handler;
|
||||
import android.media.AudioManager;
|
||||
@@ -33,7 +32,6 @@ import android.media.AudioManager;
|
||||
import com.nextcloud.client.account.CurrentAccountProvider;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.account.UserAccountManagerImpl;
|
||||
import com.nextcloud.client.appinfo.AppInfo;
|
||||
import com.nextcloud.client.core.AsyncRunner;
|
||||
import com.nextcloud.client.core.Clock;
|
||||
import com.nextcloud.client.core.ClockImpl;
|
||||
@@ -43,9 +41,6 @@ import com.nextcloud.client.logger.FileLogHandler;
|
||||
import com.nextcloud.client.logger.Logger;
|
||||
import com.nextcloud.client.logger.LoggerImpl;
|
||||
import com.nextcloud.client.logger.LogsRepository;
|
||||
import com.nextcloud.client.migrations.Migrations;
|
||||
import com.nextcloud.client.migrations.MigrationsManager;
|
||||
import com.nextcloud.client.migrations.MigrationsManagerImpl;
|
||||
import com.nextcloud.client.network.ClientFactory;
|
||||
import com.owncloud.android.datamodel.ArbitraryDataProvider;
|
||||
import com.owncloud.android.datamodel.UploadsStorageManager;
|
||||
@@ -57,8 +52,6 @@ import com.owncloud.android.ui.activities.data.files.FilesRepository;
|
||||
import com.owncloud.android.ui.activities.data.files.FilesServiceApiImpl;
|
||||
import com.owncloud.android.ui.activities.data.files.RemoteFilesRepository;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
@@ -171,26 +164,4 @@ class AppModule {
|
||||
AudioManager audioManager(Context context) {
|
||||
return (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
EventBus eventBus() {
|
||||
return EventBus.getDefault();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
Migrations migrations(UserAccountManager userAccountManager) {
|
||||
return new Migrations(userAccountManager);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
MigrationsManager migrationsManager(Application application,
|
||||
AppInfo appInfo,
|
||||
AsyncRunner asyncRunner,
|
||||
Migrations migrations) {
|
||||
SharedPreferences migrationsDb = application.getSharedPreferences("migrations", Context.MODE_PRIVATE);
|
||||
return new MigrationsManagerImpl(appInfo, migrationsDb, asyncRunner, migrations.getSteps());
|
||||
}
|
||||
}
|
||||
@@ -19,53 +19,23 @@
|
||||
*/
|
||||
package com.nextcloud.client.etm
|
||||
|
||||
import android.accounts.Account
|
||||
import android.accounts.AccountManager
|
||||
import android.content.SharedPreferences
|
||||
import android.content.res.Resources
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.nextcloud.client.etm.pages.EtmAccountsFragment
|
||||
import com.nextcloud.client.etm.pages.EtmPreferencesFragment
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.lib.common.accounts.AccountUtils
|
||||
import javax.inject.Inject
|
||||
|
||||
class EtmViewModel @Inject constructor(
|
||||
private val defaultPreferences: SharedPreferences,
|
||||
private val platformAccountManager: AccountManager,
|
||||
private val resources: Resources
|
||||
private val defaultPreferences: SharedPreferences
|
||||
) : ViewModel() {
|
||||
|
||||
companion object {
|
||||
val ACCOUNT_USER_DATA_KEYS = listOf(
|
||||
// AccountUtils.Constants.KEY_COOKIES, is disabled
|
||||
AccountUtils.Constants.KEY_DISPLAY_NAME,
|
||||
AccountUtils.Constants.KEY_OC_ACCOUNT_VERSION,
|
||||
AccountUtils.Constants.KEY_OC_BASE_URL,
|
||||
AccountUtils.Constants.KEY_OC_VERSION,
|
||||
AccountUtils.Constants.KEY_USER_ID
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* This data class holds all relevant account information that is
|
||||
* otherwise kept in separate collections.
|
||||
*/
|
||||
data class AccountData(val account: Account, val userData: Map<String, String?>)
|
||||
|
||||
val currentPage: LiveData<EtmMenuEntry?> = MutableLiveData()
|
||||
val pages: List<EtmMenuEntry> = listOf(
|
||||
EtmMenuEntry(
|
||||
iconRes = R.drawable.ic_settings,
|
||||
titleRes = R.string.etm_preferences,
|
||||
pageClass = EtmPreferencesFragment::class
|
||||
),
|
||||
EtmMenuEntry(
|
||||
iconRes = R.drawable.ic_user,
|
||||
titleRes = R.string.etm_accounts,
|
||||
pageClass = EtmAccountsFragment::class
|
||||
)
|
||||
)
|
||||
|
||||
@@ -76,16 +46,6 @@ class EtmViewModel @Inject constructor(
|
||||
.toMap()
|
||||
}
|
||||
|
||||
val accounts: List<AccountData> get() {
|
||||
val accountType = resources.getString(R.string.account_type)
|
||||
return platformAccountManager.getAccountsByType(accountType).map { account ->
|
||||
val userData: Map<String, String?> = ACCOUNT_USER_DATA_KEYS.map { key ->
|
||||
key to platformAccountManager.getUserData(account, key)
|
||||
}.toMap()
|
||||
AccountData(account, userData)
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
(currentPage as MutableLiveData).apply {
|
||||
value = null
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Chris Narkiewicz
|
||||
* Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.nextcloud.client.etm.pages
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.nextcloud.client.etm.EtmBaseFragment
|
||||
import com.owncloud.android.R
|
||||
import kotlinx.android.synthetic.main.fragment_etm_accounts.*
|
||||
import kotlinx.android.synthetic.main.fragment_etm_preferences.*
|
||||
|
||||
class EtmAccountsFragment : EtmBaseFragment() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setHasOptionsMenu(true)
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
return inflater.inflate(R.layout.fragment_etm_accounts, container, false)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
val builder = StringBuilder()
|
||||
vm.accounts.forEach {
|
||||
builder.append("Account: ${it.account.name}\n")
|
||||
it.userData.forEach {
|
||||
builder.append("\t${it.key}: ${it.value}\n")
|
||||
}
|
||||
}
|
||||
etm_accounts_text.text = builder.toString()
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater)
|
||||
inflater.inflate(R.menu.fragment_etm_accounts, menu)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
R.id.etm_accounts_share -> {
|
||||
onClickedShare(); true
|
||||
}
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
|
||||
private fun onClickedShare() {
|
||||
val intent = Intent(Intent.ACTION_SEND)
|
||||
intent.putExtra(Intent.EXTRA_SUBJECT, "Nextcloud accounts information")
|
||||
intent.putExtra(Intent.EXTRA_TEXT, etm_accounts_text.text)
|
||||
intent.type = "text/plain"
|
||||
startActivity(intent)
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Chris Narkiewicz
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.nextcloud.client.migrations
|
||||
|
||||
class MigrationError(val id: Int, message: String, cause: Throwable?) : RuntimeException(message, cause) {
|
||||
constructor(id: Int, message: String) : this(id, message, null)
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Chris Narkiewicz
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.nextcloud.client.migrations
|
||||
|
||||
import com.nextcloud.client.account.UserAccountManager
|
||||
import javax.inject.Inject
|
||||
import kotlin.IllegalStateException
|
||||
|
||||
/**
|
||||
* This class collects all migration steps and provides API to supply those
|
||||
* steps to [MigrationsManager] for execution.
|
||||
*
|
||||
* Note to maintainers: put all migration routines here and export collection of
|
||||
* opaque [Runnable]s via steps property.
|
||||
*/
|
||||
class Migrations @Inject constructor(
|
||||
private val userAccountManager: UserAccountManager
|
||||
) {
|
||||
|
||||
/**
|
||||
* @param id Step id; id must be unique
|
||||
* @param description Human readable migration step description
|
||||
* @param function Migration runnable object
|
||||
* @param mandatory If true, failing migration will cause an exception; if false, it will be skipped and repeated
|
||||
* again on next startup
|
||||
*/
|
||||
data class Step(val id: Int, val description: String, val function: Runnable, val mandatory: Boolean = true)
|
||||
|
||||
/**
|
||||
* List of migration steps. Those steps will be loaded and run by [MigrationsManager]
|
||||
*/
|
||||
val steps: List<Step> = listOf(
|
||||
Step(0, "migrate user id", Runnable { migrateUserId() }, false)
|
||||
).sortedBy { it.id }
|
||||
|
||||
fun migrateUserId() {
|
||||
val allAccountsHaveUserId = userAccountManager.migrateUserId()
|
||||
if (!allAccountsHaveUserId) {
|
||||
throw IllegalStateException("Failed to set user id for all accounts")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Chris Narkiewicz
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.nextcloud.client.migrations
|
||||
|
||||
import androidx.annotation.MainThread
|
||||
import androidx.lifecycle.LiveData
|
||||
|
||||
/**
|
||||
* This component allows starting and monitoring of application state migrations.
|
||||
* Migrations are intended to upgrade any existing, persisted application state
|
||||
* after upgrade to new version, similarly to database migrations.
|
||||
*/
|
||||
interface MigrationsManager {
|
||||
|
||||
enum class Status {
|
||||
/**
|
||||
* Application migration was not evaluated yet. This is the default
|
||||
* state just after [android.app.Application] start
|
||||
*/
|
||||
UNKNOWN,
|
||||
|
||||
/**
|
||||
* All migrations applied successfully.
|
||||
*/
|
||||
APPLIED,
|
||||
|
||||
/**
|
||||
* Migration in progress.
|
||||
*/
|
||||
RUNNING,
|
||||
|
||||
/**
|
||||
* Migration failed. Application is in undefined state.
|
||||
*/
|
||||
FAILED
|
||||
}
|
||||
|
||||
/**
|
||||
* Listenable migration progress.
|
||||
*/
|
||||
val status: LiveData<Status>
|
||||
|
||||
/**
|
||||
* Starts application state migration. Migrations will be run in background thread.
|
||||
* Callers can use [status] to monitor migration progress.
|
||||
*
|
||||
* Although the migration process is run in background, status is updated
|
||||
* immediately and can be accessed immediately after start.
|
||||
*
|
||||
* @return Number of migration steps enqueued; 0 if no migrations were started.
|
||||
*/
|
||||
@Throws(MigrationError::class)
|
||||
@MainThread
|
||||
fun startMigration(): Int
|
||||
}
|
||||
@@ -1,138 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Chris Narkiewicz
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.nextcloud.client.migrations
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import androidx.annotation.MainThread
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.nextcloud.client.appinfo.AppInfo
|
||||
import com.nextcloud.client.core.AsyncRunner
|
||||
import com.nextcloud.client.migrations.MigrationsManager.Status
|
||||
import java.util.TreeSet
|
||||
|
||||
internal class MigrationsManagerImpl(
|
||||
private val appInfo: AppInfo,
|
||||
private val migrationsDb: SharedPreferences,
|
||||
private val asyncRunner: AsyncRunner,
|
||||
private val migrations: Collection<Migrations.Step>
|
||||
) : MigrationsManager {
|
||||
|
||||
companion object {
|
||||
const val DB_KEY_LAST_MIGRATED_VERSION = "last_migrated_version"
|
||||
const val DB_KEY_APPLIED_MIGRATIONS = "applied_migrations"
|
||||
const val DB_KEY_FAILED = "failed"
|
||||
const val DB_KEY_FAILED_MIGRATION_ID = "failed_migration_id"
|
||||
const val DB_KEY_FAILED_MIGRATION_ERROR_MESSAGE = "failed_migration_error"
|
||||
}
|
||||
|
||||
override val status: LiveData<Status>
|
||||
|
||||
init {
|
||||
this.status = MutableLiveData<Status>(Status.UNKNOWN)
|
||||
}
|
||||
|
||||
fun getAppliedMigrations(): List<Int> {
|
||||
val appliedIdsStr: Set<String> = migrationsDb.getStringSet(DB_KEY_APPLIED_MIGRATIONS, null) ?: TreeSet()
|
||||
return appliedIdsStr.mapNotNull {
|
||||
try {
|
||||
it.toInt()
|
||||
} catch (_: NumberFormatException) {
|
||||
null
|
||||
}
|
||||
}.sorted()
|
||||
}
|
||||
|
||||
fun addAppliedMigration(vararg migrations: Int) {
|
||||
val oldApplied = migrationsDb.getStringSet(DB_KEY_APPLIED_MIGRATIONS, null) ?: TreeSet()
|
||||
val newApplied = TreeSet<String>().apply {
|
||||
addAll(oldApplied)
|
||||
addAll(migrations.map { it.toString() })
|
||||
}
|
||||
migrationsDb.edit().putStringSet(DB_KEY_APPLIED_MIGRATIONS, newApplied).apply()
|
||||
}
|
||||
|
||||
@Throws(MigrationError::class)
|
||||
@Suppress("ReturnCount")
|
||||
override fun startMigration(): Int {
|
||||
|
||||
if (migrationsDb.getBoolean(DB_KEY_FAILED, false)) {
|
||||
(status as MutableLiveData<Status>).value = Status.FAILED
|
||||
return 0
|
||||
}
|
||||
val lastMigratedVersion = migrationsDb.getInt(DB_KEY_LAST_MIGRATED_VERSION, -1)
|
||||
if (lastMigratedVersion >= appInfo.versionCode) {
|
||||
(status as MutableLiveData<Status>).value = Status.APPLIED
|
||||
return 0
|
||||
}
|
||||
val applied = getAppliedMigrations()
|
||||
val toApply = migrations.filter { !applied.contains(it.id) }
|
||||
if (toApply.isEmpty()) {
|
||||
onMigrationSuccess()
|
||||
return 0
|
||||
}
|
||||
(status as MutableLiveData<Status>).value = Status.RUNNING
|
||||
asyncRunner.post(
|
||||
task = { asyncApplyMigrations(toApply) },
|
||||
onResult = { onMigrationSuccess() },
|
||||
onError = { onMigrationFailed(it) }
|
||||
)
|
||||
return toApply.size
|
||||
}
|
||||
|
||||
/**
|
||||
* This method calls all pending migrations which can execute long-blocking code.
|
||||
* It should be run in a background thread.
|
||||
*/
|
||||
private fun asyncApplyMigrations(migrations: Collection<Migrations.Step>) {
|
||||
migrations.forEach {
|
||||
@Suppress("TooGenericExceptionCaught") // migration code is free to throw anything
|
||||
try {
|
||||
it.function.run()
|
||||
addAppliedMigration(it.id)
|
||||
} catch (t: Throwable) {
|
||||
if (it.mandatory) {
|
||||
throw MigrationError(id = it.id, message = t.message ?: t.javaClass.simpleName)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MainThread
|
||||
private fun onMigrationFailed(error: Throwable) {
|
||||
val id = when (error) {
|
||||
is MigrationError -> error.id
|
||||
else -> -1
|
||||
}
|
||||
migrationsDb
|
||||
.edit()
|
||||
.putBoolean(DB_KEY_FAILED, true)
|
||||
.putString(DB_KEY_FAILED_MIGRATION_ERROR_MESSAGE, error.message)
|
||||
.putInt(DB_KEY_FAILED_MIGRATION_ID, id)
|
||||
.apply()
|
||||
(status as MutableLiveData<Status>).value = Status.FAILED
|
||||
}
|
||||
|
||||
@MainThread
|
||||
private fun onMigrationSuccess() {
|
||||
migrationsDb.edit().putInt(DB_KEY_LAST_MIGRATED_VERSION, appInfo.versionCode).apply()
|
||||
(status as MutableLiveData<Status>).value = Status.APPLIED
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
# Package com.nextcloud.client.migrations
|
||||
|
||||
This package provides utitilies to migrate application state
|
||||
during version upgrade.
|
||||
|
||||
Migrations are registered upon run so they can be run only once.
|
||||