I am trying to use Wifi P2P NSD to exchange a small line between phones and hubs (servers and clients respectively).
Since the phones are moving, and the hubs will be in fixed places (I think, beacons), it would be ideal if the phone constantly advertised its service and its DNS record. I am doing 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 a call to DiscoverServices, the service is in a framework that will look different (unless I clear it or close the / reset wifi channel).
However, I burn a ton of battery. Just by looking at the battery system preferences, it seems like Google Play Services burns most of my battery while nothing is connected to the Wifi component. In addition, in my basic state (flight mode, the screen is off, Wi-Fi is on but inactive) the phone switches to a drawing of ~ 20 mA, and after executing the above code once it does not drop below ~ 130 mA from the battery.
My question is: what exactly is happening, is it battery consumption? Does it only support infrastructure by supporting Wi-Fi or a phone, and is there any way to do this? I'm just confused because the battery leak does not seem to be related to the lack of idle wifi component.