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

Commit 5b3da2a4 authored by dshivangi's avatar dshivangi
Browse files

Mock new conditions for DSAutoRotate setting

This change mocks the newly added conditions in SettingsHelperTest to enable the Device state-based auto-rotate setting.
The original change (ag/34594784) introduced new checks that must pass for this setting to be enabled. This test update ensures that SettingsHelperTest continues to work as expected by mocking these conditions.

Test: atest SettingsHelperTest
Fixes: 436577666
Flag: EXEMPT TEST_ONLY
Change-Id: I049f12d608a4e82190e5d17576f94573e8716fe4
parent aa7929f6
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ android_test {
        // Note we statically link SettingsProviderLib to do some unit tests.  It's not accessible otherwise
        // because this test is not an instrumentation test. (because the target runs in the system process.)
        "SettingsProviderLib",
        "DSAutoRotateSetting-testutils",
        "androidx.test.rules",
        "frameworks-base-testutils",
        "device_config_service_flags_java",
@@ -74,7 +75,7 @@ android_test {
        "junit",
        "junit-params",
        "libaconfig_java_proto_lite",
        "mockito-target-minus-junit4",
        "mockito-target-extended-minus-junit4",
        "platform-test-annotations",
        "truth",
        "Nene",
@@ -86,6 +87,13 @@ android_test {
        "android.test.mock.stubs.system",
        "unsupportedappusage",
    ],
    defaults: [
        "modules-utils-testable-device-config-defaults",
    ],
    jni_libs: [
        "libdexmakerjvmtiagent",
        "libstaticjvmtiagent",
    ],
    resource_dirs: [],
    platform_apis: true,
    certificate: "platform",
+1 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@
    <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL"/>
    <uses-permission android:name="android.permission.MANAGE_USERS"/>

    <application>
    <application android:debuggable="true">
        <uses-library android:name="android.test.runner" />
    </application>

+9 −4
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.providers.settings;

import static com.android.settings.testutils.DeviceStateAutoRotateSettingTestUtils.setDeviceStateRotationLockEnabled;

import static com.google.common.truth.Truth.assertThat;

import static junit.framework.Assert.assertEquals;
@@ -40,6 +42,7 @@ import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.hardware.devicestate.DeviceStateManager;
import android.media.AudioManager;
import android.media.Utils;
import android.net.Uri;
@@ -103,6 +106,7 @@ public class SettingsHelperTest {
    @Mock private Resources mResources;
    @Mock private AudioManager mAudioManager;
    @Mock private TelephonyManager mTelephonyManager;
    @Mock private DeviceStateManager mDeviceStateManager;

    private MockContentResolver mContentResolver;
    private MockSettingsProvider mSettingsProvider;
@@ -112,6 +116,9 @@ public class SettingsHelperTest {
    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);

        when(mContext.getSystemService(eq(DeviceStateManager.class))).thenReturn(
                mDeviceStateManager);
        when(mContext.getSystemService(eq(Context.AUDIO_SERVICE))).thenReturn(mAudioManager);
        when(mContext.getSystemService(eq(Context.TELEPHONY_SERVICE))).thenReturn(
                mTelephonyManager);
@@ -951,8 +958,7 @@ public class SettingsHelperTest {

    @Test
    public void restoreValue_autoRotation_deviceStateAutoRotationDisabled_restoresValue() {
        when(mResources.getStringArray(R.array.config_perDeviceStateRotationLockDefaults))
                .thenReturn(new String[]{});
        setDeviceStateRotationLockEnabled(/* enable= */ false, mResources, mDeviceStateManager);
        int previousValue = 0;
        int newValue = 1;
        setAutoRotationSettingValue(previousValue);
@@ -964,8 +970,7 @@ public class SettingsHelperTest {

    @Test
    public void restoreValue_autoRotation_deviceStateAutoRotationEnabled_doesNotRestoreValue() {
        when(mResources.getStringArray(R.array.config_perDeviceStateRotationLockDefaults))
                .thenReturn(new String[]{"0:1", "1:1"});
        setDeviceStateRotationLockEnabled(/* enable= */ true, mResources, mDeviceStateManager);
        int previousValue = 0;
        int newValue = 1;
        setAutoRotationSettingValue(previousValue);