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

Commit bd2f353f authored by Jakub Rotkiewicz's avatar Jakub Rotkiewicz Committed by Automerger Merge Worker
Browse files

Merge "SnoopLogger: Debug enhancements added settings" am: cfde422f

parents 016f304b cfde422f
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -5426,6 +5426,18 @@
    <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>
    <!-- Title for snoop logger filters dashboard where developers can turn on filters [CHAR LIMIT=50] -->
    <string name="snoop_logger_filters_dashboard_title">Snoop Logger Filters</string>
    <!-- Summary for the snoop logger filters [CHAR LIMIT=50] -->
    <string name="bt_hci_snoop_log_filters_dashboard_summary">Set filters (Toggle Bluetooth after changing this setting)</string>
    <!-- Title for the snoop logger pbap filter [CHAR LIMIT=50] -->
    <string name="bt_hci_snoop_log_filter_pbap_title">Snoop Logger Filter PBAP</string>
    <!-- Title for the snoop logger map filter [CHAR LIMIT=50] -->
    <string name="bt_hci_snoop_log_filter_map_title">Snoop Logger Filter MAP</string>
    <!-- Summary for the snoop logger filters [CHAR LIMIT=50] -->
    <string name="bt_hci_snoop_log_filter_summary">Set filtering mode. (Toggle Bluetooth after changing this setting)</string>
    <!-- Summary for the snoop logger profile filters while disabled [CHAR LIMIT=50] -->
    <string name="bt_hci_snoop_log_filtered_mode_disabled_summary">Enable Snoop Log Mode Filtered to change this option.</string>
    <!-- Title for the Talkback Accessibility Service. Displayed on the Accessibility Settings screen in Setup Wizard. [CHAR_LIMIT=25] -->
    <string name="talkback_title">Talkback</string>
    <!-- Summary for the Talkback Accessibility Service. Lets the user know that Talkback is a screenreader and that it is usually most helpful to blind and low vision users and whether the service is on. [CHAR_LIMIT=none] -->
+20 −0
Original line number Diff line number Diff line
@@ -80,6 +80,26 @@
            android:entries="@array/bt_hci_snoop_log_entries"
            android:entryValues="@array/bt_hci_snoop_log_values" />

        <Preference
            android:key="snoop_logger_filters_dashboard"
            android:title="@string/snoop_logger_filters_dashboard_title"
            android:fragment=
                "com.android.settings.development.snooplogger.SnoopLoggerFiltersDashboard" />

        <ListPreference
            android:key="bt_hci_snoop_log_filter_pbap"
            android:title="@string/bt_hci_snoop_log_filter_pbap_title"
            android:dialogTitle="@string/bt_hci_snoop_log_filter_summary"
            android:entries="@array/bt_hci_snoop_log_profile_filter_entries"
            android:entryValues="@array/bt_hci_snoop_log_profile_filter_values" />

        <ListPreference
            android:key="bt_hci_snoop_log_filter_map"
            android:title="@string/bt_hci_snoop_log_filter_map_title"
            android:dialogTitle="@string/bt_hci_snoop_log_filter_summary"
            android:entries="@array/bt_hci_snoop_log_profile_filter_entries"
            android:entryValues="@array/bt_hci_snoop_log_profile_filter_values" />

        <com.android.settingslib.RestrictedSwitchPreference
            android:key="oem_unlock_enable"
            android:title="@string/oem_unlock_enable"
+29 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  Copyright (C) 2022 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.
  -->

<PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:settings="http://schemas.android.com/apk/res-auto"
    android:title="@string/snoop_logger_filters_dashboard_title" >

    <PreferenceCategory
        android:key="snoop_logger_filters_category"
        android:layout="@layout/preference_category_no_label"
        android:title="@string/bt_hci_snoop_log_filters_dashboard_summary"
        settings:controller=
          "com.android.settings.development.snooplogger.SnoopLoggerFiltersPreferenceController" />
</PreferenceScreen>
+137 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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;

import android.content.Context;
import android.sysprop.BluetoothProperties;

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;

import java.util.Locale;

/** Bluetooth Snoop Logger Map Profile Filter Preference Controller */
public class BluetoothSnoopLogFilterProfileMapPreferenceController
        extends DeveloperOptionsPreferenceController
        implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {

    private static final String TAG = "BluetoothSnoopLogFilterProfileMapPreferenceController";
    private static final String PREFERENCE_KEY = "bt_hci_snoop_log_filter_map";
    @VisibleForTesting static final int BTSNOOP_LOG_PROFILE_FILTER_MODE_DISABLED_INDEX = 0;
    @VisibleForTesting static final int BTSNOOP_LOG_PROFILE_FILTER_MODE_MAGIC_INDEX = 1;
    @VisibleForTesting static final int BTSNOOP_LOG_PROFILE_FILTER_MODE_HEADER_INDEX = 2;
    @VisibleForTesting static final int BTSNOOP_LOG_PROFILE_FILTER_MODE_FULL_FILTER_INDEX = 3;

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

    @VisibleForTesting
    static boolean isSnoopLogModeFilteredEnabled() {
        return (BluetoothProperties.snoop_log_mode()
                        .orElse(BluetoothProperties.snoop_log_mode_values.DISABLED)
                == BluetoothProperties.snoop_log_mode_values.FILTERED);
    }

    public BluetoothSnoopLogFilterProfileMapPreferenceController(Context context) {
        super(context);
        mListValues =
                context.getResources()
                        .getStringArray(R.array.bt_hci_snoop_log_profile_filter_values);
        mListEntries =
                context.getResources()
                        .getStringArray(R.array.bt_hci_snoop_log_profile_filter_entries);
        mProfilesFilterDisabledEntry =
                context.getResources()
                        .getString(R.string.bt_hci_snoop_log_filtered_mode_disabled_summary);
    }

    // Default mode is DISABLED.
    public int getDefaultModeIndex() {
        return BTSNOOP_LOG_PROFILE_FILTER_MODE_DISABLED_INDEX;
    }

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

    @Override
    public boolean onPreferenceChange(Preference preference, Object newValue) {
        BluetoothProperties.snoop_log_filter_profile_map(
                BluetoothProperties.snoop_log_filter_profile_map_values.valueOf(
                        newValue.toString().toUpperCase(Locale.US)));
        updateState(mPreference);
        return true;
    }

    @Override
    public void updateState(Preference preference) {
        super.updateState(preference);
        final ListPreference listPreference = (ListPreference) preference;
        if (isSnoopLogModeFilteredEnabled()) {
            mPreference.setEnabled(true);

            BluetoothProperties.snoop_log_filter_profile_map_values currentValue =
                    BluetoothProperties.snoop_log_filter_profile_map()
                            .orElse(
                                    BluetoothProperties.snoop_log_filter_profile_map_values
                                            .DISABLED);

            int index = getDefaultModeIndex();
            for (int i = 0; i < mListValues.length; i++) {
                if (currentValue
                        == BluetoothProperties.snoop_log_filter_profile_map_values.valueOf(
                                mListValues[i].toUpperCase(Locale.US))) {
                    index = i;
                    break;
                }
            }
            listPreference.setValue(mListValues[index]);
            listPreference.setSummary(mListEntries[index]);
        } else {
            mPreference.setEnabled(false);
            listPreference.setSummary(mProfilesFilterDisabledEntry);
        }
    }

    /** Called when the Bluetooth Snoop Log Mode changes. */
    public void onSettingChanged() {
        updateState(mPreference);
    }

    @Override
    protected void onDeveloperOptionsSwitchEnabled() {
        super.onDeveloperOptionsSwitchEnabled();
        mPreference.setEnabled(isSnoopLogModeFilteredEnabled());
    }

    @Override
    protected void onDeveloperOptionsSwitchDisabled() {
        super.onDeveloperOptionsSwitchDisabled();
        BluetoothProperties.snoop_log_filter_profile_map(
                BluetoothProperties.snoop_log_filter_profile_map_values.DISABLED);
        ((ListPreference) mPreference).setValue(mListValues[getDefaultModeIndex()]);
        ((ListPreference) mPreference).setSummary(mListEntries[getDefaultModeIndex()]);
        mPreference.setEnabled(false);
    }
}
+136 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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;

import android.content.Context;
import android.sysprop.BluetoothProperties;

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;

import java.util.Locale;

/** Bluetooth Snoop Logger Pbap Profile Filter Preference Controller */
public class BluetoothSnoopLogFilterProfilePbapPreferenceController
        extends DeveloperOptionsPreferenceController
        implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {

    private static final String TAG = "BluetoothSnoopLogFilterProfilePbapPreferenceController";
    private static final String PREFERENCE_KEY = "bt_hci_snoop_log_filter_pbap";
    @VisibleForTesting static final int BTSNOOP_LOG_PROFILE_FILTER_MODE_DISABLED_INDEX = 0;
    @VisibleForTesting static final int BTSNOOP_LOG_PROFILE_FILTER_MODE_MAGIC_INDEX = 1;
    @VisibleForTesting static final int BTSNOOP_LOG_PROFILE_FILTER_MODE_HEADER_INDEX = 2;
    @VisibleForTesting static final int BTSNOOP_LOG_PROFILE_FILTER_MODE_FULL_FILTER_INDEX = 3;

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

    @VisibleForTesting
    static boolean isSnoopLogModeFilteredEnabled() {
        return (BluetoothProperties.snoop_log_mode()
                        .orElse(BluetoothProperties.snoop_log_mode_values.DISABLED)
                == BluetoothProperties.snoop_log_mode_values.FILTERED);
    }

    public BluetoothSnoopLogFilterProfilePbapPreferenceController(Context context) {
        super(context);
        mListValues =
                context.getResources()
                        .getStringArray(R.array.bt_hci_snoop_log_profile_filter_values);
        mListEntries =
                context.getResources()
                        .getStringArray(R.array.bt_hci_snoop_log_profile_filter_entries);
        mProfilesFilterDisabledEntry =
                context.getResources()
                        .getString(R.string.bt_hci_snoop_log_filtered_mode_disabled_summary);
    }

    // Default mode is DISABLED.
    public int getDefaultModeIndex() {
        return BTSNOOP_LOG_PROFILE_FILTER_MODE_DISABLED_INDEX;
    }

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

    @Override
    public boolean onPreferenceChange(Preference preference, Object newValue) {
        BluetoothProperties.snoop_log_filter_profile_pbap(
                BluetoothProperties.snoop_log_filter_profile_pbap_values.valueOf(
                        newValue.toString().toUpperCase(Locale.US)));
        updateState(mPreference);
        return true;
    }

    @Override
    public void updateState(Preference preference) {
        super.updateState(preference);
        final ListPreference listPreference = (ListPreference) preference;
        if (isSnoopLogModeFilteredEnabled()) {
            mPreference.setEnabled(true);
            BluetoothProperties.snoop_log_filter_profile_pbap_values currentValue =
                    BluetoothProperties.snoop_log_filter_profile_pbap()
                            .orElse(
                                    BluetoothProperties.snoop_log_filter_profile_pbap_values
                                            .DISABLED);

            int index = getDefaultModeIndex();
            for (int i = 0; i < mListValues.length; i++) {
                if (currentValue
                        == BluetoothProperties.snoop_log_filter_profile_pbap_values.valueOf(
                                mListValues[i].toUpperCase(Locale.US))) {
                    index = i;
                    break;
                }
            }
            listPreference.setValue(mListValues[index]);
            listPreference.setSummary(mListEntries[index]);
        } else {
            mPreference.setEnabled(false);
            listPreference.setSummary(mProfilesFilterDisabledEntry);
        }
    }

    /** Called when the Bluetooth Snoop Log Mode changes. */
    public void onSettingChanged() {
        updateState(mPreference);
    }

    @Override
    protected void onDeveloperOptionsSwitchEnabled() {
        super.onDeveloperOptionsSwitchEnabled();
        mPreference.setEnabled(isSnoopLogModeFilteredEnabled());
    }

    @Override
    protected void onDeveloperOptionsSwitchDisabled() {
        super.onDeveloperOptionsSwitchDisabled();
        BluetoothProperties.snoop_log_filter_profile_pbap(
                BluetoothProperties.snoop_log_filter_profile_pbap_values.DISABLED);
        ((ListPreference) mPreference).setValue(mListValues[getDefaultModeIndex()]);
        ((ListPreference) mPreference).setSummary(mListEntries[getDefaultModeIndex()]);
        mPreference.setEnabled(false);
    }
}
Loading