• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
18 package com.android.systemui.keyguard.data.quickaffordance
19 
20 import android.app.StatusBarManager
21 import android.app.admin.DevicePolicyManager
22 import android.content.Context
23 import android.content.Intent
24 import com.android.systemui.ActivityIntentHelper
25 import com.android.systemui.R
26 import com.android.systemui.animation.Expandable
27 import com.android.systemui.camera.CameraIntents
28 import com.android.systemui.camera.CameraIntentsWrapper
29 import com.android.systemui.common.shared.model.ContentDescription
30 import com.android.systemui.common.shared.model.Icon
31 import com.android.systemui.dagger.SysUISingleton
32 import com.android.systemui.dagger.qualifiers.Application
33 import com.android.systemui.dagger.qualifiers.Background
34 import com.android.systemui.settings.UserTracker
35 import javax.inject.Inject
36 import kotlinx.coroutines.CoroutineDispatcher
37 import kotlinx.coroutines.flow.Flow
38 import kotlinx.coroutines.flow.flow
39 import kotlinx.coroutines.withContext
40 
41 @SysUISingleton
42 class VideoCameraQuickAffordanceConfig
43 @Inject
44 constructor(
45     @Application private val context: Context,
46     private val cameraIntents: CameraIntentsWrapper,
47     private val activityIntentHelper: ActivityIntentHelper,
48     private val userTracker: UserTracker,
49     private val devicePolicyManager: DevicePolicyManager,
50     @Background private val backgroundDispatcher: CoroutineDispatcher,
51 ) : KeyguardQuickAffordanceConfig {
52 
<lambda>null53     private val intent: Intent by lazy {
54         cameraIntents.getVideoCameraIntent().apply {
55             putExtra(
56                 CameraIntents.EXTRA_LAUNCH_SOURCE,
57                 StatusBarManager.CAMERA_LAUNCH_SOURCE_QUICK_AFFORDANCE,
58             )
59         }
60     }
61 
62     override val key: String
63         get() = BuiltInKeyguardQuickAffordanceKeys.VIDEO_CAMERA
64 
65     override val pickerName: String
66         get() = context.getString(R.string.video_camera)
67 
68     override val pickerIconResourceId: Int
69         get() = R.drawable.ic_videocam
70 
71     override val lockScreenState: Flow<KeyguardQuickAffordanceConfig.LockScreenState>
<lambda>null72         get() = flow {
73             emit(
74                 if (isLaunchable()) {
75                     KeyguardQuickAffordanceConfig.LockScreenState.Visible(
76                         icon =
77                             Icon.Resource(
78                                 R.drawable.ic_videocam,
79                                 ContentDescription.Resource(R.string.video_camera)
80                             )
81                     )
82                 } else {
83                     KeyguardQuickAffordanceConfig.LockScreenState.Hidden
84                 }
85             )
86         }
87 
getPickerScreenStatenull88     override suspend fun getPickerScreenState(): KeyguardQuickAffordanceConfig.PickerScreenState {
89         return if (isLaunchable()) {
90             super.getPickerScreenState()
91         } else {
92             KeyguardQuickAffordanceConfig.PickerScreenState.UnavailableOnDevice
93         }
94     }
95 
onTriggerednull96     override fun onTriggered(
97         expandable: Expandable?
98     ): KeyguardQuickAffordanceConfig.OnTriggeredResult {
99         return KeyguardQuickAffordanceConfig.OnTriggeredResult.StartActivity(
100             intent = intent,
101             canShowWhileLocked = false,
102         )
103     }
104 
isLaunchablenull105     private suspend fun isLaunchable(): Boolean {
106         return activityIntentHelper.getTargetActivityInfo(
107             intent,
108             userTracker.userId,
109             true,
110         ) != null &&
111             withContext(backgroundDispatcher) {
112                 !devicePolicyManager.getCameraDisabled(null, userTracker.userId)
113             }
114     }
115 }
116