• 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.statusbar.notification.row;
18 
19 import static com.android.systemui.Dependency.ALLOW_NOTIFICATION_LONG_PRESS_NAME;
20 import static com.android.systemui.statusbar.NotificationRemoteInputManager.ENABLE_REMOTE_INPUT;
21 
22 import android.view.View;
23 import android.view.ViewGroup;
24 
25 import com.android.systemui.plugins.FalsingManager;
26 import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin;
27 import com.android.systemui.plugins.statusbar.StatusBarStateController;
28 import com.android.systemui.shared.plugins.PluginManager;
29 import com.android.systemui.statusbar.NotificationMediaManager;
30 import com.android.systemui.statusbar.notification.logging.NotificationLogger;
31 import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier;
32 import com.android.systemui.statusbar.notification.row.dagger.AppName;
33 import com.android.systemui.statusbar.notification.row.dagger.DismissRunnable;
34 import com.android.systemui.statusbar.notification.row.dagger.NotificationKey;
35 import com.android.systemui.statusbar.notification.row.dagger.NotificationRowScope;
36 import com.android.systemui.statusbar.phone.KeyguardBypassController;
37 import com.android.systemui.statusbar.phone.NotificationGroupManager;
38 import com.android.systemui.statusbar.policy.HeadsUpManager;
39 import com.android.systemui.util.time.SystemClock;
40 
41 import javax.inject.Inject;
42 import javax.inject.Named;
43 
44 /**
45  * Controller for {@link ExpandableNotificationRow}.
46  */
47 @NotificationRowScope
48 public class ExpandableNotificationRowController {
49     private final ExpandableNotificationRow mView;
50     private final ActivatableNotificationViewController mActivatableNotificationViewController;
51     private final NotificationMediaManager mMediaManager;
52     private final PluginManager mPluginManager;
53     private final SystemClock mClock;
54     private final String mAppName;
55     private final String mNotificationKey;
56     private final KeyguardBypassController mKeyguardBypassController;
57     private final NotificationGroupManager mNotificationGroupManager;
58     private final RowContentBindStage mRowContentBindStage;
59     private final NotificationLogger mNotificationLogger;
60     private final HeadsUpManager mHeadsUpManager;
61     private final ExpandableNotificationRow.OnExpandClickListener mOnExpandClickListener;
62     private final StatusBarStateController mStatusBarStateController;
63 
64     private final ExpandableNotificationRow.ExpansionLogger mExpansionLogger =
65             this::logNotificationExpansion;
66     private final ExpandableNotificationRow.OnAppOpsClickListener mOnAppOpsClickListener;
67     private final NotificationGutsManager mNotificationGutsManager;
68     private Runnable mOnDismissRunnable;
69     private final FalsingManager mFalsingManager;
70     private final boolean mAllowLongPress;
71     private final PeopleNotificationIdentifier mPeopleNotificationIdentifier;
72 
73     @Inject
ExpandableNotificationRowController(ExpandableNotificationRow view, ActivatableNotificationViewController activatableNotificationViewController, NotificationMediaManager mediaManager, PluginManager pluginManager, SystemClock clock, @AppName String appName, @NotificationKey String notificationKey, KeyguardBypassController keyguardBypassController, NotificationGroupManager notificationGroupManager, RowContentBindStage rowContentBindStage, NotificationLogger notificationLogger, HeadsUpManager headsUpManager, ExpandableNotificationRow.OnExpandClickListener onExpandClickListener, StatusBarStateController statusBarStateController, NotificationGutsManager notificationGutsManager, @Named(ALLOW_NOTIFICATION_LONG_PRESS_NAME) boolean allowLongPress, @DismissRunnable Runnable onDismissRunnable, FalsingManager falsingManager, PeopleNotificationIdentifier peopleNotificationIdentifier)74     public ExpandableNotificationRowController(ExpandableNotificationRow view,
75             ActivatableNotificationViewController activatableNotificationViewController,
76             NotificationMediaManager mediaManager, PluginManager pluginManager,
77             SystemClock clock, @AppName String appName, @NotificationKey String notificationKey,
78             KeyguardBypassController keyguardBypassController,
79             NotificationGroupManager notificationGroupManager,
80             RowContentBindStage rowContentBindStage,
81             NotificationLogger notificationLogger, HeadsUpManager headsUpManager,
82             ExpandableNotificationRow.OnExpandClickListener onExpandClickListener,
83             StatusBarStateController statusBarStateController,
84             NotificationGutsManager notificationGutsManager,
85             @Named(ALLOW_NOTIFICATION_LONG_PRESS_NAME) boolean allowLongPress,
86             @DismissRunnable Runnable onDismissRunnable, FalsingManager falsingManager,
87             PeopleNotificationIdentifier peopleNotificationIdentifier) {
88         mView = view;
89         mActivatableNotificationViewController = activatableNotificationViewController;
90         mMediaManager = mediaManager;
91         mPluginManager = pluginManager;
92         mClock = clock;
93         mAppName = appName;
94         mNotificationKey = notificationKey;
95         mKeyguardBypassController = keyguardBypassController;
96         mNotificationGroupManager = notificationGroupManager;
97         mRowContentBindStage = rowContentBindStage;
98         mNotificationLogger = notificationLogger;
99         mHeadsUpManager = headsUpManager;
100         mOnExpandClickListener = onExpandClickListener;
101         mStatusBarStateController = statusBarStateController;
102         mNotificationGutsManager = notificationGutsManager;
103         mOnDismissRunnable = onDismissRunnable;
104         mOnAppOpsClickListener = mNotificationGutsManager::openGuts;
105         mAllowLongPress = allowLongPress;
106         mFalsingManager = falsingManager;
107         mPeopleNotificationIdentifier = peopleNotificationIdentifier;
108     }
109 
110     /**
111      * Initialize the controller.
112      */
init()113     public void init() {
114         mActivatableNotificationViewController.init();
115         mView.initialize(
116                 mAppName,
117                 mNotificationKey,
118                 mExpansionLogger,
119                 mKeyguardBypassController,
120                 mNotificationGroupManager,
121                 mHeadsUpManager,
122                 mRowContentBindStage,
123                 mOnExpandClickListener,
124                 mMediaManager,
125                 mOnAppOpsClickListener,
126                 mFalsingManager,
127                 mStatusBarStateController,
128                 mPeopleNotificationIdentifier
129         );
130         mView.setOnDismissRunnable(mOnDismissRunnable);
131         mView.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
132         if (mAllowLongPress) {
133             mView.setLongPressListener((v, x, y, item) -> {
134                 if (mView.isSummaryWithChildren()) {
135                     mView.expandNotification();
136                     return true;
137                 }
138                 return mNotificationGutsManager.openGuts(v, x, y, item);
139             });
140         }
141         if (ENABLE_REMOTE_INPUT) {
142             mView.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
143         }
144 
145         mView.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
146             @Override
147             public void onViewAttachedToWindow(View v) {
148                 mView.getEntry().setInitializationTime(mClock.elapsedRealtime());
149                 mPluginManager.addPluginListener(mView,
150                         NotificationMenuRowPlugin.class, false /* Allow multiple */);
151             }
152 
153             @Override
154             public void onViewDetachedFromWindow(View v) {
155                 mPluginManager.removePluginListener(mView);
156             }
157         });
158     }
159 
logNotificationExpansion(String key, boolean userAction, boolean expanded)160     private void logNotificationExpansion(String key, boolean userAction, boolean expanded) {
161         mNotificationLogger.onExpansionChanged(key, userAction, expanded);
162     }
163 
164     /** */
setOnDismissRunnable(Runnable onDismissRunnable)165     public void setOnDismissRunnable(Runnable onDismissRunnable) {
166         mOnDismissRunnable = onDismissRunnable;
167         mView.setOnDismissRunnable(onDismissRunnable);
168     }
169 }
170