Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1bc5731b authored by Ajay Panicker's avatar Ajay Panicker
Browse files

Add Filtering for snoop logs based on L2CAP and RFCOMM Channels (4/4)

Snoop logs will now always exist but will be filtered by default. If
full logging is turned on then al the packets will be logged.

Bug: 112970672
Bug: 67669544
Test: See that the snoop file always exists but is filtered when
snooplogs are disabled and unfiltered when enabled and.
testSnoopLoggingChange still passes.

Change-Id: I56df2c55738a9a9469610245b319492000583334
parent 96b41123
Loading
Loading
Loading
Loading
+22 −6
Original line number Original line Diff line number Diff line
@@ -112,8 +112,11 @@ public class AdapterService extends Service {
    private static final String ACTION_ALARM_WAKEUP =
    private static final String ACTION_ALARM_WAKEUP =
            "com.android.bluetooth.btservice.action.ALARM_WAKEUP";
            "com.android.bluetooth.btservice.action.ALARM_WAKEUP";


    static final String BLUETOOTH_BTSNOOP_ENABLE_PROPERTY = "persist.bluetooth.btsnoopenable";
    static final String BLUETOOTH_BTSNOOP_LOG_MODE_PROPERTY = "persist.bluetooth.btsnooplogmode";
    private boolean mSnoopLogSettingAtEnable = false;
    static final String BLUETOOTH_BTSNOOP_DEFAULT_MODE_PROPERTY =
            "persist.bluetooth.btsnoopdefaultmode";
    private String mSnoopLogSettingAtEnable = "empty";
    private String mDefaultSnoopLogSettingAtEnable = "empty";


    public static final String BLUETOOTH_ADMIN_PERM = android.Manifest.permission.BLUETOOTH_ADMIN;
    public static final String BLUETOOTH_ADMIN_PERM = android.Manifest.permission.BLUETOOTH_ADMIN;
    public static final String BLUETOOTH_PRIVILEGED =
    public static final String BLUETOOTH_PRIVILEGED =
@@ -610,15 +613,27 @@ public class AdapterService extends Service {
            }
            }
            mCallbacks.finishBroadcast();
            mCallbacks.finishBroadcast();
        }
        }

        // Turn the Adapter all the way off if we are disabling and the snoop log setting changed.
        // Turn the Adapter all the way off if we are disabling and the snoop log setting changed.
        if (newState == BluetoothAdapter.STATE_BLE_TURNING_ON) {
        if (newState == BluetoothAdapter.STATE_BLE_TURNING_ON) {
            mSnoopLogSettingAtEnable =
            mSnoopLogSettingAtEnable =
                    SystemProperties.getBoolean(BLUETOOTH_BTSNOOP_ENABLE_PROPERTY, false);
                    SystemProperties.get(BLUETOOTH_BTSNOOP_LOG_MODE_PROPERTY, "empty");
            mDefaultSnoopLogSettingAtEnable =
                    Settings.Global.getString(getContentResolver(),
                            Settings.Global.BLUETOOTH_BTSNOOP_DEFAULT_MODE);
            SystemProperties.set(BLUETOOTH_BTSNOOP_DEFAULT_MODE_PROPERTY,
                    mDefaultSnoopLogSettingAtEnable);
        } else if (newState == BluetoothAdapter.STATE_BLE_ON
        } else if (newState == BluetoothAdapter.STATE_BLE_ON
                   && prevState != BluetoothAdapter.STATE_OFF) {
                   && prevState != BluetoothAdapter.STATE_OFF) {
            boolean snoopLogSetting =
            String snoopLogSetting =
                    SystemProperties.getBoolean(BLUETOOTH_BTSNOOP_ENABLE_PROPERTY, false);
                    SystemProperties.get(BLUETOOTH_BTSNOOP_LOG_MODE_PROPERTY, "empty");
            if (mSnoopLogSettingAtEnable != snoopLogSetting) {
            String snoopDefaultModeSetting =
                    Settings.Global.getString(getContentResolver(),
                            Settings.Global.BLUETOOTH_BTSNOOP_DEFAULT_MODE);

            if (!TextUtils.equals(mSnoopLogSettingAtEnable, snoopLogSetting)
                    || !TextUtils.equals(mDefaultSnoopLogSettingAtEnable,
                            snoopDefaultModeSetting)) {
                mAdapterStateMachine.sendMessage(AdapterState.BLE_TURN_OFF);
                mAdapterStateMachine.sendMessage(AdapterState.BLE_TURN_OFF);
            }
            }
        }
        }
@@ -2540,6 +2555,7 @@ public class AdapterService extends Service {
        writer.println();
        writer.println();
        mAdapterProperties.dump(fd, writer, args);
        mAdapterProperties.dump(fd, writer, args);
        writer.println("mSnoopLogSettingAtEnable = " + mSnoopLogSettingAtEnable);
        writer.println("mSnoopLogSettingAtEnable = " + mSnoopLogSettingAtEnable);
        writer.println("mDefaultSnoopLogSettingAtEnable = " + mDefaultSnoopLogSettingAtEnable);


        writer.println();
        writer.println();
        mAdapterStateMachine.dump(fd, writer, args);
        mAdapterStateMachine.dump(fd, writer, args);
+6 −6
Original line number Original line Diff line number Diff line
@@ -451,17 +451,17 @@ public class AdapterServiceTest {
    @Test
    @Test
    public void testSnoopLoggingChange() {
    public void testSnoopLoggingChange() {
        String snoopSetting =
        String snoopSetting =
                SystemProperties.get(AdapterService.BLUETOOTH_BTSNOOP_ENABLE_PROPERTY, "");
                SystemProperties.get(AdapterService.BLUETOOTH_BTSNOOP_LOG_MODE_PROPERTY, "");
        SystemProperties.set(AdapterService.BLUETOOTH_BTSNOOP_ENABLE_PROPERTY, "false");
        SystemProperties.set(AdapterService.BLUETOOTH_BTSNOOP_LOG_MODE_PROPERTY, "false");
        doEnable(0, false);
        doEnable(0, false);


        Assert.assertTrue(mAdapterService.isEnabled());
        Assert.assertTrue(mAdapterService.isEnabled());


        Assert.assertFalse(
        Assert.assertFalse(
                SystemProperties.getBoolean(AdapterService.BLUETOOTH_BTSNOOP_ENABLE_PROPERTY,
                SystemProperties.get(AdapterService.BLUETOOTH_BTSNOOP_LOG_MODE_PROPERTY,
                        true));
                        "true").equals("true"));


        SystemProperties.set(AdapterService.BLUETOOTH_BTSNOOP_ENABLE_PROPERTY, "true");
        SystemProperties.set(AdapterService.BLUETOOTH_BTSNOOP_LOG_MODE_PROPERTY, "true");


        mAdapterService.disable();
        mAdapterService.disable();


@@ -491,7 +491,7 @@ public class AdapterServiceTest {
        Assert.assertFalse(mAdapterService.isEnabled());
        Assert.assertFalse(mAdapterService.isEnabled());


        // Restore earlier setting
        // Restore earlier setting
        SystemProperties.set(AdapterService.BLUETOOTH_BTSNOOP_ENABLE_PROPERTY, snoopSetting);
        SystemProperties.set(AdapterService.BLUETOOTH_BTSNOOP_LOG_MODE_PROPERTY, snoopSetting);
    }
    }


    /**
    /**