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

Commit 5a13de6b authored by dshivangi's avatar dshivangi Committed by Shivangi Dubey
Browse files

Remove isCameraRotationEnabled from RotationPolicyWrapper

The reason for this change is to enable the reuse of RotationPolicyWrapper in Launcher for better unit testability.
The original implementation was difficult to use in Launcher because it required SystemUI-specific dependencies.

To simplify sharing the RotationPolicyWrapper, we are decoupling it from SecureSettings.
This also aligns with the principle that the method isCameraRotationEnabled should not be part of the RotationPolicyWrapper in the first place, as it's not a part of the RotationPolicy class itself.

Test: Refactor only, No behaviour change
Flag: EXEMPTY REFACTOR
Bug: 430756509
Change-Id: Ia9a9aaf94b4c52f3151d0908d043a67cda640aa0
parent 79c374eb
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ import com.android.systemui.util.concurrency.FakeExecutor;
import com.android.systemui.util.settings.FakeSettings;
import com.android.systemui.util.time.FakeSystemClock;
import com.android.systemui.rotation.RotationPolicyWrapper;
import com.android.systemui.util.wrapper.CameraRotationSettingProvider;

import org.junit.After;
import org.junit.Before;
@@ -106,6 +107,8 @@ public class RotationLockTileTest extends SysuiTestCase {
    @Mock
    RotationPolicyWrapper mRotationPolicyWrapper;
    @Mock
    CameraRotationSettingProvider mCameraRotationSettingProvider;
    @Mock
    QsEventLogger mUiEventLogger;

    private RotationLockController mController;
@@ -132,6 +135,7 @@ public class RotationLockTileTest extends SysuiTestCase {

        mController = new RotationLockControllerImpl(
                mRotationPolicyWrapper,
                mCameraRotationSettingProvider,
                mDeviceStateRotationLockSettingController,
                DEFAULT_SETTINGS,
                mFakeExecutor,
@@ -302,11 +306,11 @@ public class RotationLockTileTest extends SysuiTestCase {
    }

    private void enableCameraBasedRotation() {
        when(mRotationPolicyWrapper.isCameraRotationEnabled()).thenReturn(true);
        when(mCameraRotationSettingProvider.isCameraRotationEnabled()).thenReturn(true);
    }

    private void disableCameraBasedRotation() {
        when(mRotationPolicyWrapper.isCameraRotationEnabled()).thenReturn(false);
        when(mCameraRotationSettingProvider.isCameraRotationEnabled()).thenReturn(false);
    }

    private QSTile.Icon createExpectedIcon(int resId) {
+4 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import com.android.systemui.SysuiTestCase;
import com.android.systemui.util.concurrency.FakeExecutor;
import com.android.systemui.util.time.FakeSystemClock;
import com.android.systemui.rotation.RotationPolicyWrapper;
import com.android.systemui.util.wrapper.CameraRotationSettingProvider;

import org.junit.Before;
import org.junit.Test;
@@ -51,6 +52,8 @@ public class RotationLockControllerImplTest extends SysuiTestCase {
    @Mock
    RotationPolicyWrapper mRotationPolicyWrapper;
    @Mock
    CameraRotationSettingProvider mCameraRotationSettingProvider;
    @Mock
    DeviceStateRotationLockSettingController mDeviceStateRotationLockSettingController;

    private ArgumentCaptor<RotationPolicy.RotationPolicyListener> mRotationPolicyListenerCaptor;
@@ -102,6 +105,7 @@ public class RotationLockControllerImplTest extends SysuiTestCase {
    private void createRotationLockController(String[] deviceStateRotationLockDefaults) {
        new RotationLockControllerImpl(
                mRotationPolicyWrapper,
                mCameraRotationSettingProvider,
                Optional.of(mDeviceStateRotationLockSettingController),
                deviceStateRotationLockDefaults,
                mFakeExecutor,
+0 −1
Original line number Diff line number Diff line
@@ -42,7 +42,6 @@ java_library {
    static_libs: [
        "//frameworks/libs/systemui:tracinglib-platform",
        "com.android.systemui.rotation-api",
        "com.android.systemui.util.settings-api",
    ],
    defaults: [
        "SystemUI_pod_defaults_impl",
+0 −1
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ public interface RotationPolicyWrapper {
    public fun getRotationLockOrientation(): Int
    public fun isRotationLockToggleVisible(): Boolean
    public fun isRotationLocked(): Boolean
    public fun isCameraRotationEnabled(): Boolean
    public fun registerRotationPolicyListener(listener: RotationPolicyListener, userHandle: Int)
    public fun unregisterRotationPolicyListener(listener: RotationPolicyListener)
}
 No newline at end of file
+0 −6
Original line number Diff line number Diff line
@@ -17,17 +17,14 @@
package com.android.systemui.rotation.impl

import android.content.Context
import android.provider.Settings.Secure.CAMERA_AUTOROTATE
import com.android.app.tracing.traceSection
import com.android.internal.view.RotationPolicy
import com.android.internal.view.RotationPolicy.RotationPolicyListener
import com.android.systemui.rotation.RotationPolicyWrapper
import com.android.systemui.util.settings.SecureSettings
import javax.inject.Inject

public class RotationPolicyWrapperImpl @Inject constructor(
    private val context: Context,
    private val secureSettings: SecureSettings
) :
        RotationPolicyWrapper {

@@ -59,9 +56,6 @@ public class RotationPolicyWrapperImpl @Inject constructor(
    override fun isRotationLocked(): Boolean =
        RotationPolicy.isRotationLocked(context)

    override fun isCameraRotationEnabled(): Boolean =
            secureSettings.getInt(CAMERA_AUTOROTATE, 0) == 1

    override fun registerRotationPolicyListener(
        listener: RotationPolicyListener,
        userHandle: Int
Loading