1

I can't get a Note 2 running 4.1.2 or Nexus One running 2.2 to stay 'awake enough' with the screen off to keep acting on UDP broadcast packets. I have tried various wakelocks and permissions (see below), it works fine on a Desire HD on 2.3, a Huawei U8110 (T-Mobile pulse mini) on 2.1 and a Samsung Galaxy Mini on 2.2.1.

It does receive and act on new TCP connections directly to its IP/port, but not broadcast UDP packets. If I tap the power button to wake the screen it immediately responds to broadcasts. Forcing the the screen to stay on (PowerManager.SCREEN_DIM_WAKE_LOCK or higher) does keep it listening but that's not practical.

I'm acquiring wakelocks:

powerManager.newWakeLock(PARTIAL_WAKE_LOCK)
wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL)
wifiManager.createMulticastLock()

And declaring permissions:

android.permission.INTERNET
android.permission.WAKE_LOCK
android.permission.CHANGE_WIFI_MULTICAST_STATE
android.permission.ACCESS_WIFI_STATE
android.permission.CHANGE_WIFI_STATE

System Wifi sleep policy is 'never'.

The working devices all timeout their screens but still respond to the UDP broadcasts.

In the debugger's Threads view I can see it is still blocking at DatagramSocket.receive() whereas on the working devices that returns with a packet which is then logged to logcat.

All devices are running the same .apk.

NeilS
  • 625
  • 7
  • 13
  • Are you making it in a separated Thread and is that Thread still running when the screen off? – user2652394 Oct 30 '13 at 04:33
  • Yes. I think it's still running, it's in DDMS' Threads view and doesn't seem to change when the screen goes off. And it looks the same as the TCP listen Thread which does work. – NeilS Oct 30 '13 at 12:28

1 Answers1

1

An update for anyone else with the same problem:

Google seem to think this should work fine:

http://code.google.com/p/android/issues/detail?id=34278

The Nexus One is old so I guess nobody cares.

The Note 2 however is not so I asked in Samsung's developer forum. They don't care either:

http://developer.samsung.com/forum/board/thread/view.do?boardName=General&messageId=247968#postId247968

My current workaround is to provide an option in user-preferences to grab a full wakelock instead of the partial. I added code to cover my UI with a black screen which disappears on a tap; although the backlight is still on this is less annoying and stops potential screen burn. Turning the other lights (capacative buttons) off should be doable but IMHO it's 'good' to let the user know their phone is actually still fully awake.
It stops the device's normal lockscreen timeout. A manual power button press will lock but turns the screen off and so stops UDP receiving, on wake the lockscreen stays on forever until the user unlocks.
So this provides a poor user experience but it's the best I've found.

Any suggestions welcome.

NeilS
  • 625
  • 7
  • 13