1 /* 2 * Copyright (C) 2021 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.util.wrapper 18 19 import android.content.Context 20 import android.provider.Settings.Secure.CAMERA_AUTOROTATE 21 import com.android.internal.view.RotationPolicy 22 import com.android.internal.view.RotationPolicy.RotationPolicyListener 23 import com.android.systemui.util.settings.SecureSettings 24 import com.android.app.tracing.traceSection 25 import javax.inject.Inject 26 27 /** 28 * Testable wrapper interface around RotationPolicy {link com.android.internal.view.RotationPolicy} 29 */ 30 interface RotationPolicyWrapper { setRotationLocknull31 fun setRotationLock(enabled: Boolean, caller: String) 32 fun setRotationLockAtAngle(enabled: Boolean, rotation: Int, caller: String) 33 fun getRotationLockOrientation(): Int 34 fun isRotationLockToggleVisible(): Boolean 35 fun isRotationLocked(): Boolean 36 fun isCameraRotationEnabled(): Boolean 37 fun registerRotationPolicyListener(listener: RotationPolicyListener, userHandle: Int) 38 fun unregisterRotationPolicyListener(listener: RotationPolicyListener) 39 } 40 41 class RotationPolicyWrapperImpl @Inject constructor( 42 private val context: Context, 43 private val secureSettings: SecureSettings 44 ) : 45 RotationPolicyWrapper { 46 47 override fun setRotationLock(enabled: Boolean, caller: String) { 48 traceSection("RotationPolicyWrapperImpl#setRotationLock") { 49 RotationPolicy.setRotationLock(context, enabled, caller) 50 } 51 } 52 53 override fun setRotationLockAtAngle(enabled: Boolean, rotation: Int, caller: String) { 54 RotationPolicy.setRotationLockAtAngle(context, enabled, rotation, caller) 55 } 56 57 override fun getRotationLockOrientation(): Int = 58 RotationPolicy.getRotationLockOrientation(context) 59 60 override fun isRotationLockToggleVisible(): Boolean = 61 RotationPolicy.isRotationLockToggleVisible(context) 62 63 override fun isRotationLocked(): Boolean = 64 RotationPolicy.isRotationLocked(context) 65 66 override fun isCameraRotationEnabled(): Boolean = 67 secureSettings.getInt(CAMERA_AUTOROTATE, 0) == 1 68 69 override fun registerRotationPolicyListener( 70 listener: RotationPolicyListener, 71 userHandle: Int 72 ) { 73 RotationPolicy.registerRotationPolicyListener(context, listener, userHandle) 74 } 75 76 override fun unregisterRotationPolicyListener(listener: RotationPolicyListener) { 77 RotationPolicy.unregisterRotationPolicyListener(context, listener) 78 } 79 } 80