fix(magnification): make always on toggle unavailable when capabilities is window only

As b/328787031, we make the MagnificationAlwaysOnPreferenceController observe the magnification capabilities then update the preference enabled state. Therefore, when changing the capabilities to window mode only, the preference will become unavailable.

We use the bug-fix flag to verify the fix with rollout process.

Bug: 328787031
Flag: ACONFIG com.android.settings.accessibility.hide_magnification_always_on_toggle_when_window_mode_only DEVELOPMENT
Test: manually flip the flag
      atest MagnificationCapabilitiesTest
      atest ToggleScreenMagnificationPreferenceFragmentTest
      atest MagnificationAlwaysOnPreferenceControllerTest
Change-Id: I1a25f80131d84ecdd927030e40a18ebb32b7862f
This commit is contained in:
Roy Chou
2024-03-25 09:37:42 +00:00
parent d47736635b
commit 1c898252cb
8 changed files with 242 additions and 8 deletions

View File

@@ -18,7 +18,14 @@ package com.android.settings.accessibility;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import android.content.Context;
import android.database.ContentObserver;
import androidx.test.core.app.ApplicationProvider;
@@ -42,7 +49,6 @@ public final class MagnificationCapabilitiesTest {
final int windowCapabilities = MagnificationCapabilities.getCapabilities(mContext);
assertThat(windowCapabilities).isEqualTo(
MagnificationCapabilities.MagnificationMode.WINDOW);
}
@Test
@@ -63,4 +69,35 @@ public final class MagnificationCapabilitiesTest {
assertThat(windowCapabilities).isEqualTo(
MagnificationCapabilities.MagnificationMode.FULLSCREEN);
}
@Test
public void registerObserver_triggeredWhenCapabilitiesChanged() {
MagnificationCapabilities.setCapabilities(mContext,
MagnificationCapabilities.MagnificationMode.FULLSCREEN);
ContentObserver contentObserver =
spy(new ContentObserver(/* handler= */ null) {});
MagnificationCapabilities.registerObserver(mContext, contentObserver);
MagnificationCapabilities.setCapabilities(mContext,
MagnificationCapabilities.MagnificationMode.WINDOW);
verify(contentObserver).onChange(/* selfChange= */ anyBoolean(), /* uri= */ any());
}
@Test
public void unregisterObserver_neverTriggeredWhenCapabilitiesChanged() {
MagnificationCapabilities.setCapabilities(mContext,
MagnificationCapabilities.MagnificationMode.FULLSCREEN);
ContentObserver contentObserver =
spy(new ContentObserver(/* handler= */ null) {});
MagnificationCapabilities.registerObserver(mContext, contentObserver);
MagnificationCapabilities.unregisterObserver(mContext, contentObserver);
MagnificationCapabilities.setCapabilities(mContext,
MagnificationCapabilities.MagnificationMode.WINDOW);
verify(contentObserver, never()).onChange(/* selfChange= */ anyBoolean(), /* uri= */ any());
}
}