[Android Apps and Games] almoped:
Yea I've been trying with Tasker aswell, but I figured since FD was already handeling wifi/data on/off it would be nice to have that functionality in just one place. Thanks for making this app in any case, and especially as open source. It has enabled me to try out a tiny bit android development as I patched in the functionality I mentioned. Seems to work ok. In case anyone else want to give 15sec wifi try/ 20min cooldown a go, here's the diff:

--- ForceDozeService.java.org	2016-06-09 11:12:06.000000000 +0200
+++ ForceDozeService.java	2016-06-10 22:26:12.651224600 +0200
@@ -8,11 +8,14 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
+import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.AsyncTask;
import android.os.Build;
+import android.os.CountDownTimer;
import android.os.IBinder;
import android.os.PowerManager;
+import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.support.v4.app.NotificationCompat;
@@ -49,6 +52,13 @@
boolean wasWiFiTurnedOn = false;
boolean wasMobileDataTurnedOn = false;
boolean maintenance = false;
+ boolean hasWiFiTimedOut = false;
+ boolean tryingToConnectWiFi = false;
+ boolean optionTryWiFi = true;
+ int wiFiConnectSecs = 15;
+ int wiFiCooldownMins = 20;
+ long lastWiFiTimeOut = 0;
+ CountDownTimer wiFiConnectTimer;
int dozeEnterDelay = 0;
Timer enterDozeTimer;
Timer disableSensorsTimer;
@@ -249,6 +259,9 @@
if (wasWiFiTurnedOn) {
Log.i(TAG, "Disabling WiFi");
disableWiFi();
+ } else if (hasWiFiTimedOut) { /* timeout disabled wifi */
+ Log.i(TAG, "Keeping Wifi meta-enabled since it has timed out");
+ wasWiFiTurnedOn = true;
}

}
@@ -483,13 +496,69 @@
}

public void disableWiFi() {
+ if (optionTryWiFi) {
+ if (tryingToConnectWiFi) {
+ Log.i(TAG, "Canceling WiFi connect timer");
+ wiFiConnectTimer.cancel();
+ tryingToConnectWiFi = false;
+ hasWiFiTimedOut = false;
+ }
+ }
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifi.setWifiEnabled(false);
}

public void enableWiFi() {
+ if (optionTryWiFi) {
+ if (hasWiFiTimedOut) {
+ long timeNow = SystemClock.elapsedRealtime();
+ if ((timeNow - lastWiFiTimeOut) > (wiFiCooldownMins*60*1000)) { //xx minutes, 60 secs pr min, 1000 milliseconds pr sec
+ Log.i(TAG, "WiFi has come out of timeout");
+ enableWiFiReally();
+ } else {
+ Log.i(TAG, "WiFi not enabled since it's in timeout");
+ }
+ } else { // we're not timed out
+ enableWiFiReally();
+ }
+ } else { //we're not using tryWifi
+ enableWiFiReally();
+ }
+ }
+
+ public void enableWiFiReally() {
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifi.setWifiEnabled(true);
+
+ if (optionTryWiFi) {
+ tryingToConnectWiFi = true;
+ Log.i(TAG, "Starting WiFi connect timer");
+ wiFiConnectTimer = new CountDownTimer( (wiFiConnectSecs*1000), 1000) { //secs*millisecs, every 1 sec do onTick..
+
+ public void onTick(long millisUntilFinished) {
+ //do nada, need this method?
+ }
+
+ public void onFinish() {
+ tryingToConnectWiFi = false;
+ WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
+ if (wifi.isWifiEnabled()) {
+ WifiInfo wifiInfo = wifi.getConnectionInfo();
+ if (wifiInfo.getNetworkId() == -1) {
+ Log.i(TAG, "WiFi connection has timed out");
+ hasWiFiTimedOut = true;
+ lastWiFiTimeOut = SystemClock.elapsedRealtime();
+ disableWiFi();
+ } else {
+ Log.i(TAG, "WiFi has connected");
+ hasWiFiTimedOut = false;
+ }
+ } else {
+ Log.i(TAG, "User disabled WiFi in connection window");
+ hasWiFiTimedOut = false;
+ }
+ }
+ }.start();
+ }
}

class ReloadSettingsReceiver extends BroadcastReceiver {
@@ -642,6 +711,9 @@
if (wasWiFiTurnedOn) {
Log.i(TAG, "Disabling WiFi");
disableWiFi();
+ } else if (hasWiFiTimedOut) {
+ Log.i(TAG, "Keeping Wifi meta-enabled since it has timed out");
+ wasWiFiTurnedOn = true;
}

}

It's just for ForceDozeService.java as I have no idea how android UI stuff works. boolean optionTryWiFi = true/false, should turn on/off the functionality.