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

Commit 0a898d9e authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Foldable auto-rotation: Add support for rear display device state" into...

Merge "Foldable auto-rotation: Add support for rear display device state" into udc-dev am: 9bb3e1ef

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/22813597



Change-Id: Id96692fc5f050b964a19d7e17c26723c7daaf666
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents c1dff416 9bb3e1ef
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -11496,6 +11496,8 @@ public final class Settings {
        public static final int DEVICE_STATE_ROTATION_KEY_HALF_FOLDED = 1;
        /** @hide */
        public static final int DEVICE_STATE_ROTATION_KEY_UNFOLDED = 2;
        /** @hide */
        public static final int DEVICE_STATE_ROTATION_KEY_REAR_DISPLAY = 3;
        /**
         * The different postures that can be used as keys with
@@ -11507,6 +11509,7 @@ public final class Settings {
                DEVICE_STATE_ROTATION_KEY_FOLDED,
                DEVICE_STATE_ROTATION_KEY_HALF_FOLDED,
                DEVICE_STATE_ROTATION_KEY_UNFOLDED,
                DEVICE_STATE_ROTATION_KEY_REAR_DISPLAY,
        })
        @Retention(RetentionPolicy.SOURCE)
        public @interface DeviceStateRotationLockKey {
+5 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.settingslib.devicestate
import android.content.Context
import android.provider.Settings.Secure.DEVICE_STATE_ROTATION_KEY_FOLDED
import android.provider.Settings.Secure.DEVICE_STATE_ROTATION_KEY_HALF_FOLDED
import android.provider.Settings.Secure.DEVICE_STATE_ROTATION_KEY_REAR_DISPLAY
import android.provider.Settings.Secure.DEVICE_STATE_ROTATION_KEY_UNFOLDED
import android.provider.Settings.Secure.DEVICE_STATE_ROTATION_KEY_UNKNOWN
import android.provider.Settings.Secure.DeviceStateRotationLockKey
@@ -33,6 +34,8 @@ class PosturesHelper(context: Context) {
        context.resources.getIntArray(R.array.config_halfFoldedDeviceStates)
    private val unfoldedDeviceStates =
        context.resources.getIntArray(R.array.config_openDeviceStates)
    private val rearDisplayDeviceStates =
        context.resources.getIntArray(R.array.config_rearDisplayDeviceStates)

    @DeviceStateRotationLockKey
    fun deviceStateToPosture(deviceState: Int): Int {
@@ -40,6 +43,7 @@ class PosturesHelper(context: Context) {
            in foldedDeviceStates -> DEVICE_STATE_ROTATION_KEY_FOLDED
            in halfFoldedDeviceStates -> DEVICE_STATE_ROTATION_KEY_HALF_FOLDED
            in unfoldedDeviceStates -> DEVICE_STATE_ROTATION_KEY_UNFOLDED
            in rearDisplayDeviceStates -> DEVICE_STATE_ROTATION_KEY_REAR_DISPLAY
            else -> DEVICE_STATE_ROTATION_KEY_UNKNOWN
        }
    }
@@ -49,6 +53,7 @@ class PosturesHelper(context: Context) {
            DEVICE_STATE_ROTATION_KEY_FOLDED -> foldedDeviceStates.firstOrNull()
            DEVICE_STATE_ROTATION_KEY_HALF_FOLDED -> halfFoldedDeviceStates.firstOrNull()
            DEVICE_STATE_ROTATION_KEY_UNFOLDED -> unfoldedDeviceStates.firstOrNull()
            DEVICE_STATE_ROTATION_KEY_REAR_DISPLAY -> rearDisplayDeviceStates.firstOrNull()
            else -> null
        }
    }
+4 −1
Original line number Diff line number Diff line
@@ -30,7 +30,10 @@ android_test {

    certificate: "platform",

    srcs: ["src/**/*.java"],
    srcs: [
        "src/**/*.java",
        "src/**/*.kt",
    ],

    libs: [
        "android.test.runner",
+108 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.settingslib.devicestate

import android.content.Context
import android.content.res.Resources
import android.provider.Settings.Secure.DEVICE_STATE_ROTATION_KEY_FOLDED
import android.provider.Settings.Secure.DEVICE_STATE_ROTATION_KEY_HALF_FOLDED
import android.provider.Settings.Secure.DEVICE_STATE_ROTATION_KEY_REAR_DISPLAY
import android.provider.Settings.Secure.DEVICE_STATE_ROTATION_KEY_UNFOLDED
import android.provider.Settings.Secure.DEVICE_STATE_ROTATION_KEY_UNKNOWN
import androidx.test.filters.SmallTest
import androidx.test.runner.AndroidJUnit4
import com.android.internal.R
import com.google.common.truth.Expect
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.Mockito.`when` as whenever
import org.mockito.MockitoAnnotations

private const val DEVICE_STATE_UNKNOWN = 0
private const val DEVICE_STATE_CLOSED = 1
private const val DEVICE_STATE_HALF_FOLDED = 2
private const val DEVICE_STATE_OPEN = 3
private const val DEVICE_STATE_REAR_DISPLAY = 4

@SmallTest
@RunWith(AndroidJUnit4::class)
class PosturesHelperTest {

    @get:Rule val expect: Expect = Expect.create()

    @Mock private lateinit var context: Context

    @Mock private lateinit var resources: Resources

    private lateinit var posturesHelper: PosturesHelper

    @Before
    fun setUp() {
        MockitoAnnotations.initMocks(this)

        whenever(context.resources).thenReturn(resources)
        whenever(resources.getIntArray(R.array.config_foldedDeviceStates))
            .thenReturn(intArrayOf(DEVICE_STATE_CLOSED))
        whenever(resources.getIntArray(R.array.config_halfFoldedDeviceStates))
            .thenReturn(intArrayOf(DEVICE_STATE_HALF_FOLDED))
        whenever(resources.getIntArray(R.array.config_openDeviceStates))
            .thenReturn(intArrayOf(DEVICE_STATE_OPEN))
        whenever(resources.getIntArray(R.array.config_rearDisplayDeviceStates))
            .thenReturn(intArrayOf(DEVICE_STATE_REAR_DISPLAY))

        posturesHelper = PosturesHelper(context)
    }

    @Test
    fun deviceStateToPosture_mapsCorrectly() {
        expect
            .that(posturesHelper.deviceStateToPosture(DEVICE_STATE_CLOSED))
            .isEqualTo(DEVICE_STATE_ROTATION_KEY_FOLDED)
        expect
            .that(posturesHelper.deviceStateToPosture(DEVICE_STATE_HALF_FOLDED))
            .isEqualTo(DEVICE_STATE_ROTATION_KEY_HALF_FOLDED)
        expect
            .that(posturesHelper.deviceStateToPosture(DEVICE_STATE_OPEN))
            .isEqualTo(DEVICE_STATE_ROTATION_KEY_UNFOLDED)
        expect
            .that(posturesHelper.deviceStateToPosture(DEVICE_STATE_REAR_DISPLAY))
            .isEqualTo(DEVICE_STATE_ROTATION_KEY_REAR_DISPLAY)
        expect
            .that(posturesHelper.deviceStateToPosture(DEVICE_STATE_UNKNOWN))
            .isEqualTo(DEVICE_STATE_ROTATION_KEY_UNKNOWN)
    }

    @Test
    fun postureToDeviceState_mapsCorrectly() {
        expect
            .that(posturesHelper.postureToDeviceState(DEVICE_STATE_ROTATION_KEY_FOLDED))
            .isEqualTo(DEVICE_STATE_CLOSED)
        expect
            .that(posturesHelper.postureToDeviceState(DEVICE_STATE_ROTATION_KEY_HALF_FOLDED))
            .isEqualTo(DEVICE_STATE_HALF_FOLDED)
        expect
            .that(posturesHelper.postureToDeviceState(DEVICE_STATE_ROTATION_KEY_UNFOLDED))
            .isEqualTo(DEVICE_STATE_OPEN)
        expect
            .that(posturesHelper.postureToDeviceState(DEVICE_STATE_ROTATION_KEY_REAR_DISPLAY))
            .isEqualTo(DEVICE_STATE_REAR_DISPLAY)
        expect.that(posturesHelper.postureToDeviceState(DEVICE_STATE_ROTATION_KEY_UNKNOWN)).isNull()
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -34,6 +34,8 @@ constructor(@DeviceStateAutoRotationLog private val logBuffer: LogBuffer, contex
    private val halfFoldedStates =
        context.resources.getIntArray(R.array.config_halfFoldedDeviceStates)
    private val unfoldedStates = context.resources.getIntArray(R.array.config_openDeviceStates)
    private val rearDisplayStates =
        context.resources.getIntArray(R.array.config_rearDisplayDeviceStates)

    fun logListeningChange(listening: Boolean) {
        logBuffer.log(TAG, VERBOSE, { bool1 = listening }, { "setListening: $bool1" })
@@ -122,6 +124,7 @@ constructor(@DeviceStateAutoRotationLog private val logBuffer: LogBuffer, contex
            in foldedStates -> "Folded"
            in unfoldedStates -> "Unfolded"
            in halfFoldedStates -> "Half-Folded"
            in rearDisplayStates -> "Rear display"
            -1 -> "Uninitialized"
            else -> "Unknown"
        }