Revert "Add support for device state based auto-rotation prefere..."
Revert submission 16745827-device-state-auto-rotation-preferences-aops Reason for revert: Checking if reason for test failures Reverted Changes: I77ed93f04:Add support for device state based auto-rotation p... I5b2791f54:Add support for device state based auto-rotation p... If254220ca:Add support for device state based auto-rotation p... If254220ca:Add support for device state based auto-rotation p... Fix: 219652963 Change-Id: Id95d5d7bb18a28403a6d3199945044e6617e0772
This commit is contained in:
@@ -26,7 +26,6 @@ import androidx.preference.SwitchPreference;
|
||||
|
||||
import com.android.internal.view.RotationPolicy;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.testutils.shadow.ShadowDeviceStateRotationLockSettingsManager;
|
||||
import com.android.settings.testutils.shadow.ShadowRotationPolicy;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -51,10 +50,7 @@ public class LockScreenRotationPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {
|
||||
ShadowRotationPolicy.class,
|
||||
ShadowDeviceStateRotationLockSettingsManager.class
|
||||
})
|
||||
@Config(shadows = {ShadowRotationPolicy.class})
|
||||
public void getAvailabilityStatus_supportedRotation_shouldReturnAvailable() {
|
||||
ShadowRotationPolicy.setRotationSupported(true /* supported */);
|
||||
|
||||
@@ -63,23 +59,8 @@ public class LockScreenRotationPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {
|
||||
ShadowRotationPolicy.class,
|
||||
ShadowDeviceStateRotationLockSettingsManager.class
|
||||
})
|
||||
public void getAvailabilityStatus_deviceStateRotationEnabled_returnsUnsupported() {
|
||||
ShadowRotationPolicy.setRotationSupported(true /* supported */);
|
||||
ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(true);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {
|
||||
ShadowRotationPolicy.class,
|
||||
ShadowDeviceStateRotationLockSettingsManager.class
|
||||
}) public void getAvailabilityStatus_unsupportedRotation_shouldReturnUnsupportedOnDevice() {
|
||||
@Config(shadows = {ShadowRotationPolicy.class})
|
||||
public void getAvailabilityStatus_unsupportedRotation_shouldReturnUnsupportedOnDevice() {
|
||||
ShadowRotationPolicy.setRotationSupported(false /* supported */);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
|
@@ -143,21 +143,6 @@ public class DashboardFragmentTest {
|
||||
assertThat(controller1).isSameInstanceAs(retrievedController);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void useAll_returnsAllControllersOfType() {
|
||||
final TestPreferenceController controller1 = new TestPreferenceController(mContext);
|
||||
final TestPreferenceController controller2 = new TestPreferenceController(mContext);
|
||||
final SubTestPreferenceController controller3 = new SubTestPreferenceController(mContext);
|
||||
mTestFragment.addPreferenceController(controller1);
|
||||
mTestFragment.addPreferenceController(controller2);
|
||||
mTestFragment.addPreferenceController(controller3);
|
||||
|
||||
final List<TestPreferenceController> retrievedControllers = mTestFragment.useAll(
|
||||
TestPreferenceController.class);
|
||||
|
||||
assertThat(retrievedControllers).containsExactly(controller1, controller2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayTilesAsPreference_shouldAddTilesWithIntent() {
|
||||
when(mFakeFeatureFactory.dashboardFeatureProvider
|
||||
@@ -375,13 +360,6 @@ public class DashboardFragmentTest {
|
||||
}
|
||||
}
|
||||
|
||||
public static class SubTestPreferenceController extends TestPreferenceController {
|
||||
|
||||
private SubTestPreferenceController(Context context) {
|
||||
super(context);
|
||||
}
|
||||
}
|
||||
|
||||
private static class TestFragment extends DashboardFragment {
|
||||
|
||||
private final PreferenceManager mPreferenceManager;
|
||||
|
@@ -30,7 +30,6 @@ import android.provider.Settings;
|
||||
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.internal.view.RotationPolicy;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
@@ -65,7 +64,6 @@ public class AutoRotatePreferenceControllerTest {
|
||||
mPreference = new SwitchPreference(RuntimeEnvironment.application);
|
||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
when(mContext.getContentResolver()).thenReturn(mContentResolver);
|
||||
disableDeviceStateRotation();
|
||||
|
||||
mController = new AutoRotatePreferenceController(mContext, "auto_rotate");
|
||||
}
|
||||
@@ -113,26 +111,6 @@ public class AutoRotatePreferenceControllerTest {
|
||||
.UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_deviceRotationDisabled_returnsAvailable() {
|
||||
enableAutoRotationPreference();
|
||||
disableDeviceStateRotation();
|
||||
|
||||
int availability = mController.getAvailabilityStatus();
|
||||
|
||||
assertThat(availability).isEqualTo(BasePreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_deviceRotationEnabled_returnsUnsupported() {
|
||||
enableAutoRotationPreference();
|
||||
enableDeviceStateRotation();
|
||||
|
||||
int availability = mController.getAvailabilityStatus();
|
||||
|
||||
assertThat(availability).isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsCheck() {
|
||||
assertThat(mController.isChecked()).isFalse();
|
||||
@@ -202,15 +180,4 @@ public class AutoRotatePreferenceControllerTest {
|
||||
Settings.System.putIntForUser(mContentResolver,
|
||||
Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT);
|
||||
}
|
||||
|
||||
private void enableDeviceStateRotation() {
|
||||
when(mContext.getResources().getStringArray(
|
||||
R.array.config_perDeviceStateRotationLockDefaults)).thenReturn(
|
||||
new String[]{"0:0", "1:1", "2:2"});
|
||||
}
|
||||
|
||||
private void disableDeviceStateRotation() {
|
||||
when(mContext.getResources().getStringArray(
|
||||
R.array.config_perDeviceStateRotationLockDefaults)).thenReturn(new String[]{});
|
||||
}
|
||||
}
|
||||
|
@@ -1,105 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.display;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class DeviceStateAutoRotateDetailsFragmentTest {
|
||||
|
||||
private final DeviceStateAutoRotateDetailsFragment mFragment =
|
||||
spy(new DeviceStateAutoRotateDetailsFragment());
|
||||
private final Context mContext = spy(RuntimeEnvironment.application);
|
||||
private final Resources mResources = spy(mContext.getResources());
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
when(mContext.getApplicationContext()).thenReturn(mContext);
|
||||
when(mFragment.getContext()).thenReturn(mContext);
|
||||
when(mFragment.getResources()).thenReturn(mResources);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMetricsCategory_returnsAutoRotateSettings() {
|
||||
assertThat(mFragment.getMetricsCategory()).isEqualTo(
|
||||
SettingsEnums.DISPLAY_AUTO_ROTATE_SETTINGS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPreferenceScreenResId_returnsDeviceStateAutoRotationSettings() {
|
||||
assertThat(mFragment.getPreferenceScreenResId()).isEqualTo(
|
||||
R.xml.device_state_auto_rotate_settings);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createPreferenceControllers_settableDeviceStates_returnsDeviceStateControllers() {
|
||||
enableDeviceStateSettableRotationStates(new String[]{"0:1", "1:1"},
|
||||
new String[]{"Folded", "Unfolded"});
|
||||
|
||||
List<AbstractPreferenceController> preferenceControllers =
|
||||
mFragment.createPreferenceControllers(mContext);
|
||||
|
||||
assertThat(preferenceControllers).hasSize(2);
|
||||
assertThat(preferenceControllers.get(0)).isInstanceOf(
|
||||
DeviceStateAutoRotateSettingController.class);
|
||||
assertThat(preferenceControllers.get(1)).isInstanceOf(
|
||||
DeviceStateAutoRotateSettingController.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createPreferenceControllers_noSettableDeviceStates_returnsEmptyList() {
|
||||
enableDeviceStateSettableRotationStates(new String[]{}, new String[]{});
|
||||
|
||||
List<AbstractPreferenceController> preferenceControllers =
|
||||
mFragment.createPreferenceControllers(mContext);
|
||||
|
||||
assertThat(preferenceControllers).isEmpty();
|
||||
}
|
||||
|
||||
private void enableDeviceStateSettableRotationStates(String[] settableStates,
|
||||
String[] settableStatesDescriptions) {
|
||||
when(mResources.getStringArray(
|
||||
com.android.internal.R.array.config_perDeviceStateRotationLockDefaults)).thenReturn(
|
||||
settableStates);
|
||||
when(mResources.getStringArray(
|
||||
R.array.config_settableAutoRotationDeviceStatesDescriptions)).thenReturn(
|
||||
settableStatesDescriptions);
|
||||
DeviceStateRotationLockSettingsManager.resetInstance();
|
||||
DeviceStateRotationLockSettingsManager.getInstance(mContext)
|
||||
.resetStateForTesting(mResources);
|
||||
}
|
||||
}
|
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.display;
|
||||
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.android.settings.testutils.shadow.ShadowDeviceStateRotationLockSettingsManager;
|
||||
import com.android.settings.testutils.shadow.ShadowRotationPolicy;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowRotationPolicy.class, ShadowDeviceStateRotationLockSettingsManager.class})
|
||||
public class DeviceStateAutoRotateOverviewControllerTest {
|
||||
|
||||
private final DeviceStateAutoRotateOverviewController mController =
|
||||
new DeviceStateAutoRotateOverviewController(
|
||||
RuntimeEnvironment.application, "device_state_auto_rotate");
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_rotationAndDeviceStateRotationEnabled_returnsAvailable() {
|
||||
ShadowRotationPolicy.setRotationSupported(true);
|
||||
ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(true);
|
||||
|
||||
int availability = mController.getAvailabilityStatus();
|
||||
|
||||
assertThat(availability).isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_rotationNotSupported_returnsUnsupportedOnDevice() {
|
||||
ShadowRotationPolicy.setRotationSupported(false);
|
||||
ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(true);
|
||||
|
||||
int availability = mController.getAvailabilityStatus();
|
||||
|
||||
assertThat(availability).isEqualTo(UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_deviceStateRotationNotSupported_returnsUnsupportedOnDevice() {
|
||||
ShadowRotationPolicy.setRotationSupported(true);
|
||||
ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(false);
|
||||
|
||||
int availability = mController.getAvailabilityStatus();
|
||||
|
||||
assertThat(availability).isEqualTo(UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
}
|
@@ -1,175 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.display;
|
||||
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.shadow.ShadowDeviceStateRotationLockSettingsManager;
|
||||
import com.android.settings.testutils.shadow.ShadowRotationPolicy;
|
||||
import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager;
|
||||
import com.android.settingslib.search.SearchIndexableRaw;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {
|
||||
ShadowRotationPolicy.class,
|
||||
ShadowDeviceStateRotationLockSettingsManager.class
|
||||
})
|
||||
public class DeviceStateAutoRotateSettingControllerTest {
|
||||
|
||||
private static final int DEFAULT_DEVICE_STATE = 1;
|
||||
private static final String DEFAULT_DEVICE_STATE_DESCRIPTION = "Device state description";
|
||||
private static final int DEFAULT_ORDER = -10;
|
||||
|
||||
private final Context mContext = RuntimeEnvironment.application;
|
||||
private final DeviceStateAutoRotateSettingController mController =
|
||||
new DeviceStateAutoRotateSettingController(mContext, DEFAULT_DEVICE_STATE,
|
||||
DEFAULT_DEVICE_STATE_DESCRIPTION, DEFAULT_ORDER);
|
||||
private final DeviceStateRotationLockSettingsManager mAutoRotateSettingsManager =
|
||||
DeviceStateRotationLockSettingsManager.getInstance(mContext);
|
||||
|
||||
@Test
|
||||
public void displayPreference_addsPreferenceToPreferenceScreen() {
|
||||
PreferenceScreen screen = new PreferenceManager(mContext).createPreferenceScreen(mContext);
|
||||
|
||||
mController.displayPreference(screen);
|
||||
|
||||
assertThat(screen.getPreferenceCount()).isEqualTo(1);
|
||||
Preference preference = screen.getPreference(0);
|
||||
assertThat(preference.getTitle().toString()).isEqualTo(DEFAULT_DEVICE_STATE_DESCRIPTION);
|
||||
assertThat(preference.getOrder()).isEqualTo(DEFAULT_ORDER);
|
||||
assertThat(preference.getKey()).isEqualTo(mController.getPreferenceKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_rotationAndDeviceStateRotationEnabled_returnsAvailable() {
|
||||
ShadowRotationPolicy.setRotationSupported(true);
|
||||
ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(true);
|
||||
|
||||
int availability = mController.getAvailabilityStatus();
|
||||
|
||||
assertThat(availability).isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_deviceStateRotationDisabled_returnsUnsupported() {
|
||||
ShadowRotationPolicy.setRotationSupported(true);
|
||||
ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(false);
|
||||
|
||||
int availability = mController.getAvailabilityStatus();
|
||||
|
||||
assertThat(availability).isEqualTo(UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_rotationDisabled_returnsUnsupported() {
|
||||
ShadowRotationPolicy.setRotationSupported(false);
|
||||
ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(true);
|
||||
|
||||
int availability = mController.getAvailabilityStatus();
|
||||
|
||||
assertThat(availability).isEqualTo(UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPreferenceKey_returnsKeyBasedOnDeviceState() {
|
||||
String key = mController.getPreferenceKey();
|
||||
|
||||
String expectedKey = "auto_rotate_device_state_" + DEFAULT_DEVICE_STATE;
|
||||
assertThat(key).isEqualTo(expectedKey);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isChecked_settingForStateIsUnlocked_returnsTrue() {
|
||||
mAutoRotateSettingsManager.updateSetting(DEFAULT_DEVICE_STATE, /* rotationLocked= */ false);
|
||||
|
||||
assertThat(mController.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isChecked_settingForStateIsLocked_returnsFalse() {
|
||||
mAutoRotateSettingsManager.updateSetting(DEFAULT_DEVICE_STATE, /* rotationLocked= */ true);
|
||||
|
||||
assertThat(mController.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_true_deviceStateSettingIsUnlocked() {
|
||||
mController.setChecked(true);
|
||||
|
||||
boolean rotationLocked = mAutoRotateSettingsManager.isRotationLocked(DEFAULT_DEVICE_STATE);
|
||||
|
||||
assertThat(rotationLocked).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_false_deviceStateSettingIsLocked() {
|
||||
mController.setChecked(false);
|
||||
|
||||
boolean rotationLocked = mAutoRotateSettingsManager.isRotationLocked(DEFAULT_DEVICE_STATE);
|
||||
|
||||
assertThat(rotationLocked).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateRawDataToIndex_addsItemToList() {
|
||||
List<SearchIndexableRaw> rawData = new ArrayList<>();
|
||||
|
||||
mController.updateRawDataToIndex(rawData);
|
||||
|
||||
assertThat(rawData).hasSize(1);
|
||||
SearchIndexableRaw item = rawData.get(0);
|
||||
assertThat(item.key).isEqualTo(mController.getPreferenceKey());
|
||||
assertThat(item.title).isEqualTo(DEFAULT_DEVICE_STATE_DESCRIPTION);
|
||||
assertThat(item.screenTitle).isEqualTo(mContext.getString(R.string.accelerometer_title));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSliceHighlightMenuRes_returnsMenuKeyDisplay() {
|
||||
int sliceHighlightMenuRes = mController.getSliceHighlightMenuRes();
|
||||
|
||||
assertThat(sliceHighlightMenuRes).isEqualTo(R.string.menu_key_display);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSliceable_returnsTrue() {
|
||||
assertThat(mController.isSliceable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isPublicSlice_returnsTrue() {
|
||||
assertThat(mController.isPublicSlice()).isTrue();
|
||||
}
|
||||
}
|
@@ -39,10 +39,7 @@ import android.provider.Settings;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.testutils.ResolveInfoBuilder;
|
||||
import com.android.settings.testutils.shadow.ShadowDeviceStateRotationLockSettingsManager;
|
||||
import com.android.settings.testutils.shadow.ShadowRotationPolicy;
|
||||
import com.android.settings.testutils.shadow.ShadowSensorPrivacyManager;
|
||||
import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -66,8 +63,6 @@ public class SmartAutoRotateControllerTest {
|
||||
@Mock
|
||||
private Preference mPreference;
|
||||
private ContentResolver mContentResolver;
|
||||
private final DeviceStateRotationLockSettingsManager mDeviceStateAutoRotateSettingsManager =
|
||||
DeviceStateRotationLockSettingsManager.getInstance(RuntimeEnvironment.application);
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -127,34 +122,6 @@ public class SmartAutoRotateControllerTest {
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {
|
||||
ShadowDeviceStateRotationLockSettingsManager.class,
|
||||
ShadowRotationPolicy.class
|
||||
})
|
||||
public void getAvailabilityStatus_deviceStateRotationLocked_returnDisableDependentSetting() {
|
||||
enableDeviceStateRotation();
|
||||
lockDeviceStateRotation();
|
||||
|
||||
int availabilityStatus = mController.getAvailabilityStatus();
|
||||
|
||||
assertThat(availabilityStatus).isEqualTo(DISABLED_DEPENDENT_SETTING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {
|
||||
ShadowDeviceStateRotationLockSettingsManager.class,
|
||||
ShadowRotationPolicy.class
|
||||
})
|
||||
public void getAvailabilityStatus_deviceStateRotationUnlocked_returnAvailable() {
|
||||
enableDeviceStateRotation();
|
||||
unlockDeviceStateRotation();
|
||||
|
||||
int availabilityStatus = mController.getAvailabilityStatus();
|
||||
|
||||
assertThat(availabilityStatus).isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
private void enableAutoRotation() {
|
||||
Settings.System.putIntForUser(mContentResolver,
|
||||
Settings.System.ACCELEROMETER_ROTATION, 1, UserHandle.USER_CURRENT);
|
||||
@@ -164,23 +131,4 @@ public class SmartAutoRotateControllerTest {
|
||||
Settings.System.putIntForUser(mContentResolver,
|
||||
Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT);
|
||||
}
|
||||
|
||||
private void enableDeviceStateRotation() {
|
||||
ShadowRotationPolicy.setRotationSupported(true);
|
||||
ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(true);
|
||||
}
|
||||
|
||||
private void lockDeviceStateRotation() {
|
||||
mDeviceStateAutoRotateSettingsManager.updateSetting(
|
||||
/* deviceState= */0, /* rotationLocked= */ true);
|
||||
mDeviceStateAutoRotateSettingsManager.updateSetting(
|
||||
/* deviceState= */1, /* rotationLocked= */ true);
|
||||
}
|
||||
|
||||
private void unlockDeviceStateRotation() {
|
||||
mDeviceStateAutoRotateSettingsManager.updateSetting(
|
||||
/* deviceState= */0, /* rotationLocked= */ false);
|
||||
mDeviceStateAutoRotateSettingsManager.updateSetting(
|
||||
/* deviceState= */1, /* rotationLocked= */ true);
|
||||
}
|
||||
}
|
||||
|
@@ -40,7 +40,6 @@ import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.ResolveInfoBuilder;
|
||||
import com.android.settings.testutils.shadow.ShadowDeviceStateRotationLockSettingsManager;
|
||||
import com.android.settings.testutils.shadow.ShadowSensorPrivacyManager;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -54,10 +53,7 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {
|
||||
ShadowSensorPrivacyManager.class,
|
||||
ShadowDeviceStateRotationLockSettingsManager.class
|
||||
})
|
||||
@Config(shadows = ShadowSensorPrivacyManager.class)
|
||||
public class SmartAutoRotatePreferenceControllerTest {
|
||||
|
||||
private static final String PACKAGE_NAME = "package_name";
|
||||
@@ -99,7 +95,6 @@ public class SmartAutoRotatePreferenceControllerTest {
|
||||
new SmartAutoRotatePreferenceController(mContext, "smart_auto_rotate"));
|
||||
when(mController.isCameraLocked()).thenReturn(false);
|
||||
when(mController.isPowerSaveMode()).thenReturn(false);
|
||||
ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -204,16 +199,6 @@ public class SmartAutoRotatePreferenceControllerTest {
|
||||
.UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_deviceStateRotationEnabled_returnsUnsupported() {
|
||||
enableAutoRotationPreference();
|
||||
ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(true);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSliceableCorrectKey_returnsTrue() {
|
||||
final AutoRotatePreferenceController controller =
|
||||
|
@@ -18,8 +18,6 @@ package com.android.settings.display;
|
||||
|
||||
import static com.android.settings.display.SmartAutoRotatePreferenceFragment.AUTO_ROTATE_SWITCH_PREFERENCE_ID;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
@@ -35,7 +33,6 @@ import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.content.res.Resources;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
@@ -43,11 +40,7 @@ import androidx.preference.Preference;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.testutils.ResolveInfoBuilder;
|
||||
import com.android.settings.testutils.shadow.ShadowDeviceStateRotationLockSettingsManager;
|
||||
import com.android.settings.testutils.shadow.ShadowRotationPolicy;
|
||||
import com.android.settings.widget.SettingsMainSwitchBar;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -56,15 +49,8 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {
|
||||
ShadowDeviceStateRotationLockSettingsManager.class,
|
||||
ShadowRotationPolicy.class
|
||||
})
|
||||
public class SmartAutoRotatePreferenceFragmentTest {
|
||||
|
||||
private static final String PACKAGE_NAME = "package_name";
|
||||
@@ -84,24 +70,19 @@ public class SmartAutoRotatePreferenceFragmentTest {
|
||||
|
||||
@Mock
|
||||
private Preference mRotateSwitchPreference;
|
||||
private Resources mResources;
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
final Context context = spy(RuntimeEnvironment.application);
|
||||
ContentResolver mContentResolver = RuntimeEnvironment.application.getContentResolver();
|
||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
when(mContext.getContentResolver()).thenReturn(mContentResolver);
|
||||
when(context.getPackageManager()).thenReturn(mPackageManager);
|
||||
when(context.getContentResolver()).thenReturn(mContentResolver);
|
||||
doReturn(PACKAGE_NAME).when(mPackageManager).getRotationResolverPackageName();
|
||||
doReturn(PackageManager.PERMISSION_GRANTED).when(mPackageManager).checkPermission(
|
||||
Manifest.permission.CAMERA, PACKAGE_NAME);
|
||||
|
||||
mResources = spy(mContext.getResources());
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
|
||||
final ResolveInfo resolveInfo = new ResolveInfoBuilder(PACKAGE_NAME).build();
|
||||
resolveInfo.serviceInfo = new ServiceInfo();
|
||||
when(mPackageManager.resolveService(any(), anyInt())).thenReturn(resolveInfo);
|
||||
@@ -109,16 +90,15 @@ public class SmartAutoRotatePreferenceFragmentTest {
|
||||
mFragment = spy(new SmartAutoRotatePreferenceFragment());
|
||||
when(mActivity.getPackageManager()).thenReturn(mPackageManager);
|
||||
when(mFragment.getActivity()).thenReturn(mActivity);
|
||||
when(mFragment.getContext()).thenReturn(mContext);
|
||||
when(mFragment.getContext()).thenReturn(context);
|
||||
doReturn(mView).when(mFragment).getView();
|
||||
|
||||
when(mFragment.findPreference(AUTO_ROTATE_SWITCH_PREFERENCE_ID)).thenReturn(
|
||||
mRotateSwitchPreference);
|
||||
|
||||
mSwitchBar = spy(new SettingsMainSwitchBar(mContext));
|
||||
mSwitchBar = spy(new SettingsMainSwitchBar(context));
|
||||
when(mActivity.getSwitchBar()).thenReturn(mSwitchBar);
|
||||
doReturn(mSwitchBar).when(mView).findViewById(R.id.switch_bar);
|
||||
ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -130,17 +110,6 @@ public class SmartAutoRotatePreferenceFragmentTest {
|
||||
verify(mRotateSwitchPreference, times(1)).setVisible(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createHeader_deviceStateRotationSupported_switchBarIsDisabled() {
|
||||
ShadowRotationPolicy.setRotationSupported(true);
|
||||
ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(true);
|
||||
|
||||
mFragment.createHeader(mActivity);
|
||||
|
||||
verify(mSwitchBar, never()).show();
|
||||
verify(mRotateSwitchPreference, never()).setVisible(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createHeader_faceDetectionUnSupported_switchBarIsDisabled() {
|
||||
doReturn(null).when(mPackageManager).getRotationResolverPackageName();
|
||||
@@ -151,41 +120,4 @@ public class SmartAutoRotatePreferenceFragmentTest {
|
||||
verify(mRotateSwitchPreference, never()).setVisible(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createPreferenceControllers_noSettableDeviceStates_returnsEmptyList() {
|
||||
enableDeviceStateSettableRotationStates(new String[]{}, new String[]{});
|
||||
|
||||
List<AbstractPreferenceController> preferenceControllers =
|
||||
mFragment.createPreferenceControllers(mContext);
|
||||
|
||||
assertThat(preferenceControllers).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createPreferenceControllers_settableDeviceStates_returnsDeviceStateControllers() {
|
||||
enableDeviceStateSettableRotationStates(new String[]{"0:1", "1:1"},
|
||||
new String[]{"Folded", "Unfolded"});
|
||||
|
||||
List<AbstractPreferenceController> preferenceControllers =
|
||||
mFragment.createPreferenceControllers(mContext);
|
||||
|
||||
assertThat(preferenceControllers).hasSize(2);
|
||||
assertThat(preferenceControllers.get(0)).isInstanceOf(
|
||||
DeviceStateAutoRotateSettingController.class);
|
||||
assertThat(preferenceControllers.get(1)).isInstanceOf(
|
||||
DeviceStateAutoRotateSettingController.class);
|
||||
}
|
||||
|
||||
private void enableDeviceStateSettableRotationStates(String[] settableStates,
|
||||
String[] settableStatesDescriptions) {
|
||||
when(mResources.getStringArray(
|
||||
com.android.internal.R.array.config_perDeviceStateRotationLockDefaults)).thenReturn(
|
||||
settableStates);
|
||||
when(mResources.getStringArray(
|
||||
R.array.config_settableAutoRotationDeviceStatesDescriptions)).thenReturn(
|
||||
settableStatesDescriptions);
|
||||
DeviceStateRotationLockSettingsManager.resetInstance();
|
||||
DeviceStateRotationLockSettingsManager.getInstance(mContext)
|
||||
.resetStateForTesting(mResources);
|
||||
}
|
||||
}
|
||||
|
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.testutils.shadow;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager;
|
||||
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
|
||||
@Implements(DeviceStateRotationLockSettingsManager.class)
|
||||
public class ShadowDeviceStateRotationLockSettingsManager {
|
||||
|
||||
private static boolean sDeviceStateRotationLockEnabled;
|
||||
|
||||
@Implementation
|
||||
public static boolean isDeviceStateRotationLockEnabled(Context context) {
|
||||
return sDeviceStateRotationLockEnabled;
|
||||
}
|
||||
|
||||
public static void setDeviceStateRotationLockEnabled(boolean enabled) {
|
||||
sDeviceStateRotationLockEnabled = enabled;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user