diff --git a/app/src/main/java/com/jens/automation2/Action.java b/app/src/main/java/com/jens/automation2/Action.java index 528924c8..6c9aae2d 100644 --- a/app/src/main/java/com/jens/automation2/Action.java +++ b/app/src/main/java/com/jens/automation2/Action.java @@ -491,7 +491,7 @@ public class Action Actions.setUsbTethering(context, getParameter1(), toggleActionIfPossible); break; case setWifi: - Actions.WifiStuff.setWifi(context, getParameter1(), toggleActionIfPossible); + Actions.WifiStuff.setWifi(context, getParameter1(), getParameter2(), toggleActionIfPossible); break; case setWifiTethering: Actions.setWifiTethering(context, getParameter1(), toggleActionIfPossible); diff --git a/app/src/main/java/com/jens/automation2/Actions.java b/app/src/main/java/com/jens/automation2/Actions.java index f5462af9..d907475e 100644 --- a/app/src/main/java/com/jens/automation2/Actions.java +++ b/app/src/main/java/com/jens/automation2/Actions.java @@ -44,6 +44,7 @@ import com.jens.automation2.location.WifiBroadcastReceiver; import com.jens.automation2.receivers.ConnectivityReceiver; import com.jens.automation2.receivers.NotificationListener; +import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.apache.http.client.HttpClient; import org.apache.http.conn.ClientConnectionManager; @@ -211,9 +212,20 @@ public class Actions public static class WifiStuff { - public static Boolean setWifi(Context context, Boolean desiredState, boolean toggleActionIfPossible) + public static Boolean setWifi(Context context, Boolean desiredState, String parameter2, boolean toggleActionIfPossible) { - if(context.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.Q) + boolean forceUseRoot = false; + + try + { + forceUseRoot = Boolean.parseBoolean(parameter2); + } + catch(Exception e) + { + + } + + if(context.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.Q || forceUseRoot) return setWifiWithRoot(context, desiredState, toggleActionIfPossible); else return setWifiOldFashioned(context, desiredState, toggleActionIfPossible); @@ -249,8 +261,15 @@ public class Actions { Miscellaneous.logEvent("i", "Wifi", "Changing wifi to " + String.valueOf(desiredState), 4); - if (desiredState && Settings.useWifiForPositioning) - WifiBroadcastReceiver.startWifiReceiver(automationServerRef.getLocationProvider()); + try + { + if (desiredState && Settings.useWifiForPositioning) + WifiBroadcastReceiver.startWifiReceiver(automationServerRef.getLocationProvider()); + } + catch(Exception e) + { + Miscellaneous.logEvent("w", "setWifiOldFashioned()", Log.getStackTraceString(e), 4); + } WifiManager myWifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); diff --git a/app/src/main/res/layout/activity_control_center.xml b/app/src/main/res/layout/activity_control_center.xml index 6dcdaa0a..cada1108 100644 --- a/app/src/main/res/layout/activity_control_center.xml +++ b/app/src/main/res/layout/activity_control_center.xml @@ -100,6 +100,7 @@ android:id="@+id/bSendEmailToDev" android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginBottom="@dimen/default_margin" android:text="@string/sendEmailToDev" />