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.AutomationService; import com.jens.automation2.Miscellaneous; import com.jens.automation2.Rule; import com.jens.automation2.Trigger; import java.util.ArrayList; 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 boolean tetheringActive = false; 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; 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