Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dc15244a authored by Richard MacGregor's avatar Richard MacGregor
Browse files

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
parent b16781d2
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -11979,6 +11979,11 @@
    <!-- Developer settings: Summary for allowing mock modem service. [CHAR LIMIT=NONE]-->
    <string name="allow_mock_modem_summary">Allow this device to run Mock Modem service for instrumentation testing. Do not enable this during normal usage of the phone</string>
    <!-- Developer settings: Title for disable app and notification screen share protections [CHAR LIMIT=50] -->
    <string name="disable_screen_share_protections_for_apps_and_notifications">Disable screen share protections</string>
    <!-- Developer settings: Summary for disable app and notification screen share protections summary [CHAR LIMIT=150] -->
    <string name="disable_screen_share_protections_for_apps_and_notifications_summary">Disables system applied app and notifications protections during screen sharing</string>
    <!-- Title for media control settings [CHAR LIMIT=50]-->
    <string name="media_controls_title">Media</string>
    <!-- Title of toggle to enable or disable the media resumption feature in quick settings [CHAR LIMIT=50]-->
+5 −0
Original line number Diff line number Diff line
@@ -705,6 +705,11 @@
            android:title="@string/show_notification_channel_warnings"
            android:summary="@string/show_notification_channel_warnings_summary" />

        <SwitchPreferenceCompat
            android:key="disable_screen_share_protections_for_apps_and_notifications"
            android:title="@string/disable_screen_share_protections_for_apps_and_notifications"
            android:summary="@string/disable_screen_share_protections_for_apps_and_notifications_summary" />

        <Preference
            android:key="asst_importance_reset"
            android:title="@string/asst_importance_reset_title"
+1 −0
Original line number Diff line number Diff line
@@ -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;
    }
+3 −0
Original line number Diff line number Diff line
# 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

+79 −0
Original line number Diff line number Diff line
/*
 * 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
    }
}
Loading