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

Commit 9ed64677 authored by Richard MacGregor's avatar Richard MacGregor Committed by Android (Google) Code Review
Browse files

Merge "Add developer option for screenshare protections" into main

parents 8d89dbc5 dc15244a
Loading
Loading
Loading
Loading
+5 −0
Original line number Original line Diff line number Diff line
@@ -11979,6 +11979,11 @@
    <!-- Developer settings: Summary for allowing mock modem service. [CHAR LIMIT=NONE]-->
    <!-- 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>
    <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]-->
    <!-- Title for media control settings [CHAR LIMIT=50]-->
    <string name="media_controls_title">Media</string>
    <string name="media_controls_title">Media</string>
    <!-- Title of toggle to enable or disable the media resumption feature in quick settings [CHAR LIMIT=50]-->
    <!-- Title of toggle to enable or disable the media resumption feature in quick settings [CHAR LIMIT=50]-->
+5 −0
Original line number Original line Diff line number Diff line
@@ -705,6 +705,11 @@
            android:title="@string/show_notification_channel_warnings"
            android:title="@string/show_notification_channel_warnings"
            android:summary="@string/show_notification_channel_warnings_summary" />
            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
        <Preference
            android:key="asst_importance_reset"
            android:key="asst_importance_reset"
            android:title="@string/asst_importance_reset_title"
            android:title="@string/asst_importance_reset_title"
+1 −0
Original line number Original line Diff line number Diff line
@@ -763,6 +763,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
                context, context.getSystemService(UiModeManager.class)));
                context, context.getSystemService(UiModeManager.class)));
        controllers.add(new ForceEnableNotesRolePreferenceController(context));
        controllers.add(new ForceEnableNotesRolePreferenceController(context));
        controllers.add(new GrammaticalGenderPreferenceController(context));
        controllers.add(new GrammaticalGenderPreferenceController(context));
        controllers.add(new SensitiveContentProtectionPreferenceController(context));


        return controllers;
        return controllers;
    }
    }
+3 −0
Original line number Original line Diff line number Diff line
# GameDefaultFrameRatePreferenceController
# GameDefaultFrameRatePreferenceController
per-file GameDefaultFrameRatePreferenceController.java=file:platform/frameworks/base:/GAME_MANAGER_OWNERS
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
# ShowHdrSdrRatioPreferenceController
per-file ShowHdrSdrRatioPreferenceController.java=file:platform/frameworks/native:/services/surfaceflinger/OWNERS
per-file ShowHdrSdrRatioPreferenceController.java=file:platform/frameworks/native:/services/surfaceflinger/OWNERS


+79 −0
Original line number Original line 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