Menu

#33 Set WIFI_MODE_FULL_HIGH_PERF for SDK_INT < 12 also

Next Release
closed
None
1
2015-01-29
2013-12-16
No

In ServeStream there's support for disabling Wifi power saving using WIFI_MODE_FULL_HIGH_PERF:

// prevent WIFI throttling when the screen is off
int lockType = WifiManager.WIFI_MODE_FULL;
if (Build.VERSION.SDK_INT >= 12) {
    lockType = 3;
}

...

lockType = 3 means WIFI_MODE_FULL_HIGH_PERF. But, this code is not run on a Motorola Defy Mini because its SDK_INT is 10.

WIFI_MODE_FULL_HIGH_PERF does work well on this phone. I've verified this with voip app csipsimple which has the following logic for enabling WIFI_MODE_FULL_HIGH_PERF:

int mode = WifiManager.WIFI_MODE_FULL;
if(Compatibility.isCompatible(9) && prefsWrapper.getPreferenceBooleanValue(SipConfigManager.LOCK_WIFI_PERFS)) {
        mode = 0x3; // WIFI_MODE_FULL_HIGH_PERF
}

The isCompatible(9) expands to SDK_INT >= 9.

So, I think that ServeStream could lower the required SDK_INT version for WIFI_MODE_FULL_HIGH_PERF to 9.

Discussion

  • William Seemann

    William Seemann - 2013-12-16

    Thanks for the report. Here is my only issue: WIFI_MODE_FULL_HIGH_PREF is only available in API 12+ (http://developer.android.com/reference/android/net/wifi/WifiManager.html#WIFI_MODE_FULL_HIGH_PERF) This would imply to me that devices running an older version wouldn't recoginize this lock type since it wouldn't be recognized by the platform. This is why I coded it that way. Any ideas? - William

     
  • Robert Högberg

    Robert Högberg - 2013-12-16

    There's some historical information about WIFI_MODE_FULL_HIGH_PERF available here:
    http://code.google.com/p/android/issues/detail?id=9781#c32

    .. and in some other comments following that one.

    In short, it seems like WIFI_MODE_FULL_HIGH_PERF was added in API 9, but wasn't documented until API 12.

    I guess it's possible that there are devices with API >= 9 and API < 12 which don't support WIFI_MODE_FULL_HIGH_PERF. To support that case, I see three possibilities:

    1. Add yet another UI setting which the user can toggle. Probably not desired since it could get confusing and difficult to use (but option could be hidden if API >= 12). This is what csipsimple has done.
    2. Try to handle both lock modes automatically depending on what the device supports. According to http://code.google.com/p/android/issues/detail?id=15549#c4 this may be hard and/or complicated.
    3. Add a list of pre-API 12 devices known to support WIFI_MODE_FULL_HIGH_PERF and if such a device is detected, use WIFI_MODE_FULL_HIGH_PERF. Unless option 1 above is implemented it will be difficult for users to try out WIFI_MODE_FULL_HIGH_PERF and report back if it works for them or not.

    But.. Maybe it's ok to always set WIFI_MODE_FULL_HIGH_PREF if API >= 9?

    I realize that none of the suggested fixes above is "perfect" and could cause problems for others :-/ But if I can use WIFI_MODE_FULL_HIGH_PERF instead of having to use the screen wake lock that would be a big win, so of course I hope that you can either figure out a "perfect" fix or implement something from above :-)

     
  • Robert Högberg

    Robert Högberg - 2013-12-16

    Maybe I should try WIFI_MODE_FULL_HIGH_PERF before we go any further with this. I haven't actually tried it yet. Can you easily provide a test build for me?

     
  • William Seemann

    William Seemann - 2013-12-16

    Haha, no problem. I will try to get you one by tomorrow. I want to try calling:

    createWifiLock(int lockType, String tag);
    

    with an invalid lockType and see what it returns first. Depending out the outcome of that test I may be able to implement an easy fix. Worst case, I can just add a preference setting. It's not the most elegant solution but at least I won't run the risk of breaking the app for all users running API 9-11 who already use the WIFI lock. Problems like this make me love Android development... :-)

     
  • William Seemann

    William Seemann - 2013-12-17

    Here is a test version with the following modification:

    // prevent WIFI throttling when the screen is off
    int lockType = WifiManager.WIFI_MODE_FULL;
    if (Build.VERSION.SDK_INT >= 9) {
        lockType = 3;
    }
    

    Please test and let me know if it works for you.

     
  • Robert Högberg

    Robert Högberg - 2013-12-17

    Thanks for the build William.

    I tested this and it didn't actually work on my phone.

    I went back to check my configuration of csipsimple and noticed that I had mixed up two settings and WIFI_MODE_FULL_HIGH_PERF wasn't the setting that caused csipsimple to work. I need the screen activated when using csipsimple to get good wifi performance so I guess I have to keep using the screen lock with servestream also.

    Sorry for this confusion :-/ It's ok to close this feature request if you want.

    It's possible that some old phones with API < 12 would benefit from WIFI_MODE_FULL_HIGH_PERF, but not my phone so I can't really help test this.

     
  • Robert Högberg

    Robert Högberg - 2013-12-17
    • summary: Set WIFI_MODE_FULL_HIGH_PERF for Motorola Defy Mini --> Set WIFI_MODE_FULL_HIGH_PERF for SDK_INT < 12 also
     
  • William Seemann

    William Seemann - 2013-12-17
    • status: open --> closed
    • assigned_to: William Seemann
     
  • William Seemann

    William Seemann - 2013-12-17

    No problem Robert. Let me know if you need help with anything else.

     
  • jaylus12

    jaylus12 - 2014-12-12

    Use reflection..

    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    int lockType = WifiManager.WIFI_MODE_FULL;
    try {
      Field field = wifiManager.getClass().getField("WIFI_MODE_FULL_HIGH_PERF");
      lockType = (Integer) field.get(null);
    }
    catch (Exception e) {
    
    }
    wifiLock = wifiManager.createWifiLock(lockType, "tag...");
    wifiLock.setReferenceCounted(false);
    
     

    Last edit: jaylus12 2014-12-12
  • William Seemann

    William Seemann - 2014-12-17

    The solution you proposed is better. I've update the code accordingly, thank you.

     

Log in to post a comment.