diff --git a/changelog.txt b/changelog.txt index 2a61458d08..69f62dc1a1 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,7 +1,6 @@ vNext ---------- - [MINOR] Add telemetry for the switch browser protocol (#2612) -- [MINOR] Enable the new Broker discovery on MSAL by default (#2618) Version 21.0.0 ---------- diff --git a/common/src/main/java/com/microsoft/identity/common/internal/activebrokerdiscovery/BrokerDiscoveryClientFactory.kt b/common/src/main/java/com/microsoft/identity/common/internal/activebrokerdiscovery/BrokerDiscoveryClientFactory.kt index 45614a9ba3..0b10ccffbc 100644 --- a/common/src/main/java/com/microsoft/identity/common/internal/activebrokerdiscovery/BrokerDiscoveryClientFactory.kt +++ b/common/src/main/java/com/microsoft/identity/common/internal/activebrokerdiscovery/BrokerDiscoveryClientFactory.kt @@ -39,6 +39,11 @@ class BrokerDiscoveryClientFactory { companion object { + private val TAG = BrokerDiscoveryClientFactory::class.simpleName + + @Volatile + private var IS_NEW_DISCOVERY_ENABLED = false + @Volatile private var clientSdkInstance: IBrokerDiscoveryClient? = null @@ -56,7 +61,12 @@ class BrokerDiscoveryClientFactory { **/ @JvmStatic fun setNewBrokerDiscoveryEnabled(isEnabled: Boolean){ - // noop + // If the flag changes, wipe the existing singleton. + if (isEnabled != IS_NEW_DISCOVERY_ENABLED) { + clientSdkInstance = null + brokerSdkInstance = null + IS_NEW_DISCOVERY_ENABLED = isEnabled + } } /** @@ -64,7 +74,7 @@ class BrokerDiscoveryClientFactory { **/ @JvmStatic fun isNewBrokerDiscoveryEnabled(): Boolean { - return true; + return BuildConfig.newBrokerDiscoveryEnabledFlag || IS_NEW_DISCOVERY_ENABLED; } /** @@ -116,7 +126,14 @@ class BrokerDiscoveryClientFactory { private fun getInstance(context: Context, platformComponents: IPlatformComponents, cache: IClientActiveBrokerCache) : IBrokerDiscoveryClient{ - return BrokerDiscoveryClient(context, platformComponents, cache) + val methodTag = "$TAG:getInstance" + return if (isNewBrokerDiscoveryEnabled()) { + Logger.info(methodTag, "Broker Discovery is enabled. Use the new logic on the SDK side") + BrokerDiscoveryClient(context, platformComponents, cache) + } else { + Logger.info(methodTag, "Broker Discovery is disabled. Use AccountManager on the SDK side.") + LegacyBrokerDiscoveryClient(context) + } } } } diff --git a/common/src/main/java/com/microsoft/identity/common/internal/activebrokerdiscovery/LegacyBrokerDiscoveryClient.kt b/common/src/main/java/com/microsoft/identity/common/internal/activebrokerdiscovery/LegacyBrokerDiscoveryClient.kt new file mode 100644 index 0000000000..789cefbe3f --- /dev/null +++ b/common/src/main/java/com/microsoft/identity/common/internal/activebrokerdiscovery/LegacyBrokerDiscoveryClient.kt @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +package com.microsoft.identity.common.internal.activebrokerdiscovery + +import android.content.Context +import com.microsoft.identity.common.internal.broker.BrokerData + +/** + * An [IBrokerDiscoveryClient] which is based on AccountManager. + **/ +class LegacyBrokerDiscoveryClient(val context: Context): IBrokerDiscoveryClient { + + override fun getActiveBroker(shouldSkipCache: Boolean): BrokerData? { + return AccountManagerBrokerDiscoveryUtil(context) + .getActiveBrokerFromAccountManager() + } +}