xref: /aosp_15_r20/frameworks/base/packages/SystemUI/unfold/src/com/android/systemui/unfold/UnfoldRemoteModule.kt (revision d57664e9bc4670b3ecf6748a746a57c557b6bc9e)
1 /*
2  * Copyright (C) 2023 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.unfold
18 
19 import android.os.Handler
20 import com.android.systemui.unfold.config.UnfoldTransitionConfig
21 import com.android.systemui.unfold.dagger.UnfoldMain
22 import com.android.systemui.unfold.dagger.UseReceivingFilter
23 import com.android.systemui.unfold.progress.RemoteUnfoldTransitionReceiver
24 import com.android.systemui.unfold.updates.RotationChangeProvider
25 import com.android.systemui.unfold.util.ATraceLoggerTransitionProgressListener
26 import dagger.Module
27 import dagger.Provides
28 import java.util.Optional
29 import javax.inject.Provider
30 import javax.inject.Singleton
31 
32 /** Binds classes needed to provide unfold transition progresses to another process. */
33 @Module
34 class UnfoldRemoteModule {
35     @Provides
36     @Singleton
provideTransitionProvidernull37     fun provideTransitionProvider(
38         config: UnfoldTransitionConfig,
39         traceListener: ATraceLoggerTransitionProgressListener.Factory,
40         remoteReceiverProvider: Provider<RemoteUnfoldTransitionReceiver>,
41     ): Optional<RemoteUnfoldTransitionReceiver> {
42         if (!config.isEnabled) {
43             return Optional.empty()
44         }
45         val remoteReceiver = remoteReceiverProvider.get()
46         remoteReceiver.addCallback(traceListener.create("remoteReceiver"))
47         return Optional.of(remoteReceiver)
48     }
49 
useReceivingFilternull50     @Provides @UseReceivingFilter fun useReceivingFilter(): Boolean = true
51 
52     @Provides
53     @UnfoldMain
54     fun provideMainRotationChangeProvider(
55         rotationChangeProviderFactory: RotationChangeProvider.Factory,
56         @UnfoldMain callbackHandler: Handler,
57     ): RotationChangeProvider {
58         return rotationChangeProviderFactory.create(callbackHandler)
59     }
60 }
61