1
votes

I have been working on some app that connects to an external device which is a WiFi Access Point that has no network connection in order to configurate it.

On some mobile phones it is causing me problems since they have the "Wifi Assistant" activated, that manages to switch the network when the WiFi signal is low. So I want to detect if this option is activated and show a proper dialog to the user saying that he should disable the wifi assistant (watchdog) to be able to configurate the device properly.

My code is the following:

/**
 * Checks whether the "Avoid poor networks" setting (named "Auto network switch" on some Samsung devices
 * or "Wifi assistant" on some Xiaomis) is enabled, which can in some instances interfere with Wi-Fi.
 *
 * @return true if the "Avoid poor networks" or "Auto network switch" setting is enabled
 */
public static boolean isPoorNetworkAvoidanceEnabled(final Context ctx, final boolean isWatchdogServiceFind) {
    final int SETTING_UNKNOWN = -1;
    final int SETTING_ENABLED = 1;
    String avoidPoorText = "wifi_watchdog_poor_network_test_enabled";
    final ContentResolver cr = ctx.getContentResolver();

    if (isWatchdogServiceFind) {
        avoidPoorText = "wifi_watchdog_on";
    }

    int result = Settings.Global.getInt(cr, avoidPoorText, SETTING_UNKNOWN);

    // Return if the setting value is known or unknown
    if (result != SETTING_UNKNOWN) {
        return (result == SETTING_ENABLED);
    } else {
        return false;
    }
}

This code is working fine for my Samsung devices but the result from Settings.Global.getInt(cr, "wifi_watchdog_poor_network_test_enabled") and Settings.Global.getInt(cr, "wifi_watchdog_on") are returning a SettingNotFoundException for other manufacturers. It fails at least in: Xiaomi Redmi 7, Xiaomi Redmi Note 8 and Motorola One Action.

Why for some devices it is not returning the value of the setting if I enable/disable the "WiFi assistant" option? Is there any way to fix it? From the official documentation (https://developer.android.com/reference/android/provider/Settings.Global#WIFI_WATCHDOG_ON) that should return the actual value of the WiFi watchdog.

1

1 Answers

1
votes

You can use :

adb shell settings list settings

adb shell settings list global

adb shell settings list secure

to check the strings of your terminal .

In Xiaomi is :

Settings.System.getString(cr,"wifi_assistant");