Tethering

This commit is contained in:
jens 2022-08-27 02:07:47 +02:00
parent b73a45f4cd
commit eff04037a1

View File

@ -51,37 +51,43 @@ public class TetheringReceiver extends android.content.BroadcastReceiver impleme
{ {
Miscellaneous.logEvent("i", "TetheringReceiver", "Received " + intent.getAction(), 5); Miscellaneous.logEvent("i", "TetheringReceiver", "Received " + intent.getAction(), 5);
/*
DETECT BY DATA DELIVERED IN INTENT
*/
// if(intent.getAction().equals("android.net.conn.TETHER_STATE_CHANGED"))
// {
String searchArray = null; String searchArray = null;
if(Build.VERSION.SDK_INT >= 26) if (Build.VERSION.SDK_INT >= 26)
searchArray = "tetherArray"; searchArray = "tetherArray";
else else
searchArray = "activeArray"; searchArray = "activeArray";
for(String key : intent.getExtras().keySet()) for (String key : intent.getExtras().keySet())
{ {
// Miscellaneous.logEvent("i", "Broadcast extra", "Broadcast " + intent.getAction() + " has extra " + key + " and type " + intent.getExtras().get(key).getClass().getName(), 4); // Miscellaneous.logEvent("i", "Broadcast extra", "Broadcast " + intent.getAction() + " has extra " + key + " and type " + intent.getExtras().get(key).getClass().getName(), 4);
Object ob = intent.getExtras().get(key); Object ob = intent.getExtras().get(key);
if(key.equals(searchArray) && ob instanceof ArrayList) if (key.equals(searchArray) && ob instanceof ArrayList)
{ {
if(((ArrayList<String>)ob).size() > 0) if (((ArrayList<String>) ob).size() > 0)
{ {
tetheringActive = true; tetheringActive = true;
if(lastTetheringTypes == null) if (lastTetheringTypes == null)
lastTetheringTypes = new ArrayList<>(); lastTetheringTypes = new ArrayList<>();
else else
lastTetheringTypes.clear(); lastTetheringTypes.clear();
for(String adapterName : (ArrayList<String>)ob) for (String adapterName : (ArrayList<String>) ob)
{ {
if(adapterName.contains("wlan")) if (adapterName.contains("wlan"))
lastTetheringTypes.add(ActivityManageTriggerTethering.tetheringTypeWifi); lastTetheringTypes.add(ActivityManageTriggerTethering.tetheringTypeWifi);
else if(adapterName.contains("bluetooth")) else if (adapterName.contains("bluetooth"))
lastTetheringTypes.add(ActivityManageTriggerTethering.tetheringTypeBluetooth); lastTetheringTypes.add(ActivityManageTriggerTethering.tetheringTypeBluetooth);
else if(adapterName.contains("rndis")) else if (adapterName.contains("rndis"))
lastTetheringTypes.add(ActivityManageTriggerTethering.tetheringTypeUsb); lastTetheringTypes.add(ActivityManageTriggerTethering.tetheringTypeUsb);
else if(adapterName.contains("ndis")) else if (adapterName.contains("ndis"))
lastTetheringTypes.add(ActivityManageTriggerTethering.tetheringTypeCable); lastTetheringTypes.add(ActivityManageTriggerTethering.tetheringTypeCable);
} }
} }
@ -91,29 +97,43 @@ public class TetheringReceiver extends android.content.BroadcastReceiver impleme
// Miscellaneous.logEvent("i", "Broadcast extra", "Broadcast " + intent.getAction() + " has extra " + key + " and type " + intent.getExtras().get(key).getClass().getName(), 4); // Miscellaneous.logEvent("i", "Broadcast extra", "Broadcast " + intent.getAction() + " has extra " + key + " and type " + intent.getExtras().get(key).getClass().getName(), 4);
} }
// }
try // else if(intent.getAction().equals("android.net.conn.CONNECTIVITY_CHANGE"))
/*
DETECT BY CHECKING ALL NETWORK INTERFACES
*/
// {
/*try
{ {
for(Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); )
{ {
NetworkInterface intf = en.nextElement(); NetworkInterface intf = en.nextElement();
for(Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); )
{ {
InetAddress inetAddress = enumIpAddr.nextElement(); InetAddress inetAddress = enumIpAddr.nextElement();
if(!intf.isLoopback()) if (!intf.isLoopback())
{ {
if(intf.getName().contains("rndis")) if (intf.getName().contains("rndis"))
{ {
Miscellaneous.logEvent("i", "TetheringReceiver", "Tethering on interface " + intf.getName() + " seems to be active.", 4);
lastTetheringTypes.add(ActivityManageTriggerTethering.tetheringTypeUsb);
tetheringActive = true;
}
else if (intf.getName().contains("ndis"))
{
Miscellaneous.logEvent("i", "TetheringReceiver", "Tethering on interface " + intf.getName() + " seems to be active.", 4);
lastTetheringTypes.add(ActivityManageTriggerTethering.tetheringTypeCable);
tetheringActive = true; tetheringActive = true;
} }
} }
} }
} }
} }
catch(Exception e) catch (Exception e)
{ {
Miscellaneous.logEvent("e", "TetheringReceiver", Log.getStackTraceString(e), 1); Miscellaneous.logEvent("e", "TetheringReceiver", Log.getStackTraceString(e), 1);
} }*/
// }
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.tethering); ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.tethering);
for(int i=0; i<ruleCandidates.size(); i++) for(int i=0; i<ruleCandidates.size(); i++)
@ -137,6 +157,7 @@ public class TetheringReceiver extends android.content.BroadcastReceiver impleme
{ {
intentFilter = new IntentFilter(); intentFilter = new IntentFilter();
intentFilter.addAction("android.net.conn.TETHER_STATE_CHANGED"); intentFilter.addAction("android.net.conn.TETHER_STATE_CHANGED");
// intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
} }
try try