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

Commit bf6d06dd authored by Ebru Kurnaz's avatar Ebru Kurnaz
Browse files

Do not add size preference if display is in mirroring mode.

Flag: com.android.settings.flags.display_size_connected_display_setting
Bug: 404679607
Test: atest ExternalDisplayPreferenceFragmentTest
Change-Id: Ib04fd71165beb5c3c0ac53c59a0e619244bbd58b
parent 12f9d7d8
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static com.android.settings.connecteddevice.display.ExternalDisplaySettin
import static com.android.settings.connecteddevice.display.ExternalDisplaySettingsConfiguration.isRotationSettingEnabled;
import static com.android.settings.connecteddevice.display.ExternalDisplaySettingsConfiguration.isTopologyPaneEnabled;
import static com.android.settings.connecteddevice.display.ExternalDisplaySettingsConfiguration.isUseDisplaySettingEnabled;
import static com.android.settings.connecteddevice.display.ExternalDisplayUtilsKt.isDisplayInMiroringMode;

import android.app.Activity;
import android.app.settings.SettingsEnums;
@@ -442,7 +443,7 @@ public class ExternalDisplayPreferenceFragment extends SettingsPreferenceFragmen
                        context, refresh, EXTERNAL_DISPLAY_CHANGE_RESOLUTION_FOOTER_RESOURCE);
            }
        }
        if (isDisplaySizeSettingEnabled(mInjector)) {
        if (isDisplaySizeSettingEnabled(mInjector) && !isDisplayInMiroringMode(context)) {
            addSizePreference(context, refresh, display, position);
        }
    }
+32 −0
Original line number Diff line number Diff line
/*
 * Copyright 2025 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.connecteddevice.display

import android.content.Context
import android.provider.Settings
import android.window.DesktopExperienceFlags


fun isDisplayInMiroringMode(context: Context) =
    if (DesktopExperienceFlags.ENABLE_DISPLAY_CONTENT_MODE_MANAGEMENT.isTrue) {
        0 != Settings.Secure.getInt(context.contentResolver,
            Settings.Secure.MIRROR_BUILT_IN_DISPLAY, 0)
    } else {
        0 == Settings.Global.getInt(
            context.contentResolver,
            Settings.Global.DEVELOPMENT_FORCE_DESKTOP_MODE_ON_EXTERNAL_DISPLAYS, 0)
    }
+1 −7
Original line number Diff line number Diff line
@@ -34,13 +34,7 @@ class MirrorPreference(context: Context, val contentModeEnabled: Boolean):
        super.onAttached()

        isEnabled = contentModeEnabled
        if (contentModeEnabled) {
            setChecked(0 != Settings.Secure.getInt(context.contentResolver, MIRROR_SETTING, 0))
        } else {
            setChecked(0 == Settings.Global.getInt(
                    context.contentResolver,
                    Settings.Global.DEVELOPMENT_FORCE_DESKTOP_MODE_ON_EXTERNAL_DISPLAYS, 0))
        }
        isChecked = isDisplayInMiroringMode(context)
    }

    override fun onClick() {
+30 −0
Original line number Diff line number Diff line
@@ -16,7 +16,9 @@
package com.android.settings.connecteddevice.display;

import static android.view.Display.INVALID_DISPLAY;
import static android.provider.Settings.Secure.MIRROR_BUILT_IN_DISPLAY;

import static com.android.server.display.feature.flags.Flags.FLAG_ENABLE_DISPLAY_CONTENT_MODE_MANAGEMENT;
import static com.android.settings.connecteddevice.display.ExternalDisplayPreferenceFragment.EXTERNAL_DISPLAY_CHANGE_RESOLUTION_FOOTER_RESOURCE;
import static com.android.settings.connecteddevice.display.ExternalDisplayPreferenceFragment.EXTERNAL_DISPLAY_NOT_FOUND_FOOTER_RESOURCE;
import static com.android.settings.connecteddevice.display.ExternalDisplayPreferenceFragment.EXTERNAL_DISPLAY_SETTINGS_RESOURCE;
@@ -37,6 +39,8 @@ import static org.mockito.Mockito.verify;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.platform.test.annotations.EnableFlags;
import android.provider.Settings;
import android.view.View;
import android.widget.TextView;

@@ -247,6 +251,32 @@ public class ExternalDisplayPreferenceFragmentTest extends ExternalDisplayTestBa
                .isEqualTo(getText(EXTERNAL_DISPLAY_CHANGE_RESOLUTION_FOOTER_RESOURCE));
    }

    @Test
    @UiThreadTest
    @EnableFlags(FLAG_ENABLE_DISPLAY_CONTENT_MODE_MANAGEMENT)
    public void testShowEnabledDisplay_displaySizeDisabled_isInMirrorMode_doNotShowSizePref() {
        // Mirror built in display
        Settings.Secure.putInt(
                mContext.getContentResolver(), MIRROR_BUILT_IN_DISPLAY, 1);
        // Only one display available
        doReturn(List.of(mDisplays.get(0))).when(mMockedInjector).getConnectedDisplays();
        // Init
        initFragment();
        mHandler.flush();
        assertDisplayListCount(1);
        var category = getExternalDisplayCategory(0);
        var pref = category.findPreference(PrefBasics.EXTERNAL_DISPLAY_RESOLUTION.keyForNth(0));
        assertThat(pref).isNotNull();
        pref = category.findPreference(PrefBasics.EXTERNAL_DISPLAY_ROTATION.keyForNth(0));
        assertThat(pref).isNotNull();
        var footerPref = category.findPreference(PrefBasics.FOOTER.key);
        assertThat(footerPref).isNotNull();
        var sizePref = category.findPreference(PrefBasics.EXTERNAL_DISPLAY_SIZE.keyForNth(0));
        assertThat(sizePref).isNull();
        assertThat("" + footerPref.getTitle())
                .isEqualTo(getText(EXTERNAL_DISPLAY_CHANGE_RESOLUTION_FOOTER_RESOURCE));
    }

    @Test
    @UiThreadTest
    public void testShowEnabledDisplay_OnlyOneDisplayAvailable() {