Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3dc09767 authored by mincheli's avatar mincheli
Browse files

Stores magnification mode settings for multi-user

Stores the settings with the current user handle when toggling the
magnification switch button. It can prevent the magnification mode
settings missmatched when AccessibilityManagerService.switchUser
is called.

Bug: 171007010
Test: atest MagnificationModeSwitchTest
Change-Id: I074b7e427fc3d6ac068be0380704beafd7f7aa0e
parent b27f59f6
Loading
Loading
Loading
Loading
+6 −2
Original line number Original line Diff line number Diff line
@@ -24,6 +24,7 @@ import android.content.pm.ActivityInfo;
import android.graphics.PixelFormat;
import android.graphics.PixelFormat;
import android.graphics.PointF;
import android.graphics.PointF;
import android.os.Bundle;
import android.os.Bundle;
import android.os.UserHandle;
import android.provider.Settings;
import android.provider.Settings;
import android.util.MathUtils;
import android.util.MathUtils;
import android.view.Gravity;
import android.view.Gravity;
@@ -232,8 +233,11 @@ class MagnificationModeSwitch {
                mMagnificationMode ^ Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_ALL;
                mMagnificationMode ^ Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_ALL;
        mMagnificationMode = newMode;
        mMagnificationMode = newMode;
        mImageView.setImageResource(getIconResId(newMode));
        mImageView.setImageResource(getIconResId(newMode));
        Settings.Secure.putInt(mContext.getContentResolver(),
        Settings.Secure.putIntForUser(
                Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE, newMode);
                mContext.getContentResolver(),
                Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE,
                newMode,
                UserHandle.USER_CURRENT);
    }
    }


    private void handleSingleTap() {
    private void handleSingleTap() {
+5 −4
Original line number Original line Diff line number Diff line
@@ -43,6 +43,7 @@ import static org.mockito.Mockito.when;


import android.content.Context;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.pm.ActivityInfo;
import android.os.UserHandle;
import android.provider.Settings;
import android.provider.Settings;
import android.testing.AndroidTestingRunner;
import android.testing.AndroidTestingRunner;
import android.view.MotionEvent;
import android.view.MotionEvent;
@@ -186,8 +187,8 @@ public class MagnificationModeSwitchTest extends SysuiTestCase {
        // Perform dragging
        // Perform dragging
        final View.OnTouchListener listener = mTouchListenerCaptor.getValue();
        final View.OnTouchListener listener = mTouchListenerCaptor.getValue();
        final int offset = ViewConfiguration.get(mContext).getScaledTouchSlop();
        final int offset = ViewConfiguration.get(mContext).getScaledTouchSlop();
        final int previousMode = Settings.Secure.getInt(mContext.getContentResolver(),
        final int previousMode = Settings.Secure.getIntForUser(mContext.getContentResolver(),
                Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE, 0);
                Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE, 0, UserHandle.USER_CURRENT);
        listener.onTouch(mSpyImageView, MotionEvent.obtain(
        listener.onTouch(mSpyImageView, MotionEvent.obtain(
                0, 0, ACTION_DOWN, 100, 100, 0));
                0, 0, ACTION_DOWN, 100, 100, 0));
        verify(mViewPropertyAnimator).cancel();
        verify(mViewPropertyAnimator).cancel();
@@ -334,8 +335,8 @@ public class MagnificationModeSwitchTest extends SysuiTestCase {
        verify(mSpyImageView).setImageResource(
        verify(mSpyImageView).setImageResource(
                getIconResId(expectedMode));
                getIconResId(expectedMode));
        verify(mWindowManager).removeView(mSpyImageView);
        verify(mWindowManager).removeView(mSpyImageView);
        final int actualMode = Settings.Secure.getInt(mContext.getContentResolver(),
        final int actualMode = Settings.Secure.getIntForUser(mContext.getContentResolver(),
                Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE, 0);
                Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE, 0, UserHandle.USER_CURRENT);
        assertEquals(expectedMode, actualMode);
        assertEquals(expectedMode, actualMode);
    }
    }
}
}