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:
@@ -5399,6 +5399,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] -->
|
||||
|
@@ -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
res/xml/snoop_logger_filters_settings.xml
Normal file
29
res/xml/snoop_logger_filters_settings.xml
Normal file
@@ -0,0 +1,29 @@
|
||||
<?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>
|
@@ -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]));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,185 @@
|
||||
/*
|
||||
* 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 static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.sysprop.BluetoothProperties;
|
||||
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.Spy;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class BluetoothSnoopLogFilterProfileMapPreferenceControllerTest {
|
||||
|
||||
@Spy private Context mSpyContext = RuntimeEnvironment.application;
|
||||
@Spy private Resources mSpyResources = RuntimeEnvironment.application.getResources();
|
||||
private ListPreference mPreference;
|
||||
@Mock private PreferenceScreen mPreferenceScreen;
|
||||
private BluetoothSnoopLogFilterProfileMapPreferenceController mController;
|
||||
|
||||
private CharSequence[] mListValues;
|
||||
private CharSequence[] mListEntries;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
doReturn(mSpyResources).when(mSpyContext).getResources();
|
||||
// Get XML values without mock
|
||||
// Setup test list preference using XML values
|
||||
mPreference = new ListPreference(mSpyContext);
|
||||
mPreference.setEntries(R.array.bt_hci_snoop_log_profile_filter_entries);
|
||||
mPreference.setEntryValues(R.array.bt_hci_snoop_log_profile_filter_values);
|
||||
// Init the actual controller
|
||||
mController = new BluetoothSnoopLogFilterProfileMapPreferenceController(mSpyContext);
|
||||
// Construct preference in the controller via a mocked preference screen object
|
||||
when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
|
||||
.thenReturn(mPreference);
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
mListValues = mPreference.getEntryValues();
|
||||
mListEntries = mPreference.getEntries();
|
||||
BluetoothProperties.snoop_log_mode(BluetoothProperties.snoop_log_mode_values.FILTERED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyResourceSizeAndRange() {
|
||||
Assert.assertTrue(
|
||||
BluetoothSnoopLogFilterProfileMapPreferenceController
|
||||
.isSnoopLogModeFilteredEnabled());
|
||||
// Verify normal list entries and default preference entries have the same size
|
||||
Assert.assertEquals(mListEntries.length, mListValues.length);
|
||||
// Update the preference
|
||||
mController.updateState(mPreference);
|
||||
// Verify default preference value, entry and summary
|
||||
final int defaultIndex = mController.getDefaultModeIndex();
|
||||
Assert.assertEquals(mPreference.getValue(), mListValues[defaultIndex]);
|
||||
Assert.assertEquals(mPreference.getEntry(), mListEntries[defaultIndex]);
|
||||
Assert.assertEquals(mPreference.getSummary(), mListEntries[defaultIndex]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChanged_turnOnBluetoothSnoopLogFullFilterMap() {
|
||||
Assert.assertTrue(
|
||||
BluetoothSnoopLogFilterProfileMapPreferenceController
|
||||
.isSnoopLogModeFilteredEnabled());
|
||||
mController.onPreferenceChange(
|
||||
null,
|
||||
mListValues[
|
||||
BluetoothSnoopLogFilterProfileMapPreferenceController
|
||||
.BTSNOOP_LOG_PROFILE_FILTER_MODE_FULL_FILTER_INDEX]);
|
||||
var mode =
|
||||
BluetoothProperties.snoop_log_filter_profile_map()
|
||||
.orElse(BluetoothProperties.snoop_log_filter_profile_map_values.DISABLED);
|
||||
// "fullfilter" is hard-coded between Settings and system/bt
|
||||
Assert.assertEquals(
|
||||
mode, BluetoothProperties.snoop_log_filter_profile_map_values.FULLFILTER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChanged_turnOnBluetoothSnoopLogHeaderFilterMap() {
|
||||
Assert.assertTrue(
|
||||
BluetoothSnoopLogFilterProfileMapPreferenceController
|
||||
.isSnoopLogModeFilteredEnabled());
|
||||
mController.onPreferenceChange(
|
||||
null,
|
||||
mListValues[
|
||||
BluetoothSnoopLogFilterProfileMapPreferenceController
|
||||
.BTSNOOP_LOG_PROFILE_FILTER_MODE_HEADER_INDEX]);
|
||||
var mode =
|
||||
BluetoothProperties.snoop_log_filter_profile_map()
|
||||
.orElse(BluetoothProperties.snoop_log_filter_profile_map_values.DISABLED);
|
||||
// "header" is hard-coded between Settings and system/bt
|
||||
Assert.assertEquals(mode, BluetoothProperties.snoop_log_filter_profile_map_values.HEADER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChanged_turnOnBluetoothSnoopLogMagicFilterMap() {
|
||||
Assert.assertTrue(
|
||||
BluetoothSnoopLogFilterProfileMapPreferenceController
|
||||
.isSnoopLogModeFilteredEnabled());
|
||||
mController.onPreferenceChange(
|
||||
null,
|
||||
mListValues[
|
||||
BluetoothSnoopLogFilterProfileMapPreferenceController
|
||||
.BTSNOOP_LOG_PROFILE_FILTER_MODE_MAGIC_INDEX]);
|
||||
var mode =
|
||||
BluetoothProperties.snoop_log_filter_profile_map()
|
||||
.orElse(BluetoothProperties.snoop_log_filter_profile_map_values.DISABLED);
|
||||
// "magic" is hard-coded between Settings and system/bt
|
||||
Assert.assertEquals(mode, BluetoothProperties.snoop_log_filter_profile_map_values.MAGIC);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChanged_turnOffBluetoothSnoopLogFilterMap() {
|
||||
Assert.assertTrue(
|
||||
BluetoothSnoopLogFilterProfileMapPreferenceController
|
||||
.isSnoopLogModeFilteredEnabled());
|
||||
mController.onPreferenceChange(
|
||||
null,
|
||||
mListValues[
|
||||
BluetoothSnoopLogFilterProfileMapPreferenceController
|
||||
.BTSNOOP_LOG_PROFILE_FILTER_MODE_DISABLED_INDEX]);
|
||||
var mode =
|
||||
BluetoothProperties.snoop_log_filter_profile_map()
|
||||
.orElse(BluetoothProperties.snoop_log_filter_profile_map_values.DISABLED);
|
||||
// "disabled" is hard-coded between Settings and system/bt
|
||||
Assert.assertEquals(mode, BluetoothProperties.snoop_log_filter_profile_map_values.DISABLED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceShouldBeSetToRightValue() {
|
||||
Assert.assertTrue(
|
||||
BluetoothSnoopLogFilterProfileMapPreferenceController
|
||||
.isSnoopLogModeFilteredEnabled());
|
||||
for (int i = 0; i < mListValues.length; ++i) {
|
||||
BluetoothProperties.snoop_log_filter_profile_map(
|
||||
BluetoothProperties.snoop_log_filter_profile_map_values.valueOf(
|
||||
mListValues[i].toString().toUpperCase(Locale.US)));
|
||||
mController.updateState(mPreference);
|
||||
Assert.assertEquals(mPreference.getValue(), mListValues[i].toString());
|
||||
Assert.assertEquals(mPreference.getSummary(), mListEntries[i].toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onDeveloperOptionsDisabled_shouldDisablePreference() {
|
||||
mController.onDeveloperOptionsDisabled();
|
||||
Assert.assertFalse(mPreference.isEnabled());
|
||||
Assert.assertEquals(
|
||||
mPreference.getValue(), mListValues[mController.getDefaultModeIndex()].toString());
|
||||
Assert.assertEquals(
|
||||
mPreference.getSummary(),
|
||||
mListEntries[mController.getDefaultModeIndex()].toString());
|
||||
}
|
||||
}
|
@@ -0,0 +1,186 @@
|
||||
/*
|
||||
* 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 static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.sysprop.BluetoothProperties;
|
||||
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.Spy;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class BluetoothSnoopLogFilterProfilePbapPreferenceControllerTest {
|
||||
|
||||
@Spy private Context mSpyContext = RuntimeEnvironment.application;
|
||||
@Spy private Resources mSpyResources = RuntimeEnvironment.application.getResources();
|
||||
private ListPreference mPreference;
|
||||
@Mock private PreferenceScreen mPreferenceScreen;
|
||||
private BluetoothSnoopLogFilterProfilePbapPreferenceController mController;
|
||||
|
||||
private CharSequence[] mListValues;
|
||||
private CharSequence[] mListEntries;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
doReturn(mSpyResources).when(mSpyContext).getResources();
|
||||
// Get XML values without mock
|
||||
// Setup test list preference using XML values
|
||||
mPreference = new ListPreference(mSpyContext);
|
||||
mPreference.setEntries(R.array.bt_hci_snoop_log_profile_filter_entries);
|
||||
mPreference.setEntryValues(R.array.bt_hci_snoop_log_profile_filter_values);
|
||||
// Init the actual controller
|
||||
mController = new BluetoothSnoopLogFilterProfilePbapPreferenceController(mSpyContext);
|
||||
// Construct preference in the controller via a mocked preference screen object
|
||||
when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
|
||||
.thenReturn(mPreference);
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
mListValues = mPreference.getEntryValues();
|
||||
mListEntries = mPreference.getEntries();
|
||||
BluetoothProperties.snoop_log_mode(BluetoothProperties.snoop_log_mode_values.FILTERED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyResourceSizeAndRange() {
|
||||
Assert.assertTrue(
|
||||
BluetoothSnoopLogFilterProfilePbapPreferenceController
|
||||
.isSnoopLogModeFilteredEnabled());
|
||||
// Verify normal list entries and default preference entries have the same size
|
||||
Assert.assertEquals(mListEntries.length, mListValues.length);
|
||||
// Update the preference
|
||||
mController.updateState(mPreference);
|
||||
// Verify default preference value, entry and summary
|
||||
final int defaultIndex = mController.getDefaultModeIndex();
|
||||
Assert.assertEquals(mPreference.getValue(), mListValues[defaultIndex]);
|
||||
Assert.assertEquals(mPreference.getEntry(), mListEntries[defaultIndex]);
|
||||
Assert.assertEquals(mPreference.getSummary(), mListEntries[defaultIndex]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChanged_turnOnBluetoothSnoopLogFullFilterPbap() {
|
||||
Assert.assertTrue(
|
||||
BluetoothSnoopLogFilterProfilePbapPreferenceController
|
||||
.isSnoopLogModeFilteredEnabled());
|
||||
mController.onPreferenceChange(
|
||||
null,
|
||||
mListValues[
|
||||
BluetoothSnoopLogFilterProfilePbapPreferenceController
|
||||
.BTSNOOP_LOG_PROFILE_FILTER_MODE_FULL_FILTER_INDEX]);
|
||||
var mode =
|
||||
BluetoothProperties.snoop_log_filter_profile_pbap()
|
||||
.orElse(BluetoothProperties.snoop_log_filter_profile_pbap_values.DISABLED);
|
||||
// "fullfilter" is hard-coded between Settings and system/bt
|
||||
Assert.assertEquals(
|
||||
mode, BluetoothProperties.snoop_log_filter_profile_pbap_values.FULLFILTER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChanged_turnOnBluetoothSnoopLogHeaderFilterPbap() {
|
||||
Assert.assertTrue(
|
||||
BluetoothSnoopLogFilterProfilePbapPreferenceController
|
||||
.isSnoopLogModeFilteredEnabled());
|
||||
mController.onPreferenceChange(
|
||||
null,
|
||||
mListValues[
|
||||
BluetoothSnoopLogFilterProfilePbapPreferenceController
|
||||
.BTSNOOP_LOG_PROFILE_FILTER_MODE_HEADER_INDEX]);
|
||||
var mode =
|
||||
BluetoothProperties.snoop_log_filter_profile_pbap()
|
||||
.orElse(BluetoothProperties.snoop_log_filter_profile_pbap_values.DISABLED);
|
||||
// "header" is hard-coded between Settings and system/bt
|
||||
Assert.assertEquals(mode, BluetoothProperties.snoop_log_filter_profile_pbap_values.HEADER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChanged_turnOnBluetoothSnoopLogMagicFilterPbap() {
|
||||
Assert.assertTrue(
|
||||
BluetoothSnoopLogFilterProfilePbapPreferenceController
|
||||
.isSnoopLogModeFilteredEnabled());
|
||||
mController.onPreferenceChange(
|
||||
null,
|
||||
mListValues[
|
||||
BluetoothSnoopLogFilterProfilePbapPreferenceController
|
||||
.BTSNOOP_LOG_PROFILE_FILTER_MODE_MAGIC_INDEX]);
|
||||
var mode =
|
||||
BluetoothProperties.snoop_log_filter_profile_pbap()
|
||||
.orElse(BluetoothProperties.snoop_log_filter_profile_pbap_values.DISABLED);
|
||||
// "magic" is hard-coded between Settings and system/bt
|
||||
Assert.assertEquals(mode, BluetoothProperties.snoop_log_filter_profile_pbap_values.MAGIC);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChanged_turnOffBluetoothSnoopLogFilterPbap() {
|
||||
Assert.assertTrue(
|
||||
BluetoothSnoopLogFilterProfilePbapPreferenceController
|
||||
.isSnoopLogModeFilteredEnabled());
|
||||
mController.onPreferenceChange(
|
||||
null,
|
||||
mListValues[
|
||||
BluetoothSnoopLogFilterProfilePbapPreferenceController
|
||||
.BTSNOOP_LOG_PROFILE_FILTER_MODE_DISABLED_INDEX]);
|
||||
var mode =
|
||||
BluetoothProperties.snoop_log_filter_profile_pbap()
|
||||
.orElse(BluetoothProperties.snoop_log_filter_profile_pbap_values.DISABLED);
|
||||
// "disabled" is hard-coded between Settings and system/bt
|
||||
Assert.assertEquals(
|
||||
mode, BluetoothProperties.snoop_log_filter_profile_pbap_values.DISABLED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceShouldBeSetToRightValue() {
|
||||
Assert.assertTrue(
|
||||
BluetoothSnoopLogFilterProfilePbapPreferenceController
|
||||
.isSnoopLogModeFilteredEnabled());
|
||||
for (int i = 0; i < mListValues.length; ++i) {
|
||||
BluetoothProperties.snoop_log_filter_profile_pbap(
|
||||
BluetoothProperties.snoop_log_filter_profile_pbap_values.valueOf(
|
||||
mListValues[i].toString().toUpperCase(Locale.US)));
|
||||
mController.updateState(mPreference);
|
||||
Assert.assertEquals(mPreference.getValue(), mListValues[i].toString());
|
||||
Assert.assertEquals(mPreference.getSummary(), mListEntries[i].toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onDeveloperOptionsDisabled_shouldDisablePreference() {
|
||||
mController.onDeveloperOptionsDisabled();
|
||||
Assert.assertFalse(mPreference.isEnabled());
|
||||
Assert.assertEquals(
|
||||
mPreference.getValue(), mListValues[mController.getDefaultModeIndex()].toString());
|
||||
Assert.assertEquals(
|
||||
mPreference.getSummary(),
|
||||
mListEntries[mController.getDefaultModeIndex()].toString());
|
||||
}
|
||||
}
|
@@ -17,9 +17,8 @@
|
||||
package com.android.settings.development;
|
||||
|
||||
import static com.android.settings.development.BluetoothSnoopLogPreferenceController.BLUETOOTH_BTSNOOP_LOG_MODE_PROPERTY;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
@@ -31,6 +30,7 @@ import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -43,13 +43,10 @@ import org.robolectric.RuntimeEnvironment;
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class BluetoothSnoopLogPreferenceControllerTest {
|
||||
|
||||
@Spy
|
||||
private Context mSpyContext = RuntimeEnvironment.application;
|
||||
@Spy
|
||||
private Resources mSpyResources = RuntimeEnvironment.application.getResources();
|
||||
@Spy private Context mSpyContext = RuntimeEnvironment.application;
|
||||
@Spy private Resources mSpyResources = RuntimeEnvironment.application.getResources();
|
||||
private ListPreference mPreference;
|
||||
@Mock
|
||||
private PreferenceScreen mPreferenceScreen;
|
||||
@Mock private PreferenceScreen mPreferenceScreen;
|
||||
private BluetoothSnoopLogPreferenceController mController;
|
||||
|
||||
private CharSequence[] mListValues;
|
||||
@@ -65,10 +62,10 @@ public class BluetoothSnoopLogPreferenceControllerTest {
|
||||
mPreference.setEntries(R.array.bt_hci_snoop_log_entries);
|
||||
mPreference.setEntryValues(R.array.bt_hci_snoop_log_values);
|
||||
// Init the actual controller
|
||||
mController = new BluetoothSnoopLogPreferenceController(mSpyContext);
|
||||
mController = new BluetoothSnoopLogPreferenceController(mSpyContext, null);
|
||||
// Construct preference in the controller via a mocked preference screen object
|
||||
when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
|
||||
.thenReturn(mPreference);
|
||||
.thenReturn(mPreference);
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
mListValues = mPreference.getEntryValues();
|
||||
mListEntries = mPreference.getEntries();
|
||||
@@ -77,41 +74,44 @@ public class BluetoothSnoopLogPreferenceControllerTest {
|
||||
@Test
|
||||
public void verifyResourceSizeAndRange() {
|
||||
// Verify normal list entries and default preference entries have the same size
|
||||
assertThat(mListEntries.length).isEqualTo(mListValues.length);
|
||||
Assert.assertEquals(mListEntries.length, mListValues.length);
|
||||
// Update the preference
|
||||
mController.updateState(mPreference);
|
||||
// Verify default preference value, entry and summary
|
||||
final int defaultIndex = mController.getDefaultModeIndex();
|
||||
assertThat(mPreference.getValue()).isEqualTo(mListValues[defaultIndex]);
|
||||
assertThat(mPreference.getEntry()).isEqualTo(mListEntries[defaultIndex]);
|
||||
assertThat(mPreference.getSummary()).isEqualTo(mListEntries[defaultIndex]);
|
||||
Assert.assertEquals(mPreference.getValue(), mListValues[defaultIndex]);
|
||||
Assert.assertEquals(mPreference.getEntry(), mListEntries[defaultIndex]);
|
||||
Assert.assertEquals(mPreference.getSummary(), mListEntries[defaultIndex]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChanged_turnOnFullBluetoothSnoopLog() {
|
||||
mController.onPreferenceChange(null,
|
||||
mController.onPreferenceChange(
|
||||
null,
|
||||
mListValues[BluetoothSnoopLogPreferenceController.BTSNOOP_LOG_MODE_FULL_INDEX]);
|
||||
final String mode = SystemProperties.get(BLUETOOTH_BTSNOOP_LOG_MODE_PROPERTY);
|
||||
// "full" is hard-coded between Settings and system/bt
|
||||
assertThat(mode).isEqualTo("full");
|
||||
Assert.assertEquals(mode, "full");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChanged_turnOnFilteredBluetoothSnoopLog() {
|
||||
mController.onPreferenceChange(null,
|
||||
mController.onPreferenceChange(
|
||||
null,
|
||||
mListValues[BluetoothSnoopLogPreferenceController.BTSNOOP_LOG_MODE_FILTERED_INDEX]);
|
||||
final String mode = SystemProperties.get(BLUETOOTH_BTSNOOP_LOG_MODE_PROPERTY);
|
||||
// "filtered" is hard-coded between Settings and system/bt
|
||||
assertThat(mode).isEqualTo("filtered");
|
||||
Assert.assertEquals(mode, "filtered");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChanged_turnOffBluetoothSnoopLog() {
|
||||
mController.onPreferenceChange(null,
|
||||
mController.onPreferenceChange(
|
||||
null,
|
||||
mListValues[BluetoothSnoopLogPreferenceController.BTSNOOP_LOG_MODE_DISABLED_INDEX]);
|
||||
final String mode = SystemProperties.get(BLUETOOTH_BTSNOOP_LOG_MODE_PROPERTY);
|
||||
// "disabled" is hard-coded between Settings and system/bt
|
||||
assertThat(mode).isEqualTo("disabled");
|
||||
Assert.assertEquals(mode, "disabled");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -119,20 +119,19 @@ public class BluetoothSnoopLogPreferenceControllerTest {
|
||||
for (int i = 0; i < mListValues.length; ++i) {
|
||||
SystemProperties.set(BLUETOOTH_BTSNOOP_LOG_MODE_PROPERTY, mListValues[i].toString());
|
||||
mController.updateState(mPreference);
|
||||
assertThat(mPreference.getValue()).isEqualTo(mListValues[i].toString());
|
||||
assertThat(mPreference.getSummary()).isEqualTo(mListEntries[i].toString());
|
||||
Assert.assertEquals(mPreference.getValue(), mListValues[i].toString());
|
||||
Assert.assertEquals(mPreference.getSummary(), mListEntries[i].toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onDeveloperOptionsDisabled_shouldDisablePreference() {
|
||||
mController.onDeveloperOptionsDisabled();
|
||||
assertThat(mPreference.isEnabled()).isFalse();
|
||||
assertThat(mPreference.getValue()).isEqualTo(
|
||||
mListValues[mController.getDefaultModeIndex()]
|
||||
.toString());
|
||||
assertThat(mPreference.getSummary()).isEqualTo(
|
||||
mListEntries[mController.getDefaultModeIndex()]
|
||||
.toString());
|
||||
Assert.assertFalse(mPreference.isEnabled());
|
||||
Assert.assertEquals(
|
||||
mPreference.getValue(), mListValues[mController.getDefaultModeIndex()].toString());
|
||||
Assert.assertEquals(
|
||||
mPreference.getSummary(),
|
||||
mListEntries[mController.getDefaultModeIndex()].toString());
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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 static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class SnoopLoggerFiltersDashboardTest {
|
||||
|
||||
private SnoopLoggerFiltersDashboard mDashboard;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mDashboard = new SnoopLoggerFiltersDashboard();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotHaveHelpResource() {
|
||||
assertThat(mDashboard.getHelpResource()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldLogAsSnoopLoggerFiltersPage() {
|
||||
assertThat(mDashboard.getMetricsCategory())
|
||||
.isEqualTo(SettingsEnums.SETTINGS_SNOOP_LOGGER_DASHBOARD);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldUseSnoopLoggerFiltersPreferenceLayout() {
|
||||
assertThat(mDashboard.getPreferenceScreenResId())
|
||||
.isEqualTo(R.xml.snoop_logger_filters_settings);
|
||||
}
|
||||
}
|
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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 static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.DISABLED_DEPENDENT_SETTING;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.sysprop.BluetoothProperties;
|
||||
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class SnoopLoggerFiltersPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private PreferenceCategory mCategory;
|
||||
private Context mContext;
|
||||
private SnoopLoggerFiltersPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new SnoopLoggerFiltersPreferenceController(mContext, "test_key");
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mCategory);
|
||||
when(mCategory.getContext()).thenReturn(mContext);
|
||||
mController.displayPreference(mScreen);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailability_debug_available() {
|
||||
BluetoothProperties.snoop_log_mode(BluetoothProperties.snoop_log_mode_values.FILTERED);
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailability_user_unavailable() {
|
||||
BluetoothProperties.snoop_log_mode(BluetoothProperties.snoop_log_mode_values.DISABLED);
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStart_shouldRefreshFilters() {
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mCategory, atLeastOnce()).addPreference(any(SnoopLoggerFiltersPreference.class));
|
||||
}
|
||||
}
|
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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 com.android.settings.R;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class SnoopLoggerFiltersPreferenceTest {
|
||||
|
||||
private static String sKEY;
|
||||
private static String sENTRY;
|
||||
|
||||
private Context mContext;
|
||||
private SnoopLoggerFiltersPreference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
sKEY = mContext.getResources().getStringArray(R.array.bt_hci_snoop_log_filters_values)[0];
|
||||
sENTRY =
|
||||
mContext.getResources().getStringArray(R.array.bt_hci_snoop_log_filters_entries)[0];
|
||||
mPreference = new SnoopLoggerFiltersPreference(mContext, sKEY, sENTRY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructor_shouldSetTitle() {
|
||||
Assert.assertEquals(mPreference.getTitle(), sENTRY);
|
||||
Assert.assertFalse(mPreference.isChecked());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_shouldSetChecked() {
|
||||
mPreference.setChecked(true);
|
||||
Assert.assertTrue(mPreference.isChecked());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user