• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.car.notification;
18 
19 import android.app.Notification;
20 import android.service.notification.StatusBarNotification;
21 
22 import androidx.annotation.VisibleForTesting;
23 
24 /**
25  * Wrapper class to store the state of a {@link StatusBarNotification}.
26  */
27 public class AlertEntry {
28 
29     private String mKey;
30     private long mPostTime;
31     private StatusBarNotification mStatusBarNotification;
32     private NotificationClickHandlerFactory mClickHandlerFactory;
33 
AlertEntry(StatusBarNotification statusBarNotification)34     public AlertEntry(StatusBarNotification statusBarNotification) {
35         mStatusBarNotification = statusBarNotification;
36         mKey = statusBarNotification.getKey();
37         mPostTime = calculatePostTime();
38     }
39 
40     // Empty constructor for Spy compatibility.
41     @VisibleForTesting
AlertEntry()42     protected AlertEntry() {}
43 
44     /**
45      * Updates the current post time for the Heads up notification.
46      */
updatePostTime()47     void updatePostTime() {
48         mPostTime = calculatePostTime();
49     }
50 
getPostTime()51     long getPostTime() {
52         return mPostTime;
53     }
54 
55     /**
56      * Calculate what the post time of a notification is at some current time.
57      *
58      * @return the post time
59      */
calculatePostTime()60     private long calculatePostTime() {
61         return System.currentTimeMillis();
62     }
63 
64     /**
65      * Returns the {@link StatusBarNotification} that this instance of AlertEntry is wrapping.
66      */
getStatusBarNotification()67     public StatusBarNotification getStatusBarNotification() {
68         return mStatusBarNotification;
69     }
70 
getClickHandlerFactory()71     NotificationClickHandlerFactory getClickHandlerFactory() {
72         return mClickHandlerFactory;
73     }
74 
setClickHandlerFactory(NotificationClickHandlerFactory clickHandlerFactory)75     void setClickHandlerFactory(NotificationClickHandlerFactory clickHandlerFactory) {
76         mClickHandlerFactory = clickHandlerFactory;
77     }
78 
79     /**
80      * Returns the key associated with the {@link StatusBarNotification} stored in this AlertEntry
81      * instance. This ensures that the same unique key is associated with a StatusBarNotification
82      * and the {@link AlertEntry} that wraps it.
83      */
getKey()84     public String getKey() {
85         return mKey;
86     }
87 
88     /**
89      * Returns the {@link Notification} that is associated with the {@link StatusBarNotification}
90      * that this AlertEntry instance wraps.
91      */
getNotification()92     public Notification getNotification() {
93         return mStatusBarNotification.getNotification();
94     }
95 }
96