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; 18 19 import android.annotation.NonNull; 20 21 import com.android.systemui.statusbar.NotificationData; 22 23 /** 24 * Interface for anything that may need to keep notifications managed even after 25 * {@link NotificationListener} removes it. The lifetime extender is in charge of performing the 26 * callback when the notification is then safe to remove. 27 */ 28 public interface NotificationLifetimeExtender { 29 30 /** 31 * Set the handler to callback to when the notification is safe to remove. 32 * 33 * @param callback the handler to callback 34 */ setCallback(@onNull NotificationSafeToRemoveCallback callback)35 void setCallback(@NonNull NotificationSafeToRemoveCallback callback); 36 37 /** 38 * Determines whether or not the extender needs the notification kept after removal. 39 * 40 * @param entry the entry containing the notification to check 41 * @return true if the notification lifetime should be extended 42 */ shouldExtendLifetime(@onNull NotificationData.Entry entry)43 boolean shouldExtendLifetime(@NonNull NotificationData.Entry entry); 44 45 /** 46 * It's possible that a notification was canceled before it ever became visible. This callback 47 * gives lifetime extenders a chance to make sure it shows up. For example if a foreground 48 * service is canceled too quickly but we still want to make sure a FGS notification shows. 49 * @param pendingEntry the canceled (but pending) entry 50 * @return true if the notification lifetime should be extended 51 */ shouldExtendLifetimeForPendingNotification( @onNull NotificationData.Entry pendingEntry)52 default boolean shouldExtendLifetimeForPendingNotification( 53 @NonNull NotificationData.Entry pendingEntry) { 54 return false; 55 } 56 57 /** 58 * Sets whether or not the lifetime should be managed by the extender. In practice, if 59 * shouldManage is true, this is where the extender starts managing the entry internally and is 60 * now responsible for calling {@link NotificationSafeToRemoveCallback#onSafeToRemove(String)} 61 * when the entry is safe to remove. If shouldManage is false, the extender no longer needs to 62 * worry about it (either because we will be removing it anyway or the entry is no longer 63 * removed due to an update). 64 * 65 * @param entry the entry that needs an extended lifetime 66 * @param shouldManage true if the extender should manage the entry now, false otherwise 67 */ setShouldManageLifetime(@onNull NotificationData.Entry entry, boolean shouldManage)68 void setShouldManageLifetime(@NonNull NotificationData.Entry entry, boolean shouldManage); 69 70 /** 71 * The callback for when the notification is now safe to remove (i.e. its lifetime has ended). 72 */ 73 interface NotificationSafeToRemoveCallback { 74 /** 75 * Called when the lifetime extender determines it's safe to remove. 76 * 77 * @param key key of the entry that is now safe to remove 78 */ onSafeToRemove(String key)79 void onSafeToRemove(String key); 80 } 81 } 82