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.collection; 18 19 20 import android.annotation.UptimeMillisLong; 21 22 import androidx.annotation.Nullable; 23 24 import com.android.systemui.statusbar.notification.collection.listbuilder.NotifSection; 25 26 /** 27 * Abstract superclass for top-level entries, i.e. things that can appear in the final notification 28 * list shown to users. In practice, this means either GroupEntries or NotificationEntries. 29 */ 30 public abstract class ListEntry { 31 private final String mKey; 32 private final long mCreationTime; 33 34 int mFirstAddedIteration = -1; 35 36 private final ListAttachState mPreviousAttachState = ListAttachState.create(); 37 private final ListAttachState mAttachState = ListAttachState.create(); 38 ListEntry(String key, long creationTime)39 ListEntry(String key, long creationTime) { 40 mKey = key; 41 mCreationTime = creationTime; 42 } 43 getKey()44 public String getKey() { 45 return mKey; 46 } 47 48 /** 49 * The SystemClock.uptimeMillis() when this object was created. In general, this means the 50 * moment when NotificationManager notifies our listener about the existence of this entry. 51 * 52 * This value will not change if the notification is updated, although it will change if the 53 * notification is removed and then re-posted. It is also wholly independent from 54 * Notification#when. 55 */ 56 @UptimeMillisLong getCreationTime()57 public long getCreationTime() { 58 return mCreationTime; 59 } 60 61 /** 62 * Should return the "representative entry" for this ListEntry. For NotificationEntries, its 63 * the entry itself. For groups, it should be the summary (but if a summary doesn't exist, 64 * this can return null). This method exists to interface with 65 * legacy code that expects groups to also be NotificationEntries. 66 */ getRepresentativeEntry()67 public abstract @Nullable NotificationEntry getRepresentativeEntry(); 68 getParent()69 @Nullable public GroupEntry getParent() { 70 return mAttachState.getParent(); 71 } 72 setParent(@ullable GroupEntry parent)73 void setParent(@Nullable GroupEntry parent) { 74 mAttachState.setParent(parent); 75 } 76 getPreviousParent()77 @Nullable public GroupEntry getPreviousParent() { 78 return mPreviousAttachState.getParent(); 79 } 80 getSection()81 @Nullable public NotifSection getSection() { 82 return mAttachState.getSection(); 83 } 84 getSectionIndex()85 public int getSectionIndex() { 86 return mAttachState.getSection() != null ? mAttachState.getSection().getIndex() : -1; 87 } 88 getAttachState()89 ListAttachState getAttachState() { 90 return mAttachState; 91 } 92 getPreviousAttachState()93 ListAttachState getPreviousAttachState() { 94 return mPreviousAttachState; 95 } 96 97 /** 98 * True if this entry has been attached to the shade at least once in its lifetime (it may not 99 * currently be attached). 100 */ hasBeenAttachedBefore()101 public boolean hasBeenAttachedBefore() { 102 return mFirstAddedIteration != -1; 103 } 104 105 /** 106 * Stores the current attach state into {@link #getPreviousAttachState()}} and then starts a 107 * fresh attach state (all entries will be null/default-initialized). 108 */ beginNewAttachState()109 void beginNewAttachState() { 110 mPreviousAttachState.clone(mAttachState); 111 mAttachState.reset(); 112 } 113 114 /** 115 * True if this entry was attached in the last pass, else false. 116 */ wasAttachedInPreviousPass()117 public boolean wasAttachedInPreviousPass() { 118 return getPreviousAttachState().getParent() != null; 119 } 120 } 121