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

Commit 39629df4 authored by Jakub Rotkiewicz's avatar Jakub Rotkiewicz
Browse files

SnoopLogger: Reset after bluetooth toggling

Now after choosing filters, toggling bluetooth applies the changes and
allows full restart of SnoopLogger.

Bug: 247859568
Tag: #feature
Test: manual: restart bluetooth after switching filtering options
BYPASS_LONG_LINES_REASON: Bluetooth likes 120 lines

Change-Id: I714d7cef5d864c722b80e02b44a91f957b5c61a2
parent 76daa966
Loading
Loading
Loading
Loading
+61 −18
Original line number Diff line number Diff line
@@ -90,7 +90,6 @@ import android.os.PowerManager;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.DeviceConfig;
@@ -198,11 +197,18 @@ public class AdapterService extends Service {
    private static final String ACTION_ALARM_WAKEUP =
            "com.android.bluetooth.btservice.action.ALARM_WAKEUP";

    static final String BLUETOOTH_BTSNOOP_LOG_MODE_PROPERTY = "persist.bluetooth.btsnooplogmode";
    static final String BLUETOOTH_BTSNOOP_DEFAULT_MODE_PROPERTY =
            "persist.bluetooth.btsnoopdefaultmode";
    private String mSnoopLogSettingAtEnable = "empty";
    private String mDefaultSnoopLogSettingAtEnable = "empty";
    private static BluetoothProperties.snoop_log_mode_values sSnoopLogSettingAtEnable =
            BluetoothProperties.snoop_log_mode_values.EMPTY;
    private static String sDefaultSnoopLogSettingAtEnable = "empty";
    private static Boolean sSnoopLogFilterHeadersSettingAtEnable = false;
    private static Boolean sSnoopLogFilterProfileA2dpSettingAtEnable = false;
    private static Boolean sSnoopLogFilterProfileRfcommSettingAtEnable = false;
    private static BluetoothProperties.snoop_log_filter_profile_pbap_values
            sSnoopLogFilterProfilePbapModeSettingAtEnable =
                    BluetoothProperties.snoop_log_filter_profile_pbap_values.EMPTY;
    private static BluetoothProperties.snoop_log_filter_profile_map_values
            sSnoopLogFilterProfileMapModeSettingAtEnable =
                    BluetoothProperties.snoop_log_filter_profile_map_values.EMPTY;

    public static final String BLUETOOTH_PRIVILEGED =
            android.Manifest.permission.BLUETOOTH_PRIVILEGED;
@@ -819,30 +825,67 @@ public class AdapterService extends Service {

        // Turn the Adapter all the way off if we are disabling and the snoop log setting changed.
        if (newState == BluetoothAdapter.STATE_BLE_TURNING_ON) {
            mSnoopLogSettingAtEnable =
                    SystemProperties.get(BLUETOOTH_BTSNOOP_LOG_MODE_PROPERTY, "empty");
            mDefaultSnoopLogSettingAtEnable =
            sSnoopLogSettingAtEnable = BluetoothProperties.snoop_log_mode()
                    .orElse(BluetoothProperties.snoop_log_mode_values.EMPTY);
            sDefaultSnoopLogSettingAtEnable =
                    Settings.Global.getString(getContentResolver(),
                            Settings.Global.BLUETOOTH_BTSNOOP_DEFAULT_MODE);

            sSnoopLogFilterHeadersSettingAtEnable =
                    BluetoothProperties.snoop_log_filter_snoop_headers_enabled().orElse(false);
            sSnoopLogFilterProfileA2dpSettingAtEnable =
                    BluetoothProperties.snoop_log_filter_profile_a2dp_enabled().orElse(false);
            sSnoopLogFilterProfileRfcommSettingAtEnable =
                    BluetoothProperties.snoop_log_filter_profile_rfcomm_enabled().orElse(false);
            sSnoopLogFilterProfilePbapModeSettingAtEnable =
                    BluetoothProperties.snoop_log_filter_profile_pbap()
                    .orElse(BluetoothProperties.snoop_log_filter_profile_pbap_values.EMPTY);
            sSnoopLogFilterProfileMapModeSettingAtEnable =
                    BluetoothProperties.snoop_log_filter_profile_map()
                    .orElse(BluetoothProperties.snoop_log_filter_profile_map_values.EMPTY);

            BluetoothProperties.snoop_default_mode(
                    BluetoothProperties.snoop_default_mode_values.DISABLED);
            for (BluetoothProperties.snoop_default_mode_values value :
                    BluetoothProperties.snoop_default_mode_values.values()) {
                if (value.getPropValue().equals(mDefaultSnoopLogSettingAtEnable)) {
                if (value.getPropValue().equals(sDefaultSnoopLogSettingAtEnable)) {
                    BluetoothProperties.snoop_default_mode(value);
                }
            }
        } else if (newState == BluetoothAdapter.STATE_BLE_ON
                   && prevState != BluetoothAdapter.STATE_OFF) {
            String snoopLogSetting =
                    SystemProperties.get(BLUETOOTH_BTSNOOP_LOG_MODE_PROPERTY, "empty");
            String snoopDefaultModeSetting =
            var snoopLogSetting = BluetoothProperties.snoop_log_mode()
                    .orElse(BluetoothProperties.snoop_log_mode_values.EMPTY);
            var snoopDefaultModeSetting =
                    Settings.Global.getString(getContentResolver(),
                            Settings.Global.BLUETOOTH_BTSNOOP_DEFAULT_MODE);

            if (!TextUtils.equals(mSnoopLogSettingAtEnable, snoopLogSetting)
                    || !TextUtils.equals(mDefaultSnoopLogSettingAtEnable,
                            snoopDefaultModeSetting)) {
            var snoopLogFilterHeadersSettingAtEnable =
                    BluetoothProperties.snoop_log_filter_snoop_headers_enabled().orElse(false);
            var snoopLogFilterProfileA2dpSettingAtEnable =
                    BluetoothProperties.snoop_log_filter_profile_a2dp_enabled().orElse(false);
            var snoopLogFilterProfileRfcommSettingAtEnable =
                    BluetoothProperties.snoop_log_filter_profile_rfcomm_enabled().orElse(false);

            var snoopLogFilterProfilePbapModeSetting =
                    BluetoothProperties.snoop_log_filter_profile_pbap()
                    .orElse(BluetoothProperties.snoop_log_filter_profile_pbap_values.EMPTY);
            var snoopLogFilterProfileMapModeSetting =
                    BluetoothProperties.snoop_log_filter_profile_map()
                    .orElse(BluetoothProperties.snoop_log_filter_profile_map_values.EMPTY);

            if (!(sSnoopLogSettingAtEnable == snoopLogSetting)
                    || !(sDefaultSnoopLogSettingAtEnable == snoopDefaultModeSetting)
                    || !(sSnoopLogFilterHeadersSettingAtEnable
                            == snoopLogFilterHeadersSettingAtEnable)
                    || !(sSnoopLogFilterProfileA2dpSettingAtEnable
                            == snoopLogFilterProfileA2dpSettingAtEnable)
                    || !(sSnoopLogFilterProfileRfcommSettingAtEnable
                            == snoopLogFilterProfileRfcommSettingAtEnable)
                    || !(sSnoopLogFilterProfilePbapModeSettingAtEnable
                            == snoopLogFilterProfilePbapModeSetting)
                    || !(sSnoopLogFilterProfileMapModeSettingAtEnable
                            == snoopLogFilterProfileMapModeSetting)) {
                mAdapterStateMachine.sendMessage(AdapterState.BLE_TURN_OFF);
            }
        }
@@ -5760,8 +5803,8 @@ public class AdapterService extends Service {

        writer.println();
        mAdapterProperties.dump(fd, writer, args);
        writer.println("mSnoopLogSettingAtEnable = " + mSnoopLogSettingAtEnable);
        writer.println("mDefaultSnoopLogSettingAtEnable = " + mDefaultSnoopLogSettingAtEnable);
        writer.println("sSnoopLogSettingAtEnable = " + sSnoopLogSettingAtEnable);
        writer.println("sDefaultSnoopLogSettingAtEnable = " + sDefaultSnoopLogSettingAtEnable);

        writer.println();
        writer.println("Enabled Profile Services:");
+3 −3
Original line number Diff line number Diff line
@@ -42,7 +42,6 @@ import android.os.Looper;
import android.os.PowerManager;
import android.os.Process;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManager;
import android.permission.PermissionCheckerManager;
@@ -666,8 +665,9 @@ public class AdapterServiceTest {
        Assert.assertTrue(mAdapterService.getState() == BluetoothAdapter.STATE_ON);

        Assert.assertFalse(
                SystemProperties.get(AdapterService.BLUETOOTH_BTSNOOP_LOG_MODE_PROPERTY,
                        "full").equals("full"));
                (BluetoothProperties.snoop_log_mode()
                                .orElse(BluetoothProperties.snoop_log_mode_values.EMPTY))
                        .equals(BluetoothProperties.snoop_log_mode_values.FULL));

        BluetoothProperties.snoop_log_mode(BluetoothProperties.snoop_log_mode_values.FULL);