1 /* 2 * Copyright (C) 2025 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settingslib.devicestate 18 19 import android.provider.Settings.Secure.DEVICE_STATE_ROTATION_LOCK 20 import android.util.Dumpable 21 22 /** 23 * Interface for managing [DEVICE_STATE_ROTATION_LOCK] setting. 24 * 25 * It provides methods to register/unregister listeners for setting changes, update the setting for 26 * specific device states, retrieve the setting value, and check if rotation is locked for specific 27 * or all device states. 28 */ 29 interface DeviceStateAutoRotateSettingManager : Dumpable { 30 // TODO: b/397928958 - Rename all terms from rotationLock to autoRotate in all apis. 31 32 /** Listener for changes in device-state based auto rotate setting. */ 33 interface DeviceStateAutoRotateSettingListener { 34 /** Called whenever the setting has changed. */ onSettingsChangednull35 fun onSettingsChanged() 36 } 37 38 /** Register listener for changes to [DEVICE_STATE_ROTATION_LOCK] setting. */ 39 fun registerListener(settingListener: DeviceStateAutoRotateSettingListener) 40 41 /** Unregister listener for changes to [DEVICE_STATE_ROTATION_LOCK] setting. */ 42 fun unregisterListener(settingListener: DeviceStateAutoRotateSettingListener) 43 44 /** 45 * Write [deviceState]'s setting value as [autoRotate], for [DEVICE_STATE_ROTATION_LOCK] setting. 46 */ 47 fun updateSetting(deviceState: Int, autoRotate: Boolean) 48 49 /** Get [DEVICE_STATE_ROTATION_LOCK] setting value for [deviceState]. */ 50 fun getRotationLockSetting(deviceState: Int): Int 51 52 /** Returns true if auto-rotate setting is OFF for [deviceState]. */ 53 fun isRotationLocked(deviceState: Int): Boolean 54 55 /** Returns true if the auto-rotate setting value for all device states is OFF. */ 56 fun isRotationLockedForAllStates(): Boolean 57 58 /** Returns a list of device states and their respective auto rotate setting availability. */ 59 fun getSettableDeviceStates(): List<SettableDeviceState> 60 } 61 62 /** Represents a device state and whether it has an auto-rotation setting. */ 63 data class SettableDeviceState( 64 /** Returns the device state associated with this object. */ 65 val deviceState: Int, 66 /** Returns whether there is an auto-rotation setting for this device state. */ 67 val isSettable: Boolean 68 ) 69