Merge remote-tracking branch 'origin/development' into development

# Conflicts:
#	app/src/main/res/values/strings.xml
This commit is contained in:
jens 2022-07-19 17:58:41 +02:00
commit 937c6ffe1d
12 changed files with 85 additions and 15 deletions

View File

@ -396,7 +396,7 @@ public class Rule implements Comparable<Rule>
return true; return true;
} }
Miscellaneous.logEvent("i", String.format(context.getResources().getString(R.string.ruleCheckOf), this.getName()), String.format(context.getResources().getString(R.string.ruleIsDeactivatedCantApply), this.getName()), 3); Miscellaneous.logEvent("i", String.format(context.getResources().getString(R.string.ruleCheckOf), this.getName()), String.format(context.getResources().getString(R.string.ruleIsDeactivatedCantApply), this.getName()), 4);
return false; return false;
} }

View File

@ -393,7 +393,7 @@ public class Rule implements Comparable<Rule>
return true; return true;
} }
Miscellaneous.logEvent("i", String.format(context.getResources().getString(R.string.ruleCheckOf), this.getName()), String.format(context.getResources().getString(R.string.ruleIsDeactivatedCantApply), this.getName()), 3); Miscellaneous.logEvent("i", String.format(context.getResources().getString(R.string.ruleCheckOf), this.getName()), String.format(context.getResources().getString(R.string.ruleIsDeactivatedCantApply), this.getName()), 4);
return false; return false;
} }

View File

@ -396,7 +396,7 @@ public class Rule implements Comparable<Rule>
return true; return true;
} }
Miscellaneous.logEvent("i", String.format(context.getResources().getString(R.string.ruleCheckOf), this.getName()), String.format(context.getResources().getString(R.string.ruleIsDeactivatedCantApply), this.getName()), 3); Miscellaneous.logEvent("i", String.format(context.getResources().getString(R.string.ruleCheckOf), this.getName()), String.format(context.getResources().getString(R.string.ruleIsDeactivatedCantApply), this.getName()), 4);
return false; return false;
} }

View File

@ -491,7 +491,7 @@ public class Action
Actions.setUsbTethering(context, getParameter1(), toggleActionIfPossible); Actions.setUsbTethering(context, getParameter1(), toggleActionIfPossible);
break; break;
case setWifi: case setWifi:
Actions.WifiStuff.setWifi(context, getParameter1(), toggleActionIfPossible); Actions.WifiStuff.setWifi(context, getParameter1(), getParameter2(), toggleActionIfPossible);
break; break;
case setWifiTethering: case setWifiTethering:
Actions.setWifiTethering(context, getParameter1(), toggleActionIfPossible); Actions.setWifiTethering(context, getParameter1(), toggleActionIfPossible);

View File

@ -44,6 +44,7 @@ import com.jens.automation2.location.WifiBroadcastReceiver;
import com.jens.automation2.receivers.ConnectivityReceiver; import com.jens.automation2.receivers.ConnectivityReceiver;
import com.jens.automation2.receivers.NotificationListener; import com.jens.automation2.receivers.NotificationListener;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.HttpClient; import org.apache.http.client.HttpClient;
import org.apache.http.conn.ClientConnectionManager; import org.apache.http.conn.ClientConnectionManager;
@ -83,10 +84,6 @@ public class Actions
public static AutomationService automationServerRef; public static AutomationService automationServerRef;
public static Context context; public static Context context;
private static Intent playMusicIntent; private static Intent playMusicIntent;
private static boolean suAvailable = false;
private static String suVersion = null;
private static String suVersionInternal = null;
private static List<String> suResult = null;
public final static String smsSeparator = "&sms&"; public final static String smsSeparator = "&sms&";
public final static String dummyPackageString = "dummyPkg239asd"; public final static String dummyPackageString = "dummyPkg239asd";
@ -215,9 +212,20 @@ public class Actions
public static class WifiStuff 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); return setWifiWithRoot(context, desiredState, toggleActionIfPossible);
else else
return setWifiOldFashioned(context, desiredState, toggleActionIfPossible); return setWifiOldFashioned(context, desiredState, toggleActionIfPossible);
@ -253,8 +261,15 @@ public class Actions
{ {
Miscellaneous.logEvent("i", "Wifi", "Changing wifi to " + String.valueOf(desiredState), 4); Miscellaneous.logEvent("i", "Wifi", "Changing wifi to " + String.valueOf(desiredState), 4);
try
{
if (desiredState && Settings.useWifiForPositioning) if (desiredState && Settings.useWifiForPositioning)
WifiBroadcastReceiver.startWifiReceiver(automationServerRef.getLocationProvider()); WifiBroadcastReceiver.startWifiReceiver(automationServerRef.getLocationProvider());
}
catch(Exception e)
{
Miscellaneous.logEvent("w", "setWifiOldFashioned()", Log.getStackTraceString(e), 4);
}
WifiManager myWifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiManager myWifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
@ -1865,6 +1880,12 @@ public class Actions
protected static boolean executeCommandViaSu(String[] commands) protected static boolean executeCommandViaSu(String[] commands)
{ {
boolean suAvailable = false;
String suVersion = null;
String suVersionInternal = null;
// List<String> suResult = null;
int suResult;
boolean success = false; boolean success = false;
try try
@ -1874,17 +1895,30 @@ public class Actions
{ {
suVersion = Shell.SU.version(false); suVersion = Shell.SU.version(false);
suVersionInternal = Shell.SU.version(true); suVersionInternal = Shell.SU.version(true);
suResult = Shell.SU.run(commands);
if (suResult != null) Miscellaneous.logEvent("i", "executeCommandViaSu()", "suVersion: " + suVersion + ", suVersionInternal: " + suVersionInternal, 5);
// suResult = Shell.SU.run(commands);
suResult = Shell.Pool.SU.run(commands);
// if (suResult != null)
// success = true;
Miscellaneous.logEvent("i", "executeCommandViaSu()", "RC=" + String.valueOf(suResult), 3);
if(suResult == 0)
success = true; success = true;
} }
else
Miscellaneous.logEvent("w", "executeCommandViaSu()", "su not available.", 4);
} }
catch (Exception e) catch (Exception e)
{ {
success = false; success = false;
} }
Miscellaneous.logEvent("i", "executeCommandViaSu()", "Returning " + String.valueOf(success), 4);
return success; return success;
} }

View File

@ -20,6 +20,7 @@ import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.RadioButton; import android.widget.RadioButton;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -42,6 +43,7 @@ public class ActivityManageTriggerWifi extends Activity
List<String> wifiList = new ArrayList<>(); List<String> wifiList = new ArrayList<>();
ArrayAdapter<String> wifiSpinnerAdapter; ArrayAdapter<String> wifiSpinnerAdapter;
private final static int requestCodeLocationPermission = 124; private final static int requestCodeLocationPermission = 124;
TextView tvWifiTriggerNameLocationNotice;
@Override @Override
protected void onCreate(@Nullable Bundle savedInstanceState) protected void onCreate(@Nullable Bundle savedInstanceState)
@ -55,11 +57,19 @@ public class ActivityManageTriggerWifi extends Activity
spinnerWifiList = (Spinner) findViewById(R.id.spinnerWifiList); spinnerWifiList = (Spinner) findViewById(R.id.spinnerWifiList);
bTriggerWifiSave = (Button) findViewById(R.id.bTriggerWifiSave); bTriggerWifiSave = (Button) findViewById(R.id.bTriggerWifiSave);
bLoadWifiList = (Button) findViewById(R.id.bLoadWifiList); bLoadWifiList = (Button) findViewById(R.id.bLoadWifiList);
tvWifiTriggerNameLocationNotice = (TextView)findViewById(R.id.tvWifiTriggerNameLocationNotice);
wifiSpinnerAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, wifiList); wifiSpinnerAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, wifiList);
spinnerWifiList.setAdapter(wifiSpinnerAdapter); spinnerWifiList.setAdapter(wifiSpinnerAdapter);
spinnerWifiList.setEnabled(false); // bug in Android; this only works when done in code, not in xml spinnerWifiList.setEnabled(false); // bug in Android; this only works when done in code, not in xml
if(
Miscellaneous.getTargetSDK(Miscellaneous.getAnyContext()) >= 29
&&
!ActivityPermissions.isPermissionDeclaratedInManifest(Miscellaneous.getAnyContext(), Manifest.permission.ACCESS_BACKGROUND_LOCATION)
)
tvWifiTriggerNameLocationNotice.setVisibility(View.VISIBLE);
if (getIntent().hasExtra("edit")) if (getIntent().hasExtra("edit"))
{ {
boolean connected = getIntent().getBooleanExtra("wifiState", false); boolean connected = getIntent().getBooleanExtra("wifiState", false);

View File

@ -509,6 +509,12 @@ public class ActivityPermissions extends Activity
case wifiConnection: case wifiConnection:
addToArrayListUnique(Manifest.permission.ACCESS_NETWORK_STATE, requiredPermissions); addToArrayListUnique(Manifest.permission.ACCESS_NETWORK_STATE, requiredPermissions);
addToArrayListUnique(Manifest.permission.ACCESS_WIFI_STATE, requiredPermissions); addToArrayListUnique(Manifest.permission.ACCESS_WIFI_STATE, requiredPermissions);
if(
Miscellaneous.getTargetSDK(Miscellaneous.getAnyContext()) >= 29
&&
isPermissionDeclaratedInManifest(Miscellaneous.getAnyContext(), Manifest.permission.ACCESS_BACKGROUND_LOCATION)
)
addToArrayListUnique(Manifest.permission.ACCESS_BACKGROUND_LOCATION, requiredPermissions);
break; break;
case notification: case notification:
addToArrayListUnique(Manifest.permission.BIND_NOTIFICATION_LISTENER_SERVICE, requiredPermissions); addToArrayListUnique(Manifest.permission.BIND_NOTIFICATION_LISTENER_SERVICE, requiredPermissions);

View File

@ -1911,4 +1911,9 @@ public class Miscellaneous extends Service
return null; return null;
} }
public static int getTargetSDK(Context context)
{
return context.getApplicationContext().getApplicationInfo().targetSdkVersion;
}
} }

View File

@ -63,7 +63,7 @@ public class WifiBroadcastReceiver extends BroadcastReceiver
// int state = -1; // int state = -1;
NetworkInfo myWifi = null; NetworkInfo myWifi = null;
if(intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) //gefeuert bei Trennung if(intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) // fired upon disconnection
{ {
// state = intent.getIntExtra(WifiManager.NETWORK_STATE_CHANGED_ACTION, -1); // state = intent.getIntExtra(WifiManager.NETWORK_STATE_CHANGED_ACTION, -1);
// Miscellaneous.logEvent("i", "WifiReceiver", "NETWORK_STATE_CHANGED_ACTION: " + String.valueOf(state)); // Miscellaneous.logEvent("i", "WifiReceiver", "NETWORK_STATE_CHANGED_ACTION: " + String.valueOf(state));

View File

@ -100,6 +100,7 @@
android:id="@+id/bSendEmailToDev" android:id="@+id/bSendEmailToDev"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/default_margin"
android:text="@string/sendEmailToDev" /> android:text="@string/sendEmailToDev" />
<TextView <TextView

View File

@ -47,6 +47,19 @@
</TableRow> </TableRow>
<TableRow>
<TextView
android:id="@+id/tvWifiTriggerNameLocationNotice"
android:layout_span="2"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="@color/red"
android:text="@string/locationRequiredToDetermineWifiName"
android:layout_marginVertical="@dimen/default_margin"
android:visibility="gone" />
</TableRow>
<TableRow> <TableRow>
<TextView <TextView

View File

@ -841,6 +841,7 @@
<string name="wakeLockTimeout">Specify timeout</string> <string name="wakeLockTimeout">Specify timeout</string>
<string name="wakeLockExplanation">Activate will keep the screen on while deactivate will let it turn off. For keeping it on you can either enter a duration after which it may turn off again or you can keep it on indefinitely. In the latter case you would need to create another keep-awake action (in this or another rule) in which you select deactivate.</string> <string name="wakeLockExplanation">Activate will keep the screen on while deactivate will let it turn off. For keeping it on you can either enter a duration after which it may turn off again or you can keep it on indefinitely. In the latter case you would need to create another keep-awake action (in this or another rule) in which you select deactivate.</string>
<string name="mayUseRegularExpressions">You may also enter a regular expression here.</string> <string name="mayUseRegularExpressions">You may also enter a regular expression here.</string>
<string name="locationRequiredToDetermineWifiName">To get the wifi SSID, the app requires location permissions. Because the Google version cannot get that, you can only use this trigger if you do not specify an SSID. So it can only be used to detect if wifi is connected or not.</string>
<string name="simplyDismissNotification">Simply dismiss</string> <string name="simplyDismissNotification">Simply dismiss</string>
<string name="clickNotificationButton">Click a button</string> <string name="clickNotificationButton">Click a button</string>
</resources> </resources>