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

Commit 410c1d28 authored by Yi Jiang's avatar Yi Jiang Committed by Android (Google) Code Review
Browse files

Merge "Creates a flag for auto-rotate with face detection" into tm-qpr-dev

parents a0e5f09d 1145b26a
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -643,4 +643,6 @@
    <!-- Whether sim related information is visible to the end user. -->
    <bool name="config_show_sim_info">true</bool>

    <!-- Whether the toggle for Auto-rotate with Face Detection should be shown. -->
    <bool name="config_auto_rotate_face_detection_available">true</bool>
</resources>
+4 −0
Original line number Diff line number Diff line
@@ -180,6 +180,10 @@ public class SmartAutoRotateController extends TogglePreferenceController implem
     * Returns true if there is a {@link RotationResolverService} available
     */
    public static boolean isRotationResolverServiceAvailable(Context context) {
        if (!context.getResources().getBoolean(
                R.bool.config_auto_rotate_face_detection_available)) {
            return false;
        }
        final PackageManager packageManager = context.getPackageManager();
        final String resolvePackage = packageManager.getRotationResolverPackageName();
        if (TextUtils.isEmpty(resolvePackage)) {
+3 −0
Original line number Diff line number Diff line
@@ -80,6 +80,9 @@ public class SmartAutoRotatePreferenceControllerTest {
        when(mContext.getResources()).thenReturn(mResources);
        when(mContext.getContentResolver()).thenReturn(mContentResolver);

        when(mResources.getBoolean(R.bool.config_auto_rotate_face_detection_available)).thenReturn(
                true);

        doReturn(PACKAGE_NAME).when(mPackageManager).getRotationResolverPackageName();
        doReturn(PackageManager.PERMISSION_GRANTED).when(mPackageManager).checkPermission(
                Manifest.permission.CAMERA, PACKAGE_NAME);
+15 −0
Original line number Diff line number Diff line
@@ -111,6 +111,8 @@ public class SmartAutoRotatePreferenceFragmentTest {
        when(mActivity.getPackageManager()).thenReturn(mPackageManager);
        when(mFragment.getActivity()).thenReturn(mActivity);
        when(mFragment.getContext()).thenReturn(mContext);
        when(mActivity.getResources()).thenReturn(mResources);

        doReturn(mView).when(mFragment).getView();

        when(mFragment.findPreference(AUTO_ROTATE_SWITCH_PREFERENCE_KEY)).thenReturn(
@@ -152,6 +154,17 @@ public class SmartAutoRotatePreferenceFragmentTest {
        verify(mRotateSwitchPreference, never()).setVisible(false);
    }

    @Test
    public void createHeader_faceDetectionNotEnabledByConfig_switchBarIsDisabled() {
        doReturn(false).when(mResources).getBoolean(
                R.bool.config_auto_rotate_face_detection_available);

        mFragment.createHeader(mActivity);

        verify(mRotateMainSwitchPreference, times(1)).setVisible(false);
        verify(mRotateSwitchPreference, never()).setVisible(false);
    }

    @Test
    public void createPreferenceControllers_noSettableDeviceStates_returnsEmptyList() {
        enableDeviceStateSettableRotationStates(new String[]{}, new String[]{});
@@ -198,6 +211,8 @@ public class SmartAutoRotatePreferenceFragmentTest {
        when(mResources.getStringArray(
                R.array.config_settableAutoRotationDeviceStatesDescriptions)).thenReturn(
                settableStatesDescriptions);
        when(mResources.getBoolean(R.bool.config_auto_rotate_face_detection_available)).thenReturn(
                true);
        DeviceStateRotationLockSettingsManager.resetInstance();
        DeviceStateRotationLockSettingsManager.getInstance(mContext)
                .resetStateForTesting(mResources);