Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.annotation.VisibleForTesting
import com.nextcloud.client.core.Clock
import com.nextcloud.client.preferences.AppPreferences
import com.owncloud.android.MainApp
import com.owncloud.android.authentication.PassCodeManager.Companion.PASS_CODE_TIMEOUT
import com.owncloud.android.ui.activity.PassCodeActivity
import com.owncloud.android.ui.activity.RequestCredentialsActivity
import com.owncloud.android.ui.activity.SettingsActivity
Expand Down Expand Up @@ -85,6 +86,19 @@ class PassCodeManager(private val preferences: AppPreferences, private val clock
return askedForPin
}

fun isLocked(activity: Activity): Boolean {
var askedForPin = false
val timestamp = preferences.lockTimestamp

if (!isExemptActivity(activity)) {
val passcodeRequested = passCodeShouldBeRequested(timestamp)
val credentialsRequested = deviceCredentialsShouldBeRequested(timestamp, activity)
askedForPin = passcodeRequested || credentialsRequested
}

return askedForPin
}

private fun requestPasscode(activity: Activity) {
val i = Intent(MainApp.getAppContext(), PassCodeActivity::class.java).apply {
action = PassCodeActivity.ACTION_CHECK
Expand Down Expand Up @@ -121,7 +135,7 @@ class PassCodeManager(private val preferences: AppPreferences, private val clock
@VisibleForTesting
fun passCodeShouldBeRequested(timestamp: Long): Boolean = shouldBeLocked(timestamp) && isPassCodeEnabled()

private fun isPassCodeEnabled(): Boolean = SettingsActivity.LOCK_PASSCODE == preferences.lockPreference
fun isPassCodeEnabled(): Boolean = SettingsActivity.LOCK_PASSCODE == preferences.lockPreference

private fun deviceCredentialsShouldBeRequested(timestamp: Long, activity: Activity): Boolean =
shouldBeLocked(timestamp) && deviceCredentialsAreEnabled(activity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ import com.nextcloud.utils.fileNameValidator.FileNameValidator.checkFolderPath
import com.nextcloud.utils.view.FastScrollUtils
import com.owncloud.android.MainApp
import com.owncloud.android.R
import com.owncloud.android.authentication.PassCodeManager
import com.owncloud.android.databinding.FilesBinding
import com.owncloud.android.datamodel.FileDataStorageManager
import com.owncloud.android.datamodel.OCFile
Expand Down Expand Up @@ -253,6 +254,9 @@ class FileDisplayActivity :
@Inject
lateinit var syncedFolderProvider: SyncedFolderProvider

@Inject
lateinit var passCodeManager: PassCodeManager

/**
* Indicates whether the downloaded file should be previewed immediately. Since `FileDownloadWorker` can be
* triggered from multiple sources, this helps determine if an automatic preview is needed after download.
Expand Down Expand Up @@ -628,6 +632,10 @@ class FileDisplayActivity :

@SuppressLint("UnsafeIntentLaunch")
private fun handleCommonIntents(intent: Intent) {
if (passCodeManager.isPassCodeEnabled() && passCodeManager.isLocked(this)) {
return
}

when (intent.action) {
Intent.ACTION_VIEW -> handleOpenFileViaIntent(intent)

Expand Down
Loading