fmetzger / android-sensorium

Sensorium - The Generic Sensor Framework
45 stars 19 forks source link

Scanning for wireless/cellular connections even if the wireless/radio is off #19

Open ReyhanJB opened 7 years ago

ReyhanJB commented 7 years ago

What steps will reproduce the problem? Turn on the wireless, start the app, go to setting and make sure that wireless connection sensor is enabled. After few minutes, turn off the wireless on the device.

What is the expected output? What do you see instead? When I turn off the wireless, I expect the app stops scanning for wireless connections. However, it does not remove the scanTask callback and unnecessarily scans for wireless devices, which drains the battery.

What version are you using? On what operating system? Latest version available on the F-Droid on both Nexus 5x and Nexus 6 running Android Marshmallow.

My suggestion to fix the problem This issue can be fixed similar to what is suggested in #17. In the "WifiConnectionSensor.java", identify a broadcast receiver that listens to changes in the status of the wireless sensor (That would be a Broadcast Receiver registered with "ConnectivityManager.CONNECTIVITY_ACTION" intent filter). In the "onReceive()" method of the broadcast receiver, if the wireless is turned off, then remove the scanTask callback. If the wireless is turned on, register it again to resume scanning.

IntentFilter filters = new IntentFilter(); filters.addAction(ConnectivityManager.CONNECTIVITY_ACTION); registerReceiver(connectivityChange, filters);

private final BroadcastReceiver connectivityChange = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Intent intent1 = new Intent(getApplicationContext(), DisplayMessageActivity.class); boolean disconnection = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false); if(!disconnection) intent1.putExtra(EXTRA_MESSAGE, "Connected to WiFi"); //The first parameter is the key for the intent if(disconnection) intent1.putExtra(EXTRA_MESSAGE, "Disconnected from WiFi"); } }

@aaaaalbert

fmetzger commented 7 years ago

Thanks for the report @ReyhanJB. I am currently not actively developing Sensorium. But I'd be happy to look at and merge PRs that fix these issues. Same goes for the other issues you reported.

ReyhanJB commented 7 years ago

@fmetzger: I can fix the issues with my suggestions and submit a pull request.