Wake + Wifi Lock No Effect

My background service sends messages to the local server as quickly as possible. Each message usually takes about 30 ms. But when the phone is in sleep mode, it takes about 400 ms-1000 ms (the screen is off with the β€œcorrect” Wifi policy).

In my service, I use the following code to purchase Wifi-lock and WakeLock.

PowerManager lPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = lPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "WakeLockTag"); WifiManager lWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) { mWifiLock = lWifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "LockTag"); } else { mWifiLock = lWifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, "LockTag"); } mWifiLock.acquire(); mWakeLock.acquire(); 

Is it possible to get the same performance as when the screen is on?

+6
source share
1 answer

As far as I know, there is a known problem. Some devices are unreliable with a combination of PARTIAL_WAKE_LOCK and WifiLock: WIFI_MODE_FULL_HIGH_PERF.

This does not work when the screen is off.

You can also check with SCREEN_DIM_WAKE_LOCK on this particular device.

0
source

Source: https://habr.com/ru/post/952107/


All Articles