1 /*
2  * Copyright (C) 2022 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.car.users;
18 
19 import android.app.ActivityManager;
20 import android.app.IActivityManager;
21 import android.content.Context;
22 import android.os.Handler;
23 import android.os.Process;
24 import android.os.UserHandle;
25 import android.os.UserManager;
26 
27 import com.android.systemui.CoreStartable;
28 import com.android.systemui.InitController;
29 import com.android.systemui.car.CarServiceProvider;
30 import com.android.systemui.dagger.SysUISingleton;
31 import com.android.systemui.dagger.qualifiers.Application;
32 import com.android.systemui.dagger.qualifiers.Background;
33 import com.android.systemui.dump.DumpManager;
34 import com.android.systemui.flags.FeatureFlagsClassic;
35 import com.android.systemui.settings.DisplayTracker;
36 import com.android.systemui.settings.UserContentResolverProvider;
37 import com.android.systemui.settings.UserContextProvider;
38 import com.android.systemui.settings.UserFileManager;
39 import com.android.systemui.settings.UserFileManagerImpl;
40 import com.android.systemui.settings.UserTracker;
41 
42 import dagger.Binds;
43 import dagger.Module;
44 import dagger.Provides;
45 import dagger.multibindings.ClassKey;
46 import dagger.multibindings.IntoMap;
47 
48 import javax.inject.Provider;
49 
50 import kotlinx.coroutines.CoroutineDispatcher;
51 import kotlinx.coroutines.CoroutineScope;
52 
53 /**
54  * Car-specific dagger Module for classes found within the com.android.systemui.settings package.
55  */
56 @Module
57 public abstract class CarMultiUserUtilsModule {
58     @Binds
59     @SysUISingleton
bindUserContextProvider(UserTracker tracker)60     abstract UserContextProvider bindUserContextProvider(UserTracker tracker);
61 
62     @Binds
63     @SysUISingleton
bindUserContentResolverProvider( UserTracker tracker)64     abstract UserContentResolverProvider bindUserContentResolverProvider(
65             UserTracker tracker);
66 
67     @SysUISingleton
68     @Provides
provideUserTracker( Context context, Provider<FeatureFlagsClassic> featureFlagsProvider, UserManager userManager, IActivityManager iActivityManager, DumpManager dumpManager, @Application CoroutineScope appScope, @Background CoroutineDispatcher backgroundDispatcher, @Background Handler handler, CarServiceProvider carServiceProvider, InitController initController )69     static UserTracker provideUserTracker(
70             Context context,
71             Provider<FeatureFlagsClassic> featureFlagsProvider,
72             UserManager userManager,
73             IActivityManager iActivityManager,
74             DumpManager dumpManager,
75             @Application CoroutineScope appScope,
76             @Background CoroutineDispatcher backgroundDispatcher,
77             @Background Handler handler,
78             CarServiceProvider carServiceProvider,
79             InitController initController
80     ) {
81         if (CarSystemUIUserUtil.isMUPANDSystemUI()) {
82             CarMUPANDUserTrackerImpl mupandTracker = new CarMUPANDUserTrackerImpl(context,
83                     featureFlagsProvider, userManager, iActivityManager, dumpManager, appScope,
84                     backgroundDispatcher, handler, carServiceProvider, initController);
85             mupandTracker.initialize(ActivityManager.getCurrentUser());
86             return mupandTracker;
87         }
88         UserHandle processUser = Process.myUserHandle();
89         boolean isSecondaryUserSystemUI =
90                 CarSystemUIUserUtil.isSecondaryMUMDSystemUI();
91         int startingUser = isSecondaryUserSystemUI
92                 ? processUser.getIdentifier()
93                 : ActivityManager.getCurrentUser();
94         CarUserTrackerImpl tracker = new CarUserTrackerImpl(context, featureFlagsProvider,
95                 userManager, iActivityManager, dumpManager, appScope, backgroundDispatcher,
96                 handler, isSecondaryUserSystemUI);
97         tracker.initialize(startingUser);
98         return tracker;
99     }
100 
101     @SysUISingleton
102     @Provides
provideDisplayTracker( Context context, UserTracker userTracker, CarServiceProvider carServiceProvider, @Background Handler handler )103     static DisplayTracker provideDisplayTracker(
104             Context context,
105             UserTracker userTracker,
106             CarServiceProvider carServiceProvider,
107             @Background Handler handler
108     ) {
109         return new CarDisplayTrackerImpl(context, userTracker, carServiceProvider, handler);
110     }
111 
112     @Binds
113     @IntoMap
114     @ClassKey(UserFileManagerImpl.class)
bindUserFileManagerCoreStartable(UserFileManagerImpl sysui)115     abstract CoreStartable bindUserFileManagerCoreStartable(UserFileManagerImpl sysui);
116 
117     @Binds
bindUserFileManager(UserFileManagerImpl impl)118     abstract UserFileManager bindUserFileManager(UserFileManagerImpl impl);
119 
120 
121 }
122