Merge changes I995a059c,Ibf78c90b into udc-qpr-dev
* changes: chore(#MagSettingsPanel): change persisting scale timing chore(#MagSettingsPanel): make seekbar index reflect the controlling magnifier scale
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.
|
||||
|
||||
@@ -107,6 +107,10 @@ public class MagnificationSettingsController implements ComponentCallbacks {
|
||||
return mWindowMagnificationSettings.isSettingPanelShowing();
|
||||
}
|
||||
|
||||
void setMagnificationScale(float scale) {
|
||||
mWindowMagnificationSettings.setMagnificationScale(scale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(@NonNull Configuration newConfig) {
|
||||
final int configDiff = newConfig.diff(mConfiguration);
|
||||
@@ -160,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.
|
||||
@@ -211,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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -310,6 +310,10 @@ public class WindowMagnification implements CoreStartable, CommandQueue.Callback
|
||||
return;
|
||||
}
|
||||
scales.put(displayId, scale);
|
||||
|
||||
final MagnificationSettingsController magnificationSettingsController =
|
||||
mMagnificationSettingsSupplier.get(displayId);
|
||||
magnificationSettingsController.setMagnificationScale(scale);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -329,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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -380,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);
|
||||
}
|
||||
|
||||
@@ -1491,13 +1491,9 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold
|
||||
// Simulate tapping the drag view so it opens the Settings.
|
||||
handleSingleTap(mDragView);
|
||||
} else if (action == R.id.accessibility_action_zoom_in) {
|
||||
final float scale = mScale + A11Y_CHANGE_SCALE_DIFFERENCE;
|
||||
mWindowMagnifierCallback.onPerformScaleAction(mDisplayId,
|
||||
A11Y_ACTION_SCALE_RANGE.clamp(scale));
|
||||
performScale(mScale + A11Y_CHANGE_SCALE_DIFFERENCE);
|
||||
} else if (action == R.id.accessibility_action_zoom_out) {
|
||||
final float scale = mScale - A11Y_CHANGE_SCALE_DIFFERENCE;
|
||||
mWindowMagnifierCallback.onPerformScaleAction(mDisplayId,
|
||||
A11Y_ACTION_SCALE_RANGE.clamp(scale));
|
||||
performScale(mScale - A11Y_CHANGE_SCALE_DIFFERENCE);
|
||||
} else if (action == R.id.accessibility_action_move_up) {
|
||||
move(0, -mSourceBounds.height());
|
||||
} else if (action == R.id.accessibility_action_move_down) {
|
||||
@@ -1512,5 +1508,11 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold
|
||||
mWindowMagnifierCallback.onAccessibilityActionPerformed(mDisplayId);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void performScale(float scale) {
|
||||
scale = A11Y_ACTION_SCALE_RANGE.clamp(scale);
|
||||
mWindowMagnifierCallback.onPerformScaleAction(
|
||||
mDisplayId, scale, /* updatePersistence= */ true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,6 @@ import android.widget.SeekBar;
|
||||
import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.internal.accessibility.common.MagnificationConstants;
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.graphics.SfVsyncFrameCallbackProvider;
|
||||
import com.android.systemui.R;
|
||||
@@ -89,14 +88,12 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest
|
||||
private final MagnificationGestureDetector mGestureDetector;
|
||||
private boolean mSingleTapDetected = false;
|
||||
|
||||
@VisibleForTesting
|
||||
SeekBarWithIconButtonsView mZoomSeekbar;
|
||||
private SeekBarWithIconButtonsView mZoomSeekbar;
|
||||
private LinearLayout mAllowDiagonalScrollingView;
|
||||
private TextView mAllowDiagonalScrollingTitle;
|
||||
private Switch mAllowDiagonalScrollingSwitch;
|
||||
private LinearLayout mPanelView;
|
||||
private LinearLayout mSettingView;
|
||||
private LinearLayout mButtonView;
|
||||
private ImageButton mSmallButton;
|
||||
private ImageButton mMediumButton;
|
||||
private ImageButton mLargeButton;
|
||||
@@ -110,10 +107,11 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest
|
||||
* magnitude = 10 means, for every 1 scale increase, 10 progress increase in seekbar.
|
||||
*/
|
||||
private int mSeekBarMagnitude;
|
||||
private float mScale = SCALE_MIN_VALUE;
|
||||
|
||||
private WindowMagnificationSettingsCallback mCallback;
|
||||
|
||||
private ContentObserver mMagnificationCapabilityObserver;
|
||||
private ContentObserver mMagnificationScaleObserver;
|
||||
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef({
|
||||
@@ -163,30 +161,20 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest
|
||||
});
|
||||
}
|
||||
};
|
||||
mMagnificationScaleObserver = new ContentObserver(
|
||||
mContext.getMainThreadHandler()) {
|
||||
@Override
|
||||
public void onChange(boolean selfChange) {
|
||||
setScaleSeekbar(getMagnificationScale());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private class ZoomSeekbarChangeListener implements
|
||||
SeekBarWithIconButtonsView.OnSeekBarWithIconButtonsChangeListener {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
float scale = (progress / (float) mSeekBarMagnitude) + SCALE_MIN_VALUE;
|
||||
// Update persisted scale only when scale >= PERSISTED_SCALE_MIN_VALUE const.
|
||||
// We assume if the scale is lower than the PERSISTED_SCALE_MIN_VALUE, there will be
|
||||
// no obvious magnification effect.
|
||||
if (scale >= MagnificationConstants.PERSISTED_SCALE_MIN_VALUE) {
|
||||
mSecureSettings.putFloatForUser(
|
||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE,
|
||||
scale,
|
||||
UserHandle.USER_CURRENT);
|
||||
// Notify the service to update the magnifier scale only when the progress changed is
|
||||
// triggered by user interaction on seekbar
|
||||
if (fromUser) {
|
||||
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);
|
||||
}
|
||||
mCallback.onMagnifierScale(scale);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -201,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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,7 +317,6 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest
|
||||
|
||||
// Unregister observer before removing view
|
||||
mSecureSettings.unregisterContentObserver(mMagnificationCapabilityObserver);
|
||||
mSecureSettings.unregisterContentObserver(mMagnificationScaleObserver);
|
||||
mWindowManager.removeView(mSettingView);
|
||||
mIsVisible = false;
|
||||
if (resetPosition) {
|
||||
@@ -374,7 +368,7 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest
|
||||
private void showSettingPanel(boolean resetPosition) {
|
||||
if (!mIsVisible) {
|
||||
updateUIControlsIfNeeded();
|
||||
setScaleSeekbar(getMagnificationScale());
|
||||
setScaleSeekbar(mScale);
|
||||
if (resetPosition) {
|
||||
mDraggableWindowBounds.set(getDraggableWindowBounds());
|
||||
mParams.x = mDraggableWindowBounds.right;
|
||||
@@ -387,10 +381,6 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest
|
||||
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_CAPABILITY,
|
||||
mMagnificationCapabilityObserver,
|
||||
UserHandle.USER_CURRENT);
|
||||
mSecureSettings.registerContentObserverForUser(
|
||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE,
|
||||
mMagnificationScaleObserver,
|
||||
UserHandle.USER_CURRENT);
|
||||
|
||||
// Exclude magnification switch button from system gesture area.
|
||||
setSystemGestureExclusion();
|
||||
@@ -430,11 +420,17 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest
|
||||
UserHandle.USER_CURRENT);
|
||||
}
|
||||
|
||||
private float getMagnificationScale() {
|
||||
return mSecureSettings.getFloatForUser(
|
||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE,
|
||||
SCALE_MIN_VALUE,
|
||||
UserHandle.USER_CURRENT);
|
||||
/**
|
||||
* Only called from outside to notify the controlling magnifier scale changed
|
||||
*
|
||||
* @param scale The new controlling magnifier scale
|
||||
*/
|
||||
public void setMagnificationScale(float scale) {
|
||||
mScale = scale;
|
||||
|
||||
if (isSettingPanelShowing()) {
|
||||
setScaleSeekbar(scale);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateUIControlsIfNeeded() {
|
||||
@@ -523,10 +519,7 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest
|
||||
mZoomSeekbar.setMax((int) (mZoomSeekbar.getChangeMagnitude()
|
||||
* (SCALE_MAX_VALUE - SCALE_MIN_VALUE)));
|
||||
mSeekBarMagnitude = mZoomSeekbar.getChangeMagnitude();
|
||||
float scale = mSecureSettings.getFloatForUser(
|
||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE, 0,
|
||||
UserHandle.USER_CURRENT);
|
||||
setScaleSeekbar(scale);
|
||||
setScaleSeekbar(mScale);
|
||||
mZoomSeekbar.setOnSeekBarWithIconButtonsChangeListener(new ZoomSeekbarChangeListener());
|
||||
|
||||
mAllowDiagonalScrollingView =
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -170,6 +170,22 @@ public class SeekBarWithIconButtonsView extends LinearLayout {
|
||||
mSeekBarListener.setOnSeekBarWithIconButtonsChangeListener(onSeekBarChangeListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Only for testing. Get previous set mOnSeekBarChangeListener to the seekbar.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public OnSeekBarWithIconButtonsChangeListener getOnSeekBarWithIconButtonsChangeListener() {
|
||||
return mSeekBarListener.mOnSeekBarChangeListener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only for testing. Get {@link #mSeekbar} in the layout.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public SeekBar getSeekbar() {
|
||||
return mSeekbar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start and End icons might need to be updated when there is a change in seekbar progress.
|
||||
* Icon Start will need to be enabled when the seekbar progress is larger than 0.
|
||||
|
||||
@@ -198,6 +198,7 @@ public class IWindowMagnificationConnectionTest extends SysuiTestCase {
|
||||
assertTrue(mWindowMagnification.mUsersScales.contains(testUserId));
|
||||
assertEquals(mWindowMagnification.mUsersScales.get(testUserId).get(TEST_DISPLAY),
|
||||
(Float) testScale);
|
||||
verify(mMagnificationSettingsController).setMagnificationScale(eq(testScale));
|
||||
}
|
||||
|
||||
private class FakeControllerSupplier extends
|
||||
|
||||
@@ -85,6 +85,14 @@ public class MagnificationSettingsControllerTest extends SysuiTestCase {
|
||||
verify(mWindowMagnificationSettings).hideSettingPanel();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetMagnificationScale() {
|
||||
final float scale = 3.0f;
|
||||
mMagnificationSettingsController.setMagnificationScale(scale);
|
||||
|
||||
verify(mWindowMagnificationSettings).setMagnificationScale(eq(scale));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnConfigurationChanged_notifySettingsPanel() {
|
||||
mMagnificationSettingsController.onConfigurationChanged(ActivityInfo.CONFIG_DENSITY);
|
||||
@@ -145,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));
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.android.systemui.accessibility;
|
||||
|
||||
import static android.provider.Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE;
|
||||
import static android.provider.Settings.Secure.ACCESSIBILITY_MAGNIFICATION_CAPABILITY;
|
||||
import static android.provider.Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_ALL;
|
||||
import static android.provider.Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN;
|
||||
@@ -28,10 +27,12 @@ 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;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -55,10 +56,11 @@ import android.widget.LinearLayout;
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.internal.accessibility.common.MagnificationConstants;
|
||||
import com.android.internal.graphics.SfVsyncFrameCallbackProvider;
|
||||
import com.android.systemui.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.util.settings.SecureSettings;
|
||||
|
||||
import org.junit.After;
|
||||
@@ -79,6 +81,7 @@ public class WindowMagnificationSettingsTest extends SysuiTestCase {
|
||||
private static final int MAGNIFICATION_SIZE_LARGE = 3;
|
||||
|
||||
private ViewGroup mSettingView;
|
||||
private SeekBarWithIconButtonsView mZoomSeekbar;
|
||||
@Mock
|
||||
private AccessibilityManager mAccessibilityManager;
|
||||
@Mock
|
||||
@@ -111,6 +114,7 @@ public class WindowMagnificationSettingsTest extends SysuiTestCase {
|
||||
mSecureSettings);
|
||||
|
||||
mSettingView = mWindowMagnificationSettings.getSettingView();
|
||||
mZoomSeekbar = mSettingView.findViewById(R.id.magnifier_zoom_slider);
|
||||
mSecureSettingsScaleCaptor = ArgumentCaptor.forClass(Float.class);
|
||||
mSecureSettingsNameCaptor = ArgumentCaptor.forClass(String.class);
|
||||
mSecureSettingsUserHandleCaptor = ArgumentCaptor.forClass(Integer.class);
|
||||
@@ -336,20 +340,6 @@ public class WindowMagnificationSettingsTest extends SysuiTestCase {
|
||||
eq(UserHandle.USER_CURRENT));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void showSettingsPanel_observerForMagnificationScaleRegistered() {
|
||||
setupMagnificationCapabilityAndMode(
|
||||
/* capability= */ ACCESSIBILITY_MAGNIFICATION_MODE_ALL,
|
||||
/* mode= */ ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW);
|
||||
|
||||
mWindowMagnificationSettings.showSettingPanel();
|
||||
|
||||
verify(mSecureSettings).registerContentObserverForUser(
|
||||
eq(ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE),
|
||||
any(ContentObserver.class),
|
||||
eq(UserHandle.USER_CURRENT));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hideSettingsPanel_observerUnregistered() {
|
||||
setupMagnificationCapabilityAndMode(
|
||||
@@ -359,19 +349,25 @@ public class WindowMagnificationSettingsTest extends SysuiTestCase {
|
||||
mWindowMagnificationSettings.showSettingPanel();
|
||||
mWindowMagnificationSettings.hideSettingPanel();
|
||||
|
||||
verify(mSecureSettings, times(2)).unregisterContentObserver(any(ContentObserver.class));
|
||||
verify(mSecureSettings).unregisterContentObserver(any(ContentObserver.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seekbarProgress_justInflated_maxValueAndProgressSetCorrectly() {
|
||||
setupScaleInSecureSettings(0f);
|
||||
assertThat(mWindowMagnificationSettings.mZoomSeekbar.getProgress()).isEqualTo(0);
|
||||
assertThat(mWindowMagnificationSettings.mZoomSeekbar.getMax()).isEqualTo(70);
|
||||
mWindowMagnificationSettings.setMagnificationScale(2f);
|
||||
mWindowMagnificationSettings.inflateView();
|
||||
|
||||
// inflateView() would create new settingsView in WindowMagnificationSettings so we
|
||||
// need to retrieve the new mZoomSeekbar
|
||||
mSettingView = mWindowMagnificationSettings.getSettingView();
|
||||
mZoomSeekbar = mSettingView.findViewById(R.id.magnifier_zoom_slider);
|
||||
assertThat(mZoomSeekbar.getProgress()).isEqualTo(10);
|
||||
assertThat(mZoomSeekbar.getMax()).isEqualTo(70);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seekbarProgress_minMagnification_seekbarProgressIsCorrect() {
|
||||
setupScaleInSecureSettings(0f);
|
||||
mWindowMagnificationSettings.setMagnificationScale(1f);
|
||||
setupMagnificationCapabilityAndMode(
|
||||
/* capability= */ ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW,
|
||||
/* mode= */ ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW);
|
||||
@@ -379,24 +375,24 @@ public class WindowMagnificationSettingsTest extends SysuiTestCase {
|
||||
mWindowMagnificationSettings.showSettingPanel();
|
||||
|
||||
// Seekbar index from 0 to 70. 1.0f scale (A11Y_SCALE_MIN_VALUE) would correspond to 0.
|
||||
assertThat(mWindowMagnificationSettings.mZoomSeekbar.getProgress()).isEqualTo(0);
|
||||
assertThat(mZoomSeekbar.getProgress()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seekbarProgress_belowMinMagnification_seekbarProgressIsZero() {
|
||||
setupScaleInSecureSettings(0f);
|
||||
mWindowMagnificationSettings.setMagnificationScale(0f);
|
||||
setupMagnificationCapabilityAndMode(
|
||||
/* capability= */ ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW,
|
||||
/* mode= */ ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW);
|
||||
|
||||
mWindowMagnificationSettings.showSettingPanel();
|
||||
|
||||
assertThat(mWindowMagnificationSettings.mZoomSeekbar.getProgress()).isEqualTo(0);
|
||||
assertThat(mZoomSeekbar.getProgress()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seekbarProgress_magnificationBefore_seekbarProgressIsHalf() {
|
||||
setupScaleInSecureSettings(4f);
|
||||
mWindowMagnificationSettings.setMagnificationScale(4f);
|
||||
setupMagnificationCapabilityAndMode(
|
||||
/* capability= */ ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW,
|
||||
/* mode= */ ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW);
|
||||
@@ -405,12 +401,12 @@ public class WindowMagnificationSettingsTest extends SysuiTestCase {
|
||||
|
||||
// float scale : from 1.0f to 8.0f, seekbar index from 0 to 70.
|
||||
// 4.0f would correspond to 30.
|
||||
assertThat(mWindowMagnificationSettings.mZoomSeekbar.getProgress()).isEqualTo(30);
|
||||
assertThat(mZoomSeekbar.getProgress()).isEqualTo(30);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seekbarProgress_maxMagnificationBefore_seekbarProgressIsMax() {
|
||||
setupScaleInSecureSettings(8f);
|
||||
mWindowMagnificationSettings.setMagnificationScale(8f);
|
||||
setupMagnificationCapabilityAndMode(
|
||||
/* capability= */ ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW,
|
||||
/* mode= */ ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW);
|
||||
@@ -419,12 +415,12 @@ public class WindowMagnificationSettingsTest extends SysuiTestCase {
|
||||
|
||||
// 8.0f is max magnification {@link MagnificationScaleProvider#MAX_SCALE}.
|
||||
// Max zoom seek bar is 70.
|
||||
assertThat(mWindowMagnificationSettings.mZoomSeekbar.getProgress()).isEqualTo(70);
|
||||
assertThat(mZoomSeekbar.getProgress()).isEqualTo(70);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seekbarProgress_aboveMaxMagnificationBefore_seekbarProgressIsMax() {
|
||||
setupScaleInSecureSettings(9f);
|
||||
mWindowMagnificationSettings.setMagnificationScale(9f);
|
||||
setupMagnificationCapabilityAndMode(
|
||||
/* capability= */ ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW,
|
||||
/* mode= */ ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW);
|
||||
@@ -432,88 +428,81 @@ public class WindowMagnificationSettingsTest extends SysuiTestCase {
|
||||
mWindowMagnificationSettings.showSettingPanel();
|
||||
|
||||
// Max zoom seek bar is 70.
|
||||
assertThat(mWindowMagnificationSettings.mZoomSeekbar.getProgress()).isEqualTo(70);
|
||||
assertThat(mZoomSeekbar.getProgress()).isEqualTo(70);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seekbarProgress_progressChangedRoughlyHalf_scaleAndCallbackUpdated() {
|
||||
setupMagnificationCapabilityAndMode(
|
||||
/* capability= */ ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW,
|
||||
/* mode= */ ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW);
|
||||
mWindowMagnificationSettings.showSettingPanel();
|
||||
public void onSeekBarProgressChanged_fromUserFalse_callbackNotTriggered() {
|
||||
OnSeekBarWithIconButtonsChangeListener onChangeListener =
|
||||
mZoomSeekbar.getOnSeekBarWithIconButtonsChangeListener();
|
||||
onChangeListener.onProgressChanged(
|
||||
mZoomSeekbar.getSeekbar(), /* progress= */ 30, /* fromUser= */ false);
|
||||
|
||||
mWindowMagnificationSettings.mZoomSeekbar.setProgress(30);
|
||||
verify(mWindowMagnificationSettingsCallback, never())
|
||||
.onMagnifierScale(/* scale= */ anyFloat(), /* updatePersistence= */ eq(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onSeekBarProgressChangedToRoughlyHalf_fromUserTrue_callbackUpdated() {
|
||||
OnSeekBarWithIconButtonsChangeListener onChangeListener =
|
||||
mZoomSeekbar.getOnSeekBarWithIconButtonsChangeListener();
|
||||
onChangeListener.onProgressChanged(
|
||||
mZoomSeekbar.getSeekbar(), /* progress= */ 30, /* fromUser= */ true);
|
||||
|
||||
verifyScaleUpdatedInSecureSettings(4f);
|
||||
verifyCallbackOnMagnifierScale(4f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seekbarProgress_minProgress_callbackUpdated() {
|
||||
setupMagnificationCapabilityAndMode(
|
||||
/* capability= */ ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW,
|
||||
/* mode= */ ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW);
|
||||
mWindowMagnificationSettings.showSettingPanel();
|
||||
// Set progress to non-zero first so onProgressChanged can be triggered upon setting to 0.
|
||||
mWindowMagnificationSettings.mZoomSeekbar.setProgress(30);
|
||||
public void onSeekBarProgressChangedToMin_fromUserTrue_callbackUpdated() {
|
||||
OnSeekBarWithIconButtonsChangeListener onChangeListener =
|
||||
mZoomSeekbar.getOnSeekBarWithIconButtonsChangeListener();
|
||||
onChangeListener.onProgressChanged(
|
||||
mZoomSeekbar.getSeekbar(), /* progress= */ 0, /* fromUser= */ true);
|
||||
|
||||
mWindowMagnificationSettings.mZoomSeekbar.setProgress(0);
|
||||
|
||||
// For now, secure settings will not be updated for values < 1.3f. Follow up on this later.
|
||||
verify(mWindowMagnificationSettingsCallback, times(2))
|
||||
.onMagnifierScale(mCallbackMagnifierScaleCaptor.capture());
|
||||
var capturedArgs = mCallbackMagnifierScaleCaptor.getAllValues();
|
||||
assertThat(capturedArgs).hasSize(2);
|
||||
assertThat(capturedArgs.get(1)).isWithin(0.01f).of(1f);
|
||||
verifyCallbackOnMagnifierScale(1f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seekbarProgress_maxProgress_scaleAndCallbackUpdated() {
|
||||
setupMagnificationCapabilityAndMode(
|
||||
/* capability= */ ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW,
|
||||
/* mode= */ ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW);
|
||||
mWindowMagnificationSettings.showSettingPanel();
|
||||
public void onSeekBarProgressChangedToMax_fromUserTrue_callbackUpdated() {
|
||||
OnSeekBarWithIconButtonsChangeListener onChangeListener =
|
||||
mZoomSeekbar.getOnSeekBarWithIconButtonsChangeListener();
|
||||
onChangeListener.onProgressChanged(
|
||||
mZoomSeekbar.getSeekbar(), /* progress= */ 70, /* fromUser= */ true);
|
||||
|
||||
mWindowMagnificationSettings.mZoomSeekbar.setProgress(70);
|
||||
|
||||
verifyScaleUpdatedInSecureSettings(8f);
|
||||
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(
|
||||
/* capability= */ ACCESSIBILITY_MAGNIFICATION_MODE_ALL,
|
||||
/* mode= */ ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW);
|
||||
var contentObserverCaptor = ArgumentCaptor.forClass(ContentObserver.class);
|
||||
mWindowMagnificationSettings.showSettingPanel();
|
||||
verify(mSecureSettings).registerContentObserverForUser(
|
||||
eq(ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE),
|
||||
contentObserverCaptor.capture(),
|
||||
eq(UserHandle.USER_CURRENT));
|
||||
|
||||
// Simulate outside changes.
|
||||
setupScaleInSecureSettings(4f);
|
||||
// Simulate callback due to outside change.
|
||||
contentObserverCaptor.getValue().onChange(/* selfChange= */ false);
|
||||
mWindowMagnificationSettings.setMagnificationScale(4f);
|
||||
|
||||
assertThat(mWindowMagnificationSettings.mZoomSeekbar.getProgress()).isEqualTo(30);
|
||||
}
|
||||
|
||||
private void verifyScaleUpdatedInSecureSettings(float scale) {
|
||||
verify(mSecureSettings).putFloatForUser(
|
||||
mSecureSettingsNameCaptor.capture(),
|
||||
mSecureSettingsScaleCaptor.capture(),
|
||||
mSecureSettingsUserHandleCaptor.capture());
|
||||
assertThat(mSecureSettingsScaleCaptor.getValue()).isWithin(0.01f).of(scale);
|
||||
assertThat(mSecureSettingsNameCaptor.getValue())
|
||||
.isEqualTo(Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE);
|
||||
assertThat(mSecureSettingsUserHandleCaptor.getValue()).isEqualTo(UserHandle.USER_CURRENT);
|
||||
assertThat(mZoomSeekbar.getProgress()).isEqualTo(30);
|
||||
}
|
||||
|
||||
private void verifyCallbackOnMagnifierScale(float scale) {
|
||||
verify(mWindowMagnificationSettingsCallback)
|
||||
.onMagnifierScale(mCallbackMagnifierScaleCaptor.capture());
|
||||
.onMagnifierScale(mCallbackMagnifierScaleCaptor.capture(), anyBoolean());
|
||||
assertThat(mCallbackMagnifierScaleCaptor.getValue()).isWithin(0.01f).of(scale);
|
||||
}
|
||||
|
||||
@@ -533,11 +522,4 @@ public class WindowMagnificationSettingsTest extends SysuiTestCase {
|
||||
anyInt(),
|
||||
eq(UserHandle.USER_CURRENT))).thenReturn(mode);
|
||||
}
|
||||
|
||||
private void setupScaleInSecureSettings(float scale) {
|
||||
when(mSecureSettings.getFloatForUser(
|
||||
ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE,
|
||||
MagnificationConstants.SCALE_MIN_VALUE,
|
||||
UserHandle.USER_CURRENT)).thenReturn(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