use MDMConfig

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-11-05 12:02:11 +01:00 committed by Alper Öztürk
parent 8bdfbb49ab
commit f4b49b5da5
7 changed files with 39 additions and 34 deletions

View file

@ -25,7 +25,7 @@ import com.nextcloud.client.account.UserAccountManager
import com.nextcloud.client.di.Injectable import com.nextcloud.client.di.Injectable
import com.nextcloud.client.network.ClientFactory import com.nextcloud.client.network.ClientFactory
import com.nextcloud.utils.extensions.getParcelableArgument 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.R
import com.owncloud.android.databinding.DialogChooseAccountBinding import com.owncloud.android.databinding.DialogChooseAccountBinding
import com.owncloud.android.datamodel.FileDataStorageManager 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.ui.adapter.UserListItem
import com.owncloud.android.utils.DisplayUtils import com.owncloud.android.utils.DisplayUtils
import com.owncloud.android.utils.DisplayUtils.AvatarGenerationListener import com.owncloud.android.utils.DisplayUtils.AvatarGenerationListener
import com.owncloud.android.utils.appConfig.AppConfigKeys
import com.owncloud.android.utils.theme.ViewThemeUtils import com.owncloud.android.utils.theme.ViewThemeUtils
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import javax.inject.Inject import javax.inject.Inject
@ -122,13 +121,7 @@ class ChooseAccountDialogFragment :
viewThemeUtils viewThemeUtils
) )
val disableMultiAccountViaMDM = requireContext().getRestriction( if (!MDMConfig.multiAccountSupport(requireContext())) {
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) {
binding.addAccount.visibility = View.GONE binding.addAccount.visibility = View.GONE
} }

View file

@ -0,0 +1,26 @@
/*
* Nextcloud - Android Client
*
* SPDX-FileCopyrightText: 2024 Alper Ozturk <alper.ozturk@nextcloud.com>
* 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
}
}

View file

@ -21,12 +21,11 @@ import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.widget.Toast; 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.MainApp;
import com.owncloud.android.R; import com.owncloud.android.R;
import com.owncloud.android.lib.common.accounts.AccountTypeUtils; import com.owncloud.android.lib.common.accounts.AccountTypeUtils;
import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.utils.appConfig.AppConfigKeys;
/** /**
* Authenticator for ownCloud accounts. * Authenticator for ownCloud accounts.
@ -72,8 +71,7 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator {
final Bundle bundle = new Bundle(); final Bundle bundle = new Bundle();
boolean disableMultiAccountViaMDM = ContextExtensionsKt.getRestriction(mContext, AppConfigKeys.DisableMultiAccount, mContext.getResources().getBoolean(R.bool.disable_multiaccount)); if (MDMConfig.INSTANCE.multiAccountSupport(mContext) && accounts.length > 1) {
if (!disableMultiAccountViaMDM && mContext.getResources().getBoolean(R.bool.multiaccount_support) && accounts.length > 1) {
try { try {
validateAccountType(accountType); validateAccountType(accountType);
} catch (AuthenticatorException e) { } catch (AuthenticatorException e) {

View file

@ -21,7 +21,6 @@ import android.app.Activity;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.RestrictionsManager;
import android.content.ServiceConnection; import android.content.ServiceConnection;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
@ -72,6 +71,7 @@ import com.nextcloud.common.PlainClient;
import com.nextcloud.operations.PostMethod; import com.nextcloud.operations.PostMethod;
import com.nextcloud.utils.extensions.BundleExtensionsKt; import com.nextcloud.utils.extensions.BundleExtensionsKt;
import com.nextcloud.utils.extensions.ContextExtensionsKt; import com.nextcloud.utils.extensions.ContextExtensionsKt;
import com.nextcloud.utils.mdm.MDMConfig;
import com.owncloud.android.MainApp; import com.owncloud.android.MainApp;
import com.owncloud.android.R; import com.owncloud.android.R;
import com.owncloud.android.databinding.AccountSetupBinding; import com.owncloud.android.databinding.AccountSetupBinding;
@ -811,10 +811,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
passCodeManager.onActivityResumed(this); passCodeManager.onActivityResumed(this);
Uri data = intent.getData(); 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 (data != null && data.toString().startsWith(getString(R.string.login_data_own_scheme))) {
if (disableMultiAccountViaMDM || if (!MDMConfig.INSTANCE.multiAccountSupport(this) ||
!getResources().getBoolean(R.bool.multiaccount_support) ||
accountManager.getAccounts().length == 1) { accountManager.getAccounts().length == 1) {
Toast.makeText(this, R.string.no_mutliple_accounts_allowed, Toast.LENGTH_LONG).show(); Toast.makeText(this, R.string.no_mutliple_accounts_allowed, Toast.LENGTH_LONG).show();
finish(); finish();
@ -1535,9 +1533,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
return; return;
} }
boolean disableMultiAccountViaMDM = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableMultiAccount, getResources().getBoolean(R.bool.disable_multiaccount)); if (!MDMConfig.INSTANCE.multiAccountSupport(this) ||
if (disableMultiAccountViaMDM ||
!getResources().getBoolean(R.bool.multiaccount_support) ||
accountManager.getAccounts().length == 1) { accountManager.getAccounts().length == 1) {
Toast.makeText(this, R.string.no_mutliple_accounts_allowed, Toast.LENGTH_LONG).show(); Toast.makeText(this, R.string.no_mutliple_accounts_allowed, Toast.LENGTH_LONG).show();
} else { } else {

View file

@ -11,19 +11,14 @@ import android.os.Bundle
import android.widget.TextView import android.widget.TextView
import android.widget.Toast import android.widget.Toast
import com.nextcloud.client.di.Injectable 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.R
import com.owncloud.android.utils.appConfig.AppConfigKeys
class DeepLinkLoginActivity : AuthenticatorActivity(), Injectable { class DeepLinkLoginActivity : AuthenticatorActivity(), Injectable {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
val disableMultiAccountViaMDM = getRestriction(AppConfigKeys.DisableMultiAccount, resources.getBoolean(R.bool.disable_multiaccount)) if (!MDMConfig.multiAccountSupport(this) || accountManager.accounts.size == 1) {
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() Toast.makeText(this, R.string.no_mutliple_accounts_allowed, Toast.LENGTH_LONG).show()
return return
} }

View file

@ -30,7 +30,7 @@ import com.nextcloud.client.onboarding.FirstRunActivity;
import com.nextcloud.model.WorkerState; import com.nextcloud.model.WorkerState;
import com.nextcloud.model.WorkerStateLiveData; import com.nextcloud.model.WorkerStateLiveData;
import com.nextcloud.utils.extensions.BundleExtensionsKt; 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.MainApp;
import com.owncloud.android.R; import com.owncloud.android.R;
import com.owncloud.android.authentication.AuthenticatorActivity; 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.dialog.AccountRemovalDialog;
import com.owncloud.android.ui.events.AccountRemovedEvent; import com.owncloud.android.ui.events.AccountRemovedEvent;
import com.owncloud.android.ui.helpers.FileOperationsHelper; import com.owncloud.android.ui.helpers.FileOperationsHelper;
import com.owncloud.android.utils.appConfig.AppConfigKeys;
import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode; import org.greenrobot.eventbus.ThreadMode;
@ -133,8 +132,7 @@ public class ManageAccountsActivity extends FileActivity implements UserListAdap
} }
arbitraryDataProvider = new ArbitraryDataProviderImpl(this); arbitraryDataProvider = new ArbitraryDataProviderImpl(this);
boolean disableMultiAccountViaMDM = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableMultiAccount, getResources().getBoolean(R.bool.disable_multiaccount)); multipleAccountsSupported = MDMConfig.INSTANCE.multiAccountSupport(this);
multipleAccountsSupported = getResources().getBoolean(R.bool.multiaccount_support) && !disableMultiAccountViaMDM;
userListAdapter = new UserListAdapter(this, userListAdapter = new UserListAdapter(this,
accountManager, accountManager,
@ -232,8 +230,7 @@ public class ManageAccountsActivity extends FileActivity implements UserListAdap
userListItems.add(new UserListItem(user, !pendingForRemoval)); userListItems.add(new UserListItem(user, !pendingForRemoval));
} }
boolean disableMultiAccountViaMDM = ContextExtensionsKt.getRestriction(this, AppConfigKeys.DisableMultiAccount, getResources().getBoolean(R.bool.disable_multiaccount)); if (MDMConfig.INSTANCE.multiAccountSupport(this)) {
if (getResources().getBoolean(R.bool.multiaccount_support) && !disableMultiAccountViaMDM) {
userListItems.add(new UserListItem()); userListItems.add(new UserListItem());
} }

View file

@ -65,7 +65,7 @@ class MultipleAccountsDialog : DialogFragment(), Injectable, UserListAdapter.Cli
private val accountListItems: List<UserListItem> private val accountListItems: List<UserListItem>
/** /**
* creates the account list items list including the add-account action in case * 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 * @return list of account list items
*/ */