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 package com.android.systemui.mediaprojection.devicepolicy
17 
18 import android.os.UserHandle
19 import com.android.systemui.settings.UserTracker
20 import com.android.systemui.shared.system.ActivityManagerWrapper
21 import dagger.Module
22 import dagger.Provides
23 import javax.inject.Qualifier
24 
25 @Qualifier @Retention(AnnotationRetention.BINARY) annotation class WorkProfile
26 
27 @Qualifier @Retention(AnnotationRetention.BINARY) annotation class PersonalProfile
28 
29 /** Module for media projection device policy related dependencies */
30 @Module
31 class MediaProjectionDevicePolicyModule {
32     @Provides
33     @PersonalProfile
personalUserHandlenull34     fun personalUserHandle(activityManagerWrapper: ActivityManagerWrapper): UserHandle {
35         // Current foreground user is the 'personal' profile
36         return UserHandle.of(activityManagerWrapper.currentUserId)
37     }
38 
39     @Provides
40     @WorkProfile
workProfileUserHandlenull41     fun workProfileUserHandle(userTracker: UserTracker): UserHandle? =
42         userTracker.userProfiles.find { it.isManagedProfile }?.userHandle
43 }
44