Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,6 @@ tasks.named("check").configure {
val kspConfiguration = "ksp"
val kspAndroidTestConfiguration = "kspAndroidTest"
val gplayImplementationConfiguration = "gplayImplementation"
val huaweiImplementationConfiguration = "huaweiImplementation"
val qaImplementationConfiguration = "qaImplementation"
val appScanConfigurations = listOf(
gplayImplementationConfiguration,
huaweiImplementationConfiguration,
qaImplementationConfiguration
)

dependencies {
// region Nextcloud library
Expand Down Expand Up @@ -443,11 +436,8 @@ dependencies {
implementation(libs.emoji.google)
// endregion

// region AppScan, document scanner not available on FDroid (generic) due to OpenCV binaries
// To enable the feature for another variant, add its "<variant>Implementation" here.
appScanConfigurations.forEach { configuration ->
add(configuration, project(":appscan"))
}
// region FairScan
implementation(libs.fairscan)
Comment thread
PhilLab marked this conversation as resolved.
// endregion

// region SpotBugs
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import android.os.Looper
import android.view.ViewGroup
import android.webkit.SslErrorHandler
import android.widget.TextView
import androidx.activity.result.contract.ActivityResultContract
import androidx.fragment.app.DialogFragment
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.launchActivity
Expand All @@ -37,7 +36,6 @@ import com.nextcloud.android.lib.resources.profile.HoverCard
import com.nextcloud.client.account.RegisteredUser
import com.nextcloud.client.account.Server
import com.nextcloud.client.device.DeviceInfo
import com.nextcloud.client.documentscan.AppScanOptionalFeature
import com.nextcloud.ui.dialog.account.ChooseAccountDialogFragment
import com.nextcloud.ui.dialog.account.ChooseAccountDialogFragment.Companion.newInstance
import com.nextcloud.ui.dialog.account.onlineStatus.SetOnlineStatusBottomSheet
Expand Down Expand Up @@ -433,10 +431,7 @@ class DialogFragmentIT : AbstractIT() {
override fun newSpreadsheet() = Unit
override fun newPresentation() = Unit
override fun directCameraUpload() = Unit
override fun scanDocUpload() = Unit
override fun scanDocUploadFromApp() = Unit
override val isScanDocUploadFromAppAvailable: Boolean
get() = false
override fun showTemplate(creator: Creator?, headline: String?) = Unit
override fun createRichWorkspace() = Unit
}
Expand Down Expand Up @@ -503,11 +498,6 @@ class DialogFragmentIT : AbstractIT() {
}
CapabilityUtils.updateCapability(capability)

val appScanOptionalFeature: AppScanOptionalFeature = object : AppScanOptionalFeature() {
override fun getScanContract(): ActivityResultContract<Unit, String?> =
throw UnsupportedOperationException("Document scan is not available")
}

val viewThemeUtils = ViewThemeUtils(
materialSchemesForCurrentUser,
ColorUtil(targetContext)
Expand All @@ -523,8 +513,7 @@ class DialogFragmentIT : AbstractIT() {
ocFile,
fda.themeUtils,
viewThemeUtils,
editorUtils,
appScanOptionalFeature
editorUtils
)

sut.show()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* Nextcloud - Android Client
*
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

package com.owncloud.android.ui.fragment

import android.app.Activity
import android.app.Instrumentation
import android.content.Intent
import android.os.SystemClock
import androidx.test.core.app.launchActivity
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.intent.Intents.intending
import androidx.test.espresso.intent.matcher.IntentMatchers.hasAction
import com.nextcloud.client.account.UserAccountManagerImpl
import com.nextcloud.test.TestActivity
import com.owncloud.android.AbstractIT
import com.owncloud.android.datamodel.UploadsStorageManager
import com.owncloud.android.db.OCUpload
import com.nextcloud.client.jobs.upload.FileUploadWorker
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Assert.fail
import org.junit.Before
import org.junit.Test

class OCFileListFragmentScanIT : AbstractIT() {

private lateinit var uploadsStorageManager: UploadsStorageManager

@Before
fun setUp() {
Intents.init()
uploadsStorageManager = UploadsStorageManager(
UserAccountManagerImpl.fromContext(targetContext),
targetContext.contentResolver
)
uploadsStorageManager.removeUploads(account.name)
}

@After
fun tearDown() {
Intents.release()
uploadsStorageManager.removeUploads(account.name)
}

@Test
fun scanStartsEmbeddedFairScanWithAutoDeletionDisabled() {
scan(Activity.RESULT_CANCELED, null)

val scanIntent = Intents.getIntents().single { it.action == FAIRSCAN_ACTION }
assertEquals(FAIRSCAN_ACTIVITY, scanIntent.component?.className)
assertEquals(FAIRSCAN_ACTION, scanIntent.action)
assertTrue(scanIntent.getBooleanExtra(FAIRSCAN_EXTRA_DISABLE_AUTO_DELETION, false))
}

@Test
fun cancelledScanDoesNotUpload() {
scan(Activity.RESULT_CANCELED, null)
SystemClock.sleep(NO_UPLOAD_GRACE_MILLIS)

assertEquals(0, uploadsStorageManager.getAllStoredUploads().size)
}

@Test
fun embeddedScanResultIsQueuedForUploadWithMoveBehaviour() {
val pdf = createFile("scan.pdf", 1)
scan(Activity.RESULT_OK, Intent().putExtra(FAIRSCAN_EXTRA_PDF_PATH, pdf.absolutePath))

val upload = waitForUpload()
assertEquals(pdf.absolutePath, upload.localPath)
assertTrue(upload.remotePath.startsWith("/"))
assertTrue(upload.remotePath.endsWith(".pdf"))
assertEquals(FileUploadWorker.LOCAL_BEHAVIOUR_MOVE, upload.localAction)
assertEquals(account.name, upload.accountName)
}

private fun scan(resultCode: Int, data: Intent?) {
launchActivity<TestActivity>().use { scenario ->
intending(hasAction(FAIRSCAN_ACTION)).respondWith(Instrumentation.ActivityResult(resultCode, data))
scenario.onActivity { activity ->
val fragment = OCFileListFragment()
activity.addFragment(fragment)
activity.supportFragmentManager.executePendingTransactions()
fragment.scanDocUploadFromApp()
}
SystemClock.sleep(RESULT_DELIVERY_MILLIS)
}
}

private fun waitForUpload(): OCUpload {
val deadline = SystemClock.elapsedRealtime() + WAIT_TIMEOUT_MILLIS
while (SystemClock.elapsedRealtime() < deadline) {
uploadsStorageManager.getAllStoredUploads().firstOrNull()?.let { return it }
SystemClock.sleep(WAIT_POLL_INTERVAL_MILLIS)
}
fail("No upload was queued for the scanned PDF")
error("unreachable")
}

private companion object {
const val FAIRSCAN_ACTIVITY = "org.fairscan.app.MainActivity"
const val FAIRSCAN_ACTION = "org.fairscan.app.action.SCAN_TO_PDF"
const val FAIRSCAN_EXTRA_DISABLE_AUTO_DELETION = "org.fairscan.app.extra.DISABLE_AUTO_DELETION"
const val FAIRSCAN_EXTRA_PDF_PATH = "org.fairscan.app.extra.PDF_PATH"
const val RESULT_DELIVERY_MILLIS = 1_000L
const val NO_UPLOAD_GRACE_MILLIS = 1_000L
const val WAIT_TIMEOUT_MILLIS = 10_000L
const val WAIT_POLL_INTERVAL_MILLIS = 200L
}
}

This file was deleted.

This file was deleted.

14 changes: 9 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="29"
tools:ignore="ScopedStorage" />
tools:ignore="ScopedStorage"
tools:replace="android:maxSdkVersion" />
<uses-permission
android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
Expand Down Expand Up @@ -131,6 +132,13 @@
android:name="android.content.APP_RESTRICTIONS"
android:resource="@xml/app_config" />

<meta-data android:name="org.fairscan.app.STORAGE_SUBDIR"
android:value="fairscan" />

<meta-data
android:name="org.fairscan.app.SHOW_SUPPORT"
android:value="false" />

<activity
android:name="com.nextcloud.ui.composeActivity.ComposeActivity"
android:exported="true"
Expand Down Expand Up @@ -666,10 +674,6 @@
android:name=".ui.preview.pdf.PreviewBitmapActivity"
android:exported="false"
android:theme="@style/Theme.ownCloud.OverlayGrey" />
<activity
android:name="com.nextcloud.client.documentscan.DocumentScanActivity"
android:exported="false"
android:theme="@style/Theme.ownCloud.Toolbar" />
<activity
android:name="com.nextcloud.client.editimage.EditImageActivity"
android:exported="false"
Expand Down
Loading
Loading