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 private final ListAttachState mPreviousAttachState = ListAttachState.create(); 35 private final ListAttachState mAttachState = ListAttachState.create(); 36 ListEntry(String key, long creationTime)37 protected ListEntry(String key, long creationTime) { 38 mKey = key; 39 mCreationTime = creationTime; 40 } 41 getKey()42 public String getKey() { 43 return mKey; 44 } 45 46 /** 47 * The SystemClock.uptimeMillis() when this object was created. In general, this means the 48 * moment when NotificationManager notifies our listener about the existence of this entry. 49 * 50 * This value will not change if the notification is updated, although it will change if the 51 * notification is removed and then re-posted. It is also wholly independent from 52 * Notification#when. 53 */ 54 @UptimeMillisLong getCreationTime()55 public long getCreationTime() { 56 return mCreationTime; 57 } 58 59 /** 60 * Should return the "representative entry" for this ListEntry. For NotificationEntries, its 61 * the entry itself. For groups, it should be the summary (but if a summary doesn't exist, 62 * this can return null). This method exists to interface with 63 * legacy code that expects groups to also be NotificationEntries. 64 */ getRepresentativeEntry()65 public abstract @Nullable NotificationEntry getRepresentativeEntry(); 66 getParent()67 @Nullable public GroupEntry getParent() { 68 return mAttachState.getParent(); 69 } 70 setParent(@ullable GroupEntry parent)71 void setParent(@Nullable GroupEntry parent) { 72 mAttachState.setParent(parent); 73 } 74 getPreviousParent()75 @Nullable public GroupEntry getPreviousParent() { 76 return mPreviousAttachState.getParent(); 77 } 78 getSection()79 @Nullable public NotifSection getSection() { 80 return mAttachState.getSection(); 81 } 82 getSectionIndex()83 public int getSectionIndex() { 84 return mAttachState.getSection() != null ? mAttachState.getSection().getIndex() : -1; 85 } 86 getAttachState()87 ListAttachState getAttachState() { 88 return mAttachState; 89 } 90 getPreviousAttachState()91 ListAttachState getPreviousAttachState() { 92 return mPreviousAttachState; 93 } 94 95 /** 96 * Stores the current attach state into {@link #getPreviousAttachState()}} and then starts a 97 * fresh attach state (all entries will be null/default-initialized). 98 */ beginNewAttachState()99 void beginNewAttachState() { 100 mPreviousAttachState.clone(mAttachState); 101 mAttachState.reset(); 102 } 103 104 /** 105 * True if this entry was attached in the last pass, else false. 106 */ wasAttachedInPreviousPass()107 public boolean wasAttachedInPreviousPass() { 108 return getPreviousAttachState().getParent() != null; 109 } 110 } 111