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
This commit is contained in:
Richard MacGregor
2024-01-18 09:43:15 -08:00
parent b16781d2bc
commit dc15244a5d
6 changed files with 244 additions and 0 deletions

View File

@@ -763,6 +763,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
context, context.getSystemService(UiModeManager.class)));
controllers.add(new ForceEnableNotesRolePreferenceController(context));
controllers.add(new GrammaticalGenderPreferenceController(context));
controllers.add(new SensitiveContentProtectionPreferenceController(context));
return controllers;
}

View File

@@ -1,6 +1,9 @@
# GameDefaultFrameRatePreferenceController
per-file GameDefaultFrameRatePreferenceController.java=file:platform/frameworks/base:/GAME_MANAGER_OWNERS
# SensitiveContentProtectionPreferenceController
per-file SensitiveContentProtectionPreferenceController.kt=file:platform/frameworks/base:/core/java/android/permission/OWNERS
# ShowHdrSdrRatioPreferenceController
per-file ShowHdrSdrRatioPreferenceController.java=file:platform/frameworks/native:/services/surfaceflinger/OWNERS

View File

@@ -0,0 +1,79 @@
/*
* Copyright (C) 2024 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.provider.Settings
import androidx.annotation.VisibleForTesting
import androidx.preference.Preference
import androidx.preference.TwoStatePreference
import com.android.server.notification.Flags.sensitiveNotificationAppProtection
import com.android.server.notification.Flags.screenshareNotificationHiding
import com.android.settings.core.PreferenceControllerMixin
import com.android.settingslib.development.DeveloperOptionsPreferenceController
class SensitiveContentProtectionPreferenceController(val context: Context) :
DeveloperOptionsPreferenceController(context),
Preference.OnPreferenceChangeListener,
PreferenceControllerMixin {
override fun getPreferenceKey(): String =
DISABLE_SCREEN_SHARE_PROTECTIONS_FOR_APPS_AND_NOTIFICATIONS_KEY
override fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean {
val isEnabled = newValue as Boolean
Settings.Global.putInt(
mContext.getContentResolver(),
Settings.Global.DISABLE_SCREEN_SHARE_PROTECTIONS_FOR_APPS_AND_NOTIFICATIONS,
if (isEnabled) SETTING_VALUE_ON else SETTING_VALUE_OFF
)
return true
}
override fun updateState(preference: Preference?) {
val mode = Settings.Global.getInt(
mContext.getContentResolver(),
Settings.Global.DISABLE_SCREEN_SHARE_PROTECTIONS_FOR_APPS_AND_NOTIFICATIONS,
0)
(mPreference as TwoStatePreference).isChecked = mode != SETTING_VALUE_OFF
}
// Overriding as public, kotlin tests can not invoke a protected method
public override fun onDeveloperOptionsSwitchDisabled() {
super.onDeveloperOptionsSwitchDisabled()
Settings.Global.putInt(
mContext.getContentResolver(),
Settings.Global.DISABLE_SCREEN_SHARE_PROTECTIONS_FOR_APPS_AND_NOTIFICATIONS,
SETTING_VALUE_OFF
)
(mPreference as TwoStatePreference).isChecked = false
}
override fun isAvailable(): Boolean {
return sensitiveNotificationAppProtection() || screenshareNotificationHiding()
}
companion object {
private const val DISABLE_SCREEN_SHARE_PROTECTIONS_FOR_APPS_AND_NOTIFICATIONS_KEY =
"disable_screen_share_protections_for_apps_and_notifications"
@VisibleForTesting
val SETTING_VALUE_ON = 1
@VisibleForTesting
val SETTING_VALUE_OFF = 0
}
}