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 com.android.internal.view.RotationPolicy 21 import com.android.internal.view.RotationPolicy.RotationPolicyListener 22 import javax.inject.Inject 23 24 /** 25 * Testable wrapper interface around RotationPolicy {link com.android.internal.view.RotationPolicy} 26 */ 27 interface RotationPolicyWrapper { 28 fun setRotationLock(enabled: Boolean) 29 fun setRotationLockAtAngle(enabled: Boolean, rotation: Int) 30 fun getRotationLockOrientation(): Int 31 fun isRotationLockToggleVisible(): Boolean 32 fun isRotationLocked(): Boolean 33 fun registerRotationPolicyListener(listener: RotationPolicyListener, userHandle: Int) 34 fun unregisterRotationPolicyListener(listener: RotationPolicyListener) 35 } 36 37 class RotationPolicyWrapperImpl @Inject constructor(private val context: Context) : 38 RotationPolicyWrapper { 39 40 override fun setRotationLock(enabled: Boolean) { 41 RotationPolicy.setRotationLock(context, enabled) 42 } 43 44 override fun setRotationLockAtAngle(enabled: Boolean, rotation: Int) { 45 RotationPolicy.setRotationLockAtAngle(context, enabled, rotation) 46 } 47 48 override fun getRotationLockOrientation(): Int = 49 RotationPolicy.getRotationLockOrientation(context) 50 51 override fun isRotationLockToggleVisible(): Boolean = 52 RotationPolicy.isRotationLockToggleVisible(context) 53 54 override fun isRotationLocked(): Boolean = 55 RotationPolicy.isRotationLocked(context) 56 57 override fun registerRotationPolicyListener( 58 listener: RotationPolicyListener, 59 userHandle: Int 60 ) { 61 RotationPolicy.registerRotationPolicyListener(context, listener, userHandle) 62 } 63 64 override fun unregisterRotationPolicyListener(listener: RotationPolicyListener) { 65 RotationPolicy.unregisterRotationPolicyListener(context, listener) 66 } 67 } 68