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 private final boolean mSensitiveContent; 50 private final String mSummarization; 51 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, boolean sensitiveContent, String summarization)52 NotificationRecordExtractorData(int position, int visibility, boolean showBadge, 53 boolean allowBubble, boolean isBubble, NotificationChannel channel, String groupKey, 54 ArrayList<String> overridePeople, ArrayList<SnoozeCriterion> snoozeCriteria, 55 Integer userSentiment, Integer suppressVisually, 56 ArrayList<Notification.Action> systemSmartActions, 57 ArrayList<CharSequence> smartReplies, int importance, float rankingScore, 58 boolean isConversation, int proposedImportance, boolean sensitiveContent, 59 String summarization) { 60 mPosition = position; 61 mVisibility = visibility; 62 mShowBadge = showBadge; 63 mAllowBubble = allowBubble; 64 mIsBubble = isBubble; 65 mChannel = channel; 66 mGroupKey = groupKey; 67 mOverridePeople = overridePeople; 68 mSnoozeCriteria = snoozeCriteria; 69 mUserSentiment = userSentiment; 70 mSuppressVisually = suppressVisually; 71 mSystemSmartActions = systemSmartActions; 72 mSmartReplies = smartReplies; 73 mImportance = importance; 74 mRankingScore = rankingScore; 75 mIsConversation = isConversation; 76 mProposedImportance = proposedImportance; 77 mSensitiveContent = sensitiveContent; 78 mSummarization = summarization; 79 } 80 81 // Returns whether the provided NotificationRecord differs from the cached data in any way. 82 // Should be guarded by mNotificationLock; not annotated here as this class is static. hasDiffForRankingLocked(NotificationRecord r, int newPosition)83 boolean hasDiffForRankingLocked(NotificationRecord r, int newPosition) { 84 return mPosition != newPosition 85 || mVisibility != r.getPackageVisibilityOverride() 86 || mShowBadge != r.canShowBadge() 87 || mAllowBubble != r.canBubble() 88 || mIsBubble != r.getNotification().isBubbleNotification() 89 || !Objects.equals(mChannel, r.getChannel()) 90 || !Objects.equals(mGroupKey, r.getGroupKey()) 91 || !Objects.equals(mOverridePeople, r.getPeopleOverride()) 92 || !Objects.equals(mSnoozeCriteria, r.getSnoozeCriteria()) 93 || !Objects.equals(mUserSentiment, r.getUserSentiment()) 94 || !Objects.equals(mSuppressVisually, r.getSuppressedVisualEffects()) 95 || !Objects.equals(mSystemSmartActions, r.getSystemGeneratedSmartActions()) 96 || !Objects.equals(mSmartReplies, r.getSmartReplies()) 97 || mImportance != r.getImportance() 98 || mProposedImportance != r.getProposedImportance() 99 || mSensitiveContent != r.hasSensitiveContent() 100 || !Objects.equals(mSummarization, r.getSummarization()); 101 } 102 103 // Returns whether the NotificationRecord has a change from this data for which we should 104 // log an update. This method specifically targets fields that may be changed via 105 // adjustments from the assistant. 106 // 107 // Fields here are the union of things in NotificationRecordLogger.shouldLogReported 108 // and NotificationRecord.applyAdjustments. 109 // 110 // Should be guarded by mNotificationLock; not annotated here as this class is static. hasDiffForLoggingLocked(NotificationRecord r, int newPosition)111 boolean hasDiffForLoggingLocked(NotificationRecord r, int newPosition) { 112 return mPosition != newPosition 113 || !Objects.equals(mChannel, r.getChannel()) 114 || !Objects.equals(mGroupKey, r.getGroupKey()) 115 || !Objects.equals(mOverridePeople, r.getPeopleOverride()) 116 || !Objects.equals(mSnoozeCriteria, r.getSnoozeCriteria()) 117 || !Objects.equals(mUserSentiment, r.getUserSentiment()) 118 || !Objects.equals(mSystemSmartActions, r.getSystemGeneratedSmartActions()) 119 || !Objects.equals(mSmartReplies, r.getSmartReplies()) 120 || mImportance != r.getImportance() 121 || !r.rankingScoreMatches(mRankingScore) 122 || mIsConversation != r.isConversation() 123 || mProposedImportance != r.getProposedImportance() 124 || mSensitiveContent != r.hasSensitiveContent() 125 || !Objects.equals(mSummarization, r.getSummarization()); 126 } 127 } 128