Merge "The legacy magnification controller APIs controls only full-screen magnification"

This commit is contained in:
Minche Li
2021-12-14 02:20:08 +00:00
committed by Android (Google) Code Review
5 changed files with 99 additions and 103 deletions

View File

@@ -1394,6 +1394,12 @@ public abstract class AccessibilityService extends Service {
* {@link AccessibilityService#onServiceConnected()} has not yet been
* called) or the service has been disconnected, this method will
* return a default value of {@code 1.0f}.
* </p>
* <p>
* <strong>Note:</strong> This legacy API gets the scale of full-screen
* magnification. To get the scale of the current controlling magnifier,
* use {@link #getMagnificationConfig} instead.
* </p>
*
* @return the current magnification scale
*/
@@ -1422,6 +1428,12 @@ public abstract class AccessibilityService extends Service {
* {@link AccessibilityService#onServiceConnected()} has not yet been
* called) or the service has been disconnected, this method will
* return a default value of {@code 0.0f}.
* </p>
* <p>
* <strong>Note:</strong> This legacy API gets the center position of full-screen
* magnification. To get the magnification center of the current controlling magnifier,
* use {@link #getMagnificationConfig} instead.
* </p>
*
* @return the unscaled screen-relative X coordinate of the center of
* the magnified region
@@ -1451,6 +1463,12 @@ public abstract class AccessibilityService extends Service {
* {@link AccessibilityService#onServiceConnected()} has not yet been
* called) or the service has been disconnected, this method will
* return a default value of {@code 0.0f}.
* </p>
* <p>
* <strong>Note:</strong> This legacy API gets the center position of full-screen
* magnification. To get the magnification center of the current controlling magnifier,
* use {@link #getMagnificationConfig} instead.
* </p>
*
* @return the unscaled screen-relative Y coordinate of the center of
* the magnified region
@@ -1571,6 +1589,11 @@ public abstract class AccessibilityService extends Service {
* {@link AccessibilityService#onServiceConnected()} has not yet been
* called) or the service has been disconnected, this method will have
* no effect and return {@code false}.
* <p>
* <strong>Note:</strong> This legacy API sets the scale of full-screen
* magnification. To set the scale of the specified magnifier,
* use {@link #setMagnificationConfig} instead.
* </p>
*
* @param scale the magnification scale to set, must be >= 1 and <= 8
* @param animate {@code true} to animate from the current scale or
@@ -1602,6 +1625,12 @@ public abstract class AccessibilityService extends Service {
* {@link AccessibilityService#onServiceConnected()} has not yet been
* called) or the service has been disconnected, this method will have
* no effect and return {@code false}.
* </p>
* <p>
* <strong>Note:</strong> This legacy API sets the center of full-screen
* magnification. To set the center of the specified magnifier,
* use {@link #setMagnificationConfig} instead.
* </p>
*
* @param centerX the unscaled screen-relative X coordinate on which to
* center the viewport

View File

@@ -1027,8 +1027,8 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ
mSystemSupport.getMagnificationProcessor();
final long identity = Binder.clearCallingIdentity();
try {
magnificationProcessor.getMagnificationRegion(displayId, region,
mSecurityPolicy.canControlMagnification(this));
magnificationProcessor.getFullscreenMagnificationRegion(displayId,
region, mSecurityPolicy.canControlMagnification(this));
return region;
} finally {
Binder.restoreCallingIdentity(identity);
@@ -1095,7 +1095,7 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ
try {
MagnificationProcessor magnificationProcessor =
mSystemSupport.getMagnificationProcessor();
return (magnificationProcessor.reset(displayId, animate)
return (magnificationProcessor.resetFullscreenMagnification(displayId, animate)
|| !magnificationProcessor.isMagnifying(displayId));
} finally {
Binder.restoreCallingIdentity(identity);

View File

@@ -119,6 +119,18 @@ public class MagnificationProcessor {
return false;
}
private boolean setScaleAndCenterForFullScreenMagnification(int displayId, float scale,
float centerX, float centerY,
boolean animate, int id) {
if (!isRegistered(displayId)) {
register(displayId);
}
return mController.getFullScreenMagnificationController().setScaleAndCenter(
displayId,
scale,
centerX, centerY, animate, id);
}
/**
* Returns {@code true} if transition magnification mode needed. And it is no need to transition
* mode when the controlling mode is unchanged or the controlling magnifier is not activated.
@@ -135,24 +147,18 @@ public class MagnificationProcessor {
}
/**
* Returns the magnification scale. If an animation is in progress,
* this reflects the end state of the animation.
* Returns the magnification scale of full-screen magnification on the display.
* If an animation is in progress, this reflects the end state of the animation.
*
* @param displayId The logical display id.
* @return the scale
*/
public float getScale(int displayId) {
int mode = getControllingMode(displayId);
if (mode == MAGNIFICATION_MODE_FULLSCREEN) {
return mController.getFullScreenMagnificationController().getScale(displayId);
} else if (mode == MAGNIFICATION_MODE_WINDOW) {
return mController.getWindowMagnificationMgr().getScale(displayId);
}
return 0;
return mController.getFullScreenMagnificationController().getScale(displayId);
}
/**
* Returns the magnification center in X coordinate of the controlling magnification mode.
* Returns the magnification center in X coordinate of full-screen magnification.
* If the service can control magnification but fullscreen magnifier is not registered, it will
* register the magnifier for this call then unregister the magnifier finally to make the
* magnification center correct.
@@ -162,25 +168,19 @@ public class MagnificationProcessor {
* @return the X coordinate
*/
public float getCenterX(int displayId, boolean canControlMagnification) {
int mode = getControllingMode(displayId);
if (mode == MAGNIFICATION_MODE_FULLSCREEN) {
boolean registeredJustForThisCall = registerDisplayMagnificationIfNeeded(displayId,
canControlMagnification);
try {
return mController.getFullScreenMagnificationController().getCenterX(displayId);
} finally {
if (registeredJustForThisCall) {
unregister(displayId);
}
boolean registeredJustForThisCall = registerDisplayMagnificationIfNeeded(displayId,
canControlMagnification);
try {
return mController.getFullScreenMagnificationController().getCenterX(displayId);
} finally {
if (registeredJustForThisCall) {
unregister(displayId);
}
} else if (mode == MAGNIFICATION_MODE_WINDOW) {
return mController.getWindowMagnificationMgr().getCenterX(displayId);
}
return 0;
}
/**
* Returns the magnification center in Y coordinate of the controlling magnification mode.
* Returns the magnification center in Y coordinate of full-screen magnification.
* If the service can control magnification but fullscreen magnifier is not registered, it will
* register the magnifier for this call then unregister the magnifier finally to make the
* magnification center correct.
@@ -190,49 +190,25 @@ public class MagnificationProcessor {
* @return the Y coordinate
*/
public float getCenterY(int displayId, boolean canControlMagnification) {
int mode = getControllingMode(displayId);
if (mode == MAGNIFICATION_MODE_FULLSCREEN) {
boolean registeredJustForThisCall = registerDisplayMagnificationIfNeeded(displayId,
canControlMagnification);
try {
return mController.getFullScreenMagnificationController().getCenterY(displayId);
} finally {
if (registeredJustForThisCall) {
unregister(displayId);
}
boolean registeredJustForThisCall = registerDisplayMagnificationIfNeeded(displayId,
canControlMagnification);
try {
return mController.getFullScreenMagnificationController().getCenterY(displayId);
} finally {
if (registeredJustForThisCall) {
unregister(displayId);
}
} else if (mode == MAGNIFICATION_MODE_WINDOW) {
return mController.getWindowMagnificationMgr().getCenterY(displayId);
}
return 0;
}
/**
* Return the magnification bounds of the current controlling magnification on the given
* display. If the magnifier is not enabled, it returns an empty region.
* If the service can control magnification but fullscreen magnifier is not registered, it will
* register the magnifier for this call then unregister the magnifier finally to make
* the magnification region correct.
* Returns the magnification bounds of full-screen magnification on the given display.
*
* @param displayId The logical display id
* @param outRegion the region to populate
* @param canControlMagnification Whether the service can control magnification
* @return outRegion the magnification bounds of full-screen magnifier or the magnification
* source bounds of window magnifier
*/
public Region getMagnificationRegion(int displayId, @NonNull Region outRegion,
boolean canControlMagnification) {
int mode = getControllingMode(displayId);
if (mode == MAGNIFICATION_MODE_FULLSCREEN) {
getFullscreenMagnificationRegion(displayId, outRegion, canControlMagnification);
} else if (mode == MAGNIFICATION_MODE_WINDOW) {
mController.getWindowMagnificationMgr().getMagnificationSourceBounds(displayId,
outRegion);
}
return outRegion;
}
private void getFullscreenMagnificationRegion(int displayId, @NonNull Region outRegion,
public void getFullscreenMagnificationRegion(int displayId, @NonNull Region outRegion,
boolean canControlMagnification) {
boolean registeredJustForThisCall = registerDisplayMagnificationIfNeeded(displayId,
canControlMagnification);
@@ -246,21 +222,9 @@ public class MagnificationProcessor {
}
}
private boolean setScaleAndCenterForFullScreenMagnification(int displayId, float scale,
float centerX, float centerY,
boolean animate, int id) {
if (!isRegistered(displayId)) {
register(displayId);
}
return mController.getFullScreenMagnificationController().setScaleAndCenter(
displayId,
scale,
centerX, centerY, animate, id);
}
/**
* Resets the magnification on the given display. The reset mode could be full-screen or
* window if it is activated.
* Resets the current magnification on the given display. The reset mode could be
* full-screen or window if it is activated.
*
* @param displayId The logical display id.
* @param animate {@code true} to animate the transition, {@code false}
@@ -268,7 +232,7 @@ public class MagnificationProcessor {
* @return {@code true} if the magnification spec changed, {@code false} if
* the spec did not change
*/
public boolean reset(int displayId, boolean animate) {
public boolean resetCurrentMagnification(int displayId, boolean animate) {
int mode = getControllingMode(displayId);
if (mode == MAGNIFICATION_MODE_FULLSCREEN) {
return mController.getFullScreenMagnificationController().reset(displayId, animate);
@@ -278,6 +242,19 @@ public class MagnificationProcessor {
return false;
}
/**
* Resets the full-screen magnification on the given display.
*
* @param displayId The logical display id.
* @param animate {@code true} to animate the transition, {@code false}
* to transition immediately
* @return {@code true} if the magnification spec changed, {@code false} if
* the spec did not change
*/
public boolean resetFullscreenMagnification(int displayId, boolean animate) {
return mController.getFullScreenMagnificationController().reset(displayId, animate);
}
/**
* {@link FullScreenMagnificationController#resetIfNeeded(int, boolean)}
*/

View File

@@ -585,8 +585,8 @@ public class AbstractAccessibilityServiceConnectionTest {
doAnswer((invocation) -> {
((Region) invocation.getArguments()[1]).set(region);
return null;
}).when(mMockMagnificationProcessor).getMagnificationRegion(eq(displayId),
any(), anyBoolean());
}).when(mMockMagnificationProcessor).getFullscreenMagnificationRegion(eq(displayId), any(),
anyBoolean());
when(mMockSystemSupport.getCurrentUserIdLocked()).thenReturn(USER_ID2);
final Region result = mServiceConnection.getMagnificationRegion(displayId);
@@ -620,7 +620,8 @@ public class AbstractAccessibilityServiceConnectionTest {
@Test
public void resetMagnification() {
final int displayId = 1;
when(mMockMagnificationProcessor.reset(displayId, true)).thenReturn(true);
when(mMockMagnificationProcessor.resetFullscreenMagnification(displayId, true)).thenReturn(
true);
final boolean result = mServiceConnection.resetMagnification(displayId, true);
assertThat(result, is(true));
@@ -629,7 +630,8 @@ public class AbstractAccessibilityServiceConnectionTest {
@Test
public void resetMagnification_cantControlMagnification_returnFalse() {
final int displayId = 1;
when(mMockMagnificationProcessor.reset(displayId, true)).thenReturn(true);
when(mMockMagnificationProcessor.resetFullscreenMagnification(displayId, true)).thenReturn(
true);
when(mMockSecurityPolicy.canControlMagnification(mServiceConnection)).thenReturn(false);
final boolean result = mServiceConnection.resetMagnification(displayId, true);
@@ -639,7 +641,8 @@ public class AbstractAccessibilityServiceConnectionTest {
@Test
public void resetMagnification_serviceNotBelongCurrentUser_returnFalse() {
final int displayId = 1;
when(mMockMagnificationProcessor.reset(displayId, true)).thenReturn(true);
when(mMockMagnificationProcessor.resetFullscreenMagnification(displayId, true)).thenReturn(
true);
when(mMockSystemSupport.getCurrentUserIdLocked()).thenReturn(USER_ID2);
final boolean result = mServiceConnection.resetMagnification(displayId, true);

View File

@@ -98,7 +98,7 @@ public class MagnificationProcessorTest {
.setScale(TEST_SCALE).build();
setMagnificationActivated(TEST_DISPLAY, config);
float scale = mMagnificationProcessor.getScale(TEST_DISPLAY);
float scale = mMagnificationProcessor.getMagnificationConfig(TEST_DISPLAY).getScale();
assertEquals(scale, TEST_SCALE, 0);
}
@@ -111,20 +111,19 @@ public class MagnificationProcessorTest {
setMagnificationActivated(TEST_DISPLAY, config);
float centerX = mMagnificationProcessor.getCenterX(
TEST_DISPLAY, /* canControlMagnification= */true);
TEST_DISPLAY, /* canControlMagnification= */true);
assertEquals(centerX, TEST_CENTER_X, 0);
}
@Test
public void getCenterX_canControlWindowMagnification_returnCenterX() {
public void getCenterX_controlWindowMagnification_returnCenterX() {
final MagnificationConfig config = new MagnificationConfig.Builder()
.setMode(MAGNIFICATION_MODE_WINDOW)
.setCenterX(TEST_CENTER_X).build();
setMagnificationActivated(TEST_DISPLAY, config);
float centerX = mMagnificationProcessor.getCenterX(
TEST_DISPLAY, /* canControlMagnification= */true);
float centerX = mMagnificationProcessor.getMagnificationConfig(TEST_DISPLAY).getCenterX();
assertEquals(centerX, TEST_CENTER_X, 0);
}
@@ -143,14 +142,13 @@ public class MagnificationProcessorTest {
}
@Test
public void getCenterY_canControlWindowMagnification_returnCenterY() {
public void getCenterY_controlWindowMagnification_returnCenterY() {
final MagnificationConfig config = new MagnificationConfig.Builder()
.setMode(MAGNIFICATION_MODE_WINDOW)
.setCenterY(TEST_CENTER_Y).build();
setMagnificationActivated(TEST_DISPLAY, config);
float centerY = mMagnificationProcessor.getCenterY(
TEST_DISPLAY, /* canControlMagnification= */false);
float centerY = mMagnificationProcessor.getMagnificationConfig(TEST_DISPLAY).getCenterY();
assertEquals(centerY, TEST_CENTER_Y, 0);
}
@@ -159,24 +157,13 @@ public class MagnificationProcessorTest {
public void getMagnificationRegion_canControlFullscreenMagnification_returnRegion() {
final Region region = new Region(10, 20, 100, 200);
setMagnificationActivated(TEST_DISPLAY, MAGNIFICATION_MODE_FULLSCREEN);
mMagnificationProcessor.getMagnificationRegion(TEST_DISPLAY,
mMagnificationProcessor.getFullscreenMagnificationRegion(TEST_DISPLAY,
region, /* canControlMagnification= */true);
verify(mMockFullScreenMagnificationController).getMagnificationRegion(eq(TEST_DISPLAY),
eq(region));
}
@Test
public void getMagnificationRegion_canControlWindowMagnification_returnRegion() {
final Region region = new Region(10, 20, 100, 200);
setMagnificationActivated(TEST_DISPLAY, MAGNIFICATION_MODE_WINDOW);
mMagnificationProcessor.getMagnificationRegion(TEST_DISPLAY,
region, /* canControlMagnification= */true);
verify(mMockWindowMagnificationManager).getMagnificationSourceBounds(eq(TEST_DISPLAY),
eq(region));
}
@Test
public void getMagnificationRegion_fullscreenModeNotRegistered_shouldRegisterThenUnregister() {
final Region region = new Region(10, 20, 100, 200);
@@ -188,7 +175,7 @@ public class MagnificationProcessorTest {
any());
final Region result = new Region();
mMagnificationProcessor.getMagnificationRegion(TEST_DISPLAY,
mMagnificationProcessor.getFullscreenMagnificationRegion(TEST_DISPLAY,
result, /* canControlMagnification= */true);
assertEquals(region, result);
verify(mMockFullScreenMagnificationController).register(TEST_DISPLAY);
@@ -237,7 +224,7 @@ public class MagnificationProcessorTest {
public void reset_fullscreenMagnificationActivated() {
setMagnificationActivated(TEST_DISPLAY, MAGNIFICATION_MODE_FULLSCREEN);
mMagnificationProcessor.reset(TEST_DISPLAY, /* animate= */false);
mMagnificationProcessor.resetFullscreenMagnification(TEST_DISPLAY, /* animate= */false);
verify(mMockFullScreenMagnificationController).reset(TEST_DISPLAY, false);
}
@@ -246,7 +233,7 @@ public class MagnificationProcessorTest {
public void reset_windowMagnificationActivated() {
setMagnificationActivated(TEST_DISPLAY, MAGNIFICATION_MODE_WINDOW);
mMagnificationProcessor.reset(TEST_DISPLAY, /* animate= */false);
mMagnificationProcessor.resetCurrentMagnification(TEST_DISPLAY, /* animate= */false);
verify(mMockWindowMagnificationManager).reset(TEST_DISPLAY);
}