Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature - Add More MDM #13942

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
b11b802
add new mdm fields
alperozturk96 Nov 4, 2024
42f997d
use bundle extensions
alperozturk96 Nov 4, 2024
731b022
add disableMultiAccount
alperozturk96 Nov 4, 2024
ce91a67
remove AppConfigManager use RestrictionManager directly due to multip…
alperozturk96 Nov 4, 2024
d0d2671
add disableClipboard
alperozturk96 Nov 4, 2024
1acd007
add disableSharing
alperozturk96 Nov 4, 2024
5443272
remove already existing capability
alperozturk96 Nov 4, 2024
3b014f8
use generic getRestriction extension
alperozturk96 Nov 4, 2024
b6495e3
make defaultValue non nullable
alperozturk96 Nov 4, 2024
596c539
use ContextExtensions
alperozturk96 Nov 4, 2024
55c2e20
use AppConfigKeys as parameter instead of String
alperozturk96 Nov 4, 2024
d1d558b
handle nullable RestrictionsManager
alperozturk96 Nov 4, 2024
b3afcc9
add all mdm configs
alperozturk96 Nov 5, 2024
cadefb3
add all mdm configs
alperozturk96 Nov 5, 2024
a6dc36e
add all mdm configs
alperozturk96 Nov 5, 2024
c0c55a5
use disableIntro
alperozturk96 Nov 5, 2024
034747b
use disableIntro
alperozturk96 Nov 5, 2024
a4070bd
use disableMoreExternalSite
alperozturk96 Nov 5, 2024
47fe75f
use disableLog
alperozturk96 Nov 5, 2024
dc835e8
use disableSharing
alperozturk96 Nov 5, 2024
8f7c798
add default values
alperozturk96 Nov 5, 2024
66bd08b
use disable_multiaccount
alperozturk96 Nov 5, 2024
8a9a982
better variable naming
alperozturk96 Nov 5, 2024
0460cfd
use MDMConfig
alperozturk96 Nov 5, 2024
e6eb2fd
add share configs to the MDM
alperozturk96 Nov 5, 2024
cb92d07
add clipboard configs to the MDM
alperozturk96 Nov 5, 2024
ab17259
add externalSiteSupport configs to the MDM
alperozturk96 Nov 5, 2024
1d38084
add showIntro configs to the MDM
alperozturk96 Nov 5, 2024
55c0ade
add enableLog configs to the MDM
alperozturk96 Nov 5, 2024
f2e0aa4
add sendFilesSupport configs to the MDM
alperozturk96 Nov 5, 2024
ee66f02
optimize imports
alperozturk96 Nov 5, 2024
a9725e2
remove extensions
alperozturk96 Nov 5, 2024
4d4d4f7
fix wrong condition
alperozturk96 Nov 5, 2024
39939bb
format code
alperozturk96 Nov 5, 2024
835156f
handle nullable contexts
alperozturk96 Nov 5, 2024
0182abb
check clipBoardSupport
alperozturk96 Nov 5, 2024
74ab95e
disable log default value is true
alperozturk96 Nov 5, 2024
7d483dc
fix spotbugs
alperozturk96 Nov 5, 2024
2c241cd
better function name
alperozturk96 Nov 5, 2024
3012c07
fix conditions for multi account
alperozturk96 Nov 5, 2024
4b8ab48
check contact app
alperozturk96 Nov 5, 2024
a93164e
check shareViaLink, shareViaUser in file detail fragment
alperozturk96 Nov 5, 2024
26eb851
check shared icon visibility in adapter
alperozturk96 Nov 5, 2024
52819c9
hide link button if clipboard disabled
alperozturk96 Nov 5, 2024
8a97812
revert if condition for AccountAuthenticator
alperozturk96 Nov 6, 2024
1142c4f
combine share logic
alperozturk96 Nov 6, 2024
7f8f382
fix sharing tab visibility
alperozturk96 Nov 12, 2024
fa7d4d3
internal link share still should be shown
alperozturk96 Nov 13, 2024
36be996
add disableDocumentsStorageProvider
alperozturk96 Nov 13, 2024
19a95ca
check sendFilesSupport via send link
alperozturk96 Nov 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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.mdm.MDMConfig
import com.owncloud.android.BuildConfig
import com.owncloud.android.R
import com.owncloud.android.authentication.AuthenticatorActivity
Expand Down Expand Up @@ -76,13 +77,12 @@ class FirstRunActivity : BaseActivity(), Injectable {
binding = FirstRunActivityBinding.inflate(layoutInflater)
setContentView(binding.root)

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(MDMConfig.showIntro(this))
setupHostOwnServerTextView(MDMConfig.showIntro(this))
deleteAccountAtFirstLaunch()
setupFeaturesViewAdapter()
handleOnBackPressed()
Expand Down Expand Up @@ -207,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ 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.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

internal class OnboardingServiceImpl constructor(
internal class OnboardingServiceImpl(
private val resources: Resources,
private val preferences: AppPreferences,
private val accountProvider: CurrentAccountProvider
Expand Down Expand Up @@ -61,8 +62,7 @@ internal class OnboardingServiceImpl constructor(
}

override fun launchFirstRunIfNeeded(activity: Activity): Boolean {
val isProviderOrOwnInstallationVisible = resources.getBoolean(R.bool.show_provider_or_own_installation)
val canLaunch = isProviderOrOwnInstallationVisible && isFirstRun && activity is AuthenticatorActivity
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +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.mdm.MDMConfig
import com.owncloud.android.R
import com.owncloud.android.databinding.DialogChooseAccountBinding
import com.owncloud.android.datamodel.FileDataStorageManager
Expand Down Expand Up @@ -120,8 +121,7 @@ class ChooseAccountDialogFragment :
viewThemeUtils
)

// hide "add account" when no multi account
if (!resources.getBoolean(R.bool.multiaccount_support)) {
if (!MDMConfig.multiAccountSupport(requireContext())) {
binding.addAccount.visibility = View.GONE
}

Expand Down
134 changes: 134 additions & 0 deletions app/src/main/java/com/nextcloud/utils/mdm/MDMConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
* Nextcloud - Android Client
*
* SPDX-FileCopyrightText: 2024 Alper Ozturk <[email protected]>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

package com.nextcloud.utils.mdm

import android.content.Context
import android.content.RestrictionsManager
import com.owncloud.android.BuildConfig
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,
context.resources.getBoolean(R.bool.disable_multiaccount)
)

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
}

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 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,
context.resources.getBoolean(R.bool.disable_clipboard)
)

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
}

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 isLogEnabled(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
}

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 <T : Any> 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
}
}
}
Loading
Loading