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.systemui.rotationlock 18 19 import com.android.systemui.dagger.SysUISingleton 20 import com.android.systemui.statusbar.policy.DeviceStateRotationLockSettingController 21 import com.android.window.flags.Flags 22 import dagger.Module 23 import dagger.Provides 24 import java.util.Optional 25 import javax.inject.Provider 26 import javax.inject.Qualifier 27 28 @Module 29 class DeviceStateAutoRotateModule { 30 /** Qualifier for dependencies to be bound with [DeviceStateAutoRotateModule]. */ 31 @Qualifier 32 @MustBeDocumented 33 @Retention(AnnotationRetention.RUNTIME) 34 annotation class BoundsDeviceStateAutoRotateModule 35 36 /** 37 * Provides an instance of [DeviceStateRotationLockSettingController]. 38 * 39 * @param controllerProvider The provider for [DeviceStateRotationLockSettingController]. 40 * @return An [Optional] containing the [DeviceStateRotationLockSettingController] instance if 41 * the `Flags.enableDeviceStateAutoRotateSettingRefactor()` flag is disabled, or an empty 42 * [Optional] otherwise. 43 */ 44 @Provides 45 @BoundsDeviceStateAutoRotateModule 46 @SysUISingleton provideDeviceStateRotationLockSettingControllernull47 fun provideDeviceStateRotationLockSettingController( 48 controllerProvider: Provider<DeviceStateRotationLockSettingController> 49 ): Optional<DeviceStateRotationLockSettingController> = 50 if (Flags.enableDeviceStateAutoRotateSettingRefactor()) { 51 Optional.empty() 52 } else { 53 Optional.of(controllerProvider.get()) 54 } 55 } 56