add enableLog configs to the MDM

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-11-05 12:22:38 +01:00 committed by Alper Öztürk
parent 90902f5194
commit e9054e1a05
3 changed files with 14 additions and 8 deletions

View file

@ -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
}
}

View file

@ -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");

View file

@ -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);