• 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.statusbar.notification.row.NotificationRowContentBinder.FLAG_CONTENT_VIEW_ALL;
20 
21 import androidx.annotation.NonNull;
22 
23 import com.android.systemui.dagger.SysUISingleton;
24 import com.android.systemui.statusbar.notification.collection.EntryAdapter;
25 import com.android.systemui.statusbar.notification.collection.NotificationEntry;
26 import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.BindParams;
27 import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.InflationCallback;
28 import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.InflationFlag;
29 import com.android.systemui.statusbar.notification.shared.NotificationBundleUi;
30 
31 import javax.inject.Inject;
32 
33 /**
34  * A stage that binds all content views for an already inflated {@link ExpandableNotificationRow}.
35  *
36  * In the farther future, the binder logic and consequently this stage should be broken into
37  * smaller stages.
38  */
39 @SysUISingleton
40 public class RowContentBindStage extends BindStage<RowContentBindParams> {
41     private final NotificationRowContentBinder mBinder;
42     private final NotifInflationErrorManager mNotifInflationErrorManager;
43     private final RowContentBindStageLogger mLogger;
44 
45     @Inject
RowContentBindStage( NotificationRowContentBinder binder, NotifInflationErrorManager errorManager, RowContentBindStageLogger logger)46     RowContentBindStage(
47             NotificationRowContentBinder binder,
48             NotifInflationErrorManager errorManager,
49             RowContentBindStageLogger logger) {
50         mBinder = binder;
51         mNotifInflationErrorManager = errorManager;
52         mLogger = logger;
53     }
54 
55     @Override
executeStage( final @NonNull NotificationEntry entry, @NonNull ExpandableNotificationRow row, @NonNull StageCallback callback)56     protected void executeStage(
57             final @NonNull NotificationEntry entry,
58             @NonNull ExpandableNotificationRow row,
59             @NonNull StageCallback callback) {
60         RowContentBindParams params = getStageParams(entry);
61 
62         mLogger.logExecutingStage(entry, params);
63 
64         // Resolve content to bind/unbind.
65         @InflationFlag int inflationFlags = params.getContentViews();
66         @InflationFlag int invalidatedFlags = params.getDirtyContentViews();
67 
68         // Rebind the content views which are needed now, and the corresponding old views are
69         // invalidated
70         @InflationFlag int contentToBind = invalidatedFlags & inflationFlags;
71         // Unbind the content views that are not needed
72         @InflationFlag int contentToUnbind = inflationFlags ^ FLAG_CONTENT_VIEW_ALL;
73 
74         // Bind/unbind with parameters
75         mBinder.unbindContent(entry, row, contentToUnbind);
76 
77         BindParams bindParams = new BindParams(params.useMinimized(), params.getRedactionType());
78         boolean forceInflate = params.needsReinflation();
79 
80         InflationCallback inflationCallback = new InflationCallback() {
81             @Override
82             public void handleInflationException(NotificationEntry errorEntry, Exception e) {
83                 if (NotificationBundleUi.isEnabled()) {
84                     mNotifInflationErrorManager.setInflationError(entry, e);
85                 } else {
86                     mNotifInflationErrorManager.setInflationError(errorEntry, e);
87                 }
88             }
89 
90             @Override
91             public void handleInflationException(Exception e) {
92 
93             }
94 
95             @Override
96             public void onAsyncInflationFinished(NotificationEntry finishedEntry) {
97                 if (NotificationBundleUi.isEnabled()) {
98                     mNotifInflationErrorManager.clearInflationError(entry);
99                     getStageParams(entry).clearDirtyContentViews();
100                     callback.onStageFinished(entry);
101                 } else {
102                     mNotifInflationErrorManager.clearInflationError(finishedEntry);
103                     getStageParams(finishedEntry).clearDirtyContentViews();
104                     callback.onStageFinished(finishedEntry);
105                 }
106             }
107 
108             @Override
109             public void onAsyncInflationFinished() {
110 
111             }
112         };
113         mBinder.cancelBind(entry, row);
114         mBinder.bindContent(entry, row, contentToBind, bindParams, forceInflate, inflationCallback);
115     }
116 
117     @Override
abortStage( @onNull NotificationEntry entry, @NonNull ExpandableNotificationRow row)118     protected void abortStage(
119             @NonNull NotificationEntry entry,
120             @NonNull ExpandableNotificationRow row) {
121         final boolean cancelledBind = mBinder.cancelBind(entry, row);
122         if (cancelledBind) {
123             mLogger.logAbortStageCancelledBind(entry);
124         }
125     }
126 
127     @Override
newStageParams()128     protected RowContentBindParams newStageParams() {
129         return new RowContentBindParams();
130     }
131 }
132