• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.app.UiModeManager;
20 import android.car.hardware.power.CarPowerManager;
21 import android.content.BroadcastReceiver;
22 import android.content.Context;
23 import android.content.Intent;
24 import android.content.IntentFilter;
25 import android.content.res.Configuration;
26 import android.os.UserHandle;
27 import android.util.Log;
28 
29 import androidx.annotation.CallSuper;
30 
31 import com.android.systemui.broadcast.BroadcastDispatcher;
32 import com.android.systemui.car.CarDeviceProvisionedController;
33 import com.android.systemui.car.systembar.CarSystemBarController;
34 import com.android.systemui.car.window.OverlayViewMediator;
35 import com.android.systemui.dagger.SysUISingleton;
36 import com.android.systemui.statusbar.policy.ConfigurationController;
37 
38 import javax.inject.Inject;
39 
40 /**
41  * The view mediator which attaches the view controller to other elements of the system ui. Disables
42  * drag open behavior of the notification panel from any navigation bar.
43  */
44 @SysUISingleton
45 public class NotificationPanelViewMediator implements OverlayViewMediator,
46         ConfigurationController.ConfigurationListener {
47 
48     private static final boolean DEBUG = false;
49     private static final String TAG = "NotificationPanelVM";
50 
51     private final CarSystemBarController mCarSystemBarController;
52     private final NotificationPanelViewController mNotificationPanelViewController;
53     private final PowerManagerHelper mPowerManagerHelper;
54     private final BroadcastDispatcher mBroadcastDispatcher;
55     private final CarDeviceProvisionedController mCarDeviceProvisionedController;
56     private final ConfigurationController mConfigurationController;
57     private final UiModeManager mUiModeManager;
58 
59     private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
60         @Override
61         public void onReceive(Context context, Intent intent) {
62             if (DEBUG) Log.v(TAG, "onReceive: " + intent);
63             String action = intent.getAction();
64             if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) {
65                 if (mNotificationPanelViewController.isPanelExpanded()) {
66                     mNotificationPanelViewController.toggle();
67                 }
68             }
69         }
70     };
71 
72     private boolean mIsUiModeNight;
73 
74     @Inject
NotificationPanelViewMediator( CarSystemBarController carSystemBarController, NotificationPanelViewController notificationPanelViewController, PowerManagerHelper powerManagerHelper, BroadcastDispatcher broadcastDispatcher, CarDeviceProvisionedController carDeviceProvisionedController, ConfigurationController configurationController, UiModeManager uiModeManager )75     public NotificationPanelViewMediator(
76             CarSystemBarController carSystemBarController,
77             NotificationPanelViewController notificationPanelViewController,
78 
79             PowerManagerHelper powerManagerHelper,
80             BroadcastDispatcher broadcastDispatcher,
81 
82             CarDeviceProvisionedController carDeviceProvisionedController,
83             ConfigurationController configurationController,
84             UiModeManager uiModeManager
85     ) {
86         mCarSystemBarController = carSystemBarController;
87         mNotificationPanelViewController = notificationPanelViewController;
88         mPowerManagerHelper = powerManagerHelper;
89         mBroadcastDispatcher = broadcastDispatcher;
90         mCarDeviceProvisionedController = carDeviceProvisionedController;
91         mConfigurationController = configurationController;
92         mUiModeManager = uiModeManager;
93     }
94 
95     @Override
96     @CallSuper
registerListeners()97     public void registerListeners() {
98         registerTopBarTouchListener();
99         registerBottomBarTouchListener();
100         registerLeftBarTouchListener();
101         registerRightBarTouchListener();
102 
103         mCarSystemBarController.registerNotificationController(
104                 new CarSystemBarController.NotificationsShadeController() {
105                     @Override
106                     public void togglePanel() {
107                         mNotificationPanelViewController.toggle();
108                     }
109 
110                     @Override
111                     public boolean isNotificationPanelOpen() {
112                         return mNotificationPanelViewController.isPanelExpanded();
113                     }
114                 });
115 
116         mBroadcastDispatcher.registerReceiver(mBroadcastReceiver,
117                 new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS), null, UserHandle.ALL);
118     }
119 
120     @Override
setUpOverlayContentViewControllers()121     public void setUpOverlayContentViewControllers() {
122         mNotificationPanelViewController.setOnUnseenCountUpdateListener(unseenNotificationCount -> {
123             boolean hasUnseen = unseenNotificationCount > 0;
124             mCarSystemBarController.toggleAllNotificationsUnseenIndicator(
125                     mCarDeviceProvisionedController.isCurrentUserFullySetup(), hasUnseen);
126         });
127 
128         mPowerManagerHelper.setCarPowerStateListener(state -> {
129             if (state == CarPowerManager.STATE_ON) {
130                 mNotificationPanelViewController.onCarPowerStateOn();
131             }
132         });
133         mPowerManagerHelper.connectToCarService();
134 
135         mConfigurationController.addCallback(this);
136     }
137 
138     @Override
onConfigChanged(Configuration newConfig)139     public void onConfigChanged(Configuration newConfig) {
140         boolean isConfigNightMode = (newConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK)
141                 == Configuration.UI_MODE_NIGHT_YES;
142         // Only refresh UI on Night mode changes
143         if (isConfigNightMode != mIsUiModeNight) {
144             mIsUiModeNight = isConfigNightMode;
145             mUiModeManager.setNightModeActivated(mIsUiModeNight);
146             mNotificationPanelViewController.reinflate();
147             registerListeners();
148         }
149     }
150 
151     @Override
onDensityOrFontScaleChanged()152     public void onDensityOrFontScaleChanged() {
153         registerListeners();
154     }
155 
156     @Override
onUiModeChanged()157     public void onUiModeChanged() {
158         // No op.
159     }
160 
161     @Override
onThemeChanged()162     public void onThemeChanged() {
163         // No op.
164     }
165 
166     @Override
onLocaleListChanged()167     public void onLocaleListChanged() {
168         mNotificationPanelViewController.reinflate();
169         registerListeners();
170     }
171 
registerTopBarTouchListener()172     protected void registerTopBarTouchListener() {
173         mCarSystemBarController.registerTopBarTouchListener(
174                 mNotificationPanelViewController.getDragCloseTouchListener());
175     }
176 
registerBottomBarTouchListener()177     protected void registerBottomBarTouchListener() {
178         mCarSystemBarController.registerBottomBarTouchListener(
179                 mNotificationPanelViewController.getDragCloseTouchListener());
180     }
181 
registerLeftBarTouchListener()182     protected void registerLeftBarTouchListener() {
183         mCarSystemBarController.registerLeftBarTouchListener(
184                 mNotificationPanelViewController.getDragCloseTouchListener());
185     }
186 
registerRightBarTouchListener()187     protected void registerRightBarTouchListener() {
188         mCarSystemBarController.registerRightBarTouchListener(
189                 mNotificationPanelViewController.getDragCloseTouchListener());
190     }
191 
getCarSystemBarController()192     protected final CarSystemBarController getCarSystemBarController() {
193         return mCarSystemBarController;
194     }
195 
getNotificationPanelViewController()196     protected final NotificationPanelViewController getNotificationPanelViewController() {
197         return mNotificationPanelViewController;
198     }
199 }
200