package com.jens.automation2.receivers; import android.content.Context; import android.content.Intent; 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; import com.jens.automation2.Trigger; import java.util.ArrayList; import java.util.List; public class TetheringReceiver extends android.content.BroadcastReceiver implements AutomationListenerInterface { public static AutomationService automationServiceRef = null; private static boolean receiverActive = false; private static TetheringReceiver receiverInstance = null; private static IntentFilter intentFilter = null; private static List lastTetheringTypes = null; private static boolean tetheringActive = false; public static List getLastTetheringTypes() { return lastTetheringTypes; } public static TetheringReceiver getInstance() { if(receiverInstance == null) receiverInstance = new TetheringReceiver(); return receiverInstance; } public static boolean isTetheringActive() { return tetheringActive; } @Override public void onReceive(Context context, Intent intent) { 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); Object ob = intent.getExtras().get(key); String target = null; if(Build.VERSION.SDK_INT >= 26) target = "tetherArray"; else target = "activeArray"; if(key.equals(target) && ob instanceof ArrayList) { if(((ArrayList)ob).size() > 0) { tetheringActive = true; if(lastTetheringTypes == null) lastTetheringTypes = new ArrayList<>(); else lastTetheringTypes.clear(); for(String adapterName : (ArrayList)ob) { 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 tetheringActive = false; } // Miscellaneous.logEvent("i", "Broadcast extra", "Broadcast " + intent.getAction() + " has extra " + key + " and type " + intent.getExtras().get(key).getClass().getName(), 4); } ArrayList ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.tethering); for(int i=0; i