From c3c7606edc1a7017169506baf19e5ab495aca61f Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 4 Nov 2024 15:08:12 +0100 Subject: [PATCH 01/52] add new mdm fields Signed-off-by: alperozturk --- .../com/owncloud/android/utils/appConfig/AppConfigKeys.kt | 8 +++++++- app/src/main/res/values/setup.xml | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/owncloud/android/utils/appConfig/AppConfigKeys.kt b/app/src/main/java/com/owncloud/android/utils/appConfig/AppConfigKeys.kt index 5df2a65a05..6781938c76 100644 --- a/app/src/main/java/com/owncloud/android/utils/appConfig/AppConfigKeys.kt +++ b/app/src/main/java/com/owncloud/android/utils/appConfig/AppConfigKeys.kt @@ -13,5 +13,11 @@ package com.owncloud.android.utils.appConfig enum class AppConfigKeys(val key: String) { BaseUrl("base_url"), ProxyHost("proxy_host"), - ProxyPort("proxy_port") + ProxyPort("proxy_port"), + DisableIntro("disable_intro"), + DisableMultiAccount("disable_multiaccount"), + DisableMoreExternalSite("disable_more_external_site"), + DisableSharing("disable_sharing"), + DisableClipboard("disable_clipboard"), + // TODO add other MDM's } diff --git a/app/src/main/res/values/setup.xml b/app/src/main/res/values/setup.xml index 3b6c753293..6f2b38eab8 100644 --- a/app/src/main/res/values/setup.xml +++ b/app/src/main/res/values/setup.xml @@ -36,6 +36,12 @@ -1 + false + false + false + false + false + on true From 33d20128cc4aa5a4758f3d8c7e5f738e55e5849c Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 4 Nov 2024 15:08:24 +0100 Subject: [PATCH 02/52] use bundle extensions Signed-off-by: alperozturk --- .../utils/extensions/BundleExtensions.kt | 16 ++++++++++++++ .../utils/appConfig/AppConfigManager.kt | 21 ++++--------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/nextcloud/utils/extensions/BundleExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/BundleExtensions.kt index 5b341c76b3..ecb1bbb772 100644 --- a/app/src/main/java/com/nextcloud/utils/extensions/BundleExtensions.kt +++ b/app/src/main/java/com/nextcloud/utils/extensions/BundleExtensions.kt @@ -56,3 +56,19 @@ fun Bundle?.getParcelableArgument(key: String, type: Class) null } } + +fun Bundle.getRestriction(key: String, defaultValue: String?): String? { + return if (containsKey(key)) { + getString(key) + } else { + defaultValue + } +} + +fun Bundle.getRestriction(key: String, defaultValue: Int): Int { + return if (containsKey(key)) { + getInt(key) + } else { + defaultValue + } +} diff --git a/app/src/main/java/com/owncloud/android/utils/appConfig/AppConfigManager.kt b/app/src/main/java/com/owncloud/android/utils/appConfig/AppConfigManager.kt index a390a6aee1..f56a5c64c4 100644 --- a/app/src/main/java/com/owncloud/android/utils/appConfig/AppConfigManager.kt +++ b/app/src/main/java/com/owncloud/android/utils/appConfig/AppConfigManager.kt @@ -11,6 +11,7 @@ import android.content.Context import android.content.res.Resources import android.os.Bundle import android.text.TextUtils +import com.nextcloud.utils.extensions.getRestriction import com.owncloud.android.R import com.owncloud.android.lib.common.OwnCloudClientManagerFactory import com.owncloud.android.lib.common.utils.Log_OC @@ -25,17 +26,8 @@ class AppConfigManager(private val context: Context, private val appRestrictions return } - val host = if (appRestrictions.containsKey(AppConfigKeys.ProxyHost.key)) { - appRestrictions.getString(AppConfigKeys.ProxyHost.key) - } else { - context.getString(R.string.proxy_host) - } - - val port = if (appRestrictions.containsKey(AppConfigKeys.ProxyPort.key)) { - appRestrictions.getInt(AppConfigKeys.ProxyPort.key) - } else { - context.resources.getInteger(R.integer.proxy_port) - } + val host = appRestrictions.getRestriction(AppConfigKeys.ProxyHost.key, context.getString(R.string.proxy_host)) + val port = appRestrictions.getRestriction(AppConfigKeys.ProxyPort.key, context.resources.getInteger(R.integer.proxy_port)) if (TextUtils.isEmpty(host) || port == -1) { Log_OC.d(tag, "Proxy configuration cannot be found") @@ -58,11 +50,6 @@ class AppConfigManager(private val context: Context, private val appRestrictions return null } - return if (appRestrictions.containsKey(AppConfigKeys.BaseUrl.key)) { - appRestrictions.getString(AppConfigKeys.BaseUrl.key) - } else { - Log_OC.d(tag, "BaseUrl configuration cannot be found, default url applied") - null - } + return appRestrictions.getRestriction(AppConfigKeys.BaseUrl.key, null) } } From 088cb729121fd3679f4a144aaa109e5c423ac702 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 4 Nov 2024 15:26:51 +0100 Subject: [PATCH 03/52] add disableMultiAccount Signed-off-by: alperozturk --- .../ui/ChooseAccountDialogFragment.kt | 17 ++++++++ .../utils/extensions/BundleExtensions.kt | 16 -------- .../RestrictionsManagerExtensions.kt | 40 +++++++++++++++++++ .../java/com/owncloud/android/MainApp.java | 2 +- .../authentication/AuthenticatorActivity.java | 2 +- .../utils/appConfig/AppConfigManager.kt | 10 ++--- 6 files changed, 64 insertions(+), 23 deletions(-) create mode 100644 app/src/main/java/com/nextcloud/utils/extensions/RestrictionsManagerExtensions.kt diff --git a/app/src/main/java/com/nextcloud/ui/ChooseAccountDialogFragment.kt b/app/src/main/java/com/nextcloud/ui/ChooseAccountDialogFragment.kt index 920c595398..e576a3a0eb 100644 --- a/app/src/main/java/com/nextcloud/ui/ChooseAccountDialogFragment.kt +++ b/app/src/main/java/com/nextcloud/ui/ChooseAccountDialogFragment.kt @@ -11,6 +11,7 @@ package com.nextcloud.ui import android.annotation.SuppressLint import android.app.Dialog import android.content.Context +import android.content.RestrictionsManager import android.graphics.drawable.Drawable import android.os.Bundle import android.view.LayoutInflater @@ -25,6 +26,7 @@ import com.nextcloud.client.account.UserAccountManager import com.nextcloud.client.di.Injectable import com.nextcloud.client.network.ClientFactory import com.nextcloud.utils.extensions.getParcelableArgument +import com.nextcloud.utils.extensions.getRestriction import com.owncloud.android.R import com.owncloud.android.databinding.DialogChooseAccountBinding import com.owncloud.android.datamodel.FileDataStorageManager @@ -36,6 +38,7 @@ import com.owncloud.android.ui.adapter.UserListAdapter import com.owncloud.android.ui.adapter.UserListItem import com.owncloud.android.utils.DisplayUtils import com.owncloud.android.utils.DisplayUtils.AvatarGenerationListener +import com.owncloud.android.utils.appConfig.AppConfigKeys import com.owncloud.android.utils.theme.ViewThemeUtils import kotlinx.coroutines.launch import javax.inject.Inject @@ -156,6 +159,20 @@ class ChooseAccountDialogFragment : } themeViews() + checkAppRestrictions() + } + + private fun checkAppRestrictions() { + val restrictionsManager = requireContext().getSystemService(Context.RESTRICTIONS_SERVICE) as RestrictionsManager + val disableMultiAccount = restrictionsManager.getRestriction( + AppConfigKeys.DisableMultiAccount.key, + context?.resources?.getBoolean(R.bool.disable_multiaccount) ?: false + ) + + if (disableMultiAccount) { + binding.addAccount.visibility = View.GONE + binding.manageAccounts.visibility = View.GONE + } } private fun loadAndSetUserStatus(user: User) { diff --git a/app/src/main/java/com/nextcloud/utils/extensions/BundleExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/BundleExtensions.kt index ecb1bbb772..5b341c76b3 100644 --- a/app/src/main/java/com/nextcloud/utils/extensions/BundleExtensions.kt +++ b/app/src/main/java/com/nextcloud/utils/extensions/BundleExtensions.kt @@ -56,19 +56,3 @@ fun Bundle?.getParcelableArgument(key: String, type: Class) null } } - -fun Bundle.getRestriction(key: String, defaultValue: String?): String? { - return if (containsKey(key)) { - getString(key) - } else { - defaultValue - } -} - -fun Bundle.getRestriction(key: String, defaultValue: Int): Int { - return if (containsKey(key)) { - getInt(key) - } else { - defaultValue - } -} diff --git a/app/src/main/java/com/nextcloud/utils/extensions/RestrictionsManagerExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/RestrictionsManagerExtensions.kt new file mode 100644 index 0000000000..fb7424ed83 --- /dev/null +++ b/app/src/main/java/com/nextcloud/utils/extensions/RestrictionsManagerExtensions.kt @@ -0,0 +1,40 @@ +/* + * Nextcloud - Android Client + * + * SPDX-FileCopyrightText: 2024 Alper Ozturk + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +package com.nextcloud.utils.extensions + +import android.content.RestrictionsManager + +fun RestrictionsManager.getRestriction(key: String, defaultValue: String?): String? { + val appRestrictions = getApplicationRestrictions() + + return if (appRestrictions.containsKey(key)) { + appRestrictions.getString(key) + } else { + defaultValue + } +} + +fun RestrictionsManager.getRestriction(key: String, defaultValue: Int): Int { + val appRestrictions = getApplicationRestrictions() + + return if (appRestrictions.containsKey(key)) { + appRestrictions.getInt(key) + } else { + defaultValue + } +} + +fun RestrictionsManager.getRestriction(key: String, defaultValue: Boolean): Boolean { + val appRestrictions = getApplicationRestrictions() + + return if (appRestrictions.containsKey(key)) { + appRestrictions.getBoolean(key) + } else { + defaultValue + } +} diff --git a/app/src/main/java/com/owncloud/android/MainApp.java b/app/src/main/java/com/owncloud/android/MainApp.java index 08b52ea776..903cab6b88 100644 --- a/app/src/main/java/com/owncloud/android/MainApp.java +++ b/app/src/main/java/com/owncloud/android/MainApp.java @@ -334,7 +334,7 @@ public class MainApp extends Application implements HasAndroidInjector, NetworkC if (isClientBrandedPlus()) { RestrictionsManager restrictionsManager = (RestrictionsManager) getSystemService(Context.RESTRICTIONS_SERVICE); - appConfigManager = new AppConfigManager(this, restrictionsManager.getApplicationRestrictions()); + appConfigManager = new AppConfigManager(this, restrictionsManager); appConfigManager.setProxyConfig(isClientBrandedPlus()); // Listen app config changes diff --git a/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java b/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java index 158cfcd9e0..a36aa163f1 100644 --- a/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -321,7 +321,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity if (MainApp.isClientBrandedPlus()) { RestrictionsManager restrictionsManager = (RestrictionsManager) getSystemService(Context.RESTRICTIONS_SERVICE); - AppConfigManager appConfigManager = new AppConfigManager(this, restrictionsManager.getApplicationRestrictions()); + AppConfigManager appConfigManager = new AppConfigManager(this, restrictionsManager); if (!TextUtils.isEmpty(appConfigManager.getBaseUrl(MainApp.isClientBrandedPlus()))) { webloginUrl = appConfigManager.getBaseUrl(MainApp.isClientBrandedPlus()) + WEB_LOGIN; diff --git a/app/src/main/java/com/owncloud/android/utils/appConfig/AppConfigManager.kt b/app/src/main/java/com/owncloud/android/utils/appConfig/AppConfigManager.kt index f56a5c64c4..204a9f8e2c 100644 --- a/app/src/main/java/com/owncloud/android/utils/appConfig/AppConfigManager.kt +++ b/app/src/main/java/com/owncloud/android/utils/appConfig/AppConfigManager.kt @@ -8,15 +8,15 @@ package com.owncloud.android.utils.appConfig import android.content.Context +import android.content.RestrictionsManager import android.content.res.Resources -import android.os.Bundle import android.text.TextUtils import com.nextcloud.utils.extensions.getRestriction import com.owncloud.android.R import com.owncloud.android.lib.common.OwnCloudClientManagerFactory import com.owncloud.android.lib.common.utils.Log_OC -class AppConfigManager(private val context: Context, private val appRestrictions: Bundle) { +class AppConfigManager(private val context: Context, private val restrictionsManager: RestrictionsManager) { private val tag = "AppConfigManager" @@ -26,8 +26,8 @@ class AppConfigManager(private val context: Context, private val appRestrictions return } - val host = appRestrictions.getRestriction(AppConfigKeys.ProxyHost.key, context.getString(R.string.proxy_host)) - val port = appRestrictions.getRestriction(AppConfigKeys.ProxyPort.key, context.resources.getInteger(R.integer.proxy_port)) + val host = restrictionsManager.getRestriction(AppConfigKeys.ProxyHost.key, context.getString(R.string.proxy_host)) + val port = restrictionsManager.getRestriction(AppConfigKeys.ProxyPort.key, context.resources.getInteger(R.integer.proxy_port)) if (TextUtils.isEmpty(host) || port == -1) { Log_OC.d(tag, "Proxy configuration cannot be found") @@ -50,6 +50,6 @@ class AppConfigManager(private val context: Context, private val appRestrictions return null } - return appRestrictions.getRestriction(AppConfigKeys.BaseUrl.key, null) + return restrictionsManager.getRestriction(AppConfigKeys.BaseUrl.key, null) } } From 3134ab1936cc72109d2c7cba16eee796c5c49261 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 4 Nov 2024 15:44:04 +0100 Subject: [PATCH 04/52] remove AppConfigManager use RestrictionManager directly due to multiple usage requirements Signed-off-by: alperozturk --- .../nextcloud/utils/AppConfigManagerTests.kt | 86 ------------------- .../java/com/owncloud/android/MainApp.java | 43 +++++++--- .../authentication/AuthenticatorActivity.java | 10 +-- .../utils/appConfig/AppConfigManager.kt | 55 ------------ 4 files changed, 36 insertions(+), 158 deletions(-) delete mode 100644 app/src/androidTest/java/com/nextcloud/utils/AppConfigManagerTests.kt delete mode 100644 app/src/main/java/com/owncloud/android/utils/appConfig/AppConfigManager.kt diff --git a/app/src/androidTest/java/com/nextcloud/utils/AppConfigManagerTests.kt b/app/src/androidTest/java/com/nextcloud/utils/AppConfigManagerTests.kt deleted file mode 100644 index 8392ae549f..0000000000 --- a/app/src/androidTest/java/com/nextcloud/utils/AppConfigManagerTests.kt +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Nextcloud - Android Client - * - * SPDX-FileCopyrightText: 2024 Alper Ozturk - * SPDX-License-Identifier: AGPL-3.0-or-later - */ - -package com.nextcloud.utils - -import android.os.Bundle -import com.owncloud.android.AbstractIT -import com.owncloud.android.lib.common.OwnCloudClientManagerFactory -import com.owncloud.android.utils.appConfig.AppConfigKeys -import com.owncloud.android.utils.appConfig.AppConfigManager -import org.junit.AfterClass -import org.junit.Test - -class AppConfigManagerTests : AbstractIT() { - - private val testBaseUrl = "nextcloud.cloud.cloud" - private val testProxyHost = "nextcloud.cloud.cloud.com" - - @Suppress("MagicNumber") - private val testProxyPort = 8800 - - @Test - fun testSetProxyConfigWhenGivenClientBrandedPlusAndCorrectBundleDataProxyConfigurationShouldSet() { - val proxySetting = Bundle().apply { - putString(AppConfigKeys.ProxyHost.key, testProxyHost) - putInt(AppConfigKeys.ProxyPort.key, testProxyPort) - } - - AppConfigManager(targetContext, proxySetting).run { - setProxyConfig(true) - } - - val proxyHost = OwnCloudClientManagerFactory.getProxyHost() - val proxyPort = OwnCloudClientManagerFactory.getProxyPort() - - assert(proxyHost.equals(testProxyHost)) - assert(proxyPort == testProxyPort) - } - - @Test - fun testSetProxyConfigWhenGivenClientNotBrandedPlusAndCorrectBundleDataProxyConfigurationShouldNotSet() { - val proxySetting = Bundle().apply { - putString(AppConfigKeys.ProxyHost.key, testProxyHost) - putInt(AppConfigKeys.ProxyPort.key, testProxyPort) - } - - AppConfigManager(targetContext, proxySetting).run { - setProxyConfig(false) - } - - val proxyHost = OwnCloudClientManagerFactory.getProxyHost() - val proxyPort = OwnCloudClientManagerFactory.getProxyPort() - - assert(proxyHost.equals("")) - assert(proxyPort == -1) - } - - @Test - fun testGetBaseUrlConfigWhenGivenClientBrandedPlusAndCorrectBundleDataBaseUrlConfigurationShouldSet() { - val baseUrlConfig = Bundle().apply { - putString(AppConfigKeys.BaseUrl.key, testBaseUrl) - } - val sut = AppConfigManager(targetContext, baseUrlConfig) - assert(!sut.getBaseUrl(true).isNullOrEmpty()) - } - - @Test - fun testGetBaseUrlConfigWhenGivenClientBrandedPlusAndBrokenBundleDataBaseUrlConfigurationShouldNotSet() { - val baseUrlConfig = Bundle() - val sut = AppConfigManager(targetContext, baseUrlConfig) - assert(sut.getBaseUrl(true).isNullOrEmpty()) - } - - companion object { - @JvmStatic - @AfterClass - fun tearDown() { - OwnCloudClientManagerFactory.setProxyHost("") - OwnCloudClientManagerFactory.setProxyPort(-1) - } - } -} diff --git a/app/src/main/java/com/owncloud/android/MainApp.java b/app/src/main/java/com/owncloud/android/MainApp.java index 903cab6b88..acd76a6cf2 100644 --- a/app/src/main/java/com/owncloud/android/MainApp.java +++ b/app/src/main/java/com/owncloud/android/MainApp.java @@ -62,6 +62,7 @@ import com.nextcloud.client.preferences.DarkMode; import com.nextcloud.receiver.NetworkChangeListener; import com.nextcloud.receiver.NetworkChangeReceiver; import com.nextcloud.utils.extensions.ContextExtensionsKt; +import com.nextcloud.utils.extensions.RestrictionsManagerExtensionsKt; import com.nmc.android.ui.LauncherActivity; import com.owncloud.android.authentication.PassCodeManager; import com.owncloud.android.datamodel.ArbitraryDataProvider; @@ -87,7 +88,7 @@ import com.owncloud.android.utils.FilesSyncHelper; import com.owncloud.android.utils.PermissionUtil; import com.owncloud.android.utils.ReceiversHelper; import com.owncloud.android.utils.SecurityUtils; -import com.owncloud.android.utils.appConfig.AppConfigManager; +import com.owncloud.android.utils.appConfig.AppConfigKeys; import com.owncloud.android.utils.theme.ViewThemeUtils; import org.conscrypt.Conscrypt; @@ -199,8 +200,6 @@ public class MainApp extends Application implements HasAndroidInjector, NetworkC @SuppressWarnings("unused") private boolean mBound; - private AppConfigManager appConfigManager; - private static AppComponent appComponent; private NetworkChangeReceiver networkChangeReceiver; @@ -333,11 +332,7 @@ public class MainApp extends Application implements HasAndroidInjector, NetworkC OwnCloudClientManagerFactory.setUserAgent(getUserAgent()); if (isClientBrandedPlus()) { - RestrictionsManager restrictionsManager = (RestrictionsManager) getSystemService(Context.RESTRICTIONS_SERVICE); - appConfigManager = new AppConfigManager(this, restrictionsManager); - appConfigManager.setProxyConfig(isClientBrandedPlus()); - - // Listen app config changes + setProxyConfig(); ContextExtensionsKt.registerBroadcastReceiver(this, restrictionsReceiver, restrictionsFilter, ReceiverFlag.NotExported); } else { setProxyForNonBrandedPlusClients(); @@ -397,8 +392,7 @@ public class MainApp extends Application implements HasAndroidInjector, NetworkC passCodeManager.setCanAskPin(true); Log_OC.d(TAG, "APP IN BACKGROUND"); } else if (event == Lifecycle.Event.ON_RESUME) { - if (appConfigManager == null) return; - appConfigManager.setProxyConfig(isClientBrandedPlus()); + setProxyConfig(); Log_OC.d(TAG, "APP ON RESUME"); } }); @@ -420,11 +414,36 @@ public class MainApp extends Application implements HasAndroidInjector, NetworkC private final BroadcastReceiver restrictionsReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { - if (appConfigManager == null) return; - appConfigManager.setProxyConfig(isClientBrandedPlus()); + setProxyConfig(); } }; + private void setProxyConfig() { + if (!isClientBrandedPlus()) { + Log_OC.d(TAG, "Proxy configuration cannot be set. Client is not branded plus."); + return; + } + + RestrictionsManager restrictionsManager = (RestrictionsManager) getSystemService(Context.RESTRICTIONS_SERVICE); + + String host = RestrictionsManagerExtensionsKt.getRestriction(restrictionsManager,AppConfigKeys.ProxyHost.getKey(), getString(R.string.proxy_host)); + int port = RestrictionsManagerExtensionsKt.getRestriction(restrictionsManager, AppConfigKeys.ProxyPort.getKey(), getResources().getInteger(R.integer.proxy_port)); + + if (TextUtils.isEmpty(host) || port == -1) { + Log_OC.d(TAG, "Proxy configuration cannot be found"); + return; + } + + try { + OwnCloudClientManagerFactory.setProxyHost(host); + OwnCloudClientManagerFactory.setProxyPort(port); + + Log_OC.d(TAG, "Proxy configuration successfully set"); + } catch (Resources.NotFoundException e) { + Log_OC.e(TAG, "Proxy config cannot able to set due to: $e"); + } + } + private void registerGlobalPassCodeProtection() { registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() { diff --git a/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java b/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java index a36aa163f1..453d0c0b0a 100644 --- a/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -71,6 +71,7 @@ import com.nextcloud.client.preferences.AppPreferences; import com.nextcloud.common.PlainClient; import com.nextcloud.operations.PostMethod; import com.nextcloud.utils.extensions.BundleExtensionsKt; +import com.nextcloud.utils.extensions.RestrictionsManagerExtensionsKt; import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.databinding.AccountSetupBinding; @@ -112,7 +113,7 @@ import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.ErrorMessageAdapter; import com.owncloud.android.utils.PermissionUtil; import com.owncloud.android.utils.WebViewUtil; -import com.owncloud.android.utils.appConfig.AppConfigManager; +import com.owncloud.android.utils.appConfig.AppConfigKeys; import com.owncloud.android.utils.theme.CapabilityUtils; import com.owncloud.android.utils.theme.ViewThemeUtils; @@ -321,10 +322,9 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity if (MainApp.isClientBrandedPlus()) { RestrictionsManager restrictionsManager = (RestrictionsManager) getSystemService(Context.RESTRICTIONS_SERVICE); - AppConfigManager appConfigManager = new AppConfigManager(this, restrictionsManager); - - if (!TextUtils.isEmpty(appConfigManager.getBaseUrl(MainApp.isClientBrandedPlus()))) { - webloginUrl = appConfigManager.getBaseUrl(MainApp.isClientBrandedPlus()) + WEB_LOGIN; + String baseUrl = RestrictionsManagerExtensionsKt.getRestriction(restrictionsManager, AppConfigKeys.BaseUrl.getKey(),null); + if (!TextUtils.isEmpty(baseUrl)) { + webloginUrl = baseUrl + WEB_LOGIN; } } diff --git a/app/src/main/java/com/owncloud/android/utils/appConfig/AppConfigManager.kt b/app/src/main/java/com/owncloud/android/utils/appConfig/AppConfigManager.kt deleted file mode 100644 index 204a9f8e2c..0000000000 --- a/app/src/main/java/com/owncloud/android/utils/appConfig/AppConfigManager.kt +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Nextcloud - Android Client - * - * SPDX-FileCopyrightText: 2024 Alper Ozturk - * SPDX-License-Identifier: AGPL-3.0-or-later - */ - -package com.owncloud.android.utils.appConfig - -import android.content.Context -import android.content.RestrictionsManager -import android.content.res.Resources -import android.text.TextUtils -import com.nextcloud.utils.extensions.getRestriction -import com.owncloud.android.R -import com.owncloud.android.lib.common.OwnCloudClientManagerFactory -import com.owncloud.android.lib.common.utils.Log_OC - -class AppConfigManager(private val context: Context, private val restrictionsManager: RestrictionsManager) { - - private val tag = "AppConfigManager" - - fun setProxyConfig(isBrandedPlus: Boolean) { - if (!isBrandedPlus) { - Log_OC.d(tag, "Proxy configuration cannot be set. Client is not branded plus.") - return - } - - val host = restrictionsManager.getRestriction(AppConfigKeys.ProxyHost.key, context.getString(R.string.proxy_host)) - val port = restrictionsManager.getRestriction(AppConfigKeys.ProxyPort.key, context.resources.getInteger(R.integer.proxy_port)) - - if (TextUtils.isEmpty(host) || port == -1) { - Log_OC.d(tag, "Proxy configuration cannot be found") - return - } - - try { - OwnCloudClientManagerFactory.setProxyHost(host) - OwnCloudClientManagerFactory.setProxyPort(port) - - Log_OC.d(tag, "Proxy configuration successfully set") - } catch (e: Resources.NotFoundException) { - Log_OC.e(tag, "Proxy config cannot able to set due to: $e") - } - } - - fun getBaseUrl(isBrandedPlus: Boolean): String? { - if (!isBrandedPlus) { - Log_OC.d(tag, "Proxy configuration cannot be set. Client is not branded plus. Default url applied") - return null - } - - return restrictionsManager.getRestriction(AppConfigKeys.BaseUrl.key, null) - } -} From f6827152928f8f717b050122570be739d0d100ae Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 4 Nov 2024 15:47:44 +0100 Subject: [PATCH 05/52] add disableClipboard Signed-off-by: alperozturk --- .../java/com/owncloud/android/utils/ClipboardUtil.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/src/main/java/com/owncloud/android/utils/ClipboardUtil.kt b/app/src/main/java/com/owncloud/android/utils/ClipboardUtil.kt index da2f4b65d7..e9bed2ae52 100644 --- a/app/src/main/java/com/owncloud/android/utils/ClipboardUtil.kt +++ b/app/src/main/java/com/owncloud/android/utils/ClipboardUtil.kt @@ -10,10 +10,13 @@ import android.app.Activity import android.content.ClipData import android.content.ClipboardManager import android.content.Context +import android.content.RestrictionsManager import android.text.TextUtils import android.widget.Toast +import com.nextcloud.utils.extensions.getRestriction import com.owncloud.android.R import com.owncloud.android.lib.common.utils.Log_OC +import com.owncloud.android.utils.appConfig.AppConfigKeys /** * Helper implementation to copy a string into the system clipboard. @@ -25,6 +28,15 @@ object ClipboardUtil { @JvmOverloads @Suppress("TooGenericExceptionCaught") fun copyToClipboard(activity: Activity, text: String?, showToast: Boolean = true) { + val restrictionsManager = activity.getSystemService(Context.RESTRICTIONS_SERVICE) as RestrictionsManager + val disableClipboard = restrictionsManager.getRestriction( + AppConfigKeys.DisableClipboard.key, + activity.resources.getBoolean(R.bool.disable_clipboard) + ) + if (disableClipboard) { + return + } + if (!TextUtils.isEmpty(text)) { try { val clip = ClipData.newPlainText( From de21cfd9c9ad243fd11f26752666989fd7b6d42b Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 4 Nov 2024 15:59:42 +0100 Subject: [PATCH 06/52] add disableSharing Signed-off-by: alperozturk --- .../owncloud/android/ui/dialog/SendShareDialog.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.kt b/app/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.kt index 9be56aff7e..23f4abcdcb 100644 --- a/app/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.kt +++ b/app/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.kt @@ -12,7 +12,9 @@ package com.owncloud.android.ui.dialog import android.content.ComponentName +import android.content.Context import android.content.Intent +import android.content.RestrictionsManager import android.graphics.drawable.Drawable import android.os.Bundle import android.view.LayoutInflater @@ -27,6 +29,7 @@ import com.nextcloud.android.common.ui.theme.utils.ColorRole import com.nextcloud.client.di.Injectable import com.nextcloud.client.utils.IntentUtil.createSendIntent import com.nextcloud.utils.extensions.getParcelableArgument +import com.nextcloud.utils.extensions.getRestriction import com.owncloud.android.BuildConfig import com.owncloud.android.R import com.owncloud.android.databinding.SendShareFragmentBinding @@ -39,6 +42,7 @@ import com.owncloud.android.ui.adapter.SendButtonAdapter import com.owncloud.android.ui.components.SendButtonData import com.owncloud.android.ui.helpers.FileOperationsHelper import com.owncloud.android.utils.MimeTypeUtil +import com.owncloud.android.utils.appConfig.AppConfigKeys import com.owncloud.android.utils.theme.ViewThemeUtils import javax.inject.Inject @@ -85,6 +89,16 @@ class SendShareDialog : BottomSheetDialogFragment(R.layout.send_share_fragment), @Suppress("MagicNumber") private fun setupSendButtonRecyclerView() { + val restrictionsManager = requireContext().getSystemService(Context.RESTRICTIONS_SERVICE) as RestrictionsManager + val disableSharing = restrictionsManager.getRestriction( + AppConfigKeys.DisableSharing.key, + context?.resources?.getBoolean(R.bool.disable_sharing) ?: false + ) + + if (disableSharing) { + return + } + val sendIntent = createSendIntent(requireContext(), file!!) val sendButtonDataList = setupSendButtonData(sendIntent) val clickListener = setupSendButtonClickListener(sendIntent) From f32438693c13fc2fba5ed79f07bd8e2fba8dfc24 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 4 Nov 2024 16:45:14 +0100 Subject: [PATCH 07/52] remove already existing capability Signed-off-by: alperozturk --- .../java/com/owncloud/android/utils/appConfig/AppConfigKeys.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/com/owncloud/android/utils/appConfig/AppConfigKeys.kt b/app/src/main/java/com/owncloud/android/utils/appConfig/AppConfigKeys.kt index 6781938c76..912586052e 100644 --- a/app/src/main/java/com/owncloud/android/utils/appConfig/AppConfigKeys.kt +++ b/app/src/main/java/com/owncloud/android/utils/appConfig/AppConfigKeys.kt @@ -16,7 +16,6 @@ enum class AppConfigKeys(val key: String) { ProxyPort("proxy_port"), DisableIntro("disable_intro"), DisableMultiAccount("disable_multiaccount"), - DisableMoreExternalSite("disable_more_external_site"), DisableSharing("disable_sharing"), DisableClipboard("disable_clipboard"), // TODO add other MDM's From 43ce5582afb7ee5ab2f11e3a864a352c1a8f220b Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 4 Nov 2024 16:52:54 +0100 Subject: [PATCH 08/52] use generic getRestriction extension Signed-off-by: alperozturk --- .../RestrictionsManagerExtensions.kt | 33 ++++--------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/com/nextcloud/utils/extensions/RestrictionsManagerExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/RestrictionsManagerExtensions.kt index fb7424ed83..978d2e435e 100644 --- a/app/src/main/java/com/nextcloud/utils/extensions/RestrictionsManagerExtensions.kt +++ b/app/src/main/java/com/nextcloud/utils/extensions/RestrictionsManagerExtensions.kt @@ -9,32 +9,13 @@ package com.nextcloud.utils.extensions import android.content.RestrictionsManager -fun RestrictionsManager.getRestriction(key: String, defaultValue: String?): String? { +@Suppress("UNCHECKED_CAST") +fun RestrictionsManager.getRestriction(key: String, defaultValue: T): T { val appRestrictions = getApplicationRestrictions() - - return if (appRestrictions.containsKey(key)) { - appRestrictions.getString(key) - } else { - defaultValue - } -} - -fun RestrictionsManager.getRestriction(key: String, defaultValue: Int): Int { - val appRestrictions = getApplicationRestrictions() - - return if (appRestrictions.containsKey(key)) { - appRestrictions.getInt(key) - } else { - defaultValue - } -} - -fun RestrictionsManager.getRestriction(key: String, defaultValue: Boolean): Boolean { - val appRestrictions = getApplicationRestrictions() - - return if (appRestrictions.containsKey(key)) { - appRestrictions.getBoolean(key) - } else { - defaultValue + return when (defaultValue) { + is String -> appRestrictions.getString(key) as T? ?: defaultValue + is Int -> appRestrictions.getInt(key) as T? ?: defaultValue + is Boolean -> appRestrictions.getBoolean(key) as T? ?: defaultValue + else -> defaultValue } } From a95a1ecf2b9446e36a56e7b082f1a319bf0a5f9a Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 4 Nov 2024 16:57:39 +0100 Subject: [PATCH 09/52] make defaultValue non nullable Signed-off-by: alperozturk --- .../nextcloud/utils/extensions/RestrictionsManagerExtensions.kt | 2 +- .../owncloud/android/authentication/AuthenticatorActivity.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/nextcloud/utils/extensions/RestrictionsManagerExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/RestrictionsManagerExtensions.kt index 978d2e435e..062be9edd7 100644 --- a/app/src/main/java/com/nextcloud/utils/extensions/RestrictionsManagerExtensions.kt +++ b/app/src/main/java/com/nextcloud/utils/extensions/RestrictionsManagerExtensions.kt @@ -10,7 +10,7 @@ package com.nextcloud.utils.extensions import android.content.RestrictionsManager @Suppress("UNCHECKED_CAST") -fun RestrictionsManager.getRestriction(key: String, defaultValue: T): T { +fun RestrictionsManager.getRestriction(key: String, defaultValue: T): T { val appRestrictions = getApplicationRestrictions() return when (defaultValue) { is String -> appRestrictions.getString(key) as T? ?: defaultValue diff --git a/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java b/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java index 453d0c0b0a..d3ff243a1f 100644 --- a/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -322,7 +322,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity if (MainApp.isClientBrandedPlus()) { RestrictionsManager restrictionsManager = (RestrictionsManager) getSystemService(Context.RESTRICTIONS_SERVICE); - String baseUrl = RestrictionsManagerExtensionsKt.getRestriction(restrictionsManager, AppConfigKeys.BaseUrl.getKey(),null); + String baseUrl = RestrictionsManagerExtensionsKt.getRestriction(restrictionsManager, AppConfigKeys.BaseUrl.getKey(),""); if (!TextUtils.isEmpty(baseUrl)) { webloginUrl = baseUrl + WEB_LOGIN; } From 6c936885f16650f3b861de66a483dddabd49ca69 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 4 Nov 2024 17:03:11 +0100 Subject: [PATCH 10/52] use ContextExtensions Signed-off-by: alperozturk --- .../ui/ChooseAccountDialogFragment.kt | 4 +--- .../utils/extensions/ContextExtensions.kt | 17 +++++++++++++++ .../RestrictionsManagerExtensions.kt | 21 ------------------- .../java/com/owncloud/android/MainApp.java | 8 ++----- .../authentication/AuthenticatorActivity.java | 5 ++--- .../android/ui/dialog/SendShareDialog.kt | 5 +---- .../owncloud/android/utils/ClipboardUtil.kt | 4 +--- 7 files changed, 24 insertions(+), 40 deletions(-) delete mode 100644 app/src/main/java/com/nextcloud/utils/extensions/RestrictionsManagerExtensions.kt diff --git a/app/src/main/java/com/nextcloud/ui/ChooseAccountDialogFragment.kt b/app/src/main/java/com/nextcloud/ui/ChooseAccountDialogFragment.kt index e576a3a0eb..d7fcd1a242 100644 --- a/app/src/main/java/com/nextcloud/ui/ChooseAccountDialogFragment.kt +++ b/app/src/main/java/com/nextcloud/ui/ChooseAccountDialogFragment.kt @@ -11,7 +11,6 @@ package com.nextcloud.ui import android.annotation.SuppressLint import android.app.Dialog import android.content.Context -import android.content.RestrictionsManager import android.graphics.drawable.Drawable import android.os.Bundle import android.view.LayoutInflater @@ -163,8 +162,7 @@ class ChooseAccountDialogFragment : } private fun checkAppRestrictions() { - val restrictionsManager = requireContext().getSystemService(Context.RESTRICTIONS_SERVICE) as RestrictionsManager - val disableMultiAccount = restrictionsManager.getRestriction( + val disableMultiAccount = requireContext().getRestriction( AppConfigKeys.DisableMultiAccount.key, context?.resources?.getBoolean(R.bool.disable_multiaccount) ?: false ) diff --git a/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt index 0cfc83439e..8a870af5a5 100644 --- a/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt +++ b/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt @@ -12,6 +12,7 @@ import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.content.IntentFilter +import android.content.RestrictionsManager import android.os.Build import android.os.Handler import android.os.Looper @@ -20,6 +21,22 @@ import com.google.common.io.Resources import com.owncloud.android.R import com.owncloud.android.datamodel.ReceiverFlag +fun Context.getRestriction(key: String, defaultValue: T): T { + val restrictionsManager = getSystemService(Context.RESTRICTIONS_SERVICE) as RestrictionsManager + return restrictionsManager.getRestriction(key, defaultValue) +} + +@Suppress("UNCHECKED_CAST") +private fun RestrictionsManager.getRestriction(key: String, defaultValue: T): T { + val appRestrictions = getApplicationRestrictions() + return when (defaultValue) { + is String -> appRestrictions.getString(key) as T? ?: defaultValue + is Int -> appRestrictions.getInt(key) as T? ?: defaultValue + is Boolean -> appRestrictions.getBoolean(key) as T? ?: defaultValue + else -> defaultValue + } +} + fun Context.hourPlural(hour: Int): String = resources.getQuantityString(R.plurals.hours, hour, hour) fun Context.minPlural(min: Int): String = resources.getQuantityString(R.plurals.minutes, min, min) diff --git a/app/src/main/java/com/nextcloud/utils/extensions/RestrictionsManagerExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/RestrictionsManagerExtensions.kt deleted file mode 100644 index 062be9edd7..0000000000 --- a/app/src/main/java/com/nextcloud/utils/extensions/RestrictionsManagerExtensions.kt +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Nextcloud - Android Client - * - * SPDX-FileCopyrightText: 2024 Alper Ozturk - * SPDX-License-Identifier: AGPL-3.0-or-later - */ - -package com.nextcloud.utils.extensions - -import android.content.RestrictionsManager - -@Suppress("UNCHECKED_CAST") -fun RestrictionsManager.getRestriction(key: String, defaultValue: T): T { - val appRestrictions = getApplicationRestrictions() - return when (defaultValue) { - is String -> appRestrictions.getString(key) as T? ?: defaultValue - is Int -> appRestrictions.getInt(key) as T? ?: defaultValue - is Boolean -> appRestrictions.getBoolean(key) as T? ?: defaultValue - else -> defaultValue - } -} diff --git a/app/src/main/java/com/owncloud/android/MainApp.java b/app/src/main/java/com/owncloud/android/MainApp.java index acd76a6cf2..d9f4e19720 100644 --- a/app/src/main/java/com/owncloud/android/MainApp.java +++ b/app/src/main/java/com/owncloud/android/MainApp.java @@ -26,7 +26,6 @@ import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; -import android.content.RestrictionsManager; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.res.Resources; @@ -62,7 +61,6 @@ import com.nextcloud.client.preferences.DarkMode; import com.nextcloud.receiver.NetworkChangeListener; import com.nextcloud.receiver.NetworkChangeReceiver; import com.nextcloud.utils.extensions.ContextExtensionsKt; -import com.nextcloud.utils.extensions.RestrictionsManagerExtensionsKt; import com.nmc.android.ui.LauncherActivity; import com.owncloud.android.authentication.PassCodeManager; import com.owncloud.android.datamodel.ArbitraryDataProvider; @@ -424,10 +422,8 @@ public class MainApp extends Application implements HasAndroidInjector, NetworkC return; } - RestrictionsManager restrictionsManager = (RestrictionsManager) getSystemService(Context.RESTRICTIONS_SERVICE); - - String host = RestrictionsManagerExtensionsKt.getRestriction(restrictionsManager,AppConfigKeys.ProxyHost.getKey(), getString(R.string.proxy_host)); - int port = RestrictionsManagerExtensionsKt.getRestriction(restrictionsManager, AppConfigKeys.ProxyPort.getKey(), getResources().getInteger(R.integer.proxy_port)); + String host = ContextExtensionsKt.getRestriction(this, AppConfigKeys.ProxyHost.getKey(), getString(R.string.proxy_host)); + int port = ContextExtensionsKt.getRestriction(this, AppConfigKeys.ProxyPort.getKey(), getResources().getInteger(R.integer.proxy_port)); if (TextUtils.isEmpty(host) || port == -1) { Log_OC.d(TAG, "Proxy configuration cannot be found"); diff --git a/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java b/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java index d3ff243a1f..b83bce5071 100644 --- a/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -71,7 +71,7 @@ import com.nextcloud.client.preferences.AppPreferences; import com.nextcloud.common.PlainClient; import com.nextcloud.operations.PostMethod; import com.nextcloud.utils.extensions.BundleExtensionsKt; -import com.nextcloud.utils.extensions.RestrictionsManagerExtensionsKt; +import com.nextcloud.utils.extensions.ContextExtensionsKt; import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.databinding.AccountSetupBinding; @@ -321,8 +321,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity String webloginUrl = null; if (MainApp.isClientBrandedPlus()) { - RestrictionsManager restrictionsManager = (RestrictionsManager) getSystemService(Context.RESTRICTIONS_SERVICE); - String baseUrl = RestrictionsManagerExtensionsKt.getRestriction(restrictionsManager, AppConfigKeys.BaseUrl.getKey(),""); + String baseUrl = ContextExtensionsKt.getRestriction(this, AppConfigKeys.BaseUrl.getKey(), ""); if (!TextUtils.isEmpty(baseUrl)) { webloginUrl = baseUrl + WEB_LOGIN; } diff --git a/app/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.kt b/app/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.kt index 23f4abcdcb..6a64fe9195 100644 --- a/app/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.kt +++ b/app/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.kt @@ -12,9 +12,7 @@ package com.owncloud.android.ui.dialog import android.content.ComponentName -import android.content.Context import android.content.Intent -import android.content.RestrictionsManager import android.graphics.drawable.Drawable import android.os.Bundle import android.view.LayoutInflater @@ -89,8 +87,7 @@ class SendShareDialog : BottomSheetDialogFragment(R.layout.send_share_fragment), @Suppress("MagicNumber") private fun setupSendButtonRecyclerView() { - val restrictionsManager = requireContext().getSystemService(Context.RESTRICTIONS_SERVICE) as RestrictionsManager - val disableSharing = restrictionsManager.getRestriction( + val disableSharing = requireContext().getRestriction( AppConfigKeys.DisableSharing.key, context?.resources?.getBoolean(R.bool.disable_sharing) ?: false ) diff --git a/app/src/main/java/com/owncloud/android/utils/ClipboardUtil.kt b/app/src/main/java/com/owncloud/android/utils/ClipboardUtil.kt index e9bed2ae52..d4f45a730f 100644 --- a/app/src/main/java/com/owncloud/android/utils/ClipboardUtil.kt +++ b/app/src/main/java/com/owncloud/android/utils/ClipboardUtil.kt @@ -10,7 +10,6 @@ import android.app.Activity import android.content.ClipData import android.content.ClipboardManager import android.content.Context -import android.content.RestrictionsManager import android.text.TextUtils import android.widget.Toast import com.nextcloud.utils.extensions.getRestriction @@ -28,8 +27,7 @@ object ClipboardUtil { @JvmOverloads @Suppress("TooGenericExceptionCaught") fun copyToClipboard(activity: Activity, text: String?, showToast: Boolean = true) { - val restrictionsManager = activity.getSystemService(Context.RESTRICTIONS_SERVICE) as RestrictionsManager - val disableClipboard = restrictionsManager.getRestriction( + val disableClipboard = activity.getRestriction( AppConfigKeys.DisableClipboard.key, activity.resources.getBoolean(R.bool.disable_clipboard) ) From a2ed2a701f9f37c9af1cd0fa1a3f57da09dbf682 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 4 Nov 2024 17:05:24 +0100 Subject: [PATCH 11/52] use AppConfigKeys as parameter instead of String Signed-off-by: alperozturk --- .../java/com/nextcloud/ui/ChooseAccountDialogFragment.kt | 2 +- .../java/com/nextcloud/utils/extensions/ContextExtensions.kt | 5 +++-- app/src/main/java/com/owncloud/android/MainApp.java | 4 ++-- .../android/authentication/AuthenticatorActivity.java | 2 +- .../java/com/owncloud/android/ui/dialog/SendShareDialog.kt | 2 +- .../main/java/com/owncloud/android/utils/ClipboardUtil.kt | 2 +- 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/nextcloud/ui/ChooseAccountDialogFragment.kt b/app/src/main/java/com/nextcloud/ui/ChooseAccountDialogFragment.kt index d7fcd1a242..50dd7f7de6 100644 --- a/app/src/main/java/com/nextcloud/ui/ChooseAccountDialogFragment.kt +++ b/app/src/main/java/com/nextcloud/ui/ChooseAccountDialogFragment.kt @@ -163,7 +163,7 @@ class ChooseAccountDialogFragment : private fun checkAppRestrictions() { val disableMultiAccount = requireContext().getRestriction( - AppConfigKeys.DisableMultiAccount.key, + AppConfigKeys.DisableMultiAccount, context?.resources?.getBoolean(R.bool.disable_multiaccount) ?: false ) diff --git a/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt index 8a870af5a5..5c6010d7e4 100644 --- a/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt +++ b/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt @@ -20,10 +20,11 @@ import android.widget.Toast import com.google.common.io.Resources import com.owncloud.android.R import com.owncloud.android.datamodel.ReceiverFlag +import com.owncloud.android.utils.appConfig.AppConfigKeys -fun Context.getRestriction(key: String, defaultValue: T): T { +fun Context.getRestriction(appConfigKey: AppConfigKeys, defaultValue: T): T { val restrictionsManager = getSystemService(Context.RESTRICTIONS_SERVICE) as RestrictionsManager - return restrictionsManager.getRestriction(key, defaultValue) + return restrictionsManager.getRestriction(appConfigKey.key, defaultValue) } @Suppress("UNCHECKED_CAST") diff --git a/app/src/main/java/com/owncloud/android/MainApp.java b/app/src/main/java/com/owncloud/android/MainApp.java index d9f4e19720..2f346e6e2d 100644 --- a/app/src/main/java/com/owncloud/android/MainApp.java +++ b/app/src/main/java/com/owncloud/android/MainApp.java @@ -422,8 +422,8 @@ public class MainApp extends Application implements HasAndroidInjector, NetworkC return; } - String host = ContextExtensionsKt.getRestriction(this, AppConfigKeys.ProxyHost.getKey(), getString(R.string.proxy_host)); - int port = ContextExtensionsKt.getRestriction(this, AppConfigKeys.ProxyPort.getKey(), getResources().getInteger(R.integer.proxy_port)); + String host = ContextExtensionsKt.getRestriction(this, AppConfigKeys.ProxyHost, getString(R.string.proxy_host)); + int port = ContextExtensionsKt.getRestriction(this, AppConfigKeys.ProxyPort, getResources().getInteger(R.integer.proxy_port)); if (TextUtils.isEmpty(host) || port == -1) { Log_OC.d(TAG, "Proxy configuration cannot be found"); diff --git a/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java b/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java index b83bce5071..4ce2b782a1 100644 --- a/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -321,7 +321,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity String webloginUrl = null; if (MainApp.isClientBrandedPlus()) { - String baseUrl = ContextExtensionsKt.getRestriction(this, AppConfigKeys.BaseUrl.getKey(), ""); + String baseUrl = ContextExtensionsKt.getRestriction(this, AppConfigKeys.BaseUrl, ""); if (!TextUtils.isEmpty(baseUrl)) { webloginUrl = baseUrl + WEB_LOGIN; } diff --git a/app/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.kt b/app/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.kt index 6a64fe9195..37cd8bd73b 100644 --- a/app/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.kt +++ b/app/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.kt @@ -88,7 +88,7 @@ class SendShareDialog : BottomSheetDialogFragment(R.layout.send_share_fragment), @Suppress("MagicNumber") private fun setupSendButtonRecyclerView() { val disableSharing = requireContext().getRestriction( - AppConfigKeys.DisableSharing.key, + AppConfigKeys.DisableSharing, context?.resources?.getBoolean(R.bool.disable_sharing) ?: false ) diff --git a/app/src/main/java/com/owncloud/android/utils/ClipboardUtil.kt b/app/src/main/java/com/owncloud/android/utils/ClipboardUtil.kt index d4f45a730f..94766fd57c 100644 --- a/app/src/main/java/com/owncloud/android/utils/ClipboardUtil.kt +++ b/app/src/main/java/com/owncloud/android/utils/ClipboardUtil.kt @@ -28,7 +28,7 @@ object ClipboardUtil { @Suppress("TooGenericExceptionCaught") fun copyToClipboard(activity: Activity, text: String?, showToast: Boolean = true) { val disableClipboard = activity.getRestriction( - AppConfigKeys.DisableClipboard.key, + AppConfigKeys.DisableClipboard, activity.resources.getBoolean(R.bool.disable_clipboard) ) if (disableClipboard) { From da1a9518e0138acbb2b1778b430195dbc00d41bb Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 4 Nov 2024 17:10:55 +0100 Subject: [PATCH 12/52] handle nullable RestrictionsManager Signed-off-by: alperozturk --- .../java/com/nextcloud/utils/extensions/ContextExtensions.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt index 5c6010d7e4..ea416e139f 100644 --- a/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt +++ b/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt @@ -23,8 +23,8 @@ import com.owncloud.android.datamodel.ReceiverFlag import com.owncloud.android.utils.appConfig.AppConfigKeys fun Context.getRestriction(appConfigKey: AppConfigKeys, defaultValue: T): T { - val restrictionsManager = getSystemService(Context.RESTRICTIONS_SERVICE) as RestrictionsManager - return restrictionsManager.getRestriction(appConfigKey.key, defaultValue) + val restrictionsManager = getSystemService(Context.RESTRICTIONS_SERVICE) as? RestrictionsManager + return restrictionsManager?.getRestriction(appConfigKey.key, defaultValue) ?: defaultValue } @Suppress("UNCHECKED_CAST") From 00c2b76b176f9c6f068cd12b1423dc2fcfc0ebb8 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 5 Nov 2024 10:27:04 +0100 Subject: [PATCH 13/52] add all mdm configs Signed-off-by: alperozturk --- .../android/utils/appConfig/AppConfigKeys.kt | 5 +-- app/src/main/res/values/setup.xml | 2 +- app/src/main/res/values/strings.xml | 6 ++++ app/src/main/res/xml/app_config.xml | 36 +++++++++++++++++++ 4 files changed, 46 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/utils/appConfig/AppConfigKeys.kt b/app/src/main/java/com/owncloud/android/utils/appConfig/AppConfigKeys.kt index 912586052e..ea4db8fc02 100644 --- a/app/src/main/java/com/owncloud/android/utils/appConfig/AppConfigKeys.kt +++ b/app/src/main/java/com/owncloud/android/utils/appConfig/AppConfigKeys.kt @@ -14,9 +14,10 @@ enum class AppConfigKeys(val key: String) { BaseUrl("base_url"), ProxyHost("proxy_host"), ProxyPort("proxy_port"), - DisableIntro("disable_intro"), DisableMultiAccount("disable_multiaccount"), DisableSharing("disable_sharing"), DisableClipboard("disable_clipboard"), - // TODO add other MDM's + DisableMoreExternalSite("disable_more_external_site"), + DisableIntro("disable_intro"), + DisableLog("disable_log"), } diff --git a/app/src/main/res/values/setup.xml b/app/src/main/res/values/setup.xml index 6f2b38eab8..143586cb76 100644 --- a/app/src/main/res/values/setup.xml +++ b/app/src/main/res/values/setup.xml @@ -39,7 +39,7 @@ false false false - false + true false diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index df0aa8fc00..228a01825b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -26,6 +26,12 @@ Pending Operation Assistant Unexpected error occurred + Disable Multi Account + Disable Sharing + Disable Clipboard + Disable External Sites + Disable Intro + Disable Log Base URL Proxy Hostname Proxy Port diff --git a/app/src/main/res/xml/app_config.xml b/app/src/main/res/xml/app_config.xml index e4043cbc1e..89d22b0853 100644 --- a/app/src/main/res/xml/app_config.xml +++ b/app/src/main/res/xml/app_config.xml @@ -25,4 +25,40 @@ android:restrictionType="string" android:title="@string/app_config_base_url_title" /> + + + + + + + + + + + + \ No newline at end of file From 79ebc7c6f14ec5516b702d0128166bba9f03a3a7 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 5 Nov 2024 10:28:00 +0100 Subject: [PATCH 14/52] add all mdm configs Signed-off-by: alperozturk --- app/src/main/res/values/setup.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values/setup.xml b/app/src/main/res/values/setup.xml index 143586cb76..6f2b38eab8 100644 --- a/app/src/main/res/values/setup.xml +++ b/app/src/main/res/values/setup.xml @@ -39,7 +39,7 @@ false false false - true + false false From 66150af6366de32b7678103756d5534caeb5e203 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 5 Nov 2024 10:28:46 +0100 Subject: [PATCH 15/52] add all mdm configs Signed-off-by: alperozturk --- app/src/main/res/values/setup.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/res/values/setup.xml b/app/src/main/res/values/setup.xml index 6f2b38eab8..ac64932de5 100644 --- a/app/src/main/res/values/setup.xml +++ b/app/src/main/res/values/setup.xml @@ -41,6 +41,8 @@ false false false + false + on From 8b8ac0b0384f82f4351968fc535976def4f703f4 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 5 Nov 2024 10:31:20 +0100 Subject: [PATCH 16/52] use disableIntro Signed-off-by: alperozturk --- .../com/nextcloud/client/onboarding/OnboardingServiceImpl.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/nextcloud/client/onboarding/OnboardingServiceImpl.kt b/app/src/main/java/com/nextcloud/client/onboarding/OnboardingServiceImpl.kt index 95b9b677f7..ef7f854349 100644 --- a/app/src/main/java/com/nextcloud/client/onboarding/OnboardingServiceImpl.kt +++ b/app/src/main/java/com/nextcloud/client/onboarding/OnboardingServiceImpl.kt @@ -13,11 +13,13 @@ import android.content.Intent import android.content.res.Resources import com.nextcloud.client.account.CurrentAccountProvider import com.nextcloud.client.preferences.AppPreferences +import com.nextcloud.utils.extensions.getRestriction import com.owncloud.android.BuildConfig import com.owncloud.android.R import com.owncloud.android.authentication.AuthenticatorActivity import com.owncloud.android.features.FeatureItem import com.owncloud.android.ui.activity.PassCodeActivity +import com.owncloud.android.utils.appConfig.AppConfigKeys internal class OnboardingServiceImpl constructor( private val resources: Resources, @@ -61,9 +63,10 @@ internal class OnboardingServiceImpl constructor( } override fun launchFirstRunIfNeeded(activity: Activity): Boolean { + val disableIntro = activity.getRestriction(AppConfigKeys.DisableIntro, resources.getBoolean(R.bool.disable_intro)) val isProviderOrOwnInstallationVisible = resources.getBoolean(R.bool.show_provider_or_own_installation) val canLaunch = isProviderOrOwnInstallationVisible && isFirstRun && activity is AuthenticatorActivity - if (canLaunch) { + if (canLaunch && !disableIntro) { val intent = Intent(activity, FirstRunActivity::class.java) activity.startActivityForResult(intent, AuthenticatorActivity.REQUEST_CODE_FIRST_RUN) } From 904e556a97b1c2b5d38f3a243cb4ec633c0f5f3d Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 5 Nov 2024 10:36:54 +0100 Subject: [PATCH 17/52] use disableIntro Signed-off-by: alperozturk --- .../client/onboarding/FirstRunActivity.kt | 7 +++++-- .../android/ui/activity/DrawerActivity.java | 5 ++++- .../android/ui/adapter/UserListAdapter.java | 15 +++++++++++---- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/nextcloud/client/onboarding/FirstRunActivity.kt b/app/src/main/java/com/nextcloud/client/onboarding/FirstRunActivity.kt index 132189c36a..748c20cc35 100644 --- a/app/src/main/java/com/nextcloud/client/onboarding/FirstRunActivity.kt +++ b/app/src/main/java/com/nextcloud/client/onboarding/FirstRunActivity.kt @@ -24,6 +24,7 @@ import com.nextcloud.client.account.UserAccountManager import com.nextcloud.client.appinfo.AppInfo import com.nextcloud.client.di.Injectable import com.nextcloud.client.preferences.AppPreferences +import com.nextcloud.utils.extensions.getRestriction import com.owncloud.android.BuildConfig import com.owncloud.android.R import com.owncloud.android.authentication.AuthenticatorActivity @@ -33,6 +34,7 @@ import com.owncloud.android.ui.activity.BaseActivity import com.owncloud.android.ui.activity.FileDisplayActivity import com.owncloud.android.ui.adapter.FeaturesViewAdapter import com.owncloud.android.utils.DisplayUtils +import com.owncloud.android.utils.appConfig.AppConfigKeys import com.owncloud.android.utils.theme.ViewThemeUtils import javax.inject.Inject @@ -76,13 +78,14 @@ class FirstRunActivity : BaseActivity(), Injectable { binding = FirstRunActivityBinding.inflate(layoutInflater) setContentView(binding.root) + val disableIntro = getRestriction(AppConfigKeys.DisableIntro, resources.getBoolean(R.bool.disable_intro)) val isProviderOrOwnInstallationVisible = resources.getBoolean(R.bool.show_provider_or_own_installation) setSlideshowSize(resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) registerActivityResult() setupLoginButton() - setupSignupButton(isProviderOrOwnInstallationVisible) - setupHostOwnServerTextView(isProviderOrOwnInstallationVisible) + setupSignupButton(isProviderOrOwnInstallationVisible && !disableIntro) + setupHostOwnServerTextView(isProviderOrOwnInstallationVisible && !disableIntro) deleteAccountAtFirstLaunch() setupFeaturesViewAdapter() handleOnBackPressed() diff --git a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java index 9d6e8704c3..bcd3a059f1 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java @@ -59,6 +59,7 @@ import com.nextcloud.common.NextcloudClient; import com.nextcloud.ui.ChooseAccountDialogFragment; import com.nextcloud.ui.composeActivity.ComposeActivity; import com.nextcloud.ui.composeActivity.ComposeDestination; +import com.nextcloud.utils.extensions.ContextExtensionsKt; import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.authentication.PassCodeManager; @@ -95,6 +96,7 @@ import com.owncloud.android.utils.BitmapUtils; import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.DrawerMenuUtil; import com.owncloud.android.utils.FilesSyncHelper; +import com.owncloud.android.utils.appConfig.AppConfigKeys; import com.owncloud.android.utils.svg.MenuSimpleTarget; import com.owncloud.android.utils.svg.SVGorImage; import com.owncloud.android.utils.svg.SvgOrImageBitmapTranscoder; @@ -602,10 +604,11 @@ public abstract class DrawerActivity extends ToolbarActivity } public void openAddAccount() { + boolean disableIntro = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableIntro, getResources().getBoolean(R.bool.disable_intro)); boolean isProviderOrOwnInstallationVisible = getResources() .getBoolean(R.bool.show_provider_or_own_installation); - if (isProviderOrOwnInstallationVisible) { + if (isProviderOrOwnInstallationVisible && !disableIntro) { Intent firstRunIntent = new Intent(getApplicationContext(), FirstRunActivity.class); firstRunIntent.putExtra(FirstRunActivity.EXTRA_ALLOW_CLOSE, true); startActivity(firstRunIntent); diff --git a/app/src/main/java/com/owncloud/android/ui/adapter/UserListAdapter.java b/app/src/main/java/com/owncloud/android/ui/adapter/UserListAdapter.java index 747355080b..b39f28dcfc 100644 --- a/app/src/main/java/com/owncloud/android/ui/adapter/UserListAdapter.java +++ b/app/src/main/java/com/owncloud/android/ui/adapter/UserListAdapter.java @@ -22,12 +22,14 @@ import android.widget.ImageView; import com.nextcloud.client.account.User; import com.nextcloud.client.account.UserAccountManager; +import com.nextcloud.utils.extensions.ContextExtensionsKt; import com.owncloud.android.R; import com.owncloud.android.databinding.AccountActionBinding; import com.owncloud.android.databinding.AccountItemBinding; import com.owncloud.android.lib.common.OwnCloudAccount; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.utils.DisplayUtils; +import com.owncloud.android.utils.appConfig.AppConfigKeys; import com.owncloud.android.utils.theme.ViewThemeUtils; import java.util.ArrayList; @@ -94,7 +96,9 @@ public class UserListAdapter extends RecyclerView.Adapter accountListAdapterListener.showFirstRunActivity()); } else { itemView.setOnClickListener(v -> accountListAdapterListener.startAccountCreation()); From bae0ab70f63eac79f95e874fe3507d04e4e7a689 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 5 Nov 2024 10:39:37 +0100 Subject: [PATCH 18/52] use disableMoreExternalSite Signed-off-by: alperozturk --- .../com/owncloud/android/ui/activity/DrawerActivity.java | 9 ++++++--- .../owncloud/android/ui/activity/SettingsActivity.java | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java index bcd3a059f1..8a09a8aa74 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java @@ -827,7 +827,8 @@ public abstract class DrawerActivity extends ToolbarActivity private void updateQuotaLink() { if (mQuotaTextLink != null) { - if (getBaseContext().getResources().getBoolean(R.bool.show_external_links)) { + boolean disableMoreExternalSite = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableMoreExternalSite, getResources().getBoolean(R.bool.disable_more_external_site)); + if (getBaseContext().getResources().getBoolean(R.bool.show_external_links) && !disableMoreExternalSite) { List quotas = externalLinksProvider.getExternalLink(ExternalLinkType.QUOTA); float density = getResources().getDisplayMetrics().density; @@ -976,7 +977,8 @@ public abstract class DrawerActivity extends ToolbarActivity } private void updateExternalLinksInDrawer() { - if (mNavigationView != null && getBaseContext().getResources().getBoolean(R.bool.show_external_links)) { + boolean disableMoreExternalSite = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableMoreExternalSite, getResources().getBoolean(R.bool.disable_more_external_site)); + if (mNavigationView != null && getBaseContext().getResources().getBoolean(R.bool.show_external_links) && !disableMoreExternalSite) { mNavigationView.getMenu().removeGroup(R.id.drawer_menu_external_links); int greyColor = ContextCompat.getColor(this, R.color.drawer_menu_icon); @@ -1225,7 +1227,8 @@ public abstract class DrawerActivity extends ToolbarActivity * Retrieves external links via api from 'external' app */ public void fetchExternalLinks(final boolean force) { - if (!getBaseContext().getResources().getBoolean(R.bool.show_external_links)) { + boolean disableMoreExternalSite = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableMoreExternalSite, getResources().getBoolean(R.bool.disable_more_external_site)); + if (!getBaseContext().getResources().getBoolean(R.bool.show_external_links) || disableMoreExternalSite) { return; } diff --git a/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java index b17f814b57..e543d22839 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java @@ -50,6 +50,7 @@ import com.nextcloud.client.network.ConnectivityService; import com.nextcloud.client.preferences.AppPreferences; import com.nextcloud.client.preferences.AppPreferencesImpl; import com.nextcloud.client.preferences.DarkMode; +import com.nextcloud.utils.extensions.ContextExtensionsKt; import com.owncloud.android.BuildConfig; import com.owncloud.android.MainApp; import com.owncloud.android.R; @@ -72,6 +73,7 @@ import com.owncloud.android.utils.DeviceCredentialUtils; import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.EncryptionUtils; import com.owncloud.android.utils.MimeTypeUtil; +import com.owncloud.android.utils.appConfig.AppConfigKeys; import com.owncloud.android.utils.theme.CapabilityUtils; import com.owncloud.android.utils.theme.ViewThemeUtils; @@ -1101,7 +1103,8 @@ public class SettingsActivity extends PreferenceActivity } private void loadExternalSettingLinks(PreferenceCategory preferenceCategory) { - if (getBaseContext().getResources().getBoolean(R.bool.show_external_links)) { + boolean disableMoreExternalSite = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableMoreExternalSite, getResources().getBoolean(R.bool.disable_more_external_site)); + if (getBaseContext().getResources().getBoolean(R.bool.show_external_links) && !disableMoreExternalSite) { ExternalLinksProvider externalLinksProvider = new ExternalLinksProvider(getContentResolver()); for (final ExternalLink link : externalLinksProvider.getExternalLink(ExternalLinkType.SETTINGS)) { From 22b091014dba74e18807191e7d479f8cc66873b4 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 5 Nov 2024 10:41:46 +0100 Subject: [PATCH 19/52] use disableLog Signed-off-by: alperozturk --- app/src/main/java/com/owncloud/android/MainApp.java | 4 ++-- .../com/owncloud/android/ui/activity/SettingsActivity.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/MainApp.java b/app/src/main/java/com/owncloud/android/MainApp.java index 2f346e6e2d..067d710582 100644 --- a/app/src/main/java/com/owncloud/android/MainApp.java +++ b/app/src/main/java/com/owncloud/android/MainApp.java @@ -339,8 +339,8 @@ public class MainApp extends Application implements HasAndroidInjector, NetworkC // initialise thumbnails cache on background thread new ThumbnailsCacheManager.InitDiskCacheTask().execute(); - - if (BuildConfig.DEBUG || getApplicationContext().getResources().getBoolean(R.bool.logger_enabled)) { + boolean disableLog = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableLog, getResources().getBoolean(R.bool.disable_log)); + if ((BuildConfig.DEBUG || getApplicationContext().getResources().getBoolean(R.bool.logger_enabled)) && !disableLog) { // use app writable dir, no permissions needed Log_OC.setLoggerImplementation(new LegacyLoggerAdapter(logger)); Log_OC.d("Debug", "start logging"); diff --git a/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java index e543d22839..9cbd09d501 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java @@ -381,11 +381,11 @@ public class SettingsActivity extends PreferenceActivity } private void setupLoggingPreference(PreferenceCategory preferenceCategoryMore) { - + boolean disableLog = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableLog, getResources().getBoolean(R.bool.disable_log)); boolean loggerEnabled = getResources().getBoolean(R.bool.logger_enabled) || BuildConfig.DEBUG; Preference pLogger = findPreference("logger"); if (pLogger != null) { - if (loggerEnabled) { + if (loggerEnabled && !disableLog) { pLogger.setOnPreferenceClickListener(preference -> { Intent loggerIntent = new Intent(getApplicationContext(), LogsActivity.class); startActivity(loggerIntent); From 5662885d829630209e2d4bf46085addca0ad4740 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 5 Nov 2024 10:49:36 +0100 Subject: [PATCH 20/52] use disableSharing Signed-off-by: alperozturk --- .../com/owncloud/android/files/FileMenuFilter.java | 11 ++++++++--- .../com/owncloud/android/ui/dialog/SendShareDialog.kt | 11 ----------- .../android/ui/helpers/FileOperationsHelper.java | 2 ++ 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/files/FileMenuFilter.java b/app/src/main/java/com/owncloud/android/files/FileMenuFilter.java index 3170f934cd..277c69568c 100644 --- a/app/src/main/java/com/owncloud/android/files/FileMenuFilter.java +++ b/app/src/main/java/com/owncloud/android/files/FileMenuFilter.java @@ -23,6 +23,7 @@ import com.nextcloud.client.editimage.EditImageActivity; import com.nextcloud.client.jobs.download.FileDownloadHelper; import com.nextcloud.client.jobs.upload.FileUploadHelper; import com.nextcloud.utils.EditorUtils; +import com.nextcloud.utils.extensions.ContextExtensionsKt; import com.owncloud.android.R; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; @@ -32,6 +33,7 @@ import com.owncloud.android.ui.activity.ComponentsGetter; import com.owncloud.android.ui.helpers.FileOperationsHelper; import com.owncloud.android.utils.MimeTypeUtil; import com.owncloud.android.utils.NextcloudServer; +import com.owncloud.android.utils.appConfig.AppConfigKeys; import java.util.ArrayList; import java.util.Collection; @@ -184,7 +186,8 @@ public class FileMenuFilter { } private void filterSendFiles(List toHide, boolean inSingleFileFragment) { - if ((overflowMenu || SEND_OFF.equalsIgnoreCase(context.getString(R.string.send_files_to_other_apps)) || containsEncryptedFile()) || + boolean disableSharing = ContextExtensionsKt.getRestriction(context, AppConfigKeys.DisableSharing, context.getResources().getBoolean(R.bool.disable_sharing)); + if (!disableSharing || (overflowMenu || SEND_OFF.equalsIgnoreCase(context.getString(R.string.send_files_to_other_apps)) || containsEncryptedFile()) || (!inSingleFileFragment && (isSingleSelection() || !allFileDown())) || !toHide.contains(R.id.action_send_share_file)) { toHide.add(R.id.action_send_file); @@ -426,12 +429,14 @@ public class FileMenuFilter { private boolean isShareWithUsersAllowed() { return context != null && - context.getResources().getBoolean(R.bool.share_with_users_feature); + context.getResources().getBoolean(R.bool.share_with_users_feature) && + !ContextExtensionsKt.getRestriction(context, AppConfigKeys.DisableSharing, context.getResources().getBoolean(R.bool.disable_sharing)); } private boolean isShareViaLinkAllowed() { return context != null && - context.getResources().getBoolean(R.bool.share_via_link_feature); + context.getResources().getBoolean(R.bool.share_via_link_feature) && + !ContextExtensionsKt.getRestriction(context, AppConfigKeys.DisableSharing, context.getResources().getBoolean(R.bool.disable_sharing)); } private boolean isSingleSelection() { diff --git a/app/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.kt b/app/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.kt index 37cd8bd73b..9be56aff7e 100644 --- a/app/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.kt +++ b/app/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.kt @@ -27,7 +27,6 @@ import com.nextcloud.android.common.ui.theme.utils.ColorRole import com.nextcloud.client.di.Injectable import com.nextcloud.client.utils.IntentUtil.createSendIntent import com.nextcloud.utils.extensions.getParcelableArgument -import com.nextcloud.utils.extensions.getRestriction import com.owncloud.android.BuildConfig import com.owncloud.android.R import com.owncloud.android.databinding.SendShareFragmentBinding @@ -40,7 +39,6 @@ import com.owncloud.android.ui.adapter.SendButtonAdapter import com.owncloud.android.ui.components.SendButtonData import com.owncloud.android.ui.helpers.FileOperationsHelper import com.owncloud.android.utils.MimeTypeUtil -import com.owncloud.android.utils.appConfig.AppConfigKeys import com.owncloud.android.utils.theme.ViewThemeUtils import javax.inject.Inject @@ -87,15 +85,6 @@ class SendShareDialog : BottomSheetDialogFragment(R.layout.send_share_fragment), @Suppress("MagicNumber") private fun setupSendButtonRecyclerView() { - val disableSharing = requireContext().getRestriction( - AppConfigKeys.DisableSharing, - context?.resources?.getBoolean(R.bool.disable_sharing) ?: false - ) - - if (disableSharing) { - return - } - val sendIntent = createSendIntent(requireContext(), file!!) val sendButtonDataList = setupSendButtonData(sendIntent) val clickListener = setupSendButtonClickListener(sendIntent) diff --git a/app/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java b/app/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java index 6b765c2afd..8841c74c78 100755 --- a/app/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java +++ b/app/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java @@ -36,6 +36,7 @@ import com.nextcloud.client.jobs.download.FileDownloadHelper; import com.nextcloud.client.jobs.upload.FileUploadHelper; import com.nextcloud.client.network.ConnectivityService; import com.nextcloud.utils.EditorUtils; +import com.nextcloud.utils.extensions.ContextExtensionsKt; import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.datamodel.ArbitraryDataProvider; @@ -69,6 +70,7 @@ import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.EncryptionUtils; import com.owncloud.android.utils.FileStorageUtils; import com.owncloud.android.utils.UriUtils; +import com.owncloud.android.utils.appConfig.AppConfigKeys; import com.owncloud.android.utils.theme.ViewThemeUtils; import org.greenrobot.eventbus.EventBus; From 87784c23453dcb7827a98e6d9cb5448affc83527 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 5 Nov 2024 10:52:47 +0100 Subject: [PATCH 21/52] add default values Signed-off-by: alperozturk --- .../nextcloud/utils/extensions/ContextExtensions.kt | 6 +++--- app/src/main/res/xml/app_config.xml | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt index ea416e139f..d953e2d594 100644 --- a/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt +++ b/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt @@ -31,9 +31,9 @@ fun Context.getRestriction(appConfigKey: AppConfigKeys, defaultValue: private fun RestrictionsManager.getRestriction(key: String, defaultValue: T): T { val appRestrictions = getApplicationRestrictions() return when (defaultValue) { - is String -> appRestrictions.getString(key) as T? ?: defaultValue - is Int -> appRestrictions.getInt(key) as T? ?: defaultValue - is Boolean -> appRestrictions.getBoolean(key) as T? ?: defaultValue + is String -> appRestrictions.getString(key, defaultValue) as T? ?: defaultValue + is Int -> appRestrictions.getInt(key, defaultValue) as T? ?: defaultValue + is Boolean -> appRestrictions.getBoolean(key, defaultValue) as T? ?: defaultValue else -> defaultValue } } diff --git a/app/src/main/res/xml/app_config.xml b/app/src/main/res/xml/app_config.xml index 89d22b0853..d6c4038a2b 100644 --- a/app/src/main/res/xml/app_config.xml +++ b/app/src/main/res/xml/app_config.xml @@ -27,37 +27,37 @@ From 66902d2ced1c0f272caa0f821ff90002b2b1bfe3 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 5 Nov 2024 11:08:46 +0100 Subject: [PATCH 22/52] use disable_multiaccount Signed-off-by: alperozturk --- .../client/onboarding/FirstRunActivity.kt | 6 +++--- .../onboarding/OnboardingServiceImpl.kt | 6 +++--- .../ui/ChooseAccountDialogFragment.kt | 20 ++++++------------- .../authentication/AccountAuthenticator.java | 5 ++++- .../authentication/AuthenticatorActivity.java | 9 ++++++--- .../authentication/DeepLinkLoginActivity.kt | 7 +++++-- .../ui/activity/ManageAccountsActivity.java | 9 ++++++--- 7 files changed, 33 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/com/nextcloud/client/onboarding/FirstRunActivity.kt b/app/src/main/java/com/nextcloud/client/onboarding/FirstRunActivity.kt index 748c20cc35..e811b81664 100644 --- a/app/src/main/java/com/nextcloud/client/onboarding/FirstRunActivity.kt +++ b/app/src/main/java/com/nextcloud/client/onboarding/FirstRunActivity.kt @@ -78,14 +78,14 @@ class FirstRunActivity : BaseActivity(), Injectable { binding = FirstRunActivityBinding.inflate(layoutInflater) setContentView(binding.root) - val disableIntro = getRestriction(AppConfigKeys.DisableIntro, resources.getBoolean(R.bool.disable_intro)) + val disableIntroViaMDM = getRestriction(AppConfigKeys.DisableIntro, resources.getBoolean(R.bool.disable_intro)) val isProviderOrOwnInstallationVisible = resources.getBoolean(R.bool.show_provider_or_own_installation) setSlideshowSize(resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) registerActivityResult() setupLoginButton() - setupSignupButton(isProviderOrOwnInstallationVisible && !disableIntro) - setupHostOwnServerTextView(isProviderOrOwnInstallationVisible && !disableIntro) + setupSignupButton(isProviderOrOwnInstallationVisible && !disableIntroViaMDM) + setupHostOwnServerTextView(isProviderOrOwnInstallationVisible && !disableIntroViaMDM) deleteAccountAtFirstLaunch() setupFeaturesViewAdapter() handleOnBackPressed() diff --git a/app/src/main/java/com/nextcloud/client/onboarding/OnboardingServiceImpl.kt b/app/src/main/java/com/nextcloud/client/onboarding/OnboardingServiceImpl.kt index ef7f854349..b928c7b172 100644 --- a/app/src/main/java/com/nextcloud/client/onboarding/OnboardingServiceImpl.kt +++ b/app/src/main/java/com/nextcloud/client/onboarding/OnboardingServiceImpl.kt @@ -21,7 +21,7 @@ import com.owncloud.android.features.FeatureItem import com.owncloud.android.ui.activity.PassCodeActivity import com.owncloud.android.utils.appConfig.AppConfigKeys -internal class OnboardingServiceImpl constructor( +internal class OnboardingServiceImpl( private val resources: Resources, private val preferences: AppPreferences, private val accountProvider: CurrentAccountProvider @@ -63,10 +63,10 @@ internal class OnboardingServiceImpl constructor( } override fun launchFirstRunIfNeeded(activity: Activity): Boolean { - val disableIntro = activity.getRestriction(AppConfigKeys.DisableIntro, resources.getBoolean(R.bool.disable_intro)) + val disableIntroViaMDM = activity.getRestriction(AppConfigKeys.DisableIntro, resources.getBoolean(R.bool.disable_intro)) val isProviderOrOwnInstallationVisible = resources.getBoolean(R.bool.show_provider_or_own_installation) val canLaunch = isProviderOrOwnInstallationVisible && isFirstRun && activity is AuthenticatorActivity - if (canLaunch && !disableIntro) { + if (canLaunch && !disableIntroViaMDM) { val intent = Intent(activity, FirstRunActivity::class.java) activity.startActivityForResult(intent, AuthenticatorActivity.REQUEST_CODE_FIRST_RUN) } diff --git a/app/src/main/java/com/nextcloud/ui/ChooseAccountDialogFragment.kt b/app/src/main/java/com/nextcloud/ui/ChooseAccountDialogFragment.kt index 50dd7f7de6..5478ad6667 100644 --- a/app/src/main/java/com/nextcloud/ui/ChooseAccountDialogFragment.kt +++ b/app/src/main/java/com/nextcloud/ui/ChooseAccountDialogFragment.kt @@ -122,8 +122,13 @@ class ChooseAccountDialogFragment : viewThemeUtils ) + val disableMultiAccountViaMDM = requireContext().getRestriction( + AppConfigKeys.DisableMultiAccount, + context?.resources?.getBoolean(R.bool.disable_multiaccount) ?: false + ) + // hide "add account" when no multi account - if (!resources.getBoolean(R.bool.multiaccount_support)) { + if (!resources.getBoolean(R.bool.multiaccount_support) || disableMultiAccountViaMDM) { binding.addAccount.visibility = View.GONE } @@ -158,19 +163,6 @@ class ChooseAccountDialogFragment : } themeViews() - checkAppRestrictions() - } - - private fun checkAppRestrictions() { - val disableMultiAccount = requireContext().getRestriction( - AppConfigKeys.DisableMultiAccount, - context?.resources?.getBoolean(R.bool.disable_multiaccount) ?: false - ) - - if (disableMultiAccount) { - binding.addAccount.visibility = View.GONE - binding.manageAccounts.visibility = View.GONE - } } private fun loadAndSetUserStatus(user: User) { diff --git a/app/src/main/java/com/owncloud/android/authentication/AccountAuthenticator.java b/app/src/main/java/com/owncloud/android/authentication/AccountAuthenticator.java index 591d3ecc74..d7e49ff62b 100644 --- a/app/src/main/java/com/owncloud/android/authentication/AccountAuthenticator.java +++ b/app/src/main/java/com/owncloud/android/authentication/AccountAuthenticator.java @@ -21,10 +21,12 @@ import android.os.Bundle; import android.os.Handler; import android.widget.Toast; +import com.nextcloud.utils.extensions.ContextExtensionsKt; import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.lib.common.accounts.AccountTypeUtils; import com.owncloud.android.lib.common.utils.Log_OC; +import com.owncloud.android.utils.appConfig.AppConfigKeys; /** * Authenticator for ownCloud accounts. @@ -70,7 +72,8 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator { final Bundle bundle = new Bundle(); - if (mContext.getResources().getBoolean(R.bool.multiaccount_support) || accounts.length < 1) { + boolean disableMultiAccountViaMDM = ContextExtensionsKt.getRestriction(mContext, AppConfigKeys.DisableMultiAccount, mContext.getResources().getBoolean(R.bool.disable_multiaccount)); + if (!disableMultiAccountViaMDM && mContext.getResources().getBoolean(R.bool.multiaccount_support) && accounts.length > 1) { try { validateAccountType(accountType); } catch (AuthenticatorException e) { diff --git a/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java b/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java index 4ce2b782a1..f6f8b9cc69 100644 --- a/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -811,9 +811,10 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity passCodeManager.onActivityResumed(this); Uri data = intent.getData(); - + boolean disableMultiAccountViaMDM = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableMultiAccount, getResources().getBoolean(R.bool.disable_multiaccount)); if (data != null && data.toString().startsWith(getString(R.string.login_data_own_scheme))) { - if (!getResources().getBoolean(R.bool.multiaccount_support) && + if (disableMultiAccountViaMDM || + !getResources().getBoolean(R.bool.multiaccount_support) || accountManager.getAccounts().length == 1) { Toast.makeText(this, R.string.no_mutliple_accounts_allowed, Toast.LENGTH_LONG).show(); finish(); @@ -1534,7 +1535,9 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity return; } - if (!getResources().getBoolean(R.bool.multiaccount_support) && + boolean disableMultiAccountViaMDM = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableMultiAccount, getResources().getBoolean(R.bool.disable_multiaccount)); + if (disableMultiAccountViaMDM || + !getResources().getBoolean(R.bool.multiaccount_support) || accountManager.getAccounts().length == 1) { Toast.makeText(this, R.string.no_mutliple_accounts_allowed, Toast.LENGTH_LONG).show(); } else { diff --git a/app/src/main/java/com/owncloud/android/authentication/DeepLinkLoginActivity.kt b/app/src/main/java/com/owncloud/android/authentication/DeepLinkLoginActivity.kt index 25283adcbc..6a6ca6691b 100644 --- a/app/src/main/java/com/owncloud/android/authentication/DeepLinkLoginActivity.kt +++ b/app/src/main/java/com/owncloud/android/authentication/DeepLinkLoginActivity.kt @@ -11,14 +11,17 @@ import android.os.Bundle import android.widget.TextView import android.widget.Toast import com.nextcloud.client.di.Injectable +import com.nextcloud.utils.extensions.getRestriction import com.owncloud.android.R +import com.owncloud.android.utils.appConfig.AppConfigKeys class DeepLinkLoginActivity : AuthenticatorActivity(), Injectable { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - - if (!resources.getBoolean(R.bool.multiaccount_support) && + val disableMultiAccountViaMDM = getRestriction(AppConfigKeys.DisableMultiAccount, resources.getBoolean(R.bool.disable_multiaccount)) + if (disableMultiAccountViaMDM || + !resources.getBoolean(R.bool.multiaccount_support) || accountManager.accounts.size == 1 ) { Toast.makeText(this, R.string.no_mutliple_accounts_allowed, Toast.LENGTH_LONG).show() diff --git a/app/src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java index 4ff007d2bc..602e5bff33 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java @@ -30,6 +30,7 @@ import com.nextcloud.client.onboarding.FirstRunActivity; import com.nextcloud.model.WorkerState; import com.nextcloud.model.WorkerStateLiveData; import com.nextcloud.utils.extensions.BundleExtensionsKt; +import com.nextcloud.utils.extensions.ContextExtensionsKt; import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.authentication.AuthenticatorActivity; @@ -46,6 +47,7 @@ import com.owncloud.android.ui.adapter.UserListItem; import com.owncloud.android.ui.dialog.AccountRemovalDialog; import com.owncloud.android.ui.events.AccountRemovedEvent; import com.owncloud.android.ui.helpers.FileOperationsHelper; +import com.owncloud.android.utils.appConfig.AppConfigKeys; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; @@ -131,8 +133,8 @@ public class ManageAccountsActivity extends FileActivity implements UserListAdap } arbitraryDataProvider = new ArbitraryDataProviderImpl(this); - - multipleAccountsSupported = getResources().getBoolean(R.bool.multiaccount_support); + boolean disableMultiAccountViaMDM = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableMultiAccount, getResources().getBoolean(R.bool.disable_multiaccount)); + multipleAccountsSupported = getResources().getBoolean(R.bool.multiaccount_support) && !disableMultiAccountViaMDM; userListAdapter = new UserListAdapter(this, accountManager, @@ -230,7 +232,8 @@ public class ManageAccountsActivity extends FileActivity implements UserListAdap userListItems.add(new UserListItem(user, !pendingForRemoval)); } - if (getResources().getBoolean(R.bool.multiaccount_support)) { + boolean disableMultiAccountViaMDM = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableMultiAccount, getResources().getBoolean(R.bool.disable_multiaccount)); + if (getResources().getBoolean(R.bool.multiaccount_support) && !disableMultiAccountViaMDM) { userListItems.add(new UserListItem()); } From 8bdfbb49ab0fd36dee5d28f89ab668c9a9f48d4e Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 5 Nov 2024 11:13:24 +0100 Subject: [PATCH 23/52] better variable naming Signed-off-by: alperozturk --- .../main/java/com/owncloud/android/MainApp.java | 4 ++-- .../owncloud/android/files/FileMenuFilter.java | 4 ++-- .../android/ui/activity/DrawerActivity.java | 16 ++++++++-------- .../android/ui/activity/SettingsActivity.java | 8 ++++---- .../android/ui/adapter/UserListAdapter.java | 4 ++-- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/MainApp.java b/app/src/main/java/com/owncloud/android/MainApp.java index 067d710582..631e2fd4e8 100644 --- a/app/src/main/java/com/owncloud/android/MainApp.java +++ b/app/src/main/java/com/owncloud/android/MainApp.java @@ -339,8 +339,8 @@ public class MainApp extends Application implements HasAndroidInjector, NetworkC // initialise thumbnails cache on background thread new ThumbnailsCacheManager.InitDiskCacheTask().execute(); - boolean disableLog = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableLog, getResources().getBoolean(R.bool.disable_log)); - if ((BuildConfig.DEBUG || getApplicationContext().getResources().getBoolean(R.bool.logger_enabled)) && !disableLog) { + boolean disableLogViaMDM = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableLog, getResources().getBoolean(R.bool.disable_log)); + if ((BuildConfig.DEBUG || getApplicationContext().getResources().getBoolean(R.bool.logger_enabled)) && !disableLogViaMDM) { // use app writable dir, no permissions needed Log_OC.setLoggerImplementation(new LegacyLoggerAdapter(logger)); Log_OC.d("Debug", "start logging"); diff --git a/app/src/main/java/com/owncloud/android/files/FileMenuFilter.java b/app/src/main/java/com/owncloud/android/files/FileMenuFilter.java index 277c69568c..55b3d38038 100644 --- a/app/src/main/java/com/owncloud/android/files/FileMenuFilter.java +++ b/app/src/main/java/com/owncloud/android/files/FileMenuFilter.java @@ -186,8 +186,8 @@ public class FileMenuFilter { } private void filterSendFiles(List toHide, boolean inSingleFileFragment) { - boolean disableSharing = ContextExtensionsKt.getRestriction(context, AppConfigKeys.DisableSharing, context.getResources().getBoolean(R.bool.disable_sharing)); - if (!disableSharing || (overflowMenu || SEND_OFF.equalsIgnoreCase(context.getString(R.string.send_files_to_other_apps)) || containsEncryptedFile()) || + boolean disableSharingViaMDM = ContextExtensionsKt.getRestriction(context, AppConfigKeys.DisableSharing, context.getResources().getBoolean(R.bool.disable_sharing)); + if (!disableSharingViaMDM || (overflowMenu || SEND_OFF.equalsIgnoreCase(context.getString(R.string.send_files_to_other_apps)) || containsEncryptedFile()) || (!inSingleFileFragment && (isSingleSelection() || !allFileDown())) || !toHide.contains(R.id.action_send_share_file)) { toHide.add(R.id.action_send_file); diff --git a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java index 8a09a8aa74..83e3db017f 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java @@ -604,11 +604,11 @@ public abstract class DrawerActivity extends ToolbarActivity } public void openAddAccount() { - boolean disableIntro = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableIntro, getResources().getBoolean(R.bool.disable_intro)); + boolean disableIntroViaMDM = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableIntro, getResources().getBoolean(R.bool.disable_intro)); boolean isProviderOrOwnInstallationVisible = getResources() .getBoolean(R.bool.show_provider_or_own_installation); - if (isProviderOrOwnInstallationVisible && !disableIntro) { + if (isProviderOrOwnInstallationVisible && !disableIntroViaMDM) { Intent firstRunIntent = new Intent(getApplicationContext(), FirstRunActivity.class); firstRunIntent.putExtra(FirstRunActivity.EXTRA_ALLOW_CLOSE, true); startActivity(firstRunIntent); @@ -827,8 +827,8 @@ public abstract class DrawerActivity extends ToolbarActivity private void updateQuotaLink() { if (mQuotaTextLink != null) { - boolean disableMoreExternalSite = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableMoreExternalSite, getResources().getBoolean(R.bool.disable_more_external_site)); - if (getBaseContext().getResources().getBoolean(R.bool.show_external_links) && !disableMoreExternalSite) { + boolean disableMoreExternalSiteViaMDM = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableMoreExternalSite, getResources().getBoolean(R.bool.disable_more_external_site)); + if (getBaseContext().getResources().getBoolean(R.bool.show_external_links) && !disableMoreExternalSiteViaMDM) { List quotas = externalLinksProvider.getExternalLink(ExternalLinkType.QUOTA); float density = getResources().getDisplayMetrics().density; @@ -977,8 +977,8 @@ public abstract class DrawerActivity extends ToolbarActivity } private void updateExternalLinksInDrawer() { - boolean disableMoreExternalSite = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableMoreExternalSite, getResources().getBoolean(R.bool.disable_more_external_site)); - if (mNavigationView != null && getBaseContext().getResources().getBoolean(R.bool.show_external_links) && !disableMoreExternalSite) { + boolean disableMoreExternalSiteViaMDM = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableMoreExternalSite, getResources().getBoolean(R.bool.disable_more_external_site)); + if (mNavigationView != null && getBaseContext().getResources().getBoolean(R.bool.show_external_links) && !disableMoreExternalSiteViaMDM) { mNavigationView.getMenu().removeGroup(R.id.drawer_menu_external_links); int greyColor = ContextCompat.getColor(this, R.color.drawer_menu_icon); @@ -1227,8 +1227,8 @@ public abstract class DrawerActivity extends ToolbarActivity * Retrieves external links via api from 'external' app */ public void fetchExternalLinks(final boolean force) { - boolean disableMoreExternalSite = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableMoreExternalSite, getResources().getBoolean(R.bool.disable_more_external_site)); - if (!getBaseContext().getResources().getBoolean(R.bool.show_external_links) || disableMoreExternalSite) { + boolean disableMoreExternalSiteViaMDM = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableMoreExternalSite, getResources().getBoolean(R.bool.disable_more_external_site)); + if (!getBaseContext().getResources().getBoolean(R.bool.show_external_links) || disableMoreExternalSiteViaMDM) { return; } diff --git a/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java index 9cbd09d501..bb48f97c16 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java @@ -381,11 +381,11 @@ public class SettingsActivity extends PreferenceActivity } private void setupLoggingPreference(PreferenceCategory preferenceCategoryMore) { - boolean disableLog = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableLog, getResources().getBoolean(R.bool.disable_log)); + boolean disableLogViaMDM = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableLog, getResources().getBoolean(R.bool.disable_log)); boolean loggerEnabled = getResources().getBoolean(R.bool.logger_enabled) || BuildConfig.DEBUG; Preference pLogger = findPreference("logger"); if (pLogger != null) { - if (loggerEnabled && !disableLog) { + if (loggerEnabled && !disableLogViaMDM) { pLogger.setOnPreferenceClickListener(preference -> { Intent loggerIntent = new Intent(getApplicationContext(), LogsActivity.class); startActivity(loggerIntent); @@ -1103,8 +1103,8 @@ public class SettingsActivity extends PreferenceActivity } private void loadExternalSettingLinks(PreferenceCategory preferenceCategory) { - boolean disableMoreExternalSite = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableMoreExternalSite, getResources().getBoolean(R.bool.disable_more_external_site)); - if (getBaseContext().getResources().getBoolean(R.bool.show_external_links) && !disableMoreExternalSite) { + boolean disableMoreExternalSiteViaMDM = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableMoreExternalSite, getResources().getBoolean(R.bool.disable_more_external_site)); + if (getBaseContext().getResources().getBoolean(R.bool.show_external_links) && !disableMoreExternalSiteViaMDM) { ExternalLinksProvider externalLinksProvider = new ExternalLinksProvider(getContentResolver()); for (final ExternalLink link : externalLinksProvider.getExternalLink(ExternalLinkType.SETTINGS)) { diff --git a/app/src/main/java/com/owncloud/android/ui/adapter/UserListAdapter.java b/app/src/main/java/com/owncloud/android/ui/adapter/UserListAdapter.java index b39f28dcfc..5603afb6eb 100644 --- a/app/src/main/java/com/owncloud/android/ui/adapter/UserListAdapter.java +++ b/app/src/main/java/com/owncloud/android/ui/adapter/UserListAdapter.java @@ -320,11 +320,11 @@ public class UserListAdapter extends RecyclerView.Adapter accountListAdapterListener.showFirstRunActivity()); } else { itemView.setOnClickListener(v -> accountListAdapterListener.startAccountCreation()); From f4b49b5da52c5b67845d989dadc7f3936b348c55 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 5 Nov 2024 12:02:11 +0100 Subject: [PATCH 24/52] use MDMConfig Signed-off-by: alperozturk --- .../ui/ChooseAccountDialogFragment.kt | 11 ++------ .../java/com/nextcloud/utils/mdm/MDMConfig.kt | 26 +++++++++++++++++++ .../authentication/AccountAuthenticator.java | 6 ++--- .../authentication/AuthenticatorActivity.java | 10 +++---- .../authentication/DeepLinkLoginActivity.kt | 9 ++----- .../ui/activity/ManageAccountsActivity.java | 9 +++---- .../ui/dialog/MultipleAccountsDialog.kt | 2 +- 7 files changed, 39 insertions(+), 34 deletions(-) create mode 100644 app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt diff --git a/app/src/main/java/com/nextcloud/ui/ChooseAccountDialogFragment.kt b/app/src/main/java/com/nextcloud/ui/ChooseAccountDialogFragment.kt index 5478ad6667..edf674d988 100644 --- a/app/src/main/java/com/nextcloud/ui/ChooseAccountDialogFragment.kt +++ b/app/src/main/java/com/nextcloud/ui/ChooseAccountDialogFragment.kt @@ -25,7 +25,7 @@ import com.nextcloud.client.account.UserAccountManager import com.nextcloud.client.di.Injectable import com.nextcloud.client.network.ClientFactory import com.nextcloud.utils.extensions.getParcelableArgument -import com.nextcloud.utils.extensions.getRestriction +import com.nextcloud.utils.mdm.MDMConfig import com.owncloud.android.R import com.owncloud.android.databinding.DialogChooseAccountBinding import com.owncloud.android.datamodel.FileDataStorageManager @@ -37,7 +37,6 @@ import com.owncloud.android.ui.adapter.UserListAdapter import com.owncloud.android.ui.adapter.UserListItem import com.owncloud.android.utils.DisplayUtils import com.owncloud.android.utils.DisplayUtils.AvatarGenerationListener -import com.owncloud.android.utils.appConfig.AppConfigKeys import com.owncloud.android.utils.theme.ViewThemeUtils import kotlinx.coroutines.launch import javax.inject.Inject @@ -122,13 +121,7 @@ class ChooseAccountDialogFragment : viewThemeUtils ) - val disableMultiAccountViaMDM = requireContext().getRestriction( - AppConfigKeys.DisableMultiAccount, - context?.resources?.getBoolean(R.bool.disable_multiaccount) ?: false - ) - - // hide "add account" when no multi account - if (!resources.getBoolean(R.bool.multiaccount_support) || disableMultiAccountViaMDM) { + if (!MDMConfig.multiAccountSupport(requireContext())) { binding.addAccount.visibility = View.GONE } diff --git a/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt b/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt new file mode 100644 index 0000000000..702dd1fb55 --- /dev/null +++ b/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt @@ -0,0 +1,26 @@ +/* + * Nextcloud - Android Client + * + * SPDX-FileCopyrightText: 2024 Alper Ozturk + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +package com.nextcloud.utils.mdm + +import android.content.Context +import com.nextcloud.utils.extensions.getRestriction +import com.owncloud.android.MainApp +import com.owncloud.android.R +import com.owncloud.android.utils.appConfig.AppConfigKeys + +object MDMConfig { + fun multiAccountSupport(context: Context): Boolean { + val multiAccountSupport = context.resources.getBoolean(R.bool.multiaccount_support) + val disableMultiAccountViaMDM = context.getRestriction( + AppConfigKeys.DisableMultiAccount, + MainApp.getAppContext().resources.getBoolean(R.bool.disable_multiaccount) + ) + + return multiAccountSupport && !disableMultiAccountViaMDM + } +} diff --git a/app/src/main/java/com/owncloud/android/authentication/AccountAuthenticator.java b/app/src/main/java/com/owncloud/android/authentication/AccountAuthenticator.java index d7e49ff62b..b791aa2f3e 100644 --- a/app/src/main/java/com/owncloud/android/authentication/AccountAuthenticator.java +++ b/app/src/main/java/com/owncloud/android/authentication/AccountAuthenticator.java @@ -21,12 +21,11 @@ import android.os.Bundle; import android.os.Handler; import android.widget.Toast; -import com.nextcloud.utils.extensions.ContextExtensionsKt; +import com.nextcloud.utils.mdm.MDMConfig; import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.lib.common.accounts.AccountTypeUtils; import com.owncloud.android.lib.common.utils.Log_OC; -import com.owncloud.android.utils.appConfig.AppConfigKeys; /** * Authenticator for ownCloud accounts. @@ -72,8 +71,7 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator { final Bundle bundle = new Bundle(); - boolean disableMultiAccountViaMDM = ContextExtensionsKt.getRestriction(mContext, AppConfigKeys.DisableMultiAccount, mContext.getResources().getBoolean(R.bool.disable_multiaccount)); - if (!disableMultiAccountViaMDM && mContext.getResources().getBoolean(R.bool.multiaccount_support) && accounts.length > 1) { + if (MDMConfig.INSTANCE.multiAccountSupport(mContext) && accounts.length > 1) { try { validateAccountType(accountType); } catch (AuthenticatorException e) { diff --git a/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java b/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java index f6f8b9cc69..05c63306f9 100644 --- a/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -21,7 +21,6 @@ import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; -import android.content.RestrictionsManager; import android.content.ServiceConnection; import android.content.SharedPreferences; import android.content.pm.PackageManager; @@ -72,6 +71,7 @@ import com.nextcloud.common.PlainClient; import com.nextcloud.operations.PostMethod; import com.nextcloud.utils.extensions.BundleExtensionsKt; import com.nextcloud.utils.extensions.ContextExtensionsKt; +import com.nextcloud.utils.mdm.MDMConfig; import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.databinding.AccountSetupBinding; @@ -811,10 +811,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity passCodeManager.onActivityResumed(this); Uri data = intent.getData(); - boolean disableMultiAccountViaMDM = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableMultiAccount, getResources().getBoolean(R.bool.disable_multiaccount)); if (data != null && data.toString().startsWith(getString(R.string.login_data_own_scheme))) { - if (disableMultiAccountViaMDM || - !getResources().getBoolean(R.bool.multiaccount_support) || + if (!MDMConfig.INSTANCE.multiAccountSupport(this) || accountManager.getAccounts().length == 1) { Toast.makeText(this, R.string.no_mutliple_accounts_allowed, Toast.LENGTH_LONG).show(); finish(); @@ -1535,9 +1533,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity return; } - boolean disableMultiAccountViaMDM = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableMultiAccount, getResources().getBoolean(R.bool.disable_multiaccount)); - if (disableMultiAccountViaMDM || - !getResources().getBoolean(R.bool.multiaccount_support) || + if (!MDMConfig.INSTANCE.multiAccountSupport(this) || accountManager.getAccounts().length == 1) { Toast.makeText(this, R.string.no_mutliple_accounts_allowed, Toast.LENGTH_LONG).show(); } else { diff --git a/app/src/main/java/com/owncloud/android/authentication/DeepLinkLoginActivity.kt b/app/src/main/java/com/owncloud/android/authentication/DeepLinkLoginActivity.kt index 6a6ca6691b..c355cdcbc9 100644 --- a/app/src/main/java/com/owncloud/android/authentication/DeepLinkLoginActivity.kt +++ b/app/src/main/java/com/owncloud/android/authentication/DeepLinkLoginActivity.kt @@ -11,19 +11,14 @@ import android.os.Bundle import android.widget.TextView import android.widget.Toast import com.nextcloud.client.di.Injectable -import com.nextcloud.utils.extensions.getRestriction +import com.nextcloud.utils.mdm.MDMConfig import com.owncloud.android.R -import com.owncloud.android.utils.appConfig.AppConfigKeys class DeepLinkLoginActivity : AuthenticatorActivity(), Injectable { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - val disableMultiAccountViaMDM = getRestriction(AppConfigKeys.DisableMultiAccount, resources.getBoolean(R.bool.disable_multiaccount)) - if (disableMultiAccountViaMDM || - !resources.getBoolean(R.bool.multiaccount_support) || - accountManager.accounts.size == 1 - ) { + if (!MDMConfig.multiAccountSupport(this) || accountManager.accounts.size == 1) { Toast.makeText(this, R.string.no_mutliple_accounts_allowed, Toast.LENGTH_LONG).show() return } diff --git a/app/src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java index 602e5bff33..579173fffd 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java @@ -30,7 +30,7 @@ import com.nextcloud.client.onboarding.FirstRunActivity; import com.nextcloud.model.WorkerState; import com.nextcloud.model.WorkerStateLiveData; import com.nextcloud.utils.extensions.BundleExtensionsKt; -import com.nextcloud.utils.extensions.ContextExtensionsKt; +import com.nextcloud.utils.mdm.MDMConfig; import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.authentication.AuthenticatorActivity; @@ -47,7 +47,6 @@ import com.owncloud.android.ui.adapter.UserListItem; import com.owncloud.android.ui.dialog.AccountRemovalDialog; import com.owncloud.android.ui.events.AccountRemovedEvent; import com.owncloud.android.ui.helpers.FileOperationsHelper; -import com.owncloud.android.utils.appConfig.AppConfigKeys; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; @@ -133,8 +132,7 @@ public class ManageAccountsActivity extends FileActivity implements UserListAdap } arbitraryDataProvider = new ArbitraryDataProviderImpl(this); - boolean disableMultiAccountViaMDM = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableMultiAccount, getResources().getBoolean(R.bool.disable_multiaccount)); - multipleAccountsSupported = getResources().getBoolean(R.bool.multiaccount_support) && !disableMultiAccountViaMDM; + multipleAccountsSupported = MDMConfig.INSTANCE.multiAccountSupport(this); userListAdapter = new UserListAdapter(this, accountManager, @@ -232,8 +230,7 @@ public class ManageAccountsActivity extends FileActivity implements UserListAdap userListItems.add(new UserListItem(user, !pendingForRemoval)); } - boolean disableMultiAccountViaMDM = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableMultiAccount, getResources().getBoolean(R.bool.disable_multiaccount)); - if (getResources().getBoolean(R.bool.multiaccount_support) && !disableMultiAccountViaMDM) { + if (MDMConfig.INSTANCE.multiAccountSupport(this)) { userListItems.add(new UserListItem()); } diff --git a/app/src/main/java/com/owncloud/android/ui/dialog/MultipleAccountsDialog.kt b/app/src/main/java/com/owncloud/android/ui/dialog/MultipleAccountsDialog.kt index 0bb2043c4b..5b95a263a3 100644 --- a/app/src/main/java/com/owncloud/android/ui/dialog/MultipleAccountsDialog.kt +++ b/app/src/main/java/com/owncloud/android/ui/dialog/MultipleAccountsDialog.kt @@ -65,7 +65,7 @@ class MultipleAccountsDialog : DialogFragment(), Injectable, UserListAdapter.Cli private val accountListItems: List /** * creates the account list items list including the add-account action in case - * multiaccount_support is enabled. + * multi account support is enabled. * * @return list of account list items */ From 0c42df23372839d62d47cd9f2637081b0a9fd3cd Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 5 Nov 2024 12:08:28 +0100 Subject: [PATCH 25/52] add share configs to the MDM Signed-off-by: alperozturk --- .../java/com/nextcloud/utils/mdm/MDMConfig.kt | 37 ++++++++++++++----- .../android/files/FileMenuFilter.java | 10 ++--- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt b/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt index 702dd1fb55..1474e0edc4 100644 --- a/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt +++ b/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt @@ -9,18 +9,37 @@ package com.nextcloud.utils.mdm import android.content.Context import com.nextcloud.utils.extensions.getRestriction -import com.owncloud.android.MainApp import com.owncloud.android.R import com.owncloud.android.utils.appConfig.AppConfigKeys object MDMConfig { - fun multiAccountSupport(context: Context): Boolean { - val multiAccountSupport = context.resources.getBoolean(R.bool.multiaccount_support) - val disableMultiAccountViaMDM = context.getRestriction( - AppConfigKeys.DisableMultiAccount, - MainApp.getAppContext().resources.getBoolean(R.bool.disable_multiaccount) - ) + fun multiAccountSupport(context: Context): Boolean { + val multiAccountSupport = context.resources.getBoolean(R.bool.multiaccount_support) + val disableMultiAccountViaMDM = context.getRestriction( + AppConfigKeys.DisableMultiAccount, + context.resources.getBoolean(R.bool.disable_multiaccount) + ) - return multiAccountSupport && !disableMultiAccountViaMDM - } + return multiAccountSupport && !disableMultiAccountViaMDM + } + + fun shareViaLink(context: Context): Boolean { + val disableShareViaMDM = context.getRestriction( + AppConfigKeys.DisableSharing, + context.resources.getBoolean(R.bool.disable_sharing) + ) + val shareViaLink = context.resources.getBoolean(R.bool.share_via_link_feature) + + return shareViaLink && disableShareViaMDM + } + + fun shareViaUser(context: Context): Boolean { + val disableShareViaMDM = context.getRestriction( + AppConfigKeys.DisableSharing, + context.resources.getBoolean(R.bool.disable_sharing) + ) + val shareViaUsers = context.resources.getBoolean(R.bool.share_with_users_feature) + + return shareViaUsers && disableShareViaMDM + } } diff --git a/app/src/main/java/com/owncloud/android/files/FileMenuFilter.java b/app/src/main/java/com/owncloud/android/files/FileMenuFilter.java index 55b3d38038..435daffec5 100644 --- a/app/src/main/java/com/owncloud/android/files/FileMenuFilter.java +++ b/app/src/main/java/com/owncloud/android/files/FileMenuFilter.java @@ -24,6 +24,7 @@ import com.nextcloud.client.jobs.download.FileDownloadHelper; import com.nextcloud.client.jobs.upload.FileUploadHelper; import com.nextcloud.utils.EditorUtils; import com.nextcloud.utils.extensions.ContextExtensionsKt; +import com.nextcloud.utils.mdm.MDMConfig; import com.owncloud.android.R; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; @@ -45,6 +46,7 @@ import javax.inject.Inject; import androidx.annotation.IdRes; import androidx.core.content.pm.ShortcutManagerCompat; +import androidx.media3.common.C; /** * Filters out the file actions available in a given {@link Menu} for a given {@link OCFile} @@ -428,15 +430,11 @@ public class FileMenuFilter { } private boolean isShareWithUsersAllowed() { - return context != null && - context.getResources().getBoolean(R.bool.share_with_users_feature) && - !ContextExtensionsKt.getRestriction(context, AppConfigKeys.DisableSharing, context.getResources().getBoolean(R.bool.disable_sharing)); + return context != null && MDMConfig.INSTANCE.shareViaUser(context); } private boolean isShareViaLinkAllowed() { - return context != null && - context.getResources().getBoolean(R.bool.share_via_link_feature) && - !ContextExtensionsKt.getRestriction(context, AppConfigKeys.DisableSharing, context.getResources().getBoolean(R.bool.disable_sharing)); + return context != null && MDMConfig.INSTANCE.shareViaLink(context); } private boolean isSingleSelection() { From 005bbcd20ff1937251a550ec5abcaf50b1824281 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 5 Nov 2024 12:10:26 +0100 Subject: [PATCH 26/52] add clipboard configs to the MDM Signed-off-by: alperozturk --- app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt | 9 +++++++++ .../java/com/owncloud/android/utils/ClipboardUtil.kt | 9 ++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt b/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt index 1474e0edc4..96e28a9da4 100644 --- a/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt +++ b/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt @@ -42,4 +42,13 @@ object MDMConfig { return shareViaUsers && disableShareViaMDM } + + fun clipBoardSupport(context: Context): Boolean { + val disableClipboardSupport = context.getRestriction( + AppConfigKeys.DisableClipboard, + context.resources.getBoolean(R.bool.disable_clipboard) + ) + + return !disableClipboardSupport + } } diff --git a/app/src/main/java/com/owncloud/android/utils/ClipboardUtil.kt b/app/src/main/java/com/owncloud/android/utils/ClipboardUtil.kt index 94766fd57c..d10e31329a 100644 --- a/app/src/main/java/com/owncloud/android/utils/ClipboardUtil.kt +++ b/app/src/main/java/com/owncloud/android/utils/ClipboardUtil.kt @@ -12,10 +12,9 @@ import android.content.ClipboardManager import android.content.Context import android.text.TextUtils import android.widget.Toast -import com.nextcloud.utils.extensions.getRestriction +import com.nextcloud.utils.mdm.MDMConfig import com.owncloud.android.R import com.owncloud.android.lib.common.utils.Log_OC -import com.owncloud.android.utils.appConfig.AppConfigKeys /** * Helper implementation to copy a string into the system clipboard. @@ -27,11 +26,7 @@ object ClipboardUtil { @JvmOverloads @Suppress("TooGenericExceptionCaught") fun copyToClipboard(activity: Activity, text: String?, showToast: Boolean = true) { - val disableClipboard = activity.getRestriction( - AppConfigKeys.DisableClipboard, - activity.resources.getBoolean(R.bool.disable_clipboard) - ) - if (disableClipboard) { + if (!MDMConfig.clipBoardSupport(activity)) { return } From e0ad34c4727249cb39f81ce8f498ef0bd1363195 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 5 Nov 2024 12:14:34 +0100 Subject: [PATCH 27/52] add externalSiteSupport configs to the MDM Signed-off-by: alperozturk --- .../main/java/com/nextcloud/utils/mdm/MDMConfig.kt | 14 ++++++++++++++ .../android/ui/activity/DrawerActivity.java | 10 ++++------ .../android/ui/activity/SettingsActivity.java | 4 ++-- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt b/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt index 96e28a9da4..872980d39a 100644 --- a/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt +++ b/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt @@ -15,6 +15,7 @@ import com.owncloud.android.utils.appConfig.AppConfigKeys object MDMConfig { fun multiAccountSupport(context: Context): Boolean { val multiAccountSupport = context.resources.getBoolean(R.bool.multiaccount_support) + val disableMultiAccountViaMDM = context.getRestriction( AppConfigKeys.DisableMultiAccount, context.resources.getBoolean(R.bool.disable_multiaccount) @@ -28,6 +29,7 @@ object MDMConfig { AppConfigKeys.DisableSharing, context.resources.getBoolean(R.bool.disable_sharing) ) + val shareViaLink = context.resources.getBoolean(R.bool.share_via_link_feature) return shareViaLink && disableShareViaMDM @@ -38,6 +40,7 @@ object MDMConfig { AppConfigKeys.DisableSharing, context.resources.getBoolean(R.bool.disable_sharing) ) + val shareViaUsers = context.resources.getBoolean(R.bool.share_with_users_feature) return shareViaUsers && disableShareViaMDM @@ -51,4 +54,15 @@ object MDMConfig { return !disableClipboardSupport } + + fun externalSiteSupport(context: Context): Boolean { + val disableMoreExternalSiteViaMDM = context.getRestriction( + AppConfigKeys.DisableMoreExternalSite, + context.resources.getBoolean(R.bool.disable_more_external_site) + ) + + val showExternalLinks = context.resources.getBoolean(R.bool.show_external_links) + + return showExternalLinks && !disableMoreExternalSiteViaMDM + } } diff --git a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java index 83e3db017f..410b39bee4 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java @@ -60,6 +60,7 @@ import com.nextcloud.ui.ChooseAccountDialogFragment; import com.nextcloud.ui.composeActivity.ComposeActivity; import com.nextcloud.ui.composeActivity.ComposeDestination; import com.nextcloud.utils.extensions.ContextExtensionsKt; +import com.nextcloud.utils.mdm.MDMConfig; import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.authentication.PassCodeManager; @@ -827,8 +828,7 @@ public abstract class DrawerActivity extends ToolbarActivity private void updateQuotaLink() { if (mQuotaTextLink != null) { - boolean disableMoreExternalSiteViaMDM = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableMoreExternalSite, getResources().getBoolean(R.bool.disable_more_external_site)); - if (getBaseContext().getResources().getBoolean(R.bool.show_external_links) && !disableMoreExternalSiteViaMDM) { + if (MDMConfig.INSTANCE.externalSiteSupport(this)) { List quotas = externalLinksProvider.getExternalLink(ExternalLinkType.QUOTA); float density = getResources().getDisplayMetrics().density; @@ -977,8 +977,7 @@ public abstract class DrawerActivity extends ToolbarActivity } private void updateExternalLinksInDrawer() { - boolean disableMoreExternalSiteViaMDM = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableMoreExternalSite, getResources().getBoolean(R.bool.disable_more_external_site)); - if (mNavigationView != null && getBaseContext().getResources().getBoolean(R.bool.show_external_links) && !disableMoreExternalSiteViaMDM) { + if (mNavigationView != null && MDMConfig.INSTANCE.externalSiteSupport(this)) { mNavigationView.getMenu().removeGroup(R.id.drawer_menu_external_links); int greyColor = ContextCompat.getColor(this, R.color.drawer_menu_icon); @@ -1227,8 +1226,7 @@ public abstract class DrawerActivity extends ToolbarActivity * Retrieves external links via api from 'external' app */ public void fetchExternalLinks(final boolean force) { - boolean disableMoreExternalSiteViaMDM = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableMoreExternalSite, getResources().getBoolean(R.bool.disable_more_external_site)); - if (!getBaseContext().getResources().getBoolean(R.bool.show_external_links) || disableMoreExternalSiteViaMDM) { + if (!MDMConfig.INSTANCE.externalSiteSupport(this)) { return; } diff --git a/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java index bb48f97c16..298f343b9c 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java @@ -51,6 +51,7 @@ import com.nextcloud.client.preferences.AppPreferences; import com.nextcloud.client.preferences.AppPreferencesImpl; import com.nextcloud.client.preferences.DarkMode; import com.nextcloud.utils.extensions.ContextExtensionsKt; +import com.nextcloud.utils.mdm.MDMConfig; import com.owncloud.android.BuildConfig; import com.owncloud.android.MainApp; import com.owncloud.android.R; @@ -1103,8 +1104,7 @@ public class SettingsActivity extends PreferenceActivity } private void loadExternalSettingLinks(PreferenceCategory preferenceCategory) { - boolean disableMoreExternalSiteViaMDM = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableMoreExternalSite, getResources().getBoolean(R.bool.disable_more_external_site)); - if (getBaseContext().getResources().getBoolean(R.bool.show_external_links) && !disableMoreExternalSiteViaMDM) { + if (MDMConfig.INSTANCE.externalSiteSupport(this)) { ExternalLinksProvider externalLinksProvider = new ExternalLinksProvider(getContentResolver()); for (final ExternalLink link : externalLinksProvider.getExternalLink(ExternalLinkType.SETTINGS)) { From 90902f51940c82ba003f648d5e75a77651f90612 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 5 Nov 2024 12:19:17 +0100 Subject: [PATCH 28/52] add showIntro configs to the MDM Signed-off-by: alperozturk --- .../nextcloud/client/onboarding/FirstRunActivity.kt | 12 ++++-------- .../client/onboarding/OnboardingServiceImpl.kt | 9 +++------ .../main/java/com/nextcloud/utils/mdm/MDMConfig.kt | 8 ++++++++ .../owncloud/android/ui/activity/DrawerActivity.java | 8 +------- .../owncloud/android/ui/adapter/UserListAdapter.java | 9 ++------- 5 files changed, 18 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/com/nextcloud/client/onboarding/FirstRunActivity.kt b/app/src/main/java/com/nextcloud/client/onboarding/FirstRunActivity.kt index e811b81664..5f9e872464 100644 --- a/app/src/main/java/com/nextcloud/client/onboarding/FirstRunActivity.kt +++ b/app/src/main/java/com/nextcloud/client/onboarding/FirstRunActivity.kt @@ -24,7 +24,7 @@ import com.nextcloud.client.account.UserAccountManager import com.nextcloud.client.appinfo.AppInfo import com.nextcloud.client.di.Injectable import com.nextcloud.client.preferences.AppPreferences -import com.nextcloud.utils.extensions.getRestriction +import com.nextcloud.utils.mdm.MDMConfig import com.owncloud.android.BuildConfig import com.owncloud.android.R import com.owncloud.android.authentication.AuthenticatorActivity @@ -34,7 +34,6 @@ import com.owncloud.android.ui.activity.BaseActivity import com.owncloud.android.ui.activity.FileDisplayActivity import com.owncloud.android.ui.adapter.FeaturesViewAdapter import com.owncloud.android.utils.DisplayUtils -import com.owncloud.android.utils.appConfig.AppConfigKeys import com.owncloud.android.utils.theme.ViewThemeUtils import javax.inject.Inject @@ -78,14 +77,12 @@ class FirstRunActivity : BaseActivity(), Injectable { binding = FirstRunActivityBinding.inflate(layoutInflater) setContentView(binding.root) - val disableIntroViaMDM = getRestriction(AppConfigKeys.DisableIntro, resources.getBoolean(R.bool.disable_intro)) - val isProviderOrOwnInstallationVisible = resources.getBoolean(R.bool.show_provider_or_own_installation) setSlideshowSize(resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) registerActivityResult() setupLoginButton() - setupSignupButton(isProviderOrOwnInstallationVisible && !disableIntroViaMDM) - setupHostOwnServerTextView(isProviderOrOwnInstallationVisible && !disableIntroViaMDM) + setupSignupButton(MDMConfig.showIntro(this)) + setupHostOwnServerTextView(MDMConfig.showIntro(this)) deleteAccountAtFirstLaunch() setupFeaturesViewAdapter() handleOnBackPressed() @@ -210,10 +207,9 @@ class FirstRunActivity : BaseActivity(), Injectable { } private fun setSlideshowSize(isLandscape: Boolean) { - val isProviderOrOwnInstallationVisible = resources.getBoolean(R.bool.show_provider_or_own_installation) binding.buttonLayout.orientation = if (isLandscape) LinearLayout.HORIZONTAL else LinearLayout.VERTICAL - val layoutParams: LinearLayout.LayoutParams = if (isProviderOrOwnInstallationVisible) { + val layoutParams: LinearLayout.LayoutParams = if (MDMConfig.showIntro(this)) { LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT diff --git a/app/src/main/java/com/nextcloud/client/onboarding/OnboardingServiceImpl.kt b/app/src/main/java/com/nextcloud/client/onboarding/OnboardingServiceImpl.kt index b928c7b172..e121d32d02 100644 --- a/app/src/main/java/com/nextcloud/client/onboarding/OnboardingServiceImpl.kt +++ b/app/src/main/java/com/nextcloud/client/onboarding/OnboardingServiceImpl.kt @@ -13,13 +13,12 @@ import android.content.Intent import android.content.res.Resources import com.nextcloud.client.account.CurrentAccountProvider import com.nextcloud.client.preferences.AppPreferences -import com.nextcloud.utils.extensions.getRestriction +import com.nextcloud.utils.mdm.MDMConfig import com.owncloud.android.BuildConfig import com.owncloud.android.R import com.owncloud.android.authentication.AuthenticatorActivity import com.owncloud.android.features.FeatureItem import com.owncloud.android.ui.activity.PassCodeActivity -import com.owncloud.android.utils.appConfig.AppConfigKeys internal class OnboardingServiceImpl( private val resources: Resources, @@ -63,10 +62,8 @@ internal class OnboardingServiceImpl( } override fun launchFirstRunIfNeeded(activity: Activity): Boolean { - val disableIntroViaMDM = activity.getRestriction(AppConfigKeys.DisableIntro, resources.getBoolean(R.bool.disable_intro)) - val isProviderOrOwnInstallationVisible = resources.getBoolean(R.bool.show_provider_or_own_installation) - val canLaunch = isProviderOrOwnInstallationVisible && isFirstRun && activity is AuthenticatorActivity - if (canLaunch && !disableIntroViaMDM) { + val canLaunch = MDMConfig.showIntro(activity) && isFirstRun && activity is AuthenticatorActivity + if (canLaunch) { val intent = Intent(activity, FirstRunActivity::class.java) activity.startActivityForResult(intent, AuthenticatorActivity.REQUEST_CODE_FIRST_RUN) } diff --git a/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt b/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt index 872980d39a..b315201b4a 100644 --- a/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt +++ b/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt @@ -65,4 +65,12 @@ object MDMConfig { return showExternalLinks && !disableMoreExternalSiteViaMDM } + + fun showIntro(context: Context): Boolean { + val disableIntroViaMDM = + context.getRestriction(AppConfigKeys.DisableIntro, context.resources.getBoolean(R.bool.disable_intro)) + val isProviderOrOwnInstallationVisible = context.resources.getBoolean(R.bool.show_provider_or_own_installation) + + return isProviderOrOwnInstallationVisible && !disableIntroViaMDM + } } diff --git a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java index 410b39bee4..98658dbf06 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java @@ -59,7 +59,6 @@ import com.nextcloud.common.NextcloudClient; import com.nextcloud.ui.ChooseAccountDialogFragment; import com.nextcloud.ui.composeActivity.ComposeActivity; import com.nextcloud.ui.composeActivity.ComposeDestination; -import com.nextcloud.utils.extensions.ContextExtensionsKt; import com.nextcloud.utils.mdm.MDMConfig; import com.owncloud.android.MainApp; import com.owncloud.android.R; @@ -97,7 +96,6 @@ import com.owncloud.android.utils.BitmapUtils; import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.DrawerMenuUtil; import com.owncloud.android.utils.FilesSyncHelper; -import com.owncloud.android.utils.appConfig.AppConfigKeys; import com.owncloud.android.utils.svg.MenuSimpleTarget; import com.owncloud.android.utils.svg.SVGorImage; import com.owncloud.android.utils.svg.SvgOrImageBitmapTranscoder; @@ -605,11 +603,7 @@ public abstract class DrawerActivity extends ToolbarActivity } public void openAddAccount() { - boolean disableIntroViaMDM = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableIntro, getResources().getBoolean(R.bool.disable_intro)); - boolean isProviderOrOwnInstallationVisible = getResources() - .getBoolean(R.bool.show_provider_or_own_installation); - - if (isProviderOrOwnInstallationVisible && !disableIntroViaMDM) { + if (MDMConfig.INSTANCE.showIntro(this)) { Intent firstRunIntent = new Intent(getApplicationContext(), FirstRunActivity.class); firstRunIntent.putExtra(FirstRunActivity.EXTRA_ALLOW_CLOSE, true); startActivity(firstRunIntent); diff --git a/app/src/main/java/com/owncloud/android/ui/adapter/UserListAdapter.java b/app/src/main/java/com/owncloud/android/ui/adapter/UserListAdapter.java index 5603afb6eb..8353353bd2 100644 --- a/app/src/main/java/com/owncloud/android/ui/adapter/UserListAdapter.java +++ b/app/src/main/java/com/owncloud/android/ui/adapter/UserListAdapter.java @@ -22,14 +22,13 @@ import android.widget.ImageView; import com.nextcloud.client.account.User; import com.nextcloud.client.account.UserAccountManager; -import com.nextcloud.utils.extensions.ContextExtensionsKt; +import com.nextcloud.utils.mdm.MDMConfig; import com.owncloud.android.R; import com.owncloud.android.databinding.AccountActionBinding; import com.owncloud.android.databinding.AccountItemBinding; import com.owncloud.android.lib.common.OwnCloudAccount; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.utils.DisplayUtils; -import com.owncloud.android.utils.appConfig.AppConfigKeys; import com.owncloud.android.utils.theme.ViewThemeUtils; import java.util.ArrayList; @@ -320,11 +319,7 @@ public class UserListAdapter extends RecyclerView.Adapter accountListAdapterListener.showFirstRunActivity()); } else { itemView.setOnClickListener(v -> accountListAdapterListener.startAccountCreation()); From e9054e1a056e8913c7baf940beabd77b79f645e6 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 5 Nov 2024 12:22:38 +0100 Subject: [PATCH 29/52] add enableLog configs to the MDM Signed-off-by: alperozturk --- .../main/java/com/nextcloud/utils/mdm/MDMConfig.kt | 11 +++++++++++ app/src/main/java/com/owncloud/android/MainApp.java | 4 ++-- .../android/ui/activity/SettingsActivity.java | 7 +------ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt b/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt index b315201b4a..945a89feb8 100644 --- a/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt +++ b/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt @@ -9,6 +9,7 @@ package com.nextcloud.utils.mdm import android.content.Context import com.nextcloud.utils.extensions.getRestriction +import com.owncloud.android.BuildConfig import com.owncloud.android.R import com.owncloud.android.utils.appConfig.AppConfigKeys @@ -69,8 +70,18 @@ object MDMConfig { fun showIntro(context: Context): Boolean { val disableIntroViaMDM = context.getRestriction(AppConfigKeys.DisableIntro, context.resources.getBoolean(R.bool.disable_intro)) + val isProviderOrOwnInstallationVisible = context.resources.getBoolean(R.bool.show_provider_or_own_installation) return isProviderOrOwnInstallationVisible && !disableIntroViaMDM } + + fun enableLog(context: Context): Boolean { + val disableLogViaMDM = + context.getRestriction(AppConfigKeys.DisableLog, context.resources.getBoolean(R.bool.disable_log)) + + val loggerEnabled = context.resources.getBoolean(R.bool.logger_enabled) + + return loggerEnabled && !disableLogViaMDM && BuildConfig.DEBUG + } } diff --git a/app/src/main/java/com/owncloud/android/MainApp.java b/app/src/main/java/com/owncloud/android/MainApp.java index 631e2fd4e8..cbb9063cf1 100644 --- a/app/src/main/java/com/owncloud/android/MainApp.java +++ b/app/src/main/java/com/owncloud/android/MainApp.java @@ -61,6 +61,7 @@ import com.nextcloud.client.preferences.DarkMode; import com.nextcloud.receiver.NetworkChangeListener; import com.nextcloud.receiver.NetworkChangeReceiver; import com.nextcloud.utils.extensions.ContextExtensionsKt; +import com.nextcloud.utils.mdm.MDMConfig; import com.nmc.android.ui.LauncherActivity; import com.owncloud.android.authentication.PassCodeManager; import com.owncloud.android.datamodel.ArbitraryDataProvider; @@ -339,8 +340,7 @@ public class MainApp extends Application implements HasAndroidInjector, NetworkC // initialise thumbnails cache on background thread new ThumbnailsCacheManager.InitDiskCacheTask().execute(); - boolean disableLogViaMDM = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableLog, getResources().getBoolean(R.bool.disable_log)); - if ((BuildConfig.DEBUG || getApplicationContext().getResources().getBoolean(R.bool.logger_enabled)) && !disableLogViaMDM) { + if (MDMConfig.INSTANCE.enableLog(this)) { // use app writable dir, no permissions needed Log_OC.setLoggerImplementation(new LegacyLoggerAdapter(logger)); Log_OC.d("Debug", "start logging"); diff --git a/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java index 298f343b9c..9db4033dae 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java @@ -50,9 +50,7 @@ import com.nextcloud.client.network.ConnectivityService; import com.nextcloud.client.preferences.AppPreferences; import com.nextcloud.client.preferences.AppPreferencesImpl; import com.nextcloud.client.preferences.DarkMode; -import com.nextcloud.utils.extensions.ContextExtensionsKt; import com.nextcloud.utils.mdm.MDMConfig; -import com.owncloud.android.BuildConfig; import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.authentication.AuthenticatorActivity; @@ -74,7 +72,6 @@ import com.owncloud.android.utils.DeviceCredentialUtils; import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.EncryptionUtils; import com.owncloud.android.utils.MimeTypeUtil; -import com.owncloud.android.utils.appConfig.AppConfigKeys; import com.owncloud.android.utils.theme.CapabilityUtils; import com.owncloud.android.utils.theme.ViewThemeUtils; @@ -382,11 +379,9 @@ public class SettingsActivity extends PreferenceActivity } private void setupLoggingPreference(PreferenceCategory preferenceCategoryMore) { - boolean disableLogViaMDM = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableLog, getResources().getBoolean(R.bool.disable_log)); - boolean loggerEnabled = getResources().getBoolean(R.bool.logger_enabled) || BuildConfig.DEBUG; Preference pLogger = findPreference("logger"); if (pLogger != null) { - if (loggerEnabled && !disableLogViaMDM) { + if (MDMConfig.INSTANCE.enableLog(this)) { pLogger.setOnPreferenceClickListener(preference -> { Intent loggerIntent = new Intent(getApplicationContext(), LogsActivity.class); startActivity(loggerIntent); From 60bcb92cd9cbbc31add6a52e437a1acf26082d8c Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 5 Nov 2024 12:28:00 +0100 Subject: [PATCH 30/52] add sendFilesSupport configs to the MDM Signed-off-by: alperozturk --- .../main/java/com/nextcloud/utils/mdm/MDMConfig.kt | 12 ++++++++++++ .../com/owncloud/android/files/FileMenuFilter.java | 3 +-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt b/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt index 945a89feb8..17de96aea3 100644 --- a/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt +++ b/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt @@ -11,6 +11,7 @@ import android.content.Context import com.nextcloud.utils.extensions.getRestriction import com.owncloud.android.BuildConfig import com.owncloud.android.R +import com.owncloud.android.files.FileMenuFilter import com.owncloud.android.utils.appConfig.AppConfigKeys object MDMConfig { @@ -47,6 +48,17 @@ object MDMConfig { return shareViaUsers && disableShareViaMDM } + fun sendFilesSupport(context: Context): Boolean { + val disableShareViaMDM = context.getRestriction( + AppConfigKeys.DisableSharing, + context.resources.getBoolean(R.bool.disable_sharing) + ) + + val sendFilesToOtherApp = "on".equals(context.getString(R.string.send_files_to_other_apps), ignoreCase = true) + + return sendFilesToOtherApp && !disableShareViaMDM + } + fun clipBoardSupport(context: Context): Boolean { val disableClipboardSupport = context.getRestriction( AppConfigKeys.DisableClipboard, diff --git a/app/src/main/java/com/owncloud/android/files/FileMenuFilter.java b/app/src/main/java/com/owncloud/android/files/FileMenuFilter.java index 435daffec5..a7e9a31f6e 100644 --- a/app/src/main/java/com/owncloud/android/files/FileMenuFilter.java +++ b/app/src/main/java/com/owncloud/android/files/FileMenuFilter.java @@ -188,8 +188,7 @@ public class FileMenuFilter { } private void filterSendFiles(List toHide, boolean inSingleFileFragment) { - boolean disableSharingViaMDM = ContextExtensionsKt.getRestriction(context, AppConfigKeys.DisableSharing, context.getResources().getBoolean(R.bool.disable_sharing)); - if (!disableSharingViaMDM || (overflowMenu || SEND_OFF.equalsIgnoreCase(context.getString(R.string.send_files_to_other_apps)) || containsEncryptedFile()) || + if (!MDMConfig.INSTANCE.sendFilesSupport(context) || (overflowMenu || containsEncryptedFile()) || (!inSingleFileFragment && (isSingleSelection() || !allFileDown())) || !toHide.contains(R.id.action_send_share_file)) { toHide.add(R.id.action_send_file); From 772f9c9b56ed705a203492e0bf40b8f702beb656 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 5 Nov 2024 12:30:44 +0100 Subject: [PATCH 31/52] optimize imports Signed-off-by: alperozturk --- app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt | 1 - .../main/java/com/owncloud/android/files/FileMenuFilter.java | 3 --- .../com/owncloud/android/ui/helpers/FileOperationsHelper.java | 2 -- 3 files changed, 6 deletions(-) diff --git a/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt b/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt index 17de96aea3..16a97820ef 100644 --- a/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt +++ b/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt @@ -11,7 +11,6 @@ import android.content.Context import com.nextcloud.utils.extensions.getRestriction import com.owncloud.android.BuildConfig import com.owncloud.android.R -import com.owncloud.android.files.FileMenuFilter import com.owncloud.android.utils.appConfig.AppConfigKeys object MDMConfig { diff --git a/app/src/main/java/com/owncloud/android/files/FileMenuFilter.java b/app/src/main/java/com/owncloud/android/files/FileMenuFilter.java index a7e9a31f6e..873a6e293a 100644 --- a/app/src/main/java/com/owncloud/android/files/FileMenuFilter.java +++ b/app/src/main/java/com/owncloud/android/files/FileMenuFilter.java @@ -23,7 +23,6 @@ import com.nextcloud.client.editimage.EditImageActivity; import com.nextcloud.client.jobs.download.FileDownloadHelper; import com.nextcloud.client.jobs.upload.FileUploadHelper; import com.nextcloud.utils.EditorUtils; -import com.nextcloud.utils.extensions.ContextExtensionsKt; import com.nextcloud.utils.mdm.MDMConfig; import com.owncloud.android.R; import com.owncloud.android.datamodel.FileDataStorageManager; @@ -34,7 +33,6 @@ import com.owncloud.android.ui.activity.ComponentsGetter; import com.owncloud.android.ui.helpers.FileOperationsHelper; import com.owncloud.android.utils.MimeTypeUtil; import com.owncloud.android.utils.NextcloudServer; -import com.owncloud.android.utils.appConfig.AppConfigKeys; import java.util.ArrayList; import java.util.Collection; @@ -46,7 +44,6 @@ import javax.inject.Inject; import androidx.annotation.IdRes; import androidx.core.content.pm.ShortcutManagerCompat; -import androidx.media3.common.C; /** * Filters out the file actions available in a given {@link Menu} for a given {@link OCFile} diff --git a/app/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java b/app/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java index 8841c74c78..6b765c2afd 100755 --- a/app/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java +++ b/app/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java @@ -36,7 +36,6 @@ import com.nextcloud.client.jobs.download.FileDownloadHelper; import com.nextcloud.client.jobs.upload.FileUploadHelper; import com.nextcloud.client.network.ConnectivityService; import com.nextcloud.utils.EditorUtils; -import com.nextcloud.utils.extensions.ContextExtensionsKt; import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.datamodel.ArbitraryDataProvider; @@ -70,7 +69,6 @@ import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.EncryptionUtils; import com.owncloud.android.utils.FileStorageUtils; import com.owncloud.android.utils.UriUtils; -import com.owncloud.android.utils.appConfig.AppConfigKeys; import com.owncloud.android.utils.theme.ViewThemeUtils; import org.greenrobot.eventbus.EventBus; From 35533e12642058a3d00ae3880fa57fde6098e894 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 5 Nov 2024 12:37:43 +0100 Subject: [PATCH 32/52] remove extensions Signed-off-by: alperozturk --- .../utils/extensions/ContextExtensions.kt | 18 --------------- .../java/com/nextcloud/utils/mdm/MDMConfig.kt | 23 ++++++++++++++++++- .../java/com/owncloud/android/MainApp.java | 5 ++-- .../authentication/AuthenticatorActivity.java | 4 +--- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt index d953e2d594..0cfc83439e 100644 --- a/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt +++ b/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt @@ -12,7 +12,6 @@ import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.content.IntentFilter -import android.content.RestrictionsManager import android.os.Build import android.os.Handler import android.os.Looper @@ -20,23 +19,6 @@ import android.widget.Toast import com.google.common.io.Resources import com.owncloud.android.R import com.owncloud.android.datamodel.ReceiverFlag -import com.owncloud.android.utils.appConfig.AppConfigKeys - -fun Context.getRestriction(appConfigKey: AppConfigKeys, defaultValue: T): T { - val restrictionsManager = getSystemService(Context.RESTRICTIONS_SERVICE) as? RestrictionsManager - return restrictionsManager?.getRestriction(appConfigKey.key, defaultValue) ?: defaultValue -} - -@Suppress("UNCHECKED_CAST") -private fun RestrictionsManager.getRestriction(key: String, defaultValue: T): T { - val appRestrictions = getApplicationRestrictions() - return when (defaultValue) { - is String -> appRestrictions.getString(key, defaultValue) as T? ?: defaultValue - is Int -> appRestrictions.getInt(key, defaultValue) as T? ?: defaultValue - is Boolean -> appRestrictions.getBoolean(key, defaultValue) as T? ?: defaultValue - else -> defaultValue - } -} fun Context.hourPlural(hour: Int): String = resources.getQuantityString(R.plurals.hours, hour, hour) diff --git a/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt b/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt index 16a97820ef..e688579381 100644 --- a/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt +++ b/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt @@ -8,7 +8,7 @@ package com.nextcloud.utils.mdm import android.content.Context -import com.nextcloud.utils.extensions.getRestriction +import android.content.RestrictionsManager import com.owncloud.android.BuildConfig import com.owncloud.android.R import com.owncloud.android.utils.appConfig.AppConfigKeys @@ -95,4 +95,25 @@ object MDMConfig { return loggerEnabled && !disableLogViaMDM && BuildConfig.DEBUG } + + fun getBaseUrl(context: Context): String = context.getRestriction(AppConfigKeys.BaseUrl, "") + + fun getHost(context: Context): String = + context.getRestriction(AppConfigKeys.ProxyHost, context.getString(R.string.proxy_host)) + + fun getPort(context: Context): Int = + context.getRestriction(AppConfigKeys.ProxyPort, context.resources.getInteger(R.integer.proxy_port)) + + @Suppress("UNCHECKED_CAST") + private fun Context.getRestriction(appConfigKey: AppConfigKeys, defaultValue: T): T { + val restrictionsManager = getSystemService(Context.RESTRICTIONS_SERVICE) as? RestrictionsManager + val appRestrictions = restrictionsManager?.getApplicationRestrictions() ?: return defaultValue + + return when (defaultValue) { + is String -> appRestrictions.getString(appConfigKey.key, defaultValue) as T? ?: defaultValue + is Int -> appRestrictions.getInt(appConfigKey.key, defaultValue) as T? ?: defaultValue + is Boolean -> appRestrictions.getBoolean(appConfigKey.key, defaultValue) as T? ?: defaultValue + else -> defaultValue + } + } } diff --git a/app/src/main/java/com/owncloud/android/MainApp.java b/app/src/main/java/com/owncloud/android/MainApp.java index cbb9063cf1..1a90b8cf32 100644 --- a/app/src/main/java/com/owncloud/android/MainApp.java +++ b/app/src/main/java/com/owncloud/android/MainApp.java @@ -87,7 +87,6 @@ import com.owncloud.android.utils.FilesSyncHelper; import com.owncloud.android.utils.PermissionUtil; import com.owncloud.android.utils.ReceiversHelper; import com.owncloud.android.utils.SecurityUtils; -import com.owncloud.android.utils.appConfig.AppConfigKeys; import com.owncloud.android.utils.theme.ViewThemeUtils; import org.conscrypt.Conscrypt; @@ -422,8 +421,8 @@ public class MainApp extends Application implements HasAndroidInjector, NetworkC return; } - String host = ContextExtensionsKt.getRestriction(this, AppConfigKeys.ProxyHost, getString(R.string.proxy_host)); - int port = ContextExtensionsKt.getRestriction(this, AppConfigKeys.ProxyPort, getResources().getInteger(R.integer.proxy_port)); + String host = MDMConfig.INSTANCE.getHost(this); + int port = MDMConfig.INSTANCE.getPort(this); if (TextUtils.isEmpty(host) || port == -1) { Log_OC.d(TAG, "Proxy configuration cannot be found"); diff --git a/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java b/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java index 05c63306f9..0930e8d12e 100644 --- a/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -70,7 +70,6 @@ import com.nextcloud.client.preferences.AppPreferences; import com.nextcloud.common.PlainClient; import com.nextcloud.operations.PostMethod; import com.nextcloud.utils.extensions.BundleExtensionsKt; -import com.nextcloud.utils.extensions.ContextExtensionsKt; import com.nextcloud.utils.mdm.MDMConfig; import com.owncloud.android.MainApp; import com.owncloud.android.R; @@ -113,7 +112,6 @@ import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.ErrorMessageAdapter; import com.owncloud.android.utils.PermissionUtil; import com.owncloud.android.utils.WebViewUtil; -import com.owncloud.android.utils.appConfig.AppConfigKeys; import com.owncloud.android.utils.theme.CapabilityUtils; import com.owncloud.android.utils.theme.ViewThemeUtils; @@ -321,7 +319,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity String webloginUrl = null; if (MainApp.isClientBrandedPlus()) { - String baseUrl = ContextExtensionsKt.getRestriction(this, AppConfigKeys.BaseUrl, ""); + String baseUrl = MDMConfig.INSTANCE.getBaseUrl(this); if (!TextUtils.isEmpty(baseUrl)) { webloginUrl = baseUrl + WEB_LOGIN; } From 7014ad133af54c425bcc52626026563c3ca2b26a Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 5 Nov 2024 12:40:32 +0100 Subject: [PATCH 33/52] fix wrong condition Signed-off-by: alperozturk --- app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt b/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt index e688579381..76cedcd70c 100644 --- a/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt +++ b/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt @@ -33,7 +33,7 @@ object MDMConfig { val shareViaLink = context.resources.getBoolean(R.bool.share_via_link_feature) - return shareViaLink && disableShareViaMDM + return shareViaLink && !disableShareViaMDM } fun shareViaUser(context: Context): Boolean { @@ -44,7 +44,7 @@ object MDMConfig { val shareViaUsers = context.resources.getBoolean(R.bool.share_with_users_feature) - return shareViaUsers && disableShareViaMDM + return shareViaUsers && !disableShareViaMDM } fun sendFilesSupport(context: Context): Boolean { From 50e76e7d9e505d25e413c99bc150054be2710f0d Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 5 Nov 2024 12:41:03 +0100 Subject: [PATCH 34/52] format code Signed-off-by: alperozturk --- .../java/com/owncloud/android/utils/appConfig/AppConfigKeys.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/owncloud/android/utils/appConfig/AppConfigKeys.kt b/app/src/main/java/com/owncloud/android/utils/appConfig/AppConfigKeys.kt index ea4db8fc02..30a86e413a 100644 --- a/app/src/main/java/com/owncloud/android/utils/appConfig/AppConfigKeys.kt +++ b/app/src/main/java/com/owncloud/android/utils/appConfig/AppConfigKeys.kt @@ -19,5 +19,5 @@ enum class AppConfigKeys(val key: String) { DisableClipboard("disable_clipboard"), DisableMoreExternalSite("disable_more_external_site"), DisableIntro("disable_intro"), - DisableLog("disable_log"), + DisableLog("disable_log") } From 4a8ceb59aaad8afa1d4e6b3d9044aa14cae8b0bd Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 5 Nov 2024 13:56:32 +0100 Subject: [PATCH 35/52] handle nullable contexts Signed-off-by: alperozturk --- .../java/com/owncloud/android/files/FileMenuFilter.java | 3 ++- .../com/owncloud/android/ui/adapter/UserListAdapter.java | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/files/FileMenuFilter.java b/app/src/main/java/com/owncloud/android/files/FileMenuFilter.java index 873a6e293a..f3b9002811 100644 --- a/app/src/main/java/com/owncloud/android/files/FileMenuFilter.java +++ b/app/src/main/java/com/owncloud/android/files/FileMenuFilter.java @@ -185,7 +185,8 @@ public class FileMenuFilter { } private void filterSendFiles(List toHide, boolean inSingleFileFragment) { - if (!MDMConfig.INSTANCE.sendFilesSupport(context) || (overflowMenu || containsEncryptedFile()) || + if ((context != null && !MDMConfig.INSTANCE.sendFilesSupport(context)) || + (overflowMenu || containsEncryptedFile()) || (!inSingleFileFragment && (isSingleSelection() || !allFileDown())) || !toHide.contains(R.id.action_send_share_file)) { toHide.add(R.id.action_send_file); diff --git a/app/src/main/java/com/owncloud/android/ui/adapter/UserListAdapter.java b/app/src/main/java/com/owncloud/android/ui/adapter/UserListAdapter.java index 8353353bd2..1f2c7144a8 100644 --- a/app/src/main/java/com/owncloud/android/ui/adapter/UserListAdapter.java +++ b/app/src/main/java/com/owncloud/android/ui/adapter/UserListAdapter.java @@ -308,7 +308,7 @@ public class UserListAdapter extends RecyclerView.Adapter accountListAdapterListener.showFirstRunActivity()); } else { From d8db5739bdadb03c9439863d15cb1bf935eff922 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 5 Nov 2024 14:32:24 +0100 Subject: [PATCH 36/52] check clipBoardSupport Signed-off-by: alperozturk --- .../android/ui/activity/FileActivity.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/ui/activity/FileActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/FileActivity.java index 95b726f2f6..769e943506 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/FileActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/FileActivity.java @@ -45,6 +45,7 @@ import com.nextcloud.utils.extensions.ActivityExtensionsKt; import com.nextcloud.utils.extensions.BundleExtensionsKt; import com.nextcloud.utils.extensions.FileExtensionsKt; import com.nextcloud.utils.extensions.IntentExtensionsKt; +import com.nextcloud.utils.mdm.MDMConfig; import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.authentication.AuthenticatorActivity; @@ -718,15 +719,21 @@ public abstract class FileActivity extends DrawerActivity OCFile file, String link, final ViewThemeUtils viewThemeUtils) { - ClipboardUtil.copyToClipboard(activity, link, false); - Snackbar snackbar = Snackbar.make(activity.findViewById(android.R.id.content), R.string.clipboard_text_copied, - Snackbar.LENGTH_LONG) - .setAction(R.string.share, v -> showShareLinkDialog(activity, file, link)); - viewThemeUtils.material.themeSnackbar(snackbar); - snackbar.show(); + if (MDMConfig.INSTANCE.shareViaLink(activity) && MDMConfig.INSTANCE.clipBoardSupport(activity)) { + ClipboardUtil.copyToClipboard(activity, link, false); + Snackbar snackbar = Snackbar.make(activity.findViewById(android.R.id.content), R.string.clipboard_text_copied, + Snackbar.LENGTH_LONG) + .setAction(R.string.share, v -> showShareLinkDialog(activity, file, link)); + viewThemeUtils.material.themeSnackbar(snackbar); + snackbar.show(); + } } public static void showShareLinkDialog(FileActivity activity, ServerFileInterface file, String link) { + if (!MDMConfig.INSTANCE.shareViaLink(activity)) { + return; + } + // Create dialog to allow the user choose an app to send the link Intent intentToShareLink = new Intent(Intent.ACTION_SEND); From d45ed86f3f81cce3b2e32909699cf7a61fbec67e Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 5 Nov 2024 14:38:38 +0100 Subject: [PATCH 37/52] disable log default value is true Signed-off-by: alperozturk --- app/src/main/res/xml/app_config.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/xml/app_config.xml b/app/src/main/res/xml/app_config.xml index d6c4038a2b..a8475a9d28 100644 --- a/app/src/main/res/xml/app_config.xml +++ b/app/src/main/res/xml/app_config.xml @@ -57,7 +57,7 @@ From 7abddb240dae7a3d76455b7a12e2e979cac3336e Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 5 Nov 2024 14:54:36 +0100 Subject: [PATCH 38/52] fix spotbugs Signed-off-by: alperozturk --- .../authentication/AccountAuthenticator.java | 2 +- .../android/files/FileMenuFilter.java | 22 +++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/authentication/AccountAuthenticator.java b/app/src/main/java/com/owncloud/android/authentication/AccountAuthenticator.java index b791aa2f3e..97119bf5e7 100644 --- a/app/src/main/java/com/owncloud/android/authentication/AccountAuthenticator.java +++ b/app/src/main/java/com/owncloud/android/authentication/AccountAuthenticator.java @@ -71,7 +71,7 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator { final Bundle bundle = new Bundle(); - if (MDMConfig.INSTANCE.multiAccountSupport(mContext) && accounts.length > 1) { + if (accounts.length > 1 && MDMConfig.INSTANCE.multiAccountSupport(mContext)) { try { validateAccountType(accountType); } catch (AuthenticatorException e) { diff --git a/app/src/main/java/com/owncloud/android/files/FileMenuFilter.java b/app/src/main/java/com/owncloud/android/files/FileMenuFilter.java index f3b9002811..2bb9e99e4c 100644 --- a/app/src/main/java/com/owncloud/android/files/FileMenuFilter.java +++ b/app/src/main/java/com/owncloud/android/files/FileMenuFilter.java @@ -185,10 +185,24 @@ public class FileMenuFilter { } private void filterSendFiles(List toHide, boolean inSingleFileFragment) { - if ((context != null && !MDMConfig.INSTANCE.sendFilesSupport(context)) || - (overflowMenu || containsEncryptedFile()) || - (!inSingleFileFragment && (isSingleSelection() || !allFileDown())) || - !toHide.contains(R.id.action_send_share_file)) { + boolean sendFilesNotSupported = context != null && !MDMConfig.INSTANCE.sendFilesSupport(context); + boolean hasEncryptedFile = containsEncryptedFile(); + boolean isSingleSelection = isSingleSelection(); + boolean allFilesNotDown = !allFileDown(); + + if (sendFilesNotSupported) { + toHide.add(R.id.action_send_file); + return; + } + + if (overflowMenu || hasEncryptedFile) { + toHide.add(R.id.action_send_file); + return; + } + + if (!inSingleFileFragment && (isSingleSelection || allFilesNotDown)) { + toHide.add(R.id.action_send_file); + } else if (!toHide.contains(R.id.action_send_share_file)) { toHide.add(R.id.action_send_file); } } From 8746e903cf52583af63cf806d50590905408de36 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 5 Nov 2024 15:05:36 +0100 Subject: [PATCH 39/52] better function name Signed-off-by: alperozturk --- app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt | 2 +- app/src/main/java/com/owncloud/android/MainApp.java | 2 +- .../java/com/owncloud/android/ui/activity/SettingsActivity.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt b/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt index 76cedcd70c..c65a24760e 100644 --- a/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt +++ b/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt @@ -87,7 +87,7 @@ object MDMConfig { return isProviderOrOwnInstallationVisible && !disableIntroViaMDM } - fun enableLog(context: Context): Boolean { + fun isLogEnabled(context: Context): Boolean { val disableLogViaMDM = context.getRestriction(AppConfigKeys.DisableLog, context.resources.getBoolean(R.bool.disable_log)) diff --git a/app/src/main/java/com/owncloud/android/MainApp.java b/app/src/main/java/com/owncloud/android/MainApp.java index 1a90b8cf32..a5595f1154 100644 --- a/app/src/main/java/com/owncloud/android/MainApp.java +++ b/app/src/main/java/com/owncloud/android/MainApp.java @@ -339,7 +339,7 @@ public class MainApp extends Application implements HasAndroidInjector, NetworkC // initialise thumbnails cache on background thread new ThumbnailsCacheManager.InitDiskCacheTask().execute(); - if (MDMConfig.INSTANCE.enableLog(this)) { + if (MDMConfig.INSTANCE.isLogEnabled(this)) { // use app writable dir, no permissions needed Log_OC.setLoggerImplementation(new LegacyLoggerAdapter(logger)); Log_OC.d("Debug", "start logging"); diff --git a/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java index 9db4033dae..1df63428dd 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java @@ -381,7 +381,7 @@ public class SettingsActivity extends PreferenceActivity private void setupLoggingPreference(PreferenceCategory preferenceCategoryMore) { Preference pLogger = findPreference("logger"); if (pLogger != null) { - if (MDMConfig.INSTANCE.enableLog(this)) { + if (MDMConfig.INSTANCE.isLogEnabled(this)) { pLogger.setOnPreferenceClickListener(preference -> { Intent loggerIntent = new Intent(getApplicationContext(), LogsActivity.class); startActivity(loggerIntent); From d5b18914396648ed2023553feeb4cdef3cf8fad0 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 5 Nov 2024 15:18:08 +0100 Subject: [PATCH 40/52] fix conditions for multi account Signed-off-by: alperozturk --- .../android/authentication/AuthenticatorActivity.java | 4 ++-- .../owncloud/android/authentication/DeepLinkLoginActivity.kt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java b/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java index 0930e8d12e..10f63668bc 100644 --- a/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -810,7 +810,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity Uri data = intent.getData(); if (data != null && data.toString().startsWith(getString(R.string.login_data_own_scheme))) { - if (!MDMConfig.INSTANCE.multiAccountSupport(this) || + if (!MDMConfig.INSTANCE.multiAccountSupport(this) && accountManager.getAccounts().length == 1) { Toast.makeText(this, R.string.no_mutliple_accounts_allowed, Toast.LENGTH_LONG).show(); finish(); @@ -1531,7 +1531,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity return; } - if (!MDMConfig.INSTANCE.multiAccountSupport(this) || + if (!MDMConfig.INSTANCE.multiAccountSupport(this) && accountManager.getAccounts().length == 1) { Toast.makeText(this, R.string.no_mutliple_accounts_allowed, Toast.LENGTH_LONG).show(); } else { diff --git a/app/src/main/java/com/owncloud/android/authentication/DeepLinkLoginActivity.kt b/app/src/main/java/com/owncloud/android/authentication/DeepLinkLoginActivity.kt index c355cdcbc9..971fde8fc0 100644 --- a/app/src/main/java/com/owncloud/android/authentication/DeepLinkLoginActivity.kt +++ b/app/src/main/java/com/owncloud/android/authentication/DeepLinkLoginActivity.kt @@ -18,7 +18,7 @@ class DeepLinkLoginActivity : AuthenticatorActivity(), Injectable { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - if (!MDMConfig.multiAccountSupport(this) || accountManager.accounts.size == 1) { + if (!MDMConfig.multiAccountSupport(this) && accountManager.accounts.size == 1) { Toast.makeText(this, R.string.no_mutliple_accounts_allowed, Toast.LENGTH_LONG).show() return } From 4039ffe0c904d3a3d055d29fbc1927fd80758285 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 5 Nov 2024 15:54:12 +0100 Subject: [PATCH 41/52] check contact app Signed-off-by: alperozturk --- .../android/ui/fragment/FileDetailSharingFragment.java | 10 +++++++--- app/src/main/res/values/strings.xml | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java b/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java index 0cdeb930c7..620443556b 100644 --- a/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java +++ b/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java @@ -494,9 +494,13 @@ public class FileDetailSharingFragment extends Fragment implements ShareeListAda } private void pickContactEmail() { - Intent intent = new Intent(Intent.ACTION_PICK); - intent.setDataAndType(ContactsContract.Contacts.CONTENT_URI, ContactsContract.CommonDataKinds.Email.CONTENT_TYPE); - onContactSelectionResultLauncher.launch(intent); + Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds.Email.CONTENT_URI); + + if (intent.resolveActivity(requireContext().getPackageManager()) != null) { + onContactSelectionResultLauncher.launch(intent); + } else { + DisplayUtils.showSnackMessage(requireActivity(), getString(R.string.file_detail_sharing_fragment_no_contact_app_message)); + } } private void handleContactResult(@NonNull Uri contactUri) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 228a01825b..2e15ac5baa 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -814,7 +814,7 @@ Add name, picture and contact details on your profile page. Background image of drawer header Account icon - + No app available to select contacts This folder is not empty. Error while decrypting. Wrong password? Decrypting… From 3ae45b4beb1fe6ea05d8edb15a1125cf01925c10 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 5 Nov 2024 15:55:28 +0100 Subject: [PATCH 42/52] check shareViaLink, shareViaUser in file detail fragment Signed-off-by: alperozturk --- .../com/owncloud/android/ui/fragment/FileDetailFragment.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java b/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java index 2dc7fe4b10..4a6201670d 100644 --- a/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java +++ b/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java @@ -36,6 +36,7 @@ import com.nextcloud.ui.fileactions.FileActionsBottomSheet; import com.nextcloud.utils.MenuUtils; import com.nextcloud.utils.extensions.BundleExtensionsKt; import com.nextcloud.utils.extensions.FileExtensionsKt; +import com.nextcloud.utils.mdm.MDMConfig; import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.databinding.FileDetailsFragmentBinding; @@ -841,6 +842,10 @@ public class FileDetailFragment extends FileFragment implements OnClickListener, } private boolean showSharingTab() { + if (!MDMConfig.INSTANCE.shareViaLink(requireContext()) || MDMConfig.INSTANCE.shareViaUser(requireContext())) { + return false; + } + if (getFile().isEncrypted()) { if (parentFolder == null) { parentFolder = storageManager.getFileById(getFile().getParentId()); From 7a7c12b3df42fdd1f3aa58a33538c457bf42422d Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 5 Nov 2024 16:18:36 +0100 Subject: [PATCH 43/52] check shared icon visibility in adapter Signed-off-by: alperozturk --- .../com/owncloud/android/ui/adapter/OCFileListAdapter.java | 7 +++++++ .../com/owncloud/android/ui/adapter/OCFileListDelegate.kt | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java b/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java index 6c290c5548..4fd2ae6ae0 100644 --- a/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java +++ b/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java @@ -39,6 +39,7 @@ import com.nextcloud.client.preferences.AppPreferences; import com.nextcloud.model.OfflineOperationType; import com.nextcloud.model.OCFileFilterType; import com.nextcloud.utils.extensions.ViewExtensionsKt; +import com.nextcloud.utils.mdm.MDMConfig; import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.databinding.GridImageBinding; @@ -458,6 +459,12 @@ public class OCFileListAdapter extends RecyclerView.Adapter Date: Tue, 5 Nov 2024 16:41:14 +0100 Subject: [PATCH 44/52] hide link button if clipboard disabled Signed-off-by: alperozturk --- .../com/owncloud/android/ui/dialog/SendShareDialog.kt | 8 +++++++- .../owncloud/android/ui/fragment/FileDetailFragment.java | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.kt b/app/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.kt index 9be56aff7e..fd30641164 100644 --- a/app/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.kt +++ b/app/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.kt @@ -27,6 +27,7 @@ import com.nextcloud.android.common.ui.theme.utils.ColorRole import com.nextcloud.client.di.Injectable import com.nextcloud.client.utils.IntentUtil.createSendIntent import com.nextcloud.utils.extensions.getParcelableArgument +import com.nextcloud.utils.mdm.MDMConfig import com.owncloud.android.BuildConfig import com.owncloud.android.R import com.owncloud.android.databinding.SendShareFragmentBinding @@ -73,7 +74,12 @@ class SendShareDialog : BottomSheetDialogFragment(R.layout.send_share_fragment), binding = SendShareFragmentBinding.inflate(inflater, container, false) binding.btnShare.setOnClickListener { shareFile(file) } - binding.btnLink.setOnClickListener { shareByLink() } + + if (MDMConfig.shareViaLink(requireContext()) && MDMConfig.clipBoardSupport(requireContext())) { + binding.btnLink.setOnClickListener { shareByLink() } + } else { + binding.btnLink.visibility = View.GONE + } applyTintColor() setupBottomSheetBehaviour() diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java b/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java index 4a6201670d..b1805ace78 100644 --- a/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java +++ b/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java @@ -842,7 +842,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener, } private boolean showSharingTab() { - if (!MDMConfig.INSTANCE.shareViaLink(requireContext()) || MDMConfig.INSTANCE.shareViaUser(requireContext())) { + if (!MDMConfig.INSTANCE.shareViaLink(requireContext()) || !MDMConfig.INSTANCE.shareViaUser(requireContext())) { return false; } From 9f7f1f288c6772b934723ca91043dc314c70b636 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Wed, 6 Nov 2024 09:15:27 +0100 Subject: [PATCH 45/52] revert if condition for AccountAuthenticator Signed-off-by: alperozturk --- .../owncloud/android/authentication/AccountAuthenticator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/owncloud/android/authentication/AccountAuthenticator.java b/app/src/main/java/com/owncloud/android/authentication/AccountAuthenticator.java index 97119bf5e7..6f3adf6a3a 100644 --- a/app/src/main/java/com/owncloud/android/authentication/AccountAuthenticator.java +++ b/app/src/main/java/com/owncloud/android/authentication/AccountAuthenticator.java @@ -71,7 +71,7 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator { final Bundle bundle = new Bundle(); - if (accounts.length > 1 && MDMConfig.INSTANCE.multiAccountSupport(mContext)) { + if (accounts.length < 1 || MDMConfig.INSTANCE.multiAccountSupport(mContext)) { try { validateAccountType(accountType); } catch (AuthenticatorException e) { From 3f9e563dea8c4b43ad57b0a2063cb94e8298720e Mon Sep 17 00:00:00 2001 From: alperozturk Date: Wed, 6 Nov 2024 09:19:55 +0100 Subject: [PATCH 46/52] combine share logic Signed-off-by: alperozturk --- .../java/com/nextcloud/utils/mdm/MDMConfig.kt | 15 +++++++++++++++ .../android/ui/adapter/OCFileListAdapter.java | 6 ++---- .../android/ui/adapter/OCFileListDelegate.kt | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt b/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt index c65a24760e..126dcf3404 100644 --- a/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt +++ b/app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt @@ -58,6 +58,21 @@ object MDMConfig { return sendFilesToOtherApp && !disableShareViaMDM } + fun sharingSupport(context: Context): Boolean { + val disableShareViaMDM = context.getRestriction( + AppConfigKeys.DisableSharing, + context.resources.getBoolean(R.bool.disable_sharing) + ) + + val sendFilesToOtherApp = "on".equals(context.getString(R.string.send_files_to_other_apps), ignoreCase = true) + + val shareViaUsers = context.resources.getBoolean(R.bool.share_with_users_feature) + + val shareViaLink = context.resources.getBoolean(R.bool.share_via_link_feature) + + return sendFilesToOtherApp && shareViaLink && shareViaUsers && !disableShareViaMDM + } + fun clipBoardSupport(context: Context): Boolean { val disableClipboardSupport = context.getRestriction( AppConfigKeys.DisableClipboard, diff --git a/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java b/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java index 4fd2ae6ae0..4c32b2bc8e 100644 --- a/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java +++ b/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java @@ -36,8 +36,8 @@ import com.nextcloud.client.account.User; import com.nextcloud.client.database.entity.OfflineOperationEntity; import com.nextcloud.client.jobs.upload.FileUploadHelper; import com.nextcloud.client.preferences.AppPreferences; -import com.nextcloud.model.OfflineOperationType; import com.nextcloud.model.OCFileFilterType; +import com.nextcloud.model.OfflineOperationType; import com.nextcloud.utils.extensions.ViewExtensionsKt; import com.nextcloud.utils.mdm.MDMConfig; import com.owncloud.android.MainApp; @@ -460,9 +460,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter Date: Tue, 12 Nov 2024 10:24:10 +0100 Subject: [PATCH 47/52] fix sharing tab visibility Signed-off-by: alperozturk --- .../android/ui/fragment/FileDetailFragment.java | 2 +- .../ui/fragment/FileDetailSharingFragment.java | 17 +++++++++++++++++ app/src/main/res/values/setup.xml | 1 - 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java b/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java index b1805ace78..b36cf8f2cd 100644 --- a/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java +++ b/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java @@ -842,7 +842,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener, } private boolean showSharingTab() { - if (!MDMConfig.INSTANCE.shareViaLink(requireContext()) || !MDMConfig.INSTANCE.shareViaUser(requireContext())) { + if (!MDMConfig.INSTANCE.shareViaLink(requireContext()) && !MDMConfig.INSTANCE.shareViaUser(requireContext())) { return false; } diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java b/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java index 620443556b..5389bfc7d4 100644 --- a/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java +++ b/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java @@ -37,6 +37,7 @@ import com.nextcloud.client.di.Injectable; import com.nextcloud.client.network.ClientFactory; import com.nextcloud.utils.extensions.BundleExtensionsKt; import com.nextcloud.utils.extensions.FileExtensionsKt; +import com.nextcloud.utils.mdm.MDMConfig; import com.owncloud.android.R; import com.owncloud.android.databinding.FileDetailsSharingFragmentBinding; import com.owncloud.android.datamodel.FileDataStorageManager; @@ -244,6 +245,22 @@ public class FileDetailSharingFragment extends Fragment implements ShareeListAda binding.pickContactEmailBtn.setVisibility(View.GONE); disableSearchView(binding.searchView); } + + checkShareLink(); + checkShareViaUser(); + } + + private void checkShareViaUser() { + if (!MDMConfig.INSTANCE.shareViaUser(requireContext())) { + binding.searchContainer.setVisibility(View.GONE); + } + } + + private void checkShareLink() { + if (!MDMConfig.INSTANCE.shareViaLink(requireContext())) { + binding.sharedWithYouContainer.setVisibility(View.GONE); + binding.sharesList.setVisibility(View.GONE); + } } private void disableSearchView(View view) { diff --git a/app/src/main/res/values/setup.xml b/app/src/main/res/values/setup.xml index ac64932de5..aa6be51253 100644 --- a/app/src/main/res/values/setup.xml +++ b/app/src/main/res/values/setup.xml @@ -43,7 +43,6 @@ false false - on true From 5fe0fdcbeb0dc4ebb90a4d00f3d4cb791956430b Mon Sep 17 00:00:00 2001 From: alperozturk Date: Wed, 13 Nov 2024 17:25:20 +0100 Subject: [PATCH 48/52] internal link share still should be shown Signed-off-by: alperozturk --- .../android/ui/activity/FileActivity.java | 4 - .../android/ui/adapter/ShareeListAdapter.java | 93 ++++++++++++------- .../fragment/FileDetailSharingFragment.java | 8 -- 3 files changed, 59 insertions(+), 46 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/ui/activity/FileActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/FileActivity.java index 769e943506..8f3faef621 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/FileActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/FileActivity.java @@ -730,10 +730,6 @@ public abstract class FileActivity extends DrawerActivity } public static void showShareLinkDialog(FileActivity activity, ServerFileInterface file, String link) { - if (!MDMConfig.INSTANCE.shareViaLink(activity)) { - return; - } - // Create dialog to allow the user choose an app to send the link Intent intentToShareLink = new Intent(Intent.ACTION_SEND); diff --git a/app/src/main/java/com/owncloud/android/ui/adapter/ShareeListAdapter.java b/app/src/main/java/com/owncloud/android/ui/adapter/ShareeListAdapter.java index 2e051086d9..96c3904ac6 100644 --- a/app/src/main/java/com/owncloud/android/ui/adapter/ShareeListAdapter.java +++ b/app/src/main/java/com/owncloud/android/ui/adapter/ShareeListAdapter.java @@ -14,10 +14,12 @@ package com.owncloud.android.ui.adapter; import android.annotation.SuppressLint; import android.graphics.drawable.Drawable; import android.view.LayoutInflater; +import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import com.nextcloud.client.account.User; +import com.nextcloud.utils.mdm.MDMConfig; import com.owncloud.android.R; import com.owncloud.android.databinding.FileDetailsShareInternalShareLinkBinding; import com.owncloud.android.databinding.FileDetailsShareLinkShareItemBinding; @@ -79,43 +81,51 @@ public class ShareeListAdapter extends RecyclerView.Adapter { - return new LinkShareViewHolder( - FileDetailsShareLinkShareItemBinding.inflate(LayoutInflater.from(fileActivity), - parent, - false), - fileActivity, - viewThemeUtils); - } - case NEW_PUBLIC_LINK -> { - if (encrypted) { - return new NewSecureFileDropViewHolder( - FileDetailsShareSecureFileDropAddNewItemBinding.inflate(LayoutInflater.from(fileActivity), + boolean shareViaLink = MDMConfig.INSTANCE.shareViaLink(fileActivity); + + if (shareViaLink) { + switch (ShareType.fromValue(viewType)) { + case PUBLIC_LINK, EMAIL -> { + return new LinkShareViewHolder( + FileDetailsShareLinkShareItemBinding.inflate(LayoutInflater.from(fileActivity), + parent, + false), + fileActivity, + viewThemeUtils); + } + case NEW_PUBLIC_LINK -> { + if (encrypted) { + return new NewSecureFileDropViewHolder( + FileDetailsShareSecureFileDropAddNewItemBinding.inflate(LayoutInflater.from(fileActivity), + parent, + false) + ); + } else { + return new NewLinkShareViewHolder( + FileDetailsSharePublicLinkAddNewItemBinding.inflate(LayoutInflater.from(fileActivity), parent, false) - ); - } else { - return new NewLinkShareViewHolder( - FileDetailsSharePublicLinkAddNewItemBinding.inflate(LayoutInflater.from(fileActivity), - parent, - false) - ); + ); + } + } + case INTERNAL -> { + return new InternalShareViewHolder( + FileDetailsShareInternalShareLinkBinding.inflate(LayoutInflater.from(fileActivity), parent, false), + fileActivity); + } + default -> { + return new ShareViewHolder(FileDetailsShareShareItemBinding.inflate(LayoutInflater.from(fileActivity), + parent, + false), + user, + fileActivity, + viewThemeUtils); } } - case INTERNAL -> { - return new InternalShareViewHolder( - FileDetailsShareInternalShareLinkBinding.inflate(LayoutInflater.from(fileActivity), parent, false), - fileActivity); - } - default -> { - return new ShareViewHolder(FileDetailsShareShareItemBinding.inflate(LayoutInflater.from(fileActivity), - parent, - false), - user, - fileActivity, - viewThemeUtils); - } + } else { + return new InternalShareViewHolder( + FileDetailsShareInternalShareLinkBinding.inflate(LayoutInflater.from(fileActivity), parent, false), + fileActivity); } } @@ -127,6 +137,16 @@ public class ShareeListAdapter extends RecyclerView.Adapter Date: Wed, 13 Nov 2024 17:35:14 +0100 Subject: [PATCH 49/52] add disableDocumentsStorageProvider Signed-off-by: alperozturk --- app/src/main/java/com/owncloud/android/MainApp.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/src/main/java/com/owncloud/android/MainApp.java b/app/src/main/java/com/owncloud/android/MainApp.java index a5595f1154..d8c5d37b1c 100644 --- a/app/src/main/java/com/owncloud/android/MainApp.java +++ b/app/src/main/java/com/owncloud/android/MainApp.java @@ -22,6 +22,7 @@ import android.app.Application; import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.BroadcastReceiver; +import android.content.ComponentName; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; @@ -380,6 +381,18 @@ public class MainApp extends Application implements HasAndroidInjector, NetworkC registerGlobalPassCodeProtection(); networkChangeReceiver = new NetworkChangeReceiver(this, connectivityService); registerNetworkChangeReceiver(); + + if (!MDMConfig.INSTANCE.sendFilesSupport(this)) { + disableDocumentsStorageProvider(); + } + } + + public void disableDocumentsStorageProvider() { + String packageName = getPackageName(); + String providerClassName = "com.owncloud.android.providers.DocumentsStorageProvider"; + ComponentName componentName = new ComponentName(packageName, providerClassName); + PackageManager packageManager = getPackageManager(); + packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); } private final LifecycleEventObserver lifecycleEventObserver = ((lifecycleOwner, event) -> { From 54cc1df23a9c3b3cde2812163ddec42a615041be Mon Sep 17 00:00:00 2001 From: alperozturk Date: Thu, 14 Nov 2024 11:38:26 +0100 Subject: [PATCH 50/52] check sendFilesSupport via send link Signed-off-by: alperozturk --- .../ui/fragment/FileDetailSharingMenuBottomSheetDialog.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingMenuBottomSheetDialog.java b/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingMenuBottomSheetDialog.java index bf2c1ae72d..8a9d373d8a 100644 --- a/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingMenuBottomSheetDialog.java +++ b/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingMenuBottomSheetDialog.java @@ -16,6 +16,7 @@ import android.view.ViewGroup; import com.google.android.material.bottomsheet.BottomSheetBehavior; import com.google.android.material.bottomsheet.BottomSheetDialog; +import com.nextcloud.utils.mdm.MDMConfig; import com.owncloud.android.databinding.FileDetailsSharingMenuBottomSheetFragmentBinding; import com.owncloud.android.lib.resources.shares.OCShare; import com.owncloud.android.lib.resources.shares.ShareType; @@ -72,7 +73,10 @@ public class FileDetailSharingMenuBottomSheetDialog extends BottomSheetDialog { private void updateUI() { if (ocShare.getShareType() == ShareType.PUBLIC_LINK) { binding.menuShareAddAnotherLink.setVisibility(View.VISIBLE); - binding.menuShareSendLink.setVisibility(View.VISIBLE); + + if (MDMConfig.INSTANCE.sendFilesSupport(getContext())) { + binding.menuShareSendLink.setVisibility(View.VISIBLE); + } } else { binding.menuShareAddAnotherLink.setVisibility(View.GONE); binding.menuShareSendLink.setVisibility(View.GONE); From 887dd0f106bfb9babcc85139b78ef56aa48bf595 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Thu, 14 Nov 2024 15:39:06 +0100 Subject: [PATCH 51/52] fix send files support Signed-off-by: alperozturk --- .../java/com/owncloud/android/ui/dialog/SendShareDialog.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.kt b/app/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.kt index fd30641164..c45d2f854f 100644 --- a/app/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.kt +++ b/app/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.kt @@ -91,6 +91,10 @@ class SendShareDialog : BottomSheetDialogFragment(R.layout.send_share_fragment), @Suppress("MagicNumber") private fun setupSendButtonRecyclerView() { + if (!MDMConfig.sendFilesSupport(requireContext())) { + return + } + val sendIntent = createSendIntent(requireContext(), file!!) val sendButtonDataList = setupSendButtonData(sendIntent) val clickListener = setupSendButtonClickListener(sendIntent) From dbe54da4be93ca8d978b93eff7e3c25c429543d9 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 18 Nov 2024 14:23:07 +0100 Subject: [PATCH 52/52] hide binding.copyLink if clipBoardNotSupported Signed-off-by: alperozturk --- .../owncloud/android/ui/adapter/LinkShareViewHolder.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/owncloud/android/ui/adapter/LinkShareViewHolder.java b/app/src/main/java/com/owncloud/android/ui/adapter/LinkShareViewHolder.java index f6666905d8..f35d5ce770 100644 --- a/app/src/main/java/com/owncloud/android/ui/adapter/LinkShareViewHolder.java +++ b/app/src/main/java/com/owncloud/android/ui/adapter/LinkShareViewHolder.java @@ -19,6 +19,7 @@ import android.graphics.PorterDuff; import android.text.TextUtils; import android.view.View; +import com.nextcloud.utils.mdm.MDMConfig; import com.owncloud.android.R; import com.owncloud.android.databinding.FileDetailsShareLinkShareItemBinding; import com.owncloud.android.lib.resources.shares.OCShare; @@ -78,11 +79,16 @@ class LinkShareViewHolder extends RecyclerView.ViewHolder { String permissionName = SharingMenuHelper.getPermissionName(context, publicShare); setPermissionName(publicShare, permissionName); - binding.copyLink.setOnClickListener(v -> listener.copyLink(publicShare)); binding.overflowMenu.setOnClickListener(v -> listener.showSharingMenuActionSheet(publicShare)); if (!SharingMenuHelper.isSecureFileDrop(publicShare)) { binding.shareByLinkContainer.setOnClickListener(v -> listener.showPermissionsDialog(publicShare)); } + + if (MDMConfig.INSTANCE.clipBoardSupport(context)) { + binding.copyLink.setOnClickListener(v -> listener.copyLink(publicShare)); + } else { + binding.copyLink.setVisibility(View.GONE); + } } private void setPermissionName(OCShare publicShare, String permissionName) {