-
Notifications
You must be signed in to change notification settings - Fork 18
feat: Allow disabling kDrive display in files #2015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
1cb1e52
fb4eb1b
473369a
196b5b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -34,6 +34,7 @@ import android.provider.DocumentsContract | |||||||||
| import android.provider.DocumentsProvider | ||||||||||
| import android.provider.Settings | ||||||||||
| import androidx.core.app.NotificationManagerCompat | ||||||||||
| import androidx.core.content.edit | ||||||||||
| import androidx.core.net.toUri | ||||||||||
| import androidx.core.os.bundleOf | ||||||||||
| import com.infomaniak.core.common.cancellable | ||||||||||
|
|
@@ -89,6 +90,10 @@ class CloudStorageProvider : DocumentsProvider() { | |||||||||
| private val cloudScope = CoroutineScope( | ||||||||||
| CoroutineName("CloudStorage") + Executors.newSingleThreadExecutor().asCoroutineDispatcher() | ||||||||||
| ) | ||||||||||
| private fun isProviderDisabled(): Boolean { | ||||||||||
| val ctx = context ?: return true | ||||||||||
| return isDisabled(ctx) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Indicates whether the current platform is Chrome OS. | ||||||||||
|
|
@@ -176,6 +181,11 @@ class CloudStorageProvider : DocumentsProvider() { | |||||||||
| override fun queryChildDocuments(parentDocumentId: String, projection: Array<out String>?, sortOrder: String?): Cursor { | ||||||||||
| val cursor = DocumentCursor(projection ?: DEFAULT_DOCUMENT_PROJECTION, isAutoCloseableJob = false) | ||||||||||
|
|
||||||||||
| if (isProviderDisabled()) { | ||||||||||
| cursor.extras = bundleOf(DocumentsContract.EXTRA_ERROR to (context?.getString(R.string.fileProviderExtensionError))) | ||||||||||
| return cursor | ||||||||||
| } | ||||||||||
|
aymericmariaux marked this conversation as resolved.
|
||||||||||
|
|
||||||||||
| val uri = DocumentCursor.createUri(context, parentDocumentId) | ||||||||||
| val isNewJob = uri != oldQueryChildUri || needRefresh | ||||||||||
|
|
||||||||||
|
|
@@ -285,6 +295,9 @@ class CloudStorageProvider : DocumentsProvider() { | |||||||||
|
|
||||||||||
| 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)) | ||||||||||
| } | ||||||||||
|
aymericmariaux marked this conversation as resolved.
|
||||||||||
| val context = context ?: return null | ||||||||||
|
Comment on lines
296
to
301
|
||||||||||
|
|
||||||||||
| fun getRemoteFile(localFile: File?, fileId: Int, driveId: Int): File? { | ||||||||||
|
|
@@ -863,6 +876,8 @@ class CloudStorageProvider : DocumentsProvider() { | |||||||||
| private const val DRIVE_SEPARATOR = "@" | ||||||||||
| private const val MY_SHARES_FOLDER_ID = -1 | ||||||||||
| private const val SHARED_WITHME_FOLDER_ID = -2 | ||||||||||
| private const val PREFS_NAME = "cloud_storage_provider" | ||||||||||
| private const val KEY_PROVIDER_DISABLED = "provider_disabled" | ||||||||||
|
|
||||||||||
| private val SHARED_URI_REGEX = Regex("\\d+/-\\d+/.+$DRIVE_SEPARATOR\\d+/\\d+") | ||||||||||
|
|
||||||||||
|
|
@@ -964,6 +979,15 @@ class CloudStorageProvider : DocumentsProvider() { | |||||||||
| comeFromSharedWithMe(documentId) | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| fun isDisabled(context: Context): Boolean { | ||||||||||
| return context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE).getBoolean(KEY_PROVIDER_DISABLED, false) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| fun setDisabled(context: Context, disabled: Boolean) { | ||||||||||
| context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE).edit { putBoolean(KEY_PROVIDER_DISABLED, disabled) } | ||||||||||
|
||||||||||
| 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) | |
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /* | ||
| * Infomaniak kDrive - Android | ||
| * Copyright (C) 2022-2026 Infomaniak Network SA | ||
| * | ||
| * 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/>. | ||
| */ | ||
| package com.infomaniak.drive.ui.menu.settings | ||
|
|
||
| import android.os.Bundle | ||
| import android.view.LayoutInflater | ||
| import android.view.View | ||
| import android.view.ViewGroup | ||
| import androidx.core.view.isGone | ||
| import androidx.core.view.isVisible | ||
| import androidx.fragment.app.Fragment | ||
| import androidx.navigation.fragment.findNavController | ||
| import com.infomaniak.core.applock.AppLockManager | ||
| import com.infomaniak.core.fragmentnavigation.safelyNavigate | ||
| import com.infomaniak.core.legacy.utils.safeBinding | ||
| import com.infomaniak.drive.MatomoDrive.MatomoName | ||
| import com.infomaniak.drive.MatomoDrive.trackSettingsEvent | ||
| import com.infomaniak.drive.R | ||
| import com.infomaniak.drive.data.documentprovider.CloudStorageProvider | ||
| import com.infomaniak.drive.data.models.AppSettings | ||
| import com.infomaniak.drive.databinding.FragmentSettingsSecurityBinding | ||
| import com.infomaniak.drive.extensions.enableEdgeToEdge | ||
| import splitties.init.appCtx | ||
|
|
||
| class SecuritySettingsFragment : Fragment() { | ||
|
|
||
| private var binding: FragmentSettingsSecurityBinding by safeBinding() | ||
|
|
||
| override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { | ||
| return FragmentSettingsSecurityBinding.inflate(inflater, container, false).also { binding = it }.root | ||
| } | ||
|
|
||
| override fun onViewCreated(view: View, savedInstanceState: Bundle?) = with(binding) { | ||
| super.onViewCreated(view, savedInstanceState) | ||
|
|
||
| toolbar.setNavigationOnClickListener { | ||
| findNavController().popBackStack() | ||
| } | ||
|
|
||
| appSecurity.apply { | ||
| if (AppLockManager.hasBiometrics()) { | ||
| isVisible = true | ||
| setOnClickListener { | ||
| trackSettingsEvent(MatomoName.LockApp) | ||
| safelyNavigate(R.id.appSecurityActivity) | ||
| } | ||
| } else { | ||
| isGone = true | ||
| } | ||
| } | ||
| contentProviderSwitch.isChecked = !CloudStorageProvider.isDisabled(appCtx) | ||
|
|
||
| contentProviderSwitch.setOnCheckedChangeListener { _, isChecked -> | ||
| CloudStorageProvider.setDisabled(appCtx, disabled = !isChecked) | ||
| } | ||
|
aymericmariaux marked this conversation as resolved.
Comment on lines
+66
to
+70
|
||
|
|
||
| binding.root.enableEdgeToEdge() | ||
| } | ||
|
|
||
| override fun onResume() = with(binding) { | ||
| super.onResume() | ||
| appSecurity.endText = getString(if (AppSettings.appSecurityLock) R.string.allActivated else R.string.allDisabled) | ||
| val isContentProviderEnabled = !CloudStorageProvider.isDisabled(appCtx) | ||
| if (contentProviderSwitch.isChecked != isContentProviderEnabled) { | ||
| contentProviderSwitch.isChecked = isContentProviderEnabled | ||
| } | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| <?xml version="1.0" encoding="utf-8"?><!-- | ||
| ~ Infomaniak kDrive - Android | ||
| ~ Copyright (C) 2026 Infomaniak Network SA | ||
| ~ | ||
| ~ 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/>. | ||
| --> | ||
| <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
| xmlns:app="http://schemas.android.com/apk/res-auto" | ||
| xmlns:tools="http://schemas.android.com/tools" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent"> | ||
|
|
||
| <com.google.android.material.appbar.AppBarLayout | ||
| android:id="@+id/appBar" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="@dimen/appBarHeight" | ||
| android:touchscreenBlocksFocus="false"> | ||
|
|
||
| <com.google.android.material.appbar.CollapsingToolbarLayout | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" | ||
| app:layout_scrollFlags="scroll|exitUntilCollapsed|snap" | ||
| app:title="@string/securityTitle"> | ||
|
|
||
| <com.google.android.material.appbar.MaterialToolbar | ||
| android:id="@+id/toolbar" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="?attr/actionBarSize" | ||
| android:touchscreenBlocksFocus="false" | ||
| app:layout_collapseMode="pin" /> | ||
|
|
||
| </com.google.android.material.appbar.CollapsingToolbarLayout> | ||
| </com.google.android.material.appbar.AppBarLayout> | ||
|
|
||
| <androidx.core.widget.NestedScrollView | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" | ||
| app:layout_behavior="@string/appbar_scrolling_view_behavior"> | ||
|
|
||
| <com.google.android.material.card.MaterialCardView | ||
| style="@style/CardViewInfomaniak" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:layout_margin="@dimen/marginStandard"> | ||
|
|
||
| <LinearLayout | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" | ||
| android:divider="@drawable/divider" | ||
| android:orientation="vertical" | ||
| android:showDividers="middle"> | ||
|
|
||
| <com.infomaniak.drive.ui.menu.settings.ItemSettingView | ||
| android:id="@+id/appSecurity" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| app:endText="@string/allDisabled" | ||
| app:itemAction="text" | ||
| app:title="@string/appSecurityTitle" /> | ||
|
|
||
| <com.infomaniak.drive.ui.menu.settings.ItemSettingView | ||
| android:id="@+id/contentProviderSwitch" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| app:itemAction="toggle" | ||
| app:title="@string/fileProviderExtensionTitle" | ||
| app:description="@string/fileProviderExtensionDescription" /> | ||
|
|
||
| </LinearLayout> | ||
| </com.google.android.material.card.MaterialCardView> | ||
| </androidx.core.widget.NestedScrollView> | ||
| </androidx.coordinatorlayout.widget.CoordinatorLayout> |
Uh oh!
There was an error while loading. Please reload this page.