1 /*
2  * Copyright (C) 2020 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.notification;
18 
19 import android.content.Context;
20 import android.graphics.PixelFormat;
21 import android.view.Gravity;
22 import android.view.ViewGroup;
23 import android.view.WindowManager;
24 
25 import com.android.car.notification.headsup.CarHeadsUpNotificationContainer;
26 import com.android.systemui.car.CarDeviceProvisionedController;
27 import com.android.systemui.car.window.OverlayViewGlobalStateController;
28 import com.android.systemui.dagger.SysUISingleton;
29 
30 import javax.inject.Inject;
31 
32 /**
33  * A controller for SysUI's HUN display.
34  *
35  * Used to attach HUNs views to window and determine whether to show HUN panel.
36  */
37 @SysUISingleton
38 public class CarHeadsUpNotificationSystemContainer extends CarHeadsUpNotificationContainer {
39     private static final String WINDOW_TITLE = "HeadsUpNotification";
40     private final CarDeviceProvisionedController mCarDeviceProvisionedController;
41     private final OverlayViewGlobalStateController mOverlayViewGlobalStateController;
42 
43     @Inject
CarHeadsUpNotificationSystemContainer(Context context, CarDeviceProvisionedController deviceProvisionedController, WindowManager windowManager, OverlayViewGlobalStateController overlayViewGlobalStateController)44     CarHeadsUpNotificationSystemContainer(Context context,
45             CarDeviceProvisionedController deviceProvisionedController,
46             WindowManager windowManager,
47             OverlayViewGlobalStateController overlayViewGlobalStateController) {
48         super(context, windowManager);
49         mCarDeviceProvisionedController = deviceProvisionedController;
50         mOverlayViewGlobalStateController = overlayViewGlobalStateController;
51     }
52 
53     @Override
getWindowManagerLayoutParams()54     protected WindowManager.LayoutParams getWindowManagerLayoutParams() {
55         // Use TYPE_STATUS_BAR_SUB_PANEL window type since we need to find a window that is above
56         // status bar but below navigation bar.
57         WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
58                 ViewGroup.LayoutParams.MATCH_PARENT,
59                 WindowManager.LayoutParams.WRAP_CONTENT,
60                 WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL,
61                 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
62                         | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
63                 PixelFormat.TRANSLUCENT);
64 
65         lp.gravity = getShowHunOnBottom() ? Gravity.BOTTOM : Gravity.TOP;
66         lp.setTitle(WINDOW_TITLE);
67 
68         return lp;
69     }
70 
71     @Override
shouldShowHunPanel()72     public boolean shouldShowHunPanel() {
73         return mCarDeviceProvisionedController.isCurrentUserFullySetup()
74                 && mOverlayViewGlobalStateController.shouldShowHUN();
75     }
76 }
77