tethering detection

This commit is contained in:
jens 2022-06-03 19:26:34 +02:00
parent b3ad72cc50
commit b35208b7aa
4 changed files with 64 additions and 2 deletions

View File

@ -67,6 +67,7 @@ import java.net.NetworkInterface;
import java.security.KeyStore; import java.security.KeyStore;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collections; import java.util.Collections;
import java.util.Enumeration;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -2067,4 +2068,34 @@ public class Actions
return null; return null;
} }
public static boolean isTetheringActive1(Context context)
{
try
{
for(Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();)
{
NetworkInterface intf = en.nextElement();
for(Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();)
{
InetAddress inetAddress = enumIpAddr.nextElement();
if(!intf.isLoopback())
{
if(intf.getName().contains("rndis"))
{
return true;
}
}
}
}
}
catch(Exception e)
{
Miscellaneous.logEvent("e", "isTetheringActive()", Log.getStackTraceString(e), 3);
}
return false;
}
} }

View File

@ -78,6 +78,16 @@ public class ActivityMainScreen extends ActivityGeneric
tbLockSound = (ToggleButton) findViewById(R.id.tbLockSound); tbLockSound = (ToggleButton) findViewById(R.id.tbLockSound);
toggleService = (ToggleButton) findViewById(R.id.tbArmMastListener); toggleService = (ToggleButton) findViewById(R.id.tbArmMastListener);
Button bTether = (Button)findViewById(R.id.bTethering);
bTether.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View view)
{
Toast.makeText(ActivityMainScreen.this, "Tethering active: " + String.valueOf(Actions.isTetheringActive1(ActivityMainScreen.this)), Toast.LENGTH_LONG).show();
}
});
bDonate = (Button)findViewById(R.id.bDonate); bDonate = (Button)findViewById(R.id.bDonate);
if(!BuildConfig.FLAVOR.equalsIgnoreCase(AutomationService.flavor_name_googleplay)) if(!BuildConfig.FLAVOR.equalsIgnoreCase(AutomationService.flavor_name_googleplay))

View File

@ -3,6 +3,7 @@ package com.jens.automation2.receivers;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
@ -53,8 +54,22 @@ public class BroadcastListener extends android.content.BroadcastReceiver impleme
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);
// Miscellaneous.logEvent("i", "Broadcast extra", "Broadcast " + intent.getAction() + " has extra " + key + " and type " + intent.getExtras().get(key).getClass().getName(), 4);
String target = null;
if(Build.VERSION.SDK_INT >= 26)
target = "tetherArray";
else
target = "activeArray";
if(key.equals(target) && ob instanceof ArrayList)
{
if(((ArrayList<String>)ob).size() > 0)
;
}
Miscellaneous.logEvent("i", "Broadcast extra", "Broadcast " + intent.getAction() + " has extra " + key + " and type " + intent.getExtras().get(key).getClass().getName(), 4);
} }
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.broadcastReceived); ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.broadcastReceived);

View File

@ -339,6 +339,12 @@
android:layout_marginTop="30dp" android:layout_marginTop="30dp"
android:gravity="center_horizontal" > android:gravity="center_horizontal" >
<Button
android:id="@+id/bTethering"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/test" />
<Button <Button
android:id="@+id/bShowHelp" android:id="@+id/bShowHelp"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"