I'm trying to use Wifi P2P NSD to share a small string between phones and "hubs" (servers and clients, respectively)
Since phones move around and the hubs will be in fixed places (think beacons), it would be ideal for the phone to constantly advertise its service and its DNS record. I execute the following:
mManager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
mChannel = mManager.initialize(this, getMainLooper(), null);
mRecord = new HashMap<String, String>();
mRecord.put(AppConstants.RECORD_KEY, val);
mService = WifiP2pDnsSdServiceInfo.newInstance(
AppConstants.SERVICE_INSTANCE, AppConstants.SERVICE_REG_TYPE, mRecord);
mManager.addLocalService(mChannel, mService, addServiceListener);
mManager.setDnsSdResponseListeners(mChannel, dnsSdServiceResponseListener,
dnsSdTxtRecordListener);
mManager.addServiceRequest(mChannel, mRequest, addServiceRequestListener);
mManager.discoverServices(mChannel, serviceDiscoveryListener);
After making the call to discoverServices, the service is on the framework it would seem permantly (unless I clear it or close the channel/reset the wifi).
However, I am burning a ton of battery. Just looking at the system's battery preferences it seems like Google Play Services is burning the majority of my battery, while nothing is attributed to the "Wifi" component. Additionally, in my baseline state (airplane mode, screen off, wifi on but idle), the phone gets down to drawing ~20mA, while after executing the above code once, it doesn't go below ~130mA draw from the battery.
My question is, what exactly is going on that is consuming battery? Does just supporting the framework keep the wifi or phone awake and is there any way around this? I'm just confused because the battery drain doesn't seem to be attributed to any non-idling of the wifi component.