BT tethering

This commit is contained in:
jens 2021-11-15 20:28:38 +01:00
parent 92ca6d6cb4
commit 17109b12d4
2 changed files with 45 additions and 21 deletions

View File

@ -349,6 +349,8 @@ public class Rule implements Comparable<Rule>
return true; return true;
case setWifiTethering: case setWifiTethering:
return true; return true;
case setBluetoothTethering:
return true;
default: default:
break; break;
} }

View File

@ -331,29 +331,37 @@ public class Actions
// if (((state && !desiredState) || (!state && desiredState))) // if (((state && !desiredState) || (!state && desiredState)))
// { // {
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
Class<?> classBluetoothPan = null; Class<?> classBluetoothPan = null;
Constructor<?> BTPanCtor = null; Constructor<?> BTPanCtor = null;
Object BTSrvInstance = null; Object BTSrvInstance = null;
Method mBTPanConnect = null; Method mBTPanConnect = null;
try String sClassName = "android.bluetooth.BluetoothPan";
try
{
classBluetoothPan = Class.forName(sClassName);
Constructor<?> ctor = classBluetoothPan.getDeclaredConstructor(Context.class, BluetoothProfile.ServiceListener.class);
ctor.setAccessible(true);
// Set Tethering ON
Class[] paramSet = new Class[1];
paramSet[0] = boolean.class;
synchronized (mutex)
{ {
classBluetoothPan = Class.forName("android.bluetooth.BluetoothPan"); setTetheringOn = classBluetoothPan.getDeclaredMethod("setBluetoothTethering", paramSet);
mBTPanConnect = classBluetoothPan.getDeclaredMethod("connect", BluetoothDevice.class); isTetheringOn = classBluetoothPan.getDeclaredMethod("isTetheringOn", null);
BTPanCtor = classBluetoothPan.getDeclaredConstructor(Context.class, BluetoothProfile.ServiceListener.class); instance = ctor.newInstance(context, new BTPanServiceListener(context));
BTPanCtor.setAccessible(true);
BTSrvInstance = BTPanCtor.newInstance(context, new BTPanServiceListener(context));
}
catch (ClassNotFoundException e)
{
Miscellaneous.logEvent("e", "Bluetooth Tethering", Log.getStackTraceString(e), 1);
}
catch (Exception e)
{
Miscellaneous.logEvent("e", "Bluetooth Tethering", Log.getStackTraceString(e), 1);
} }
classBluetoothPan = Class.forName("android.bluetooth.BluetoothPan");
mBTPanConnect = classBluetoothPan.getDeclaredMethod("connect", BluetoothDevice.class);
BTPanCtor = classBluetoothPan.getDeclaredConstructor(Context.class, BluetoothProfile.ServiceListener.class);
BTPanCtor.setAccessible(true);
BTSrvInstance = BTPanCtor.newInstance(context, new BTPanServiceListener(context));
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices(); Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
// If there are paired devices // If there are paired devices
@ -372,8 +380,22 @@ public class Actions
} }
} }
} }
// } return true;
return true; }
catch (NoSuchMethodException e)
{
Miscellaneous.logEvent("e", "Bluetooth Tethering", Log.getStackTraceString(e), 1);
}
catch (ClassNotFoundException e)
{
Miscellaneous.logEvent("e", "Bluetooth Tethering", Log.getStackTraceString(e), 1);
}
catch (Exception e)
{
Miscellaneous.logEvent("e", "Bluetooth Tethering", Log.getStackTraceString(e), 1);
}
return false;
} }
public static class BTPanServiceListener implements BluetoothProfile.ServiceListener public static class BTPanServiceListener implements BluetoothProfile.ServiceListener