From b71de640b56abb4669cee12b32b2700d39b52d5a Mon Sep 17 00:00:00 2001 From: Jack Yu Date: Tue, 2 Aug 2022 13:04:24 +0000 Subject: [PATCH 1/4] Add a new NFC developer setting option for NFCSNOOP Add a new developer setting option to enable full NFCSNOOP log. Bug: 204397062 Test: manual Change-Id: I3fd34500e5e7093c9d77ff737987a35f6866814e --- res/values/strings.xml | 11 ++ res/xml/development_settings.xml | 5 + .../DevelopmentSettingsDashboardFragment.java | 18 ++- .../settings/development/NfcRebootDialog.java | 99 ++++++++++++++ .../NfcSnoopLogPreferenceController.java | 129 ++++++++++++++++++ 5 files changed, 261 insertions(+), 1 deletion(-) create mode 100644 src/com/android/settings/development/NfcRebootDialog.java create mode 100644 src/com/android/settings/development/NfcSnoopLogPreferenceController.java diff --git a/res/values/strings.xml b/res/values/strings.xml index cc7690e2c1e..a6d8eeb17f1 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1962,6 +1962,17 @@ Increase NFC stack logging level + + NFC NCI unfiltered snoop log + + Capture detail NFC packets, which may contain private information. + + Restart Device? + + Detail NFC logging is intended for development purposes only. Additional NFC data is included in bug reports, which may contain private information. Restart your device to change this setting. + + Restart + Cast diff --git a/res/xml/development_settings.xml b/res/xml/development_settings.xml index 19c12091400..3cccf01700a 100644 --- a/res/xml/development_settings.xml +++ b/res/xml/development_settings.xml @@ -402,6 +402,11 @@ android:title="@string/nfc_stack_debuglog_title" android:summary="@string/nfc_stack_debuglog_summary" /> + + Date: Tue, 2 Aug 2022 13:31:59 +0000 Subject: [PATCH 2/4] Add a new NFC developer setting option for NFC vendor verbose log Add a new developer setting option to enable vendor verbose log. Bug: 204397062 Test: manual Change-Id: Ic837bbcc32979c44732e99d51e4dcf93eb201cf1 --- res/values/strings.xml | 4 + res/xml/development_settings.xml | 5 + .../DevelopmentSettingsDashboardFragment.java | 9 ++ ...cVerboseVendorLogPreferenceController.java | 130 ++++++++++++++++++ 4 files changed, 148 insertions(+) create mode 100644 src/com/android/settings/development/NfcVerboseVendorLogPreferenceController.java diff --git a/res/values/strings.xml b/res/values/strings.xml index a6d8eeb17f1..bb98ad0d796 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1962,6 +1962,10 @@ Increase NFC stack logging level + + NFC verbose vendor debug log + + Include additional device-specific vendor logs in bugreports, which may contain private information. NFC NCI unfiltered snoop log diff --git a/res/xml/development_settings.xml b/res/xml/development_settings.xml index 3cccf01700a..a0640f5be70 100644 --- a/res/xml/development_settings.xml +++ b/res/xml/development_settings.xml @@ -402,6 +402,11 @@ android:title="@string/nfc_stack_debuglog_title" android:summary="@string/nfc_stack_debuglog_summary" /> + + Date: Thu, 4 Aug 2022 09:52:30 +0000 Subject: [PATCH 3/4] Show reboot dialog when users disable developer options When NFC detailed logging mechanisms are enabled and users try to disable develoepr options, show reboot request dialog to make sure NFC logging mechanisms are also disabled. Bug: 204397062 Test: manual Change-Id: I531c85fd77934ad7821c480df07465a8cd8f24f9 --- .../DevelopmentSettingsDashboardFragment.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java index 856bee37e26..210d0115334 100644 --- a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java +++ b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java @@ -300,10 +300,19 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra final BluetoothLeAudioHwOffloadPreferenceController leAudioController = getDevelopmentOptionsController( BluetoothLeAudioHwOffloadPreferenceController.class); + final NfcSnoopLogPreferenceController nfcSnoopLogController = + getDevelopmentOptionsController( + NfcSnoopLogPreferenceController.class); + final NfcVerboseVendorLogPreferenceController nfcVerboseLogController = + getDevelopmentOptionsController( + NfcVerboseVendorLogPreferenceController.class); // If hardware offload isn't default value, we must reboot after disable // developer options. Show a dialog for the user to confirm. if ((a2dpController == null || a2dpController.isDefaultValue()) - && (leAudioController == null || leAudioController.isDefaultValue())) { + && (leAudioController == null || leAudioController.isDefaultValue()) + && (nfcSnoopLogController == null || nfcSnoopLogController.isDefaultValue()) + && (nfcVerboseLogController == null + || nfcVerboseLogController.isDefaultValue())) { disableDeveloperOptions(); } else { DisableDevSettingsDialogFragment.show(this /* host */); From bcf2efe31e5f9e9bd131b2db83b2a6b379e255a4 Mon Sep 17 00:00:00 2001 From: Jack Yu Date: Thu, 18 Aug 2022 13:11:11 +0000 Subject: [PATCH 4/4] Add test cases for NfcSnoopLog and NfcVerboseVendorLog Bug: 204397062 Test: make RunSettingsRoboTests Change-Id: Id12e3c10dc04816d4a69692b2d922840a8e84c61 --- .../NfcSnoopLogPreferenceControllerTest.java | 99 +++++++++++++++++++ ...boseVendorLogPreferenceControllerTest.java | 99 +++++++++++++++++++ 2 files changed, 198 insertions(+) create mode 100644 tests/robotests/src/com/android/settings/development/NfcSnoopLogPreferenceControllerTest.java create mode 100644 tests/robotests/src/com/android/settings/development/NfcVerboseVendorLogPreferenceControllerTest.java diff --git a/tests/robotests/src/com/android/settings/development/NfcSnoopLogPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/NfcSnoopLogPreferenceControllerTest.java new file mode 100644 index 00000000000..4ea5475f02a --- /dev/null +++ b/tests/robotests/src/com/android/settings/development/NfcSnoopLogPreferenceControllerTest.java @@ -0,0 +1,99 @@ +/* + * 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 com.android.settings.development.NfcSnoopLogPreferenceController + .NFCSNOOP_MODE_FILTERED; +import static com.android.settings.development.NfcSnoopLogPreferenceController + .NFCSNOOP_MODE_FULL; +import static com.android.settings.development.NfcSnoopLogPreferenceController + .NFC_NFCSNOOP_LOG_MODE_PROPERTY; + +import static com.google.common.truth.Truth.assertThat; + +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import android.content.Context; +import android.os.SystemProperties; + +import androidx.preference.PreferenceScreen; +import androidx.preference.SwitchPreference; + +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 NfcSnoopLogPreferenceControllerTest { + @Mock + private PreferenceScreen mPreferenceScreen; + @Mock + private DevelopmentSettingsDashboardFragment mFragment; + + private Context mContext; + private SwitchPreference mPreference; + private NfcSnoopLogPreferenceController mController; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + mContext = RuntimeEnvironment.application; + mPreference = new SwitchPreference(mContext); + mController = spy(new NfcSnoopLogPreferenceController(mContext, mFragment)); + when(mPreferenceScreen.findPreference(mController.getPreferenceKey())) + .thenReturn(mPreference); + mController.displayPreference(mPreferenceScreen); + } + + @Test + public void onNfcRebootDialogConfirmed_nfcSnoopLogDisabled_shouldChangeProperty() { + SystemProperties.set(NFC_NFCSNOOP_LOG_MODE_PROPERTY, NFCSNOOP_MODE_FILTERED); + mController.mChanged = true; + + mController.onNfcRebootDialogConfirmed(); + + final String currentValue = SystemProperties.get(NFC_NFCSNOOP_LOG_MODE_PROPERTY); + assertThat(currentValue.equals(NFCSNOOP_MODE_FULL)).isTrue(); + } + + @Test + public void onNfcRebootDialogConfirmed_nfcSnoopLogEnabled_shouldChangeProperty() { + SystemProperties.set(NFC_NFCSNOOP_LOG_MODE_PROPERTY, NFCSNOOP_MODE_FULL); + mController.mChanged = true; + + mController.onNfcRebootDialogConfirmed(); + + final String currentValue = SystemProperties.get(NFC_NFCSNOOP_LOG_MODE_PROPERTY); + assertThat(currentValue.equals(NFCSNOOP_MODE_FILTERED)).isTrue(); + } + + @Test + public void onNfcRebootDialogCanceled_shouldNotChangeProperty() { + SystemProperties.set(NFC_NFCSNOOP_LOG_MODE_PROPERTY, NFCSNOOP_MODE_FILTERED); + mController.mChanged = true; + + mController.onNfcRebootDialogCanceled(); + + final String currentValue = SystemProperties.get(NFC_NFCSNOOP_LOG_MODE_PROPERTY); + assertThat(currentValue.equals(NFCSNOOP_MODE_FILTERED)).isTrue(); + } +} diff --git a/tests/robotests/src/com/android/settings/development/NfcVerboseVendorLogPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/NfcVerboseVendorLogPreferenceControllerTest.java new file mode 100644 index 00000000000..49ddd30dc35 --- /dev/null +++ b/tests/robotests/src/com/android/settings/development/NfcVerboseVendorLogPreferenceControllerTest.java @@ -0,0 +1,99 @@ +/* + * 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 com.android.settings.development.NfcVerboseVendorLogPreferenceController + .NFC_VERBOSE_VENDOR_LOG_PROPERTY; +import static com.android.settings.development.NfcVerboseVendorLogPreferenceController + .VERBOSE_VENDOR_LOG_DISABLED; +import static com.android.settings.development.NfcVerboseVendorLogPreferenceController + .VERBOSE_VENDOR_LOG_ENABLED; + +import static com.google.common.truth.Truth.assertThat; + +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import android.content.Context; +import android.os.SystemProperties; + +import androidx.preference.PreferenceScreen; +import androidx.preference.SwitchPreference; + +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 NfcVerboseVendorLogPreferenceControllerTest { + @Mock + private PreferenceScreen mPreferenceScreen; + @Mock + private DevelopmentSettingsDashboardFragment mFragment; + + private Context mContext; + private SwitchPreference mPreference; + private NfcVerboseVendorLogPreferenceController mController; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + mContext = RuntimeEnvironment.application; + mPreference = new SwitchPreference(mContext); + mController = spy(new NfcVerboseVendorLogPreferenceController(mContext, mFragment)); + when(mPreferenceScreen.findPreference(mController.getPreferenceKey())) + .thenReturn(mPreference); + mController.displayPreference(mPreferenceScreen); + } + + @Test + public void onNfcRebootDialogConfirmed_nfcVendorLogDisabled_shouldChangeProperty() { + SystemProperties.set(NFC_VERBOSE_VENDOR_LOG_PROPERTY, VERBOSE_VENDOR_LOG_DISABLED); + mController.mChanged = true; + + mController.onNfcRebootDialogConfirmed(); + + final String currentValue = SystemProperties.get(NFC_VERBOSE_VENDOR_LOG_PROPERTY); + assertThat(currentValue.equals(VERBOSE_VENDOR_LOG_ENABLED)).isTrue(); + } + + @Test + public void onNfcRebootDialogConfirmed_nfcVendorLogEnabled_shouldChangeProperty() { + SystemProperties.set(NFC_VERBOSE_VENDOR_LOG_PROPERTY, VERBOSE_VENDOR_LOG_ENABLED); + mController.mChanged = true; + + mController.onNfcRebootDialogConfirmed(); + + final String currentValue = SystemProperties.get(NFC_VERBOSE_VENDOR_LOG_PROPERTY); + assertThat(currentValue.equals(VERBOSE_VENDOR_LOG_DISABLED)).isTrue(); + } + + @Test + public void onNfcRebootDialogCanceled_shouldNotChangeProperty() { + SystemProperties.set(NFC_VERBOSE_VENDOR_LOG_PROPERTY, VERBOSE_VENDOR_LOG_DISABLED); + mController.mChanged = true; + + mController.onNfcRebootDialogCanceled(); + + final String currentValue = SystemProperties.get(NFC_VERBOSE_VENDOR_LOG_PROPERTY); + assertThat(currentValue.equals(VERBOSE_VENDOR_LOG_DISABLED)).isTrue(); + } +}