A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/2144 below:

[Feature] Implement power optimization flag to enable MSAL to catch the broker's power optimization exceptions. · Issue #2144 · AzureAD/microsoft-authentication-library-for-dotnet · GitHub

Which Version of MSAL are you using ?
4.22

Platform
xamarin android

What authentication flow has the issue?

Repro
Enable power optimizations.
Try to acquire a token with broker

Expected behavior
MSAL should throw a specific exception to enable customers to inform end users to disable power optimization.

Actual behavior
MSAL throws a generic error message indicating that the broker may not be installed

Possible Solution
power optimization flag

"power_opt_check_for_network_req_enabled": true

MSAL Andorid code for reference:

/**
 * Determines if the client app cannot access the network due to power saving optimizations introduced in API 23.
 *
 * @return true if the device is API23 and one or both of the following is true: the device is in doze or the company
 * portal is in standby, false otherwise.
 */
@TargetApi(Build.VERSION_CODES.M)
public boolean isNetworkDisabledFromOptimizations() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        final PowerManagerWrapper powerManagerWrapper = PowerManagerWrapper.getInstance();
        if (powerManagerWrapper.isDeviceIdleMode(mConnectionContext) && !powerManagerWrapper.isIgnoringBatteryOptimizations(mConnectionContext)) {
            Telemetry.emit((BaseEvent) new BaseEvent().put(TelemetryEventStrings.Key.POWER_OPTIMIZATION, String.valueOf(true)));
            return true;
        }
    }
    Telemetry.emit((BaseEvent) new BaseEvent().put(TelemetryEventStrings.Key.POWER_OPTIMIZATION, String.valueOf(false)));
    return false;
}
/**
 * Check if the network is available. If the network is unavailable, {@link ClientException}
 * will throw with error code {@link ErrorStrings#NO_NETWORK_CONNECTION_POWER_OPTIMIZATION}
 * when connection is not available to refresh token because power optimization is enabled, or
 * throw with error code {@link ErrorStrings#DEVICE_NETWORK_NOT_AVAILABLE} otherwise.
 *
 * @param context                       application context
 * @param performPowerOptimizationCheck True, if power optimization checks should be performed.
 *                                      False otherwise.
 * @throws ClientException throw network exception
 */
public static void throwIfNetworkNotAvailable(final Context context,
                                              final boolean performPowerOptimizationCheck)
        throws ClientException {
    final DefaultConnectionService connectionService = new DefaultConnectionService(context);
    if (performPowerOptimizationCheck && connectionService.isNetworkDisabledFromOptimizations()) {
        throw new ClientException(
                ErrorStrings.NO_NETWORK_CONNECTION_POWER_OPTIMIZATION,
                "Connection is not available to refresh token because power optimization is "
                        + "enabled. And the device is in doze mode or the app is standby");
    }
    if (!connectionService.isConnectionAvailable()) {
        throw new ClientException(
                ErrorStrings.DEVICE_NETWORK_NOT_AVAILABLE,
                "Connection is not available to refresh token");
    }
}

Additional context/ Logs / Screenshots
Android PR with power optimization
AzureAD/microsoft-authentication-library-common-for-android#894


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4