SnoopLogger: Debug enhancements added settings
Bug: 247859568 Tag: #feature Test: make RunSettingsRoboTests3 Test: make RunSettingsRoboTests4 Change-Id: I132a1558ea67400d9c10dda523456f99eb815b92 Merged-In: I132a1558ea67400d9c10dda523456f99eb815b92
This commit is contained in:
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
}
|
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Interface for BluetoothSnoopLogPreferenceController callbacks.
|
||||
*/
|
||||
public interface BluetoothSnoopLogHost {
|
||||
|
||||
/**
|
||||
* Called when the Bluetooth Snoop Log Mode changes.
|
||||
*/
|
||||
void onSettingChanged();
|
||||
}
|
@@ -22,12 +22,9 @@ import android.os.SystemProperties;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
@@ -37,22 +34,23 @@ public class BluetoothSnoopLogPreferenceController extends DeveloperOptionsPrefe
|
||||
implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
|
||||
|
||||
private static final String PREFERENCE_KEY = "bt_hci_snoop_log";
|
||||
@VisibleForTesting
|
||||
static final int BTSNOOP_LOG_MODE_DISABLED_INDEX = 0;
|
||||
@VisibleForTesting
|
||||
static final int BTSNOOP_LOG_MODE_FILTERED_INDEX = 1;
|
||||
@VisibleForTesting
|
||||
static final int BTSNOOP_LOG_MODE_FULL_INDEX = 2;
|
||||
@VisibleForTesting static final int BTSNOOP_LOG_MODE_DISABLED_INDEX = 0;
|
||||
@VisibleForTesting static final int BTSNOOP_LOG_MODE_FILTERED_INDEX = 1;
|
||||
@VisibleForTesting static final int BTSNOOP_LOG_MODE_FULL_INDEX = 2;
|
||||
|
||||
@VisibleForTesting
|
||||
static final String BLUETOOTH_BTSNOOP_LOG_MODE_PROPERTY = "persist.bluetooth.btsnooplogmode";
|
||||
|
||||
private final String[] mListValues;
|
||||
private final String[] mListEntries;
|
||||
private DevelopmentSettingsDashboardFragment mFragment;
|
||||
|
||||
public BluetoothSnoopLogPreferenceController(Context context) {
|
||||
public BluetoothSnoopLogPreferenceController(
|
||||
Context context, DevelopmentSettingsDashboardFragment fragment) {
|
||||
super(context);
|
||||
mListValues = context.getResources().getStringArray(R.array.bt_hci_snoop_log_values);
|
||||
mListEntries = context.getResources().getStringArray(R.array.bt_hci_snoop_log_entries);
|
||||
mFragment = fragment;
|
||||
}
|
||||
|
||||
// Default mode is DISABLED. It can also be changed by modifying the global setting.
|
||||
@@ -61,8 +59,10 @@ public class BluetoothSnoopLogPreferenceController extends DeveloperOptionsPrefe
|
||||
return BTSNOOP_LOG_MODE_DISABLED_INDEX;
|
||||
}
|
||||
|
||||
final String default_mode = Settings.Global.getString(mContext.getContentResolver(),
|
||||
Settings.Global.BLUETOOTH_BTSNOOP_DEFAULT_MODE);
|
||||
final String default_mode =
|
||||
Settings.Global.getString(
|
||||
mContext.getContentResolver(),
|
||||
Settings.Global.BLUETOOTH_BTSNOOP_DEFAULT_MODE);
|
||||
|
||||
for (int i = 0; i < mListValues.length; i++) {
|
||||
if (TextUtils.equals(default_mode, mListValues[i])) {
|
||||
@@ -82,6 +82,9 @@ public class BluetoothSnoopLogPreferenceController extends DeveloperOptionsPrefe
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
SystemProperties.set(BLUETOOTH_BTSNOOP_LOG_MODE_PROPERTY, newValue.toString());
|
||||
updateState(mPreference);
|
||||
if (mFragment != null) {
|
||||
mFragment.onSettingChanged();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -81,7 +81,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
|
||||
implements OnMainSwitchChangeListener, OemUnlockDialogHost, AdbDialogHost,
|
||||
AdbClearKeysDialogHost, LogPersistDialogHost,
|
||||
BluetoothRebootDialog.OnRebootDialogListener,
|
||||
AbstractBluetoothPreferenceController.Callback {
|
||||
AbstractBluetoothPreferenceController.Callback, BluetoothSnoopLogHost {
|
||||
|
||||
private static final String TAG = "DevSettingsDashboard";
|
||||
|
||||
@@ -395,6 +395,18 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
|
||||
leAudioFeatureController.onRebootDialogCanceled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSettingChanged() {
|
||||
final BluetoothSnoopLogFilterProfileMapPreferenceController controllerMap =
|
||||
getDevelopmentOptionsController(
|
||||
BluetoothSnoopLogFilterProfileMapPreferenceController.class);
|
||||
final BluetoothSnoopLogFilterProfilePbapPreferenceController controllerPbap =
|
||||
getDevelopmentOptionsController(
|
||||
BluetoothSnoopLogFilterProfilePbapPreferenceController.class);
|
||||
controllerMap.onSettingChanged();
|
||||
controllerPbap.onSettingChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
boolean handledResult = false;
|
||||
@@ -513,7 +525,11 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
|
||||
controllers.add(new LocalBackupPasswordPreferenceController(context));
|
||||
controllers.add(new StayAwakePreferenceController(context, lifecycle));
|
||||
controllers.add(new HdcpCheckingPreferenceController(context));
|
||||
controllers.add(new BluetoothSnoopLogPreferenceController(context));
|
||||
controllers.add(new BluetoothSnoopLogPreferenceController(context, fragment));
|
||||
controllers.add(new DefaultLaunchPreferenceController(context,
|
||||
"snoop_logger_filters_dashboard"));
|
||||
controllers.add(new BluetoothSnoopLogFilterProfilePbapPreferenceController(context));
|
||||
controllers.add(new BluetoothSnoopLogFilterProfileMapPreferenceController(context));
|
||||
controllers.add(new OemUnlockPreferenceController(context, activity, fragment));
|
||||
controllers.add(new PictureColorModePreferenceController(context, lifecycle));
|
||||
controllers.add(new WebViewAppPreferenceController(context));
|
||||
|
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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.snooplogger;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.provider.SearchIndexableResource;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.development.DevelopmentSettingsEnabler;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Bluetooth Snoop Logger Filters Dashboard
|
||||
*/
|
||||
@SearchIndexable
|
||||
public class SnoopLoggerFiltersDashboard extends DashboardFragment {
|
||||
|
||||
private static final String TAG = "SnoopLoggerFiltersDashboard";
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.SETTINGS_SNOOP_LOGGER_DASHBOARD;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.snoop_logger_filters_settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHelpResource() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(
|
||||
Context context, boolean enabled) {
|
||||
final SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.snoop_logger_filters_settings;
|
||||
return List.of(sir);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isPageSearchEnabled(Context context) {
|
||||
return DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(context);
|
||||
}
|
||||
};
|
||||
}
|
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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.snooplogger;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.SystemProperties;
|
||||
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
/**
|
||||
* Bluetooth Snoop Logger Filters Preference
|
||||
*/
|
||||
public class SnoopLoggerFiltersPreference extends SwitchPreference {
|
||||
|
||||
private final String mKey;
|
||||
private static final String TAG = "SnoopLoggerFiltersPreference";
|
||||
private static final String SNOOP_LOG_FILTERS_PREFIX = "persist.bluetooth.snooplogfilter.";
|
||||
private static final String SNOOP_LOG_FILTERS_SUFFIX = ".enabled";
|
||||
|
||||
public SnoopLoggerFiltersPreference(Context context, String key, String entry) {
|
||||
super(context);
|
||||
mKey = key;
|
||||
setKey(key);
|
||||
setTitle(entry);
|
||||
|
||||
String filterProp = SNOOP_LOG_FILTERS_PREFIX.concat(mKey).concat(SNOOP_LOG_FILTERS_SUFFIX);
|
||||
|
||||
boolean isFilterEnabled = SystemProperties.get(filterProp).equals("true");
|
||||
|
||||
super.setChecked(isFilterEnabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChecked(boolean isChecked) {
|
||||
super.setChecked(isChecked);
|
||||
String filterProp = SNOOP_LOG_FILTERS_PREFIX.concat(mKey).concat(SNOOP_LOG_FILTERS_SUFFIX);
|
||||
SystemProperties.set(filterProp, isChecked ? "true" : "false");
|
||||
}
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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.snooplogger;
|
||||
|
||||
import android.content.Context;
|
||||
import android.sysprop.BluetoothProperties;
|
||||
|
||||
import androidx.preference.PreferenceGroup;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
/** A {@link BasePreferenceController} used in {@link SnoopLoggerFiltersDashboard} */
|
||||
public class SnoopLoggerFiltersPreferenceController extends BasePreferenceController {
|
||||
private static final String TAG = "SnoopLoggerFiltersPreferenceController";
|
||||
|
||||
private final String[] mListValues;
|
||||
private final String[] mListEntries;
|
||||
|
||||
public SnoopLoggerFiltersPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
mListValues =
|
||||
context.getResources().getStringArray(R.array.bt_hci_snoop_log_filters_values);
|
||||
mListEntries =
|
||||
context.getResources().getStringArray(R.array.bt_hci_snoop_log_filters_entries);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
BluetoothProperties.snoop_log_mode_values snoopLogMode =
|
||||
BluetoothProperties.snoop_log_mode()
|
||||
.orElse(BluetoothProperties.snoop_log_mode_values.DISABLED);
|
||||
if (snoopLogMode == BluetoothProperties.snoop_log_mode_values.FILTERED) {
|
||||
return AVAILABLE;
|
||||
}
|
||||
return DISABLED_DEPENDENT_SETTING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
PreferenceGroup mGroup = screen.findPreference(getPreferenceKey());
|
||||
mGroup.removeAll();
|
||||
final Context prefContext = mGroup.getContext();
|
||||
for (int i = 0; i < mListValues.length; i++) {
|
||||
mGroup.addPreference(
|
||||
new SnoopLoggerFiltersPreference(prefContext, mListValues[i], mListEntries[i]));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user