Set WIFI_MODE_FULL_HIGH_PERF for SDK_INT < 12 also
Streaming Media Player for Android
Brought to you by:
wseemann
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.
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
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:
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 :-)
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?
Haha, no problem. I will try to get you one by tomorrow. I want to try calling:
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... :-)
Here is a test version with the following modification:
Please test and let me know if it works for you.
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.
No problem Robert. Let me know if you need help with anything else.
Use reflection..
Last edit: jaylus12 2014-12-12
The solution you proposed is better. I've update the code accordingly, thank you.