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.keyguard
18 
19 import android.app.Presentation
20 import android.content.Context
21 import android.graphics.Color
22 import android.os.Bundle
23 import android.view.Display
24 import android.view.LayoutInflater
25 import android.view.View
26 import android.view.WindowManager
27 import com.android.keyguard.dagger.KeyguardStatusViewComponent
28 import com.android.systemui.R
29 import dagger.assisted.Assisted
30 import dagger.assisted.AssistedFactory
31 import dagger.assisted.AssistedInject
32 
33 /** [Presentation] shown in connected displays while on keyguard. */
34 class ConnectedDisplayKeyguardPresentation
35 @AssistedInject
36 constructor(
37     @Assisted display: Display,
38     context: Context,
39     private val keyguardStatusViewComponentFactory: KeyguardStatusViewComponent.Factory,
40 ) :
41     Presentation(
42         context,
43         display,
44         R.style.Theme_SystemUI_KeyguardPresentation,
45         WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
46     ) {
47 
48     private lateinit var keyguardStatusViewController: KeyguardStatusViewController
49     private lateinit var clock: KeyguardStatusView
50 
51     override fun onCreate(savedInstanceState: Bundle?) {
52         super.onCreate(savedInstanceState)
53 
54         setContentView(
55             LayoutInflater.from(context)
56                 .inflate(R.layout.keyguard_clock_presentation, /* root= */ null)
57         )
58         val window = window ?: error("no window available.")
59 
60         // Logic to make the lock screen fullscreen
61         window.decorView.systemUiVisibility =
62             (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
63                 View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
64                 View.SYSTEM_UI_FLAG_LAYOUT_STABLE)
65         window.attributes.fitInsetsTypes = 0
66         window.isNavigationBarContrastEnforced = false
67         window.navigationBarColor = Color.TRANSPARENT
68 
69         clock = requireViewById(R.id.clock)
70         keyguardStatusViewController =
71             keyguardStatusViewComponentFactory.build(clock).keyguardStatusViewController.apply {
72                 setDisplayedOnSecondaryDisplay()
73                 init()
74             }
75     }
76 
77     /** [ConnectedDisplayKeyguardPresentation] factory. */
78     @AssistedFactory
79     interface Factory {
80         /** Creates a new [Presentation] for the given [display]. */
81         fun create(
82             display: Display,
83         ): ConnectedDisplayKeyguardPresentation
84     }
85 }
86