Merge "SnoopLogger: Debug enhancements added settings" am: cfde422f91
Original change: https://android-review.googlesource.com/c/platform/packages/apps/Settings/+/2362495 Change-Id: I3c138106ebdaaf6b5597c6a79054915a04098117 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -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