Skip to content

feat: Allow disabling kDrive display in files#2015

Open
aymericmariaux wants to merge 4 commits intomainfrom
disable-kdrive-in-file-app
Open

feat: Allow disabling kDrive display in files#2015
aymericmariaux wants to merge 4 commits intomainfrom
disable-kdrive-in-file-app

Conversation

@aymericmariaux
Copy link
Copy Markdown

No description provided.

Copilot AI review requested due to automatic review settings April 28, 2026 13:07
@aymericmariaux aymericmariaux force-pushed the disable-kdrive-in-file-app branch from fb2ddb0 to 1cb1e52 Compare April 28, 2026 13:11
@aymericmariaux aymericmariaux marked this pull request as draft April 28, 2026 13:24
@aymericmariaux aymericmariaux marked this pull request as ready for review April 28, 2026 13:24
@aymericmariaux aymericmariaux force-pushed the disable-kdrive-in-file-app branch 2 times, most recently from 0480d50 to 1cb1e52 Compare April 29, 2026 11:29
@aymericmariaux aymericmariaux requested review from NicolasBourdin88 and Copilot and removed request for NicolasBourdin88 and Copilot April 29, 2026 12:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new Security settings screen that lets users toggle whether kDrive’s DocumentsProvider is exposed to the system “Files” app (and other third‑party file pickers), and wires that screen into the existing Settings navigation.

Changes:

  • Added “Show in Files” strings (with multiple localizations) and a new Security settings screen UI.
  • Added a new SecuritySettingsFragment and navigation route from SettingsFragment.
  • Implemented a persisted “provider disabled” flag in CloudStorageProvider and enforced it in queryChildDocuments() / openDocument().

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
app/src/main/res/values/strings.xml Adds new strings for the “Show in Files” toggle and provider-disabled error.
app/src/main/res/values-*/strings.xml Adds translations for the new provider toggle/error strings (sv/pt/pl/nl/nb/it/fr/fi/es/el/de/da).
app/src/main/res/navigation/main_navigation.xml Adds navigation action from Settings to the new Security settings fragment; registers the fragment destination.
app/src/main/res/layout/fragment_settings_security.xml New Security settings screen layout containing app lock and provider toggle.
app/src/main/res/layout/fragment_settings.xml Replaces the previous “App Security” row with a chevron row leading to Security settings.
app/src/main/java/com/infomaniak/drive/ui/menu/settings/SettingsFragment.kt Updates Settings click handling to navigate to the new Security settings screen.
app/src/main/java/com/infomaniak/drive/ui/menu/settings/SecuritySettingsFragment.kt New fragment controlling app-lock entry and “Show in Files” provider toggle.
app/src/main/java/com/infomaniak/drive/ui/menu/settings/AppSecuritySettingsActivity.kt Forces provider disable when enabling app lock.
app/src/main/java/com/infomaniak/drive/data/documentprovider/CloudStorageProvider.kt Adds shared-pref flag + enforcement for disabled provider behavior and root refresh notifications.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/src/main/res/layout/fragment_settings.xml Outdated
Comment thread app/src/main/res/layout/fragment_settings_security.xml Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 20 out of 20 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/src/main/res/navigation/main_navigation.xml Outdated
Prevents contentProviderSwitch from re-triggering its listener in onResume, avoiding redundant calls to CloudStorageProvider.setDisabled() and notifyRootsChanged().
@aymericmariaux aymericmariaux requested a review from Copilot April 30, 2026 07:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 20 out of 20 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}

fun setDisabled(context: Context, disabled: Boolean) {
context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE).edit { putBoolean(KEY_PROVIDER_DISABLED, disabled) }
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SharedPreferences.edit { ... } uses apply() by default (async). Calling notifyRootsChanged(context) immediately after can race with persistence, so the provider may be re-queried before the new flag is stored. Make the write synchronous (e.g., commit=true / commit()) or otherwise ensure the preference is persisted before notifying roots changed.

Suggested change
context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE).edit { putBoolean(KEY_PROVIDER_DISABLED, disabled) }
context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE).edit(commit = true) {
putBoolean(KEY_PROVIDER_DISABLED, disabled)
}

Copilot uses AI. Check for mistakes.
Comment on lines 296 to 301
override fun openDocument(documentId: String, mode: String, signal: CancellationSignal?): ParcelFileDescriptor? {
SentryLog.d(TAG, "openDocument(), id=$documentId, mode=$mode, signalIsCancelled: ${signal?.isCanceled}")
if (isProviderDisabled()) {
throw SecurityException(context?.getString(R.string.fileProviderExtensionError))
}
val context = context ?: return null
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the provider is disabled by a user preference, throwing SecurityException can lead to harsher client behavior than necessary (some clients treat it as an authorization failure). Consider throwing FileNotFoundException (or an appropriate DocumentsContract-aligned exception) with the same message to better reflect 'content unavailable' rather than 'permission denied'.

Copilot uses AI. Check for mistakes.
Comment on lines +66 to +70
contentProviderSwitch.isChecked = !CloudStorageProvider.isDisabled(appCtx)

contentProviderSwitch.setOnCheckedChangeListener { _, isChecked ->
CloudStorageProvider.setDisabled(appCtx, disabled = !isChecked)
}
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In onResume(), assigning contentProviderSwitch.isChecked may trigger the existing setOnCheckedChangeListener, causing redundant preference writes and repeated notifyRootsChanged() calls. A common fix is to temporarily clear/reinstall the listener around the assignment, or only assign when the value actually changes.

Copilot uses AI. Check for mistakes.
@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants