• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 package com.android.server.notification;
17 
18 import android.app.Notification;
19 import android.app.NotificationChannel;
20 import android.service.notification.SnoozeCriterion;
21 
22 import java.util.ArrayList;
23 import java.util.Objects;
24 
25 /**
26  * Class that stores any field in a NotificationRecord that can change via an extractor.
27  * Used to cache previous data used in a sort.
28  */
29 public final class NotificationRecordExtractorData {
30     private final int mPosition;
31     private final int mVisibility;
32     private final boolean mShowBadge;
33     private final boolean mAllowBubble;
34     private final boolean mIsBubble;
35     private final NotificationChannel mChannel;
36     private final String mGroupKey;
37     private final ArrayList<String> mOverridePeople;
38     private final ArrayList<SnoozeCriterion> mSnoozeCriteria;
39     private final Integer mUserSentiment;
40     private final Integer mSuppressVisually;
41     private final ArrayList<Notification.Action> mSystemSmartActions;
42     private final ArrayList<CharSequence> mSmartReplies;
43     private final int mImportance;
44 
45     // These fields may not trigger a reranking but diffs here may be logged.
46     private final float mRankingScore;
47     private final boolean mIsConversation;
48     private final int mProposedImportance;
49 
NotificationRecordExtractorData(int position, int visibility, boolean showBadge, boolean allowBubble, boolean isBubble, NotificationChannel channel, String groupKey, ArrayList<String> overridePeople, ArrayList<SnoozeCriterion> snoozeCriteria, Integer userSentiment, Integer suppressVisually, ArrayList<Notification.Action> systemSmartActions, ArrayList<CharSequence> smartReplies, int importance, float rankingScore, boolean isConversation, int proposedImportance)50     NotificationRecordExtractorData(int position, int visibility, boolean showBadge,
51             boolean allowBubble, boolean isBubble, NotificationChannel channel, String groupKey,
52             ArrayList<String> overridePeople, ArrayList<SnoozeCriterion> snoozeCriteria,
53             Integer userSentiment, Integer suppressVisually,
54             ArrayList<Notification.Action> systemSmartActions,
55             ArrayList<CharSequence> smartReplies, int importance, float rankingScore,
56             boolean isConversation, int proposedImportance) {
57         mPosition = position;
58         mVisibility = visibility;
59         mShowBadge = showBadge;
60         mAllowBubble = allowBubble;
61         mIsBubble = isBubble;
62         mChannel = channel;
63         mGroupKey = groupKey;
64         mOverridePeople = overridePeople;
65         mSnoozeCriteria = snoozeCriteria;
66         mUserSentiment = userSentiment;
67         mSuppressVisually = suppressVisually;
68         mSystemSmartActions = systemSmartActions;
69         mSmartReplies = smartReplies;
70         mImportance = importance;
71         mRankingScore = rankingScore;
72         mIsConversation = isConversation;
73         mProposedImportance = proposedImportance;
74     }
75 
76     // Returns whether the provided NotificationRecord differs from the cached data in any way.
77     // Should be guarded by mNotificationLock; not annotated here as this class is static.
hasDiffForRankingLocked(NotificationRecord r, int newPosition)78     boolean hasDiffForRankingLocked(NotificationRecord r, int newPosition) {
79         return mPosition != newPosition
80                 || mVisibility != r.getPackageVisibilityOverride()
81                 || mShowBadge != r.canShowBadge()
82                 || mAllowBubble != r.canBubble()
83                 || mIsBubble != r.getNotification().isBubbleNotification()
84                 || !Objects.equals(mChannel, r.getChannel())
85                 || !Objects.equals(mGroupKey, r.getGroupKey())
86                 || !Objects.equals(mOverridePeople, r.getPeopleOverride())
87                 || !Objects.equals(mSnoozeCriteria, r.getSnoozeCriteria())
88                 || !Objects.equals(mUserSentiment, r.getUserSentiment())
89                 || !Objects.equals(mSuppressVisually, r.getSuppressedVisualEffects())
90                 || !Objects.equals(mSystemSmartActions, r.getSystemGeneratedSmartActions())
91                 || !Objects.equals(mSmartReplies, r.getSmartReplies())
92                 || mImportance != r.getImportance()
93                 || mProposedImportance != r.getProposedImportance();
94     }
95 
96     // Returns whether the NotificationRecord has a change from this data for which we should
97     // log an update. This method specifically targets fields that may be changed via
98     // adjustments from the assistant.
99     //
100     // Fields here are the union of things in NotificationRecordLogger.shouldLogReported
101     // and NotificationRecord.applyAdjustments.
102     //
103     // Should be guarded by mNotificationLock; not annotated here as this class is static.
hasDiffForLoggingLocked(NotificationRecord r, int newPosition)104     boolean hasDiffForLoggingLocked(NotificationRecord r, int newPosition) {
105         return mPosition != newPosition
106                 || !Objects.equals(mChannel, r.getChannel())
107                 || !Objects.equals(mGroupKey, r.getGroupKey())
108                 || !Objects.equals(mOverridePeople, r.getPeopleOverride())
109                 || !Objects.equals(mSnoozeCriteria, r.getSnoozeCriteria())
110                 || !Objects.equals(mUserSentiment, r.getUserSentiment())
111                 || !Objects.equals(mSystemSmartActions, r.getSystemGeneratedSmartActions())
112                 || !Objects.equals(mSmartReplies, r.getSmartReplies())
113                 || mImportance != r.getImportance()
114                 || !r.rankingScoreMatches(mRankingScore)
115                 || mIsConversation != r.isConversation()
116                 || mProposedImportance != r.getProposedImportance();
117     }
118 }
119