Many small fixes

This commit is contained in:
2025-12-28 15:27:50 +01:00
parent fd90b14bdc
commit 4a90b36f6a
10 changed files with 43 additions and 17 deletions

View File

@@ -514,8 +514,6 @@ public class Rule implements Comparable<Rule>
protected boolean activateInternally(AutomationService automationService)
{
boolean isActuallyToggleable = isActuallyToggable();
// boolean notLastActive = getLastActivatedRule() == null || !getLastActivatedRule().equals(Rule.this);
boolean doToggle = ruleToggle && isActuallyToggleable;
String message;

View File

@@ -487,8 +487,6 @@ public class Rule implements Comparable<Rule>
protected boolean activateInternally(AutomationService automationService)
{
boolean isActuallyToggleable = isActuallyToggable();
// boolean notLastActive = getLastActivatedRule() == null || !getLastActivatedRule().equals(Rule.this);
boolean doToggle = ruleToggle && isActuallyToggleable;
String message;

View File

@@ -514,8 +514,6 @@ public class Rule implements Comparable<Rule>
protected boolean activateInternally(AutomationService automationService)
{
boolean isActuallyToggleable = isActuallyToggable();
// boolean notLastActive = getLastActivatedRule() == null || !getLastActivatedRule().equals(Rule.this);
boolean doToggle = ruleToggle && isActuallyToggleable;
String message;

View File

@@ -1777,7 +1777,7 @@ public class Actions
}
catch (Exception e)
{
Miscellaneous.logEvent("e", "setData", "Error changing network type: " + Log.getStackTraceString(e), 2);
Miscellaneous.logEvent("e", "setData", "Error setting data connection: " + Log.getStackTraceString(e), 2);
return false;
}
}

View File

@@ -36,14 +36,14 @@ public class ActivityManageActionWifi extends Activity
Intent input = getIntent();
if(input.hasExtra(ActivityManageRule.intentNameActionParameter1))
{
rbActionWifiOn.setChecked(input.getBooleanExtra(ActivityManageRule.intentNameActionParameter1, true));
rbActionWifiOff.setChecked(!input.getBooleanExtra(ActivityManageRule.intentNameActionParameter1, true));
}
if(input.hasExtra(ActivityManageRule.intentNameActionParameter2))
chkWifiRunAsRoot.setChecked(Boolean.parseBoolean(input.getStringExtra(ActivityManageRule.intentNameActionParameter2)));
// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
// Miscellaneous.messageBox(getResources().getString(R.string.app_name), getResources().getString(R.string.android10WifiToggleNotice), ActivityManageActionWifi.this).show();
if(getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.Q)
tvWifiExplanation1.setVisibility(View.VISIBLE);
else

View File

@@ -281,6 +281,19 @@ public class ActivityPermissions extends Activity
return false;
}
public static int getAmountOfRulesWhichLackPermissions(Context context)
{
int rulesWhichLackPermissions = 0;
for(Rule r : Rule.getRuleCollection())
{
if(!ActivityPermissions.havePermissionsForRule(r, context))
rulesWhichLackPermissions++;
}
return rulesWhichLackPermissions;
}
public static boolean havePermission(String s, Context context)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
@@ -536,6 +549,8 @@ public class ActivityPermissions extends Activity
addToArrayListUnique(Manifest.permission.BLUETOOTH_ADMIN, requiredPermissions);
addToArrayListUnique(Manifest.permission.BLUETOOTH, requiredPermissions);
addToArrayListUnique(Manifest.permission.ACCESS_NETWORK_STATE, requiredPermissions);
if(Build.VERSION.SDK_INT >= 31)
addToArrayListUnique(Manifest.permission.BLUETOOTH_CONNECT, requiredPermissions);
break;
case charging:
// addToArrayListUnique(Manifest.permission.READ_PHONE_STATE, requiredPermissions);
@@ -911,12 +926,8 @@ public class ActivityPermissions extends Activity
usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName));
break;
case Manifest.permission.BLUETOOTH_ADMIN:
for(String ruleName : getRulesUsing(Trigger.Trigger_Enum.bluetoothConnection))
usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName));
for(String ruleName : getRulesUsing(Action.Action_Enum.setBluetooth))
usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName));
break;
case Manifest.permission.BLUETOOTH:
case Manifest.permission.BLUETOOTH_CONNECT:
for(String ruleName : getRulesUsing(Trigger.Trigger_Enum.bluetoothConnection))
usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName));
for(String ruleName : getRulesUsing(Action.Action_Enum.setBluetooth))

View File

@@ -180,6 +180,17 @@ public class AutomationService extends Service implements OnInitListener
Rule.getRuleCollection().size() == 0
)
{
if(
Rule.getRuleCollection().size() > 0
&&
Rule.getRuleCollection().size() == ActivityPermissions.getAmountOfRulesWhichLackPermissions(Miscellaneous.getAnyContext())
)
{
Miscellaneous.logEvent("w", "AutomationService", "Don't have complete permissions for any defined rule. Not starting service.", 1);
Toast.makeText(context, context.getResources().getString(R.string.serviceWontStartPermissions), Toast.LENGTH_LONG).show();
return false;
}
if (startAtBoot)
{
/*

View File

@@ -7,6 +7,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.util.Log;
import android.widget.Toast;
import com.jens.automation2.ActivityPermissions;
import com.jens.automation2.AutomationService;
@@ -149,8 +150,6 @@ public class BluetoothReceiver extends BroadcastReceiver implements AutomationLi
{
return lhs.getName().compareTo(rhs.getName());
}
;
});
}
catch(NullPointerException e)
@@ -159,6 +158,12 @@ public class BluetoothReceiver extends BroadcastReceiver implements AutomationLi
returnArray = new BluetoothDevice[] {};
}
catch(SecurityException se)
{
Toast.makeText(Miscellaneous.getAnyContext(), Miscellaneous.getAnyContext().getResources().getString(R.string.permissionRequiredBluetooth), Toast.LENGTH_SHORT).show();
returnArray = new BluetoothDevice[] {};
}
return returnArray;
}

View File

@@ -12,6 +12,7 @@
<string name="pleaseSpecifiyTrigger">Please specify at least one trigger.</string>
<string name="pleaseSpecifiyAction">Please specify at least one action.</string>
<string name="serviceWontStart">No rules defined. Service won\'t start.</string>
<string name="serviceWontStartPermissions">Don\'t have full permission for any defined rule. Service won\'t start.</string>
<string name="serviceWontStartNoActivatedRules">No activated rules defined. Service won\'t start.</string>
<string name="serviceStarted">Automation Service started.</string>
<string name="version">Version %1$s.</string>
@@ -970,4 +971,5 @@
<string name="far">far</string>
<string name="proximityText">proximity is between \"%1$s\" and \"%2$s\"</string>
<string name="pleaseWait">Please wait.</string>
<string name="permissionRequiredBluetooth">Bluetooth permission required to edit this rule. Request permissions from the main screen first.</string>
</resources>

View File

@@ -0,0 +1,3 @@
* Fixed: Set-wifi action wasn't correctly pre-filled-out when editing action.
* Fixed: Service startup checks improved when no rules with full permissions were present.
* Fixed: Editing bluetooth trigger could crash if permissions weren't given.