From dc15244a5d120471938f0595227d899c6ce3f29b Mon Sep 17 00:00:00 2001 From: Richard MacGregor Date: Thu, 18 Jan 2024 09:43:15 -0800 Subject: [PATCH] Add developer option for screenshare protections Add developer option that allows disabling screenshare protections to allow for better bug reports and debugging. Bug: 320757744 Bug: 316955558 Bug: 316954829 Flag: ACONFIG com.android.server.notification.sensitive_notification_app_protection DISABLED Flag: ACONFIG com.android.server.notification.screenshare_notification_hiding DISABLED Test: atest SensitiveContentProtectionPreferenceControllerTest Change-Id: Ibcb9f886aa599fe2442e755653c49f44cfa1830f --- res/values/strings.xml | 5 + res/xml/development_settings.xml | 5 + .../DevelopmentSettingsDashboardFragment.java | 1 + src/com/android/settings/development/OWNERS | 3 + ...veContentProtectionPreferenceController.kt | 79 +++++++++ ...ntentProtectionPreferenceControllerTest.kt | 151 ++++++++++++++++++ 6 files changed, 244 insertions(+) create mode 100644 src/com/android/settings/development/SensitiveContentProtectionPreferenceController.kt create mode 100644 tests/spa_unit/src/com/android/settings/development/SensitiveContentProtectionPreferenceControllerTest.kt diff --git a/res/values/strings.xml b/res/values/strings.xml index 78900bc1584..c26e316c90f 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -11979,6 +11979,11 @@ Allow this device to run Mock Modem service for instrumentation testing. Do not enable this during normal usage of the phone + + Disable screen share protections + + Disables system applied app and notifications protections during screen sharing + Media diff --git a/res/xml/development_settings.xml b/res/xml/development_settings.xml index fb5e2809434..c0b6560b9a4 100644 --- a/res/xml/development_settings.xml +++ b/res/xml/development_settings.xml @@ -705,6 +705,11 @@ android:title="@string/show_notification_channel_warnings" android:summary="@string/show_notification_channel_warnings_summary" /> + + (controller.getPreferenceKey())) + .thenReturn(preference) + controller.displayPreference(screen) + } + + @Test + fun onPreferenceChange_settingEnabled_shouldDisableSensitiveContentProtection() { + controller.onPreferenceChange(preference, true /* new value */) + val mode = Settings.Global.getInt( + context.contentResolver, + DISABLE_SCREEN_SHARE_PROTECTIONS_FOR_APPS_AND_NOTIFICATIONS, + -1 /* default */ + ) + + assertEquals(mode, SETTING_VALUE_ON) + } + + @Test + fun onPreferenceChange_settingDisabled_shouldEnableSensitiveContentProtection() { + controller.onPreferenceChange(preference, false /* new value */) + val mode = Settings.Global.getInt( + context.contentResolver, + DISABLE_SCREEN_SHARE_PROTECTIONS_FOR_APPS_AND_NOTIFICATIONS, + -1 /* default */ + ) + + assertEquals(mode, SETTING_VALUE_OFF) + } + + @Test + fun updateState_settingEnabled_preferenceShouldBeChecked() { + Settings.Global.putInt( + context.contentResolver, + DISABLE_SCREEN_SHARE_PROTECTIONS_FOR_APPS_AND_NOTIFICATIONS, + SETTING_VALUE_ON + ) + controller.updateState(preference) + + verify(preference).isChecked = true + } + + @Test + fun updateState_settingDisabled_preferenceShouldNotBeChecked() { + Settings.Global.putInt( + context.contentResolver, + DISABLE_SCREEN_SHARE_PROTECTIONS_FOR_APPS_AND_NOTIFICATIONS, + SETTING_VALUE_OFF + ) + controller.updateState(preference) + + verify(preference).isChecked = false + } + + @Test + fun onDeveloperOptionsSwitchDisabled_preferenceShouldBeDisabled() { + controller.onDeveloperOptionsSwitchDisabled() + val mode = Settings.Global.getInt( + context.contentResolver, + DISABLE_SCREEN_SHARE_PROTECTIONS_FOR_APPS_AND_NOTIFICATIONS, + -1 /* default */ + ) + + assertEquals(mode, SETTING_VALUE_OFF) + verify(preference).isChecked = false + verify(preference).isEnabled = false + } + + @Test + @RequiresFlagsDisabled( + FLAG_SENSITIVE_NOTIFICATION_APP_PROTECTION, + FLAG_SCREENSHARE_NOTIFICATION_HIDING) + fun isAvailable_flagsDisabled_returnFalse() { + assertFalse(controller.isAvailable) + } + + @Test + @RequiresFlagsEnabled(FLAG_SENSITIVE_NOTIFICATION_APP_PROTECTION) + fun isAvailable_sensitiveNotificationAppProtectionEnabled_returnTrue() { + assertTrue(controller.isAvailable) + } + + @Test + @RequiresFlagsEnabled(FLAG_SCREENSHARE_NOTIFICATION_HIDING) + fun isAvailable_screenshareNotificationHidingEnabled_returnTrue() { + assertTrue(controller.isAvailable) + } +} \ No newline at end of file