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

Commit d983741f authored by Aditi Katragadda's avatar Aditi Katragadda Committed by Android (Google) Code Review
Browse files

Merge "Enable Bluetooth stack logging from Developer Options UI Element" into main

parents 0003443c 5c98e0fb
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -232,6 +232,23 @@


    <!-- Bluetooth Settings -->
    <!-- Titles for Bluetooth Stack Logging -->
    <string-array name="bt_stack_log_level_entries">
        <item>Verbose</item>
        <item>Debug</item>
        <item>Info</item>
        <item>Warn</item>
        <item>Error</item>
    </string-array>

    <!-- Values for Bluetooth Stack Logging -->
    <string-array name="bt_stack_log_level_values" translatable="false">
        <item>verbose</item>
        <item>debug</item>
        <item>info</item>
        <item>warn</item>
        <item>error</item>
    </string-array>

    <!-- Bluetooth developer settings: Bluetooth LE Audio modes -->
    <string-array name="bluetooth_leaudio_mode">
+4 −0
Original line number Diff line number Diff line
@@ -4676,6 +4676,10 @@
    <string name="experimental_category_title">Experimental</string>
    <!-- Title for feature flags dashboard where developers can turn on experimental features [CHAR LIMIT=50] -->
    <string name="feature_flags_dashboard_title">Feature flags</string>
    <!-- Setting Checkbox title whether to enable Bluetooth stack log -->
    <string name="bt_stack_log_level">Enable Bluetooth stack log</string>
    <!-- setting Checkbox summary to set log level [CHAR_LIMIT=100] -->
    <string name="bt_stack_log_level_summary">Change log level of Bluetooth Stack Logging (Toggle Bluetooth after changing this setting)</string>
    <!-- Title for snoop logger filters dashboard where developers can turn on filters [CHAR LIMIT=100] -->
    <string name="bt_hci_snoop_log_filters_dashboard_title">Bluetooth HCI snoop log filtering</string>
    <!-- Summary for the snoop logger filters [CHAR LIMIT=100] -->
+7 −0
Original line number Diff line number Diff line
@@ -74,6 +74,13 @@
            android:entries="@array/hdcp_checking_titles"
            android:entryValues="@array/hdcp_checking_values" />

        <ListPreference
            android:key="bt_stack_log_level"
            android:title="@string/bt_stack_log_level"
            android:dialogTitle="@string/bt_stack_log_level_summary"
            android:entries="@array/bt_stack_log_level_entries"
            android:entryValues="@array/bt_stack_log_level_values" />

        <ListPreference
            android:key="bt_hci_snoop_log"
            android:title="@string/bt_hci_snoop_log"
+2 −0
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ import com.android.settings.development.bluetooth.BluetoothCodecDialogPreference
import com.android.settings.development.bluetooth.BluetoothHDAudioPreferenceController;
import com.android.settings.development.bluetooth.BluetoothQualityDialogPreferenceController;
import com.android.settings.development.bluetooth.BluetoothSampleRateDialogPreferenceController;
import com.android.settings.development.bluetooth.BluetoothStackLogPreferenceController;
import com.android.settings.development.graphicsdriver.GraphicsDriverEnableAngleAsSystemDriverController;
import com.android.settings.development.qstile.DevelopmentTiles;
import com.android.settings.development.storage.SharedDataPreferenceController;
@@ -637,6 +638,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
        controllers.add(new StayAwakePreferenceController(context, lifecycle));
        controllers.add(new HdcpCheckingPreferenceController(context));
        controllers.add(new BluetoothSnoopLogPreferenceController(context, fragment));
        controllers.add(new BluetoothStackLogPreferenceController(context));
        controllers.add(new DefaultLaunchPreferenceController(context,
                "snoop_logger_filters_dashboard"));
        controllers.add(new BluetoothSnoopLogFilterProfilePbapPreferenceController(context));
+114 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.development.bluetooth;

import android.content.Context;
import android.os.SystemProperties;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.preference.ListPreference;
import androidx.preference.Preference;

import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;

public class BluetoothStackLogPreferenceController extends DeveloperOptionsPreferenceController
        implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {

    /* Ensure that the indexes match with bt_stack_log_values and bt_stack_log_entries ordering */
    private static final String PREFERENCE_KEY = "bt_stack_log_level";
    @VisibleForTesting static final int BTSTACK_LOG_MODE_VERBOSE_INDEX = 0;
    @VisibleForTesting static final int BTSTACK_LOG_MODE_DEBUG_INDEX = 1;
    @VisibleForTesting static final int BTSTACK_LOG_MODE_INFO_INDEX = 2;
    @VisibleForTesting static final int BTSTACK_LOG_MODE_WARN_INDEX = 3;
    @VisibleForTesting static final int BTSTACK_LOG_MODE_ERROR_INDEX = 4;

    @VisibleForTesting
    static final String BLUETOOTH_BTSTACK_LOG_MODE_PROPERTY_PERSIST = "persist.log.tag.bluetooth";
    static final String BLUETOOTH_BTSTACK_LOG_MODE_PROPERTY = "log.tag.bluetooth";
    static final String BLUETOOTH_STRING_NAME = "bluetooth";
    static final int DEFAULT_MODE = BTSTACK_LOG_MODE_INFO_INDEX;

    private final String[] mListValues;
    private final String[] mListEntries;


    public BluetoothStackLogPreferenceController(@NonNull Context context) {
        super(context);
        mListValues = context.getResources().getStringArray(R.array.bt_stack_log_level_values);
        mListEntries = context.getResources().getStringArray(R.array.bt_stack_log_level_entries);
    }

    /** returns default log level index of INFO */
    public int getDefaultModeIndex() {
        return DEFAULT_MODE;
    }

    @Override
    @Nullable
    public String getPreferenceKey() {
        return PREFERENCE_KEY;
    }

    @Override
    public boolean onPreferenceChange(@NonNull Preference preference, @NonNull Object newValue) {
        SystemProperties.set(BLUETOOTH_BTSTACK_LOG_MODE_PROPERTY_PERSIST, newValue.toString());
        SystemProperties.set(BLUETOOTH_BTSTACK_LOG_MODE_PROPERTY, newValue.toString());
        updateState(mPreference);
        return true;
    }

    @Override
    public void updateState(@NonNull Preference preference) {
        final ListPreference listPreference = (ListPreference) preference;
        int index = getBluetoothLogLevelIndex();
        listPreference.setValue(mListValues[index]);
        listPreference.setSummary(mListEntries[index]);
    }

    /**
     *  Returns the current log level from Log.isLoggable().
     */
    @VisibleForTesting
    public int getBluetoothLogLevelIndex() {
        if (Log.isLoggable(BLUETOOTH_STRING_NAME, Log.VERBOSE)) {
            return BTSTACK_LOG_MODE_VERBOSE_INDEX;
        } else if (Log.isLoggable(BLUETOOTH_STRING_NAME, Log.DEBUG)) {
            return BTSTACK_LOG_MODE_DEBUG_INDEX;
        } else if (Log.isLoggable(BLUETOOTH_STRING_NAME, Log.INFO)) {
            return BTSTACK_LOG_MODE_INFO_INDEX;
        } else if (Log.isLoggable(BLUETOOTH_STRING_NAME, Log.WARN)) {
            return BTSTACK_LOG_MODE_WARN_INDEX;
        } else if (Log.isLoggable(BLUETOOTH_STRING_NAME, Log.ERROR)) {
            return BTSTACK_LOG_MODE_ERROR_INDEX;
        }
        return BTSTACK_LOG_MODE_INFO_INDEX;
    }

    @Override
    protected void onDeveloperOptionsSwitchDisabled() {
        super.onDeveloperOptionsSwitchDisabled();
        SystemProperties.set(BLUETOOTH_BTSTACK_LOG_MODE_PROPERTY_PERSIST, null);
        SystemProperties.set(BLUETOOTH_BTSTACK_LOG_MODE_PROPERTY, null);
        ((ListPreference) mPreference).setValue(mListValues[getDefaultModeIndex()]);
        ((ListPreference) mPreference).setSummary(mListEntries[getDefaultModeIndex()]);
    }
}
Loading