Loading services/accessibility/java/com/android/server/accessibility/magnification/FullScreenMagnificationController.java +2 −2 Original line number Diff line number Diff line Loading @@ -47,7 +47,6 @@ import android.util.MathUtils; import android.util.Slog; import android.util.SparseArray; import android.util.TypedValue; import android.view.Display; import android.view.DisplayInfo; import android.view.MagnificationSpec; import android.view.View; Loading Loading @@ -1637,9 +1636,10 @@ public class FullScreenMagnificationController implements * <strong>if scale is >= {@link MagnificationConstants.PERSISTED_SCALE_MIN_VALUE}</strong>. * We assume if the scale is < {@link MagnificationConstants.PERSISTED_SCALE_MIN_VALUE}, there * will be no obvious magnification effect. * Only the value of the default display is persisted in user's settings. */ public void persistScale(int displayId) { final float scale = getScale(Display.DEFAULT_DISPLAY); final float scale = getScale(displayId); if (scale < MagnificationConstants.PERSISTED_SCALE_MIN_VALUE) { return; } Loading services/tests/servicestests/src/com/android/server/accessibility/magnification/FullScreenMagnificationControllerTest.java +36 −1 Original line number Diff line number Diff line Loading @@ -69,6 +69,7 @@ import androidx.test.InstrumentationRegistry; import androidx.test.runner.AndroidJUnit4; import com.android.internal.R; import com.android.internal.os.BackgroundThread; import com.android.internal.util.ConcurrentUtils; import com.android.internal.util.test.FakeSettingsProvider; import com.android.server.LocalServices; Loading @@ -92,6 +93,8 @@ import org.mockito.stubbing.Answer; import org.testng.Assert; import java.util.Locale; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; @RunWith(AndroidJUnit4.class) public class FullScreenMagnificationControllerTest { Loading Loading @@ -1440,18 +1443,41 @@ public class FullScreenMagnificationControllerTest { @Test public void persistScale_setValueWhenScaleIsOne_nothingChanged() { register(TEST_DISPLAY); final float persistedScale = mFullScreenMagnificationController.getPersistedScale(TEST_DISPLAY); PointF pivotPoint = INITIAL_BOUNDS_LOWER_RIGHT_2X_CENTER; mFullScreenMagnificationController.setScale(DISPLAY_0, 1.0f, pivotPoint.x, pivotPoint.y, mFullScreenMagnificationController.setScale(TEST_DISPLAY, 1.0f, pivotPoint.x, pivotPoint.y, false, SERVICE_ID_1); mFullScreenMagnificationController.persistScale(TEST_DISPLAY); // persistScale may post a task to a background thread. Let's wait for it completes. waitForBackgroundThread(); Assert.assertEquals(mFullScreenMagnificationController.getPersistedScale(TEST_DISPLAY), persistedScale); } @Test public void persistScale_setValuesOnMultipleDisplays() { register(DISPLAY_0); register(DISPLAY_1); final PointF pivotPoint = INITIAL_BOUNDS_LOWER_RIGHT_2X_CENTER; mFullScreenMagnificationController.setScale(DISPLAY_0, 3.0f, pivotPoint.x, pivotPoint.y, false, SERVICE_ID_1); mFullScreenMagnificationController.persistScale(DISPLAY_0); mFullScreenMagnificationController.setScale(DISPLAY_1, 4.0f, pivotPoint.x, pivotPoint.y, false, SERVICE_ID_1); mFullScreenMagnificationController.persistScale(DISPLAY_1); // persistScale may post a task to a background thread. Let's wait for it completes. waitForBackgroundThread(); Assert.assertEquals(mFullScreenMagnificationController.getPersistedScale(DISPLAY_0), 3.0f); Assert.assertEquals(mFullScreenMagnificationController.getPersistedScale(DISPLAY_1), 4.0f); } @Test public void testOnContextChanged_alwaysOnFeatureDisabled_resetMagnification() { setScaleToMagnifying(); Loading Loading @@ -1494,6 +1520,15 @@ public class FullScreenMagnificationControllerTest { ); } private static void waitForBackgroundThread() { final CompletableFuture<Void> future = new CompletableFuture<>(); BackgroundThread.getHandler().post(() -> future.complete(null)); try { future.get(); } catch (InterruptedException | ExecutionException ignore) { } } private void setScaleToMagnifying() { register(DISPLAY_0); float scale = 2.0f; Loading Loading
services/accessibility/java/com/android/server/accessibility/magnification/FullScreenMagnificationController.java +2 −2 Original line number Diff line number Diff line Loading @@ -47,7 +47,6 @@ import android.util.MathUtils; import android.util.Slog; import android.util.SparseArray; import android.util.TypedValue; import android.view.Display; import android.view.DisplayInfo; import android.view.MagnificationSpec; import android.view.View; Loading Loading @@ -1637,9 +1636,10 @@ public class FullScreenMagnificationController implements * <strong>if scale is >= {@link MagnificationConstants.PERSISTED_SCALE_MIN_VALUE}</strong>. * We assume if the scale is < {@link MagnificationConstants.PERSISTED_SCALE_MIN_VALUE}, there * will be no obvious magnification effect. * Only the value of the default display is persisted in user's settings. */ public void persistScale(int displayId) { final float scale = getScale(Display.DEFAULT_DISPLAY); final float scale = getScale(displayId); if (scale < MagnificationConstants.PERSISTED_SCALE_MIN_VALUE) { return; } Loading
services/tests/servicestests/src/com/android/server/accessibility/magnification/FullScreenMagnificationControllerTest.java +36 −1 Original line number Diff line number Diff line Loading @@ -69,6 +69,7 @@ import androidx.test.InstrumentationRegistry; import androidx.test.runner.AndroidJUnit4; import com.android.internal.R; import com.android.internal.os.BackgroundThread; import com.android.internal.util.ConcurrentUtils; import com.android.internal.util.test.FakeSettingsProvider; import com.android.server.LocalServices; Loading @@ -92,6 +93,8 @@ import org.mockito.stubbing.Answer; import org.testng.Assert; import java.util.Locale; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; @RunWith(AndroidJUnit4.class) public class FullScreenMagnificationControllerTest { Loading Loading @@ -1440,18 +1443,41 @@ public class FullScreenMagnificationControllerTest { @Test public void persistScale_setValueWhenScaleIsOne_nothingChanged() { register(TEST_DISPLAY); final float persistedScale = mFullScreenMagnificationController.getPersistedScale(TEST_DISPLAY); PointF pivotPoint = INITIAL_BOUNDS_LOWER_RIGHT_2X_CENTER; mFullScreenMagnificationController.setScale(DISPLAY_0, 1.0f, pivotPoint.x, pivotPoint.y, mFullScreenMagnificationController.setScale(TEST_DISPLAY, 1.0f, pivotPoint.x, pivotPoint.y, false, SERVICE_ID_1); mFullScreenMagnificationController.persistScale(TEST_DISPLAY); // persistScale may post a task to a background thread. Let's wait for it completes. waitForBackgroundThread(); Assert.assertEquals(mFullScreenMagnificationController.getPersistedScale(TEST_DISPLAY), persistedScale); } @Test public void persistScale_setValuesOnMultipleDisplays() { register(DISPLAY_0); register(DISPLAY_1); final PointF pivotPoint = INITIAL_BOUNDS_LOWER_RIGHT_2X_CENTER; mFullScreenMagnificationController.setScale(DISPLAY_0, 3.0f, pivotPoint.x, pivotPoint.y, false, SERVICE_ID_1); mFullScreenMagnificationController.persistScale(DISPLAY_0); mFullScreenMagnificationController.setScale(DISPLAY_1, 4.0f, pivotPoint.x, pivotPoint.y, false, SERVICE_ID_1); mFullScreenMagnificationController.persistScale(DISPLAY_1); // persistScale may post a task to a background thread. Let's wait for it completes. waitForBackgroundThread(); Assert.assertEquals(mFullScreenMagnificationController.getPersistedScale(DISPLAY_0), 3.0f); Assert.assertEquals(mFullScreenMagnificationController.getPersistedScale(DISPLAY_1), 4.0f); } @Test public void testOnContextChanged_alwaysOnFeatureDisabled_resetMagnification() { setScaleToMagnifying(); Loading Loading @@ -1494,6 +1520,15 @@ public class FullScreenMagnificationControllerTest { ); } private static void waitForBackgroundThread() { final CompletableFuture<Void> future = new CompletableFuture<>(); BackgroundThread.getHandler().post(() -> future.complete(null)); try { future.get(); } catch (InterruptedException | ExecutionException ignore) { } } private void setScaleToMagnifying() { register(DISPLAY_0); float scale = 2.0f; Loading