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

Commit 5776f600 authored by Roy Chou's avatar Roy Chou
Browse files

fix(magnification): draggable bounds of the settings panel is not correctly computed

The original computation of the settings panel dragging area bounds is not correct, so the settings panel would cover the gestural navigation bar area. It causes tapping on the bottom of the panel Done button would be also detected as tapping on the navigation bar, so it would trigger the window transition then make the fullscreen magnification zoom out. Therefore, we fix the computation to prevent the panel from covering the system bar area.

We also add test case in WindowMagnificationSettingsTest to verify the dragging bounds computation is expected.

Bug: 311319434
Flag: none
Test: manually
      atest WindowMagnificationSettingsTest
Change-Id: Iec81c544d3498ff02451b8ca1461c579846e52ac
parent a8c95e52
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -59,8 +59,8 @@ import android.widget.TextView;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.graphics.SfVsyncFrameCallbackProvider;
import com.android.systemui.res.R;
import com.android.systemui.common.ui.view.SeekBarWithIconButtonsView;
import com.android.systemui.res.R;
import com.android.systemui.util.settings.SecureSettings;

import java.lang.annotation.Retention;
@@ -671,17 +671,17 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest
    }

    private Rect getDraggableWindowBounds() {
        final int layoutMargin = mContext.getResources().getDimensionPixelSize(
                R.dimen.magnification_switch_button_margin);
        final WindowMetrics windowMetrics = mWindowManager.getCurrentWindowMetrics();
        final Insets windowInsets = windowMetrics.getWindowInsets().getInsetsIgnoringVisibility(
                WindowInsets.Type.systemBars() | WindowInsets.Type.displayCutout());
        // re-measure the settings panel view so that we can get the correct view size to inset
        int unspecificSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
        mSettingView.measure(unspecificSpec, unspecificSpec);

        final Rect boundRect = new Rect(windowMetrics.getBounds());
        boundRect.offsetTo(0, 0);
        boundRect.inset(0, 0, mParams.width, mParams.height);
        boundRect.inset(0, 0, mSettingView.getMeasuredWidth(), mSettingView.getMeasuredHeight());
        boundRect.inset(windowInsets);
        boundRect.inset(layoutMargin, layoutMargin);

        return boundRect;
    }

+40 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.provider.Settings.Secure.ACCESSIBILITY_MAGNIFICATION_CAPAB
import static android.provider.Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_ALL;
import static android.provider.Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN;
import static android.provider.Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW;
import static android.view.WindowInsets.Type.systemBars;

import static com.google.common.truth.Truth.assertThat;

@@ -42,6 +43,7 @@ import android.annotation.IdRes;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.database.ContentObserver;
import android.graphics.Insets;
import android.graphics.Rect;
import android.os.UserHandle;
import android.provider.Settings;
@@ -49,6 +51,7 @@ import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowInsets;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityManager;
import android.widget.Button;
@@ -59,10 +62,10 @@ import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;

import com.android.internal.graphics.SfVsyncFrameCallbackProvider;
import com.android.systemui.res.R;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.common.ui.view.SeekBarWithIconButtonsView;
import com.android.systemui.common.ui.view.SeekBarWithIconButtonsView.OnSeekBarWithIconButtonsChangeListener;
import com.android.systemui.res.R;
import com.android.systemui.util.settings.SecureSettings;

import org.junit.After;
@@ -313,6 +316,42 @@ public class WindowMagnificationSettingsTest extends SysuiTestCase {
        assertThat(magnifierMediumButton.isSelected()).isTrue();
    }

    @Test
    public void onWindowBoundsChanged_updateDraggableWindowBounds() {
        setupMagnificationCapabilityAndMode(
                /* capability= */ ACCESSIBILITY_MAGNIFICATION_MODE_ALL,
                /* mode= */ ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW);
        mWindowMagnificationSettings.showSettingPanel();

        // get the measured panel view frame size
        final int panelWidth = mSettingView.getMeasuredWidth();
        final int panelHeight = mSettingView.getMeasuredHeight();

        final Rect testWindowBounds = new Rect(10, 20, 1010, 2020);
        final WindowInsets testWindowInsets = new WindowInsets.Builder()
                .setInsetsIgnoringVisibility(systemBars(), Insets.of(100, 200, 100, 200))
                .build();
        mWindowManager.setWindowBounds(testWindowBounds);
        mWindowManager.setWindowInsets(testWindowInsets);

        InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
            mWindowMagnificationSettings.onConfigurationChanged(ActivityInfo.CONFIG_SCREEN_SIZE);
        });

        // the draggable window bounds left/top should be only related to the insets,
        // and the bounds right/bottom should consider the panel frame size
        // inset left (100) = 100
        int expectedLeft = 100;
        // inset top (200) = 200
        int expectedTop = 200;
        // window width (1010 - 10) - inset right (100) - panel width
        int expectedRight = 900 - panelWidth;
        // window height (2020 - 20) - inset bottom (200) - panel height
        int expectedBottom = 1800 - panelHeight;
        Rect expectedBounds = new Rect(expectedLeft, expectedTop, expectedRight, expectedBottom);
        assertThat(mWindowMagnificationSettings.mDraggableWindowBounds).isEqualTo(expectedBounds);
    }

    @Test
    public void onScreenSizeChanged_resetPositionToRightBottomCorner() {
        setupMagnificationCapabilityAndMode(