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:
Christian Göllner
2022-02-16 09:56:15 +00:00
parent 78a0e714c4
commit a663f10c4e
24 changed files with 14 additions and 1106 deletions

View File

@@ -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);
}
}