From 1d7cf00b94073241a6c670ce0b6f615bad8b89c2 Mon Sep 17 00:00:00 2001 From: Jens Date: Thu, 18 Aug 2022 23:32:57 +0200 Subject: [PATCH] tethering type --- .../com/jens/automation2/ActivityManageRule.java | 3 +++ .../ActivityManageTriggerTethering.java | 5 +++++ .../main/java/com/jens/automation2/Trigger.java | 2 ++ .../automation2/receivers/TetheringReceiver.java | 14 +++++++++++++- 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/jens/automation2/ActivityManageRule.java b/app/src/main/java/com/jens/automation2/ActivityManageRule.java index bc011f3b..931379fb 100644 --- a/app/src/main/java/com/jens/automation2/ActivityManageRule.java +++ b/app/src/main/java/com/jens/automation2/ActivityManageRule.java @@ -321,6 +321,7 @@ public class ActivityManageRule extends Activity case tethering: Intent tetheringEditor = new Intent(ActivityManageRule.this, ActivityManageTriggerTethering.class); tetheringEditor.putExtra(intentNameTriggerParameter1, selectedTrigger.getTriggerParameter()); + tetheringEditor.putExtra(intentNameTriggerParameter2, selectedTrigger.getTriggerParameter2()); startActivityForResult(tetheringEditor, requestCodeTriggerTetheringEdit); break; case subSystemState: @@ -1868,6 +1869,7 @@ public class ActivityManageRule extends Activity if(resultCode == RESULT_OK) { newTrigger.setTriggerParameter(data.getBooleanExtra(intentNameTriggerParameter1, true)); + newTrigger.setTriggerParameter2(data.getStringExtra(intentNameTriggerParameter2)); newTrigger.setParentRule(ruleToEdit); ruleToEdit.getTriggerSet().add(newTrigger); this.refreshTriggerList(); @@ -1891,6 +1893,7 @@ public class ActivityManageRule extends Activity Trigger editedTrigger = new Trigger(); editedTrigger.setTriggerType(Trigger_Enum.tethering); editedTrigger.setTriggerParameter(data.getBooleanExtra(intentNameTriggerParameter1, true)); + editedTrigger.setTriggerParameter2(data.getStringExtra(intentNameTriggerParameter2)); editedTrigger.setParentRule(ruleToEdit); ruleToEdit.getTriggerSet().set(editIndex, editedTrigger); this.refreshTriggerList(); diff --git a/app/src/main/java/com/jens/automation2/ActivityManageTriggerTethering.java b/app/src/main/java/com/jens/automation2/ActivityManageTriggerTethering.java index f5169002..78fd7d6c 100644 --- a/app/src/main/java/com/jens/automation2/ActivityManageTriggerTethering.java +++ b/app/src/main/java/com/jens/automation2/ActivityManageTriggerTethering.java @@ -54,14 +54,19 @@ public class ActivityManageTriggerTethering extends Activity { case tetheringTypeAny: rbTetheringTypeAny.setChecked(true); + break; case tetheringTypeWifi: rbTetheringTypeWifi.setChecked(true); + break; case tetheringTypeBluetooth: rbTetheringTypeBluetooth.setChecked(true); + break; case tetheringTypeUsb: rbTetheringTypeUsb.setChecked(true); + break; case tetheringTypeCable: rbTetheringTypeCable.setChecked(true); + break; default: } } diff --git a/app/src/main/java/com/jens/automation2/Trigger.java b/app/src/main/java/com/jens/automation2/Trigger.java index d51ff34d..e26ac1c3 100644 --- a/app/src/main/java/com/jens/automation2/Trigger.java +++ b/app/src/main/java/com/jens/automation2/Trigger.java @@ -1714,6 +1714,8 @@ public class Trigger returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.tetheringActive)); else returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.tetheringNotActive)); + + returnString.append(" (" + Miscellaneous.getAnyContext().getResources().getString(R.string.type) + ": " + triggerParameter2 + ")"); break; case subSystemState: Trigger.subSystemStates desiredState = subSystemStates.valueOf(triggerParameter2); diff --git a/app/src/main/java/com/jens/automation2/receivers/TetheringReceiver.java b/app/src/main/java/com/jens/automation2/receivers/TetheringReceiver.java index 7cd64075..3e7e4166 100644 --- a/app/src/main/java/com/jens/automation2/receivers/TetheringReceiver.java +++ b/app/src/main/java/com/jens/automation2/receivers/TetheringReceiver.java @@ -6,6 +6,7 @@ import android.content.IntentFilter; import android.os.Build; import android.util.Log; +import com.jens.automation2.ActivityManageTriggerTethering; import com.jens.automation2.AutomationService; import com.jens.automation2.Miscellaneous; import com.jens.automation2.Rule; @@ -62,10 +63,21 @@ public class TetheringReceiver extends android.content.BroadcastReceiver impleme if(((ArrayList)ob).size() > 0) { tetheringActive = true; + if(lastTetheringTypes == null) + lastTetheringTypes = new ArrayList<>(); + else + lastTetheringTypes.clear(); for(String adapterName : (ArrayList)ob) { - String test = adapterName; + if(adapterName.contains("wlan")) + lastTetheringTypes.add(ActivityManageTriggerTethering.tetheringTypeWifi); + else if(adapterName.contains("bluetooth")) + lastTetheringTypes.add(ActivityManageTriggerTethering.tetheringTypeBluetooth); + else if(adapterName.contains("usb")) + lastTetheringTypes.add(ActivityManageTriggerTethering.tetheringTypeUsb); + else if(adapterName.contains("ndis")) + lastTetheringTypes.add(ActivityManageTriggerTethering.tetheringTypeCable); } } else