1 /* 2 * Copyright (C) 2019 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.NotificationLockscreenUserManager.RedactionType; 20 21 import android.annotation.IntDef; 22 import android.annotation.NonNull; 23 import android.annotation.Nullable; 24 25 import androidx.annotation.VisibleForTesting; 26 27 import com.android.systemui.statusbar.notification.collection.EntryAdapter; 28 import com.android.systemui.statusbar.notification.collection.NotificationEntry; 29 30 import java.lang.annotation.Retention; 31 import java.lang.annotation.RetentionPolicy; 32 33 /** 34 * Binder that takes a notifications {@link ExpandableNotificationRow} and binds the appropriate 35 * content to it based off the bind parameters passed to it. 36 */ 37 public interface NotificationRowContentBinder { 38 39 /** 40 * Inflate notification content views and bind to the row. 41 * 42 * @param entry notification 43 * @param row notification row to bind views to 44 * @param contentToBind content views that should be inflated and bound 45 * @param bindParams parameters for binding content views 46 * @param forceInflate true to force reinflation even if views are cached 47 * @param callback callback after inflation is finished 48 */ bindContent( @onNull NotificationEntry entry, @NonNull ExpandableNotificationRow row, @InflationFlag int contentToBind, BindParams bindParams, boolean forceInflate, @Nullable InflationCallback callback)49 void bindContent( 50 @NonNull NotificationEntry entry, 51 @NonNull ExpandableNotificationRow row, 52 @InflationFlag int contentToBind, 53 BindParams bindParams, 54 boolean forceInflate, 55 @Nullable InflationCallback callback); 56 57 /** 58 * Cancel any on-going bind operation. 59 * 60 * @param entry notification 61 * @param row notification row to cancel bind on 62 * @return true if an on-going bind operation was cancelled 63 */ cancelBind( @onNull NotificationEntry entry, @NonNull ExpandableNotificationRow row)64 boolean cancelBind( 65 @NonNull NotificationEntry entry, 66 @NonNull ExpandableNotificationRow row); 67 68 /** 69 * Unbind content views from the row. 70 * 71 * @param entry notification 72 * @param row notification row to unbind content views from 73 * @param contentToUnbind content views that should be unbound 74 */ unbindContent( @onNull NotificationEntry entry, @NonNull ExpandableNotificationRow row, @InflationFlag int contentToUnbind)75 void unbindContent( 76 @NonNull NotificationEntry entry, 77 @NonNull ExpandableNotificationRow row, 78 @InflationFlag int contentToUnbind); 79 80 /** For testing, ensure all inflation is synchronous. */ 81 @VisibleForTesting setInflateSynchronously(boolean inflateSynchronously)82 void setInflateSynchronously(boolean inflateSynchronously); 83 84 @Retention(RetentionPolicy.SOURCE) 85 @IntDef(flag = true, 86 prefix = {"FLAG_CONTENT_VIEW_"}, 87 value = { 88 FLAG_CONTENT_VIEW_CONTRACTED, 89 FLAG_CONTENT_VIEW_EXPANDED, 90 FLAG_CONTENT_VIEW_HEADS_UP, 91 FLAG_CONTENT_VIEW_PUBLIC, 92 FLAG_CONTENT_VIEW_SINGLE_LINE, 93 FLAG_GROUP_SUMMARY_HEADER, 94 FLAG_LOW_PRIORITY_GROUP_SUMMARY_HEADER, 95 FLAG_CONTENT_VIEW_PUBLIC_SINGLE_LINE, 96 FLAG_CONTENT_VIEW_ALL}) 97 @interface InflationFlag {} 98 /** 99 * The default, contracted view. Seen when the shade is pulled down and in the lock screen 100 * if there is no worry about content sensitivity. 101 */ 102 int FLAG_CONTENT_VIEW_CONTRACTED = 1; 103 /** 104 * The expanded view. Seen when the user expands a notification. 105 */ 106 int FLAG_CONTENT_VIEW_EXPANDED = 1 << 1; 107 /** 108 * The heads up view. Seen when a high priority notification peeks in from the top. 109 */ 110 int FLAG_CONTENT_VIEW_HEADS_UP = 1 << 2; 111 /** 112 * The public view. This is a version of the contracted view that hides sensitive 113 * information and is used on the lock screen if we determine that the notification's 114 * content should be hidden. 115 */ 116 int FLAG_CONTENT_VIEW_PUBLIC = 1 << 3; 117 118 /** 119 * The single line notification view. Show when the notification is shown as a child in group. 120 */ 121 int FLAG_CONTENT_VIEW_SINGLE_LINE = 1 << 4; 122 123 /** 124 * The notification group summary header view 125 */ 126 int FLAG_GROUP_SUMMARY_HEADER = 1 << 5; 127 128 /** 129 * The notification low-priority group summary header view 130 */ 131 int FLAG_LOW_PRIORITY_GROUP_SUMMARY_HEADER = 1 << 6; 132 133 /** 134 * The public single line view. This is a version of the contracted view that hides sensitive 135 * information and is used on the lock screen if we determine that the notification's 136 * content should be hidden, and the notification is shown as a child in a group. 137 */ 138 int FLAG_CONTENT_VIEW_PUBLIC_SINGLE_LINE = 1 << 7; 139 140 int FLAG_CONTENT_VIEW_ALL = (1 << 8) - 1; 141 142 /** 143 * Parameters for content view binding 144 */ 145 class BindParams { 146 BindParams(boolean minimized, int redaction)147 public BindParams(boolean minimized, int redaction) { 148 isMinimized = minimized; 149 redactionType = redaction; 150 } 151 152 /** 153 * Bind a minimized version of the content views. 154 */ 155 public final boolean isMinimized; 156 157 /** 158 * Controls the type of public view to show, if a public view is requested 159 */ 160 public final @RedactionType int redactionType; 161 } 162 163 /** 164 * Callback for inflation finishing 165 */ 166 interface InflationCallback { 167 168 /** 169 * Callback for when there is an inflation exception 170 * 171 * @param entry notification which failed to inflate content 172 * @param e exception 173 */ handleInflationException(NotificationEntry entry, Exception e)174 default void handleInflationException(NotificationEntry entry, Exception e) { 175 handleInflationException(e); 176 } 177 178 /** 179 * Callback for when there is an inflation exception 180 * 181 * @param e exception 182 */ handleInflationException(Exception e)183 void handleInflationException(Exception e); 184 185 /** 186 * Callback for after the content views finish inflating. 187 * 188 * @param entry the entry with the content views set 189 */ onAsyncInflationFinished(NotificationEntry entry)190 default void onAsyncInflationFinished(NotificationEntry entry) { 191 onAsyncInflationFinished(); 192 } 193 194 /** 195 * Callback for after the content views finish inflating. 196 */ onAsyncInflationFinished()197 void onAsyncInflationFinished(); 198 } 199 } 200