1 /* 2 * Copyright (C) 2024 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.systemui.shared.rotation 18 19 import android.content.Context 20 import android.util.Log 21 import com.android.internal.view.RotationPolicy 22 23 class RotationPolicyUtil { 24 companion object { 25 /** 26 * Recommend to be called on bg thread, or reuse the results. It's because 27 * [RotationPolicy.isRotationLocked] may make a binder call to query settings. 28 * 29 * @return whether rotation is currently locked, or <code>null</code> if the setting 30 * couldn't be read 31 */ 32 @JvmStatic isRotationLockednull33 fun isRotationLocked(context: Context): Boolean? { 34 try { 35 return RotationPolicy.isRotationLocked(context) 36 } catch (e: SecurityException) { 37 // TODO(b/279561841): RotationPolicy uses the current user to resolve the setting 38 // which may change before the rotation watcher can be unregistered 39 Log.e("RotationPolicy", "Failed to get isRotationLocked", e) 40 return null 41 } 42 } 43 } 44 } 45