Compare commits
2 commits
Author | SHA1 | Date | |
---|---|---|---|
|
b467fc41e2 | ||
|
4a37909599 |
543 changed files with 8967 additions and 26666 deletions
28
.cirrus.yml
28
.cirrus.yml
|
@ -1,14 +1,15 @@
|
|||
container:
|
||||
image: ghcr.io/cirruslabs/android-sdk:34
|
||||
image: ghcr.io/cirruslabs/android-sdk:33
|
||||
kvm: true
|
||||
cpu: 8
|
||||
memory: 16G
|
||||
|
||||
instrumentation_tests_task:
|
||||
name: "Cirrus CI Instrumentation Tests"
|
||||
skip: "!changesInclude('.cirrus.yml', '*.gradle', '*.gradle.kts', '**/*.gradle', '**/*.gradle.kts', '*.properties', '**/*.properties', '**/*.kt', '**/*.xml')"
|
||||
start_avd_background_script:
|
||||
sdkmanager --install "system-images;android-34;default;x86_64" "emulator";
|
||||
echo no | avdmanager create avd -n seedvault -k "system-images;android-34;default;x86_64";
|
||||
sdkmanager --install "system-images;android-33;google_apis;x86_64";
|
||||
echo no | avdmanager create avd -n seedvault -k "system-images;android-33;google_apis;x86_64";
|
||||
$ANDROID_HOME/emulator/emulator
|
||||
-avd seedvault
|
||||
-no-audio
|
||||
|
@ -18,7 +19,7 @@ instrumentation_tests_task:
|
|||
-no-window
|
||||
-writable-system;
|
||||
provision_avd_background_script:
|
||||
wget https://github.com/seedvault-app/seedvault-test-data/releases/download/3/backup.tar.gz;
|
||||
wget https://github.com/seedvault-app/seedvault-test-data/releases/download/1/backup.tar.gz;
|
||||
|
||||
adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;';
|
||||
adb root;
|
||||
|
@ -31,7 +32,7 @@ instrumentation_tests_task:
|
|||
adb remount;
|
||||
sleep 5;
|
||||
assemble_script:
|
||||
./gradlew :app:assembleRelease :contacts:assembleRelease assembleAndroidTest
|
||||
./gradlew :app:assembleRelease :app:assembleAndroidTest
|
||||
install_app_script:
|
||||
timeout 180s bash -c 'while [[ -z $(adb shell mount | grep "/system " | grep "(rw,") ]]; do sleep 1; done;';
|
||||
adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;';
|
||||
|
@ -44,23 +45,14 @@ instrumentation_tests_task:
|
|||
adb push app/build/outputs/apk/release/app-release.apk /system/priv-app/Seedvault/Seedvault.apk;
|
||||
adb push permissions_com.stevesoltys.seedvault.xml /system/etc/permissions/privapp-permissions-seedvault.xml;
|
||||
adb push allowlist_com.stevesoltys.seedvault.xml /system/etc/sysconfig/allowlist-seedvault.xml;
|
||||
|
||||
adb shell mkdir -p /system/priv-app/ContactsBackup;
|
||||
adb push contactsbackup/build/outputs/apk/release/contactsbackup-release.apk /system/priv-app/ContactsBackup/contactsbackup.apk;
|
||||
adb push contactsbackup/default-permissions_org.calyxos.backup.contacts.xml /system/etc/default-permissions/default-permissions_org.calyxos.backup.contacts.xml;
|
||||
|
||||
adb shell bmgr enable true;
|
||||
adb reboot;
|
||||
adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;';
|
||||
adb shell bmgr transport com.stevesoltys.seedvault.transport.ConfigurableBackupTransport;
|
||||
adb reboot;
|
||||
adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;';
|
||||
run_large_tests_script: ./gradlew -Pandroid.testInstrumentationRunnerArguments.size=large :app:connectedAndroidTest
|
||||
run_other_tests_script: ./gradlew -Pandroid.testInstrumentationRunnerArguments.notAnnotation=androidx.test.filters.LargeTest connectedAndroidTest
|
||||
run_large_tests_script: ./gradlew -Pinstrumented_test_size=large :app:connectedAndroidTest
|
||||
run_medium_tests_script: ./gradlew -Pinstrumented_test_size=medium :app:connectedAndroidTest
|
||||
always:
|
||||
pull_screenshots_script:
|
||||
adb pull /sdcard/seedvault_test_results
|
||||
adb pull /sdcard/seedvault_test_videos
|
||||
screenshots_artifacts:
|
||||
path: "seedvault_test_results/**/*.mp4"
|
||||
logcat_artifacts:
|
||||
path: "seedvault_test_results/**/*.log"
|
||||
path: "seedvault_test_videos/**/*.mp4"
|
||||
|
|
97
.github/scripts/build_aosp.sh
vendored
97
.github/scripts/build_aosp.sh
vendored
|
@ -1,97 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# SPDX-FileCopyrightText: 2023 The Calyx Institute
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
apt-get update
|
||||
apt-get install -y git-core gnupg flex bison build-essential zip curl zlib1g-dev \
|
||||
libc6-dev-i386 libncurses5 x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev \
|
||||
libxml2-utils xsltproc unzip fontconfig python3 npm pip e2fsprogs python3-protobuf \
|
||||
fonts-dejavu diffutils rsync ccache
|
||||
|
||||
npm install --global yarn
|
||||
|
||||
mkdir -p ~/bin
|
||||
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
|
||||
chmod a+x ~/bin/repo
|
||||
ln -s /usr/bin/python3 /usr/bin/python
|
||||
export PATH=~/bin:$PATH
|
||||
|
||||
set -e
|
||||
|
||||
retry() {
|
||||
set +e
|
||||
local max_attempts=${ATTEMPTS-5}
|
||||
local timeout=${TIMEOUT-1}
|
||||
local attempt=0
|
||||
local exitCode=0
|
||||
|
||||
while [[ $attempt < $max_attempts ]]
|
||||
do
|
||||
"$@"
|
||||
exitCode=$?
|
||||
|
||||
if [[ $exitCode == 0 ]]
|
||||
then
|
||||
break
|
||||
fi
|
||||
|
||||
echo "Failure! Retrying ($*) in $timeout.."
|
||||
sleep "${timeout}"
|
||||
attempt=$(( attempt + 1 ))
|
||||
timeout=$(( timeout * 2 ))
|
||||
done
|
||||
|
||||
if [[ $exitCode != 0 ]]
|
||||
then
|
||||
echo "Failed too many times! ($*)"
|
||||
fi
|
||||
|
||||
set -e
|
||||
|
||||
return $exitCode
|
||||
}
|
||||
|
||||
DEVICE=$1
|
||||
RELEASE=$2
|
||||
TARGET=$3
|
||||
BRANCH=$4
|
||||
|
||||
git config --global user.email "seedvault@example.com"
|
||||
git config --global user.name "Seedvault CI"
|
||||
|
||||
retry curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
|
||||
chmod a+x ~/bin/repo
|
||||
|
||||
mkdir -p /aosp
|
||||
cd /aosp
|
||||
retry yes | repo init -u https://android.googlesource.com/platform/manifest -b "$BRANCH" --depth=1
|
||||
|
||||
mkdir -p .repo/local_manifests
|
||||
cat << EOF > .repo/local_manifests/seedvault.xml
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<manifest>
|
||||
|
||||
<remote name="seedvault"
|
||||
fetch="https://github.com/$CIRRUS_REPO_OWNER" />
|
||||
|
||||
<project name="seedvault" path="external/seedvault"
|
||||
revision="$CIRRUS_CHANGE_IN_REPO" remote="$CIRRUS_REPO_NAME" />
|
||||
|
||||
</manifest>
|
||||
EOF
|
||||
|
||||
retry repo sync -c -j8 --fail-fast --force-sync
|
||||
|
||||
# Cirrus CI seems to (possibly) reschedule tasks that aren't sending out logs for a while?
|
||||
while true; do echo "Still building..."; sleep 30; done &
|
||||
|
||||
source build/envsetup.sh
|
||||
lunch $DEVICE-$RELEASE-$TARGET
|
||||
m -j1 nothing
|
||||
m -j2 Seedvault
|
||||
|
||||
mv /aosp/out/target/product/generic_arm64/system/system_ext/priv-app/Seedvault/Seedvault.apk "$CIRRUS_WORKING_DIR"
|
31
.github/scripts/run_tests.sh
vendored
31
.github/scripts/run_tests.sh
vendored
|
@ -1,31 +0,0 @@
|
|||
#
|
||||
# SPDX-FileCopyrightText: 2023 The Calyx Institute
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
echo "Disable auto-restore"
|
||||
adb shell bmgr autorestore false
|
||||
|
||||
echo "Installing Seedvault app..."
|
||||
./gradlew --stacktrace :app:installDebugAndroidTest
|
||||
sleep 60
|
||||
|
||||
large_test_exit_code=0
|
||||
./gradlew --stacktrace -Pinstrumented_test_size=large :app:connectedAndroidTest || large_test_exit_code=$?
|
||||
|
||||
adb pull /sdcard/seedvault_test_results
|
||||
|
||||
if [ "$large_test_exit_code" -ne 0 ]; then
|
||||
echo 'Large tests failed.'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
medium_test_exit_code=0
|
||||
./gradlew --stacktrace -Pinstrumented_test_size=medium :app:connectedAndroidTest || medium_test_exit_code=$?
|
||||
|
||||
if [ "$medium_test_exit_code" -ne 0 ]; then
|
||||
echo 'Medium tests failed.'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exit 0
|
|
@ -1,14 +1,5 @@
|
|||
name: Build
|
||||
on: [ push, pull_request ]
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
actions: read
|
||||
checks: write
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
@ -34,14 +25,7 @@ jobs:
|
|||
java-version: 17
|
||||
cache: 'gradle'
|
||||
|
||||
- name: Validate Gradle Wrapper
|
||||
uses: gradle/actions/wrapper-validation@v3
|
||||
|
||||
- name: Build
|
||||
env:
|
||||
NEXTCLOUD_URL: ${{ vars.NEXTCLOUD_URL }}
|
||||
NEXTCLOUD_USER: ${{ secrets.NEXTCLOUD_USER }}
|
||||
NEXTCLOUD_PASS: ${{ secrets.NEXTCLOUD_PASS }}
|
||||
run: ./gradlew compileDebugAndroidTestSources check assemble ktlintCheck
|
||||
|
||||
- name: Upload APKs
|
||||
|
@ -52,10 +36,3 @@ jobs:
|
|||
app/build/outputs/apk/debug/app-debug.apk
|
||||
contactsbackup/build/outputs/apk/debug/contactsbackup-debug.apk
|
||||
storage/demo/build/outputs/apk/debug/demo-debug.apk
|
||||
|
||||
- name: Publish Test Report
|
||||
uses: mikepenz/action-junit-report@v4
|
||||
if: success() || failure()
|
||||
with:
|
||||
report_paths: '**/build/test-results/**/TEST-*.xml'
|
||||
|
62
.github/workflows/test.yml
vendored
62
.github/workflows/test.yml
vendored
|
@ -1,62 +0,0 @@
|
|||
name: Run instrumentation tests
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- android*
|
||||
pull_request:
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
instrumentation_tests:
|
||||
runs-on: macos-12
|
||||
if: github.repository == 'seedvault-app/seedvault'
|
||||
timeout-minutes: 80
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
android_target: [ 34 ]
|
||||
emulator_type: [ aosp_atd ]
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: 'adopt'
|
||||
java-version: '17'
|
||||
cache: 'gradle'
|
||||
|
||||
- name: Build Release APK
|
||||
run: ./gradlew :app:assembleRelease
|
||||
|
||||
- name: Assemble tests
|
||||
run: ./gradlew :app:assembleAndroidTest
|
||||
|
||||
- name: Run tests
|
||||
uses: Wandalen/wretry.action@v1.3.0
|
||||
with:
|
||||
attempt_limit: 1
|
||||
action: reactivecircus/android-emulator-runner@v2
|
||||
with: |
|
||||
api-level: ${{ matrix.android_target }}
|
||||
target: ${{ matrix.emulator_type }}
|
||||
arch: x86_64
|
||||
force-avd-creation: true
|
||||
emulator-options: -cores 2 -writable-system -no-snapshot-load -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
|
||||
disk-size: '14G'
|
||||
sdcard-path-or-size: '4096M'
|
||||
disable-animations: true
|
||||
script: |
|
||||
./app/development/scripts/provision_emulator.sh "test" "system-images;android-${{ matrix.android_target }};${{ matrix.emulator_type }};x86_64"
|
||||
./.github/scripts/run_tests.sh
|
||||
|
||||
- name: Upload test results
|
||||
if: always()
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: ${{ matrix.emulator_type }}-${{ matrix.android_target }}-results
|
||||
path: seedvault_test_results/**/*
|
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -6,9 +6,6 @@ hs_err_pid*
|
|||
|
||||
## Intellij
|
||||
out/
|
||||
build/
|
||||
storage/build/
|
||||
contactsbackup/build/
|
||||
/lib/
|
||||
.idea/*
|
||||
!.idea/runConfigurations*
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<JetCodeStyleSettings>
|
||||
<option name="LINE_BREAK_AFTER_MULTILINE_WHEN_ENTRY" value="false" />
|
||||
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
|
||||
<value />
|
||||
</option>
|
||||
<option name="NAME_COUNT_TO_USE_STAR_IMPORT" value="2147483647" />
|
||||
<option name="NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS" value="2147483647" />
|
||||
<option name="ALLOW_TRAILING_COMMA" value="true" />
|
||||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||
</JetCodeStyleSettings>
|
||||
<codeStyleSettings language="XML">
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
<w>ejectable</w>
|
||||
<w>hasher</w>
|
||||
<w>hkdf</w>
|
||||
<w>launchable</w>
|
||||
<w>restorable</w>
|
||||
<w>seedvault</w>
|
||||
<w>snowden</w>
|
||||
|
|
|
@ -1,66 +0,0 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="app" type="AndroidRunConfigurationType" factoryName="Android App" singleton="true">
|
||||
<module name="seedvault.Seedvault.app.main" />
|
||||
<option name="DEPLOY" value="true" />
|
||||
<option name="DEPLOY_APK_FROM_BUNDLE" value="false" />
|
||||
<option name="DEPLOY_AS_INSTANT" value="false" />
|
||||
<option name="ARTIFACT_NAME" value="" />
|
||||
<option name="PM_INSTALL_OPTIONS" value="" />
|
||||
<option name="ALL_USERS" value="false" />
|
||||
<option name="ALWAYS_INSTALL_WITH_PM" value="true" />
|
||||
<option name="CLEAR_APP_STORAGE" value="false" />
|
||||
<option name="DYNAMIC_FEATURES_DISABLED_LIST" value="" />
|
||||
<option name="ACTIVITY_EXTRA_FLAGS" value="" />
|
||||
<option name="MODE" value="default_activity" />
|
||||
<option name="CLEAR_LOGCAT" value="false" />
|
||||
<option name="SHOW_LOGCAT_AUTOMATICALLY" value="false" />
|
||||
<option name="TARGET_SELECTION_MODE" value="DEVICE_AND_SNAPSHOT_COMBO_BOX" />
|
||||
<option name="DEBUGGER_TYPE" value="Auto" />
|
||||
<Auto>
|
||||
<option name="USE_JAVA_AWARE_DEBUGGER" value="false" />
|
||||
<option name="SHOW_STATIC_VARS" value="true" />
|
||||
<option name="WORKING_DIR" value="" />
|
||||
<option name="TARGET_LOGGING_CHANNELS" value="lldb process:gdb-remote packets" />
|
||||
<option name="SHOW_OPTIMIZED_WARNING" value="true" />
|
||||
<option name="ATTACH_ON_WAIT_FOR_DEBUGGER" value="false" />
|
||||
<option name="DEBUG_SANDBOX_SDK" value="false" />
|
||||
</Auto>
|
||||
<Hybrid>
|
||||
<option name="USE_JAVA_AWARE_DEBUGGER" value="false" />
|
||||
<option name="SHOW_STATIC_VARS" value="true" />
|
||||
<option name="WORKING_DIR" value="" />
|
||||
<option name="TARGET_LOGGING_CHANNELS" value="lldb process:gdb-remote packets" />
|
||||
<option name="SHOW_OPTIMIZED_WARNING" value="true" />
|
||||
<option name="ATTACH_ON_WAIT_FOR_DEBUGGER" value="false" />
|
||||
<option name="DEBUG_SANDBOX_SDK" value="false" />
|
||||
</Hybrid>
|
||||
<Java>
|
||||
<option name="ATTACH_ON_WAIT_FOR_DEBUGGER" value="false" />
|
||||
<option name="DEBUG_SANDBOX_SDK" value="false" />
|
||||
</Java>
|
||||
<Native>
|
||||
<option name="USE_JAVA_AWARE_DEBUGGER" value="false" />
|
||||
<option name="SHOW_STATIC_VARS" value="true" />
|
||||
<option name="WORKING_DIR" value="" />
|
||||
<option name="TARGET_LOGGING_CHANNELS" value="lldb process:gdb-remote packets" />
|
||||
<option name="SHOW_OPTIMIZED_WARNING" value="true" />
|
||||
<option name="ATTACH_ON_WAIT_FOR_DEBUGGER" value="false" />
|
||||
<option name="DEBUG_SANDBOX_SDK" value="false" />
|
||||
</Native>
|
||||
<Profilers>
|
||||
<option name="ADVANCED_PROFILING_ENABLED" value="false" />
|
||||
<option name="STARTUP_PROFILING_ENABLED" value="false" />
|
||||
<option name="STARTUP_CPU_PROFILING_ENABLED" value="false" />
|
||||
<option name="STARTUP_CPU_PROFILING_CONFIGURATION_NAME" value="Java/Kotlin Method Sample (legacy)" />
|
||||
<option name="STARTUP_NATIVE_MEMORY_PROFILING_ENABLED" value="false" />
|
||||
<option name="NATIVE_MEMORY_SAMPLE_RATE_BYTES" value="2048" />
|
||||
</Profilers>
|
||||
<option name="DEEP_LINK" value="" />
|
||||
<option name="ACTIVITY_CLASS" value="" />
|
||||
<option name="SEARCH_ACTIVITY_IN_GLOBAL_SCOPE" value="false" />
|
||||
<option name="SKIP_ACTIVITY_VALIDATION" value="false" />
|
||||
<method v="2">
|
||||
<option name="Android.Gradle.BeforeRunTask" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
</component>
|
43
.reuse/dep5
43
.reuse/dep5
|
@ -3,39 +3,6 @@ Upstream-Name: Seedvault
|
|||
Upstream-Contact: The Calyx Institute
|
||||
Source: https://github.com/seedvault-app/seedvault
|
||||
|
||||
Files: .github/workflows/build.yml
|
||||
.github/workflows/client.yml
|
||||
.github/workflows/test.yml
|
||||
.gitignore
|
||||
CHANGELOG.md README.md app/development/DEVELOPMENT.md
|
||||
Copyright: 2017-2020 Steve Soltys
|
||||
2020 The Calyx Institute
|
||||
License: Apache-2.0
|
||||
|
||||
Files: .cirrus.yml .editorconfig .idea/*
|
||||
app/platform.jks app/development/platform.jks
|
||||
app/src/main/res/values-*/strings.xml
|
||||
Copyright: 2020 The Calyx Institute
|
||||
License: Apache-2.0
|
||||
|
||||
Files: libs/dav4jvm/dav4jvm-2.2.1.jar
|
||||
Copyright: 2024 bitfire web engineering
|
||||
License: MPL-2.0
|
||||
|
||||
Files: libs/dav4jvm/okhttp-4.11.0.jar
|
||||
libs/dav4jvm/okio-jvm-3.7.0.jar
|
||||
Copyright: 2024 Square, Inc.
|
||||
License: Apache-2.0
|
||||
|
||||
Files: libs/koin-android/koin-android-3.2.0.aar
|
||||
libs/koin-android/koin-core-jvm-3.2.0.jar
|
||||
Copyright: 2022 insert-koin.io
|
||||
License: Apache-2.0
|
||||
|
||||
Files: libs/kotlin-bip39-jvm-1.0.6.jar
|
||||
Copyright: 2020 Zcash
|
||||
License: MIT
|
||||
|
||||
Files: contactsbackup/*.gitignore contactsbackup/*.md
|
||||
contactsbackup/src/main/res/values-*/strings.xml
|
||||
Copyright: 2020 The Calyx Institute
|
||||
|
@ -51,7 +18,7 @@ Files: storage/*.gitignore storage/*.md
|
|||
Copyright: 2021 The Calyx Institute
|
||||
License: Apache-2.0
|
||||
|
||||
Files: storage/lib/libs/tink-android-1.10.0.jar
|
||||
Files: storage/lib/libs/tink-android-1.7.0.jar
|
||||
Copyright: 2022 Google LLC
|
||||
License: Apache-2.0
|
||||
|
||||
|
@ -62,11 +29,3 @@ License: CC-BY-SA-3.0
|
|||
Files: storage/demo/src/main/ic_launcher-playstore.png
|
||||
Copyright: Material Design Authors / Google LLC
|
||||
License: Apache-2.0
|
||||
|
||||
Files: gradle/wrapper/*
|
||||
Copyright: 2007-2023 Gradle, Inc.
|
||||
License: Apache-2.0
|
||||
|
||||
Files: gradlew*
|
||||
Copyright: 2007-2023 Gradle, Inc.
|
||||
License: Apache-2.0
|
||||
|
|
38
Android.bp
38
Android.bp
|
@ -1,6 +1,17 @@
|
|||
//
|
||||
// SPDX-FileCopyrightText: 2020 The Calyx Institute
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright (C) 2018 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
android_app {
|
||||
|
@ -8,44 +19,24 @@ android_app {
|
|||
srcs: [
|
||||
"app/src/main/java/**/*.kt",
|
||||
"app/src/main/java/**/*.java",
|
||||
"app/src/main/proto/*.proto",
|
||||
// as of Android 15, there is no way to pass --kotlin_out to aprotoc compiler
|
||||
"app/build/generated/source/proto/debug/kotlin/com/stevesoltys/seedvault/proto/*.kt",
|
||||
],
|
||||
resource_dirs: [
|
||||
"app/src/main/res",
|
||||
],
|
||||
asset_dirs: [
|
||||
"app/src/main/assets"
|
||||
],
|
||||
proto: {
|
||||
type: "lite",
|
||||
local_include_dirs: ["app/src/main/proto"],
|
||||
},
|
||||
static_libs: [
|
||||
"kotlin-stdlib-jdk8",
|
||||
"libprotobuf-java-lite",
|
||||
"androidx.core_core-ktx",
|
||||
"androidx.fragment_fragment-ktx",
|
||||
"androidx.activity_activity-ktx",
|
||||
"androidx.preference_preference",
|
||||
"androidx.documentfile_documentfile",
|
||||
"androidx.work_work-runtime-ktx",
|
||||
"androidx.lifecycle_lifecycle-viewmodel-ktx",
|
||||
"androidx.lifecycle_lifecycle-livedata-ktx",
|
||||
"androidx-constraintlayout_constraintlayout",
|
||||
"com.google.android.material_material",
|
||||
"kotlinx-coroutines-android",
|
||||
"kotlinx-coroutines-core",
|
||||
"seedvault-lib-kotlin-logging-jvm",
|
||||
// app backup related libs
|
||||
"seedvault-lib-protobuf-kotlin-lite",
|
||||
"seedvault-logback-android",
|
||||
"seedvault-lib-chunker",
|
||||
"seedvault-lib-zstd-jni",
|
||||
"okio-lib",
|
||||
// our own gradle module libs
|
||||
"seedvault-lib-core",
|
||||
// storage backup lib
|
||||
"seedvault-lib-storage",
|
||||
// koin
|
||||
"seedvault-lib-koin-core-jvm", // did not manage to add this as transitive dependency
|
||||
|
@ -53,7 +44,6 @@ android_app {
|
|||
// bip39
|
||||
"seedvault-lib-kotlin-bip39",
|
||||
],
|
||||
use_embedded_native_libs: true,
|
||||
manifest: "app/src/main/AndroidManifest.xml",
|
||||
|
||||
platform_apis: true,
|
||||
|
|
38
CHANGELOG.md
38
CHANGELOG.md
|
@ -1,41 +1,3 @@
|
|||
## [15-5.0] - 2024-10-15
|
||||
* First Android 15 release
|
||||
* New backup format using compression and deduplication
|
||||
* Can still restore old backups, but old Seedvault can't restore backups from this version
|
||||
* Faster and more reliable backups making snapshots that can individually be restored
|
||||
* Auto-cleaning of old backups
|
||||
* All backups now mimic device-to-device (allowing backup for all apps)
|
||||
* All backups now use a high per-app app quota
|
||||
* App backup (for APKs) moved to expert settings
|
||||
* Show more information for backups available to restore
|
||||
* Fix "Waiting to back up..." showing for apps
|
||||
|
||||
## [14-4.1] - 2024-08-23
|
||||
* It is now possible to restore after setting up a profile
|
||||
* It is now possible to select what to restore (e.g. apps, files...)
|
||||
* Automatic backup scheduling can now be modified by the user
|
||||
* Native support for WebDAV
|
||||
* Support for RoundSync (if enabled by the OS)
|
||||
* Now in Material 3
|
||||
* Name of profile is now shown when selecting a backup to restore
|
||||
* Already installed apps are not reinstalled anymore
|
||||
* Already stored files do not create duplicates anymore
|
||||
* Respect policy when the installation of apps is disallowed
|
||||
* Storage backup is now beta instead of experimental
|
||||
* D2D is now alpha instead of experimental
|
||||
* Various corrections to the UI
|
||||
|
||||
## [14-4.0] - 2024-01-24
|
||||
* Add experimental support for forcing "D2D" transfer backups
|
||||
* Pretend to be a device-to-device transfer to allow backing up many apps which prevent backup
|
||||
* Stop backing up excluded app APKs
|
||||
* Show size of app backups in Backup Status screen
|
||||
* Slight improvements to color scheme
|
||||
* Development: Improve CI testing setup
|
||||
|
||||
## [14-3.3] - 2023-10-06
|
||||
* Android 14
|
||||
|
||||
## [13-3.3] - 2023-01-11
|
||||
* Mark Nextcloud as "Not recommended"
|
||||
* Warn before turning off backups
|
||||
|
|
202
LICENSE
Normal file
202
LICENSE
Normal file
|
@ -0,0 +1,202 @@
|
|||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [2019] [Steve Soltys]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
|
@ -1,235 +0,0 @@
|
|||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for software and other kinds of works, specifically designed to ensure cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, our General Public Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License which gives you legal permission to copy, distribute and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that improvements made in alternate versions of the program, if they receive widespread use, become available for other developers to incorporate. Many developers of free software are heartened and encouraged by the resulting cooperation. However, in the case of software used on network servers, this result may fail to come about. The GNU General Public License permits making a modified version and letting the public access it on a server without ever releasing its source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to ensure that, in such cases, the modified source code becomes available to the community. It requires the operator of a network server to provide the source code of the modified version running there to the users of that server. Therefore, public use of a modified version, on a publicly accessible server, gives the public access to the source code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and published by Affero, was designed to accomplish similar goals. This is a different license, not a version of the Affero GPL, but Affero has released a new version of the Affero GPL which permits relicensing under this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
"Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the Program, your modified version must prominently offer all users interacting with it remotely through a computer network (if your version supports such interaction) an opportunity to receive the Corresponding Source of your version by providing access to the Corresponding Source from a network server at no charge, through some standard or customary means of facilitating copying of software. This Corresponding Source shall include the Corresponding Source for any work covered by version 3 of the GNU General Public License that is incorporated pursuant to the following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the work with which it is combined will remain governed by version 3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of the GNU Affero General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU Affero General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU Affero General Public License, you may choose any version ever published by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future versions of the GNU Affero General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
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/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer network, you should also make sure that it provides a way for users to get its source. For example, if your program is a web application, its interface could display a "Source" link that leads users to an archive of the code. There are many ways you could offer source, and different solutions will be better for different programs; see section 13 for the specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU AGPL, see <http://www.gnu.org/licenses/>.
|
|
@ -1,232 +0,0 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright © 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
“This License” refers to version 3 of the GNU General Public License.
|
||||
|
||||
“Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
|
||||
|
||||
“The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations.
|
||||
|
||||
To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work.
|
||||
|
||||
A “covered work” means either the unmodified Program or a work based on the Program.
|
||||
|
||||
To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
|
||||
|
||||
To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work.
|
||||
|
||||
A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
|
||||
|
||||
The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”.
|
||||
|
||||
c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.
|
||||
|
||||
A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
|
||||
|
||||
“Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
“Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.
|
||||
|
||||
An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”.
|
||||
|
||||
A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.
|
||||
|
||||
A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an “about box”.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read <http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
|
@ -1,9 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) <year> <copyright holders>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -1,373 +0,0 @@
|
|||
Mozilla Public License Version 2.0
|
||||
==================================
|
||||
|
||||
1. Definitions
|
||||
--------------
|
||||
|
||||
1.1. "Contributor"
|
||||
means each individual or legal entity that creates, contributes to
|
||||
the creation of, or owns Covered Software.
|
||||
|
||||
1.2. "Contributor Version"
|
||||
means the combination of the Contributions of others (if any) used
|
||||
by a Contributor and that particular Contributor's Contribution.
|
||||
|
||||
1.3. "Contribution"
|
||||
means Covered Software of a particular Contributor.
|
||||
|
||||
1.4. "Covered Software"
|
||||
means Source Code Form to which the initial Contributor has attached
|
||||
the notice in Exhibit A, the Executable Form of such Source Code
|
||||
Form, and Modifications of such Source Code Form, in each case
|
||||
including portions thereof.
|
||||
|
||||
1.5. "Incompatible With Secondary Licenses"
|
||||
means
|
||||
|
||||
(a) that the initial Contributor has attached the notice described
|
||||
in Exhibit B to the Covered Software; or
|
||||
|
||||
(b) that the Covered Software was made available under the terms of
|
||||
version 1.1 or earlier of the License, but not also under the
|
||||
terms of a Secondary License.
|
||||
|
||||
1.6. "Executable Form"
|
||||
means any form of the work other than Source Code Form.
|
||||
|
||||
1.7. "Larger Work"
|
||||
means a work that combines Covered Software with other material, in
|
||||
a separate file or files, that is not Covered Software.
|
||||
|
||||
1.8. "License"
|
||||
means this document.
|
||||
|
||||
1.9. "Licensable"
|
||||
means having the right to grant, to the maximum extent possible,
|
||||
whether at the time of the initial grant or subsequently, any and
|
||||
all of the rights conveyed by this License.
|
||||
|
||||
1.10. "Modifications"
|
||||
means any of the following:
|
||||
|
||||
(a) any file in Source Code Form that results from an addition to,
|
||||
deletion from, or modification of the contents of Covered
|
||||
Software; or
|
||||
|
||||
(b) any new file in Source Code Form that contains any Covered
|
||||
Software.
|
||||
|
||||
1.11. "Patent Claims" of a Contributor
|
||||
means any patent claim(s), including without limitation, method,
|
||||
process, and apparatus claims, in any patent Licensable by such
|
||||
Contributor that would be infringed, but for the grant of the
|
||||
License, by the making, using, selling, offering for sale, having
|
||||
made, import, or transfer of either its Contributions or its
|
||||
Contributor Version.
|
||||
|
||||
1.12. "Secondary License"
|
||||
means either the GNU General Public License, Version 2.0, the GNU
|
||||
Lesser General Public License, Version 2.1, the GNU Affero General
|
||||
Public License, Version 3.0, or any later versions of those
|
||||
licenses.
|
||||
|
||||
1.13. "Source Code Form"
|
||||
means the form of the work preferred for making modifications.
|
||||
|
||||
1.14. "You" (or "Your")
|
||||
means an individual or a legal entity exercising rights under this
|
||||
License. For legal entities, "You" includes any entity that
|
||||
controls, is controlled by, or is under common control with You. For
|
||||
purposes of this definition, "control" means (a) the power, direct
|
||||
or indirect, to cause the direction or management of such entity,
|
||||
whether by contract or otherwise, or (b) ownership of more than
|
||||
fifty percent (50%) of the outstanding shares or beneficial
|
||||
ownership of such entity.
|
||||
|
||||
2. License Grants and Conditions
|
||||
--------------------------------
|
||||
|
||||
2.1. Grants
|
||||
|
||||
Each Contributor hereby grants You a world-wide, royalty-free,
|
||||
non-exclusive license:
|
||||
|
||||
(a) under intellectual property rights (other than patent or trademark)
|
||||
Licensable by such Contributor to use, reproduce, make available,
|
||||
modify, display, perform, distribute, and otherwise exploit its
|
||||
Contributions, either on an unmodified basis, with Modifications, or
|
||||
as part of a Larger Work; and
|
||||
|
||||
(b) under Patent Claims of such Contributor to make, use, sell, offer
|
||||
for sale, have made, import, and otherwise transfer either its
|
||||
Contributions or its Contributor Version.
|
||||
|
||||
2.2. Effective Date
|
||||
|
||||
The licenses granted in Section 2.1 with respect to any Contribution
|
||||
become effective for each Contribution on the date the Contributor first
|
||||
distributes such Contribution.
|
||||
|
||||
2.3. Limitations on Grant Scope
|
||||
|
||||
The licenses granted in this Section 2 are the only rights granted under
|
||||
this License. No additional rights or licenses will be implied from the
|
||||
distribution or licensing of Covered Software under this License.
|
||||
Notwithstanding Section 2.1(b) above, no patent license is granted by a
|
||||
Contributor:
|
||||
|
||||
(a) for any code that a Contributor has removed from Covered Software;
|
||||
or
|
||||
|
||||
(b) for infringements caused by: (i) Your and any other third party's
|
||||
modifications of Covered Software, or (ii) the combination of its
|
||||
Contributions with other software (except as part of its Contributor
|
||||
Version); or
|
||||
|
||||
(c) under Patent Claims infringed by Covered Software in the absence of
|
||||
its Contributions.
|
||||
|
||||
This License does not grant any rights in the trademarks, service marks,
|
||||
or logos of any Contributor (except as may be necessary to comply with
|
||||
the notice requirements in Section 3.4).
|
||||
|
||||
2.4. Subsequent Licenses
|
||||
|
||||
No Contributor makes additional grants as a result of Your choice to
|
||||
distribute the Covered Software under a subsequent version of this
|
||||
License (see Section 10.2) or under the terms of a Secondary License (if
|
||||
permitted under the terms of Section 3.3).
|
||||
|
||||
2.5. Representation
|
||||
|
||||
Each Contributor represents that the Contributor believes its
|
||||
Contributions are its original creation(s) or it has sufficient rights
|
||||
to grant the rights to its Contributions conveyed by this License.
|
||||
|
||||
2.6. Fair Use
|
||||
|
||||
This License is not intended to limit any rights You have under
|
||||
applicable copyright doctrines of fair use, fair dealing, or other
|
||||
equivalents.
|
||||
|
||||
2.7. Conditions
|
||||
|
||||
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
|
||||
in Section 2.1.
|
||||
|
||||
3. Responsibilities
|
||||
-------------------
|
||||
|
||||
3.1. Distribution of Source Form
|
||||
|
||||
All distribution of Covered Software in Source Code Form, including any
|
||||
Modifications that You create or to which You contribute, must be under
|
||||
the terms of this License. You must inform recipients that the Source
|
||||
Code Form of the Covered Software is governed by the terms of this
|
||||
License, and how they can obtain a copy of this License. You may not
|
||||
attempt to alter or restrict the recipients' rights in the Source Code
|
||||
Form.
|
||||
|
||||
3.2. Distribution of Executable Form
|
||||
|
||||
If You distribute Covered Software in Executable Form then:
|
||||
|
||||
(a) such Covered Software must also be made available in Source Code
|
||||
Form, as described in Section 3.1, and You must inform recipients of
|
||||
the Executable Form how they can obtain a copy of such Source Code
|
||||
Form by reasonable means in a timely manner, at a charge no more
|
||||
than the cost of distribution to the recipient; and
|
||||
|
||||
(b) You may distribute such Executable Form under the terms of this
|
||||
License, or sublicense it under different terms, provided that the
|
||||
license for the Executable Form does not attempt to limit or alter
|
||||
the recipients' rights in the Source Code Form under this License.
|
||||
|
||||
3.3. Distribution of a Larger Work
|
||||
|
||||
You may create and distribute a Larger Work under terms of Your choice,
|
||||
provided that You also comply with the requirements of this License for
|
||||
the Covered Software. If the Larger Work is a combination of Covered
|
||||
Software with a work governed by one or more Secondary Licenses, and the
|
||||
Covered Software is not Incompatible With Secondary Licenses, this
|
||||
License permits You to additionally distribute such Covered Software
|
||||
under the terms of such Secondary License(s), so that the recipient of
|
||||
the Larger Work may, at their option, further distribute the Covered
|
||||
Software under the terms of either this License or such Secondary
|
||||
License(s).
|
||||
|
||||
3.4. Notices
|
||||
|
||||
You may not remove or alter the substance of any license notices
|
||||
(including copyright notices, patent notices, disclaimers of warranty,
|
||||
or limitations of liability) contained within the Source Code Form of
|
||||
the Covered Software, except that You may alter any license notices to
|
||||
the extent required to remedy known factual inaccuracies.
|
||||
|
||||
3.5. Application of Additional Terms
|
||||
|
||||
You may choose to offer, and to charge a fee for, warranty, support,
|
||||
indemnity or liability obligations to one or more recipients of Covered
|
||||
Software. However, You may do so only on Your own behalf, and not on
|
||||
behalf of any Contributor. You must make it absolutely clear that any
|
||||
such warranty, support, indemnity, or liability obligation is offered by
|
||||
You alone, and You hereby agree to indemnify every Contributor for any
|
||||
liability incurred by such Contributor as a result of warranty, support,
|
||||
indemnity or liability terms You offer. You may include additional
|
||||
disclaimers of warranty and limitations of liability specific to any
|
||||
jurisdiction.
|
||||
|
||||
4. Inability to Comply Due to Statute or Regulation
|
||||
---------------------------------------------------
|
||||
|
||||
If it is impossible for You to comply with any of the terms of this
|
||||
License with respect to some or all of the Covered Software due to
|
||||
statute, judicial order, or regulation then You must: (a) comply with
|
||||
the terms of this License to the maximum extent possible; and (b)
|
||||
describe the limitations and the code they affect. Such description must
|
||||
be placed in a text file included with all distributions of the Covered
|
||||
Software under this License. Except to the extent prohibited by statute
|
||||
or regulation, such description must be sufficiently detailed for a
|
||||
recipient of ordinary skill to be able to understand it.
|
||||
|
||||
5. Termination
|
||||
--------------
|
||||
|
||||
5.1. The rights granted under this License will terminate automatically
|
||||
if You fail to comply with any of its terms. However, if You become
|
||||
compliant, then the rights granted under this License from a particular
|
||||
Contributor are reinstated (a) provisionally, unless and until such
|
||||
Contributor explicitly and finally terminates Your grants, and (b) on an
|
||||
ongoing basis, if such Contributor fails to notify You of the
|
||||
non-compliance by some reasonable means prior to 60 days after You have
|
||||
come back into compliance. Moreover, Your grants from a particular
|
||||
Contributor are reinstated on an ongoing basis if such Contributor
|
||||
notifies You of the non-compliance by some reasonable means, this is the
|
||||
first time You have received notice of non-compliance with this License
|
||||
from such Contributor, and You become compliant prior to 30 days after
|
||||
Your receipt of the notice.
|
||||
|
||||
5.2. If You initiate litigation against any entity by asserting a patent
|
||||
infringement claim (excluding declaratory judgment actions,
|
||||
counter-claims, and cross-claims) alleging that a Contributor Version
|
||||
directly or indirectly infringes any patent, then the rights granted to
|
||||
You by any and all Contributors for the Covered Software under Section
|
||||
2.1 of this License shall terminate.
|
||||
|
||||
5.3. In the event of termination under Sections 5.1 or 5.2 above, all
|
||||
end user license agreements (excluding distributors and resellers) which
|
||||
have been validly granted by You or Your distributors under this License
|
||||
prior to termination shall survive termination.
|
||||
|
||||
************************************************************************
|
||||
* *
|
||||
* 6. Disclaimer of Warranty *
|
||||
* ------------------------- *
|
||||
* *
|
||||
* Covered Software is provided under this License on an "as is" *
|
||||
* basis, without warranty of any kind, either expressed, implied, or *
|
||||
* statutory, including, without limitation, warranties that the *
|
||||
* Covered Software is free of defects, merchantable, fit for a *
|
||||
* particular purpose or non-infringing. The entire risk as to the *
|
||||
* quality and performance of the Covered Software is with You. *
|
||||
* Should any Covered Software prove defective in any respect, You *
|
||||
* (not any Contributor) assume the cost of any necessary servicing, *
|
||||
* repair, or correction. This disclaimer of warranty constitutes an *
|
||||
* essential part of this License. No use of any Covered Software is *
|
||||
* authorized under this License except under this disclaimer. *
|
||||
* *
|
||||
************************************************************************
|
||||
|
||||
************************************************************************
|
||||
* *
|
||||
* 7. Limitation of Liability *
|
||||
* -------------------------- *
|
||||
* *
|
||||
* Under no circumstances and under no legal theory, whether tort *
|
||||
* (including negligence), contract, or otherwise, shall any *
|
||||
* Contributor, or anyone who distributes Covered Software as *
|
||||
* permitted above, be liable to You for any direct, indirect, *
|
||||
* special, incidental, or consequential damages of any character *
|
||||
* including, without limitation, damages for lost profits, loss of *
|
||||
* goodwill, work stoppage, computer failure or malfunction, or any *
|
||||
* and all other commercial damages or losses, even if such party *
|
||||
* shall have been informed of the possibility of such damages. This *
|
||||
* limitation of liability shall not apply to liability for death or *
|
||||
* personal injury resulting from such party's negligence to the *
|
||||
* extent applicable law prohibits such limitation. Some *
|
||||
* jurisdictions do not allow the exclusion or limitation of *
|
||||
* incidental or consequential damages, so this exclusion and *
|
||||
* limitation may not apply to You. *
|
||||
* *
|
||||
************************************************************************
|
||||
|
||||
8. Litigation
|
||||
-------------
|
||||
|
||||
Any litigation relating to this License may be brought only in the
|
||||
courts of a jurisdiction where the defendant maintains its principal
|
||||
place of business and such litigation shall be governed by laws of that
|
||||
jurisdiction, without reference to its conflict-of-law provisions.
|
||||
Nothing in this Section shall prevent a party's ability to bring
|
||||
cross-claims or counter-claims.
|
||||
|
||||
9. Miscellaneous
|
||||
----------------
|
||||
|
||||
This License represents the complete agreement concerning the subject
|
||||
matter hereof. If any provision of this License is held to be
|
||||
unenforceable, such provision shall be reformed only to the extent
|
||||
necessary to make it enforceable. Any law or regulation which provides
|
||||
that the language of a contract shall be construed against the drafter
|
||||
shall not be used to construe this License against a Contributor.
|
||||
|
||||
10. Versions of the License
|
||||
---------------------------
|
||||
|
||||
10.1. New Versions
|
||||
|
||||
Mozilla Foundation is the license steward. Except as provided in Section
|
||||
10.3, no one other than the license steward has the right to modify or
|
||||
publish new versions of this License. Each version will be given a
|
||||
distinguishing version number.
|
||||
|
||||
10.2. Effect of New Versions
|
||||
|
||||
You may distribute the Covered Software under the terms of the version
|
||||
of the License under which You originally received the Covered Software,
|
||||
or under the terms of any subsequent version published by the license
|
||||
steward.
|
||||
|
||||
10.3. Modified Versions
|
||||
|
||||
If you create software not governed by this License, and you want to
|
||||
create a new license for such software, you may create and use a
|
||||
modified version of this License if you rename the license and remove
|
||||
any references to the name of the license steward (except to note that
|
||||
such modified license differs from this License).
|
||||
|
||||
10.4. Distributing Source Code Form that is Incompatible With Secondary
|
||||
Licenses
|
||||
|
||||
If You choose to distribute Source Code Form that is Incompatible With
|
||||
Secondary Licenses under the terms of this version of the License, the
|
||||
notice described in Exhibit B of this License must be attached.
|
||||
|
||||
Exhibit A - Source Code Form License Notice
|
||||
-------------------------------------------
|
||||
|
||||
This Source Code Form is subject to the terms of the Mozilla Public
|
||||
License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
If it is not possible or desirable to put the notice in a particular
|
||||
file, then You may include the notice in a location (such as a LICENSE
|
||||
file in a relevant directory) where a recipient would be likely to look
|
||||
for such a notice.
|
||||
|
||||
You may add additional accurate notices of copyright ownership.
|
||||
|
||||
Exhibit B - "Incompatible With Secondary Licenses" Notice
|
||||
---------------------------------------------------------
|
||||
|
||||
This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
defined by the Mozilla Public License, v. 2.0.
|
57
README.md
57
README.md
|
@ -1,21 +1,15 @@
|
|||
# Seedvault
|
||||
[![Build](https://github.com/seedvault-app/seedvault/actions/workflows/build.yml/badge.svg)](https://github.com/seedvault-app/seedvault/actions/workflows/build.yml)
|
||||
[![Build](https://github.com/seedvault-app/seedvault/workflows/Build/badge.svg?branch=master)](https://github.com/seedvault-app/seedvault/actions?query=branch%3Amaster+workflow%3ABuild)
|
||||
|
||||
A backup application for the [Android Open Source Project](https://source.android.com/).
|
||||
Needs to be [integrated](https://github.com/seedvault-app/seedvault/wiki/ROM-Integration)
|
||||
in your Android ROM and **can not** be installed as a regular app.
|
||||
|
||||
If you are having an issue/question,
|
||||
please look at our [FAQ](https://github.com/seedvault-app/seedvault/wiki/FAQ)
|
||||
or [ask a new question](https://github.com/seedvault-app/seedvault/discussions).
|
||||
If you are having an issue/question, please look at our [FAQ](../../wiki/FAQ).
|
||||
|
||||
## Components
|
||||
|
||||
* [Local Contacts Backup](contactsbackup) - an app that backs up local on-device contacts
|
||||
* [File backup library](storage) - a library handling efficient backup of files
|
||||
([documentation](storage/doc/design.md))
|
||||
* [Storage library](storage) - a library handling efficient backup of files
|
||||
* [Seedvault app](app) - the main app where all functionality comes together
|
||||
([documentation](doc/README.md))
|
||||
|
||||
## Features
|
||||
- Backup application data to a flash drive.
|
||||
|
@ -25,27 +19,24 @@ or [ask a new question](https://github.com/seedvault-app/seedvault/discussions).
|
|||
|
||||
## Requirements
|
||||
|
||||
SeedVault is developed along with AOSP releases.
|
||||
SeedVault is developed alongwith AOSP releases
|
||||
|
||||
We update it every time Google releases a new Android version,
|
||||
make any changes required for basic functionality,
|
||||
and any improvements possible through API changes in the OS.
|
||||
We update it every time Google releases a new Android version, make any changes required for basic functionality, and any improvements possible through API changes in the OS.
|
||||
|
||||
This means that for ROMs using SeedVault it's recommended
|
||||
to use the same branch as your android version
|
||||
This means that for ROMs using SeedVault it's recommended to use the same branch as your android version
|
||||
|
||||
- This current branch `android15` is meant for usage with Android 15
|
||||
- This is indicated by the version name starting with `15`,
|
||||
and the version code starting with `35` - the Android 15 API version
|
||||
- This current branch `android13` is meant for usage with Android 13
|
||||
- This is indicated by the version name starting with `13`, and the version code starting with `33` - the Android 13 API version
|
||||
|
||||
For older versions of Android,
|
||||
check out [the branches](https://github.com/seedvault-app/seedvault/branches).
|
||||
For older versions of Android, check out [the branches](https://github.com/seedvault-app/seedvault/branches).
|
||||
|
||||
Trying to use an older branch on a newer version may lead to issues
|
||||
and is not something we can support.
|
||||
Trying to use an older branch on a newer version may lead to issues and is not something we can support.
|
||||
|
||||
## Getting Started
|
||||
- Check out [the wiki](https://github.com/seedvault-app/seedvault/wiki) for information on building the application with
|
||||
AOSP.
|
||||
|
||||
## What makes this different?
|
||||
|
||||
This application is compiled with the operating system and does not require a rooted device for use.
|
||||
It uses the same internal APIs as `adb backup` which is deprecated and thus needs a replacement.
|
||||
|
||||
|
@ -55,12 +46,10 @@ It uses the same internal APIs as `adb backup` which is deprecated and thus need
|
|||
* `android.permission.MANAGE_USB` to access the serial number of USB mass storage devices.
|
||||
* `android.permission.WRITE_SECURE_SETTINGS` to change system backup settings and enable call log backup.
|
||||
* `android.permission.QUERY_ALL_PACKAGES` to get information about all installed apps for backup.
|
||||
* `android.permission.QUERY_USERS` to get the name of the user profile that gets backed up.
|
||||
* `android.permission.INSTALL_PACKAGES` to re-install apps when restoring from backup.
|
||||
* `android.permission.MANAGE_EXTERNAL_STORAGE` to backup and restore files from device storage.
|
||||
* `android.permission.ACCESS_MEDIA_LOCATION` to backup original media files e.g. without stripped EXIF metadata.
|
||||
* `android.permission.FOREGROUND_SERVICE` to do periodic storage backups without interruption.
|
||||
* `android.permission.FOREGROUND_SERVICE_DATA_SYNC` to do periodic storage backups without interruption.
|
||||
* `android.permission.MANAGE_DOCUMENTS` to retrieve the available storage roots (optional) for better UX.
|
||||
* `android.permission.USE_BIOMETRIC` to authenticate saving a new recovery code
|
||||
* `android.permission.INTERACT_ACROSS_USERS_FULL` to use storage roots in other users (optional).
|
||||
|
@ -69,11 +58,9 @@ It uses the same internal APIs as `adb backup` which is deprecated and thus need
|
|||
## Contributing
|
||||
Bug reports and pull requests are welcome on GitHub at https://github.com/seedvault-app/seedvault.
|
||||
|
||||
See [DEVELOPMENT.md](app/development/DEVELOPMENT.md) for information
|
||||
on developing Seedvault locally.
|
||||
See [DEVELOPMENT.md](app/development/DEVELOPMENT.md) for information on developing Seedvault locally.
|
||||
|
||||
This project aims to adhere to the
|
||||
[official Kotlin coding style](https://developer.android.com/kotlin/style-guide).
|
||||
This project aims to adhere to the [official Kotlin coding style](https://developer.android.com/kotlin/style-guide).
|
||||
|
||||
## Third-party tools
|
||||
|
||||
|
@ -89,8 +76,7 @@ allows you to decrypt and inspect your backups from newer versions of Seedvault
|
|||
It is currently work-in-progress.
|
||||
|
||||
## License
|
||||
This application is available as open source under the terms
|
||||
of the [Apache-2.0 License](https://opensource.org/licenses/Apache-2.0).
|
||||
This application is available as open source under the terms of the [Apache-2.0 License](https://opensource.org/licenses/Apache-2.0).
|
||||
|
||||
## Funding
|
||||
|
||||
|
@ -106,12 +92,3 @@ a fund established by [NLnet](https://nlnet.nl)
|
|||
with financial support from the European Commission's Next Generation Internet programme,
|
||||
under the aegis of DG Communications Networks, Content and Technology
|
||||
under grant agreement No 825310.
|
||||
|
||||
### NGI0 Entrust Fund
|
||||
|
||||
This project was funded through the
|
||||
[NGI0 Entrust Fund](https://nlnet.nl/project/SeedVault-Integrity/),
|
||||
a fund established by [NLnet](https://nlnet.nl)
|
||||
with financial support from the European Commission's Next Generation Internet programme,
|
||||
under the aegis of DG Communications Networks, Content and Technology
|
||||
under grant agreement No 101069594.
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
SPDX-FileCopyrightText: 2017 Steve Soltys
|
||||
SPDX-FileCopyrightText: 2020 The Calyx Institute
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
-->
|
||||
<config>
|
||||
<backup-transport-whitelisted-service
|
||||
service="com.stevesoltys.seedvault/.transport.ConfigurableBackupTransportService" />
|
||||
|
|
232
app/build.gradle
Normal file
232
app/build.gradle
Normal file
|
@ -0,0 +1,232 @@
|
|||
plugins {
|
||||
id 'com.android.application'
|
||||
id 'org.jetbrains.kotlin.android'
|
||||
id 'org.jlleitschuh.gradle.ktlint'
|
||||
}
|
||||
|
||||
def gitDescribe = { ->
|
||||
def stdout = new ByteArrayOutputStream()
|
||||
exec {
|
||||
commandLine 'git', 'describe', '--always', '--tags', '--dirty=-dirty'
|
||||
standardOutput = stdout
|
||||
}
|
||||
return stdout.toString().trim()
|
||||
}
|
||||
|
||||
android {
|
||||
namespace 'com.stevesoltys.seedvault'
|
||||
compileSdk rootProject.ext.compileSdk
|
||||
|
||||
defaultConfig {
|
||||
minSdk 32 // leave at 32 for robolectric tests
|
||||
targetSdk rootProject.ext.targetSdk
|
||||
versionNameSuffix "-$gitDescribe"
|
||||
testInstrumentationRunner "com.stevesoltys.seedvault.KoinInstrumentationTestRunner"
|
||||
testInstrumentationRunnerArguments disableAnalytics: 'true'
|
||||
|
||||
if (project.hasProperty('instrumented_test_size')) {
|
||||
final testSize = project.getProperty('instrumented_test_size')
|
||||
println("Instrumented test size: $testSize")
|
||||
|
||||
testInstrumentationRunnerArguments size: testSize
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
}
|
||||
}
|
||||
|
||||
lint {
|
||||
disable "DialogFragmentCallbacksDetector",
|
||||
"InvalidFragmentVersionForActivityResult",
|
||||
"CheckedExceptions"
|
||||
abortOnError true
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_11
|
||||
targetCompatibility = JavaVersion.VERSION_11
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = JavaVersion.VERSION_11.toString()
|
||||
languageVersion = "1.7"
|
||||
}
|
||||
testOptions {
|
||||
unitTests.all {
|
||||
useJUnitPlatform()
|
||||
testLogging {
|
||||
events "passed", "skipped", "failed"
|
||||
}
|
||||
}
|
||||
unitTests {
|
||||
includeAndroidResources = true
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
test {
|
||||
java.srcDirs += "$projectDir/src/sharedTest/java"
|
||||
}
|
||||
androidTest {
|
||||
java.srcDirs += "$projectDir/src/sharedTest/java"
|
||||
}
|
||||
}
|
||||
|
||||
signingConfigs {
|
||||
aosp {
|
||||
// Generated from the AOSP platform key:
|
||||
// https://android.googlesource.com/platform/build/+/refs/tags/android-11.0.0_r29/target/product/security/platform.pk8
|
||||
keyAlias "platform"
|
||||
keyPassword "platform"
|
||||
storeFile file("development/platform.jks")
|
||||
storePassword "platform"
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes.release.signingConfig = signingConfigs.aosp
|
||||
buildTypes.debug.signingConfig = signingConfigs.aosp
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly rootProject.ext.aosp_libs
|
||||
|
||||
/**
|
||||
* Dependencies in AOSP
|
||||
*
|
||||
* We try to keep the dependencies in sync with what AOSP ships as Seedvault is meant to be built
|
||||
* with the AOSP build system and gradle builds are just for more pleasant development.
|
||||
* Using the AOSP versions in gradle builds allows us to spot issues early on.
|
||||
*/
|
||||
implementation rootProject.ext.kotlin_libs.std
|
||||
// These coroutine libraries get upgraded otherwise to versions incompatible with kotlin version
|
||||
implementation rootProject.ext.kotlin_libs.coroutines
|
||||
|
||||
implementation rootProject.ext.std_libs.androidx_core
|
||||
// A newer version gets pulled in with AOSP via core, so we include fragment here explicitly
|
||||
implementation rootProject.ext.std_libs.androidx_fragment
|
||||
implementation rootProject.ext.std_libs.androidx_activity
|
||||
implementation rootProject.ext.std_libs.androidx_preference
|
||||
implementation rootProject.ext.std_libs.androidx_lifecycle_viewmodel_ktx
|
||||
implementation rootProject.ext.std_libs.androidx_lifecycle_livedata_ktx
|
||||
implementation rootProject.ext.std_libs.androidx_constraintlayout
|
||||
implementation rootProject.ext.std_libs.androidx_documentfile
|
||||
implementation rootProject.ext.std_libs.com_google_android_material
|
||||
|
||||
implementation rootProject.ext.storage_libs.com_google_crypto_tink_android
|
||||
|
||||
/**
|
||||
* Storage Dependencies
|
||||
*/
|
||||
implementation project(':storage:lib')
|
||||
|
||||
/**
|
||||
* External Dependencies
|
||||
*
|
||||
* If the dependencies below are updated,
|
||||
* please make sure to update the prebuilt libraries and the Android.bp files
|
||||
* in the top-level `libs` folder to reflect that.
|
||||
* You can copy these libraries from ~/.gradle/caches/modules-2/files-2.1
|
||||
*/
|
||||
// later versions than 2.1.1 require newer kotlin version
|
||||
// implementation "io.insert-koin:koin-core-jvm:3.2.0"
|
||||
// implementation "io.insert-koin:koin-android:3.2.0"
|
||||
implementation fileTree(include: ['*.jar'], dir: "${rootProject.rootDir}/libs/koin-android")
|
||||
implementation fileTree(include: ['*.aar'], dir: "${rootProject.rootDir}/libs/koin-android")
|
||||
|
||||
// implementation "cash.z.ecc.android:kotlin-bip39:1.0.4"
|
||||
implementation fileTree(include: ['kotlin-bip39-jvm-1.0.4.jar'], dir: "${rootProject.rootDir}/libs")
|
||||
|
||||
/**
|
||||
* Test Dependencies (do not concern the AOSP build)
|
||||
*/
|
||||
lintChecks rootProject.ext.lint_libs.exceptions
|
||||
|
||||
// anything less than 'implementation' fails tests run with gradlew
|
||||
testImplementation rootProject.ext.aosp_libs
|
||||
testImplementation 'androidx.test.ext:junit:1.1.3'
|
||||
testImplementation('org.robolectric:robolectric:4.8.1') {
|
||||
// https://github.com/robolectric/robolectric/issues/5245
|
||||
exclude group: "com.google.auto.service", module: "auto-service"
|
||||
}
|
||||
testImplementation 'org.hamcrest:hamcrest:2.2'
|
||||
testImplementation "org.junit.jupiter:junit-jupiter-api:$junit5_version"
|
||||
testImplementation "org.junit.jupiter:junit-jupiter-params:$junit5_version"
|
||||
testImplementation "io.mockk:mockk:$mockk_version"
|
||||
testImplementation 'org.bitcoinj:bitcoinj-core:0.15.10'
|
||||
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junit5_version"
|
||||
testRuntimeOnly "org.junit.vintage:junit-vintage-engine:$junit5_version"
|
||||
|
||||
androidTestImplementation rootProject.ext.aosp_libs
|
||||
androidTestImplementation 'androidx.test:runner:1.4.0'
|
||||
androidTestImplementation 'androidx.test:rules:1.4.0'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
||||
androidTestImplementation "io.mockk:mockk-android:$mockk_version"
|
||||
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
|
||||
}
|
||||
|
||||
apply from: "${rootProject.rootDir}/gradle/ktlint.gradle"
|
||||
|
||||
gradle.projectsEvaluated {
|
||||
tasks.withType(JavaCompile) {
|
||||
options.compilerArgs.add('-Xbootclasspath/p:app/libs/android.jar:app/libs/libcore.jar')
|
||||
}
|
||||
}
|
||||
|
||||
configurations {
|
||||
all {
|
||||
resolutionStrategy {
|
||||
failOnNonReproducibleResolution()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register('provisionEmulator', Exec) {
|
||||
group("emulator")
|
||||
|
||||
dependsOn(tasks.assembleRelease)
|
||||
|
||||
doFirst {
|
||||
commandLine "${project.projectDir}/development/scripts/provision_emulator.sh",
|
||||
"seedvault",
|
||||
"system-images;android-33;google_apis;x86_64"
|
||||
|
||||
environment "ANDROID_HOME", android.sdkDirectory.absolutePath
|
||||
environment "JAVA_HOME", System.properties['java.home']
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register('startEmulator', Exec) {
|
||||
group("emulator")
|
||||
|
||||
doFirst {
|
||||
commandLine "${project.projectDir}/development/scripts/start_emulator.sh", "seedvault"
|
||||
|
||||
environment "ANDROID_HOME", android.sdkDirectory.absolutePath
|
||||
environment "JAVA_HOME", System.properties['java.home']
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register('installEmulatorRelease', Exec) {
|
||||
group("emulator")
|
||||
|
||||
dependsOn(tasks.assembleRelease)
|
||||
|
||||
doFirst {
|
||||
commandLine "${project.projectDir}/development/scripts/install_app.sh"
|
||||
|
||||
environment "ANDROID_HOME", android.sdkDirectory.absolutePath
|
||||
environment "JAVA_HOME", System.properties['java.home']
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register('clearEmulatorAppData', Exec) {
|
||||
group("emulator")
|
||||
|
||||
doFirst {
|
||||
commandLine "${project.projectDir}/development/scripts/clear_app_data.sh"
|
||||
|
||||
environment "ANDROID_HOME", android.sdkDirectory.absolutePath
|
||||
environment "JAVA_HOME", System.properties['java.home']
|
||||
}
|
||||
}
|
|
@ -1,286 +0,0 @@
|
|||
//
|
||||
// SPDX-FileCopyrightText: 2023 The Calyx Institute
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
import com.google.protobuf.gradle.id
|
||||
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
|
||||
import java.io.ByteArrayOutputStream
|
||||
|
||||
plugins {
|
||||
alias(libs.plugins.android.application)
|
||||
alias(libs.plugins.jetbrains.kotlin.android)
|
||||
alias(libs.plugins.google.protobuf)
|
||||
}
|
||||
|
||||
val gitDescribe = {
|
||||
val stdout = ByteArrayOutputStream()
|
||||
exec {
|
||||
commandLine("git", "describe", "--always", "--tags", "--dirty=-dirty")
|
||||
standardOutput = stdout
|
||||
}
|
||||
stdout.toString().trim()
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "com.stevesoltys.seedvault"
|
||||
compileSdk = libs.versions.compileSdk.get().toInt()
|
||||
|
||||
defaultConfig {
|
||||
minSdk = libs.versions.minSdk.get().toInt()
|
||||
targetSdk = libs.versions.targetSdk.get().toInt()
|
||||
versionNameSuffix = "-${gitDescribe()}"
|
||||
testInstrumentationRunner = "com.stevesoltys.seedvault.KoinInstrumentationTestRunner"
|
||||
testInstrumentationRunnerArguments["disableAnalytics"] = "true"
|
||||
}
|
||||
|
||||
signingConfigs {
|
||||
create("aosp") {
|
||||
// Generated from the AOSP platform key:
|
||||
// https://android.googlesource.com/platform/build/+/refs/tags/android-11.0.0_r29/target/product/security/platform.pk8
|
||||
keyAlias = "platform"
|
||||
keyPassword = "platform"
|
||||
storeFile = file("development/platform.jks")
|
||||
storePassword = "platform"
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
all {
|
||||
isMinifyEnabled = false
|
||||
}
|
||||
|
||||
getByName("release").signingConfig = signingConfigs.getByName("aosp")
|
||||
getByName("debug").signingConfig = signingConfigs.getByName("aosp")
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = JavaVersion.VERSION_17.toString()
|
||||
languageVersion = "1.8"
|
||||
}
|
||||
|
||||
packaging {
|
||||
resources {
|
||||
excludes += listOf("META-INF/LICENSE.md", "META-INF/LICENSE-notice.md")
|
||||
}
|
||||
}
|
||||
|
||||
testOptions.unitTests {
|
||||
all { it.useJUnitPlatform() }
|
||||
|
||||
isIncludeAndroidResources = true
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
named("test") {
|
||||
java.srcDirs("$projectDir/src/sharedTest/java")
|
||||
}
|
||||
named("androidTest") {
|
||||
java.srcDirs("$projectDir/src/sharedTest/java")
|
||||
}
|
||||
}
|
||||
|
||||
protobuf {
|
||||
protoc {
|
||||
artifact = if ("aarch64" == System.getProperty("os.arch")) {
|
||||
// mac m1
|
||||
"com.google.protobuf:protoc:${libs.versions.protobuf.get()}:osx-x86_64"
|
||||
} else {
|
||||
// other
|
||||
"com.google.protobuf:protoc:${libs.versions.protobuf.get()}"
|
||||
}
|
||||
}
|
||||
generateProtoTasks {
|
||||
all().forEach { task ->
|
||||
task.plugins {
|
||||
id("java") {
|
||||
option("lite")
|
||||
}
|
||||
id("kotlin") {
|
||||
option("lite")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lint {
|
||||
abortOnError = true
|
||||
|
||||
disable.clear()
|
||||
disable += setOf(
|
||||
"DialogFragmentCallbacksDetector",
|
||||
"InvalidFragmentVersionForActivityResult",
|
||||
"CheckedExceptions"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
val aospLibs: FileTree by rootProject.extra
|
||||
compileOnly(aospLibs)
|
||||
|
||||
/**
|
||||
* Dependencies in AOSP
|
||||
*
|
||||
* We try to keep the dependencies in sync with what AOSP ships as Seedvault is meant to be built
|
||||
* with the AOSP build system and gradle builds are just for more pleasant development.
|
||||
* Using the AOSP versions in gradle builds allows us to spot issues early on.
|
||||
*/
|
||||
implementation(libs.bundles.kotlin)
|
||||
// These coroutine libraries get upgraded otherwise to versions incompatible with kotlin version
|
||||
implementation(libs.bundles.coroutines)
|
||||
|
||||
implementation(libs.androidx.core)
|
||||
// A newer version gets pulled in with AOSP via core, so we include fragment here explicitly
|
||||
implementation(libs.androidx.fragment)
|
||||
implementation(libs.androidx.activity)
|
||||
implementation(libs.androidx.preference)
|
||||
implementation(libs.androidx.lifecycle.viewmodel.ktx)
|
||||
implementation(libs.androidx.lifecycle.livedata.ktx)
|
||||
implementation(libs.androidx.constraintlayout)
|
||||
implementation(libs.androidx.documentfile)
|
||||
implementation(libs.androidx.work.runtime.ktx)
|
||||
implementation(libs.google.material)
|
||||
|
||||
implementation(libs.google.protobuf.javalite)
|
||||
implementation(libs.google.tink.android)
|
||||
implementation(libs.kotlin.logging)
|
||||
implementation(libs.squareup.okio)
|
||||
|
||||
/**
|
||||
* Storage Dependencies
|
||||
*/
|
||||
implementation(project(":core"))
|
||||
implementation(project(":storage:lib"))
|
||||
|
||||
/**
|
||||
* External Dependencies
|
||||
*
|
||||
* If the dependencies below are updated,
|
||||
* please make sure to update the prebuilt libraries and the Android.bp files
|
||||
* in the top-level `libs` folder to reflect that.
|
||||
* You can copy these libraries from ~/.gradle/caches/modules-2/files-2.1
|
||||
*/
|
||||
implementation(fileTree("${rootProject.rootDir}/libs/koin-android").include("*.jar"))
|
||||
implementation(fileTree("${rootProject.rootDir}/libs/koin-android").include("*.aar"))
|
||||
|
||||
implementation(
|
||||
fileTree("${rootProject.rootDir}/libs").include("protobuf-kotlin-lite-3.21.12.jar")
|
||||
)
|
||||
implementation(fileTree("${rootProject.rootDir}/libs").include("seedvault-chunker-0.1.jar"))
|
||||
implementation(fileTree("${rootProject.rootDir}/libs").include("zstd-jni-1.5.6-5.aar"))
|
||||
implementation(fileTree("${rootProject.rootDir}/libs").include("kotlin-bip39-jvm-1.0.8.jar"))
|
||||
implementation(fileTree("${rootProject.rootDir}/libs").include("logback-android-3.0.0.aar"))
|
||||
|
||||
/**
|
||||
* Test Dependencies (do not concern the AOSP build)
|
||||
*/
|
||||
lintChecks(libs.thirdegg.lint.rules)
|
||||
|
||||
// anything less than 'implementation' fails tests run with gradlew
|
||||
testImplementation(aospLibs)
|
||||
testImplementation("androidx.test.ext:junit:1.1.5")
|
||||
testImplementation("org.slf4j:slf4j-simple:2.0.3")
|
||||
testImplementation("org.robolectric:robolectric:4.12.2")
|
||||
testImplementation("org.hamcrest:hamcrest:2.2")
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-api:${libs.versions.junit5.get()}")
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-params:${libs.versions.junit5.get()}")
|
||||
testImplementation("io.mockk:mockk:${libs.versions.mockk.get()}")
|
||||
testImplementation(
|
||||
"org.jetbrains.kotlinx:kotlinx-coroutines-test:${libs.versions.coroutines.get()}"
|
||||
)
|
||||
testImplementation("app.cash.turbine:turbine:1.0.0")
|
||||
testImplementation("org.bitcoinj:bitcoinj-core:0.16.2")
|
||||
testImplementation("com.github.luben:zstd-jni:1.5.6-5")
|
||||
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${libs.versions.junit5.get()}")
|
||||
testRuntimeOnly("org.junit.vintage:junit-vintage-engine:${libs.versions.junit5.get()}")
|
||||
|
||||
androidTestImplementation(aospLibs)
|
||||
androidTestImplementation(kotlin("test"))
|
||||
androidTestImplementation("androidx.test:runner:1.4.0")
|
||||
androidTestImplementation("androidx.test:rules:1.4.0")
|
||||
androidTestImplementation("androidx.test.ext:junit:1.1.3")
|
||||
androidTestImplementation("io.mockk:mockk-android:1.13.8")
|
||||
androidTestImplementation("androidx.test.uiautomator:uiautomator:2.2.0")
|
||||
}
|
||||
|
||||
gradle.projectsEvaluated {
|
||||
tasks.withType(JavaCompile::class) {
|
||||
options.compilerArgs.add("-Xbootclasspath/p:libs/aosp/android.jar:libs/aosp/libcore.jar")
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<Test>().configureEach {
|
||||
testLogging {
|
||||
events("passed", "skipped", "failed")
|
||||
|
||||
showExceptions = true
|
||||
showCauses = true
|
||||
showStackTraces = true
|
||||
exceptionFormat = TestExceptionFormat.FULL
|
||||
}
|
||||
}
|
||||
|
||||
configurations.all {
|
||||
resolutionStrategy {
|
||||
failOnNonReproducibleResolution()
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register<Exec>("provisionEmulator") {
|
||||
group = "emulator"
|
||||
|
||||
dependsOn(tasks.getByName("assembleRelease"))
|
||||
|
||||
doFirst {
|
||||
commandLine(
|
||||
"${project.projectDir}/development/scripts/provision_emulator.sh",
|
||||
"seedvault",
|
||||
"system-images;android-34;default;x86_64"
|
||||
)
|
||||
|
||||
environment("ANDROID_HOME", android.sdkDirectory.absolutePath)
|
||||
environment("JAVA_HOME", System.getProperty("java.home"))
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register<Exec>("startEmulator") {
|
||||
group = "emulator"
|
||||
|
||||
doFirst {
|
||||
commandLine("${project.projectDir}/development/scripts/start_emulator.sh", "seedvault")
|
||||
|
||||
environment("ANDROID_HOME", android.sdkDirectory.absolutePath)
|
||||
environment("JAVA_HOME", System.getProperty("java.home"))
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register<Exec>("installEmulatorRelease") {
|
||||
group = "emulator"
|
||||
|
||||
dependsOn(tasks.getByName("assembleRelease"))
|
||||
|
||||
doFirst {
|
||||
commandLine("${project.projectDir}/development/scripts/install_app.sh")
|
||||
|
||||
environment("ANDROID_HOME", android.sdkDirectory.absolutePath)
|
||||
environment("JAVA_HOME", System.getProperty("java.home"))
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register<Exec>("clearEmulatorAppData") {
|
||||
group = "emulator"
|
||||
|
||||
doFirst {
|
||||
commandLine("${project.projectDir}/development/scripts/clear_app_data.sh")
|
||||
|
||||
environment("ANDROID_HOME", android.sdkDirectory.absolutePath)
|
||||
environment("JAVA_HOME", System.getProperty("java.home"))
|
||||
}
|
||||
}
|
|
@ -1,950 +0,0 @@
|
|||
//Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: snapshot.proto
|
||||
|
||||
package com.stevesoltys.seedvault.proto;
|
||||
|
||||
@kotlin.jvm.JvmName("-initializesnapshot")
|
||||
public inline fun snapshot(block: com.stevesoltys.seedvault.proto.SnapshotKt.Dsl.() -> kotlin.Unit): com.stevesoltys.seedvault.proto.Snapshot =
|
||||
com.stevesoltys.seedvault.proto.SnapshotKt.Dsl._create(com.stevesoltys.seedvault.proto.Snapshot.newBuilder()).apply { block() }._build()
|
||||
public object SnapshotKt {
|
||||
@kotlin.OptIn(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)
|
||||
@com.google.protobuf.kotlin.ProtoDslMarker
|
||||
public class Dsl private constructor(
|
||||
private val _builder: com.stevesoltys.seedvault.proto.Snapshot.Builder
|
||||
) {
|
||||
public companion object {
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.PublishedApi
|
||||
internal fun _create(builder: com.stevesoltys.seedvault.proto.Snapshot.Builder): Dsl = Dsl(builder)
|
||||
}
|
||||
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.PublishedApi
|
||||
internal fun _build(): com.stevesoltys.seedvault.proto.Snapshot = _builder.build()
|
||||
|
||||
/**
|
||||
* <code>uint32 version = 1;</code>
|
||||
*/
|
||||
public var version: kotlin.Int
|
||||
@JvmName("getVersion")
|
||||
get() = _builder.getVersion()
|
||||
@JvmName("setVersion")
|
||||
set(value) {
|
||||
_builder.setVersion(value)
|
||||
}
|
||||
/**
|
||||
* <code>uint32 version = 1;</code>
|
||||
*/
|
||||
public fun clearVersion() {
|
||||
_builder.clearVersion()
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>uint64 token = 2;</code>
|
||||
*/
|
||||
public var token: kotlin.Long
|
||||
@JvmName("getToken")
|
||||
get() = _builder.getToken()
|
||||
@JvmName("setToken")
|
||||
set(value) {
|
||||
_builder.setToken(value)
|
||||
}
|
||||
/**
|
||||
* <code>uint64 token = 2;</code>
|
||||
*/
|
||||
public fun clearToken() {
|
||||
_builder.clearToken()
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>string name = 3;</code>
|
||||
*/
|
||||
public var name: kotlin.String
|
||||
@JvmName("getName")
|
||||
get() = _builder.getName()
|
||||
@JvmName("setName")
|
||||
set(value) {
|
||||
_builder.setName(value)
|
||||
}
|
||||
/**
|
||||
* <code>string name = 3;</code>
|
||||
*/
|
||||
public fun clearName() {
|
||||
_builder.clearName()
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>string user = 4;</code>
|
||||
*/
|
||||
public var user: kotlin.String
|
||||
@JvmName("getUser")
|
||||
get() = _builder.getUser()
|
||||
@JvmName("setUser")
|
||||
set(value) {
|
||||
_builder.setUser(value)
|
||||
}
|
||||
/**
|
||||
* <code>string user = 4;</code>
|
||||
*/
|
||||
public fun clearUser() {
|
||||
_builder.clearUser()
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>string androidId = 5;</code>
|
||||
*/
|
||||
public var androidId: kotlin.String
|
||||
@JvmName("getAndroidId")
|
||||
get() = _builder.getAndroidId()
|
||||
@JvmName("setAndroidId")
|
||||
set(value) {
|
||||
_builder.setAndroidId(value)
|
||||
}
|
||||
/**
|
||||
* <code>string androidId = 5;</code>
|
||||
*/
|
||||
public fun clearAndroidId() {
|
||||
_builder.clearAndroidId()
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>uint32 sdkInt = 6;</code>
|
||||
*/
|
||||
public var sdkInt: kotlin.Int
|
||||
@JvmName("getSdkInt")
|
||||
get() = _builder.getSdkInt()
|
||||
@JvmName("setSdkInt")
|
||||
set(value) {
|
||||
_builder.setSdkInt(value)
|
||||
}
|
||||
/**
|
||||
* <code>uint32 sdkInt = 6;</code>
|
||||
*/
|
||||
public fun clearSdkInt() {
|
||||
_builder.clearSdkInt()
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>string androidIncremental = 7;</code>
|
||||
*/
|
||||
public var androidIncremental: kotlin.String
|
||||
@JvmName("getAndroidIncremental")
|
||||
get() = _builder.getAndroidIncremental()
|
||||
@JvmName("setAndroidIncremental")
|
||||
set(value) {
|
||||
_builder.setAndroidIncremental(value)
|
||||
}
|
||||
/**
|
||||
* <code>string androidIncremental = 7;</code>
|
||||
*/
|
||||
public fun clearAndroidIncremental() {
|
||||
_builder.clearAndroidIncremental()
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>bool d2d = 8;</code>
|
||||
*/
|
||||
public var d2D: kotlin.Boolean
|
||||
@JvmName("getD2D")
|
||||
get() = _builder.getD2D()
|
||||
@JvmName("setD2D")
|
||||
set(value) {
|
||||
_builder.setD2D(value)
|
||||
}
|
||||
/**
|
||||
* <code>bool d2d = 8;</code>
|
||||
*/
|
||||
public fun clearD2D() {
|
||||
_builder.clearD2D()
|
||||
}
|
||||
|
||||
/**
|
||||
* An uninstantiable, behaviorless type to represent the field in
|
||||
* generics.
|
||||
*/
|
||||
@kotlin.OptIn(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)
|
||||
public class AppsProxy private constructor() : com.google.protobuf.kotlin.DslProxy()
|
||||
/**
|
||||
* <code>map<string, .com.stevesoltys.seedvault.proto.Snapshot.App> apps = 9;</code>
|
||||
*/
|
||||
public val apps: com.google.protobuf.kotlin.DslMap<kotlin.String, com.stevesoltys.seedvault.proto.Snapshot.App, AppsProxy>
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@JvmName("getAppsMap")
|
||||
get() = com.google.protobuf.kotlin.DslMap(
|
||||
_builder.getAppsMap()
|
||||
)
|
||||
/**
|
||||
* <code>map<string, .com.stevesoltys.seedvault.proto.Snapshot.App> apps = 9;</code>
|
||||
*/
|
||||
@JvmName("putApps")
|
||||
public fun com.google.protobuf.kotlin.DslMap<kotlin.String, com.stevesoltys.seedvault.proto.Snapshot.App, AppsProxy>
|
||||
.put(key: kotlin.String, value: com.stevesoltys.seedvault.proto.Snapshot.App) {
|
||||
_builder.putApps(key, value)
|
||||
}
|
||||
/**
|
||||
* <code>map<string, .com.stevesoltys.seedvault.proto.Snapshot.App> apps = 9;</code>
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@JvmName("setApps")
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
public inline operator fun com.google.protobuf.kotlin.DslMap<kotlin.String, com.stevesoltys.seedvault.proto.Snapshot.App, AppsProxy>
|
||||
.set(key: kotlin.String, value: com.stevesoltys.seedvault.proto.Snapshot.App) {
|
||||
put(key, value)
|
||||
}
|
||||
/**
|
||||
* <code>map<string, .com.stevesoltys.seedvault.proto.Snapshot.App> apps = 9;</code>
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@JvmName("removeApps")
|
||||
public fun com.google.protobuf.kotlin.DslMap<kotlin.String, com.stevesoltys.seedvault.proto.Snapshot.App, AppsProxy>
|
||||
.remove(key: kotlin.String) {
|
||||
_builder.removeApps(key)
|
||||
}
|
||||
/**
|
||||
* <code>map<string, .com.stevesoltys.seedvault.proto.Snapshot.App> apps = 9;</code>
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@JvmName("putAllApps")
|
||||
public fun com.google.protobuf.kotlin.DslMap<kotlin.String, com.stevesoltys.seedvault.proto.Snapshot.App, AppsProxy>
|
||||
.putAll(map: kotlin.collections.Map<kotlin.String, com.stevesoltys.seedvault.proto.Snapshot.App>) {
|
||||
_builder.putAllApps(map)
|
||||
}
|
||||
/**
|
||||
* <code>map<string, .com.stevesoltys.seedvault.proto.Snapshot.App> apps = 9;</code>
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@JvmName("clearApps")
|
||||
public fun com.google.protobuf.kotlin.DslMap<kotlin.String, com.stevesoltys.seedvault.proto.Snapshot.App, AppsProxy>
|
||||
.clear() {
|
||||
_builder.clearApps()
|
||||
}
|
||||
|
||||
/**
|
||||
* An uninstantiable, behaviorless type to represent the field in
|
||||
* generics.
|
||||
*/
|
||||
@kotlin.OptIn(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)
|
||||
public class IconChunkIdsProxy private constructor() : com.google.protobuf.kotlin.DslProxy()
|
||||
/**
|
||||
* <code>repeated bytes iconChunkIds = 10;</code>
|
||||
*/
|
||||
public val iconChunkIds: com.google.protobuf.kotlin.DslList<com.google.protobuf.ByteString, IconChunkIdsProxy>
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
get() = com.google.protobuf.kotlin.DslList(
|
||||
_builder.getIconChunkIdsList()
|
||||
)
|
||||
/**
|
||||
* <code>repeated bytes iconChunkIds = 10;</code>
|
||||
* @param value The iconChunkIds to add.
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.jvm.JvmName("addIconChunkIds")
|
||||
public fun com.google.protobuf.kotlin.DslList<com.google.protobuf.ByteString, IconChunkIdsProxy>.add(value: com.google.protobuf.ByteString) {
|
||||
_builder.addIconChunkIds(value)
|
||||
}/**
|
||||
* <code>repeated bytes iconChunkIds = 10;</code>
|
||||
* @param value The iconChunkIds to add.
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.jvm.JvmName("plusAssignIconChunkIds")
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
public inline operator fun com.google.protobuf.kotlin.DslList<com.google.protobuf.ByteString, IconChunkIdsProxy>.plusAssign(value: com.google.protobuf.ByteString) {
|
||||
add(value)
|
||||
}/**
|
||||
* <code>repeated bytes iconChunkIds = 10;</code>
|
||||
* @param values The iconChunkIds to add.
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.jvm.JvmName("addAllIconChunkIds")
|
||||
public fun com.google.protobuf.kotlin.DslList<com.google.protobuf.ByteString, IconChunkIdsProxy>.addAll(values: kotlin.collections.Iterable<com.google.protobuf.ByteString>) {
|
||||
_builder.addAllIconChunkIds(values)
|
||||
}/**
|
||||
* <code>repeated bytes iconChunkIds = 10;</code>
|
||||
* @param values The iconChunkIds to add.
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.jvm.JvmName("plusAssignAllIconChunkIds")
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
public inline operator fun com.google.protobuf.kotlin.DslList<com.google.protobuf.ByteString, IconChunkIdsProxy>.plusAssign(values: kotlin.collections.Iterable<com.google.protobuf.ByteString>) {
|
||||
addAll(values)
|
||||
}/**
|
||||
* <code>repeated bytes iconChunkIds = 10;</code>
|
||||
* @param index The index to set the value at.
|
||||
* @param value The iconChunkIds to set.
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.jvm.JvmName("setIconChunkIds")
|
||||
public operator fun com.google.protobuf.kotlin.DslList<com.google.protobuf.ByteString, IconChunkIdsProxy>.set(index: kotlin.Int, value: com.google.protobuf.ByteString) {
|
||||
_builder.setIconChunkIds(index, value)
|
||||
}/**
|
||||
* <code>repeated bytes iconChunkIds = 10;</code>
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.jvm.JvmName("clearIconChunkIds")
|
||||
public fun com.google.protobuf.kotlin.DslList<com.google.protobuf.ByteString, IconChunkIdsProxy>.clear() {
|
||||
_builder.clearIconChunkIds()
|
||||
}
|
||||
/**
|
||||
* An uninstantiable, behaviorless type to represent the field in
|
||||
* generics.
|
||||
*/
|
||||
@kotlin.OptIn(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)
|
||||
public class BlobsProxy private constructor() : com.google.protobuf.kotlin.DslProxy()
|
||||
/**
|
||||
* <code>map<string, .com.stevesoltys.seedvault.proto.Snapshot.Blob> blobs = 11;</code>
|
||||
*/
|
||||
public val blobs: com.google.protobuf.kotlin.DslMap<kotlin.String, com.stevesoltys.seedvault.proto.Snapshot.Blob, BlobsProxy>
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@JvmName("getBlobsMap")
|
||||
get() = com.google.protobuf.kotlin.DslMap(
|
||||
_builder.getBlobsMap()
|
||||
)
|
||||
/**
|
||||
* <code>map<string, .com.stevesoltys.seedvault.proto.Snapshot.Blob> blobs = 11;</code>
|
||||
*/
|
||||
@JvmName("putBlobs")
|
||||
public fun com.google.protobuf.kotlin.DslMap<kotlin.String, com.stevesoltys.seedvault.proto.Snapshot.Blob, BlobsProxy>
|
||||
.put(key: kotlin.String, value: com.stevesoltys.seedvault.proto.Snapshot.Blob) {
|
||||
_builder.putBlobs(key, value)
|
||||
}
|
||||
/**
|
||||
* <code>map<string, .com.stevesoltys.seedvault.proto.Snapshot.Blob> blobs = 11;</code>
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@JvmName("setBlobs")
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
public inline operator fun com.google.protobuf.kotlin.DslMap<kotlin.String, com.stevesoltys.seedvault.proto.Snapshot.Blob, BlobsProxy>
|
||||
.set(key: kotlin.String, value: com.stevesoltys.seedvault.proto.Snapshot.Blob) {
|
||||
put(key, value)
|
||||
}
|
||||
/**
|
||||
* <code>map<string, .com.stevesoltys.seedvault.proto.Snapshot.Blob> blobs = 11;</code>
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@JvmName("removeBlobs")
|
||||
public fun com.google.protobuf.kotlin.DslMap<kotlin.String, com.stevesoltys.seedvault.proto.Snapshot.Blob, BlobsProxy>
|
||||
.remove(key: kotlin.String) {
|
||||
_builder.removeBlobs(key)
|
||||
}
|
||||
/**
|
||||
* <code>map<string, .com.stevesoltys.seedvault.proto.Snapshot.Blob> blobs = 11;</code>
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@JvmName("putAllBlobs")
|
||||
public fun com.google.protobuf.kotlin.DslMap<kotlin.String, com.stevesoltys.seedvault.proto.Snapshot.Blob, BlobsProxy>
|
||||
.putAll(map: kotlin.collections.Map<kotlin.String, com.stevesoltys.seedvault.proto.Snapshot.Blob>) {
|
||||
_builder.putAllBlobs(map)
|
||||
}
|
||||
/**
|
||||
* <code>map<string, .com.stevesoltys.seedvault.proto.Snapshot.Blob> blobs = 11;</code>
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@JvmName("clearBlobs")
|
||||
public fun com.google.protobuf.kotlin.DslMap<kotlin.String, com.stevesoltys.seedvault.proto.Snapshot.Blob, BlobsProxy>
|
||||
.clear() {
|
||||
_builder.clearBlobs()
|
||||
}
|
||||
}
|
||||
@kotlin.jvm.JvmName("-initializeapp")
|
||||
public inline fun app(block: com.stevesoltys.seedvault.proto.SnapshotKt.AppKt.Dsl.() -> kotlin.Unit): com.stevesoltys.seedvault.proto.Snapshot.App =
|
||||
com.stevesoltys.seedvault.proto.SnapshotKt.AppKt.Dsl._create(com.stevesoltys.seedvault.proto.Snapshot.App.newBuilder()).apply { block() }._build()
|
||||
public object AppKt {
|
||||
@kotlin.OptIn(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)
|
||||
@com.google.protobuf.kotlin.ProtoDslMarker
|
||||
public class Dsl private constructor(
|
||||
private val _builder: com.stevesoltys.seedvault.proto.Snapshot.App.Builder
|
||||
) {
|
||||
public companion object {
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.PublishedApi
|
||||
internal fun _create(builder: com.stevesoltys.seedvault.proto.Snapshot.App.Builder): Dsl = Dsl(builder)
|
||||
}
|
||||
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.PublishedApi
|
||||
internal fun _build(): com.stevesoltys.seedvault.proto.Snapshot.App = _builder.build()
|
||||
|
||||
/**
|
||||
* <code>uint64 time = 1;</code>
|
||||
*/
|
||||
public var time: kotlin.Long
|
||||
@JvmName("getTime")
|
||||
get() = _builder.getTime()
|
||||
@JvmName("setTime")
|
||||
set(value) {
|
||||
_builder.setTime(value)
|
||||
}
|
||||
/**
|
||||
* <code>uint64 time = 1;</code>
|
||||
*/
|
||||
public fun clearTime() {
|
||||
_builder.clearTime()
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>.com.stevesoltys.seedvault.proto.Snapshot.BackupType type = 2;</code>
|
||||
*/
|
||||
public var type: com.stevesoltys.seedvault.proto.Snapshot.BackupType
|
||||
@JvmName("getType")
|
||||
get() = _builder.getType()
|
||||
@JvmName("setType")
|
||||
set(value) {
|
||||
_builder.setType(value)
|
||||
}
|
||||
/**
|
||||
* <code>.com.stevesoltys.seedvault.proto.Snapshot.BackupType type = 2;</code>
|
||||
*/
|
||||
public fun clearType() {
|
||||
_builder.clearType()
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>string name = 3;</code>
|
||||
*/
|
||||
public var name: kotlin.String
|
||||
@JvmName("getName")
|
||||
get() = _builder.getName()
|
||||
@JvmName("setName")
|
||||
set(value) {
|
||||
_builder.setName(value)
|
||||
}
|
||||
/**
|
||||
* <code>string name = 3;</code>
|
||||
*/
|
||||
public fun clearName() {
|
||||
_builder.clearName()
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>bool system = 4;</code>
|
||||
*/
|
||||
public var system: kotlin.Boolean
|
||||
@JvmName("getSystem")
|
||||
get() = _builder.getSystem()
|
||||
@JvmName("setSystem")
|
||||
set(value) {
|
||||
_builder.setSystem(value)
|
||||
}
|
||||
/**
|
||||
* <code>bool system = 4;</code>
|
||||
*/
|
||||
public fun clearSystem() {
|
||||
_builder.clearSystem()
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>bool launchableSystemApp = 5;</code>
|
||||
*/
|
||||
public var launchableSystemApp: kotlin.Boolean
|
||||
@JvmName("getLaunchableSystemApp")
|
||||
get() = _builder.getLaunchableSystemApp()
|
||||
@JvmName("setLaunchableSystemApp")
|
||||
set(value) {
|
||||
_builder.setLaunchableSystemApp(value)
|
||||
}
|
||||
/**
|
||||
* <code>bool launchableSystemApp = 5;</code>
|
||||
*/
|
||||
public fun clearLaunchableSystemApp() {
|
||||
_builder.clearLaunchableSystemApp()
|
||||
}
|
||||
|
||||
/**
|
||||
* An uninstantiable, behaviorless type to represent the field in
|
||||
* generics.
|
||||
*/
|
||||
@kotlin.OptIn(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)
|
||||
public class ChunkIdsProxy private constructor() : com.google.protobuf.kotlin.DslProxy()
|
||||
/**
|
||||
* <code>repeated bytes chunkIds = 6;</code>
|
||||
*/
|
||||
public val chunkIds: com.google.protobuf.kotlin.DslList<com.google.protobuf.ByteString, ChunkIdsProxy>
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
get() = com.google.protobuf.kotlin.DslList(
|
||||
_builder.getChunkIdsList()
|
||||
)
|
||||
/**
|
||||
* <code>repeated bytes chunkIds = 6;</code>
|
||||
* @param value The chunkIds to add.
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.jvm.JvmName("addChunkIds")
|
||||
public fun com.google.protobuf.kotlin.DslList<com.google.protobuf.ByteString, ChunkIdsProxy>.add(value: com.google.protobuf.ByteString) {
|
||||
_builder.addChunkIds(value)
|
||||
}/**
|
||||
* <code>repeated bytes chunkIds = 6;</code>
|
||||
* @param value The chunkIds to add.
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.jvm.JvmName("plusAssignChunkIds")
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
public inline operator fun com.google.protobuf.kotlin.DslList<com.google.protobuf.ByteString, ChunkIdsProxy>.plusAssign(value: com.google.protobuf.ByteString) {
|
||||
add(value)
|
||||
}/**
|
||||
* <code>repeated bytes chunkIds = 6;</code>
|
||||
* @param values The chunkIds to add.
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.jvm.JvmName("addAllChunkIds")
|
||||
public fun com.google.protobuf.kotlin.DslList<com.google.protobuf.ByteString, ChunkIdsProxy>.addAll(values: kotlin.collections.Iterable<com.google.protobuf.ByteString>) {
|
||||
_builder.addAllChunkIds(values)
|
||||
}/**
|
||||
* <code>repeated bytes chunkIds = 6;</code>
|
||||
* @param values The chunkIds to add.
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.jvm.JvmName("plusAssignAllChunkIds")
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
public inline operator fun com.google.protobuf.kotlin.DslList<com.google.protobuf.ByteString, ChunkIdsProxy>.plusAssign(values: kotlin.collections.Iterable<com.google.protobuf.ByteString>) {
|
||||
addAll(values)
|
||||
}/**
|
||||
* <code>repeated bytes chunkIds = 6;</code>
|
||||
* @param index The index to set the value at.
|
||||
* @param value The chunkIds to set.
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.jvm.JvmName("setChunkIds")
|
||||
public operator fun com.google.protobuf.kotlin.DslList<com.google.protobuf.ByteString, ChunkIdsProxy>.set(index: kotlin.Int, value: com.google.protobuf.ByteString) {
|
||||
_builder.setChunkIds(index, value)
|
||||
}/**
|
||||
* <code>repeated bytes chunkIds = 6;</code>
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.jvm.JvmName("clearChunkIds")
|
||||
public fun com.google.protobuf.kotlin.DslList<com.google.protobuf.ByteString, ChunkIdsProxy>.clear() {
|
||||
_builder.clearChunkIds()
|
||||
}
|
||||
/**
|
||||
* <code>.com.stevesoltys.seedvault.proto.Snapshot.Apk apk = 7;</code>
|
||||
*/
|
||||
public var apk: com.stevesoltys.seedvault.proto.Snapshot.Apk
|
||||
@JvmName("getApk")
|
||||
get() = _builder.getApk()
|
||||
@JvmName("setApk")
|
||||
set(value) {
|
||||
_builder.setApk(value)
|
||||
}
|
||||
/**
|
||||
* <code>.com.stevesoltys.seedvault.proto.Snapshot.Apk apk = 7;</code>
|
||||
*/
|
||||
public fun clearApk() {
|
||||
_builder.clearApk()
|
||||
}
|
||||
/**
|
||||
* <code>.com.stevesoltys.seedvault.proto.Snapshot.Apk apk = 7;</code>
|
||||
* @return Whether the apk field is set.
|
||||
*/
|
||||
public fun hasApk(): kotlin.Boolean {
|
||||
return _builder.hasApk()
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>uint64 size = 8;</code>
|
||||
*/
|
||||
public var size: kotlin.Long
|
||||
@JvmName("getSize")
|
||||
get() = _builder.getSize()
|
||||
@JvmName("setSize")
|
||||
set(value) {
|
||||
_builder.setSize(value)
|
||||
}
|
||||
/**
|
||||
* <code>uint64 size = 8;</code>
|
||||
*/
|
||||
public fun clearSize() {
|
||||
_builder.clearSize()
|
||||
}
|
||||
}
|
||||
}
|
||||
@kotlin.jvm.JvmName("-initializeapk")
|
||||
public inline fun apk(block: com.stevesoltys.seedvault.proto.SnapshotKt.ApkKt.Dsl.() -> kotlin.Unit): com.stevesoltys.seedvault.proto.Snapshot.Apk =
|
||||
com.stevesoltys.seedvault.proto.SnapshotKt.ApkKt.Dsl._create(com.stevesoltys.seedvault.proto.Snapshot.Apk.newBuilder()).apply { block() }._build()
|
||||
public object ApkKt {
|
||||
@kotlin.OptIn(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)
|
||||
@com.google.protobuf.kotlin.ProtoDslMarker
|
||||
public class Dsl private constructor(
|
||||
private val _builder: com.stevesoltys.seedvault.proto.Snapshot.Apk.Builder
|
||||
) {
|
||||
public companion object {
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.PublishedApi
|
||||
internal fun _create(builder: com.stevesoltys.seedvault.proto.Snapshot.Apk.Builder): Dsl = Dsl(builder)
|
||||
}
|
||||
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.PublishedApi
|
||||
internal fun _build(): com.stevesoltys.seedvault.proto.Snapshot.Apk = _builder.build()
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
**
|
||||
* Attention: Has default value of 0
|
||||
* </pre>
|
||||
*
|
||||
* <code>uint64 versionCode = 1;</code>
|
||||
*/
|
||||
public var versionCode: kotlin.Long
|
||||
@JvmName("getVersionCode")
|
||||
get() = _builder.getVersionCode()
|
||||
@JvmName("setVersionCode")
|
||||
set(value) {
|
||||
_builder.setVersionCode(value)
|
||||
}
|
||||
/**
|
||||
* <pre>
|
||||
**
|
||||
* Attention: Has default value of 0
|
||||
* </pre>
|
||||
*
|
||||
* <code>uint64 versionCode = 1;</code>
|
||||
*/
|
||||
public fun clearVersionCode() {
|
||||
_builder.clearVersionCode()
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>string installer = 2;</code>
|
||||
*/
|
||||
public var installer: kotlin.String
|
||||
@JvmName("getInstaller")
|
||||
get() = _builder.getInstaller()
|
||||
@JvmName("setInstaller")
|
||||
set(value) {
|
||||
_builder.setInstaller(value)
|
||||
}
|
||||
/**
|
||||
* <code>string installer = 2;</code>
|
||||
*/
|
||||
public fun clearInstaller() {
|
||||
_builder.clearInstaller()
|
||||
}
|
||||
|
||||
/**
|
||||
* An uninstantiable, behaviorless type to represent the field in
|
||||
* generics.
|
||||
*/
|
||||
@kotlin.OptIn(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)
|
||||
public class SignaturesProxy private constructor() : com.google.protobuf.kotlin.DslProxy()
|
||||
/**
|
||||
* <code>repeated bytes signatures = 3;</code>
|
||||
*/
|
||||
public val signatures: com.google.protobuf.kotlin.DslList<com.google.protobuf.ByteString, SignaturesProxy>
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
get() = com.google.protobuf.kotlin.DslList(
|
||||
_builder.getSignaturesList()
|
||||
)
|
||||
/**
|
||||
* <code>repeated bytes signatures = 3;</code>
|
||||
* @param value The signatures to add.
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.jvm.JvmName("addSignatures")
|
||||
public fun com.google.protobuf.kotlin.DslList<com.google.protobuf.ByteString, SignaturesProxy>.add(value: com.google.protobuf.ByteString) {
|
||||
_builder.addSignatures(value)
|
||||
}/**
|
||||
* <code>repeated bytes signatures = 3;</code>
|
||||
* @param value The signatures to add.
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.jvm.JvmName("plusAssignSignatures")
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
public inline operator fun com.google.protobuf.kotlin.DslList<com.google.protobuf.ByteString, SignaturesProxy>.plusAssign(value: com.google.protobuf.ByteString) {
|
||||
add(value)
|
||||
}/**
|
||||
* <code>repeated bytes signatures = 3;</code>
|
||||
* @param values The signatures to add.
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.jvm.JvmName("addAllSignatures")
|
||||
public fun com.google.protobuf.kotlin.DslList<com.google.protobuf.ByteString, SignaturesProxy>.addAll(values: kotlin.collections.Iterable<com.google.protobuf.ByteString>) {
|
||||
_builder.addAllSignatures(values)
|
||||
}/**
|
||||
* <code>repeated bytes signatures = 3;</code>
|
||||
* @param values The signatures to add.
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.jvm.JvmName("plusAssignAllSignatures")
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
public inline operator fun com.google.protobuf.kotlin.DslList<com.google.protobuf.ByteString, SignaturesProxy>.plusAssign(values: kotlin.collections.Iterable<com.google.protobuf.ByteString>) {
|
||||
addAll(values)
|
||||
}/**
|
||||
* <code>repeated bytes signatures = 3;</code>
|
||||
* @param index The index to set the value at.
|
||||
* @param value The signatures to set.
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.jvm.JvmName("setSignatures")
|
||||
public operator fun com.google.protobuf.kotlin.DslList<com.google.protobuf.ByteString, SignaturesProxy>.set(index: kotlin.Int, value: com.google.protobuf.ByteString) {
|
||||
_builder.setSignatures(index, value)
|
||||
}/**
|
||||
* <code>repeated bytes signatures = 3;</code>
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.jvm.JvmName("clearSignatures")
|
||||
public fun com.google.protobuf.kotlin.DslList<com.google.protobuf.ByteString, SignaturesProxy>.clear() {
|
||||
_builder.clearSignatures()
|
||||
}
|
||||
/**
|
||||
* An uninstantiable, behaviorless type to represent the field in
|
||||
* generics.
|
||||
*/
|
||||
@kotlin.OptIn(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)
|
||||
public class SplitsProxy private constructor() : com.google.protobuf.kotlin.DslProxy()
|
||||
/**
|
||||
* <code>repeated .com.stevesoltys.seedvault.proto.Snapshot.Split splits = 4;</code>
|
||||
*/
|
||||
public val splits: com.google.protobuf.kotlin.DslList<com.stevesoltys.seedvault.proto.Snapshot.Split, SplitsProxy>
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
get() = com.google.protobuf.kotlin.DslList(
|
||||
_builder.getSplitsList()
|
||||
)
|
||||
/**
|
||||
* <code>repeated .com.stevesoltys.seedvault.proto.Snapshot.Split splits = 4;</code>
|
||||
* @param value The splits to add.
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.jvm.JvmName("addSplits")
|
||||
public fun com.google.protobuf.kotlin.DslList<com.stevesoltys.seedvault.proto.Snapshot.Split, SplitsProxy>.add(value: com.stevesoltys.seedvault.proto.Snapshot.Split) {
|
||||
_builder.addSplits(value)
|
||||
}
|
||||
/**
|
||||
* <code>repeated .com.stevesoltys.seedvault.proto.Snapshot.Split splits = 4;</code>
|
||||
* @param value The splits to add.
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.jvm.JvmName("plusAssignSplits")
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
public inline operator fun com.google.protobuf.kotlin.DslList<com.stevesoltys.seedvault.proto.Snapshot.Split, SplitsProxy>.plusAssign(value: com.stevesoltys.seedvault.proto.Snapshot.Split) {
|
||||
add(value)
|
||||
}
|
||||
/**
|
||||
* <code>repeated .com.stevesoltys.seedvault.proto.Snapshot.Split splits = 4;</code>
|
||||
* @param values The splits to add.
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.jvm.JvmName("addAllSplits")
|
||||
public fun com.google.protobuf.kotlin.DslList<com.stevesoltys.seedvault.proto.Snapshot.Split, SplitsProxy>.addAll(values: kotlin.collections.Iterable<com.stevesoltys.seedvault.proto.Snapshot.Split>) {
|
||||
_builder.addAllSplits(values)
|
||||
}
|
||||
/**
|
||||
* <code>repeated .com.stevesoltys.seedvault.proto.Snapshot.Split splits = 4;</code>
|
||||
* @param values The splits to add.
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.jvm.JvmName("plusAssignAllSplits")
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
public inline operator fun com.google.protobuf.kotlin.DslList<com.stevesoltys.seedvault.proto.Snapshot.Split, SplitsProxy>.plusAssign(values: kotlin.collections.Iterable<com.stevesoltys.seedvault.proto.Snapshot.Split>) {
|
||||
addAll(values)
|
||||
}
|
||||
/**
|
||||
* <code>repeated .com.stevesoltys.seedvault.proto.Snapshot.Split splits = 4;</code>
|
||||
* @param index The index to set the value at.
|
||||
* @param value The splits to set.
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.jvm.JvmName("setSplits")
|
||||
public operator fun com.google.protobuf.kotlin.DslList<com.stevesoltys.seedvault.proto.Snapshot.Split, SplitsProxy>.set(index: kotlin.Int, value: com.stevesoltys.seedvault.proto.Snapshot.Split) {
|
||||
_builder.setSplits(index, value)
|
||||
}
|
||||
/**
|
||||
* <code>repeated .com.stevesoltys.seedvault.proto.Snapshot.Split splits = 4;</code>
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.jvm.JvmName("clearSplits")
|
||||
public fun com.google.protobuf.kotlin.DslList<com.stevesoltys.seedvault.proto.Snapshot.Split, SplitsProxy>.clear() {
|
||||
_builder.clearSplits()
|
||||
}
|
||||
}
|
||||
}
|
||||
@kotlin.jvm.JvmName("-initializesplit")
|
||||
public inline fun split(block: com.stevesoltys.seedvault.proto.SnapshotKt.SplitKt.Dsl.() -> kotlin.Unit): com.stevesoltys.seedvault.proto.Snapshot.Split =
|
||||
com.stevesoltys.seedvault.proto.SnapshotKt.SplitKt.Dsl._create(com.stevesoltys.seedvault.proto.Snapshot.Split.newBuilder()).apply { block() }._build()
|
||||
public object SplitKt {
|
||||
@kotlin.OptIn(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)
|
||||
@com.google.protobuf.kotlin.ProtoDslMarker
|
||||
public class Dsl private constructor(
|
||||
private val _builder: com.stevesoltys.seedvault.proto.Snapshot.Split.Builder
|
||||
) {
|
||||
public companion object {
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.PublishedApi
|
||||
internal fun _create(builder: com.stevesoltys.seedvault.proto.Snapshot.Split.Builder): Dsl = Dsl(builder)
|
||||
}
|
||||
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.PublishedApi
|
||||
internal fun _build(): com.stevesoltys.seedvault.proto.Snapshot.Split = _builder.build()
|
||||
|
||||
/**
|
||||
* <code>string name = 1;</code>
|
||||
*/
|
||||
public var name: kotlin.String
|
||||
@JvmName("getName")
|
||||
get() = _builder.getName()
|
||||
@JvmName("setName")
|
||||
set(value) {
|
||||
_builder.setName(value)
|
||||
}
|
||||
/**
|
||||
* <code>string name = 1;</code>
|
||||
*/
|
||||
public fun clearName() {
|
||||
_builder.clearName()
|
||||
}
|
||||
|
||||
/**
|
||||
* An uninstantiable, behaviorless type to represent the field in
|
||||
* generics.
|
||||
*/
|
||||
@kotlin.OptIn(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)
|
||||
public class ChunkIdsProxy private constructor() : com.google.protobuf.kotlin.DslProxy()
|
||||
/**
|
||||
* <code>repeated bytes chunkIds = 2;</code>
|
||||
*/
|
||||
public val chunkIds: com.google.protobuf.kotlin.DslList<com.google.protobuf.ByteString, ChunkIdsProxy>
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
get() = com.google.protobuf.kotlin.DslList(
|
||||
_builder.getChunkIdsList()
|
||||
)
|
||||
/**
|
||||
* <code>repeated bytes chunkIds = 2;</code>
|
||||
* @param value The chunkIds to add.
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.jvm.JvmName("addChunkIds")
|
||||
public fun com.google.protobuf.kotlin.DslList<com.google.protobuf.ByteString, ChunkIdsProxy>.add(value: com.google.protobuf.ByteString) {
|
||||
_builder.addChunkIds(value)
|
||||
}/**
|
||||
* <code>repeated bytes chunkIds = 2;</code>
|
||||
* @param value The chunkIds to add.
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.jvm.JvmName("plusAssignChunkIds")
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
public inline operator fun com.google.protobuf.kotlin.DslList<com.google.protobuf.ByteString, ChunkIdsProxy>.plusAssign(value: com.google.protobuf.ByteString) {
|
||||
add(value)
|
||||
}/**
|
||||
* <code>repeated bytes chunkIds = 2;</code>
|
||||
* @param values The chunkIds to add.
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.jvm.JvmName("addAllChunkIds")
|
||||
public fun com.google.protobuf.kotlin.DslList<com.google.protobuf.ByteString, ChunkIdsProxy>.addAll(values: kotlin.collections.Iterable<com.google.protobuf.ByteString>) {
|
||||
_builder.addAllChunkIds(values)
|
||||
}/**
|
||||
* <code>repeated bytes chunkIds = 2;</code>
|
||||
* @param values The chunkIds to add.
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.jvm.JvmName("plusAssignAllChunkIds")
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
public inline operator fun com.google.protobuf.kotlin.DslList<com.google.protobuf.ByteString, ChunkIdsProxy>.plusAssign(values: kotlin.collections.Iterable<com.google.protobuf.ByteString>) {
|
||||
addAll(values)
|
||||
}/**
|
||||
* <code>repeated bytes chunkIds = 2;</code>
|
||||
* @param index The index to set the value at.
|
||||
* @param value The chunkIds to set.
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.jvm.JvmName("setChunkIds")
|
||||
public operator fun com.google.protobuf.kotlin.DslList<com.google.protobuf.ByteString, ChunkIdsProxy>.set(index: kotlin.Int, value: com.google.protobuf.ByteString) {
|
||||
_builder.setChunkIds(index, value)
|
||||
}/**
|
||||
* <code>repeated bytes chunkIds = 2;</code>
|
||||
*/
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.jvm.JvmName("clearChunkIds")
|
||||
public fun com.google.protobuf.kotlin.DslList<com.google.protobuf.ByteString, ChunkIdsProxy>.clear() {
|
||||
_builder.clearChunkIds()
|
||||
}}
|
||||
}
|
||||
@kotlin.jvm.JvmName("-initializeblob")
|
||||
public inline fun blob(block: com.stevesoltys.seedvault.proto.SnapshotKt.BlobKt.Dsl.() -> kotlin.Unit): com.stevesoltys.seedvault.proto.Snapshot.Blob =
|
||||
com.stevesoltys.seedvault.proto.SnapshotKt.BlobKt.Dsl._create(com.stevesoltys.seedvault.proto.Snapshot.Blob.newBuilder()).apply { block() }._build()
|
||||
public object BlobKt {
|
||||
@kotlin.OptIn(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)
|
||||
@com.google.protobuf.kotlin.ProtoDslMarker
|
||||
public class Dsl private constructor(
|
||||
private val _builder: com.stevesoltys.seedvault.proto.Snapshot.Blob.Builder
|
||||
) {
|
||||
public companion object {
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.PublishedApi
|
||||
internal fun _create(builder: com.stevesoltys.seedvault.proto.Snapshot.Blob.Builder): Dsl = Dsl(builder)
|
||||
}
|
||||
|
||||
@kotlin.jvm.JvmSynthetic
|
||||
@kotlin.PublishedApi
|
||||
internal fun _build(): com.stevesoltys.seedvault.proto.Snapshot.Blob = _builder.build()
|
||||
|
||||
/**
|
||||
* <code>bytes id = 1;</code>
|
||||
*/
|
||||
public var id: com.google.protobuf.ByteString
|
||||
@JvmName("getId")
|
||||
get() = _builder.getId()
|
||||
@JvmName("setId")
|
||||
set(value) {
|
||||
_builder.setId(value)
|
||||
}
|
||||
/**
|
||||
* <code>bytes id = 1;</code>
|
||||
*/
|
||||
public fun clearId() {
|
||||
_builder.clearId()
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>uint32 length = 2;</code>
|
||||
*/
|
||||
public var length: kotlin.Int
|
||||
@JvmName("getLength")
|
||||
get() = _builder.getLength()
|
||||
@JvmName("setLength")
|
||||
set(value) {
|
||||
_builder.setLength(value)
|
||||
}
|
||||
/**
|
||||
* <code>uint32 length = 2;</code>
|
||||
*/
|
||||
public fun clearLength() {
|
||||
_builder.clearLength()
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>uint32 uncompressedLength = 3;</code>
|
||||
*/
|
||||
public var uncompressedLength: kotlin.Int
|
||||
@JvmName("getUncompressedLength")
|
||||
get() = _builder.getUncompressedLength()
|
||||
@JvmName("setUncompressedLength")
|
||||
set(value) {
|
||||
_builder.setUncompressedLength(value)
|
||||
}
|
||||
/**
|
||||
* <code>uint32 uncompressedLength = 3;</code>
|
||||
*/
|
||||
public fun clearUncompressedLength() {
|
||||
_builder.clearUncompressedLength()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public inline fun com.stevesoltys.seedvault.proto.Snapshot.copy(block: com.stevesoltys.seedvault.proto.SnapshotKt.Dsl.() -> kotlin.Unit): com.stevesoltys.seedvault.proto.Snapshot =
|
||||
com.stevesoltys.seedvault.proto.SnapshotKt.Dsl._create(this.toBuilder()).apply { block() }._build()
|
||||
|
||||
public inline fun com.stevesoltys.seedvault.proto.Snapshot.App.copy(block: com.stevesoltys.seedvault.proto.SnapshotKt.AppKt.Dsl.() -> kotlin.Unit): com.stevesoltys.seedvault.proto.Snapshot.App =
|
||||
com.stevesoltys.seedvault.proto.SnapshotKt.AppKt.Dsl._create(this.toBuilder()).apply { block() }._build()
|
||||
|
||||
public val com.stevesoltys.seedvault.proto.Snapshot.AppOrBuilder.apkOrNull: com.stevesoltys.seedvault.proto.Snapshot.Apk?
|
||||
get() = if (hasApk()) getApk() else null
|
||||
|
||||
public inline fun com.stevesoltys.seedvault.proto.Snapshot.Apk.copy(block: com.stevesoltys.seedvault.proto.SnapshotKt.ApkKt.Dsl.() -> kotlin.Unit): com.stevesoltys.seedvault.proto.Snapshot.Apk =
|
||||
com.stevesoltys.seedvault.proto.SnapshotKt.ApkKt.Dsl._create(this.toBuilder()).apply { block() }._build()
|
||||
|
||||
public inline fun com.stevesoltys.seedvault.proto.Snapshot.Split.copy(block: com.stevesoltys.seedvault.proto.SnapshotKt.SplitKt.Dsl.() -> kotlin.Unit): com.stevesoltys.seedvault.proto.Snapshot.Split =
|
||||
com.stevesoltys.seedvault.proto.SnapshotKt.SplitKt.Dsl._create(this.toBuilder()).apply { block() }._build()
|
||||
|
||||
public inline fun com.stevesoltys.seedvault.proto.Snapshot.Blob.copy(block: com.stevesoltys.seedvault.proto.SnapshotKt.BlobKt.Dsl.() -> kotlin.Unit): com.stevesoltys.seedvault.proto.Snapshot.Blob =
|
||||
com.stevesoltys.seedvault.proto.SnapshotKt.BlobKt.Dsl._create(this.toBuilder()).apply { block() }._build()
|
||||
|
|
@ -39,7 +39,7 @@ This task depends on `app:assembleRelease` and runs the script in `scripts/insta
|
|||
./app/development/scripts/install_app.sh
|
||||
```
|
||||
|
||||
There's also an Android Studio [runtime configuration](https://developer.android.com/studio/run/rundebugconfig) `app-emulator` which will build, install, and automatically launch the `com.stevesoltys.seedvault.settings.SettingsActivity` as if you clicked `Backup` in settings.
|
||||
There's also an Andriod Studio [runtime configuration](https://developer.android.com/studio/run/rundebugconfig) `app-emulator` which will build, install, and automatically launch the `com.stevesoltys.seedvault.settings.SettingsActivity` as if you clicked `Backup` in settings.
|
||||
|
||||
### Notes
|
||||
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# SPDX-FileCopyrightText: 2023 The Calyx Institute
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
# assert ANDROID_HOME is set
|
||||
if [ -z "$ANDROID_HOME" ]; then
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# SPDX-FileCopyrightText: 2023 The Calyx Institute
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
# assert ANDROID_HOME is set
|
||||
if [ -z "$ANDROID_HOME" ]; then
|
||||
|
@ -11,9 +7,10 @@ if [ -z "$ANDROID_HOME" ]; then
|
|||
fi
|
||||
|
||||
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
|
||||
DEVELOPMENT_DIR=$SCRIPT_DIR/..
|
||||
ROOT_PROJECT_DIR=$SCRIPT_DIR/../../..
|
||||
|
||||
EMULATOR_DEVICE_NAME=$("$ANDROID_HOME"/platform-tools/adb devices | grep emulator | cut -f1)
|
||||
EMULATOR_DEVICE_NAME=$($ANDROID_HOME/platform-tools/adb devices | grep emulator | cut -f1)
|
||||
|
||||
if [ -z "$EMULATOR_DEVICE_NAME" ]; then
|
||||
echo "Emulator device name not found"
|
||||
|
@ -28,9 +25,8 @@ $ADB remount # remount /system as writable
|
|||
|
||||
echo "Installing Seedvault app..."
|
||||
$ADB shell mkdir -p /system/priv-app/Seedvault
|
||||
$ADB push "$ROOT_PROJECT_DIR"/app/build/outputs/apk/release/app-release.apk /system/priv-app/Seedvault/Seedvault.apk
|
||||
$ADB push $ROOT_PROJECT_DIR/app/build/outputs/apk/release/app-release.apk /system/priv-app/Seedvault/Seedvault.apk
|
||||
|
||||
echo "Installing Seedvault permissions..."
|
||||
$ADB push "$ROOT_PROJECT_DIR"/permissions_com.stevesoltys.seedvault.xml /system/etc/permissions/privapp-permissions-seedvault.xml
|
||||
$ADB push "$ROOT_PROJECT_DIR"/allowlist_com.stevesoltys.seedvault.xml /system/etc/sysconfig/allowlist-seedvault.xml
|
||||
$ADB shell am broadcast -a android.intent.action.BOOT_COMPLETED
|
||||
$ADB push $ROOT_PROJECT_DIR/permissions_com.stevesoltys.seedvault.xml /system/etc/permissions/privapp-permissions-seedvault.xml
|
||||
$ADB push $ROOT_PROJECT_DIR/allowlist_com.stevesoltys.seedvault.xml /system/etc/sysconfig/allowlist-seedvault.xml
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# SPDX-FileCopyrightText: 2023 The Calyx Institute
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
# assert ANDROID_HOME is set
|
||||
if [ -z "$ANDROID_HOME" ]; then
|
||||
|
@ -20,36 +16,26 @@ EMULATOR_NAME=$1
|
|||
SYSTEM_IMAGE=$2
|
||||
|
||||
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
|
||||
DEVELOPMENT_DIR=$SCRIPT_DIR/..
|
||||
ROOT_PROJECT_DIR=$SCRIPT_DIR/../../..
|
||||
|
||||
echo "Downloading system image..."
|
||||
yes | "$ANDROID_HOME"/cmdline-tools/latest/bin/sdkmanager --install "$SYSTEM_IMAGE"
|
||||
$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --install "$SYSTEM_IMAGE"
|
||||
|
||||
# create AVD if it doesn't exist
|
||||
if "$ANDROID_HOME"/cmdline-tools/latest/bin/avdmanager list avd | grep -q "$EMULATOR_NAME"; then
|
||||
if $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager list avd | grep -q "$EMULATOR_NAME"; then
|
||||
echo "AVD already exists. Skipping creation."
|
||||
else
|
||||
echo "Creating AVD..."
|
||||
echo 'no' | "$ANDROID_HOME"/cmdline-tools/latest/bin/avdmanager create avd -n "$EMULATOR_NAME" -k "$SYSTEM_IMAGE"
|
||||
echo 'no' | $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager create avd -n "$EMULATOR_NAME" -k "$SYSTEM_IMAGE"
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
EMULATOR_DEVICE_NAME=$("$ANDROID_HOME"/platform-tools/adb devices | grep emulator | cut -f1)
|
||||
$SCRIPT_DIR/start_emulator.sh "$EMULATOR_NAME"
|
||||
sleep 3
|
||||
|
||||
if [ -z "$EMULATOR_DEVICE_NAME" ]; then
|
||||
"$SCRIPT_DIR"/start_emulator.sh "$EMULATOR_NAME"
|
||||
fi
|
||||
|
||||
# wait for emulator device to appear with 180 second timeout
|
||||
echo "Waiting for emulator device..."
|
||||
|
||||
for i in {1..180}; do
|
||||
if [ -z "$EMULATOR_DEVICE_NAME" ]; then
|
||||
sleep 1
|
||||
EMULATOR_DEVICE_NAME=$("$ANDROID_HOME"/platform-tools/adb devices | grep emulator | cut -f1)
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
# get emulator device name from ADB
|
||||
EMULATOR_DEVICE_NAME=$($ANDROID_HOME/platform-tools/adb devices | grep emulator | cut -f1)
|
||||
|
||||
if [ -z "$EMULATOR_DEVICE_NAME" ]; then
|
||||
echo "Emulator device name not found"
|
||||
|
@ -71,33 +57,23 @@ $ADB reboot # need to reboot first time we remount
|
|||
$ADB wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;'
|
||||
|
||||
echo "Provisioning emulator for Seedvault..."
|
||||
"$SCRIPT_DIR"/install_app.sh
|
||||
$SCRIPT_DIR/install_app.sh
|
||||
|
||||
echo "Setting backup transport to Seedvault..."
|
||||
$ADB shell bmgr enable true
|
||||
$ADB shell bmgr transport com.stevesoltys.seedvault.transport.ConfigurableBackupTransport
|
||||
|
||||
echo "Rebooting emulator..."
|
||||
$ADB reboot
|
||||
$ADB wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;'
|
||||
|
||||
echo "Disabling backup..."
|
||||
$ADB shell bmgr enable false
|
||||
|
||||
echo "Downloading and extracting test backup to '/sdcard/seedvault_baseline'..."
|
||||
|
||||
if [ ! -f backup.tar.gz ]; then
|
||||
echo "Downloading test backup..."
|
||||
wget --quiet https://github.com/seedvault-app/seedvault-test-data/releases/download/3/backup.tar.gz
|
||||
fi
|
||||
|
||||
$ADB root
|
||||
sleep 3 # wait for adb to restart
|
||||
$ADB push backup.tar.gz /sdcard
|
||||
echo "Downloading and extracting test backup to '/sdcard/seedvault'..."
|
||||
wget https://github.com/seedvault-app/seedvault-test-data/releases/download/1/backup.tar.gz
|
||||
$ADB push backup.tar.gz /sdcard/
|
||||
rm backup.tar.gz
|
||||
|
||||
$ADB wait-for-device
|
||||
$ADB shell mkdir -p /sdcard/seedvault_baseline
|
||||
$ADB shell tar xzf /sdcard/backup.tar.gz --directory=/sdcard/seedvault_baseline
|
||||
$ADB shell rm /sdcard/backup.tar.gz
|
||||
|
||||
# sometimes a system dialog (e.g. launcher stopped) is showing and taking focus
|
||||
$ADB shell am broadcast -a android.intent.action.CLOSE_SYSTEM_DIALOGS
|
||||
|
||||
echo "Emulator '$EMULATOR_NAME' has been provisioned with Seedvault!"
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# SPDX-FileCopyrightText: 2023 The Calyx Institute
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
# assert ANDROID_HOME is set
|
||||
if [ -z "$ANDROID_HOME" ]; then
|
||||
|
@ -18,5 +14,9 @@ fi
|
|||
|
||||
EMULATOR_NAME=$1
|
||||
|
||||
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
|
||||
DEVELOPMENT_DIR=$SCRIPT_DIR/..
|
||||
ROOT_PROJECT_DIR=$SCRIPT_DIR/../../..
|
||||
|
||||
echo "Starting emulator..."
|
||||
nohup $ANDROID_HOME/emulator/emulator -avd "$EMULATOR_NAME" -gpu swiftshader_indirect -writable-system >/dev/null 2>&1 &
|
||||
nohup $ANDROID_HOME/emulator/emulator -avd "$EMULATOR_NAME" -gpu swiftshader_indirect -writable-system -no-snapshot-load >/dev/null 2>&1 &
|
||||
|
|
Binary file not shown.
BIN
app/libs/libcore.jar
Normal file
BIN
app/libs/libcore.jar
Normal file
Binary file not shown.
|
@ -1,8 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
SPDX-FileCopyrightText: 2020 The Calyx Institute
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
-->
|
||||
<lint>
|
||||
<issue id="MissingTranslation" severity="ignore" />
|
||||
<issue id="ExtraTranslation" severity="ignore" />
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
SPDX-FileCopyrightText: 2020 The Calyx Institute
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
-->
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<application android:extractNativeLibs="true" />
|
||||
</manifest>
|
||||
|
|
|
@ -1,30 +1,19 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2023 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault
|
||||
|
||||
import com.stevesoltys.seedvault.restore.RestoreViewModel
|
||||
import com.stevesoltys.seedvault.settings.SettingsManager
|
||||
import com.stevesoltys.seedvault.transport.backup.FullBackup
|
||||
import com.stevesoltys.seedvault.transport.backup.InputFactory
|
||||
import com.stevesoltys.seedvault.transport.backup.KVBackup
|
||||
import com.stevesoltys.seedvault.transport.backup.PackageService
|
||||
import com.stevesoltys.seedvault.transport.restore.FullRestore
|
||||
import com.stevesoltys.seedvault.transport.restore.KVRestore
|
||||
import com.stevesoltys.seedvault.transport.restore.OutputFactory
|
||||
import com.stevesoltys.seedvault.ui.notification.BackupNotificationManager
|
||||
import com.stevesoltys.seedvault.ui.storage.BackupStorageViewModel
|
||||
import com.stevesoltys.seedvault.ui.storage.RestoreStorageViewModel
|
||||
import io.mockk.spyk
|
||||
import org.koin.androidx.viewmodel.dsl.viewModel
|
||||
import org.koin.core.module.Module
|
||||
import org.koin.dsl.module
|
||||
|
||||
internal var currentRestoreViewModel: RestoreViewModel? = null
|
||||
internal var currentBackupStorageViewModel: BackupStorageViewModel? = null
|
||||
internal var currentRestoreStorageViewModel: RestoreStorageViewModel? = null
|
||||
|
||||
class KoinInstrumentationTestApp : App() {
|
||||
|
||||
|
@ -32,50 +21,20 @@ class KoinInstrumentationTestApp : App() {
|
|||
val testModule = module {
|
||||
val context = this@KoinInstrumentationTestApp
|
||||
|
||||
single { spyk(PackageService(context, get(), get())) }
|
||||
single { spyk(SettingsManager(context)) }
|
||||
|
||||
single { spyk(BackupNotificationManager(context)) }
|
||||
single { spyk(FullBackup(get(), get(), get(), get())) }
|
||||
single { spyk(KVBackup(get(), get(), get())) }
|
||||
single { spyk(KVBackup(get(), get(), get(), get(), get())) }
|
||||
single { spyk(InputFactory()) }
|
||||
|
||||
single { spyk(FullRestore(get(), get(), get(), get(), get(), get())) }
|
||||
single { spyk(KVRestore(get(), get(), get(), get(), get(), get(), get())) }
|
||||
single { spyk(FullRestore(get(), get(), get(), get(), get())) }
|
||||
single { spyk(KVRestore(get(), get(), get(), get(), get(), get())) }
|
||||
single { spyk(OutputFactory()) }
|
||||
|
||||
viewModel {
|
||||
currentRestoreViewModel =
|
||||
spyk(
|
||||
RestoreViewModel(
|
||||
app = context,
|
||||
settingsManager = get(),
|
||||
keyManager = get(),
|
||||
backupManager = get(),
|
||||
restoreCoordinator = get(),
|
||||
appBackupManager = get(),
|
||||
apkRestore = get(),
|
||||
iconManager = get(),
|
||||
storageBackup = get(),
|
||||
backendManager = get(),
|
||||
fileSelectionManager = get(),
|
||||
)
|
||||
)
|
||||
spyk(RestoreViewModel(context, get(), get(), get(), get(), get(), get()))
|
||||
currentRestoreViewModel!!
|
||||
}
|
||||
|
||||
viewModel {
|
||||
val viewModel =
|
||||
BackupStorageViewModel(context, get(), get(), get(), get(), get(), get(), get())
|
||||
currentBackupStorageViewModel = spyk(viewModel)
|
||||
currentBackupStorageViewModel!!
|
||||
}
|
||||
|
||||
viewModel {
|
||||
currentRestoreStorageViewModel =
|
||||
spyk(RestoreStorageViewModel(context, get(), get(), get(), get()))
|
||||
currentRestoreStorageViewModel!!
|
||||
}
|
||||
}
|
||||
|
||||
return super.appModules().plus(testModule)
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2023 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault
|
||||
|
||||
import android.app.Application
|
||||
|
|
|
@ -1,26 +1,24 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2020 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault
|
||||
|
||||
import androidx.test.core.content.pm.PackageInfoBuilder
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.filters.MediumTest
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.stevesoltys.seedvault.backend.LegacyStoragePlugin
|
||||
import com.stevesoltys.seedvault.backend.saf.DocumentsProviderLegacyPlugin
|
||||
import com.stevesoltys.seedvault.backend.saf.DocumentsStorage
|
||||
import com.stevesoltys.seedvault.plugins.LegacyStoragePlugin
|
||||
import com.stevesoltys.seedvault.plugins.StoragePlugin
|
||||
import com.stevesoltys.seedvault.plugins.saf.DocumentsProviderLegacyPlugin
|
||||
import com.stevesoltys.seedvault.plugins.saf.DocumentsProviderStoragePlugin
|
||||
import com.stevesoltys.seedvault.plugins.saf.DocumentsStorage
|
||||
import com.stevesoltys.seedvault.plugins.saf.FILE_BACKUP_METADATA
|
||||
import com.stevesoltys.seedvault.plugins.saf.deleteContents
|
||||
import com.stevesoltys.seedvault.settings.SettingsManager
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.calyxos.seedvault.core.backends.LegacyAppBackupFile
|
||||
import org.calyxos.seedvault.core.backends.saf.SafBackend
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
|
@ -30,23 +28,20 @@ import org.koin.core.component.KoinComponent
|
|||
import org.koin.core.component.inject
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
@MediumTest
|
||||
class PluginTest : KoinComponent {
|
||||
|
||||
private val context = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
private val settingsManager: SettingsManager by inject()
|
||||
private val mockedSettingsManager: SettingsManager = mockk()
|
||||
private val storage = DocumentsStorage(
|
||||
appContext = context,
|
||||
safStorage = settingsManager.getSafProperties() ?: error("No SAF storage"),
|
||||
)
|
||||
private val storage = DocumentsStorage(context, mockedSettingsManager)
|
||||
|
||||
private val backend = SafBackend(context, storage.safStorage)
|
||||
private val storagePlugin: StoragePlugin = DocumentsProviderStoragePlugin(context, storage)
|
||||
|
||||
@Suppress("Deprecation")
|
||||
private val legacyStoragePlugin: LegacyStoragePlugin = DocumentsProviderLegacyPlugin(context) {
|
||||
storage
|
||||
}
|
||||
private val legacyStoragePlugin: LegacyStoragePlugin =
|
||||
DocumentsProviderLegacyPlugin(context, storage)
|
||||
|
||||
private val token = System.currentTimeMillis() - 365L * 24L * 60L * 60L * 1000L
|
||||
private val packageInfo = PackageInfoBuilder.newBuilder().setPackageName("org.example").build()
|
||||
|
@ -54,31 +49,20 @@ class PluginTest : KoinComponent {
|
|||
|
||||
@Before
|
||||
fun setup() = runBlocking {
|
||||
every {
|
||||
mockedSettingsManager.getSafProperties()
|
||||
} returns settingsManager.getSafProperties()
|
||||
backend.removeAll()
|
||||
every { mockedSettingsManager.getStorage() } returns settingsManager.getStorage()
|
||||
storage.rootBackupDir?.deleteContents(context)
|
||||
?: error("Select a storage location in the app first!")
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown() = runBlocking {
|
||||
backend.removeAll()
|
||||
storage.rootBackupDir?.deleteContents(context)
|
||||
Unit
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testProviderPackageName() {
|
||||
assertNotNull(backend.providerPackageName)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testTest() = runBlocking(Dispatchers.IO) {
|
||||
assertTrue(backend.test())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGetFreeSpace() = runBlocking(Dispatchers.IO) {
|
||||
val freeBytes = backend.getFreeSpace() ?: error("no free space retrieved")
|
||||
assertTrue(freeBytes > 0)
|
||||
assertNotNull(storagePlugin.providerPackageName)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -91,66 +75,84 @@ class PluginTest : KoinComponent {
|
|||
@Test
|
||||
fun testInitializationAndRestoreSets() = runBlocking(Dispatchers.IO) {
|
||||
// no backups available initially
|
||||
assertEquals(0, backend.getAvailableBackupFileHandles().toList().size)
|
||||
assertEquals(0, storagePlugin.getAvailableBackups()?.toList()?.size)
|
||||
val s = settingsManager.getStorage() ?: error("no storage")
|
||||
assertFalse(storagePlugin.hasBackup(s))
|
||||
|
||||
// prepare returned tokens requested when initializing device
|
||||
every { mockedSettingsManager.token } returnsMany listOf(token, token + 1, token + 1)
|
||||
every { mockedSettingsManager.getToken() } returnsMany listOf(token, token + 1, token + 1)
|
||||
|
||||
// start new restore set and initialize device afterwards
|
||||
storagePlugin.startNewRestoreSet(token)
|
||||
storagePlugin.initializeDevice()
|
||||
|
||||
// write metadata (needed for backup to be recognized)
|
||||
backend.save(LegacyAppBackupFile.Metadata(token))
|
||||
storagePlugin.getOutputStream(token, FILE_BACKUP_METADATA)
|
||||
.writeAndClose(getRandomByteArray())
|
||||
|
||||
// one backup available now
|
||||
assertEquals(1, backend.getAvailableBackupFileHandles().toList().size)
|
||||
assertEquals(1, storagePlugin.getAvailableBackups()?.toList()?.size)
|
||||
assertTrue(storagePlugin.hasBackup(s))
|
||||
|
||||
// initializing again (with another restore set) does add a restore set
|
||||
backend.save(LegacyAppBackupFile.Metadata(token + 1))
|
||||
storagePlugin.startNewRestoreSet(token + 1)
|
||||
storagePlugin.initializeDevice()
|
||||
storagePlugin.getOutputStream(token + 1, FILE_BACKUP_METADATA)
|
||||
.writeAndClose(getRandomByteArray())
|
||||
assertEquals(2, backend.getAvailableBackupFileHandles().toList().size)
|
||||
assertEquals(2, storagePlugin.getAvailableBackups()?.toList()?.size)
|
||||
assertTrue(storagePlugin.hasBackup(s))
|
||||
|
||||
// initializing again (without new restore set) doesn't change number of restore sets
|
||||
backend.save(LegacyAppBackupFile.Metadata(token + 1))
|
||||
storagePlugin.initializeDevice()
|
||||
storagePlugin.getOutputStream(token + 1, FILE_BACKUP_METADATA)
|
||||
.writeAndClose(getRandomByteArray())
|
||||
assertEquals(2, backend.getAvailableBackupFileHandles().toList().size)
|
||||
assertEquals(2, storagePlugin.getAvailableBackups()?.toList()?.size)
|
||||
|
||||
// ensure that the new backup dir exist
|
||||
assertTrue(storage.currentSetDir!!.exists())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMetadataWriteRead() = runBlocking(Dispatchers.IO) {
|
||||
every { mockedSettingsManager.token } returns token
|
||||
every { mockedSettingsManager.getToken() } returns token
|
||||
|
||||
storagePlugin.startNewRestoreSet(token)
|
||||
storagePlugin.initializeDevice()
|
||||
|
||||
// write metadata
|
||||
val metadata = getRandomByteArray()
|
||||
backend.save(LegacyAppBackupFile.Metadata(token)).writeAndClose(metadata)
|
||||
storagePlugin.getOutputStream(token, FILE_BACKUP_METADATA).writeAndClose(metadata)
|
||||
|
||||
// get available backups, expect only one with our token and no error
|
||||
var availableBackups = backend.getAvailableBackupFileHandles().toList()
|
||||
var availableBackups = storagePlugin.getAvailableBackups()?.toList()
|
||||
check(availableBackups != null)
|
||||
assertEquals(1, availableBackups.size)
|
||||
var backupHandle = availableBackups[0] as LegacyAppBackupFile.Metadata
|
||||
assertEquals(token, backupHandle.token)
|
||||
assertEquals(token, availableBackups[0].token)
|
||||
|
||||
// read metadata matches what was written earlier
|
||||
assertReadEquals(metadata, backend.load(backupHandle))
|
||||
assertReadEquals(metadata, availableBackups[0].inputStreamRetriever())
|
||||
|
||||
// initializing again (without changing storage) keeps restore set with same token
|
||||
backend.save(LegacyAppBackupFile.Metadata(token)).writeAndClose(metadata)
|
||||
availableBackups = backend.getAvailableBackupFileHandles().toList()
|
||||
storagePlugin.initializeDevice()
|
||||
storagePlugin.getOutputStream(token, FILE_BACKUP_METADATA).writeAndClose(metadata)
|
||||
availableBackups = storagePlugin.getAvailableBackups()?.toList()
|
||||
check(availableBackups != null)
|
||||
assertEquals(1, availableBackups.size)
|
||||
backupHandle = availableBackups[0] as LegacyAppBackupFile.Metadata
|
||||
assertEquals(token, backupHandle.token)
|
||||
assertEquals(token, availableBackups[0].token)
|
||||
|
||||
// metadata hasn't changed
|
||||
assertReadEquals(metadata, backend.load(backupHandle))
|
||||
assertReadEquals(metadata, availableBackups[0].inputStreamRetriever())
|
||||
}
|
||||
|
||||
@Test
|
||||
@Suppress("Deprecation")
|
||||
fun v0testApkWriteRead() = runBlocking {
|
||||
// initialize storage with given token
|
||||
initStorage(token)
|
||||
|
||||
// write random bytes as APK
|
||||
val apk1 = getRandomByteArray(1337 * 1024)
|
||||
backend.save(LegacyAppBackupFile.Blob(token, "${packageInfo.packageName}.apk"))
|
||||
.writeAndClose(apk1)
|
||||
storagePlugin.getOutputStream(token, "${packageInfo.packageName}.apk").writeAndClose(apk1)
|
||||
|
||||
// assert that read APK bytes match what was written
|
||||
assertReadEquals(
|
||||
|
@ -162,7 +164,7 @@ class PluginTest : KoinComponent {
|
|||
val suffix2 = getRandomBase64(23)
|
||||
val apk2 = getRandomByteArray(23 * 1024 * 1024)
|
||||
|
||||
backend.save(LegacyAppBackupFile.Blob(token, "${packageInfo2.packageName}$suffix2.apk"))
|
||||
storagePlugin.getOutputStream(token, "${packageInfo2.packageName}$suffix2.apk")
|
||||
.writeAndClose(apk2)
|
||||
|
||||
// assert that read APK bytes match what was written
|
||||
|
@ -180,27 +182,42 @@ class PluginTest : KoinComponent {
|
|||
val name1 = getRandomBase64()
|
||||
val name2 = getRandomBase64()
|
||||
|
||||
// no data available initially
|
||||
assertFalse(storagePlugin.hasData(token, name1))
|
||||
assertFalse(storagePlugin.hasData(token, name2))
|
||||
|
||||
// write full backup data
|
||||
val data = getRandomByteArray(5 * 1024 * 1024)
|
||||
backend.save(LegacyAppBackupFile.Blob(token, name1)).writeAndClose(data)
|
||||
storagePlugin.getOutputStream(token, name1).writeAndClose(data)
|
||||
|
||||
// data is available now, but only this token
|
||||
assertTrue(storagePlugin.hasData(token, name1))
|
||||
assertFalse(storagePlugin.hasData(token + 1, name1))
|
||||
|
||||
// restore data matches backed up data
|
||||
assertReadEquals(data, backend.load(LegacyAppBackupFile.Blob(token, name1)))
|
||||
assertReadEquals(data, storagePlugin.getInputStream(token, name1))
|
||||
|
||||
// write and check data for second package
|
||||
val data2 = getRandomByteArray(5 * 1024 * 1024)
|
||||
backend.save(LegacyAppBackupFile.Blob(token, name2)).writeAndClose(data2)
|
||||
assertReadEquals(data2, backend.load(LegacyAppBackupFile.Blob(token, name2)))
|
||||
storagePlugin.getOutputStream(token, name2).writeAndClose(data2)
|
||||
assertTrue(storagePlugin.hasData(token, name2))
|
||||
assertReadEquals(data2, storagePlugin.getInputStream(token, name2))
|
||||
|
||||
// remove data of first package again and ensure that no more data is found
|
||||
backend.remove(LegacyAppBackupFile.Blob(token, name1))
|
||||
storagePlugin.removeData(token, name1)
|
||||
assertFalse(storagePlugin.hasData(token, name1))
|
||||
|
||||
// second package is still there
|
||||
assertTrue(storagePlugin.hasData(token, name2))
|
||||
|
||||
// ensure that it gets deleted as well
|
||||
backend.remove(LegacyAppBackupFile.Blob(token, name2))
|
||||
storagePlugin.removeData(token, name2)
|
||||
assertFalse(storagePlugin.hasData(token, name2))
|
||||
}
|
||||
|
||||
private fun initStorage(token: Long) = runBlocking {
|
||||
every { mockedSettingsManager.token } returns token
|
||||
every { mockedSettingsManager.getToken() } returns token
|
||||
storagePlugin.initializeDevice()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.backend.saf
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.filters.MediumTest
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.stevesoltys.seedvault.settings.SettingsManager
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.calyxos.seedvault.core.backends.Backend
|
||||
import org.calyxos.seedvault.core.backends.BackendTest
|
||||
import org.calyxos.seedvault.core.backends.saf.SafBackend
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@MediumTest
|
||||
class SafBackendTest : BackendTest(), KoinComponent {
|
||||
|
||||
private val context = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
private val settingsManager by inject<SettingsManager>()
|
||||
private val safProperties = settingsManager.getSafProperties() ?: error("No SAF storage")
|
||||
override val backend: Backend = SafBackend(context, safProperties, ".SeedvaultTest")
|
||||
|
||||
@Test
|
||||
fun `test write list read rename delete`(): Unit = runBlocking {
|
||||
testWriteListReadRenameDelete()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test remove create write file`(): Unit = runBlocking {
|
||||
testRemoveCreateWriteFile()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test free space and create app blob without root folder`(): Unit = runBlocking {
|
||||
testTestFreeSpaceAndCreateBlob()
|
||||
}
|
||||
}
|
|
@ -1,14 +1,9 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2023 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.e2e
|
||||
|
||||
import android.content.pm.PackageInfo
|
||||
import android.os.ParcelFileDescriptor
|
||||
import androidx.test.uiautomator.Until
|
||||
import com.stevesoltys.seedvault.e2e.io.BackupDataInputIntercept
|
||||
import com.stevesoltys.seedvault.e2e.io.InputStreamIntercept
|
||||
import com.stevesoltys.seedvault.e2e.screen.impl.BackupScreen
|
||||
import com.stevesoltys.seedvault.transport.backup.FullBackup
|
||||
import com.stevesoltys.seedvault.transport.backup.InputFactory
|
||||
|
@ -20,12 +15,9 @@ import io.mockk.every
|
|||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withTimeout
|
||||
import org.calyxos.seedvault.core.toHexString
|
||||
import org.koin.core.component.get
|
||||
import java.security.DigestInputStream
|
||||
import java.security.MessageDigest
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import kotlin.test.fail
|
||||
|
||||
internal interface LargeBackupTestBase : LargeTestBase {
|
||||
|
||||
|
@ -48,17 +40,6 @@ internal interface LargeBackupTestBase : LargeTestBase {
|
|||
|
||||
fun startBackup() {
|
||||
BackupScreen {
|
||||
|
||||
if (!backupManager.isBackupEnabled) {
|
||||
backupSwitch.click()
|
||||
waitUntilIdle()
|
||||
|
||||
BackupScreen {
|
||||
device.wait(Until.hasObject(initializingText), 10000)
|
||||
device.wait(Until.gone(initializingText), 120000)
|
||||
}
|
||||
}
|
||||
|
||||
backupMenu.clickAndWaitForNewWindow()
|
||||
waitUntilIdle()
|
||||
|
||||
|
@ -76,6 +57,7 @@ internal interface LargeBackupTestBase : LargeTestBase {
|
|||
full = mutableMapOf(),
|
||||
kv = mutableMapOf(),
|
||||
userApps = packageService.userApps,
|
||||
userNotAllowedApps = packageService.userNotAllowedApps
|
||||
)
|
||||
|
||||
val completed = spyOnBackup(backupResult)
|
||||
|
@ -112,7 +94,7 @@ internal interface LargeBackupTestBase : LargeTestBase {
|
|||
var data = mutableMapOf<String, ByteArray>()
|
||||
|
||||
coEvery {
|
||||
spyKVBackup.performBackup(any(), any(), any())
|
||||
spyKVBackup.performBackup(any(), any(), any(), any(), any())
|
||||
} answers {
|
||||
packageName = firstArg<PackageInfo>().packageName
|
||||
callOriginal()
|
||||
|
@ -131,21 +113,9 @@ internal interface LargeBackupTestBase : LargeTestBase {
|
|||
coEvery {
|
||||
spyKVBackup.finishBackup()
|
||||
} answers {
|
||||
val oldMap = HashMap<String, String>()
|
||||
// @pm@ and android can get backed up multiple times (if we need more than one request)
|
||||
// so we need to keep the data it backed up before
|
||||
if (backupResult.kv.containsKey(packageName)) {
|
||||
backupResult.kv[packageName]?.forEach { (key, value) ->
|
||||
// if a key existing in new data, we use its value from new data, don't override
|
||||
if (!data.containsKey(key)) oldMap[key] = value
|
||||
}
|
||||
}
|
||||
backupResult.kv[packageName!!] = data
|
||||
.mapValues { entry -> entry.value.sha256() }
|
||||
.toMutableMap()
|
||||
.apply {
|
||||
putAll(oldMap)
|
||||
}
|
||||
|
||||
packageName = null
|
||||
data = mutableMapOf()
|
||||
|
@ -155,11 +125,10 @@ internal interface LargeBackupTestBase : LargeTestBase {
|
|||
|
||||
private fun spyOnFullBackupData(backupResult: SeedvaultLargeTestResult) {
|
||||
var packageName: String? = null
|
||||
val messageDigest = MessageDigest.getInstance("SHA-256")
|
||||
var digestInputStream: DigestInputStream? = null
|
||||
var dataIntercept = ByteArrayOutputStream()
|
||||
|
||||
coEvery {
|
||||
spyFullBackup.performFullBackup(any(), any(), any())
|
||||
spyFullBackup.performFullBackup(any(), any(), any(), any(), any())
|
||||
} answers {
|
||||
packageName = firstArg<PackageInfo>().packageName
|
||||
callOriginal()
|
||||
|
@ -168,19 +137,20 @@ internal interface LargeBackupTestBase : LargeTestBase {
|
|||
every {
|
||||
spyInputFactory.getInputStream(any())
|
||||
} answers {
|
||||
digestInputStream = DigestInputStream(callOriginal(), messageDigest)
|
||||
digestInputStream!!
|
||||
InputStreamIntercept(
|
||||
inputStream = callOriginal(),
|
||||
intercept = dataIntercept
|
||||
)
|
||||
}
|
||||
|
||||
coEvery {
|
||||
every {
|
||||
spyFullBackup.finishBackup()
|
||||
} answers {
|
||||
val result = callOriginal()
|
||||
val digest = digestInputStream?.messageDigest ?: fail("No digestInputStream")
|
||||
backupResult.full[packageName!!] = digest.digest().toHexString()
|
||||
backupResult.full[packageName!!] = dataIntercept.toByteArray().sha256()
|
||||
|
||||
packageName = null
|
||||
digest.reset()
|
||||
dataIntercept = ByteArrayOutputStream()
|
||||
result
|
||||
}
|
||||
}
|
||||
|
@ -191,18 +161,14 @@ internal interface LargeBackupTestBase : LargeTestBase {
|
|||
clearMocks(spyBackupNotificationManager)
|
||||
|
||||
every {
|
||||
spyBackupNotificationManager.onBackupSuccess(any(), any(), any())
|
||||
spyBackupNotificationManager.onBackupFinished(any(), any())
|
||||
} answers {
|
||||
val success = firstArg<Boolean>()
|
||||
assert(success) { "Backup failed." }
|
||||
|
||||
callOriginal()
|
||||
completed.set(true)
|
||||
}
|
||||
every {
|
||||
spyBackupNotificationManager.onBackupError()
|
||||
} answers {
|
||||
callOriginal()
|
||||
completed.set(true)
|
||||
fail("Backup failed.")
|
||||
}
|
||||
|
||||
return completed
|
||||
}
|
||||
|
|
|
@ -1,20 +1,14 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2023 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.e2e
|
||||
|
||||
import android.content.pm.PackageInfo
|
||||
import android.os.ParcelFileDescriptor
|
||||
import com.stevesoltys.seedvault.e2e.io.BackupDataOutputIntercept
|
||||
import com.stevesoltys.seedvault.e2e.io.OutputStreamIntercept
|
||||
import com.stevesoltys.seedvault.e2e.screen.impl.RecoveryCodeScreen
|
||||
import com.stevesoltys.seedvault.e2e.screen.impl.RestoreScreen
|
||||
import com.stevesoltys.seedvault.transport.restore.FullRestore
|
||||
import com.stevesoltys.seedvault.transport.restore.KVRestore
|
||||
import com.stevesoltys.seedvault.transport.restore.OutputFactory
|
||||
import io.mockk.Call
|
||||
import io.mockk.MockKAnswerScope
|
||||
import io.mockk.clearMocks
|
||||
import io.mockk.coEvery
|
||||
import io.mockk.every
|
||||
|
@ -23,11 +17,8 @@ import kotlinx.coroutines.delay
|
|||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlinx.coroutines.withTimeout
|
||||
import org.calyxos.seedvault.core.toHexString
|
||||
import org.koin.core.component.get
|
||||
import java.security.DigestOutputStream
|
||||
import java.security.MessageDigest
|
||||
import kotlin.test.fail
|
||||
import java.io.ByteArrayOutputStream
|
||||
|
||||
internal interface LargeRestoreTestBase : LargeTestBase {
|
||||
|
||||
|
@ -67,6 +58,7 @@ internal interface LargeRestoreTestBase : LargeTestBase {
|
|||
full = mutableMapOf(),
|
||||
kv = mutableMapOf(),
|
||||
userApps = emptyList(), // will update everything below this after restore
|
||||
userNotAllowedApps = emptyList()
|
||||
)
|
||||
|
||||
spyOnRestoreData(result)
|
||||
|
@ -75,24 +67,10 @@ internal interface LargeRestoreTestBase : LargeTestBase {
|
|||
backupListItem.clickAndWaitForNewWindow()
|
||||
waitUntilIdle()
|
||||
|
||||
waitForAppSelectionLoaded()
|
||||
// just tap next in app selection
|
||||
appsSelectedButton.clickAndWaitForNewWindow()
|
||||
|
||||
waitForInstallResult()
|
||||
|
||||
if (someAppsNotInstalledText.exists()) {
|
||||
device.pressBack()
|
||||
}
|
||||
|
||||
nextButton.clickAndWaitForNewWindow()
|
||||
|
||||
waitForRestoreDataResult()
|
||||
|
||||
if (someAppsNotRestoredText.exists()) {
|
||||
device.pressBack()
|
||||
}
|
||||
|
||||
finishButton.clickAndWaitForNewWindow()
|
||||
skipButton.clickAndWaitForNewWindow()
|
||||
waitUntilIdle()
|
||||
|
@ -100,6 +78,7 @@ internal interface LargeRestoreTestBase : LargeTestBase {
|
|||
|
||||
return result.copy(
|
||||
userApps = packageService.userApps,
|
||||
userNotAllowedApps = packageService.userNotAllowedApps
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -110,22 +89,13 @@ internal interface LargeRestoreTestBase : LargeTestBase {
|
|||
spyOnKVRestoreData(result)
|
||||
}
|
||||
|
||||
private fun waitForAppSelectionLoaded() = runBlocking {
|
||||
withContext(Dispatchers.Main) {
|
||||
withTimeout(RESTORE_TIMEOUT) {
|
||||
while (spyRestoreViewModel.selectedApps.value?.apps?.isNotEmpty() != true) {
|
||||
delay(100)
|
||||
}
|
||||
}
|
||||
}
|
||||
waitUntilIdle()
|
||||
}
|
||||
|
||||
private fun waitForInstallResult() = runBlocking {
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
withTimeout(RESTORE_TIMEOUT) {
|
||||
while (spyRestoreViewModel.installResult.value?.isFinished != true) {
|
||||
while (spyRestoreViewModel.installResult.value == null ||
|
||||
spyRestoreViewModel.nextButtonEnabled.value == false
|
||||
) {
|
||||
delay(100)
|
||||
}
|
||||
}
|
||||
|
@ -133,9 +103,7 @@ internal interface LargeRestoreTestBase : LargeTestBase {
|
|||
val restoreResultValue = spyRestoreViewModel.installResult.value
|
||||
?: error("Restore APKs timed out")
|
||||
|
||||
// TODO: Fix this, with current test an app or two breaks on install with AOSP image.
|
||||
// Just need to update the test data to work with the AOSP image.
|
||||
// assert(!restoreResultValue.hasFailed) { "Failed to install packages" }
|
||||
assert(!restoreResultValue.hasFailed) { "Failed to install packages" }
|
||||
}
|
||||
|
||||
waitUntilIdle()
|
||||
|
@ -165,26 +133,14 @@ internal interface LargeRestoreTestBase : LargeTestBase {
|
|||
|
||||
clearMocks(spyKVRestore)
|
||||
|
||||
fun initializeStateBlock(
|
||||
packageInfoIndex: Int
|
||||
): MockKAnswerScope<Unit, Unit>.(Call) -> Unit = {
|
||||
packageName = arg<PackageInfo>(packageInfoIndex).packageName
|
||||
coEvery {
|
||||
spyKVRestore.initializeState(any(), any(), any(), any(), any())
|
||||
} answers {
|
||||
packageName = arg<PackageInfo>(3).packageName
|
||||
restoreResult.kv[packageName!!] = mutableMapOf()
|
||||
callOriginal()
|
||||
}
|
||||
|
||||
coEvery {
|
||||
spyKVRestore.initializeState(any(), any(), any(), any())
|
||||
} answers initializeStateBlock(1)
|
||||
|
||||
coEvery {
|
||||
spyKVRestore.initializeStateV1(any(), any(), any(), any())
|
||||
} answers initializeStateBlock(2)
|
||||
|
||||
coEvery {
|
||||
spyKVRestore.initializeStateV0(any(), any())
|
||||
} answers initializeStateBlock(1)
|
||||
|
||||
every {
|
||||
spyOutputFactory.getBackupDataOutput(any())
|
||||
} answers {
|
||||
|
@ -198,61 +154,43 @@ internal interface LargeRestoreTestBase : LargeTestBase {
|
|||
|
||||
private fun spyOnFullRestoreData(restoreResult: SeedvaultLargeTestResult) {
|
||||
var packageName: String? = null
|
||||
val messageDigest = MessageDigest.getInstance("SHA-256")
|
||||
var digestOutputStream: DigestOutputStream? = null
|
||||
var dataIntercept = ByteArrayOutputStream()
|
||||
|
||||
clearMocks(spyFullRestore)
|
||||
|
||||
fun initializeStateBlock(
|
||||
packageInfoIndex: Int
|
||||
): MockKAnswerScope<Unit, Unit>.(Call) -> Unit = {
|
||||
packageName?.let {
|
||||
// sometimes finishRestore() doesn't get called, so get data from last package here
|
||||
digestOutputStream?.messageDigest?.let { digest ->
|
||||
restoreResult.full[packageName!!] = digest.digest().toHexString()
|
||||
}
|
||||
}
|
||||
|
||||
packageName = arg<PackageInfo>(packageInfoIndex).packageName
|
||||
coEvery {
|
||||
spyFullRestore.initializeState(any(), any(), any(), any())
|
||||
} answers {
|
||||
packageName = arg<PackageInfo>(3).packageName
|
||||
dataIntercept = ByteArrayOutputStream()
|
||||
|
||||
callOriginal()
|
||||
}
|
||||
|
||||
coEvery {
|
||||
spyFullRestore.initializeState(any(), any(), any())
|
||||
} answers initializeStateBlock(1)
|
||||
|
||||
coEvery {
|
||||
spyFullRestore.initializeStateV1(any(), any(), any())
|
||||
} answers initializeStateBlock(2)
|
||||
|
||||
coEvery {
|
||||
spyFullRestore.initializeStateV0(any(), any())
|
||||
} answers initializeStateBlock(1)
|
||||
|
||||
every {
|
||||
spyOutputFactory.getOutputStream(any())
|
||||
} answers {
|
||||
digestOutputStream = DigestOutputStream(callOriginal(), messageDigest)
|
||||
digestOutputStream!!
|
||||
OutputStreamIntercept(
|
||||
outputStream = callOriginal(),
|
||||
intercept = dataIntercept
|
||||
)
|
||||
}
|
||||
|
||||
every {
|
||||
spyFullRestore.abortFullRestore()
|
||||
} answers {
|
||||
packageName = null
|
||||
digestOutputStream?.messageDigest?.reset()
|
||||
dataIntercept = ByteArrayOutputStream()
|
||||
callOriginal()
|
||||
}
|
||||
|
||||
every {
|
||||
spyFullRestore.finishRestore()
|
||||
} answers {
|
||||
val digest = digestOutputStream?.messageDigest ?: fail("No digestOutputStream")
|
||||
restoreResult.full[packageName!!] = digest.digest().toHexString()
|
||||
restoreResult.full[packageName!!] = dataIntercept.toByteArray().sha256()
|
||||
|
||||
packageName = null
|
||||
digest.reset()
|
||||
dataIntercept = ByteArrayOutputStream()
|
||||
callOriginal()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,8 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2023 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.e2e
|
||||
|
||||
import android.app.UiAutomation
|
||||
import android.app.backup.IBackupManager
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageInfo
|
||||
import android.content.pm.PackageManager.PERMISSION_GRANTED
|
||||
import android.os.Environment
|
||||
import androidx.annotation.WorkerThread
|
||||
import androidx.preference.PreferenceManager
|
||||
|
@ -20,17 +13,16 @@ import com.stevesoltys.seedvault.crypto.ANDROID_KEY_STORE
|
|||
import com.stevesoltys.seedvault.crypto.KEY_ALIAS_BACKUP
|
||||
import com.stevesoltys.seedvault.crypto.KEY_ALIAS_MAIN
|
||||
import com.stevesoltys.seedvault.crypto.KeyManager
|
||||
import com.stevesoltys.seedvault.currentRestoreStorageViewModel
|
||||
import com.stevesoltys.seedvault.currentRestoreViewModel
|
||||
import com.stevesoltys.seedvault.e2e.screen.impl.BackupScreen
|
||||
import com.stevesoltys.seedvault.e2e.screen.impl.DocumentPickerScreen
|
||||
import com.stevesoltys.seedvault.e2e.screen.impl.RecoveryCodeScreen
|
||||
import com.stevesoltys.seedvault.metadata.MetadataManager
|
||||
import com.stevesoltys.seedvault.permitDiskReads
|
||||
import com.stevesoltys.seedvault.plugins.saf.DocumentsStorage
|
||||
import com.stevesoltys.seedvault.restore.RestoreViewModel
|
||||
import com.stevesoltys.seedvault.settings.SettingsManager
|
||||
import com.stevesoltys.seedvault.transport.backup.PackageService
|
||||
import com.stevesoltys.seedvault.ui.storage.RestoreStorageViewModel
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
|
@ -49,14 +41,14 @@ internal interface LargeTestBase : KoinComponent {
|
|||
|
||||
companion object {
|
||||
private const val TEST_STORAGE_FOLDER = "seedvault_test"
|
||||
private const val TEST_RESULT_FOLDER = "seedvault_test_results"
|
||||
private const val TEST_VIDEO_FOLDER = "seedvault_test_videos"
|
||||
}
|
||||
|
||||
val externalStorageDir: String get() = Environment.getExternalStorageDirectory().absolutePath
|
||||
|
||||
val testStoragePath get() = "$externalStorageDir/$TEST_STORAGE_FOLDER"
|
||||
|
||||
val testResultPath get() = "$externalStorageDir/$TEST_RESULT_FOLDER"
|
||||
val testVideoPath get() = "$externalStorageDir/$TEST_VIDEO_FOLDER"
|
||||
|
||||
val targetContext: Context
|
||||
get() = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
|
@ -73,18 +65,16 @@ internal interface LargeTestBase : KoinComponent {
|
|||
|
||||
val keyManager: KeyManager get() = get()
|
||||
|
||||
val spyMetadataManager: MetadataManager get() = get()
|
||||
val documentsStorage: DocumentsStorage get() = get()
|
||||
|
||||
val backupManager: IBackupManager get() = get()
|
||||
val spyMetadataManager: MetadataManager get() = get()
|
||||
|
||||
val spyRestoreViewModel: RestoreViewModel
|
||||
get() = currentRestoreViewModel ?: error("currentRestoreViewModel is null")
|
||||
|
||||
val spyRestoreStorageViewModel: RestoreStorageViewModel
|
||||
get() = currentRestoreStorageViewModel ?: error("currentRestoreStorageViewModel is null")
|
||||
|
||||
fun resetApplicationState() {
|
||||
backupManager.setAutoRestore(false)
|
||||
settingsManager.setNewToken(null)
|
||||
documentsStorage.reset(null)
|
||||
|
||||
val sharedPreferences = permitDiskReads {
|
||||
PreferenceManager.getDefaultSharedPreferences(targetContext)
|
||||
|
@ -99,7 +89,6 @@ internal interface LargeTestBase : KoinComponent {
|
|||
}
|
||||
|
||||
clearDocumentPickerAppData()
|
||||
device.executeShellCommand("rm -R $externalStorageDir/.SeedVaultAndroidBackup")
|
||||
}
|
||||
|
||||
fun waitUntilIdle() {
|
||||
|
@ -111,22 +100,18 @@ internal interface LargeTestBase : KoinComponent {
|
|||
uiAutomation.executeShellCommand(command).close()
|
||||
}
|
||||
|
||||
fun testResultFilename(testName: String): String {
|
||||
val simpleDateFormat = SimpleDateFormat("yyyyMMdd_hhmmss")
|
||||
val timeStamp = simpleDateFormat.format(Calendar.getInstance().time)
|
||||
return "${timeStamp}_${testName.replace(" ", "_")}"
|
||||
}
|
||||
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
@WorkerThread
|
||||
suspend fun startRecordingTest(
|
||||
suspend fun startScreenRecord(
|
||||
keepRecordingScreen: AtomicBoolean,
|
||||
testName: String,
|
||||
) {
|
||||
val folder = testResultPath
|
||||
runCommand("mkdir -p $folder")
|
||||
val simpleDateFormat = SimpleDateFormat("yyyyMMdd_hhmmss")
|
||||
val timeStamp = simpleDateFormat.format(Calendar.getInstance().time)
|
||||
val fileName = "${timeStamp}_${testName.replace(" ", "_")}"
|
||||
|
||||
val fileName = testResultFilename(testName)
|
||||
val folder = testVideoPath
|
||||
runCommand("mkdir -p $folder")
|
||||
|
||||
// screen record automatically stops after 3 minutes
|
||||
// we need to block on a loop and split it into multiple files
|
||||
|
@ -140,16 +125,10 @@ internal interface LargeTestBase : KoinComponent {
|
|||
}
|
||||
|
||||
@WorkerThread
|
||||
fun stopRecordingTest(
|
||||
keepRecordingScreen: AtomicBoolean,
|
||||
testName: String,
|
||||
) {
|
||||
fun stopScreenRecord(keepRecordingScreen: AtomicBoolean) {
|
||||
keepRecordingScreen.set(false)
|
||||
runCommand("pkill -2 screenrecord")
|
||||
|
||||
// write logcat to file
|
||||
val fileName = testResultFilename(testName)
|
||||
runCommand("logcat -d -f $testResultPath/$fileName.log")
|
||||
runCommand("pkill -2 screenrecord")
|
||||
}
|
||||
|
||||
fun uninstallPackages(packages: Collection<PackageInfo>) {
|
||||
|
@ -162,7 +141,6 @@ internal interface LargeTestBase : KoinComponent {
|
|||
|
||||
fun clearTestBackups() {
|
||||
File(testStoragePath).deleteRecursively()
|
||||
File(testResultPath).deleteRecursively()
|
||||
}
|
||||
|
||||
fun changeBackupLocation(
|
||||
|
@ -181,40 +159,18 @@ internal interface LargeTestBase : KoinComponent {
|
|||
folderName: String = TEST_STORAGE_FOLDER,
|
||||
exists: Boolean = false,
|
||||
) {
|
||||
val manageDocumentsPermission =
|
||||
targetContext.checkSelfPermission("android.permission.MANAGE_DOCUMENTS")
|
||||
DocumentPickerScreen {
|
||||
if (exists) {
|
||||
existingFolder(folderName).scrollTo().clickAndWaitForNewWindow()
|
||||
|
||||
if (manageDocumentsPermission != PERMISSION_GRANTED) {
|
||||
DocumentPickerScreen {
|
||||
if (exists) {
|
||||
existingFolder(folderName).scrollTo().clickAndWaitForNewWindow()
|
||||
|
||||
} else {
|
||||
createNewFolderButton.clickAndWaitForNewWindow()
|
||||
textBox.text = folderName
|
||||
okButton.clickAndWaitForNewWindow()
|
||||
}
|
||||
|
||||
useThisFolderButton.clickAndWaitForNewWindow()
|
||||
allowButton.clickAndWaitForNewWindow()
|
||||
} else {
|
||||
createNewFolderButton.clickAndWaitForNewWindow()
|
||||
textBox.text = folderName
|
||||
okButton.clickAndWaitForNewWindow()
|
||||
}
|
||||
} else {
|
||||
val extDir = externalStorageDir
|
||||
|
||||
device.executeShellCommand("rm -R $extDir/.SeedVaultAndroidBackup")
|
||||
device.executeShellCommand(
|
||||
"cp -R $extDir/$folderName/" +
|
||||
".SeedVaultAndroidBackup $extDir"
|
||||
)
|
||||
device.executeShellCommand("cp -R $extDir/$folderName/recovery-code.txt $extDir")
|
||||
|
||||
BackupScreen {
|
||||
internalStorageButton.clickAndWaitForNewWindow()
|
||||
|
||||
if (useAnywayButton.waitForExists(3000)) {
|
||||
useAnywayButton.clickAndWaitForNewWindow()
|
||||
}
|
||||
}
|
||||
useThisFolderButton.clickAndWaitForNewWindow()
|
||||
allowButton.clickAndWaitForNewWindow()
|
||||
}
|
||||
|
||||
BackupScreen {
|
||||
|
@ -225,7 +181,6 @@ internal interface LargeTestBase : KoinComponent {
|
|||
|
||||
fun confirmCode() {
|
||||
RecoveryCodeScreen {
|
||||
startNewBackupButton.click()
|
||||
confirmCodeButton.click()
|
||||
|
||||
verifyCodeButton.scrollTo().click()
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2023 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.e2e
|
||||
|
||||
import android.content.pm.PackageManager
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.After
|
||||
|
@ -15,7 +9,6 @@ import org.junit.rules.TestName
|
|||
import org.junit.runner.RunWith
|
||||
import org.koin.core.component.KoinComponent
|
||||
import java.io.File
|
||||
import java.lang.Thread.sleep
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
|
@ -44,17 +37,13 @@ internal abstract class SeedvaultLargeTest :
|
|||
resetApplicationState()
|
||||
clearTestBackups()
|
||||
|
||||
runCommand("bmgr enable true")
|
||||
runCommand("bmgr transport com.stevesoltys.seedvault.transport.ConfigurableBackupTransport")
|
||||
sleep(5000)
|
||||
|
||||
startRecordingTest(keepRecordingScreen, name.methodName)
|
||||
startScreenRecord(keepRecordingScreen, name.methodName)
|
||||
restoreBaselineBackup()
|
||||
}
|
||||
|
||||
@After
|
||||
open fun tearDown() {
|
||||
stopRecordingTest(keepRecordingScreen, name.methodName)
|
||||
stopScreenRecord(keepRecordingScreen)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -66,23 +55,6 @@ internal abstract class SeedvaultLargeTest :
|
|||
private fun restoreBaselineBackup() {
|
||||
val backupFile = File(baselineBackupPath)
|
||||
|
||||
val manageDocumentsPermission =
|
||||
targetContext.checkSelfPermission("android.permission.MANAGE_DOCUMENTS")
|
||||
|
||||
if (manageDocumentsPermission == PackageManager.PERMISSION_GRANTED) {
|
||||
val extDir = externalStorageDir
|
||||
|
||||
device.executeShellCommand("rm -R $extDir/.SeedVaultAndroidBackup")
|
||||
device.executeShellCommand(
|
||||
"cp -R $extDir/$BASELINE_BACKUP_FOLDER/" +
|
||||
".SeedVaultAndroidBackup $extDir"
|
||||
)
|
||||
device.executeShellCommand(
|
||||
"cp -R $extDir/$BASELINE_BACKUP_FOLDER/" +
|
||||
"recovery-code.txt $extDir"
|
||||
)
|
||||
}
|
||||
|
||||
if (backupFile.exists()) {
|
||||
launchRestoreActivity()
|
||||
chooseStorageLocation(folderName = BASELINE_BACKUP_FOLDER, exists = true)
|
||||
|
|
|
@ -1,13 +1,7 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2023 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.e2e
|
||||
|
||||
import android.content.pm.PackageInfo
|
||||
import com.stevesoltys.seedvault.metadata.PackageMetadata
|
||||
import com.stevesoltys.seedvault.restore.AppRestoreResult
|
||||
|
||||
/**
|
||||
* Contains maps of (package name -> SHA-256 hashes) of application data.
|
||||
|
@ -18,12 +12,12 @@ import com.stevesoltys.seedvault.restore.AppRestoreResult
|
|||
* For full backups, the mapping is: Map<PackageName, SHA-256>
|
||||
* For K/V backups, the mapping is: Map<PackageName, Map<Key, SHA-256>>
|
||||
*/
|
||||
internal data class SeedvaultLargeTestResult(
|
||||
data class SeedvaultLargeTestResult(
|
||||
val backupResults: Map<String, PackageMetadata?> = emptyMap(),
|
||||
val restoreResults: Map<String, AppRestoreResult?> = emptyMap(),
|
||||
val full: MutableMap<String, String>,
|
||||
val kv: MutableMap<String, MutableMap<String, String>>,
|
||||
val userApps: List<PackageInfo>,
|
||||
val userNotAllowedApps: List<PackageInfo>,
|
||||
) {
|
||||
fun allUserApps() = userApps
|
||||
fun allUserApps() = userApps + userNotAllowedApps
|
||||
}
|
||||
|
|
|
@ -1,18 +1,9 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2023 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.e2e.impl
|
||||
|
||||
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
import android.util.Log
|
||||
import androidx.test.filters.LargeTest
|
||||
import com.stevesoltys.seedvault.MAGIC_PACKAGE_MANAGER
|
||||
import com.stevesoltys.seedvault.e2e.SeedvaultLargeTest
|
||||
import com.stevesoltys.seedvault.e2e.SeedvaultLargeTestResult
|
||||
import com.stevesoltys.seedvault.metadata.PackageState
|
||||
import com.stevesoltys.seedvault.transport.backup.isStopped
|
||||
import org.junit.Test
|
||||
|
||||
@LargeTest
|
||||
|
@ -26,15 +17,12 @@ internal class BackupRestoreTest : SeedvaultLargeTest() {
|
|||
confirmCode()
|
||||
}
|
||||
|
||||
if (settingsManager.getSafProperties() == null) {
|
||||
if (settingsManager.getStorage() == null) {
|
||||
chooseStorageLocation()
|
||||
} else {
|
||||
changeBackupLocation()
|
||||
}
|
||||
|
||||
launchStoppedApps()
|
||||
launchBackupActivity()
|
||||
|
||||
val backupResult = performBackup()
|
||||
assertValidBackupMetadata(backupResult)
|
||||
|
||||
|
@ -64,28 +52,6 @@ internal class BackupRestoreTest : SeedvaultLargeTest() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun launchStoppedApps() {
|
||||
val packageManager = targetContext.packageManager
|
||||
val notBackedUp = packageService.notBackedUpPackages
|
||||
notBackedUp.forEach { packageInfo ->
|
||||
val i = packageManager.getLaunchIntentForPackage(packageInfo.packageName)?.apply {
|
||||
addFlags(FLAG_ACTIVITY_NEW_TASK)
|
||||
}
|
||||
Log.i("TEST", "Launching $i")
|
||||
try {
|
||||
targetContext.startActivity(i)
|
||||
} catch (e: Exception) {
|
||||
Log.e("TEST", "Could not launch activity for ${packageInfo.packageName}", e)
|
||||
}
|
||||
waitUntilIdle()
|
||||
}
|
||||
waitUntilIdle()
|
||||
notBackedUp.forEach { packageInfo ->
|
||||
val pi = packageManager.getPackageInfo(packageInfo.packageName, 0)
|
||||
Log.e("TEST", "${packageInfo.packageName} isStopped: ${pi.isStopped()}")
|
||||
}
|
||||
}
|
||||
|
||||
private fun assertValidResults(
|
||||
backup: SeedvaultLargeTestResult,
|
||||
restore: SeedvaultLargeTestResult,
|
||||
|
@ -156,19 +122,17 @@ internal class BackupRestoreTest : SeedvaultLargeTest() {
|
|||
) {
|
||||
// Assert all "key/value" restored data matches the backup data.
|
||||
restore.kv.forEach { (pkg, kvData) ->
|
||||
if (pkg != MAGIC_PACKAGE_MANAGER) {
|
||||
assert(backup.kv.containsKey(pkg)) {
|
||||
"KV data for $pkg missing from backup."
|
||||
assert(backup.kv.containsKey(pkg)) {
|
||||
"KV data for $pkg missing from backup."
|
||||
}
|
||||
|
||||
kvData.forEach { (key, value) ->
|
||||
assert(backup.kv[pkg]!!.containsKey(key)) {
|
||||
"KV data for $pkg/$key exists in restore but is missing from backup."
|
||||
}
|
||||
|
||||
kvData.forEach { (key, value) ->
|
||||
assert(backup.kv[pkg]!!.containsKey(key)) {
|
||||
"KV data for $pkg/$key exists in restore but is missing from backup."
|
||||
}
|
||||
|
||||
assert(value.contentEquals(backup.kv[pkg]!![key]!!)) {
|
||||
"KV data for $pkg/$key does not match."
|
||||
}
|
||||
assert(value.contentEquals(backup.kv[pkg]!![key]!!)) {
|
||||
"KV data for $pkg/$key does not match."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2023 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.e2e.io
|
||||
|
||||
import android.app.backup.BackupDataInput
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2023 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.e2e.io
|
||||
|
||||
import android.app.backup.BackupDataOutput
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package com.stevesoltys.seedvault.e2e.io
|
||||
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.InputStream
|
||||
|
||||
class InputStreamIntercept(
|
||||
private val inputStream: InputStream,
|
||||
private val intercept: ByteArrayOutputStream
|
||||
) : InputStream() {
|
||||
|
||||
override fun read(): Int {
|
||||
val byte = inputStream.read()
|
||||
if (byte != -1) {
|
||||
intercept.write(byte)
|
||||
}
|
||||
return byte
|
||||
}
|
||||
|
||||
override fun read(buffer: ByteArray, offset: Int, length: Int): Int {
|
||||
val bytesRead = inputStream.read(buffer, offset, length)
|
||||
if (bytesRead != -1) {
|
||||
intercept.write(buffer, offset, bytesRead)
|
||||
}
|
||||
return bytesRead
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.stevesoltys.seedvault.e2e.io
|
||||
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.OutputStream
|
||||
|
||||
class OutputStreamIntercept(
|
||||
private val outputStream: OutputStream,
|
||||
private val intercept: ByteArrayOutputStream
|
||||
) : OutputStream() {
|
||||
|
||||
override fun write(byte: Int) {
|
||||
intercept.write(byte)
|
||||
outputStream.write(byte)
|
||||
}
|
||||
|
||||
override fun write(buffer: ByteArray, offset: Int, length: Int) {
|
||||
intercept.write(buffer, offset, length)
|
||||
outputStream.write(buffer, offset, length)
|
||||
}
|
||||
}
|
|
@ -1,13 +1,7 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2023 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.e2e.screen
|
||||
|
||||
import android.widget.ScrollView
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.uiautomator.Configurator
|
||||
import androidx.test.uiautomator.UiDevice
|
||||
import androidx.test.uiautomator.UiObject
|
||||
import androidx.test.uiautomator.UiScrollable
|
||||
|
@ -16,10 +10,6 @@ import java.lang.Thread.sleep
|
|||
|
||||
abstract class UiDeviceScreen<T> {
|
||||
|
||||
companion object {
|
||||
private const val SELECTOR_TIMEOUT = 180000L
|
||||
}
|
||||
|
||||
operator fun invoke(function: T.() -> Unit) {
|
||||
function.invoke(this as T)
|
||||
}
|
||||
|
@ -27,11 +17,8 @@ abstract class UiDeviceScreen<T> {
|
|||
fun UiObject.scrollTo(
|
||||
scrollSelector: UiSelector = UiSelector().className(ScrollView::class.java),
|
||||
): UiObject {
|
||||
val uiScrollable = UiScrollable(scrollSelector)
|
||||
uiScrollable.waitForExists(SELECTOR_TIMEOUT)
|
||||
uiScrollable.scrollIntoView(this)
|
||||
waitForExists(SELECTOR_TIMEOUT)
|
||||
|
||||
UiScrollable(scrollSelector).scrollIntoView(this)
|
||||
waitForExists(15000)
|
||||
sleep(2000)
|
||||
return this
|
||||
}
|
||||
|
@ -43,7 +30,4 @@ abstract class UiDeviceScreen<T> {
|
|||
)
|
||||
|
||||
private fun device() = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
||||
.also {
|
||||
Configurator.getInstance().waitForSelectorTimeout = SELECTOR_TIMEOUT
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2023 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.e2e.screen.impl
|
||||
|
||||
import android.os.Build
|
||||
import androidx.test.uiautomator.By
|
||||
import androidx.test.uiautomator.BySelector
|
||||
import com.stevesoltys.seedvault.e2e.screen.UiDeviceScreen
|
||||
|
@ -20,11 +14,5 @@ object BackupScreen : UiDeviceScreen<BackupScreen>() {
|
|||
|
||||
val backupLocationButton = findObject { text("Backup location") }
|
||||
|
||||
val backupSwitch = findObject { text("Backup my apps") }
|
||||
|
||||
val internalStorageButton = findObject { textContains(Build.MODEL) }
|
||||
|
||||
val useAnywayButton = findObject { text("Use anyway") }
|
||||
|
||||
val initializingText: BySelector = By.textContains("Initializing backup location")
|
||||
}
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2023 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.e2e.screen.impl
|
||||
|
||||
import android.widget.EditText
|
||||
|
|
|
@ -1,16 +1,9 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2023 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.e2e.screen.impl
|
||||
|
||||
import com.stevesoltys.seedvault.e2e.screen.UiDeviceScreen
|
||||
|
||||
object RecoveryCodeScreen : UiDeviceScreen<RecoveryCodeScreen>() {
|
||||
|
||||
val startNewBackupButton = findObject { text("Start new") }
|
||||
|
||||
val confirmCodeButton = findObject { text("Confirm code") }
|
||||
|
||||
val verifyCodeButton = findObject { text("Verify") }
|
||||
|
|
|
@ -1,27 +1,14 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2023 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.e2e.screen.impl
|
||||
|
||||
import com.stevesoltys.seedvault.e2e.screen.UiDeviceScreen
|
||||
|
||||
object RestoreScreen : UiDeviceScreen<RestoreScreen>() {
|
||||
|
||||
val backupListItem = findObject {
|
||||
textContains("Android SDK") // device name of test backups
|
||||
}
|
||||
|
||||
val appsSelectedButton = findObject { text("Restore backup") }
|
||||
val backupListItem = findObject { textContains("Last backup") }
|
||||
|
||||
val nextButton = findObject { text("Next") }
|
||||
|
||||
val finishButton = findObject { text("Finish") }
|
||||
|
||||
val skipButton = findObject { text("Skip restoring files") }
|
||||
|
||||
val someAppsNotInstalledText = findObject { textContains("Some apps") }
|
||||
|
||||
val someAppsNotRestoredText = findObject { textContains("some apps") }
|
||||
}
|
||||
|
|
|
@ -0,0 +1,218 @@
|
|||
package com.stevesoltys.seedvault.plugins.saf
|
||||
|
||||
import android.database.ContentObserver
|
||||
import android.database.Cursor
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.provider.DocumentsContract.EXTRA_LOADING
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.filters.MediumTest
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.stevesoltys.seedvault.assertReadEquals
|
||||
import com.stevesoltys.seedvault.coAssertThrows
|
||||
import com.stevesoltys.seedvault.getRandomBase64
|
||||
import com.stevesoltys.seedvault.getRandomByteArray
|
||||
import com.stevesoltys.seedvault.settings.SettingsManager
|
||||
import com.stevesoltys.seedvault.writeAndClose
|
||||
import io.mockk.Runs
|
||||
import io.mockk.every
|
||||
import io.mockk.just
|
||||
import io.mockk.mockk
|
||||
import io.mockk.slot
|
||||
import io.mockk.verify
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.TimeoutCancellationException
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertArrayEquals
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
import java.io.IOException
|
||||
import kotlin.random.Random
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
@MediumTest
|
||||
class DocumentsStorageTest : KoinComponent {
|
||||
|
||||
private val context = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
private val settingsManager by inject<SettingsManager>()
|
||||
private val storage = DocumentsStorage(context, settingsManager)
|
||||
|
||||
private val filename = getRandomBase64()
|
||||
private lateinit var file: DocumentFile
|
||||
|
||||
@Before
|
||||
fun setup() = runBlocking {
|
||||
assertNotNull("Select a storage location in the app first!", storage.rootBackupDir)
|
||||
file = storage.rootBackupDir?.createOrGetFile(context, filename)
|
||||
?: error("Could not create test file")
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
file.delete()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWritingAndReadingFile() {
|
||||
// write to output stream
|
||||
val outputStream = storage.getOutputStream(file)
|
||||
val content = ByteArray(1337).apply { Random.nextBytes(this) }
|
||||
outputStream.write(content)
|
||||
outputStream.flush()
|
||||
outputStream.close()
|
||||
|
||||
// read written data from input stream
|
||||
val inputStream = storage.getInputStream(file)
|
||||
val readContent = inputStream.readBytes()
|
||||
inputStream.close()
|
||||
assertArrayEquals(content, readContent)
|
||||
|
||||
// write smaller content to same file
|
||||
val outputStream2 = storage.getOutputStream(file)
|
||||
val content2 = ByteArray(42).apply { Random.nextBytes(this) }
|
||||
outputStream2.write(content2)
|
||||
outputStream2.flush()
|
||||
outputStream2.close()
|
||||
|
||||
// read written data from input stream
|
||||
val inputStream2 = storage.getInputStream(file)
|
||||
val readContent2 = inputStream2.readBytes()
|
||||
inputStream2.close()
|
||||
assertArrayEquals(content2, readContent2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testFindFile() = runBlocking(Dispatchers.IO) {
|
||||
val foundFile = storage.rootBackupDir!!.findFileBlocking(context, file.name!!)
|
||||
assertNotNull(foundFile)
|
||||
assertEquals(filename, foundFile!!.name)
|
||||
assertEquals(storage.rootBackupDir!!.uri, foundFile.parentFile?.uri)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCreateFile() {
|
||||
// create test file
|
||||
val dir = storage.rootBackupDir!!
|
||||
val createdFile = dir.createFile("text", getRandomBase64())
|
||||
assertNotNull(createdFile)
|
||||
assertNotNull(createdFile!!.name)
|
||||
|
||||
// write some data into it
|
||||
val data = getRandomByteArray()
|
||||
context.contentResolver.openOutputStream(createdFile.uri)!!.writeAndClose(data)
|
||||
|
||||
// data should still be there
|
||||
assertReadEquals(data, context.contentResolver.openInputStream(createdFile.uri))
|
||||
|
||||
// delete again
|
||||
createdFile.delete()
|
||||
assertFalse(createdFile.exists())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCreateTwoFiles() = runBlocking {
|
||||
val mimeType = "application/octet-stream"
|
||||
val dir = storage.rootBackupDir!!
|
||||
|
||||
// create test file
|
||||
val name1 = getRandomBase64(Random.nextInt(1, 10))
|
||||
val file1 = requireNotNull(dir.createFile(mimeType, name1))
|
||||
assertTrue(file1.exists())
|
||||
assertEquals(name1, file1.name)
|
||||
assertEquals(0L, file1.length())
|
||||
|
||||
assertReadEquals(getRandomByteArray(0), context.contentResolver.openInputStream(file1.uri))
|
||||
|
||||
// write some data into it
|
||||
val data1 = getRandomByteArray(5 * 1024 * 1024)
|
||||
context.contentResolver.openOutputStream(file1.uri)!!.writeAndClose(data1)
|
||||
assertEquals(data1.size.toLong(), file1.length())
|
||||
|
||||
// data should still be there
|
||||
assertReadEquals(data1, context.contentResolver.openInputStream(file1.uri))
|
||||
|
||||
// create test file
|
||||
val name2 = getRandomBase64(Random.nextInt(1, 10))
|
||||
val file2 = requireNotNull(dir.createFile(mimeType, name2))
|
||||
assertTrue(file2.exists())
|
||||
assertEquals(name2, file2.name)
|
||||
|
||||
// write some data into it
|
||||
val data2 = getRandomByteArray(12 * 1024 * 1024)
|
||||
context.contentResolver.openOutputStream(file2.uri)!!.writeAndClose(data2)
|
||||
assertEquals(data2.size.toLong(), file2.length())
|
||||
|
||||
// data should still be there
|
||||
assertReadEquals(data2, context.contentResolver.openInputStream(file2.uri))
|
||||
|
||||
// delete files again
|
||||
file1.delete()
|
||||
file2.delete()
|
||||
assertFalse(file1.exists())
|
||||
assertFalse(file2.exists())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGetLoadedCursor() = runBlocking {
|
||||
// empty cursor extras are like not loading, returns same cursor right away
|
||||
val cursor1: Cursor = mockk()
|
||||
every { cursor1.extras } returns Bundle()
|
||||
assertEquals(cursor1, getLoadedCursor { cursor1 })
|
||||
|
||||
// explicitly not loading, returns same cursor right away
|
||||
val cursor2: Cursor = mockk()
|
||||
every { cursor2.extras } returns Bundle().apply { putBoolean(EXTRA_LOADING, false) }
|
||||
assertEquals(cursor2, getLoadedCursor { cursor2 })
|
||||
|
||||
// loading cursor registers content observer, times out and closes cursor
|
||||
val cursor3: Cursor = mockk()
|
||||
every { cursor3.extras } returns Bundle().apply { putBoolean(EXTRA_LOADING, true) }
|
||||
every { cursor3.registerContentObserver(any()) } just Runs
|
||||
every { cursor3.close() } just Runs
|
||||
coAssertThrows(TimeoutCancellationException::class.java) {
|
||||
getLoadedCursor(1000) { cursor3 }
|
||||
}
|
||||
verify { cursor3.registerContentObserver(any()) }
|
||||
verify { cursor3.close() } // ensure that cursor gets closed
|
||||
|
||||
// loading cursor registers content observer, but re-query fails
|
||||
val cursor4: Cursor = mockk()
|
||||
val observer4 = slot<ContentObserver>()
|
||||
val query: () -> Cursor? = { if (observer4.isCaptured) null else cursor4 }
|
||||
every { cursor4.extras } returns Bundle().apply { putBoolean(EXTRA_LOADING, true) }
|
||||
every { cursor4.registerContentObserver(capture(observer4)) } answers {
|
||||
observer4.captured.onChange(false, Uri.parse("foo://bar"))
|
||||
}
|
||||
every { cursor4.close() } just Runs
|
||||
coAssertThrows(IOException::class.java) {
|
||||
getLoadedCursor(10_000, query)
|
||||
}
|
||||
assertTrue(observer4.isCaptured)
|
||||
verify { cursor4.close() } // ensure that cursor gets closed
|
||||
|
||||
// loading cursor registers content observer, re-queries and returns new result
|
||||
val cursor5: Cursor = mockk()
|
||||
val result5: Cursor = mockk()
|
||||
val observer5 = slot<ContentObserver>()
|
||||
val query5: () -> Cursor? = { if (observer5.isCaptured) result5 else cursor5 }
|
||||
every { cursor5.extras } returns Bundle().apply { putBoolean(EXTRA_LOADING, true) }
|
||||
every { cursor5.registerContentObserver(capture(observer5)) } answers {
|
||||
observer5.captured.onChange(false, null)
|
||||
}
|
||||
every { cursor5.close() } just Runs
|
||||
assertEquals(result5, getLoadedCursor(10_000, query5))
|
||||
assertTrue(observer5.isCaptured)
|
||||
verify { cursor5.close() } // ensure that initial cursor got closed
|
||||
}
|
||||
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.transport.backup
|
||||
|
||||
import android.app.backup.BackupDataInput
|
||||
import android.app.backup.BackupTransport.FLAG_NON_INCREMENTAL
|
||||
import android.content.pm.PackageInfo
|
||||
import android.os.ParcelFileDescriptor
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.filters.MediumTest
|
||||
import com.stevesoltys.seedvault.repo.BackupData
|
||||
import com.stevesoltys.seedvault.repo.BackupReceiver
|
||||
import io.mockk.CapturingSlot
|
||||
import io.mockk.Runs
|
||||
import io.mockk.coEvery
|
||||
import io.mockk.every
|
||||
import io.mockk.just
|
||||
import io.mockk.mockk
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.Assert.assertArrayEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
import kotlin.random.Random
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@MediumTest
|
||||
class KvBackupInstrumentationTest : KoinComponent {
|
||||
|
||||
private val backupReceiver: BackupReceiver = mockk()
|
||||
private val inputFactory: InputFactory = mockk()
|
||||
private val dbManager: KvDbManager by inject()
|
||||
|
||||
private val backup = KVBackup(
|
||||
backupReceiver = backupReceiver,
|
||||
inputFactory = inputFactory,
|
||||
dbManager = dbManager,
|
||||
)
|
||||
|
||||
private val data = mockk<ParcelFileDescriptor>()
|
||||
private val dataInput = mockk<BackupDataInput>()
|
||||
private val key = "foo.bar"
|
||||
private val dataValue = Random.nextBytes(23)
|
||||
|
||||
@Test
|
||||
fun `test non-incremental backup with existing DB`() {
|
||||
val packageName = "com.example"
|
||||
val backupData = BackupData(emptyList(), emptyMap())
|
||||
|
||||
// create existing db
|
||||
dbManager.getDb(packageName).use { db ->
|
||||
db.put("foo", "bar".toByteArray())
|
||||
}
|
||||
|
||||
val packageInfo = PackageInfo().apply {
|
||||
this.packageName = packageName
|
||||
}
|
||||
|
||||
every { inputFactory.getBackupDataInput(data) } returns dataInput
|
||||
every { dataInput.readNextHeader() } returnsMany listOf(true, false)
|
||||
every { dataInput.key } returns key
|
||||
every { dataInput.dataSize } returns dataValue.size
|
||||
val slot = CapturingSlot<ByteArray>()
|
||||
every { dataInput.readEntityData(capture(slot), 0, dataValue.size) } answers {
|
||||
dataValue.copyInto(slot.captured)
|
||||
dataValue.size
|
||||
}
|
||||
every { data.close() } just Runs
|
||||
|
||||
backup.performBackup(packageInfo, data, FLAG_NON_INCREMENTAL)
|
||||
|
||||
coEvery { backupReceiver.readFromStream(any(), any()) } returns backupData
|
||||
|
||||
runBlocking {
|
||||
assertEquals(backupData, backup.finishBackup())
|
||||
}
|
||||
|
||||
dbManager.getDb(packageName).use { db ->
|
||||
assertNull(db.get("foo")) // existing data foo is gone
|
||||
assertArrayEquals(dataValue, db.get(key)) // new data got added
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,22 +1,8 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2020 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.transport.backup
|
||||
|
||||
import android.content.pm.PackageInfo
|
||||
import android.util.Log
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.filters.MediumTest
|
||||
import com.stevesoltys.seedvault.backend.BackendManager
|
||||
import com.stevesoltys.seedvault.settings.AppStatus
|
||||
import com.stevesoltys.seedvault.settings.SettingsManager
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import org.calyxos.seedvault.core.backends.Backend
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.koin.core.component.KoinComponent
|
||||
|
@ -28,43 +14,10 @@ class PackageServiceTest : KoinComponent {
|
|||
|
||||
private val packageService: PackageService by inject()
|
||||
|
||||
private val settingsManager: SettingsManager by inject()
|
||||
|
||||
private val backendManager: BackendManager by inject()
|
||||
|
||||
private val backend: Backend get() = backendManager.backend
|
||||
|
||||
@Test
|
||||
fun testNotAllowedPackages() {
|
||||
val packages = packageService.notBackedUpPackages
|
||||
Log.e("TEST", "Packages: $packages")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `shouldIncludeAppInBackup exempts plugin provider and blacklisted apps`() {
|
||||
val packageInfo = PackageInfo().apply {
|
||||
packageName = "com.example"
|
||||
}
|
||||
|
||||
val disabledAppStatus = mockk<AppStatus>().apply {
|
||||
every { packageName } returns packageInfo.packageName
|
||||
every { enabled } returns false
|
||||
}
|
||||
settingsManager.onAppBackupStatusChanged(disabledAppStatus)
|
||||
|
||||
// Should not backup blacklisted apps
|
||||
assertFalse(packageService.shouldIncludeAppInBackup(packageInfo.packageName))
|
||||
|
||||
val enabledAppStatus = mockk<AppStatus>().apply {
|
||||
every { packageName } returns packageInfo.packageName
|
||||
every { enabled } returns true
|
||||
}
|
||||
settingsManager.onAppBackupStatusChanged(enabledAppStatus)
|
||||
|
||||
// Should backup non-blacklisted apps
|
||||
assertTrue(packageService.shouldIncludeAppInBackup(packageInfo.packageName))
|
||||
|
||||
// Should not backup storage provider
|
||||
assertFalse(packageService.shouldIncludeAppInBackup(backend.providerPackageName!!))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,128 +0,0 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.worker
|
||||
|
||||
import android.content.pm.PackageInfo
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.filters.MediumTest
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.github.luben.zstd.ZstdOutputStream
|
||||
import com.google.protobuf.ByteString
|
||||
import com.stevesoltys.seedvault.MAGIC_PACKAGE_MANAGER
|
||||
import com.stevesoltys.seedvault.metadata.BackupType
|
||||
import com.stevesoltys.seedvault.proto.SnapshotKt.blob
|
||||
import com.stevesoltys.seedvault.repo.AppBackupManager
|
||||
import com.stevesoltys.seedvault.repo.BackupData
|
||||
import com.stevesoltys.seedvault.repo.BackupReceiver
|
||||
import com.stevesoltys.seedvault.repo.Loader
|
||||
import com.stevesoltys.seedvault.repo.SnapshotCreatorFactory
|
||||
import com.stevesoltys.seedvault.transport.backup.PackageService
|
||||
import io.mockk.Runs
|
||||
import io.mockk.coEvery
|
||||
import io.mockk.every
|
||||
import io.mockk.just
|
||||
import io.mockk.mockk
|
||||
import io.mockk.slot
|
||||
import junit.framework.TestCase.assertTrue
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.calyxos.seedvault.core.backends.AppBackupFileType
|
||||
import org.calyxos.seedvault.core.toHexString
|
||||
import org.junit.Assert.assertArrayEquals
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
import kotlin.random.Random
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@MediumTest
|
||||
class IconManagerTest : KoinComponent {
|
||||
|
||||
private val context = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
private val packageService by inject<PackageService>()
|
||||
private val backupReceiver = mockk<BackupReceiver>()
|
||||
private val loader = mockk<Loader>()
|
||||
private val appBackupManager = mockk<AppBackupManager>()
|
||||
private val snapshotCreatorFactory by inject<SnapshotCreatorFactory>()
|
||||
private val snapshotCreator = snapshotCreatorFactory.createSnapshotCreator()
|
||||
|
||||
private val iconManager = IconManager(
|
||||
context = context,
|
||||
packageService = packageService,
|
||||
crypto = mockk(),
|
||||
backupReceiver = backupReceiver,
|
||||
loader = loader,
|
||||
appBackupManager = appBackupManager,
|
||||
)
|
||||
|
||||
init {
|
||||
every { appBackupManager.snapshotCreator } returns snapshotCreator
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test upload and then download`(): Unit = runBlocking {
|
||||
// prepare output data
|
||||
val output = slot<ByteArray>()
|
||||
val chunkId = Random.nextBytes(32).toHexString()
|
||||
val chunkList = listOf(chunkId)
|
||||
val blobId = Random.nextBytes(32).toHexString()
|
||||
val blob = blob { id = ByteString.fromHex(blobId) }
|
||||
|
||||
// upload icons and capture plaintext bytes
|
||||
coEvery { backupReceiver.addBytes(any(), capture(output)) } just Runs
|
||||
coEvery {
|
||||
backupReceiver.finalize(any())
|
||||
} returns BackupData(chunkList, mapOf(chunkId to blob))
|
||||
iconManager.uploadIcons()
|
||||
assertTrue(output.captured.isNotEmpty())
|
||||
|
||||
// @pm@ is needed
|
||||
val pmPackageInfo = PackageInfo().apply { packageName = MAGIC_PACKAGE_MANAGER }
|
||||
val backupData = BackupData(emptyList(), emptyMap())
|
||||
snapshotCreator.onPackageBackedUp(pmPackageInfo, BackupType.KV, backupData)
|
||||
|
||||
// get snapshot and assert it has icon chunks
|
||||
val snapshot = snapshotCreator.finalizeSnapshot()
|
||||
assertTrue(snapshot.iconChunkIdsCount > 0)
|
||||
|
||||
// prepare data for downloading icons
|
||||
val repoId = Random.nextBytes(32).toHexString()
|
||||
val inputStream = ByteArrayInputStream(output.captured)
|
||||
coEvery { loader.loadFile(AppBackupFileType.Blob(repoId, blobId)) } returns inputStream
|
||||
|
||||
// download icons and ensure we had an icon for at least one app
|
||||
val iconSet = iconManager.downloadIcons(repoId, snapshot)
|
||||
assertTrue(iconSet.isNotEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test upload produces deterministic output`(): Unit = runBlocking {
|
||||
val output1 = slot<ByteArray>()
|
||||
val output2 = slot<ByteArray>()
|
||||
|
||||
coEvery { backupReceiver.addBytes(any(), capture(output1)) } just Runs
|
||||
coEvery { backupReceiver.finalize(any()) } returns BackupData(emptyList(), emptyMap())
|
||||
iconManager.uploadIcons()
|
||||
assertTrue(output1.captured.isNotEmpty())
|
||||
|
||||
coEvery { backupReceiver.addBytes(any(), capture(output2)) } just Runs
|
||||
coEvery { backupReceiver.finalize(any()) } returns BackupData(emptyList(), emptyMap())
|
||||
iconManager.uploadIcons()
|
||||
assertTrue(output2.captured.isNotEmpty())
|
||||
|
||||
assertArrayEquals(output1.captured, output2.captured)
|
||||
|
||||
// print compressed and uncompressed size
|
||||
val size = output1.captured.size.toFloat() / 1024 / 1024
|
||||
val outputStream = ByteArrayOutputStream()
|
||||
ZstdOutputStream(outputStream).use { it.write(output1.captured) }
|
||||
val compressedSize = outputStream.size().toFloat() / 1024 / 1024
|
||||
println("Icon size: $size MB, compressed $compressedSize MB")
|
||||
}
|
||||
|
||||
}
|
|
@ -1,8 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
SPDX-FileCopyrightText: 2020 The Calyx Institute
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
-->
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
|
@ -11,13 +7,7 @@
|
|||
<activity
|
||||
android:name="com.stevesoltys.seedvault.settings.SettingsActivity"
|
||||
android:exported="true"
|
||||
tools:remove="android:permission">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
tools:remove="android:permission" />
|
||||
<activity
|
||||
android:name="com.stevesoltys.seedvault.restore.RestoreActivity"
|
||||
android:exported="true"
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
SPDX-FileCopyrightText: 2020 The Calyx Institute
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
-->
|
||||
<resources>
|
||||
<bool name="show_restore_in_settings">true</bool>
|
||||
|
||||
<string-array name="storage_authority_whitelist">
|
||||
<item>com.android.externalstorage.documents</item>
|
||||
<item>org.nextcloud.documents</item>
|
||||
<item>org.nextcloud.beta.documents</item>
|
||||
<item>at.bitfire.davdroid.webdav</item>
|
||||
<item>de.felixnuesse.extract.vcp</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
|
|
@ -1,14 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
SPDX-FileCopyrightText: 2017-2019 Steve Soltys
|
||||
SPDX-FileCopyrightText: 2020 The Calyx Institute
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
-->
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.stevesoltys.seedvault"
|
||||
android:versionCode="35050000"
|
||||
android:versionName="15-5.0">
|
||||
android:versionCode="33030030"
|
||||
android:versionName="13-3.3">
|
||||
<!--
|
||||
The version code is the targeted SDK_VERSION plus 6 digits for our own version code.
|
||||
The version name is the targeted Android version followed by - and our own version name.
|
||||
|
@ -21,9 +16,6 @@
|
|||
<!-- This is needed to check for internet access when backup is stored on network storage -->
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
|
||||
<!-- Used for internal WebDAV plugin -->
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<!-- This is needed to inform users about backup status and errors -->
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
|
||||
|
@ -72,13 +64,6 @@
|
|||
android:name="android.permission.READ_LOGS"
|
||||
tools:ignore="ProtectedPermissions" />
|
||||
|
||||
<!-- Used to get the name of the current profile -->
|
||||
<uses-permission android:name="android.permission.QUERY_USERS"
|
||||
tools:ignore="ProtectedPermissions" />
|
||||
|
||||
<!-- Used for periodic storage backups -->
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
|
||||
|
||||
<!-- Permission used to open settings -->
|
||||
<permission
|
||||
android:name="com.stevesoltys.seedvault.OPEN_SETTINGS"
|
||||
|
@ -101,13 +86,11 @@
|
|||
<activity
|
||||
android:name=".settings.SettingsActivity"
|
||||
android:exported="true"
|
||||
android:launchMode="singleTask"
|
||||
android:permission="com.stevesoltys.seedvault.OPEN_SETTINGS"
|
||||
android:windowSoftInputMode="adjustResize" />
|
||||
android:permission="com.stevesoltys.seedvault.OPEN_SETTINGS" />
|
||||
|
||||
<activity
|
||||
android:name=".ui.storage.StorageActivity"
|
||||
android:windowSoftInputMode="adjustResize" />
|
||||
android:theme="@style/AppTheme.NoActionBar" />
|
||||
|
||||
<activity
|
||||
android:name=".ui.storage.PermissionGrantActivity"
|
||||
|
@ -117,25 +100,20 @@
|
|||
<activity
|
||||
android:name=".ui.recoverycode.RecoveryCodeActivity"
|
||||
android:label="@string/recovery_code_title"
|
||||
android:windowSoftInputMode="adjustResize" />
|
||||
android:theme="@style/AppTheme.NoActionBar" />
|
||||
|
||||
<activity
|
||||
android:name=".restore.RestoreActivity"
|
||||
android:exported="true"
|
||||
android:label="@string/restore_title"
|
||||
android:launchMode="singleTask"
|
||||
android:permission="com.stevesoltys.seedvault.RESTORE_BACKUP">
|
||||
android:permission="com.stevesoltys.seedvault.RESTORE_BACKUP"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
<intent-filter>
|
||||
<action android:name="com.stevesoltys.seedvault.RESTORE_BACKUP" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".ui.check.AppCheckResultActivity"
|
||||
android:label="@string/notification_checking_finished_title"
|
||||
android:launchMode="singleTask"/>
|
||||
|
||||
<service
|
||||
android:name=".transport.ConfigurableBackupTransportService"
|
||||
android:exported="false">
|
||||
|
@ -163,30 +141,31 @@
|
|||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<!-- Used by Workmanager to schedule our workers -->
|
||||
<service
|
||||
android:name="androidx.work.impl.foreground.SystemForegroundService"
|
||||
android:foregroundServiceType="dataSync"
|
||||
tools:node="merge" />
|
||||
<receiver
|
||||
android:name=".SecretCodeReceiver"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.telephony.action.SECRET_CODE" />
|
||||
<!-- *#*#RESTORE#*#* -->
|
||||
<data
|
||||
android:host="7378673"
|
||||
android:scheme="android_secret_code" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<!-- Used to start actual BackupService depending on scheduling criteria -->
|
||||
<service
|
||||
android:name=".storage.StorageBackupJobService"
|
||||
android:exported="false"
|
||||
android:label="BackupJobService"
|
||||
android:permission="android.permission.BIND_JOB_SERVICE" />
|
||||
<!-- Does app restore as a foreground service -->
|
||||
<service
|
||||
android:name=".restore.RestoreService"
|
||||
android:exported="false"
|
||||
android:foregroundServiceType="dataSync"
|
||||
android:label="RestoreService" />
|
||||
<!-- Does the actual file backup work as a foreground service -->
|
||||
<!-- Does the actual backup work as a foreground service -->
|
||||
<service
|
||||
android:name=".storage.StorageBackupService"
|
||||
android:exported="false"
|
||||
android:foregroundServiceType="dataSync"
|
||||
android:label="BackupService" />
|
||||
<!-- Does file restore as a foreground service -->
|
||||
<!-- Does restore as a foreground service -->
|
||||
<service
|
||||
android:name=".storage.StorageRestoreService"
|
||||
android:exported="false"
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
<!--
|
||||
SPDX-FileCopyrightText: 2024 The Calyx Institute
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
-->
|
||||
<configuration
|
||||
xmlns="https://tony19.github.io/logback-android/xml"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="https://tony19.github.io/logback-android/xml https://cdn.jsdelivr.net/gh/tony19/logback-android/logback.xsd"
|
||||
>
|
||||
<appender name="logcat" class="ch.qos.logback.classic.android.LogcatAppender">
|
||||
<tagEncoder>
|
||||
<pattern>%logger{12}</pattern>
|
||||
</tagEncoder>
|
||||
<encoder>
|
||||
<pattern>[%-20thread] %msg</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="DEBUG">
|
||||
<appender-ref ref="logcat" />
|
||||
</root>
|
||||
</configuration>
|
||||
|
|
@ -1,52 +1,34 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2020 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault
|
||||
|
||||
import android.Manifest.permission.INTERACT_ACROSS_USERS_FULL
|
||||
import android.app.ActivityManager
|
||||
import android.app.ActivityManager.RunningAppProcessInfo
|
||||
import android.app.Application
|
||||
import android.app.backup.BackupManager
|
||||
import android.app.backup.BackupManager.PACKAGE_MANAGER_SENTINEL
|
||||
import android.app.backup.IBackupManager
|
||||
import android.content.Context
|
||||
import android.content.Context.BACKUP_SERVICE
|
||||
import android.content.pm.PackageManager.PERMISSION_GRANTED
|
||||
import android.os.Build
|
||||
import android.os.ServiceManager.getService
|
||||
import android.os.StrictMode
|
||||
import android.os.UserHandle
|
||||
import android.os.UserManager
|
||||
import android.util.Log
|
||||
import androidx.work.ExistingPeriodicWorkPolicy.UPDATE
|
||||
import androidx.work.WorkManager
|
||||
import com.google.android.material.color.DynamicColors
|
||||
import com.stevesoltys.seedvault.MemoryLogger.getMemStr
|
||||
import com.stevesoltys.seedvault.backend.BackendManager
|
||||
import com.stevesoltys.seedvault.backend.saf.storagePluginModuleSaf
|
||||
import com.stevesoltys.seedvault.backend.webdav.storagePluginModuleWebDav
|
||||
import com.stevesoltys.seedvault.crypto.cryptoModule
|
||||
import com.stevesoltys.seedvault.header.headerModule
|
||||
import com.stevesoltys.seedvault.metadata.MetadataManager
|
||||
import com.stevesoltys.seedvault.metadata.metadataModule
|
||||
import com.stevesoltys.seedvault.repo.repoModule
|
||||
import com.stevesoltys.seedvault.plugins.saf.documentsProviderModule
|
||||
import com.stevesoltys.seedvault.restore.RestoreViewModel
|
||||
import com.stevesoltys.seedvault.restore.install.installModule
|
||||
import com.stevesoltys.seedvault.restore.restoreUiModule
|
||||
import com.stevesoltys.seedvault.settings.AppListRetriever
|
||||
import com.stevesoltys.seedvault.settings.SettingsManager
|
||||
import com.stevesoltys.seedvault.settings.SettingsViewModel
|
||||
import com.stevesoltys.seedvault.storage.storageModule
|
||||
import com.stevesoltys.seedvault.transport.TRANSPORT_ID
|
||||
import com.stevesoltys.seedvault.transport.backup.backupModule
|
||||
import com.stevesoltys.seedvault.transport.restore.restoreModule
|
||||
import com.stevesoltys.seedvault.ui.files.FileSelectionViewModel
|
||||
import com.stevesoltys.seedvault.ui.notification.BackupNotificationManager
|
||||
import com.stevesoltys.seedvault.ui.recoverycode.RecoveryCodeViewModel
|
||||
import com.stevesoltys.seedvault.ui.storage.BackupStorageViewModel
|
||||
import com.stevesoltys.seedvault.ui.storage.RestoreStorageViewModel
|
||||
import com.stevesoltys.seedvault.worker.AppBackupWorker
|
||||
import com.stevesoltys.seedvault.worker.workerModule
|
||||
import org.calyxos.seedvault.core.backends.BackendFactory
|
||||
import org.koin.android.ext.android.inject
|
||||
import org.koin.android.ext.koin.androidContext
|
||||
import org.koin.android.ext.koin.androidLogger
|
||||
|
@ -61,61 +43,24 @@ import org.koin.dsl.module
|
|||
*/
|
||||
open class App : Application() {
|
||||
|
||||
open val isTest: Boolean = false
|
||||
|
||||
private val appModule = module {
|
||||
single { SettingsManager(this@App) }
|
||||
single { BackupNotificationManager(this@App) }
|
||||
single { BackendManager(this@App, get(), get(), get()) }
|
||||
single {
|
||||
BackendFactory {
|
||||
// uses context of the device's main user to be able to access USB storage
|
||||
this@App.applicationContext.getStorageContext {
|
||||
get<SettingsManager>().getSafProperties()?.isUsb == true
|
||||
}
|
||||
}
|
||||
}
|
||||
single { BackupStateManager(this@App) }
|
||||
single { Clock() }
|
||||
factory<IBackupManager> { IBackupManager.Stub.asInterface(getService(BACKUP_SERVICE)) }
|
||||
factory { AppListRetriever(this@App, get(), get(), get()) }
|
||||
|
||||
viewModel {
|
||||
SettingsViewModel(
|
||||
app = this@App,
|
||||
settingsManager = get(),
|
||||
keyManager = get(),
|
||||
backendManager = get(),
|
||||
appListRetriever = get(),
|
||||
storageBackup = get(),
|
||||
backupManager = get(),
|
||||
backupStateManager = get(),
|
||||
checker = get(),
|
||||
)
|
||||
}
|
||||
viewModel {
|
||||
RecoveryCodeViewModel(this@App, get(), get(), get(), get(), get(), get(), get())
|
||||
}
|
||||
viewModel {
|
||||
BackupStorageViewModel(
|
||||
app = this@App,
|
||||
backupManager = get(),
|
||||
backupInitializer = get(),
|
||||
storageBackup = get(),
|
||||
safHandler = get(),
|
||||
webDavHandler = get(),
|
||||
settingsManager = get(),
|
||||
backendManager = get(),
|
||||
)
|
||||
}
|
||||
viewModel { RestoreStorageViewModel(this@App, get(), get(), get(), get()) }
|
||||
viewModel { SettingsViewModel(this@App, get(), get(), get(), get(), get(), get(), get()) }
|
||||
viewModel { RecoveryCodeViewModel(this@App, get(), get(), get(), get(), get(), get()) }
|
||||
viewModel { BackupStorageViewModel(this@App, get(), get(), get(), get()) }
|
||||
viewModel { RestoreStorageViewModel(this@App, get(), get()) }
|
||||
viewModel { RestoreViewModel(this@App, get(), get(), get(), get(), get(), get()) }
|
||||
viewModel { FileSelectionViewModel(this@App, get()) }
|
||||
}
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
DynamicColors.applyToActivitiesIfAvailable(this)
|
||||
startKoin()
|
||||
if (!isTest) migrateToOwnScheduling()
|
||||
if (isDebugBuild()) {
|
||||
StrictMode.setThreadPolicy(
|
||||
StrictMode.ThreadPolicy.Builder()
|
||||
|
@ -131,6 +76,9 @@ open class App : Application() {
|
|||
.build()
|
||||
)
|
||||
}
|
||||
permitDiskReads {
|
||||
migrateTokenFromMetadataToSettingsManager()
|
||||
}
|
||||
}
|
||||
|
||||
protected open fun startKoin() = startKoin {
|
||||
|
@ -143,61 +91,36 @@ open class App : Application() {
|
|||
cryptoModule,
|
||||
headerModule,
|
||||
metadataModule,
|
||||
storagePluginModuleSaf,
|
||||
storagePluginModuleWebDav,
|
||||
documentsProviderModule, // storage plugin
|
||||
backupModule,
|
||||
restoreModule,
|
||||
installModule,
|
||||
storageModule,
|
||||
repoModule,
|
||||
workerModule,
|
||||
restoreUiModule,
|
||||
appModule
|
||||
)
|
||||
|
||||
private val settingsManager: SettingsManager by inject()
|
||||
private val backupManager: IBackupManager by inject()
|
||||
private val backendManager: BackendManager by inject()
|
||||
private val backupStateManager: BackupStateManager by inject()
|
||||
|
||||
override fun onTrimMemory(level: Int) {
|
||||
Log.w("Seedvault", "onTrimMemory($level) ${getMemStr()}")
|
||||
val processInfo = RunningAppProcessInfo()
|
||||
ActivityManager.getMyMemoryState(processInfo)
|
||||
Log.w("Seedvault", " lastTrimLevel: ${processInfo.lastTrimLevel}")
|
||||
Log.w("Seedvault", " importance: ${processInfo.importance}")
|
||||
super.onTrimMemory(level)
|
||||
}
|
||||
private val metadataManager: MetadataManager by inject()
|
||||
|
||||
/**
|
||||
* Disables the framework scheduling in favor of our own.
|
||||
* Introduced in the first half of 2024 and can be removed after a suitable migration period.
|
||||
* The responsibility for the current token was moved to the [SettingsManager]
|
||||
* in the end of 2020.
|
||||
* This method migrates the token for existing installs and can be removed
|
||||
* after sufficient time has passed.
|
||||
*/
|
||||
protected open fun migrateToOwnScheduling() {
|
||||
if (!backupStateManager.isFrameworkSchedulingEnabled) { // already on own scheduling
|
||||
// fix things for removable drive users who had a job scheduled here before
|
||||
if (backendManager.isOnRemovableDrive) AppBackupWorker.unschedule(applicationContext)
|
||||
return
|
||||
}
|
||||
|
||||
if (backupManager.currentTransport == TRANSPORT_ID) {
|
||||
backupManager.setFrameworkSchedulingEnabledForUser(UserHandle.myUserId(), false)
|
||||
if (backupManager.isBackupEnabled && !backendManager.isOnRemovableDrive) {
|
||||
AppBackupWorker.schedule(applicationContext, settingsManager, UPDATE)
|
||||
}
|
||||
// cancel old D2D worker
|
||||
WorkManager.getInstance(this).cancelUniqueWork("APP_BACKUP")
|
||||
private fun migrateTokenFromMetadataToSettingsManager() {
|
||||
@Suppress("DEPRECATION")
|
||||
val token = metadataManager.getBackupToken()
|
||||
if (token != 0L && settingsManager.getToken() == null) {
|
||||
settingsManager.setNewToken(token)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const val MAGIC_PACKAGE_MANAGER: String = PACKAGE_MANAGER_SENTINEL
|
||||
const val MAGIC_PACKAGE_MANAGER = PACKAGE_MANAGER_SENTINEL
|
||||
const val ANCESTRAL_RECORD_KEY = "@ancestral_record@"
|
||||
const val NO_DATA_END_SENTINEL = "@end@"
|
||||
const val GLOBAL_METADATA_KEY = "@meta@"
|
||||
const val ERROR_BACKUP_CANCELLED: Int = BackupManager.ERROR_BACKUP_CANCELLED
|
||||
const val ERROR_BACKUP_NOT_ALLOWED: Int = BackupManager.ERROR_BACKUP_NOT_ALLOWED
|
||||
|
||||
// TODO this doesn't work for LineageOS as they do public debug builds
|
||||
fun isDebugBuild() = Build.TYPE == "userdebug"
|
||||
|
@ -220,15 +143,8 @@ fun <T> permitDiskReads(func: () -> T): T {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hack to allow other profiles access to USB backend.
|
||||
* @return the context of the device's main user, so use with great care!
|
||||
*/
|
||||
@Suppress("MissingPermission")
|
||||
fun Context.getStorageContext(isUsbStorage: () -> Boolean): Context {
|
||||
if (checkSelfPermission(INTERACT_ACROSS_USERS_FULL) == PERMISSION_GRANTED && isUsbStorage()) {
|
||||
UserManager.get(this).getProfileParent(user)
|
||||
?.let { parent -> return createContextAsUser(parent, 0) }
|
||||
}
|
||||
return this
|
||||
fun Context.getSystemContext(isUsbStorage: () -> Boolean): Context {
|
||||
return if (checkSelfPermission(INTERACT_ACROSS_USERS_FULL) == PERMISSION_GRANTED &&
|
||||
isUsbStorage()
|
||||
) createContextAsUser(UserHandle.SYSTEM, 0) else this
|
||||
}
|
||||
|
|
|
@ -1,38 +1,22 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2020 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault
|
||||
|
||||
import android.app.backup.BackupManagerMonitor.EXTRA_LOG_EVENT_CATEGORY
|
||||
import android.app.backup.BackupManagerMonitor.EXTRA_LOG_EVENT_ID
|
||||
import android.app.backup.BackupManagerMonitor.EXTRA_LOG_EVENT_PACKAGE_NAME
|
||||
import android.app.backup.BackupManagerMonitor.EXTRA_LOG_PREFLIGHT_ERROR
|
||||
import android.app.backup.BackupManagerMonitor.LOG_EVENT_ID_ERROR_PREFLIGHT
|
||||
import android.app.backup.IBackupManagerMonitor
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.util.Log.DEBUG
|
||||
|
||||
private val TAG = BackupMonitor::class.java.name
|
||||
|
||||
open class BackupMonitor : IBackupManagerMonitor.Stub() {
|
||||
class BackupMonitor : IBackupManagerMonitor.Stub() {
|
||||
|
||||
override fun onEvent(bundle: Bundle) {
|
||||
onEvent(
|
||||
id = bundle.getInt(EXTRA_LOG_EVENT_ID),
|
||||
category = bundle.getInt(EXTRA_LOG_EVENT_CATEGORY),
|
||||
packageName = bundle.getString(EXTRA_LOG_EVENT_PACKAGE_NAME),
|
||||
bundle = bundle,
|
||||
)
|
||||
}
|
||||
|
||||
open fun onEvent(id: Int, category: Int, packageName: String?, bundle: Bundle) {
|
||||
Log.d(TAG, "${packageName?.padEnd(64, ' ')} cat: $category id: $id")
|
||||
if (id == LOG_EVENT_ID_ERROR_PREFLIGHT) {
|
||||
val preflightResult = bundle.getLong(EXTRA_LOG_PREFLIGHT_ERROR, -1)
|
||||
Log.w(TAG, "Pre-flight error from $packageName: $preflightResult")
|
||||
}
|
||||
if (!Log.isLoggable(TAG, DEBUG)) return
|
||||
Log.d(TAG, "ID: " + bundle.getInt(EXTRA_LOG_EVENT_ID))
|
||||
Log.d(TAG, "CATEGORY: " + bundle.getInt(EXTRA_LOG_EVENT_CATEGORY, -1))
|
||||
Log.d(TAG, "PACKAGE: " + bundle.getString(EXTRA_LOG_EVENT_PACKAGE_NAME, "?"))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,66 +0,0 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault
|
||||
|
||||
import android.content.Context
|
||||
import android.provider.Settings
|
||||
import android.provider.Settings.Secure.BACKUP_AUTO_RESTORE
|
||||
import android.provider.Settings.Secure.BACKUP_SCHEDULING_ENABLED
|
||||
import android.util.Log
|
||||
import androidx.work.WorkInfo.State.RUNNING
|
||||
import androidx.work.WorkManager
|
||||
import com.stevesoltys.seedvault.storage.StorageBackupService
|
||||
import com.stevesoltys.seedvault.transport.ConfigurableBackupTransportService
|
||||
import com.stevesoltys.seedvault.worker.AppBackupPruneWorker
|
||||
import com.stevesoltys.seedvault.worker.AppBackupWorker.Companion.UNIQUE_WORK_NAME
|
||||
import com.stevesoltys.seedvault.worker.AppCheckerWorker
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.combine
|
||||
|
||||
private const val TAG = "BackupStateManager"
|
||||
|
||||
class BackupStateManager(
|
||||
context: Context,
|
||||
) {
|
||||
|
||||
private val workManager = WorkManager.getInstance(context)
|
||||
private val contentResolver = context.contentResolver
|
||||
|
||||
val isBackupRunning: Flow<Boolean> = combine(
|
||||
flow = ConfigurableBackupTransportService.isRunning,
|
||||
flow2 = StorageBackupService.isRunning,
|
||||
flow3 = workManager.getWorkInfosForUniqueWorkFlow(UNIQUE_WORK_NAME),
|
||||
) { appBackupRunning, filesBackupRunning, workInfo1 ->
|
||||
val workInfoState1 = workInfo1.getOrNull(0)?.state
|
||||
Log.i(
|
||||
TAG, "appBackupRunning: $appBackupRunning, " +
|
||||
"filesBackupRunning: $filesBackupRunning, " +
|
||||
"appBackupWorker: ${workInfoState1?.name}"
|
||||
)
|
||||
appBackupRunning || filesBackupRunning || workInfoState1 == RUNNING
|
||||
}
|
||||
|
||||
val isCheckOrPruneRunning: Flow<Boolean> = combine(
|
||||
flow = workManager.getWorkInfosForUniqueWorkFlow(AppBackupPruneWorker.UNIQUE_WORK_NAME),
|
||||
flow2 = workManager.getWorkInfosForUniqueWorkFlow(AppCheckerWorker.UNIQUE_WORK_NAME),
|
||||
) { pruneInfo, checkInfo ->
|
||||
val pruneInfoState = pruneInfo.getOrNull(0)?.state
|
||||
val checkInfoState = checkInfo.getOrNull(0)?.state
|
||||
Log.i(
|
||||
TAG,
|
||||
"pruneBackupWorker: ${pruneInfoState?.name}, " +
|
||||
"appCheckerWorker: ${checkInfoState?.name}"
|
||||
)
|
||||
pruneInfoState == RUNNING || checkInfoState == RUNNING
|
||||
}
|
||||
|
||||
val isAutoRestoreEnabled: Boolean
|
||||
get() = Settings.Secure.getInt(contentResolver, BACKUP_AUTO_RESTORE, 1) == 1
|
||||
|
||||
val isFrameworkSchedulingEnabled: Boolean
|
||||
get() = Settings.Secure.getInt(contentResolver, BACKUP_SCHEDULING_ENABLED, 1) == 1
|
||||
|
||||
}
|
|
@ -1,8 +1,3 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2020 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault
|
||||
|
||||
import java.nio.charset.Charset
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2020 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault
|
||||
|
||||
import android.util.Log
|
||||
|
||||
object MemoryLogger {
|
||||
|
||||
fun log() {
|
||||
Log.d("MemoryLogger", getMemStr())
|
||||
}
|
||||
|
||||
fun getMemStr(): String {
|
||||
val r = Runtime.getRuntime()
|
||||
val total = r.totalMemory() / 1024 / 1024
|
||||
val free = r.freeMemory() / 1024 / 1024
|
||||
val max = r.maxMemory() / 1024 / 1024
|
||||
val used = total - free
|
||||
return "$free MiB free - $used of $total (max $max)"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.stevesoltys.seedvault
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
import android.util.Log
|
||||
import com.stevesoltys.seedvault.restore.RestoreActivity
|
||||
|
||||
private val TAG = BroadcastReceiver::class.java.simpleName
|
||||
private const val RESTORE_SECRET_CODE = "7378673"
|
||||
|
||||
class SecretCodeReceiver : BroadcastReceiver() {
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
if (intent.data?.host != RESTORE_SECRET_CODE) return
|
||||
Log.d(TAG, "Restore secret code received.")
|
||||
val i = Intent(context, RestoreActivity::class.java).apply {
|
||||
flags = FLAG_ACTIVITY_NEW_TASK
|
||||
}
|
||||
context.startActivity(i)
|
||||
}
|
||||
}
|
|
@ -1,11 +1,5 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2020 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault
|
||||
|
||||
import android.app.backup.IBackupManager
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
|
@ -20,20 +14,26 @@ import android.os.Handler
|
|||
import android.os.Looper
|
||||
import android.provider.DocumentsContract
|
||||
import android.util.Log
|
||||
import androidx.core.content.ContextCompat.startForegroundService
|
||||
import com.stevesoltys.seedvault.metadata.MetadataManager
|
||||
import com.stevesoltys.seedvault.settings.FlashDrive
|
||||
import com.stevesoltys.seedvault.settings.SettingsManager
|
||||
import com.stevesoltys.seedvault.storage.StorageBackupService
|
||||
import com.stevesoltys.seedvault.storage.StorageBackupService.Companion.EXTRA_START_APP_BACKUP
|
||||
import com.stevesoltys.seedvault.transport.requestBackup
|
||||
import com.stevesoltys.seedvault.ui.storage.AUTHORITY_STORAGE
|
||||
import com.stevesoltys.seedvault.worker.BackupRequester.Companion.requestFilesAndAppBackup
|
||||
import org.koin.core.context.GlobalContext.get
|
||||
import java.util.Date
|
||||
import java.util.concurrent.TimeUnit.HOURS
|
||||
|
||||
private val TAG = UsbIntentReceiver::class.java.simpleName
|
||||
|
||||
private const val HOURS_AUTO_BACKUP: Long = 24
|
||||
|
||||
class UsbIntentReceiver : UsbMonitor() {
|
||||
|
||||
// using KoinComponent would crash robolectric tests :(
|
||||
private val settingsManager: SettingsManager by lazy { get().get() }
|
||||
private val backupManager: IBackupManager by lazy { get().get() }
|
||||
private val metadataManager: MetadataManager by lazy { get().get() }
|
||||
|
||||
override fun shouldMonitorStatus(context: Context, action: String, device: UsbDevice): Boolean {
|
||||
if (action != ACTION_USB_DEVICE_ATTACHED) return false
|
||||
|
@ -42,15 +42,12 @@ class UsbIntentReceiver : UsbMonitor() {
|
|||
val attachedFlashDrive = FlashDrive.from(device)
|
||||
return if (savedFlashDrive == attachedFlashDrive) {
|
||||
Log.d(TAG, "Matches stored device, checking backup time...")
|
||||
val lastBackupTime = settingsManager.lastBackupTime.value ?: 0
|
||||
val backupMillis = System.currentTimeMillis() - lastBackupTime
|
||||
if (backupMillis >= settingsManager.backupFrequencyInMillis) {
|
||||
Log.d(TAG, "Last backup older than it should be, requesting a backup...")
|
||||
Log.d(TAG, " ${Date(lastBackupTime)}")
|
||||
val backupMillis = System.currentTimeMillis() - metadataManager.getLastBackupTime()
|
||||
if (backupMillis >= HOURS.toMillis(HOURS_AUTO_BACKUP)) {
|
||||
Log.d(TAG, "Last backup older than 24 hours, requesting a backup...")
|
||||
true
|
||||
} else {
|
||||
Log.d(TAG, "We have a recent backup, not requesting a new one.")
|
||||
Log.d(TAG, " ${Date(lastBackupTime)}")
|
||||
false
|
||||
}
|
||||
} else {
|
||||
|
@ -60,7 +57,16 @@ class UsbIntentReceiver : UsbMonitor() {
|
|||
}
|
||||
|
||||
override fun onStatusChanged(context: Context, action: String, device: UsbDevice) {
|
||||
requestFilesAndAppBackup(context, settingsManager, backupManager)
|
||||
if (settingsManager.isStorageBackupEnabled()) {
|
||||
val i = Intent(context, StorageBackupService::class.java)
|
||||
// this starts an app backup afterwards
|
||||
i.putExtra(EXTRA_START_APP_BACKUP, true)
|
||||
startForegroundService(context, i)
|
||||
} else {
|
||||
Thread {
|
||||
requestBackup(context)
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -76,7 +82,7 @@ abstract class UsbMonitor : BroadcastReceiver() {
|
|||
if (intent.action == ACTION_USB_DEVICE_ATTACHED ||
|
||||
intent.action == ACTION_USB_DEVICE_DETACHED
|
||||
) {
|
||||
val device = intent.extras?.getParcelable(EXTRA_DEVICE, UsbDevice::class.java) ?: return
|
||||
val device = intent.extras?.getParcelable<UsbDevice>(EXTRA_DEVICE) ?: return
|
||||
Log.d(TAG, "New USB mass-storage device attached.")
|
||||
device.log()
|
||||
|
||||
|
|
|
@ -1,144 +0,0 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.backend
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import androidx.annotation.WorkerThread
|
||||
import com.stevesoltys.seedvault.getStorageContext
|
||||
import com.stevesoltys.seedvault.permitDiskReads
|
||||
import com.stevesoltys.seedvault.repo.BlobCache
|
||||
import com.stevesoltys.seedvault.settings.SettingsManager
|
||||
import com.stevesoltys.seedvault.settings.StoragePluginType
|
||||
import org.calyxos.seedvault.core.backends.Backend
|
||||
import org.calyxos.seedvault.core.backends.BackendFactory
|
||||
import org.calyxos.seedvault.core.backends.BackendProperties
|
||||
import org.calyxos.seedvault.core.backends.saf.SafBackend
|
||||
|
||||
class BackendManager(
|
||||
private val context: Context,
|
||||
private val settingsManager: SettingsManager,
|
||||
private val blobCache: BlobCache,
|
||||
backendFactory: BackendFactory,
|
||||
) {
|
||||
|
||||
@Volatile
|
||||
private var mBackend: Backend?
|
||||
|
||||
@Volatile
|
||||
private var mBackendProperties: BackendProperties<*>?
|
||||
|
||||
val backend: Backend
|
||||
@Synchronized
|
||||
get() {
|
||||
return mBackend ?: error("App plugin was loaded, but still null")
|
||||
}
|
||||
|
||||
val backendProperties: BackendProperties<*>?
|
||||
@Synchronized
|
||||
get() {
|
||||
return mBackendProperties
|
||||
}
|
||||
val isOnRemovableDrive: Boolean get() = backendProperties?.isUsb == true
|
||||
val requiresNetwork: Boolean get() = backendProperties?.requiresNetwork == true
|
||||
|
||||
init {
|
||||
when (settingsManager.storagePluginType) {
|
||||
StoragePluginType.SAF -> {
|
||||
val safConfig = settingsManager.getSafProperties() ?: error("No SAF storage saved")
|
||||
mBackend = backendFactory.createSafBackend(safConfig)
|
||||
mBackendProperties = safConfig
|
||||
}
|
||||
|
||||
StoragePluginType.WEB_DAV -> {
|
||||
val webDavProperties =
|
||||
settingsManager.webDavProperties ?: error("No WebDAV config saved")
|
||||
mBackend = backendFactory.createWebDavBackend(webDavProperties.config)
|
||||
mBackendProperties = webDavProperties
|
||||
}
|
||||
|
||||
null -> {
|
||||
mBackend = null
|
||||
mBackendProperties = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun isValidAppPluginSet(): Boolean {
|
||||
if (mBackend == null) return false
|
||||
if (mBackend is SafBackend) {
|
||||
val storage = settingsManager.getSafProperties() ?: return false
|
||||
if (storage.isUsb) return true
|
||||
return permitDiskReads {
|
||||
storage.getDocumentFile(context).isDirectory
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the storage plugins and current [BackendProperties].
|
||||
*
|
||||
* IMPORTANT: Do no call this while current plugins are being used,
|
||||
* e.g. while backup/restore operation is still running.
|
||||
*/
|
||||
@WorkerThread
|
||||
@Synchronized
|
||||
fun <T> changePlugins(
|
||||
backend: Backend,
|
||||
storageProperties: BackendProperties<T>,
|
||||
) {
|
||||
settingsManager.setStorageBackend(backend)
|
||||
mBackend = backend
|
||||
mBackendProperties = storageProperties
|
||||
blobCache.clearLocalCache()
|
||||
// TODO not critical, but nice to have: clear also local snapshot cache
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if we are able to do backups now by examining possible pre-conditions
|
||||
* such as plugged-in flash drive or internet access.
|
||||
*
|
||||
* Should be run off the UI thread (ideally I/O) because of disk access.
|
||||
*
|
||||
* @return true if a backup is possible, false if not.
|
||||
*/
|
||||
@WorkerThread
|
||||
fun canDoBackupNow(): Boolean {
|
||||
val storage = backendProperties ?: return false
|
||||
return !isOnUnavailableUsb() &&
|
||||
!storage.isUnavailableNetwork(context, settingsManager.useMeteredNetwork)
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if storage is on a flash drive.
|
||||
*
|
||||
* Should be run off the UI thread (ideally I/O) because of disk access.
|
||||
*
|
||||
* @return true if flash drive is not plugged in,
|
||||
* false if storage isn't on flash drive or it isn't plugged in.
|
||||
*/
|
||||
@WorkerThread
|
||||
fun isOnUnavailableUsb(): Boolean {
|
||||
val storage = backendProperties ?: return false
|
||||
val systemContext = context.getStorageContext { storage.isUsb }
|
||||
return storage.isUnavailableUsb(systemContext)
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the amount of free space in bytes, or null if unknown.
|
||||
*/
|
||||
@WorkerThread
|
||||
suspend fun getFreeSpace(): Long? {
|
||||
return try {
|
||||
backend.getFreeSpace()
|
||||
} catch (e: Throwable) { // NoClassDefFound isn't an [Exception], can get thrown by dav4jvm
|
||||
Log.e("StoragePluginManager", "Error getting free space: ", e)
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2020 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.backend.saf
|
||||
|
||||
import com.stevesoltys.seedvault.backend.LegacyStoragePlugin
|
||||
import com.stevesoltys.seedvault.settings.SettingsManager
|
||||
import org.koin.android.ext.koin.androidContext
|
||||
import org.koin.dsl.module
|
||||
|
||||
val storagePluginModuleSaf = module {
|
||||
single { SafHandler(androidContext(), get(), get(), get()) }
|
||||
|
||||
@Suppress("Deprecation")
|
||||
single<LegacyStoragePlugin> {
|
||||
DocumentsProviderLegacyPlugin(
|
||||
context = androidContext(),
|
||||
storageGetter = {
|
||||
val safProperties = get<SettingsManager>().getSafProperties()
|
||||
?: error("No SAF storage")
|
||||
DocumentsStorage(androidContext(), safProperties)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
|
@ -1,100 +0,0 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.backend.saf
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Context.USB_SERVICE
|
||||
import android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION
|
||||
import android.content.Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
||||
import android.hardware.usb.UsbManager
|
||||
import android.net.Uri
|
||||
import android.util.Log
|
||||
import androidx.annotation.WorkerThread
|
||||
import com.stevesoltys.seedvault.R
|
||||
import com.stevesoltys.seedvault.backend.BackendManager
|
||||
import com.stevesoltys.seedvault.isMassStorage
|
||||
import com.stevesoltys.seedvault.settings.FlashDrive
|
||||
import com.stevesoltys.seedvault.settings.SettingsManager
|
||||
import com.stevesoltys.seedvault.ui.storage.StorageOption
|
||||
import org.calyxos.seedvault.core.backends.BackendFactory
|
||||
import org.calyxos.seedvault.core.backends.saf.SafProperties
|
||||
import java.io.IOException
|
||||
|
||||
private const val TAG = "SafHandler"
|
||||
|
||||
internal class SafHandler(
|
||||
private val context: Context,
|
||||
private val backendFactory: BackendFactory,
|
||||
private val settingsManager: SettingsManager,
|
||||
private val backendManager: BackendManager,
|
||||
) {
|
||||
|
||||
fun onConfigReceived(uri: Uri, safOption: StorageOption.SafOption): SafProperties {
|
||||
// persist permission to access backup folder across reboots
|
||||
val takeFlags = FLAG_GRANT_READ_URI_PERMISSION or FLAG_GRANT_WRITE_URI_PERMISSION
|
||||
context.contentResolver.takePersistableUriPermission(uri, takeFlags)
|
||||
|
||||
return SafProperties(
|
||||
config = uri,
|
||||
name = if (safOption.isInternal()) {
|
||||
val brackets = context.getString(R.string.settings_backup_location_internal)
|
||||
"${safOption.title} ($brackets)"
|
||||
} else {
|
||||
safOption.title
|
||||
},
|
||||
isUsb = safOption.isUsb,
|
||||
requiresNetwork = safOption.requiresNetwork,
|
||||
rootId = safOption.rootId,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches if there's really an app backup available in the given storage location.
|
||||
* Returns true if at least one was found and false otherwise.
|
||||
*/
|
||||
@WorkerThread
|
||||
@Throws(IOException::class)
|
||||
suspend fun hasAppBackup(safProperties: SafProperties): Boolean {
|
||||
val backend = backendFactory.createSafBackend(safProperties)
|
||||
return backend.getAvailableBackupFileHandles().isNotEmpty()
|
||||
}
|
||||
|
||||
fun save(safProperties: SafProperties) {
|
||||
settingsManager.setSafProperties(safProperties)
|
||||
|
||||
if (safProperties.isUsb) {
|
||||
Log.d(TAG, "Selected storage is a removable USB device.")
|
||||
val wasSaved = saveUsbDevice()
|
||||
// reset stored flash drive, if we did not update it
|
||||
if (!wasSaved) settingsManager.setFlashDrive(null)
|
||||
} else {
|
||||
settingsManager.setFlashDrive(null)
|
||||
}
|
||||
Log.d(TAG, "New storage location saved: ${safProperties.uri}")
|
||||
}
|
||||
|
||||
private fun saveUsbDevice(): Boolean {
|
||||
val manager = context.getSystemService(USB_SERVICE) as UsbManager
|
||||
manager.deviceList.values.forEach { device ->
|
||||
if (device.isMassStorage()) {
|
||||
val flashDrive = FlashDrive.from(device)
|
||||
settingsManager.setFlashDrive(flashDrive)
|
||||
Log.d(TAG, "Saved flash drive: $flashDrive")
|
||||
return true
|
||||
}
|
||||
}
|
||||
Log.e(TAG, "No USB device found even though we were expecting one.")
|
||||
return false
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
fun setPlugin(safProperties: SafProperties) {
|
||||
backendManager.changePlugins(
|
||||
backend = backendFactory.createSafBackend(safProperties),
|
||||
storageProperties = safProperties,
|
||||
)
|
||||
}
|
||||
}
|
|
@ -1,97 +0,0 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.backend.webdav
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import androidx.annotation.WorkerThread
|
||||
import com.stevesoltys.seedvault.R
|
||||
import com.stevesoltys.seedvault.backend.BackendManager
|
||||
import com.stevesoltys.seedvault.settings.SettingsManager
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import org.calyxos.seedvault.core.backends.Backend
|
||||
import org.calyxos.seedvault.core.backends.BackendFactory
|
||||
import org.calyxos.seedvault.core.backends.webdav.WebDavConfig
|
||||
import org.calyxos.seedvault.core.backends.webdav.WebDavProperties
|
||||
import java.io.IOException
|
||||
|
||||
internal sealed interface WebDavConfigState {
|
||||
object Empty : WebDavConfigState
|
||||
object Checking : WebDavConfigState
|
||||
class Success(
|
||||
val properties: WebDavProperties,
|
||||
val backend: Backend,
|
||||
) : WebDavConfigState
|
||||
|
||||
class Error(val e: Exception?) : WebDavConfigState
|
||||
}
|
||||
|
||||
private val TAG = WebDavHandler::class.java.simpleName
|
||||
|
||||
internal class WebDavHandler(
|
||||
private val context: Context,
|
||||
private val backendFactory: BackendFactory,
|
||||
private val settingsManager: SettingsManager,
|
||||
private val backendManager: BackendManager,
|
||||
) {
|
||||
|
||||
companion object {
|
||||
fun createWebDavProperties(context: Context, config: WebDavConfig): WebDavProperties {
|
||||
val host = config.url.removePrefix("https://")
|
||||
return WebDavProperties(
|
||||
config = config,
|
||||
name = context.getString(R.string.storage_webdav_name, host),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private val mConfigState = MutableStateFlow<WebDavConfigState>(WebDavConfigState.Empty)
|
||||
val configState = mConfigState.asStateFlow()
|
||||
|
||||
suspend fun onConfigReceived(config: WebDavConfig) {
|
||||
mConfigState.value = WebDavConfigState.Checking
|
||||
val backend = backendFactory.createWebDavBackend(config)
|
||||
try {
|
||||
if (backend.test()) {
|
||||
val properties = createWebDavProperties(context, config)
|
||||
mConfigState.value = WebDavConfigState.Success(properties, backend)
|
||||
} else {
|
||||
mConfigState.value = WebDavConfigState.Error(null)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Error testing WebDAV config at ${config.url}", e)
|
||||
mConfigState.value = WebDavConfigState.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
fun resetConfigState() {
|
||||
mConfigState.value = WebDavConfigState.Empty
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches if there's really an app backup available in the given storage location.
|
||||
* Returns true if at least one was found and false otherwise.
|
||||
*/
|
||||
@WorkerThread
|
||||
@Throws(IOException::class)
|
||||
suspend fun hasAppBackup(backend: Backend): Boolean {
|
||||
return backend.getAvailableBackupFileHandles().isNotEmpty()
|
||||
}
|
||||
|
||||
fun save(properties: WebDavProperties) {
|
||||
settingsManager.saveWebDavConfig(properties.config)
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
fun setPlugin(properties: WebDavProperties, backend: Backend) {
|
||||
backendManager.changePlugins(
|
||||
backend = backend,
|
||||
storageProperties = properties,
|
||||
)
|
||||
}
|
||||
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.backend.webdav
|
||||
|
||||
import org.koin.android.ext.koin.androidContext
|
||||
import org.koin.dsl.module
|
||||
|
||||
val storagePluginModuleWebDav = module {
|
||||
single { WebDavHandler(androidContext(), get(), get(), get()) }
|
||||
}
|
|
@ -1,8 +1,3 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2020 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.crypto
|
||||
|
||||
import java.security.Key
|
||||
|
|
|
@ -1,37 +1,22 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2020 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.crypto
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.provider.Settings
|
||||
import android.provider.Settings.Secure.ANDROID_ID
|
||||
import com.google.crypto.tink.subtle.AesGcmHkdfStreaming
|
||||
import com.stevesoltys.seedvault.encodeBase64
|
||||
import com.stevesoltys.seedvault.header.HeaderReader
|
||||
import com.stevesoltys.seedvault.header.MAX_SEGMENT_LENGTH
|
||||
import com.stevesoltys.seedvault.header.MAX_VERSION_HEADER_SIZE
|
||||
import com.stevesoltys.seedvault.header.SegmentHeader
|
||||
import com.stevesoltys.seedvault.header.VERSION
|
||||
import com.stevesoltys.seedvault.header.VersionHeader
|
||||
import org.calyxos.seedvault.core.crypto.CoreCrypto
|
||||
import org.calyxos.seedvault.core.crypto.CoreCrypto.ALGORITHM_HMAC
|
||||
import org.calyxos.seedvault.core.crypto.CoreCrypto.deriveKey
|
||||
import org.calyxos.seedvault.core.toByteArrayFromHex
|
||||
import org.calyxos.seedvault.core.toHexString
|
||||
import org.calyxos.backup.storage.crypto.StreamCrypto
|
||||
import org.calyxos.backup.storage.crypto.StreamCrypto.deriveStreamKey
|
||||
import java.io.EOFException
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.io.OutputStream
|
||||
import java.nio.ByteBuffer
|
||||
import java.security.GeneralSecurityException
|
||||
import java.security.MessageDigest
|
||||
import java.security.NoSuchAlgorithmException
|
||||
import java.security.SecureRandom
|
||||
import javax.crypto.Mac
|
||||
import javax.crypto.spec.SecretKeySpec
|
||||
|
||||
/**
|
||||
|
@ -57,18 +42,13 @@ internal interface Crypto {
|
|||
*/
|
||||
fun getRandomBytes(size: Int): ByteArray
|
||||
|
||||
/**
|
||||
* Returns the ID of the backup repository as a 64 char hex string.
|
||||
*/
|
||||
val repoId: String
|
||||
fun getNameForPackage(salt: String, packageName: String): String
|
||||
|
||||
/**
|
||||
* A secret key of size [KEY_SIZE_BYTES]
|
||||
* only used to create a gear table specific to each main key.
|
||||
* Returns the name that identifies an APK in the backup storage plugin.
|
||||
* @param suffix empty string for normal APKs and the name of the split in case of an APK split
|
||||
*/
|
||||
val gearTableKey: ByteArray
|
||||
|
||||
fun sha256(bytes: ByteArray): ByteArray
|
||||
fun getNameForApk(salt: String, packageName: String, suffix: String = ""): String
|
||||
|
||||
/**
|
||||
* Returns a [AesGcmHkdfStreaming] encrypting stream
|
||||
|
@ -90,29 +70,6 @@ internal interface Crypto {
|
|||
associatedData: ByteArray,
|
||||
): InputStream
|
||||
|
||||
fun getAdForVersion(version: Byte = VERSION): ByteArray
|
||||
|
||||
@Deprecated("only for v1")
|
||||
fun getNameForPackage(salt: String, packageName: String): String
|
||||
|
||||
/**
|
||||
* Returns the name that identifies an APK in the backup storage plugin.
|
||||
* @param suffix empty string for normal APKs and the name of the split in case of an APK split
|
||||
*/
|
||||
@Deprecated("only for v1")
|
||||
fun getNameForApk(salt: String, packageName: String, suffix: String = ""): String
|
||||
|
||||
/**
|
||||
* Returns a [AesGcmHkdfStreaming] decrypting stream
|
||||
* that gets decrypted and authenticated the given associated data.
|
||||
*/
|
||||
@Deprecated("only for v1")
|
||||
@Throws(IOException::class, GeneralSecurityException::class)
|
||||
fun newDecryptingStreamV1(
|
||||
inputStream: InputStream,
|
||||
associatedData: ByteArray,
|
||||
): InputStream
|
||||
|
||||
/**
|
||||
* Reads and decrypts a [VersionHeader] from the given [InputStream]
|
||||
* and ensures that the expected version, package name and key match
|
||||
|
@ -158,73 +115,31 @@ internal interface Crypto {
|
|||
internal const val TYPE_METADATA: Byte = 0x00
|
||||
internal const val TYPE_BACKUP_KV: Byte = 0x01
|
||||
internal const val TYPE_BACKUP_FULL: Byte = 0x02
|
||||
internal const val TYPE_ICONS: Byte = 0x03
|
||||
|
||||
@SuppressLint("HardwareIds")
|
||||
internal class CryptoImpl(
|
||||
context: Context,
|
||||
private val keyManager: KeyManager,
|
||||
private val cipherFactory: CipherFactory,
|
||||
private val headerReader: HeaderReader,
|
||||
private val androidId: String = Settings.Secure.getString(context.contentResolver, ANDROID_ID),
|
||||
) : Crypto {
|
||||
|
||||
private val keyV1: ByteArray by lazy {
|
||||
deriveKey(keyManager.getMainKey(), "app data key".toByteArray())
|
||||
private val key: ByteArray by lazy {
|
||||
deriveStreamKey(keyManager.getMainKey(), "app data key".toByteArray())
|
||||
}
|
||||
private val streamKey: ByteArray by lazy {
|
||||
deriveKey(keyManager.getMainKey(), "app backup stream key".toByteArray())
|
||||
}
|
||||
private val secureRandom: SecureRandom by lazy { SecureRandom.getInstanceStrong() }
|
||||
private val secureRandom: SecureRandom by lazy { SecureRandom() }
|
||||
|
||||
override fun getRandomBytes(size: Int) = ByteArray(size).apply {
|
||||
secureRandom.nextBytes(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* The ID of the backup repository tied to this user/device via [ANDROID_ID]
|
||||
* and the current [KeyManager.getMainKey].
|
||||
*
|
||||
* Attention: If the main key ever changes, we need to kill our process,
|
||||
* so all lazy values that depend on that key or the [gearTableKey] get reinitialized.
|
||||
*/
|
||||
override val repoId: String by lazy {
|
||||
val repoIdKey =
|
||||
deriveKey(keyManager.getMainKey(), "app backup repoId key".toByteArray())
|
||||
val hmacHasher: Mac = Mac.getInstance(ALGORITHM_HMAC).apply {
|
||||
init(SecretKeySpec(repoIdKey, ALGORITHM_HMAC))
|
||||
}
|
||||
hmacHasher.doFinal(androidId.toByteArrayFromHex()).toHexString()
|
||||
}
|
||||
|
||||
override val gearTableKey: ByteArray
|
||||
get() = deriveKey(keyManager.getMainKey(), "app backup gear table key".toByteArray())
|
||||
|
||||
override fun newEncryptingStream(
|
||||
outputStream: OutputStream,
|
||||
associatedData: ByteArray,
|
||||
): OutputStream = CoreCrypto.newEncryptingStream(streamKey, outputStream, associatedData)
|
||||
|
||||
override fun newDecryptingStream(
|
||||
inputStream: InputStream,
|
||||
associatedData: ByteArray,
|
||||
): InputStream = CoreCrypto.newDecryptingStream(streamKey, inputStream, associatedData)
|
||||
|
||||
override fun getAdForVersion(version: Byte): ByteArray = ByteBuffer.allocate(1)
|
||||
.put(version)
|
||||
.array()
|
||||
|
||||
@Deprecated("only for v1")
|
||||
override fun getNameForPackage(salt: String, packageName: String): String {
|
||||
return sha256("$salt$packageName".toByteArray()).encodeBase64()
|
||||
}
|
||||
|
||||
@Deprecated("only for v1")
|
||||
override fun getNameForApk(salt: String, packageName: String, suffix: String): String {
|
||||
return sha256("${salt}APK$packageName$suffix".toByteArray()).encodeBase64()
|
||||
}
|
||||
|
||||
override fun sha256(bytes: ByteArray): ByteArray {
|
||||
private fun sha256(bytes: ByteArray): ByteArray {
|
||||
val messageDigest: MessageDigest = try {
|
||||
MessageDigest.getInstance("SHA-256")
|
||||
} catch (e: NoSuchAlgorithmException) {
|
||||
|
@ -234,12 +149,21 @@ internal class CryptoImpl(
|
|||
return messageDigest.digest()
|
||||
}
|
||||
|
||||
@Deprecated("only for v1")
|
||||
@Throws(IOException::class, GeneralSecurityException::class)
|
||||
override fun newDecryptingStreamV1(
|
||||
override fun newEncryptingStream(
|
||||
outputStream: OutputStream,
|
||||
associatedData: ByteArray,
|
||||
): OutputStream {
|
||||
return StreamCrypto.newEncryptingStream(key, outputStream, associatedData)
|
||||
}
|
||||
|
||||
@Throws(IOException::class, GeneralSecurityException::class)
|
||||
override fun newDecryptingStream(
|
||||
inputStream: InputStream,
|
||||
associatedData: ByteArray,
|
||||
): InputStream = CoreCrypto.newDecryptingStream(keyV1, inputStream, associatedData)
|
||||
): InputStream {
|
||||
return StreamCrypto.newDecryptingStream(key, inputStream, associatedData)
|
||||
}
|
||||
|
||||
@Suppress("Deprecation")
|
||||
@Throws(IOException::class, SecurityException::class)
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2020 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.crypto
|
||||
|
||||
import org.koin.android.ext.koin.androidContext
|
||||
import org.koin.dsl.module
|
||||
import java.security.KeyStore
|
||||
|
||||
|
@ -21,5 +15,5 @@ val cryptoModule = module {
|
|||
}
|
||||
KeyManagerImpl(keyStore)
|
||||
}
|
||||
single<Crypto> { CryptoImpl(androidContext(), get(), get(), get()) }
|
||||
single<Crypto> { CryptoImpl(get(), get(), get()) }
|
||||
}
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2020 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.crypto
|
||||
|
||||
import android.security.keystore.KeyProperties.BLOCK_MODE_GCM
|
||||
|
@ -24,7 +19,7 @@ internal const val KEY_ALIAS_MAIN = "com.stevesoltys.seedvault.main"
|
|||
private const val KEY_ALGORITHM_BACKUP = "AES"
|
||||
private const val KEY_ALGORITHM_MAIN = "HmacSHA256"
|
||||
|
||||
interface KeyManager : org.calyxos.seedvault.core.crypto.KeyManager {
|
||||
interface KeyManager {
|
||||
/**
|
||||
* Store a new backup key derived from the given [seed].
|
||||
*
|
||||
|
@ -57,6 +52,14 @@ interface KeyManager : org.calyxos.seedvault.core.crypto.KeyManager {
|
|||
* because the key can not leave the [KeyStore]'s hardware security module.
|
||||
*/
|
||||
fun getBackupKey(): SecretKey
|
||||
|
||||
/**
|
||||
* Returns the main key, so it can be used for deriving sub-keys.
|
||||
*
|
||||
* Note that any attempt to export the key will return null or an empty [ByteArray],
|
||||
* because the key can not leave the [KeyStore]'s hardware security module.
|
||||
*/
|
||||
fun getMainKey(): SecretKey
|
||||
}
|
||||
|
||||
internal class KeyManagerImpl(
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2020 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.header
|
||||
|
||||
import com.stevesoltys.seedvault.crypto.GCM_AUTHENTICATION_TAG_LENGTH
|
||||
|
@ -10,7 +5,7 @@ import com.stevesoltys.seedvault.crypto.TYPE_BACKUP_FULL
|
|||
import com.stevesoltys.seedvault.crypto.TYPE_BACKUP_KV
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
internal const val VERSION: Byte = 2
|
||||
internal const val VERSION: Byte = 1
|
||||
internal const val MAX_PACKAGE_LENGTH_SIZE = 255
|
||||
internal const val MAX_KEY_LENGTH_SIZE = MAX_PACKAGE_LENGTH_SIZE
|
||||
internal const val MAX_VERSION_HEADER_SIZE =
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2020 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.header
|
||||
|
||||
import org.koin.dsl.module
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2020 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.header
|
||||
|
||||
import com.stevesoltys.seedvault.Utf8
|
||||
|
|
|
@ -1,19 +1,10 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2020 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.metadata
|
||||
|
||||
import android.content.pm.ApplicationInfo.FLAG_STOPPED
|
||||
import android.os.Build
|
||||
import com.stevesoltys.seedvault.crypto.TYPE_METADATA
|
||||
import com.stevesoltys.seedvault.encodeBase64
|
||||
import com.stevesoltys.seedvault.header.VERSION
|
||||
import com.stevesoltys.seedvault.metadata.PackageState.UNKNOWN_ERROR
|
||||
import com.stevesoltys.seedvault.proto.Snapshot
|
||||
import com.stevesoltys.seedvault.repo.hexFromProto
|
||||
import com.stevesoltys.seedvault.worker.BASE_SPLIT
|
||||
import org.calyxos.backup.storage.crypto.StreamCrypto.toByteArray
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
|
@ -27,31 +18,8 @@ data class BackupMetadata(
|
|||
internal val androidVersion: Int = Build.VERSION.SDK_INT,
|
||||
internal val androidIncremental: String = Build.VERSION.INCREMENTAL,
|
||||
internal val deviceName: String = "${Build.MANUFACTURER} ${Build.MODEL}",
|
||||
internal var d2dBackup: Boolean = false,
|
||||
internal val packageMetadataMap: PackageMetadataMap = PackageMetadataMap(),
|
||||
) {
|
||||
|
||||
companion object {
|
||||
fun fromSnapshot(s: Snapshot) = BackupMetadata(
|
||||
version = s.version.toByte(),
|
||||
token = s.token,
|
||||
salt = "",
|
||||
time = s.token,
|
||||
androidVersion = s.sdkInt,
|
||||
androidIncremental = s.androidIncremental,
|
||||
deviceName = "${s.name} - ${s.user}",
|
||||
d2dBackup = s.d2D,
|
||||
packageMetadataMap = s.appsMap.mapValues { (_, app) ->
|
||||
PackageMetadata.fromSnapshot(app)
|
||||
} as PackageMetadataMap
|
||||
)
|
||||
}
|
||||
|
||||
val size: Long
|
||||
get() = packageMetadataMap.values.sumOf { m ->
|
||||
(m.size ?: 0L) + (m.splits?.sumOf { it.size ?: 0L } ?: 0L)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
internal const val JSON_METADATA = "@meta@"
|
||||
internal const val JSON_METADATA_VERSION = "version"
|
||||
|
@ -61,7 +29,6 @@ internal const val JSON_METADATA_TIME = "time"
|
|||
internal const val JSON_METADATA_SDK_INT = "sdk_int"
|
||||
internal const val JSON_METADATA_INCREMENTAL = "incremental"
|
||||
internal const val JSON_METADATA_NAME = "name"
|
||||
internal const val JSON_METADATA_D2D_BACKUP = "d2d_backup"
|
||||
|
||||
enum class PackageState {
|
||||
/**
|
||||
|
@ -105,71 +72,21 @@ data class PackageMetadata(
|
|||
internal var time: Long = 0L,
|
||||
internal var state: PackageState = UNKNOWN_ERROR,
|
||||
internal var backupType: BackupType? = null,
|
||||
internal var size: Long? = null,
|
||||
internal var name: CharSequence? = null,
|
||||
internal val system: Boolean = false,
|
||||
internal val isLaunchableSystemApp: Boolean = false,
|
||||
internal val version: Long? = null,
|
||||
internal val installer: String? = null,
|
||||
internal val splits: List<ApkSplit>? = null,
|
||||
internal val baseApkChunkIds: List<String>? = null, // used for v2
|
||||
internal val chunkIds: List<String>? = null, // used for v2
|
||||
internal val sha256: String? = null,
|
||||
internal val signatures: List<String>? = null,
|
||||
) {
|
||||
|
||||
companion object {
|
||||
fun fromSnapshot(app: Snapshot.App) = PackageMetadata(
|
||||
time = app.time,
|
||||
backupType = app.type.toBackupType(),
|
||||
name = app.name,
|
||||
chunkIds = app.chunkIdsList.hexFromProto(),
|
||||
system = app.system,
|
||||
isLaunchableSystemApp = app.launchableSystemApp,
|
||||
version = app.apk.versionCode,
|
||||
installer = app.apk.installer.takeIf { it.isNotEmpty() },
|
||||
baseApkChunkIds = run {
|
||||
val baseChunk = app.apk.splitsList.find { it.name == BASE_SPLIT }
|
||||
if (baseChunk == null || baseChunk.chunkIdsCount == 0) {
|
||||
null
|
||||
} else {
|
||||
baseChunk.chunkIdsList.hexFromProto()
|
||||
}
|
||||
},
|
||||
splits = app.apk.splitsList.filter { it.name != BASE_SPLIT }.map {
|
||||
ApkSplit(
|
||||
name = it.name,
|
||||
size = null,
|
||||
sha256 = "",
|
||||
chunkIds = if (it.chunkIdsCount == 0) null else it.chunkIdsList.hexFromProto()
|
||||
)
|
||||
}.takeIf { it.isNotEmpty() }, // expected null if there are no splits
|
||||
sha256 = null,
|
||||
signatures = app.apk.signaturesList.map { it.toByteArray().encodeBase64() }.takeIf {
|
||||
it.isNotEmpty()
|
||||
},
|
||||
)
|
||||
|
||||
fun Snapshot.BackupType.toBackupType() = when (this) {
|
||||
Snapshot.BackupType.FULL -> BackupType.FULL
|
||||
Snapshot.BackupType.KV -> BackupType.KV
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
val isInternalSystem: Boolean = system && !isLaunchableSystemApp
|
||||
fun hasApk(): Boolean {
|
||||
return version != null && // v2 doesn't use sha256 here
|
||||
(sha256 != null || baseApkChunkIds?.isNotEmpty() == true) &&
|
||||
signatures != null
|
||||
return version != null && sha256 != null && signatures != null
|
||||
}
|
||||
}
|
||||
|
||||
data class ApkSplit(
|
||||
val name: String,
|
||||
val size: Long?,
|
||||
val sha256: String,
|
||||
val chunkIds: List<String>? = null, // used for v2
|
||||
// There's also a revisionCode, but it doesn't seem to be used just yet
|
||||
)
|
||||
|
||||
|
@ -178,10 +95,7 @@ enum class BackupType { KV, FULL }
|
|||
internal const val JSON_PACKAGE_TIME = "time"
|
||||
internal const val JSON_PACKAGE_BACKUP_TYPE = "backupType"
|
||||
internal const val JSON_PACKAGE_STATE = "state"
|
||||
internal const val JSON_PACKAGE_SIZE = "size"
|
||||
internal const val JSON_PACKAGE_APP_NAME = "name"
|
||||
internal const val JSON_PACKAGE_SYSTEM = "system"
|
||||
internal const val JSON_PACKAGE_SYSTEM_LAUNCHER = "systemLauncher"
|
||||
internal const val JSON_PACKAGE_VERSION = "version"
|
||||
internal const val JSON_PACKAGE_INSTALLER = "installer"
|
||||
internal const val JSON_PACKAGE_SPLITS = "splits"
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2020 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.metadata
|
||||
|
||||
import android.content.Context
|
||||
|
@ -11,8 +6,18 @@ import android.content.pm.PackageInfo
|
|||
import android.util.Log
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import androidx.annotation.WorkerThread
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.distinctUntilChanged
|
||||
import com.stevesoltys.seedvault.Clock
|
||||
import com.stevesoltys.seedvault.crypto.Crypto
|
||||
import com.stevesoltys.seedvault.encodeBase64
|
||||
import com.stevesoltys.seedvault.header.VERSION
|
||||
import com.stevesoltys.seedvault.metadata.PackageState.APK_AND_DATA
|
||||
import com.stevesoltys.seedvault.metadata.PackageState.NOT_ALLOWED
|
||||
import com.stevesoltys.seedvault.metadata.PackageState.NO_DATA
|
||||
import com.stevesoltys.seedvault.metadata.PackageState.WAS_STOPPED
|
||||
import com.stevesoltys.seedvault.transport.backup.isSystemApp
|
||||
import java.io.FileNotFoundException
|
||||
import java.io.IOException
|
||||
import java.io.OutputStream
|
||||
|
@ -27,57 +32,120 @@ internal const val METADATA_SALT_SIZE = 32
|
|||
internal class MetadataManager(
|
||||
private val context: Context,
|
||||
private val clock: Clock,
|
||||
private val crypto: Crypto,
|
||||
private val metadataWriter: MetadataWriter,
|
||||
private val metadataReader: MetadataReader,
|
||||
) {
|
||||
|
||||
private val uninitializedMetadata = BackupMetadata(token = -42L, salt = "foo bar")
|
||||
private val uninitializedMetadata = BackupMetadata(token = 0L, salt = "")
|
||||
private var metadata: BackupMetadata = uninitializedMetadata
|
||||
get() {
|
||||
if (field == uninitializedMetadata) {
|
||||
field = try {
|
||||
val m = getMetadataFromCache() ?: throw IOException()
|
||||
if (m == uninitializedMetadata) m.copy(salt = "initialized")
|
||||
else m
|
||||
getMetadataFromCache() ?: throw IOException()
|
||||
} catch (e: IOException) {
|
||||
// This can happen if the storage location ran out of space
|
||||
// or the app process got killed while writing the file.
|
||||
// It is hard to recover from this, so we try as best as we can here:
|
||||
Log.e(TAG, "ERROR getting metadata cache, creating new file ", e)
|
||||
uninitializedMetadata.copy(salt = "initialized")
|
||||
// If this happens, it is hard to recover from this. Let's hope it never does.
|
||||
throw AssertionError("Error reading metadata from cache", e)
|
||||
}
|
||||
mLastBackupTime.postValue(field.time)
|
||||
}
|
||||
return field
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this when initializing a new device.
|
||||
*
|
||||
* Existing [BackupMetadata] will be cleared, use the given new token,
|
||||
* and written encrypted to the given [OutputStream] as well as the internal cache.
|
||||
*/
|
||||
@Synchronized
|
||||
@Throws(IOException::class)
|
||||
fun onDeviceInitialization(token: Long, metadataOutputStream: OutputStream) {
|
||||
val salt = crypto.getRandomBytes(METADATA_SALT_SIZE).encodeBase64()
|
||||
modifyMetadata(metadataOutputStream) {
|
||||
metadata = BackupMetadata(token = token, salt = salt)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this after a package's APK has been backed up successfully.
|
||||
*
|
||||
* It updates the packages' metadata
|
||||
* and writes it encrypted to the given [OutputStream] as well as the internal cache.
|
||||
*
|
||||
* Closing the [OutputStream] is the responsibility of the caller.
|
||||
*/
|
||||
@Synchronized
|
||||
@Throws(IOException::class)
|
||||
fun onApkBackedUp(
|
||||
packageInfo: PackageInfo,
|
||||
packageMetadata: PackageMetadata,
|
||||
metadataOutputStream: OutputStream,
|
||||
) {
|
||||
val packageName = packageInfo.packageName
|
||||
metadata.packageMetadataMap[packageName]?.let {
|
||||
check(packageMetadata.version != null) {
|
||||
"APK backup returned version null"
|
||||
}
|
||||
check(it.version == null || it.version < packageMetadata.version) {
|
||||
"APK backup backed up the same or a smaller version:" +
|
||||
"was ${it.version} is ${packageMetadata.version}"
|
||||
}
|
||||
}
|
||||
val oldPackageMetadata = metadata.packageMetadataMap[packageName]
|
||||
?: PackageMetadata()
|
||||
// only allow state change if backup of this package is not allowed,
|
||||
// because we need to change from the default of UNKNOWN_ERROR here,
|
||||
// but otherwise don't want to modify the state since set elsewhere.
|
||||
val newState =
|
||||
if (packageMetadata.state == NOT_ALLOWED || packageMetadata.state == WAS_STOPPED) {
|
||||
packageMetadata.state
|
||||
} else {
|
||||
oldPackageMetadata.state
|
||||
}
|
||||
modifyMetadata(metadataOutputStream) {
|
||||
metadata.packageMetadataMap[packageName] = oldPackageMetadata.copy(
|
||||
state = newState,
|
||||
system = packageInfo.isSystemApp(),
|
||||
version = packageMetadata.version,
|
||||
installer = packageMetadata.installer,
|
||||
splits = packageMetadata.splits,
|
||||
sha256 = packageMetadata.sha256,
|
||||
signatures = packageMetadata.signatures
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this after a package has been backed up successfully.
|
||||
*
|
||||
* It updates the packages' metadata.
|
||||
* It updates the packages' metadata
|
||||
* and writes it encrypted to the given [OutputStream] as well as the internal cache.
|
||||
*
|
||||
* Closing the [OutputStream] is the responsibility of the caller.
|
||||
*/
|
||||
@Synchronized
|
||||
@Throws(IOException::class)
|
||||
fun onPackageBackedUp(
|
||||
packageInfo: PackageInfo,
|
||||
type: BackupType?,
|
||||
size: Long?,
|
||||
type: BackupType,
|
||||
metadataOutputStream: OutputStream,
|
||||
) {
|
||||
val packageName = packageInfo.packageName
|
||||
modifyCachedMetadata {
|
||||
modifyMetadata(metadataOutputStream) {
|
||||
val now = clock.time()
|
||||
metadata.packageMetadataMap.getOrPut(packageName) {
|
||||
PackageMetadata(
|
||||
metadata.time = now
|
||||
if (metadata.packageMetadataMap.containsKey(packageName)) {
|
||||
metadata.packageMetadataMap[packageName]!!.time = now
|
||||
metadata.packageMetadataMap[packageName]!!.state = APK_AND_DATA
|
||||
metadata.packageMetadataMap[packageName]!!.backupType = type
|
||||
} else {
|
||||
metadata.packageMetadataMap[packageName] = PackageMetadata(
|
||||
time = now,
|
||||
state = APK_AND_DATA,
|
||||
backupType = type,
|
||||
size = size,
|
||||
system = packageInfo.isSystemApp()
|
||||
)
|
||||
}.apply {
|
||||
time = now
|
||||
state = APK_AND_DATA
|
||||
backupType = type
|
||||
// don't override a previous K/V size, if there were no K/V changes
|
||||
if (size != null) this.size = size
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -93,60 +161,31 @@ internal class MetadataManager(
|
|||
internal fun onPackageBackupError(
|
||||
packageInfo: PackageInfo,
|
||||
packageState: PackageState,
|
||||
metadataOutputStream: OutputStream,
|
||||
backupType: BackupType? = null,
|
||||
) {
|
||||
check(packageState != APK_AND_DATA) { "Backup Error with non-error package state." }
|
||||
modifyCachedMetadata {
|
||||
metadata.packageMetadataMap.getOrPut(packageInfo.packageName) {
|
||||
PackageMetadata(
|
||||
val packageName = packageInfo.packageName
|
||||
modifyMetadata(metadataOutputStream) {
|
||||
if (metadata.packageMetadataMap.containsKey(packageName)) {
|
||||
metadata.packageMetadataMap[packageName]!!.state = packageState
|
||||
} else {
|
||||
metadata.packageMetadataMap[packageName] = PackageMetadata(
|
||||
time = 0L,
|
||||
state = packageState,
|
||||
backupType = backupType,
|
||||
name = packageInfo.applicationInfo?.loadLabel(context.packageManager),
|
||||
system = packageInfo.isSystemApp()
|
||||
)
|
||||
}.state = packageState
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this for all packages we can not back up for some reason.
|
||||
*
|
||||
* It updates the packages' local metadata.
|
||||
*/
|
||||
@Synchronized
|
||||
@Throws(IOException::class)
|
||||
internal fun onPackageDoesNotGetBackedUp(
|
||||
packageInfo: PackageInfo,
|
||||
packageState: PackageState,
|
||||
) = modifyCachedMetadata {
|
||||
metadata.packageMetadataMap.getOrPut(packageInfo.packageName) {
|
||||
PackageMetadata(
|
||||
time = 0L,
|
||||
state = packageState,
|
||||
name = packageInfo.applicationInfo?.loadLabel(context.packageManager),
|
||||
)
|
||||
}.apply {
|
||||
state = packageState
|
||||
// update name, if none was set, yet (can happen while migrating to storing names)
|
||||
if (this.name == null) {
|
||||
this.name = packageInfo.applicationInfo?.loadLabel(context.packageManager)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun getPackageMetadata(packageName: String): PackageMetadata? {
|
||||
return metadata.packageMetadataMap[packageName]?.copy()
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
private fun modifyCachedMetadata(modFun: () -> Unit) {
|
||||
val oldMetadata = metadata.copy(
|
||||
// copy map, otherwise it will re-use same reference
|
||||
packageMetadataMap = PackageMetadataMap(metadata.packageMetadataMap),
|
||||
)
|
||||
private fun modifyMetadata(metadataOutputStream: OutputStream, modFun: () -> Unit) {
|
||||
val oldMetadata = metadata.copy()
|
||||
try {
|
||||
modFun.invoke()
|
||||
metadataWriter.write(metadata, metadataOutputStream)
|
||||
writeMetadataToCache()
|
||||
} catch (e: IOException) {
|
||||
Log.w(TAG, "Error writing metadata to storage", e)
|
||||
|
@ -154,6 +193,53 @@ internal class MetadataManager(
|
|||
metadata = oldMetadata
|
||||
throw IOException(e)
|
||||
}
|
||||
mLastBackupTime.postValue(metadata.time)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current backup token.
|
||||
*
|
||||
* If the token is 0L, it is not yet initialized and must not be used for anything.
|
||||
*/
|
||||
@Synchronized
|
||||
@Deprecated(
|
||||
"Responsibility for current token moved to SettingsManager",
|
||||
ReplaceWith("settingsManager.getToken()")
|
||||
)
|
||||
fun getBackupToken(): Long = metadata.token
|
||||
|
||||
/**
|
||||
* Returns the last backup time in unix epoch milli seconds.
|
||||
*
|
||||
* Note that this might be a blocking I/O call.
|
||||
*/
|
||||
@Synchronized
|
||||
fun getLastBackupTime(): Long = mLastBackupTime.value ?: metadata.time
|
||||
|
||||
private val mLastBackupTime = MutableLiveData<Long>()
|
||||
internal val lastBackupTime: LiveData<Long> = mLastBackupTime.distinctUntilChanged()
|
||||
|
||||
internal val salt: String
|
||||
@Synchronized get() = metadata.salt
|
||||
|
||||
internal val requiresInit: Boolean
|
||||
@Synchronized get() = metadata == uninitializedMetadata || metadata.version < VERSION
|
||||
|
||||
@Synchronized
|
||||
fun getPackageMetadata(packageName: String): PackageMetadata? {
|
||||
return metadata.packageMetadataMap[packageName]?.copy()
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun getPackagesNumBackedUp(): Int {
|
||||
// FIXME we are under-reporting packages here,
|
||||
// because we have no way to also include upgraded system apps
|
||||
return metadata.packageMetadataMap.filter { (_, packageMetadata) ->
|
||||
!packageMetadata.system && ( // ignore system apps
|
||||
packageMetadata.state == APK_AND_DATA || // either full success
|
||||
packageMetadata.state == NO_DATA // or apps that simply had no data
|
||||
)
|
||||
}.count()
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
|
|
|
@ -1,15 +1,10 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2020 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.metadata
|
||||
|
||||
import org.koin.android.ext.koin.androidContext
|
||||
import org.koin.dsl.module
|
||||
|
||||
val metadataModule = module {
|
||||
single { MetadataManager(androidContext(), get(), get(), get()) }
|
||||
single<MetadataWriter> { MetadataWriterImpl() }
|
||||
single { MetadataManager(androidContext(), get(), get(), get(), get()) }
|
||||
single<MetadataWriter> { MetadataWriterImpl(get()) }
|
||||
single<MetadataReader> { MetadataReaderImpl(get()) }
|
||||
}
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2020 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.metadata
|
||||
|
||||
import com.stevesoltys.seedvault.Utf8
|
||||
|
@ -56,7 +51,7 @@ internal class MetadataReaderImpl(private val crypto: Crypto) : MetadataReader {
|
|||
if (version == 0.toByte()) return readMetadataV0(inputStream, expectedToken)
|
||||
|
||||
val metadataBytes = try {
|
||||
crypto.newDecryptingStreamV1(inputStream, getAD(version, expectedToken)).readBytes()
|
||||
crypto.newDecryptingStream(inputStream, getAD(version, expectedToken)).readBytes()
|
||||
} catch (e: GeneralSecurityException) {
|
||||
throw DecryptionFailedException(e)
|
||||
}
|
||||
|
@ -94,14 +89,14 @@ internal class MetadataReaderImpl(private val crypto: Crypto) : MetadataReader {
|
|||
val json = JSONObject(bytes.toString(Utf8))
|
||||
// get backup metadata and check expectations
|
||||
val meta = json.getJSONObject(JSON_METADATA)
|
||||
val version = meta.optInt(JSON_METADATA_VERSION, VERSION.toInt()).toByte()
|
||||
val version = meta.getInt(JSON_METADATA_VERSION).toByte()
|
||||
if (expectedVersion != null && version != expectedVersion) {
|
||||
throw SecurityException(
|
||||
"Invalid version '${version.toInt()}' in metadata," +
|
||||
"expected '${expectedVersion.toInt()}'."
|
||||
)
|
||||
}
|
||||
val token = meta.optLong(JSON_METADATA_TOKEN, 0)
|
||||
val token = meta.getLong(JSON_METADATA_TOKEN)
|
||||
if (expectedToken != null && token != expectedToken) throw SecurityException(
|
||||
"Invalid token '$token' in metadata, expected '$expectedToken'."
|
||||
)
|
||||
|
@ -125,8 +120,6 @@ internal class MetadataReaderImpl(private val crypto: Crypto) : MetadataReader {
|
|||
// because when only backing up the APK for example, there's no type
|
||||
else -> null
|
||||
}
|
||||
val pSize = p.optLong(JSON_PACKAGE_SIZE, -1L)
|
||||
val pName = p.optString(JSON_PACKAGE_APP_NAME)
|
||||
val pSystem = p.optBoolean(JSON_PACKAGE_SYSTEM, false)
|
||||
val pVersion = p.optLong(JSON_PACKAGE_VERSION, 0L)
|
||||
val pInstaller = p.optString(JSON_PACKAGE_INSTALLER)
|
||||
|
@ -143,10 +136,7 @@ internal class MetadataReaderImpl(private val crypto: Crypto) : MetadataReader {
|
|||
time = p.getLong(JSON_PACKAGE_TIME),
|
||||
state = pState,
|
||||
backupType = pBackupType,
|
||||
size = if (pSize < 0L) null else pSize,
|
||||
name = if (pName == "") null else pName,
|
||||
system = pSystem,
|
||||
isLaunchableSystemApp = p.optBoolean(JSON_PACKAGE_SYSTEM_LAUNCHER, false),
|
||||
version = if (pVersion == 0L) null else pVersion,
|
||||
installer = if (pInstaller == "") null else pInstaller,
|
||||
splits = getSplits(p),
|
||||
|
@ -157,13 +147,12 @@ internal class MetadataReaderImpl(private val crypto: Crypto) : MetadataReader {
|
|||
return BackupMetadata(
|
||||
version = version,
|
||||
token = token,
|
||||
salt = if (version == 0.toByte()) "" else meta.optString(JSON_METADATA_SALT, ""),
|
||||
time = meta.optLong(JSON_METADATA_TIME, -1),
|
||||
androidVersion = meta.optInt(JSON_METADATA_SDK_INT, 0),
|
||||
androidIncremental = meta.optString(JSON_METADATA_INCREMENTAL),
|
||||
deviceName = meta.optString(JSON_METADATA_NAME),
|
||||
d2dBackup = meta.optBoolean(JSON_METADATA_D2D_BACKUP, false),
|
||||
packageMetadataMap = packageMetadataMap,
|
||||
salt = if (version == 0.toByte()) "" else meta.getString(JSON_METADATA_SALT),
|
||||
time = meta.getLong(JSON_METADATA_TIME),
|
||||
androidVersion = meta.getInt(JSON_METADATA_SDK_INT),
|
||||
androidIncremental = meta.getString(JSON_METADATA_INCREMENTAL),
|
||||
deviceName = meta.getString(JSON_METADATA_NAME),
|
||||
packageMetadataMap = packageMetadataMap
|
||||
)
|
||||
} catch (e: JSONException) {
|
||||
throw SecurityException(e)
|
||||
|
@ -177,9 +166,6 @@ internal class MetadataReaderImpl(private val crypto: Crypto) : MetadataReader {
|
|||
val jsonApkSplit = jsonSplits.getJSONObject(i)
|
||||
val apkSplit = ApkSplit(
|
||||
name = jsonApkSplit.getString(JSON_PACKAGE_SPLIT_NAME),
|
||||
size = jsonApkSplit.optLong(JSON_PACKAGE_SIZE, -1L).let {
|
||||
if (it < 0L) null else it
|
||||
},
|
||||
sha256 = jsonApkSplit.getString(JSON_PACKAGE_SHA256)
|
||||
)
|
||||
splits.add(apkSplit)
|
||||
|
|
|
@ -1,23 +1,41 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2020 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.metadata
|
||||
|
||||
import com.stevesoltys.seedvault.Utf8
|
||||
import com.stevesoltys.seedvault.crypto.Crypto
|
||||
import com.stevesoltys.seedvault.metadata.PackageState.APK_AND_DATA
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import java.io.IOException
|
||||
import java.io.OutputStream
|
||||
|
||||
interface MetadataWriter {
|
||||
@Throws(IOException::class)
|
||||
fun write(metadata: BackupMetadata, outputStream: OutputStream)
|
||||
|
||||
fun encode(metadata: BackupMetadata): ByteArray
|
||||
}
|
||||
|
||||
internal class MetadataWriterImpl : MetadataWriter {
|
||||
internal class MetadataWriterImpl(private val crypto: Crypto) : MetadataWriter {
|
||||
|
||||
@Throws(IOException::class)
|
||||
override fun write(metadata: BackupMetadata, outputStream: OutputStream) {
|
||||
outputStream.write(ByteArray(1).apply { this[0] = metadata.version })
|
||||
crypto.newEncryptingStream(outputStream, getAD(metadata.version, metadata.token)).use {
|
||||
it.write(encode(metadata))
|
||||
}
|
||||
}
|
||||
|
||||
override fun encode(metadata: BackupMetadata): ByteArray {
|
||||
val json = JSONObject().apply {
|
||||
put(JSON_METADATA, JSONObject())
|
||||
put(JSON_METADATA, JSONObject().apply {
|
||||
put(JSON_METADATA_VERSION, metadata.version.toInt())
|
||||
put(JSON_METADATA_TOKEN, metadata.token)
|
||||
put(JSON_METADATA_SALT, metadata.salt)
|
||||
put(JSON_METADATA_TIME, metadata.time)
|
||||
put(JSON_METADATA_SDK_INT, metadata.androidVersion)
|
||||
put(JSON_METADATA_INCREMENTAL, metadata.androidIncremental)
|
||||
put(JSON_METADATA_NAME, metadata.deviceName)
|
||||
})
|
||||
}
|
||||
for ((packageName, packageMetadata) in metadata.packageMetadataMap) {
|
||||
json.put(packageName, JSONObject().apply {
|
||||
|
@ -30,11 +48,24 @@ internal class MetadataWriterImpl : MetadataWriter {
|
|||
if (packageMetadata.backupType != null) {
|
||||
put(JSON_PACKAGE_BACKUP_TYPE, packageMetadata.backupType!!.name)
|
||||
}
|
||||
if (packageMetadata.size != null) {
|
||||
put(JSON_PACKAGE_SIZE, packageMetadata.size)
|
||||
if (packageMetadata.system) {
|
||||
put(JSON_PACKAGE_SYSTEM, packageMetadata.system)
|
||||
}
|
||||
packageMetadata.version?.let { put(JSON_PACKAGE_VERSION, it) }
|
||||
packageMetadata.installer?.let { put(JSON_PACKAGE_INSTALLER, it) }
|
||||
packageMetadata.splits?.let { splits ->
|
||||
put(JSON_PACKAGE_SPLITS, JSONArray().apply {
|
||||
for (split in splits) put(JSONObject().apply {
|
||||
put(JSON_PACKAGE_SPLIT_NAME, split.name)
|
||||
put(JSON_PACKAGE_SHA256, split.sha256)
|
||||
})
|
||||
})
|
||||
}
|
||||
packageMetadata.sha256?.let { put(JSON_PACKAGE_SHA256, it) }
|
||||
packageMetadata.signatures?.let { put(JSON_PACKAGE_SIGNATURES, JSONArray(it)) }
|
||||
})
|
||||
}
|
||||
return json.toString().toByteArray(Utf8)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2020 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.backend
|
||||
package com.stevesoltys.seedvault.plugins
|
||||
|
||||
import android.content.pm.PackageInfo
|
||||
import java.io.IOException
|
|
@ -0,0 +1,78 @@
|
|||
package com.stevesoltys.seedvault.plugins
|
||||
|
||||
import android.app.backup.RestoreSet
|
||||
import androidx.annotation.WorkerThread
|
||||
import com.stevesoltys.seedvault.settings.Storage
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.io.OutputStream
|
||||
|
||||
interface StoragePlugin {
|
||||
|
||||
/**
|
||||
* Start a new [RestoreSet] with the given token.
|
||||
*
|
||||
* This is typically followed by a call to [initializeDevice].
|
||||
*/
|
||||
@Throws(IOException::class)
|
||||
suspend fun startNewRestoreSet(token: Long)
|
||||
|
||||
/**
|
||||
* Initialize the storage for this device, erasing all stored data in the current [RestoreSet].
|
||||
*/
|
||||
@Throws(IOException::class)
|
||||
suspend fun initializeDevice()
|
||||
|
||||
/**
|
||||
* Return true if there is data stored for the given name.
|
||||
*/
|
||||
@Throws(IOException::class)
|
||||
suspend fun hasData(token: Long, name: String): Boolean
|
||||
|
||||
/**
|
||||
* Return a raw byte stream for writing data for the given name.
|
||||
*/
|
||||
@Throws(IOException::class)
|
||||
suspend fun getOutputStream(token: Long, name: String): OutputStream
|
||||
|
||||
/**
|
||||
* Return a raw byte stream with data for the given name.
|
||||
*/
|
||||
@Throws(IOException::class)
|
||||
suspend fun getInputStream(token: Long, name: String): InputStream
|
||||
|
||||
/**
|
||||
* Remove all data associated with the given name.
|
||||
*/
|
||||
@Throws(IOException::class)
|
||||
suspend fun removeData(token: Long, name: String)
|
||||
|
||||
/**
|
||||
* Searches if there's really a backup available in the given storage location.
|
||||
* Returns true if at least one was found and false otherwise.
|
||||
*/
|
||||
@WorkerThread
|
||||
@Throws(IOException::class)
|
||||
suspend fun hasBackup(storage: Storage): Boolean
|
||||
|
||||
/**
|
||||
* Get the set of all backups currently available for restore.
|
||||
*
|
||||
* @return metadata for the set of restore images available,
|
||||
* or null if an error occurred (the attempt should be rescheduled).
|
||||
**/
|
||||
suspend fun getAvailableBackups(): Sequence<EncryptedMetadata>?
|
||||
|
||||
/**
|
||||
* Returns the package name of the app that provides the backend storage
|
||||
* which is used for the current backup location.
|
||||
*
|
||||
* Plugins are advised to cache this as it will be requested frequently.
|
||||
*
|
||||
* @return null if no package name could be found
|
||||
*/
|
||||
val providerPackageName: String?
|
||||
|
||||
}
|
||||
|
||||
class EncryptedMetadata(val token: Long, val inputStreamRetriever: () -> InputStream)
|
|
@ -1,27 +1,21 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2020 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.backend.saf
|
||||
package com.stevesoltys.seedvault.plugins.saf
|
||||
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageInfo
|
||||
import androidx.annotation.WorkerThread
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import com.stevesoltys.seedvault.backend.LegacyStoragePlugin
|
||||
import com.stevesoltys.seedvault.plugins.LegacyStoragePlugin
|
||||
import java.io.FileNotFoundException
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
|
||||
@WorkerThread
|
||||
@Suppress("Deprecation")
|
||||
@Suppress("BlockingMethodInNonBlockingContext", "Deprecation") // all methods do I/O
|
||||
internal class DocumentsProviderLegacyPlugin(
|
||||
private val context: Context,
|
||||
private val storageGetter: () -> DocumentsStorage,
|
||||
private val storage: DocumentsStorage,
|
||||
) : LegacyStoragePlugin {
|
||||
|
||||
private val storage get() = storageGetter()
|
||||
private var packageDir: DocumentFile? = null
|
||||
private var packageChildren: List<DocumentFile>? = null
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package com.stevesoltys.seedvault.plugins.saf
|
||||
|
||||
import com.stevesoltys.seedvault.plugins.LegacyStoragePlugin
|
||||
import com.stevesoltys.seedvault.plugins.StoragePlugin
|
||||
import org.koin.android.ext.koin.androidContext
|
||||
import org.koin.dsl.module
|
||||
|
||||
val documentsProviderModule = module {
|
||||
single { DocumentsStorage(androidContext(), get()) }
|
||||
|
||||
single<StoragePlugin> { DocumentsProviderStoragePlugin(androidContext(), get()) }
|
||||
@Suppress("Deprecation")
|
||||
single<LegacyStoragePlugin> { DocumentsProviderLegacyPlugin(androidContext(), get()) }
|
||||
}
|
|
@ -0,0 +1,173 @@
|
|||
package com.stevesoltys.seedvault.plugins.saf
|
||||
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.util.Log
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import com.stevesoltys.seedvault.getSystemContext
|
||||
import com.stevesoltys.seedvault.plugins.EncryptedMetadata
|
||||
import com.stevesoltys.seedvault.plugins.StoragePlugin
|
||||
import com.stevesoltys.seedvault.settings.Storage
|
||||
import java.io.FileNotFoundException
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.io.OutputStream
|
||||
|
||||
private val TAG = DocumentsProviderStoragePlugin::class.java.simpleName
|
||||
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
internal class DocumentsProviderStoragePlugin(
|
||||
private val appContext: Context,
|
||||
private val storage: DocumentsStorage,
|
||||
) : StoragePlugin {
|
||||
|
||||
/**
|
||||
* Attention: This context might be from a different user. Use with care.
|
||||
*/
|
||||
private val context: Context
|
||||
get() = appContext.getSystemContext {
|
||||
storage.storage?.isUsb == true
|
||||
}
|
||||
|
||||
private val packageManager: PackageManager = appContext.packageManager
|
||||
|
||||
@Throws(IOException::class)
|
||||
override suspend fun startNewRestoreSet(token: Long) {
|
||||
// reset current storage
|
||||
storage.reset(token)
|
||||
|
||||
// get or create root backup dir
|
||||
storage.rootBackupDir ?: throw IOException()
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
override suspend fun initializeDevice() {
|
||||
// wipe existing data
|
||||
storage.getSetDir()?.deleteContents(context)
|
||||
|
||||
// reset storage without new token, so folders get recreated
|
||||
// otherwise stale DocumentFiles will hang around
|
||||
storage.reset(null)
|
||||
|
||||
// create backup folders
|
||||
storage.currentSetDir ?: throw IOException()
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
override suspend fun hasData(token: Long, name: String): Boolean {
|
||||
val setDir = storage.getSetDir(token) ?: return false
|
||||
return setDir.findFileBlocking(context, name) != null
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
override suspend fun getOutputStream(token: Long, name: String): OutputStream {
|
||||
val setDir = storage.getSetDir(token) ?: throw IOException()
|
||||
val file = setDir.createOrGetFile(context, name)
|
||||
return storage.getOutputStream(file)
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
override suspend fun getInputStream(token: Long, name: String): InputStream {
|
||||
val setDir = storage.getSetDir(token) ?: throw IOException()
|
||||
val file = setDir.findFileBlocking(context, name) ?: throw FileNotFoundException()
|
||||
return storage.getInputStream(file)
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
override suspend fun removeData(token: Long, name: String) {
|
||||
val setDir = storage.getSetDir(token) ?: throw IOException()
|
||||
val file = setDir.findFileBlocking(context, name) ?: return
|
||||
if (!file.delete()) throw IOException("Failed to delete $name")
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
override suspend fun hasBackup(storage: Storage): Boolean {
|
||||
// potentially get system user context if needed here
|
||||
val c = appContext.getSystemContext { storage.isUsb }
|
||||
val parent = DocumentFile.fromTreeUri(c, storage.uri) ?: throw AssertionError()
|
||||
val rootDir = parent.findFileBlocking(c, DIRECTORY_ROOT) ?: return false
|
||||
val backupSets = getBackups(c, rootDir)
|
||||
return backupSets.isNotEmpty()
|
||||
}
|
||||
|
||||
override suspend fun getAvailableBackups(): Sequence<EncryptedMetadata>? {
|
||||
val rootDir = storage.rootBackupDir ?: return null
|
||||
val backupSets = getBackups(context, rootDir)
|
||||
val iterator = backupSets.iterator()
|
||||
return generateSequence {
|
||||
if (!iterator.hasNext()) return@generateSequence null // end sequence
|
||||
val backupSet = iterator.next()
|
||||
EncryptedMetadata(backupSet.token) {
|
||||
storage.getInputStream(backupSet.metadataFile)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override val providerPackageName: String? by lazy {
|
||||
val authority = storage.getAuthority() ?: return@lazy null
|
||||
val providerInfo = packageManager.resolveContentProvider(authority, 0) ?: return@lazy null
|
||||
providerInfo.packageName
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class BackupSet(val token: Long, val metadataFile: DocumentFile)
|
||||
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
internal suspend fun getBackups(context: Context, rootDir: DocumentFile): List<BackupSet> {
|
||||
val backupSets = ArrayList<BackupSet>()
|
||||
val files = try {
|
||||
// block until the DocumentsProvider has results
|
||||
rootDir.listFilesBlocking(context)
|
||||
} catch (e: IOException) {
|
||||
Log.e(TAG, "Error loading backups from storage", e)
|
||||
return backupSets
|
||||
}
|
||||
for (set in files) {
|
||||
// retrieve name only once as this causes a DB query
|
||||
val name = set.name
|
||||
|
||||
// get current token from set or continue to next file/set
|
||||
val token = set.getTokenOrNull(name) ?: continue
|
||||
|
||||
// block until children of set are available
|
||||
val metadata = try {
|
||||
set.findFileBlocking(context, FILE_BACKUP_METADATA)
|
||||
} catch (e: IOException) {
|
||||
Log.e(TAG, "Error reading metadata file in backup set folder: $name", e)
|
||||
null
|
||||
}
|
||||
if (metadata == null) {
|
||||
Log.w(TAG, "Missing metadata file in backup set folder: $name")
|
||||
} else {
|
||||
backupSets.add(BackupSet(token, metadata))
|
||||
}
|
||||
}
|
||||
return backupSets
|
||||
}
|
||||
|
||||
private val tokenRegex = Regex("([0-9]{13})") // good until the year 2286
|
||||
private val chunkFolderRegex = Regex("[a-f0-9]{2}")
|
||||
|
||||
private fun DocumentFile.getTokenOrNull(name: String?): Long? {
|
||||
val looksLikeToken = name != null && tokenRegex.matches(name)
|
||||
// check for isDirectory only if we already have a valid token (causes DB query)
|
||||
if (!looksLikeToken || !isDirectory) {
|
||||
// only log unexpected output
|
||||
if (name != null && isUnexpectedFile(name)) {
|
||||
Log.w(TAG, "Found invalid backup set folder: $name")
|
||||
}
|
||||
return null
|
||||
}
|
||||
return try {
|
||||
name?.toLong()
|
||||
} catch (e: NumberFormatException) {
|
||||
throw AssertionError(e)
|
||||
}
|
||||
}
|
||||
|
||||
private fun isUnexpectedFile(name: String): Boolean {
|
||||
return name != FILE_NO_MEDIA &&
|
||||
!chunkFolderRegex.matches(name) &&
|
||||
!name.endsWith(".SeedSnap")
|
||||
}
|
|
@ -1,9 +1,6 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2020 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@file:Suppress("BlockingMethodInNonBlockingContext")
|
||||
|
||||
package com.stevesoltys.seedvault.backend.saf
|
||||
package com.stevesoltys.seedvault.plugins.saf
|
||||
|
||||
import android.content.ContentResolver
|
||||
import android.content.Context
|
||||
|
@ -19,43 +16,61 @@ import android.provider.DocumentsContract.getDocumentId
|
|||
import android.util.Log
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import com.stevesoltys.seedvault.getStorageContext
|
||||
import com.stevesoltys.seedvault.getSystemContext
|
||||
import com.stevesoltys.seedvault.settings.SettingsManager
|
||||
import com.stevesoltys.seedvault.settings.Storage
|
||||
import kotlinx.coroutines.TimeoutCancellationException
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||
import kotlinx.coroutines.withTimeout
|
||||
import org.calyxos.seedvault.core.backends.Constants.DIRECTORY_ROOT
|
||||
import org.calyxos.seedvault.core.backends.saf.SafProperties
|
||||
import org.calyxos.seedvault.core.backends.saf.getTreeDocumentFile
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.io.OutputStream
|
||||
import kotlin.coroutines.resume
|
||||
|
||||
const val DIRECTORY_ROOT = ".SeedVaultAndroidBackup"
|
||||
|
||||
@Deprecated("")
|
||||
const val DIRECTORY_FULL_BACKUP = "full"
|
||||
|
||||
@Deprecated("")
|
||||
const val DIRECTORY_KEY_VALUE_BACKUP = "kv"
|
||||
const val FILE_BACKUP_METADATA = ".backup.metadata"
|
||||
const val FILE_NO_MEDIA = ".nomedia"
|
||||
const val MIME_TYPE = "application/octet-stream"
|
||||
|
||||
private val TAG = DocumentsStorage::class.java.simpleName
|
||||
|
||||
internal class DocumentsStorage(
|
||||
private val appContext: Context,
|
||||
internal val safStorage: SafProperties,
|
||||
private val settingsManager: SettingsManager,
|
||||
) {
|
||||
internal var storage: Storage? = null
|
||||
get() {
|
||||
if (field == null) field = settingsManager.getStorage()
|
||||
return field
|
||||
}
|
||||
|
||||
/**
|
||||
* Attention: This context might be from a different user. Use with care.
|
||||
*/
|
||||
private val context: Context get() = appContext.getStorageContext { safStorage.isUsb }
|
||||
private val context: Context
|
||||
get() = appContext.getSystemContext {
|
||||
storage?.isUsb == true
|
||||
}
|
||||
private val contentResolver: ContentResolver get() = context.contentResolver
|
||||
|
||||
private var rootBackupDir: DocumentFile? = null
|
||||
internal var rootBackupDir: DocumentFile? = null
|
||||
get() = runBlocking {
|
||||
if (field == null) {
|
||||
val parent = safStorage.getDocumentFile(context)
|
||||
val parent = storage?.getDocumentFile(context)
|
||||
?: return@runBlocking null
|
||||
field = try {
|
||||
parent.createOrGetDirectory(context, DIRECTORY_ROOT)
|
||||
parent.createOrGetDirectory(context, DIRECTORY_ROOT).apply {
|
||||
// create .nomedia file to prevent Android's MediaScanner
|
||||
// from trying to index the backup
|
||||
createOrGetFile(context, FILE_NO_MEDIA)
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
Log.e(TAG, "Error creating root backup dir.", e)
|
||||
null
|
||||
|
@ -64,8 +79,42 @@ internal class DocumentsStorage(
|
|||
field
|
||||
}
|
||||
|
||||
private var currentToken: Long? = null
|
||||
get() {
|
||||
if (field == null) field = settingsManager.getToken()
|
||||
return field
|
||||
}
|
||||
|
||||
var currentSetDir: DocumentFile? = null
|
||||
get() = runBlocking {
|
||||
if (field == null) {
|
||||
if (currentToken == 0L) return@runBlocking null
|
||||
field = try {
|
||||
rootBackupDir?.createOrGetDirectory(context, currentToken.toString())
|
||||
} catch (e: IOException) {
|
||||
Log.e(TAG, "Error creating current restore set dir.", e)
|
||||
null
|
||||
}
|
||||
}
|
||||
field
|
||||
}
|
||||
private set
|
||||
|
||||
/**
|
||||
* Resets this storage abstraction, forcing it to re-fetch cached values on next access.
|
||||
*/
|
||||
fun reset(newToken: Long?) {
|
||||
storage = null
|
||||
currentToken = newToken
|
||||
rootBackupDir = null
|
||||
currentSetDir = null
|
||||
}
|
||||
|
||||
fun getAuthority(): String? = storage?.uri?.authority
|
||||
|
||||
@Throws(IOException::class)
|
||||
suspend fun getSetDir(token: Long): DocumentFile? {
|
||||
suspend fun getSetDir(token: Long = currentToken ?: error("no token")): DocumentFile? {
|
||||
if (token == currentToken) return currentSetDir
|
||||
return rootBackupDir?.findFileBlocking(context, token.toString())
|
||||
}
|
||||
|
||||
|
@ -85,14 +134,38 @@ internal class DocumentsStorage(
|
|||
|
||||
@Throws(IOException::class)
|
||||
fun getInputStream(file: DocumentFile): InputStream {
|
||||
return try {
|
||||
contentResolver.openInputStream(file.uri) ?: throw IOException()
|
||||
} catch (e: Exception) {
|
||||
// SAF can throw all sorts of exceptions, so wrap it in IOException
|
||||
throw IOException(e)
|
||||
}
|
||||
return contentResolver.openInputStream(file.uri) ?: throw IOException()
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun getOutputStream(file: DocumentFile): OutputStream {
|
||||
return contentResolver.openOutputStream(file.uri, "wt") ?: throw IOException()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a file exists and if not, creates it.
|
||||
*
|
||||
* If we were trying to create it right away, some providers create "filename (1)".
|
||||
*/
|
||||
@Throws(IOException::class)
|
||||
internal suspend fun DocumentFile.createOrGetFile(
|
||||
context: Context,
|
||||
name: String,
|
||||
mimeType: String = MIME_TYPE,
|
||||
): DocumentFile {
|
||||
return try {
|
||||
findFileBlocking(context, name) ?: createFile(mimeType, name)?.apply {
|
||||
if (this.name != name) {
|
||||
throw IOException("File named ${this.name}, but should be $name")
|
||||
}
|
||||
} ?: throw IOException()
|
||||
} catch (e: IllegalArgumentException) {
|
||||
// Can be thrown by FileSystemProvider#isChildDocument() when flash drive is not plugged-in
|
||||
// http://aosp.opersys.com/xref/android-11.0.0_r8/xref/frameworks/base/core/java/com/android/internal/content/FileSystemProvider.java#135
|
||||
throw IOException(e)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -107,6 +180,11 @@ suspend fun DocumentFile.createOrGetDirectory(context: Context, name: String): D
|
|||
} ?: throw IOException()
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
suspend fun DocumentFile.deleteContents(context: Context) {
|
||||
for (file in listFilesBlocking(context)) file.delete()
|
||||
}
|
||||
|
||||
fun DocumentFile.assertRightFile(packageInfo: PackageInfo) {
|
||||
if (name != packageInfo.packageName) {
|
||||
throw AssertionError("Expected ${packageInfo.packageName}, but got $name")
|
||||
|
@ -140,6 +218,26 @@ suspend fun DocumentFile.listFilesBlocking(context: Context): List<DocumentFile>
|
|||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* An extremely dirty reflection hack to instantiate a TreeDocumentFile with a parent.
|
||||
*
|
||||
* All other public ways to get a TreeDocumentFile only work from [Uri]s
|
||||
* (e.g. [DocumentFile.fromTreeUri]) and always set parent to null.
|
||||
*
|
||||
* We have a test for this method to ensure CI will alert us when this reflection breaks.
|
||||
* Also, [DocumentFile] is part of AndroidX, so we control the dependency and notice when it fails.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
internal fun getTreeDocumentFile(parent: DocumentFile, context: Context, uri: Uri): DocumentFile {
|
||||
@SuppressWarnings("MagicNumber")
|
||||
val constructor = parent.javaClass.declaredConstructors.find {
|
||||
it.name == "androidx.documentfile.provider.TreeDocumentFile" && it.parameterCount == 3
|
||||
}
|
||||
check(constructor != null) { "Could not find constructor for TreeDocumentFile" }
|
||||
constructor.isAccessible = true
|
||||
return constructor.newInstance(parent, context, uri) as DocumentFile
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as [DocumentFile.findFile] only that it re-queries when the first result was stale.
|
||||
*
|
||||
|
@ -150,7 +248,7 @@ suspend fun DocumentFile.listFilesBlocking(context: Context): List<DocumentFile>
|
|||
suspend fun DocumentFile.findFileBlocking(context: Context, displayName: String): DocumentFile? {
|
||||
val files = try {
|
||||
listFilesBlocking(context)
|
||||
} catch (e: Exception) {
|
||||
} catch (e: IOException) {
|
||||
Log.e(TAG, "Error finding file blocking", e)
|
||||
return null
|
||||
}
|
||||
|
@ -181,7 +279,7 @@ suspend fun DocumentFile.findFileBlocking(context: Context, displayName: String)
|
|||
@Throws(IOException::class, TimeoutCancellationException::class)
|
||||
internal suspend fun getLoadedCursor(timeout: Long = 15_000, query: () -> Cursor?) =
|
||||
withTimeout(timeout) {
|
||||
suspendCancellableCoroutine { cont ->
|
||||
suspendCancellableCoroutine<Cursor> { cont ->
|
||||
val cursor = query() ?: throw IOException()
|
||||
cont.invokeOnCancellation { cursor.close() }
|
||||
val loading = cursor.extras.getBoolean(EXTRA_LOADING, false)
|
|
@ -1,191 +0,0 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.repo
|
||||
|
||||
import androidx.annotation.WorkerThread
|
||||
import com.stevesoltys.seedvault.MemoryLogger
|
||||
import com.stevesoltys.seedvault.backend.BackendManager
|
||||
import com.stevesoltys.seedvault.crypto.Crypto
|
||||
import com.stevesoltys.seedvault.header.VERSION
|
||||
import com.stevesoltys.seedvault.settings.SettingsManager
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import kotlinx.coroutines.delay
|
||||
import org.calyxos.seedvault.core.backends.AppBackupFileType.Blob
|
||||
import org.calyxos.seedvault.core.backends.AppBackupFileType.Snapshot
|
||||
import org.calyxos.seedvault.core.backends.FileInfo
|
||||
import org.calyxos.seedvault.core.backends.TopLevelFolder
|
||||
import java.io.IOException
|
||||
|
||||
/**
|
||||
* Manages the process of app data backups, especially related to work that needs to happen
|
||||
* before and after a backup run.
|
||||
* See [beforeBackup] and [afterBackupFinished].
|
||||
*/
|
||||
internal class AppBackupManager(
|
||||
private val crypto: Crypto,
|
||||
private val blobCache: BlobCache,
|
||||
private val backendManager: BackendManager,
|
||||
private val settingsManager: SettingsManager,
|
||||
private val snapshotManager: SnapshotManager,
|
||||
private val snapshotCreatorFactory: SnapshotCreatorFactory,
|
||||
) {
|
||||
|
||||
private val log = KotlinLogging.logger {}
|
||||
|
||||
/**
|
||||
* A temporary [SnapshotCreator] that has a lifetime only valid during the backup run.
|
||||
*/
|
||||
@Volatile
|
||||
var snapshotCreator: SnapshotCreator? = null
|
||||
private set
|
||||
|
||||
@Volatile
|
||||
private var startedViaAdb = false
|
||||
|
||||
/**
|
||||
* Call this method before doing any kind of backup work.
|
||||
* It will
|
||||
* * download the blobs available on the backend,
|
||||
* * assemble the chunk ID to blob mapping from previous snapshots and
|
||||
* * create a new instance of a [SnapshotCreator].
|
||||
*
|
||||
* @throws IOException or other exceptions.
|
||||
* These should be caught by the caller who may retry us on transient errors.
|
||||
*/
|
||||
@WorkerThread
|
||||
@Throws(IOException::class)
|
||||
suspend fun beforeBackup() {
|
||||
log.info { "Loading existing snapshots and blobs..." }
|
||||
val blobInfos = mutableListOf<FileInfo>()
|
||||
val snapshotHandles = mutableListOf<Snapshot>()
|
||||
backendManager.backend.list(
|
||||
topLevelFolder = TopLevelFolder(crypto.repoId),
|
||||
Blob::class, Snapshot::class,
|
||||
) { fileInfo ->
|
||||
when (fileInfo.fileHandle) {
|
||||
is Blob -> blobInfos.add(fileInfo)
|
||||
is Snapshot -> snapshotHandles.add(fileInfo.fileHandle as Snapshot)
|
||||
else -> error("Unexpected FileHandle: $fileInfo")
|
||||
}
|
||||
}
|
||||
log.info { "Found ${snapshotHandles.size} existing snapshots." }
|
||||
val snapshots = snapshotManager.onSnapshotsLoaded(snapshotHandles)
|
||||
blobCache.populateCache(blobInfos, snapshots)
|
||||
snapshotCreator = snapshotCreatorFactory.createSnapshotCreator()
|
||||
}
|
||||
|
||||
/**
|
||||
* This must be called after the backup run has been completed.
|
||||
* It finalized the current snapshot and saves it to the backend.
|
||||
* Then, it clears up the [BlobCache] and the [SnapshotCreator].
|
||||
*
|
||||
* @param success true if the backup run was successful, false otherwise.
|
||||
*
|
||||
* @return the snapshot saved to the backend or null if there was an error saving it.
|
||||
*/
|
||||
@WorkerThread
|
||||
suspend fun afterBackupFinished(success: Boolean): com.stevesoltys.seedvault.proto.Snapshot? {
|
||||
MemoryLogger.log()
|
||||
log.info { "After backup finished. Success: $success" }
|
||||
// free up memory by clearing blobs cache
|
||||
blobCache.clear()
|
||||
return try {
|
||||
if (success) {
|
||||
// only save snapshot when backup was successful,
|
||||
// otherwise we'd have partial snapshots
|
||||
val snapshot = snapshotCreator?.finalizeSnapshot()
|
||||
?: error("Had no snapshotCreator")
|
||||
keepTrying { // TODO remove when we have auto-retrying backends
|
||||
// saving this is so important, we even keep trying
|
||||
snapshotManager.saveSnapshot(snapshot)
|
||||
}
|
||||
// save token and time of last backup
|
||||
settingsManager.onSuccessfulBackupCompleted(snapshot.token)
|
||||
// after snapshot was written, we can clear local cache as its info is in snapshot
|
||||
blobCache.clearLocalCache()
|
||||
snapshot
|
||||
} else null
|
||||
} catch (e: Exception) {
|
||||
log.error(e) { "Error finishing backup" }
|
||||
null
|
||||
} finally {
|
||||
snapshotCreator = null
|
||||
MemoryLogger.log()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* When doing backups with `adb shell bmgr backupnow`,
|
||||
* we don't get a chance to do our initialization in [beforeBackup],
|
||||
* so we use this opportunity to do it now.
|
||||
*/
|
||||
suspend fun ensureBackupPrepared() = if (snapshotCreator == null) {
|
||||
log.warn { "Backup not prepared. If not started via `adb shell bmgr` that's a bug" }
|
||||
startedViaAdb = true
|
||||
beforeBackup()
|
||||
} else Unit
|
||||
|
||||
/**
|
||||
* We don't get notified when backups ran from `adb shell bmgr backupnow` end,
|
||||
* so [afterBackupFinished] will not run, so we need to find a place
|
||||
*/
|
||||
suspend fun finalizeBackupIfNeeded() {
|
||||
if (startedViaAdb) {
|
||||
log.warn { "Backup not finalized. If not started via `adb shell bmgr` that's a bug" }
|
||||
startedViaAdb = false
|
||||
afterBackupFinished(true) // is there a way to know if success or not?
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the repo identified by [repoId] can be transferred to this device.
|
||||
* This is the case when it isn't the same as the current repoId and the version is latest.
|
||||
*/
|
||||
fun canRecycleBackupRepo(repoId: String?, version: Byte?): Boolean {
|
||||
if (repoId == null || version == null) return false
|
||||
return repoId != crypto.repoId && version == VERSION
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfers the ownership of the backup repository identified by the [oldRepoId]
|
||||
* to the current user and device
|
||||
* by renaming the [TopLevelFolder] of the repo to the current repoId.
|
||||
*/
|
||||
@Throws(IOException::class)
|
||||
suspend fun recycleBackupRepo(oldRepoId: String) {
|
||||
val newRepoId = crypto.repoId
|
||||
if (oldRepoId == newRepoId) return
|
||||
val oldFolder = TopLevelFolder(oldRepoId)
|
||||
val newFolder = TopLevelFolder(newRepoId)
|
||||
backendManager.backend.rename(oldFolder, newFolder)
|
||||
}
|
||||
|
||||
/**
|
||||
* Careful, this removes the entire backup repository from the backend
|
||||
* and clears local blob cache.
|
||||
*/
|
||||
@WorkerThread
|
||||
@Throws(IOException::class)
|
||||
suspend fun removeBackupRepo() {
|
||||
blobCache.clearLocalCache()
|
||||
// TODO not critical, but nice to have: clear also local snapshot cache
|
||||
backendManager.backend.remove(TopLevelFolder(crypto.repoId))
|
||||
}
|
||||
|
||||
private suspend fun keepTrying(n: Int = 3, block: suspend () -> Unit) {
|
||||
for (i in 1..n) {
|
||||
try {
|
||||
block()
|
||||
return
|
||||
} catch (e: Exception) {
|
||||
if (i == n) throw e
|
||||
log.error(e) { "Error (#$i), we'll keep trying" }
|
||||
delay(1000 * i.toLong())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.repo
|
||||
|
||||
import com.stevesoltys.seedvault.proto.Snapshot.Blob
|
||||
|
||||
/**
|
||||
* Essential metadata returned when storing backup data.
|
||||
*
|
||||
* @param chunkIds an ordered(!) list of the chunk IDs required to re-assemble the backup data.
|
||||
* @param blobMap a mapping from chunk ID to [Blob] on the backend.
|
||||
* Needed for fetching blobs from the backend for re-assembly.
|
||||
*/
|
||||
data class BackupData(
|
||||
val chunkIds: List<String>,
|
||||
val blobMap: Map<String, Blob>,
|
||||
) {
|
||||
/**
|
||||
* The uncompressed plaintext size of all blobs.
|
||||
*/
|
||||
val size get() = blobMap.values.sumOf { it.uncompressedLength }.toLong()
|
||||
}
|
|
@ -1,132 +0,0 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.repo
|
||||
|
||||
import androidx.annotation.WorkerThread
|
||||
import com.stevesoltys.seedvault.crypto.Crypto
|
||||
import com.stevesoltys.seedvault.proto.Snapshot.Blob
|
||||
import org.calyxos.seedvault.chunker.Chunk
|
||||
import org.calyxos.seedvault.chunker.Chunker
|
||||
import org.calyxos.seedvault.chunker.GearTableCreator
|
||||
import org.calyxos.seedvault.core.toHexString
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
|
||||
/**
|
||||
* The single point for receiving data for backup.
|
||||
* Data received will get split into smaller chunks, if needed.
|
||||
* [Chunk]s that don't have a corresponding [Blob] in the [blobCache]
|
||||
* will be passed to the [blobCreator] and have the new blob saved to the backend.
|
||||
*
|
||||
* Data can be received either via [addBytes] (requires matching call to [finalize])
|
||||
* or via [readFromStream].
|
||||
* This call is *not* thread-safe.
|
||||
*/
|
||||
internal class BackupReceiver(
|
||||
private val blobCache: BlobCache,
|
||||
private val blobCreator: BlobCreator,
|
||||
private val crypto: Crypto,
|
||||
private val replaceableChunker: Chunker? = null,
|
||||
) {
|
||||
|
||||
private val chunker: Chunker by lazy {
|
||||
// crypto.gearTableKey is not available at creation time, so use lazy instantiation
|
||||
replaceableChunker ?: Chunker(
|
||||
minSize = 1536 * 1024, // 1.5 MB
|
||||
avgSize = 3 * 1024 * 1024, // 3.0 MB
|
||||
maxSize = 7680 * 1024, // 7.5 MB
|
||||
normalization = 1,
|
||||
gearTable = GearTableCreator.create(crypto.gearTableKey),
|
||||
hashFunction = { bytes ->
|
||||
// this calculates the chunkId
|
||||
crypto.sha256(bytes).toHexString()
|
||||
},
|
||||
)
|
||||
}
|
||||
private val chunks = mutableListOf<String>()
|
||||
private val blobMap = mutableMapOf<String, Blob>()
|
||||
private var owner: String? = null
|
||||
|
||||
/**
|
||||
* Adds more [bytes] to be chunked and saved.
|
||||
* Must call [finalize] when done, even when an exception was thrown
|
||||
* to free up this re-usable instance of [BackupReceiver].
|
||||
*/
|
||||
@WorkerThread
|
||||
@Throws(IOException::class)
|
||||
suspend fun addBytes(owner: String, bytes: ByteArray) {
|
||||
checkOwner(owner)
|
||||
chunker.addBytes(bytes).forEach { chunk ->
|
||||
onNewChunk(chunk)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads backup data from the given [inputStream] and returns [BackupData],
|
||||
* so a call to [finalize] isn't required.
|
||||
* The caller must close the [inputStream] when done.
|
||||
*/
|
||||
@WorkerThread
|
||||
@Throws(IOException::class)
|
||||
suspend fun readFromStream(owner: String, inputStream: InputStream): BackupData {
|
||||
checkOwner(owner)
|
||||
try {
|
||||
val buffer = ByteArray(DEFAULT_BUFFER_SIZE)
|
||||
var bytes = inputStream.read(buffer)
|
||||
while (bytes >= 0) {
|
||||
if (bytes == buffer.size) {
|
||||
addBytes(owner, buffer)
|
||||
} else {
|
||||
addBytes(owner, buffer.copyOfRange(0, bytes))
|
||||
}
|
||||
bytes = inputStream.read(buffer)
|
||||
}
|
||||
return finalize(owner)
|
||||
} catch (e: Exception) {
|
||||
finalize(owner)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Must be called after one or more calls to [addBytes] to finalize usage of this instance
|
||||
* and receive the [BackupData] for snapshotting.
|
||||
*/
|
||||
@WorkerThread
|
||||
@Throws(IOException::class)
|
||||
suspend fun finalize(owner: String): BackupData {
|
||||
checkOwner(owner)
|
||||
try {
|
||||
chunker.finalize().forEach { chunk ->
|
||||
onNewChunk(chunk)
|
||||
}
|
||||
return BackupData(chunks.toList(), blobMap.toMap())
|
||||
} finally {
|
||||
chunks.clear()
|
||||
blobMap.clear()
|
||||
this.owner = null
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun onNewChunk(chunk: Chunk) {
|
||||
chunks.add(chunk.hash)
|
||||
|
||||
val existingBlob = blobCache[chunk.hash]
|
||||
if (existingBlob == null) {
|
||||
val blob = blobCreator.createNewBlob(chunk)
|
||||
blobMap[chunk.hash] = blob
|
||||
blobCache.saveNewBlob(chunk.hash, blob)
|
||||
} else {
|
||||
blobMap[chunk.hash] = existingBlob
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkOwner(owner: String) {
|
||||
if (this.owner == null) this.owner = owner
|
||||
else check(this.owner == owner) { "Owned by ${this.owner}, but called from $owner" }
|
||||
}
|
||||
|
||||
}
|
|
@ -1,273 +0,0 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.repo
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Context.MODE_APPEND
|
||||
import android.content.Context.MODE_PRIVATE
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import androidx.annotation.WorkerThread
|
||||
import com.google.protobuf.ByteString
|
||||
import com.stevesoltys.seedvault.MemoryLogger
|
||||
import com.stevesoltys.seedvault.proto.Snapshot
|
||||
import com.stevesoltys.seedvault.proto.Snapshot.Blob
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import org.calyxos.seedvault.core.backends.FileInfo
|
||||
import org.calyxos.seedvault.core.toByteArrayFromHex
|
||||
import org.calyxos.seedvault.core.toHexString
|
||||
import java.io.FileNotFoundException
|
||||
import java.io.IOException
|
||||
|
||||
@VisibleForTesting
|
||||
internal const val CACHE_FILE_NAME = "blobsCache"
|
||||
|
||||
/**
|
||||
* The filename of the file where we store which blobs are known to be corrupt
|
||||
* and should not be used anymore.
|
||||
* Each [BLOB_ID_SIZE] bytes are appended without separator or line breaks.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
internal const val DO_NOT_USE_FILE_NAME = "doNotUseBlobs"
|
||||
|
||||
private const val BLOB_ID_SIZE = 32
|
||||
|
||||
/**
|
||||
* Responsible for caching blobs during a backup run,
|
||||
* so we can know that a blob for the given chunk ID already exists
|
||||
* and does not need to be uploaded again.
|
||||
*
|
||||
* It builds up its cache from snapshots available on the backend
|
||||
* and from the persistent cache that includes blobs that could not be added to a snapshot,
|
||||
* because the backup was aborted.
|
||||
*/
|
||||
class BlobCache(
|
||||
private val context: Context,
|
||||
) {
|
||||
|
||||
private val log = KotlinLogging.logger {}
|
||||
private val blobMap = mutableMapOf<String, Blob>()
|
||||
|
||||
/**
|
||||
* This must be called before saving files to the backend to avoid uploading duplicate blobs.
|
||||
*/
|
||||
@Throws(IOException::class)
|
||||
fun populateCache(blobs: List<FileInfo>, snapshots: List<Snapshot>) {
|
||||
log.info { "Getting all blobs from backend..." }
|
||||
blobMap.clear()
|
||||
MemoryLogger.log()
|
||||
// create map of blobId to size of blob on backend
|
||||
val allowedBlobIds = blobs.associate {
|
||||
Pair(it.fileHandle.name, it.size.toInt())
|
||||
}.toMutableMap()
|
||||
// remove known bad blob IDs from allowedBlobIds
|
||||
getDoNotUseBlobIds().forEach { knownBadId ->
|
||||
if (allowedBlobIds.remove(knownBadId) != null) {
|
||||
log.info { "Removed known bad blob: $knownBadId" }
|
||||
}
|
||||
}
|
||||
// load local blob cache and include only blobs on backend
|
||||
loadPersistentBlobCache(allowedBlobIds)
|
||||
// build up mapping from chunkId to blob from available snapshots
|
||||
snapshots.forEach { snapshot ->
|
||||
onSnapshotLoaded(snapshot, allowedBlobIds)
|
||||
}
|
||||
MemoryLogger.log()
|
||||
}
|
||||
|
||||
/**
|
||||
* Should only be called after [populateCache] has returned.
|
||||
*/
|
||||
operator fun get(chunkId: String): Blob? = blobMap[chunkId]
|
||||
|
||||
/**
|
||||
* Should only be called after [populateCache] has returned.
|
||||
*
|
||||
* @return true if all [chunkIds] are in cache, or false if one or more is missing.
|
||||
*/
|
||||
fun containsAll(chunkIds: List<String>): Boolean = chunkIds.all { chunkId ->
|
||||
blobMap.containsKey(chunkId)
|
||||
}
|
||||
|
||||
/**
|
||||
* Should get called for all new blobs as soon as they've been saved to the backend.
|
||||
*
|
||||
* We shouldn't need to worry about [Pruner] removing blobs that get cached here locally,
|
||||
* because we do run [Pruner.removeOldSnapshotsAndPruneUnusedBlobs] only after
|
||||
* a successful backup which is when we also clear cache in [clearLocalCache].
|
||||
*/
|
||||
fun saveNewBlob(chunkId: String, blob: Blob) {
|
||||
val previous = blobMap.put(chunkId, blob)
|
||||
if (previous == null) {
|
||||
// persist this new blob locally in case backup gets interrupted
|
||||
context.openFileOutput(CACHE_FILE_NAME, MODE_APPEND).use { outputStream ->
|
||||
outputStream.write(chunkId.toByteArrayFromHex())
|
||||
blob.writeDelimitedTo(outputStream)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the cached blob mapping.
|
||||
* Should be called after a backup run to free up memory.
|
||||
*/
|
||||
fun clear() {
|
||||
log.info { "Clearing cache..." }
|
||||
blobMap.clear()
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the local cache.
|
||||
* Should get called after
|
||||
* * changing to a different backup to prevent usage of blobs that don't exist there
|
||||
* * uploading a new snapshot to prevent the persistent cache from growing indefinitely
|
||||
*/
|
||||
@WorkerThread
|
||||
fun clearLocalCache() {
|
||||
log.info { "Clearing local cache..." }
|
||||
context.deleteFile(CACHE_FILE_NAME)
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads persistent cache from disk and adds blobs to [blobMap]
|
||||
* if available in [allowedBlobIds] with the right size.
|
||||
*/
|
||||
private fun loadPersistentBlobCache(allowedBlobIds: Map<String, Int>) {
|
||||
try {
|
||||
context.openFileInput(CACHE_FILE_NAME).use { inputStream ->
|
||||
val chunkIdBytes = ByteArray(32)
|
||||
while (true) {
|
||||
val bytesRead = inputStream.read(chunkIdBytes)
|
||||
if (bytesRead != 32) break
|
||||
val chunkId = chunkIdBytes.toHexString()
|
||||
// parse blob
|
||||
val blob = Blob.parseDelimitedFrom(inputStream)
|
||||
val blobId = blob.id.hexFromProto()
|
||||
// include blob only if size is equal to size on backend
|
||||
val sizeOnBackend = allowedBlobIds[blobId]
|
||||
if (sizeOnBackend == blob.length) {
|
||||
blobMap[chunkId] = blob
|
||||
} else log.warn {
|
||||
if (sizeOnBackend == null) {
|
||||
"Cached blob $blobId is missing from backend."
|
||||
} else {
|
||||
"Cached blob $blobId had different size on backend: $sizeOnBackend"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
if (e is FileNotFoundException) log.info { "No local blob cache found." }
|
||||
else {
|
||||
// If the local cache is corrupted, that's not the end of the world.
|
||||
// We can still continue normally,
|
||||
// but may be writing out duplicated blobs we can't re-use.
|
||||
// Those will get deleted again when pruning.
|
||||
// So swallow the exception.
|
||||
log.error(e) { "Error loading blobs cache: " }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for populating local [blobMap] cache.
|
||||
* Adds mapping from chunkId to [Blob], if it exists on backend, i.e. part of [allowedBlobIds]
|
||||
* and its size matches the one on backend, i.e. value of [allowedBlobIds].
|
||||
*/
|
||||
private fun onSnapshotLoaded(snapshot: Snapshot, allowedBlobIds: Map<String, Int>) {
|
||||
snapshot.blobsMap.forEach { (chunkId, blob) ->
|
||||
// check if referenced blob still exists on backend
|
||||
val blobId = blob.id.hexFromProto()
|
||||
val sizeOnBackend = allowedBlobIds[blobId]
|
||||
if (sizeOnBackend == blob.length) {
|
||||
// only add blob to our mapping, if it still exists
|
||||
blobMap.putIfAbsent(chunkId, blob)?.let { previous ->
|
||||
// If there's more than one blob for the same chunk ID, it shouldn't matter
|
||||
// which one we keep on using provided both are still ok.
|
||||
// When we are here, the blob exists on storage and has the same size.
|
||||
// There may still be other corruption such as bit flips in one of the blobs.
|
||||
if (previous.id != blob.id) log.warn {
|
||||
"Chunk ID ${chunkId.substring(0..5)} had more than one blob."
|
||||
}
|
||||
}
|
||||
} else log.warn {
|
||||
if (sizeOnBackend == null) {
|
||||
"Blob $blobId in snapshot ${snapshot.token} is missing."
|
||||
} else {
|
||||
"Blob $blobId has unexpected size: $sizeOnBackend"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is expected to get called by the [Checker] when it finds a blob
|
||||
* that has the expected file size, but its content hash doesn't match what we expect.
|
||||
*
|
||||
* It appends the given [blobId] to our [DO_NOT_USE_FILE_NAME] file.
|
||||
*/
|
||||
fun doNotUseBlob(blobId: ByteString) {
|
||||
try {
|
||||
context.openFileOutput(DO_NOT_USE_FILE_NAME, MODE_APPEND).use { outputStream ->
|
||||
val bytes = blobId.toByteArray()
|
||||
check(bytes.size == 32) { "Blob ID $blobId has unexpected size of ${bytes.size}" }
|
||||
outputStream.write(bytes)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
log.error(e) { "Error adding blob to do-not-use list, may be corrupted: " }
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
fun getDoNotUseBlobIds(): Set<String> {
|
||||
val blobsIds = mutableSetOf<String>()
|
||||
try {
|
||||
context.openFileInput(DO_NOT_USE_FILE_NAME).use { inputStream ->
|
||||
val bytes = ByteArray(BLOB_ID_SIZE)
|
||||
while (inputStream.read(bytes) == 32) {
|
||||
val blobId = bytes.toHexString()
|
||||
blobsIds.add(blobId)
|
||||
}
|
||||
}
|
||||
} catch (e: FileNotFoundException) {
|
||||
log.info { "No do-not-use list found" }
|
||||
} catch (e: Exception) {
|
||||
log.error(e) { "Our internal do-not-use list is corrupted, deleting it..." }
|
||||
context.deleteFile(DO_NOT_USE_FILE_NAME)
|
||||
}
|
||||
return blobsIds
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this after deleting blobs from the backend,
|
||||
* so we can remove those from our do-not-use list.
|
||||
*/
|
||||
fun onBlobsRemoved(blobIds: Set<String>) {
|
||||
log.info { "${blobIds.size} blobs were removed." }
|
||||
|
||||
val blobsIdsToKeep = mutableSetOf<String>()
|
||||
|
||||
try {
|
||||
context.openFileInput(DO_NOT_USE_FILE_NAME).use { inputStream ->
|
||||
val bytes = ByteArray(BLOB_ID_SIZE)
|
||||
while (inputStream.read(bytes) == 32) {
|
||||
val blobId = bytes.toHexString()
|
||||
if (blobId !in blobIds) blobsIdsToKeep.add(blobId)
|
||||
}
|
||||
}
|
||||
} catch (e: FileNotFoundException) {
|
||||
log.info { "No do-not-use list found, no need to remove blobs from it." }
|
||||
return
|
||||
} // if something else goes wrong here, we'll delete the file before next backup
|
||||
context.openFileOutput(DO_NOT_USE_FILE_NAME, MODE_PRIVATE).use { outputStream ->
|
||||
blobsIdsToKeep.forEach { blobId ->
|
||||
val bytes = blobId.toByteArrayFromHex()
|
||||
outputStream.write(bytes)
|
||||
}
|
||||
}
|
||||
log.info { "${blobsIdsToKeep.size} blobs remain on do-not-use list." }
|
||||
}
|
||||
|
||||
}
|
|
@ -1,86 +0,0 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.repo
|
||||
|
||||
import androidx.annotation.WorkerThread
|
||||
import com.github.luben.zstd.ZstdOutputStream
|
||||
import com.google.protobuf.ByteString
|
||||
import com.stevesoltys.seedvault.MemoryLogger
|
||||
import com.stevesoltys.seedvault.backend.BackendManager
|
||||
import com.stevesoltys.seedvault.crypto.Crypto
|
||||
import com.stevesoltys.seedvault.header.VERSION
|
||||
import com.stevesoltys.seedvault.proto.Snapshot.Blob
|
||||
import com.stevesoltys.seedvault.proto.SnapshotKt.blob
|
||||
import com.stevesoltys.seedvault.repo.Padding.getPadTo
|
||||
import okio.Buffer
|
||||
import okio.buffer
|
||||
import okio.sink
|
||||
import org.calyxos.seedvault.chunker.Chunk
|
||||
import org.calyxos.seedvault.core.backends.AppBackupFileType
|
||||
import java.io.IOException
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
/**
|
||||
* Creates and uploads new blobs to the current backend.
|
||||
*/
|
||||
internal class BlobCreator(
|
||||
private val crypto: Crypto,
|
||||
private val backendManager: BackendManager,
|
||||
) {
|
||||
|
||||
private val payloadBuffer = Buffer()
|
||||
private val buffer = Buffer()
|
||||
|
||||
/**
|
||||
* Creates and returns a new [Blob] from the given [chunk] and uploads it to the backend.
|
||||
*/
|
||||
@WorkerThread
|
||||
@Throws(IOException::class)
|
||||
suspend fun createNewBlob(chunk: Chunk): Blob {
|
||||
// ensure buffers are cleared
|
||||
payloadBuffer.clear()
|
||||
buffer.clear()
|
||||
|
||||
// compress payload and get size
|
||||
ZstdOutputStream(payloadBuffer.outputStream()).use { zstdOutputStream ->
|
||||
zstdOutputStream.write(chunk.data)
|
||||
}
|
||||
val payloadSize = payloadBuffer.size.toInt()
|
||||
val payloadSizeBytes = ByteBuffer.allocate(4).putInt(payloadSize).array()
|
||||
val paddingSize = getPadTo(payloadSize) - payloadSize
|
||||
|
||||
// encrypt compressed payload and assemble entire blob
|
||||
val bufferStream = buffer.outputStream()
|
||||
bufferStream.write(VERSION.toInt())
|
||||
crypto.newEncryptingStream(bufferStream, crypto.getAdForVersion()).use { cryptoStream ->
|
||||
cryptoStream.write(payloadSizeBytes)
|
||||
payloadBuffer.writeTo(cryptoStream)
|
||||
// add padding
|
||||
// we could just write 0s, but because of defense in depth, we use random bytes
|
||||
cryptoStream.write(crypto.getRandomBytes(paddingSize))
|
||||
}
|
||||
MemoryLogger.log()
|
||||
payloadBuffer.clear()
|
||||
|
||||
// compute hash and save blob
|
||||
val sha256ByteString = buffer.sha256()
|
||||
val handle = AppBackupFileType.Blob(crypto.repoId, sha256ByteString.hex())
|
||||
// TODO for later: implement a backend wrapper that handles retries for transient errors
|
||||
val size = backendManager.backend.save(handle).use { outputStream ->
|
||||
val outputBuffer = outputStream.sink().buffer()
|
||||
val length = outputBuffer.writeAll(buffer)
|
||||
// flushing is important here, otherwise data doesn't get fully written!
|
||||
outputBuffer.flush()
|
||||
length
|
||||
}
|
||||
buffer.clear()
|
||||
return blob {
|
||||
id = ByteString.copyFrom(sha256ByteString.asByteBuffer())
|
||||
length = size.toInt()
|
||||
uncompressedLength = chunk.length
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,237 +0,0 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.repo
|
||||
|
||||
import androidx.annotation.WorkerThread
|
||||
import com.google.protobuf.ByteString
|
||||
import com.stevesoltys.seedvault.MemoryLogger
|
||||
import com.stevesoltys.seedvault.backend.BackendManager
|
||||
import com.stevesoltys.seedvault.crypto.Crypto
|
||||
import com.stevesoltys.seedvault.proto.Snapshot
|
||||
import com.stevesoltys.seedvault.proto.Snapshot.Blob
|
||||
import com.stevesoltys.seedvault.ui.notification.BackupNotificationManager
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.sync.Semaphore
|
||||
import kotlinx.coroutines.sync.withPermit
|
||||
import org.calyxos.seedvault.core.backends.AppBackupFileType
|
||||
import org.calyxos.seedvault.core.backends.TopLevelFolder
|
||||
import org.calyxos.seedvault.core.toHexString
|
||||
import java.security.DigestInputStream
|
||||
import java.security.GeneralSecurityException
|
||||
import java.security.MessageDigest
|
||||
import java.util.concurrent.ConcurrentSkipListSet
|
||||
import java.util.concurrent.atomic.AtomicLong
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
import kotlin.math.roundToInt
|
||||
import kotlin.math.roundToLong
|
||||
|
||||
internal class Checker(
|
||||
private val crypto: Crypto,
|
||||
private val backendManager: BackendManager,
|
||||
private val snapshotManager: SnapshotManager,
|
||||
private val loader: Loader,
|
||||
private val blobCache: BlobCache,
|
||||
private val nm: BackupNotificationManager,
|
||||
) {
|
||||
private val log = KotlinLogging.logger { }
|
||||
|
||||
private var handleSize: Int? = null
|
||||
private var snapshots: List<Snapshot>? = null
|
||||
private val concurrencyLimit: Int
|
||||
get() {
|
||||
val maxConcurrent = if (backendManager.requiresNetwork) 3 else 42
|
||||
return min(Runtime.getRuntime().availableProcessors(), maxConcurrent)
|
||||
}
|
||||
var checkerResult: CheckerResult? = null
|
||||
private set
|
||||
|
||||
@WorkerThread
|
||||
suspend fun getBackupSize(): Long? {
|
||||
return try {
|
||||
getBackupSizeInt()
|
||||
} catch (e: Exception) {
|
||||
log.error(e) { "Error loading snapshots: " }
|
||||
// we swallow this exception, because an error will be shown in the next step
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun getBackupSizeInt(): Long {
|
||||
// get all snapshots
|
||||
val folder = TopLevelFolder(crypto.repoId)
|
||||
val handles = mutableListOf<AppBackupFileType.Snapshot>()
|
||||
backendManager.backend.list(folder, AppBackupFileType.Snapshot::class) { fileInfo ->
|
||||
handles.add(fileInfo.fileHandle as AppBackupFileType.Snapshot)
|
||||
}
|
||||
val snapshots = snapshotManager.onSnapshotsLoaded(handles)
|
||||
this.snapshots = snapshots // remember loaded snapshots
|
||||
this.handleSize = handles.size // remember number of snapshot handles we had
|
||||
|
||||
// get total disk space used by snapshots
|
||||
val sizeMap = mutableMapOf<ByteString, Int>() // uses blob.id as key
|
||||
snapshots.forEach { snapshot ->
|
||||
// add sizes to a map first, so we don't double count
|
||||
snapshot.blobsMap.forEach { (_, blob) ->
|
||||
sizeMap[blob.id] = blob.length
|
||||
}
|
||||
}
|
||||
return sizeMap.values.sumOf { it.toLong() }
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
suspend fun check(percent: Int) {
|
||||
check(percent in 0..100) { "Percent $percent out of bounds." }
|
||||
|
||||
if (snapshots == null) try {
|
||||
getBackupSizeInt() // just get size again to be sure we get snapshots
|
||||
} catch (e: Exception) {
|
||||
nm.onCheckFinishedWithError(0, 0)
|
||||
checkerResult = CheckerResult.GeneralError(e)
|
||||
return
|
||||
}
|
||||
val snapshots = snapshots ?: error("Snapshots still null")
|
||||
val handleSize = handleSize ?: error("Handle size still null")
|
||||
check(handleSize >= snapshots.size) {
|
||||
"Got $handleSize handles, but ${snapshots.size} snapshots."
|
||||
}
|
||||
val blobSample = getBlobSample(snapshots, percent)
|
||||
val sampleSize = blobSample.sumOf { it.blob.length.toLong() }
|
||||
log.info { "Blob sample has ${blobSample.size} blobs worth $sampleSize bytes." }
|
||||
|
||||
// check blobs concurrently
|
||||
val semaphore = Semaphore(concurrencyLimit)
|
||||
val size = AtomicLong()
|
||||
val badChunks = ConcurrentSkipListSet<ChunkIdBlobPair>()
|
||||
val lastNotification = AtomicLong()
|
||||
val startTime = System.currentTimeMillis()
|
||||
coroutineScope {
|
||||
blobSample.forEach { (chunkId, blob) ->
|
||||
// launch a new co-routine for each blob to check
|
||||
launch {
|
||||
// suspend here until we get a permit from the semaphore (there's free workers)
|
||||
semaphore.withPermit {
|
||||
try {
|
||||
checkBlob(chunkId, blob)
|
||||
} catch (e: HashMismatchException) {
|
||||
log.error(e) { "Error loading chunk $chunkId: " }
|
||||
badChunks.add(ChunkIdBlobPair(chunkId, blob))
|
||||
blobCache.doNotUseBlob(blob.id)
|
||||
} catch (e: Exception) {
|
||||
log.error(e) { "Error loading chunk $chunkId: " }
|
||||
// TODO we could try differentiating transient backend issues
|
||||
badChunks.add(ChunkIdBlobPair(chunkId, blob))
|
||||
}
|
||||
}
|
||||
// keep track of how much we checked and for how long
|
||||
val newSize = size.addAndGet(blob.length.toLong())
|
||||
val passedTime = System.currentTimeMillis() - startTime
|
||||
// only log/show notification after some time has passed (throttling)
|
||||
if (passedTime > lastNotification.get() + 500) {
|
||||
lastNotification.set(passedTime)
|
||||
val bandwidth = (newSize / (passedTime.toDouble() / 1000)).roundToLong()
|
||||
val thousandth = ((newSize.toDouble() / sampleSize) * 1000).roundToInt()
|
||||
log.debug { "$thousandth‰ - $bandwidth KB/sec - $newSize bytes" }
|
||||
nm.showCheckNotification(bandwidth, thousandth)
|
||||
MemoryLogger.log()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sampleSize != size.get()) log.error {
|
||||
"Checked ${size.get()} bytes, but expected $sampleSize"
|
||||
}
|
||||
val passedTime = max(System.currentTimeMillis() - startTime, 1000) // no div by zero
|
||||
val bandwidth = size.get() / (passedTime.toDouble() / 1000).roundToLong()
|
||||
checkerResult = if (badChunks.isEmpty() && handleSize == snapshots.size && handleSize > 0) {
|
||||
nm.onCheckComplete(size.get(), bandwidth)
|
||||
CheckerResult.Success(snapshots, percent, size.get())
|
||||
} else {
|
||||
nm.onCheckFinishedWithError(size.get(), bandwidth)
|
||||
CheckerResult.Error(handleSize, snapshots, badChunks)
|
||||
}
|
||||
this.snapshots = null
|
||||
}
|
||||
|
||||
fun clear() {
|
||||
log.info { "Clearing..." }
|
||||
snapshots = null
|
||||
checkerResult = null
|
||||
}
|
||||
|
||||
private fun getBlobSample(
|
||||
snapshots: List<Snapshot>,
|
||||
percent: Int,
|
||||
): List<ChunkIdBlobPair> {
|
||||
// split up blobs for app data and for APKs (use blob.id as key to prevent double counting)
|
||||
val appBlobs = mutableMapOf<ByteString, ChunkIdBlobPair>()
|
||||
val apkBlobs = mutableMapOf<ByteString, ChunkIdBlobPair>()
|
||||
snapshots.forEach { snapshot ->
|
||||
val appChunkIds = snapshot.appsMap.flatMap { it.value.chunkIdsList.hexFromProto() }
|
||||
val apkChunkIds = snapshot.appsMap.flatMap {
|
||||
it.value.apk.splitsList.flatMap { split -> split.chunkIdsList.hexFromProto() }
|
||||
}
|
||||
appChunkIds.forEach { chunkId ->
|
||||
val blob = snapshot.blobsMap[chunkId] ?: error("No Blob for chunkId")
|
||||
appBlobs[blob.id] = ChunkIdBlobPair(chunkId, blob)
|
||||
}
|
||||
apkChunkIds.forEach { chunkId ->
|
||||
val blob = snapshot.blobsMap[chunkId] ?: error("No Blob for chunkId")
|
||||
apkBlobs[blob.id] = ChunkIdBlobPair(chunkId, blob)
|
||||
}
|
||||
}
|
||||
// calculate sizes
|
||||
val appSize = appBlobs.values.sumOf { it.blob.length.toLong() }
|
||||
val apkSize = apkBlobs.values.sumOf { it.blob.length.toLong() }
|
||||
// let's assume it is unlikely that app data and APKs have blobs in common
|
||||
val totalSize = appSize + apkSize
|
||||
log.info { "Got ${appBlobs.size + apkBlobs.size} blobs worth $totalSize bytes to check." }
|
||||
|
||||
// calculate target sizes (how much do we want to check)
|
||||
val targetSize = (totalSize * (percent.toDouble() / 100)).roundToLong()
|
||||
val appTargetSize = min((targetSize * 0.75).roundToLong(), appSize) // 75% of targetSize
|
||||
log.info { "Sampling $targetSize bytes of which $appTargetSize bytes for apps." }
|
||||
|
||||
val blobSample = mutableListOf<ChunkIdBlobPair>()
|
||||
var currentSize = 0L
|
||||
// check apps first until we reach their target size
|
||||
val appIterator = appBlobs.values.shuffled().iterator() // random app blob iterator
|
||||
while (currentSize < appTargetSize && appIterator.hasNext()) {
|
||||
val pair = appIterator.next()
|
||||
blobSample.add(pair)
|
||||
currentSize += pair.blob.length
|
||||
}
|
||||
// now check APKs until we reach total targetSize
|
||||
val apkIterator = apkBlobs.values.shuffled().iterator() // random APK blob iterator
|
||||
while (currentSize < targetSize && apkIterator.hasNext()) {
|
||||
val pair = apkIterator.next()
|
||||
blobSample.add(pair)
|
||||
currentSize += pair.blob.length
|
||||
}
|
||||
return blobSample
|
||||
}
|
||||
|
||||
private suspend fun checkBlob(chunkId: String, blob: Blob) {
|
||||
val messageDigest = MessageDigest.getInstance("SHA-256")
|
||||
val storageId = blob.id.hexFromProto()
|
||||
val handle = AppBackupFileType.Blob(crypto.repoId, storageId)
|
||||
val readChunkId = loader.loadFile(handle, null).use { inputStream ->
|
||||
DigestInputStream(inputStream, messageDigest).use { digestStream ->
|
||||
digestStream.readAllBytes()
|
||||
digestStream.messageDigest.digest().toHexString()
|
||||
}
|
||||
}
|
||||
if (readChunkId != chunkId) throw GeneralSecurityException("ChunkId doesn't match")
|
||||
}
|
||||
}
|
||||
|
||||
data class ChunkIdBlobPair(val chunkId: String, val blob: Blob) : Comparable<ChunkIdBlobPair> {
|
||||
override fun compareTo(other: ChunkIdBlobPair): Int {
|
||||
return chunkId.compareTo(other.chunkId)
|
||||
}
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.repo
|
||||
|
||||
import com.stevesoltys.seedvault.proto.Snapshot
|
||||
|
||||
sealed class CheckerResult {
|
||||
data class Success(
|
||||
val snapshots: List<Snapshot>,
|
||||
val percent: Int,
|
||||
val size: Long,
|
||||
) : CheckerResult()
|
||||
|
||||
data class Error(
|
||||
/**
|
||||
* This number is greater than the size of [snapshots],
|
||||
* if we could not read/decrypt one or more snapshots.
|
||||
*/
|
||||
val existingSnapshots: Int,
|
||||
val snapshots: List<Snapshot>,
|
||||
/**
|
||||
* The list of chunkIDs that had errors.
|
||||
*/
|
||||
val errorChunkIdBlobPairs: Set<ChunkIdBlobPair>,
|
||||
) : CheckerResult() {
|
||||
val goodSnapshots: List<Snapshot>
|
||||
val badSnapshots: List<Snapshot>
|
||||
|
||||
init {
|
||||
val good = mutableListOf<Snapshot>()
|
||||
val bad = mutableListOf<Snapshot>()
|
||||
val errorChunkIds = errorChunkIdBlobPairs.map { it.chunkId }.toSet()
|
||||
snapshots.forEach { snapshot ->
|
||||
val badChunkIds = snapshot.blobsMap.keys.intersect(errorChunkIds)
|
||||
if (badChunkIds.isEmpty()) {
|
||||
// snapshot doesn't contain chunks with erroneous blobs
|
||||
good.add(snapshot)
|
||||
} else {
|
||||
// snapshot may contain chunks with erroneous blobs, check deeper
|
||||
val isBad = badChunkIds.any { chunkId ->
|
||||
val blob = snapshot.blobsMap[chunkId] ?: error("No blob for chunkId")
|
||||
// is this chunkId/blob pair in errorChunkIdBlobPairs?
|
||||
errorChunkIdBlobPairs.any { pair ->
|
||||
pair.chunkId == chunkId && pair.blob == blob
|
||||
}
|
||||
}
|
||||
if (isBad) bad.add(snapshot) else good.add(snapshot)
|
||||
}
|
||||
}
|
||||
goodSnapshots = good
|
||||
badSnapshots = bad
|
||||
}
|
||||
}
|
||||
|
||||
data class GeneralError(val e: Exception) : CheckerResult()
|
||||
}
|
|
@ -1,113 +0,0 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.repo
|
||||
|
||||
import com.github.luben.zstd.ZstdInputStream
|
||||
import com.stevesoltys.seedvault.backend.BackendManager
|
||||
import com.stevesoltys.seedvault.crypto.Crypto
|
||||
import com.stevesoltys.seedvault.header.UnsupportedVersionException
|
||||
import com.stevesoltys.seedvault.header.VERSION
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.calyxos.seedvault.core.backends.AppBackupFileType
|
||||
import org.calyxos.seedvault.core.toHexString
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.io.SequenceInputStream
|
||||
import java.security.GeneralSecurityException
|
||||
import java.util.Enumeration
|
||||
|
||||
internal class Loader(
|
||||
private val crypto: Crypto,
|
||||
private val backendManager: BackendManager,
|
||||
) {
|
||||
|
||||
private val log = KotlinLogging.logger {}
|
||||
|
||||
/**
|
||||
* Downloads the given [fileHandle], decrypts and decompresses its content
|
||||
* and returns the content as a decrypted and decompressed stream.
|
||||
*
|
||||
* Attention: The responsibility with closing the returned stream lies with the caller.
|
||||
*
|
||||
* @param cacheFile if non-null, the ciphertext of the loaded file will be cached there
|
||||
* for later loading with [loadFile].
|
||||
*/
|
||||
@Throws(GeneralSecurityException::class, UnsupportedVersionException::class, IOException::class)
|
||||
suspend fun loadFile(fileHandle: AppBackupFileType, cacheFile: File? = null): InputStream {
|
||||
val expectedHash = when (fileHandle) {
|
||||
is AppBackupFileType.Snapshot -> fileHandle.hash
|
||||
is AppBackupFileType.Blob -> fileHandle.name
|
||||
}
|
||||
return loadFromStream(backendManager.backend.load(fileHandle), expectedHash, cacheFile)
|
||||
}
|
||||
|
||||
/**
|
||||
* The responsibility with closing the returned stream lies with the caller.
|
||||
*/
|
||||
@Throws(GeneralSecurityException::class, UnsupportedVersionException::class, IOException::class)
|
||||
fun loadFile(file: File, expectedHash: String): InputStream {
|
||||
return loadFromStream(file.inputStream(), expectedHash)
|
||||
}
|
||||
|
||||
@Throws(GeneralSecurityException::class, UnsupportedVersionException::class, IOException::class)
|
||||
suspend fun loadFiles(handles: List<AppBackupFileType>): InputStream {
|
||||
val enumeration: Enumeration<InputStream> = object : Enumeration<InputStream> {
|
||||
val iterator = handles.iterator()
|
||||
|
||||
override fun hasMoreElements(): Boolean {
|
||||
return iterator.hasNext()
|
||||
}
|
||||
|
||||
override fun nextElement(): InputStream {
|
||||
return runBlocking { loadFile(iterator.next()) }
|
||||
}
|
||||
}
|
||||
return SequenceInputStream(enumeration)
|
||||
}
|
||||
|
||||
@Throws(GeneralSecurityException::class, UnsupportedVersionException::class, IOException::class)
|
||||
private fun loadFromStream(
|
||||
inputStream: InputStream,
|
||||
expectedHash: String,
|
||||
cacheFile: File? = null,
|
||||
): InputStream {
|
||||
// We load the entire ciphertext into memory,
|
||||
// so we can check the SHA-256 hash before decrypting and parsing the data.
|
||||
val cipherText = inputStream.use { it.readAllBytes() }
|
||||
// check SHA-256 hash first thing
|
||||
val sha256 = crypto.sha256(cipherText).toHexString()
|
||||
if (sha256 != expectedHash) {
|
||||
throw HashMismatchException("File had wrong SHA-256 hash: $expectedHash")
|
||||
}
|
||||
// check that we can handle the version of that snapshot
|
||||
val version = cipherText[0]
|
||||
if (version <= 1) throw GeneralSecurityException("Unexpected version: $version")
|
||||
if (version > VERSION) throw UnsupportedVersionException(version)
|
||||
// cache cipherText in cacheFile, if existing
|
||||
try {
|
||||
cacheFile?.outputStream()?.use { outputStream ->
|
||||
outputStream.write(cipherText)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
log.error(e) { "Error writing cache file $cacheFile: " }
|
||||
cacheFile?.delete()
|
||||
}
|
||||
// get associated data for version, used for authenticated decryption
|
||||
val ad = crypto.getAdForVersion(version)
|
||||
// skip first version byte when creating cipherText stream
|
||||
val byteStream = ByteArrayInputStream(cipherText, 1, cipherText.size - 1)
|
||||
// decrypt, de-pad and decompress cipherText stream
|
||||
val decryptingStream = crypto.newDecryptingStream(byteStream, ad)
|
||||
val paddedStream = PaddedInputStream(decryptingStream)
|
||||
return ZstdInputStream(paddedStream)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal class HashMismatchException(msg: String? = null) : GeneralSecurityException(msg)
|
|
@ -1,51 +0,0 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.repo
|
||||
|
||||
import org.calyxos.seedvault.core.toHexString
|
||||
import java.io.FilterInputStream
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
internal class PaddedInputStream(inputStream: InputStream) : FilterInputStream(inputStream) {
|
||||
|
||||
private val size: Int
|
||||
private var bytesRead: Int = 0
|
||||
|
||||
init {
|
||||
val sizeBytes = ByteArray(4)
|
||||
val bytesRead = inputStream.read(sizeBytes)
|
||||
if (bytesRead != 4) {
|
||||
throw IOException("Could not read padding size: ${sizeBytes.toHexString()}")
|
||||
}
|
||||
size = ByteBuffer.wrap(sizeBytes).getInt()
|
||||
}
|
||||
|
||||
override fun read(): Int {
|
||||
if (bytesRead >= size) return -1
|
||||
return getReadBytes(super.read())
|
||||
}
|
||||
|
||||
override fun read(b: ByteArray, off: Int, len: Int): Int {
|
||||
if (bytesRead >= size) return -1
|
||||
if (bytesRead + len >= size) {
|
||||
return getReadBytes(super.read(b, off, size - bytesRead))
|
||||
}
|
||||
return getReadBytes(super.read(b, off, len))
|
||||
}
|
||||
|
||||
override fun available(): Int {
|
||||
return size - bytesRead
|
||||
}
|
||||
|
||||
private fun getReadBytes(read: Int): Int {
|
||||
if (read == -1) return -1
|
||||
bytesRead += read
|
||||
if (bytesRead > size) return -1
|
||||
return read
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.repo
|
||||
|
||||
import kotlin.math.floor
|
||||
import kotlin.math.log2
|
||||
import kotlin.math.pow
|
||||
|
||||
object Padding {
|
||||
|
||||
/**
|
||||
* Pads the given [size] using the [Padmé algorithm](https://lbarman.ch/blog/padme/).
|
||||
*
|
||||
* @param size unpadded object length
|
||||
* @return the padded object length
|
||||
*/
|
||||
fun getPadTo(size: Int): Int {
|
||||
val e = floor(log2(size.toFloat()))
|
||||
val s = floor(log2(e)) + 1
|
||||
val lastBits = e - s
|
||||
val bitMask = (2.toFloat().pow(lastBits) - 1).toInt()
|
||||
return (size + bitMask) and bitMask.inv()
|
||||
}
|
||||
|
||||
}
|
|
@ -1,129 +0,0 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 The Calyx Institute
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.stevesoltys.seedvault.repo
|
||||
|
||||
import com.stevesoltys.seedvault.backend.BackendManager
|
||||
import com.stevesoltys.seedvault.crypto.Crypto
|
||||
import com.stevesoltys.seedvault.proto.Snapshot
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import org.calyxos.seedvault.core.backends.AppBackupFileType
|
||||
import org.calyxos.seedvault.core.backends.TopLevelFolder
|
||||
import java.security.GeneralSecurityException
|
||||
import java.time.LocalDate
|
||||
import java.time.temporal.ChronoField
|
||||
import java.time.temporal.TemporalAdjuster
|
||||
|
||||
/**
|
||||
* Cleans up old backups data that we do not need to retain.
|
||||
*/
|
||||
internal class Pruner(
|
||||
private val crypto: Crypto,
|
||||
private val backendManager: BackendManager,
|
||||
private val snapshotManager: SnapshotManager,
|
||||
private val blobCache: BlobCache,
|
||||
) {
|
||||
|
||||
private val log = KotlinLogging.logger {}
|
||||
private val folder get() = TopLevelFolder(crypto.repoId)
|
||||
|
||||
/**
|
||||
* Keeps the last 3 daily and 2 weekly snapshots (this and last week), removes all others.
|
||||
* Then removes all blobs from the backend
|
||||
* that are not referenced anymore by remaining snapshots.
|
||||
*/
|
||||
suspend fun removeOldSnapshotsAndPruneUnusedBlobs() {
|
||||
// get snapshots currently available on backend
|
||||
val snapshotHandles = mutableListOf<AppBackupFileType.Snapshot>()
|
||||
backendManager.backend.list(folder, AppBackupFileType.Snapshot::class) { fileInfo ->
|
||||
snapshotHandles.add(fileInfo.fileHandle as AppBackupFileType.Snapshot)
|
||||
}
|
||||
// load and parse snapshots
|
||||
val snapshotMap = mutableMapOf<Long, AppBackupFileType.Snapshot>()
|
||||
val snapshots = mutableListOf<Snapshot>()
|
||||
snapshotHandles.forEach { handle ->
|
||||
try {
|
||||
val snapshot = snapshotManager.loadSnapshot(handle)
|
||||
snapshotMap[snapshot.token] = handle
|
||||
snapshots.add(snapshot)
|
||||
} catch (e: GeneralSecurityException) {
|
||||
log.error(e) { "Error loading snapshot $handle, will remove: " }
|
||||
snapshotManager.removeSnapshot(handle)
|
||||
} // other exceptions (like IOException) are allowed to bubble up, so we try again
|
||||
}
|
||||
// find out which snapshots to keep
|
||||
val toKeep = getTokenToKeep(snapshotMap.keys)
|
||||
log.info { "Found ${snapshots.size} snapshots, keeping ${toKeep.size}." }
|
||||
// remove snapshots we aren't keeping
|
||||
snapshotMap.forEach { (token, handle) ->
|
||||
if (token !in toKeep) {
|
||||
log.info { "Removing snapshot $token ${handle.name}" }
|
||||
snapshotManager.removeSnapshot(handle)
|
||||
}
|
||||
}
|
||||
// prune unused blobs
|
||||
val keptSnapshots = snapshots.filter { it.token in toKeep }
|
||||
pruneUnusedBlobs(keptSnapshots)
|
||||
}
|
||||
|
||||
private suspend fun pruneUnusedBlobs(snapshots: List<Snapshot>) {
|
||||
val blobHandles = mutableListOf<AppBackupFileType.Blob>()
|
||||
backendManager.backend.list(folder, AppBackupFileType.Blob::class) { fileInfo ->
|
||||
blobHandles.add(fileInfo.fileHandle as AppBackupFileType.Blob)
|
||||
}
|
||||
val usedBlobIds = snapshots.flatMap { snapshot ->
|
||||
snapshot.blobsMap.values.map { blob ->
|
||||
blob.id.hexFromProto()
|
||||
}
|
||||
}.toSet()
|
||||
val removedBlobs = mutableSetOf<String>()
|
||||
try {
|
||||
blobHandles.forEach { blobHandle ->
|
||||
if (blobHandle.name !in usedBlobIds) {
|
||||
log.info { "Removing blob ${blobHandle.name}" }
|
||||
backendManager.backend.remove(blobHandle)
|
||||
removedBlobs.add(blobHandle.name)
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (removedBlobs.isNotEmpty()) blobCache.onBlobsRemoved(removedBlobs)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getTokenToKeep(tokenSet: Set<Long>): Set<Long> {
|
||||
if (tokenSet.size <= 3) return tokenSet // keep at least 3 snapshots
|
||||
val tokenList = tokenSet.sortedDescending()
|
||||
val toKeep = mutableSetOf<Long>()
|
||||
toKeep += getToKeep(tokenList, 3) // 3 daily
|
||||
toKeep += getToKeep(tokenList, 2) { temporal -> // keep one from this and last week
|
||||
temporal.with(ChronoField.DAY_OF_WEEK, 1)
|
||||
}
|
||||
// ensure we keep at least three snapshots
|
||||
val tokenIterator = tokenList.iterator()
|
||||
while (toKeep.size < 3 && tokenIterator.hasNext()) toKeep.add(tokenIterator.next())
|
||||
return toKeep
|
||||
}
|
||||
|
||||
private fun getToKeep(
|
||||
tokenList: List<Long>,
|
||||
keep: Int,
|
||||
temporalAdjuster: TemporalAdjuster? = null,
|
||||
): List<Long> {
|
||||
val toKeep = mutableListOf<Long>()
|
||||
if (keep == 0) return toKeep
|
||||
var last: LocalDate? = null
|
||||
for (token in tokenList) {
|
||||
val date = LocalDate.ofEpochDay(token / 1000 / 60 / 60 / 24)
|
||||
val period = if (temporalAdjuster == null) date else date.with(temporalAdjuster)
|
||||
if (period != last) {
|
||||
toKeep.add(token)
|
||||
if (toKeep.size >= keep) break
|
||||
last = period
|
||||
}
|
||||
}
|
||||
return toKeep
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue