chore(#MagSettingsPanel): change persisting scale timing
Originally the Settings presisted scale is updated when the panel seekbar progress is changed or the window magnifier scale is changed by accessibility actions. In WindowMagnificationController we keep the same behavior. In WindowMagnificationSettings, per b/286176069 we change to only update the persisted scale with the seekbar final progress when the user interaction on seekbar is ended. We change the onPerformScaleAction parameters so when sysui call the service to change the magnifier scale, we can decide if the persisted scale should be updated.
Bug: 286176069
Test: manually
atest WindowMagnificationTest
atest MagnificationSettingsControllerTest
atest WindowMagnificationSettingsTest
atest WindowMagnificationControllerTest
atest WindowMagnificationManagerTest
atest MagnificationControllerTest
Change-Id: I995a059c6575298eeae095fb3daa9f037916014a
Merged-In: I995a059c6575298eeae095fb3daa9f037916014a
This commit is contained in:
@@ -57,8 +57,9 @@ import android.graphics.Rect;
|
||||
*
|
||||
* @param displayId The logical display id.
|
||||
* @param scale the target scale, or {@link Float#NaN} to leave unchanged
|
||||
* @param updatePersistence whether the new scale should be persisted in Settings
|
||||
*/
|
||||
void onPerformScaleAction(int displayId, float scale);
|
||||
void onPerformScaleAction(int displayId, float scale, boolean updatePersistence);
|
||||
|
||||
/**
|
||||
* Called when the accessibility action is performed.
|
||||
|
||||
@@ -164,8 +164,9 @@ public class MagnificationSettingsController implements ComponentCallbacks {
|
||||
*
|
||||
* @param displayId The logical display id.
|
||||
* @param scale Magnification scale value.
|
||||
* @param updatePersistence whether the new scale should be persisted.
|
||||
*/
|
||||
void onMagnifierScale(int displayId, float scale);
|
||||
void onMagnifierScale(int displayId, float scale, boolean updatePersistence);
|
||||
|
||||
/**
|
||||
* Called when magnification mode changed.
|
||||
@@ -215,9 +216,9 @@ public class MagnificationSettingsController implements ComponentCallbacks {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMagnifierScale(float scale) {
|
||||
public void onMagnifierScale(float scale, boolean updatePersistence) {
|
||||
mSettingsControllerCallback.onMagnifierScale(mDisplayId,
|
||||
A11Y_ACTION_SCALE_RANGE.clamp(scale));
|
||||
A11Y_ACTION_SCALE_RANGE.clamp(scale), updatePersistence);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -333,9 +333,10 @@ public class WindowMagnification implements CoreStartable, CommandQueue.Callback
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPerformScaleAction(int displayId, float scale) {
|
||||
public void onPerformScaleAction(int displayId, float scale, boolean updatePersistence) {
|
||||
if (mWindowMagnificationConnectionImpl != null) {
|
||||
mWindowMagnificationConnectionImpl.onPerformScaleAction(displayId, scale);
|
||||
mWindowMagnificationConnectionImpl.onPerformScaleAction(
|
||||
displayId, scale, updatePersistence);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -384,9 +385,10 @@ public class WindowMagnification implements CoreStartable, CommandQueue.Callback
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMagnifierScale(int displayId, float scale) {
|
||||
public void onMagnifierScale(int displayId, float scale, boolean updatePersistence) {
|
||||
if (mWindowMagnificationConnectionImpl != null) {
|
||||
mWindowMagnificationConnectionImpl.onPerformScaleAction(displayId, scale);
|
||||
mWindowMagnificationConnectionImpl.onPerformScaleAction(
|
||||
displayId, scale, updatePersistence);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -129,10 +129,10 @@ class WindowMagnificationConnectionImpl extends IWindowMagnificationConnection.S
|
||||
}
|
||||
}
|
||||
|
||||
void onPerformScaleAction(int displayId, float scale) {
|
||||
void onPerformScaleAction(int displayId, float scale, boolean updatePersistence) {
|
||||
if (mConnectionCallback != null) {
|
||||
try {
|
||||
mConnectionCallback.onPerformScaleAction(displayId, scale);
|
||||
mConnectionCallback.onPerformScaleAction(displayId, scale, updatePersistence);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Failed to inform performing scale action", e);
|
||||
}
|
||||
|
||||
@@ -1511,7 +1511,8 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold
|
||||
|
||||
private void performScale(float scale) {
|
||||
scale = A11Y_ACTION_SCALE_RANGE.clamp(scale);
|
||||
mWindowMagnifierCallback.onPerformScaleAction(mDisplayId, scale);
|
||||
mWindowMagnifierCallback.onPerformScaleAction(
|
||||
mDisplayId, scale, /* updatePersistence= */ true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -170,8 +170,10 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest
|
||||
// Notify the service to update the magnifier scale only when the progress changed is
|
||||
// triggered by user interaction on seekbar
|
||||
if (fromUser) {
|
||||
float scale = (progress / (float) mSeekBarMagnitude) + SCALE_MIN_VALUE;
|
||||
mCallback.onMagnifierScale(scale);
|
||||
final float scale = transformProgressToScale(progress);
|
||||
// We don't need to update the persisted scale when the seekbar progress is
|
||||
// changing. The update should be triggered when the changing is ended.
|
||||
mCallback.onMagnifierScale(scale, /* updatePersistence= */ false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,7 +189,14 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest
|
||||
|
||||
@Override
|
||||
public void onUserInteractionFinalized(SeekBar seekBar, @ControlUnitType int control) {
|
||||
// Do nothing
|
||||
// Update the Settings persisted scale only when user interaction with seekbar ends
|
||||
final int progress = seekBar.getProgress();
|
||||
final float scale = transformProgressToScale(progress);
|
||||
mCallback.onMagnifierScale(scale, /* updatePersistence= */ true);
|
||||
}
|
||||
|
||||
private float transformProgressToScale(float progress) {
|
||||
return (progress / (float) mSeekBarMagnitude) + SCALE_MIN_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,8 +52,9 @@ public interface WindowMagnificationSettingsCallback {
|
||||
* Called when set magnification scale.
|
||||
*
|
||||
* @param scale Magnification scale value.
|
||||
* @param updatePersistence whether the scale should be persisted
|
||||
*/
|
||||
void onMagnifierScale(float scale);
|
||||
void onMagnifierScale(float scale, boolean updatePersistence);
|
||||
|
||||
/**
|
||||
* Called when magnification mode changed.
|
||||
|
||||
@@ -44,8 +44,9 @@ interface WindowMagnifierCallback {
|
||||
*
|
||||
* @param displayId The logical display id.
|
||||
* @param scale the target scale, or {@link Float#NaN} to leave unchanged
|
||||
* @param updatePersistence whether the scale should be persisted
|
||||
*/
|
||||
void onPerformScaleAction(int displayId, float scale);
|
||||
void onPerformScaleAction(int displayId, float scale, boolean updatePersistence);
|
||||
|
||||
/**
|
||||
* Called when the accessibility action is performed.
|
||||
|
||||
@@ -153,10 +153,11 @@ public class MagnificationSettingsControllerTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void testPanelOnMagnifierScale_delegateToCallback() {
|
||||
final float scale = 3.0f;
|
||||
final boolean updatePersistence = true;
|
||||
mMagnificationSettingsController.mWindowMagnificationSettingsCallback
|
||||
.onMagnifierScale(scale);
|
||||
.onMagnifierScale(scale, updatePersistence);
|
||||
|
||||
verify(mMagnificationSettingControllerCallback).onMagnifierScale(
|
||||
eq(mContext.getDisplayId()), eq(scale));
|
||||
eq(mContext.getDisplayId()), eq(scale), eq(updatePersistence));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -645,10 +645,12 @@ public class WindowMagnificationControllerTest extends SysuiTestCase {
|
||||
assertTrue(
|
||||
mirrorView.performAccessibilityAction(R.id.accessibility_action_zoom_out, null));
|
||||
// Minimum scale is 1.0.
|
||||
verify(mWindowMagnifierCallback).onPerformScaleAction(eq(displayId), eq(1.0f));
|
||||
verify(mWindowMagnifierCallback).onPerformScaleAction(
|
||||
eq(displayId), /* scale= */ eq(1.0f), /* updatePersistence= */ eq(true));
|
||||
|
||||
assertTrue(mirrorView.performAccessibilityAction(R.id.accessibility_action_zoom_in, null));
|
||||
verify(mWindowMagnifierCallback).onPerformScaleAction(eq(displayId), eq(2.5f));
|
||||
verify(mWindowMagnifierCallback).onPerformScaleAction(
|
||||
eq(displayId), /* scale= */ eq(2.5f), /* updatePersistence= */ eq(true));
|
||||
|
||||
// TODO: Verify the final state when the mirror surface is visible.
|
||||
assertTrue(mirrorView.performAccessibilityAction(R.id.accessibility_action_move_up, null));
|
||||
|
||||
@@ -27,6 +27,7 @@ import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyFloat;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
@@ -438,7 +439,7 @@ public class WindowMagnificationSettingsTest extends SysuiTestCase {
|
||||
mZoomSeekbar.getSeekbar(), /* progress= */ 30, /* fromUser= */ false);
|
||||
|
||||
verify(mWindowMagnificationSettingsCallback, never())
|
||||
.onMagnifierScale(/* scale= */ anyFloat());
|
||||
.onMagnifierScale(/* scale= */ anyFloat(), /* updatePersistence= */ eq(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -471,6 +472,21 @@ public class WindowMagnificationSettingsTest extends SysuiTestCase {
|
||||
verifyCallbackOnMagnifierScale(8f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onSeekbarUserInteractionFinalized_persistedScaleUpdated() {
|
||||
OnSeekBarWithIconButtonsChangeListener onChangeListener =
|
||||
mZoomSeekbar.getOnSeekBarWithIconButtonsChangeListener();
|
||||
|
||||
mZoomSeekbar.setProgress(30);
|
||||
onChangeListener.onUserInteractionFinalized(
|
||||
mZoomSeekbar.getSeekbar(),
|
||||
OnSeekBarWithIconButtonsChangeListener.ControlUnitType.SLIDER);
|
||||
|
||||
// should trigger callback to update magnifier scale and persist the scale
|
||||
verify(mWindowMagnificationSettingsCallback)
|
||||
.onMagnifierScale(/* scale= */ eq(4f), /* updatePersistence= */ eq(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seekbarProgress_scaleUpdatedAfterSettingPanelOpened_progressAlsoUpdated() {
|
||||
setupMagnificationCapabilityAndMode(
|
||||
@@ -486,7 +502,7 @@ public class WindowMagnificationSettingsTest extends SysuiTestCase {
|
||||
|
||||
private void verifyCallbackOnMagnifierScale(float scale) {
|
||||
verify(mWindowMagnificationSettingsCallback)
|
||||
.onMagnifierScale(mCallbackMagnifierScaleCaptor.capture());
|
||||
.onMagnifierScale(mCallbackMagnifierScaleCaptor.capture(), anyBoolean());
|
||||
assertThat(mCallbackMagnifierScaleCaptor.getValue()).isWithin(0.01f).of(scale);
|
||||
}
|
||||
|
||||
|
||||
@@ -163,13 +163,15 @@ public class WindowMagnificationTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void onPerformScaleAction_enabled_notifyCallback() throws RemoteException {
|
||||
final float newScale = 4.0f;
|
||||
final boolean updatePersistence = true;
|
||||
mCommandQueue.requestWindowMagnificationConnection(true);
|
||||
waitForIdleSync();
|
||||
|
||||
mWindowMagnification.mWindowMagnifierCallback
|
||||
.onPerformScaleAction(TEST_DISPLAY, newScale);
|
||||
.onPerformScaleAction(TEST_DISPLAY, newScale, updatePersistence);
|
||||
|
||||
verify(mConnectionCallback).onPerformScaleAction(TEST_DISPLAY, newScale);
|
||||
verify(mConnectionCallback).onPerformScaleAction(
|
||||
eq(TEST_DISPLAY), eq(newScale), eq(updatePersistence));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -249,10 +251,12 @@ public class WindowMagnificationTest extends SysuiTestCase {
|
||||
mCommandQueue.requestWindowMagnificationConnection(true);
|
||||
waitForIdleSync();
|
||||
final float scale = 3.0f;
|
||||
final boolean updatePersistence = false;
|
||||
mWindowMagnification.mMagnificationSettingsControllerCallback.onMagnifierScale(
|
||||
TEST_DISPLAY, scale);
|
||||
TEST_DISPLAY, scale, updatePersistence);
|
||||
|
||||
verify(mConnectionCallback).onPerformScaleAction(eq(TEST_DISPLAY), eq(scale));
|
||||
verify(mConnectionCallback).onPerformScaleAction(
|
||||
eq(TEST_DISPLAY), eq(scale), eq(updatePersistence));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -172,14 +172,18 @@ public class MagnificationController implements WindowMagnificationManager.Callb
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPerformScaleAction(int displayId, float scale) {
|
||||
public void onPerformScaleAction(int displayId, float scale, boolean updatePersistence) {
|
||||
if (getFullScreenMagnificationController().isActivated(displayId)) {
|
||||
getFullScreenMagnificationController().setScaleAndCenter(displayId, scale,
|
||||
Float.NaN, Float.NaN, false, MAGNIFICATION_GESTURE_HANDLER_ID);
|
||||
getFullScreenMagnificationController().persistScale(displayId);
|
||||
if (updatePersistence) {
|
||||
getFullScreenMagnificationController().persistScale(displayId);
|
||||
}
|
||||
} else if (getWindowMagnificationMgr().isWindowMagnifierEnabled(displayId)) {
|
||||
getWindowMagnificationMgr().setScale(displayId, scale);
|
||||
getWindowMagnificationMgr().persistScale(displayId);
|
||||
if (updatePersistence) {
|
||||
getWindowMagnificationMgr().persistScale(displayId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -167,8 +167,9 @@ public class WindowMagnificationManager implements
|
||||
*
|
||||
* @param displayId The logical display id.
|
||||
* @param scale the target scale, or {@link Float#NaN} to leave unchanged
|
||||
* @param updatePersistence whether the scale should be persisted
|
||||
*/
|
||||
void onPerformScaleAction(int displayId, float scale);
|
||||
void onPerformScaleAction(int displayId, float scale, boolean updatePersistence);
|
||||
|
||||
/**
|
||||
* Called when the accessibility action is performed.
|
||||
@@ -977,14 +978,15 @@ public class WindowMagnificationManager implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPerformScaleAction(int displayId, float scale) {
|
||||
public void onPerformScaleAction(int displayId, float scale, boolean updatePersistence) {
|
||||
if (mTrace.isA11yTracingEnabledForTypes(
|
||||
FLAGS_WINDOW_MAGNIFICATION_CONNECTION_CALLBACK)) {
|
||||
mTrace.logTrace(TAG + "ConnectionCallback.onPerformScaleAction",
|
||||
FLAGS_WINDOW_MAGNIFICATION_CONNECTION_CALLBACK,
|
||||
"displayId=" + displayId + ";scale=" + scale);
|
||||
"displayId=" + displayId + ";scale=" + scale
|
||||
+ ";updatePersistence=" + updatePersistence);
|
||||
}
|
||||
mCallback.onPerformScaleAction(displayId, scale);
|
||||
mCallback.onPerformScaleAction(displayId, scale, updatePersistence);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -606,9 +606,10 @@ public class MagnificationControllerTest {
|
||||
public void onPerformScaleAction_fullScreenMagnifierEnabled_handleScaleChange()
|
||||
throws RemoteException {
|
||||
final float newScale = 4.0f;
|
||||
final boolean updatePersistence = true;
|
||||
setMagnificationEnabled(MODE_FULLSCREEN);
|
||||
|
||||
mMagnificationController.onPerformScaleAction(TEST_DISPLAY, newScale);
|
||||
mMagnificationController.onPerformScaleAction(TEST_DISPLAY, newScale, updatePersistence);
|
||||
|
||||
verify(mScreenMagnificationController).setScaleAndCenter(eq(TEST_DISPLAY), eq(newScale),
|
||||
anyFloat(), anyFloat(), anyBoolean(), anyInt());
|
||||
@@ -619,12 +620,13 @@ public class MagnificationControllerTest {
|
||||
public void onPerformScaleAction_windowMagnifierEnabled_handleScaleChange()
|
||||
throws RemoteException {
|
||||
final float newScale = 4.0f;
|
||||
final boolean updatePersistence = false;
|
||||
setMagnificationEnabled(MODE_WINDOW);
|
||||
|
||||
mMagnificationController.onPerformScaleAction(TEST_DISPLAY, newScale);
|
||||
mMagnificationController.onPerformScaleAction(TEST_DISPLAY, newScale, updatePersistence);
|
||||
|
||||
verify(mWindowMagnificationManager).setScale(eq(TEST_DISPLAY), eq(newScale));
|
||||
verify(mWindowMagnificationManager).persistScale(eq(TEST_DISPLAY));
|
||||
verify(mWindowMagnificationManager, never()).persistScale(eq(TEST_DISPLAY));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1310,9 +1312,9 @@ public class MagnificationControllerTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPerformScaleAction(int displayId, float scale) {
|
||||
public void onPerformScaleAction(int displayId, float scale, boolean updatePersistence) {
|
||||
if (mCallback != null) {
|
||||
mCallback.onPerformScaleAction(displayId, scale);
|
||||
mCallback.onPerformScaleAction(displayId, scale, updatePersistence);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -576,12 +576,15 @@ public class WindowMagnificationManagerTest {
|
||||
@Test
|
||||
public void onPerformScaleAction_magnifierEnabled_notifyAction() throws RemoteException {
|
||||
final float newScale = 4.0f;
|
||||
final boolean updatePersistence = true;
|
||||
mWindowMagnificationManager.setConnection(mMockConnection.getConnection());
|
||||
mWindowMagnificationManager.enableWindowMagnification(TEST_DISPLAY, 3.0f, NaN, NaN);
|
||||
|
||||
mMockConnection.getConnectionCallback().onPerformScaleAction(TEST_DISPLAY, newScale);
|
||||
mMockConnection.getConnectionCallback().onPerformScaleAction(
|
||||
TEST_DISPLAY, newScale, updatePersistence);
|
||||
|
||||
verify(mMockCallback).onPerformScaleAction(eq(TEST_DISPLAY), eq(newScale));
|
||||
verify(mMockCallback).onPerformScaleAction(
|
||||
eq(TEST_DISPLAY), eq(newScale), eq(updatePersistence));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user