• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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.server.notification;
18 
19 import com.android.internal.logging.InstanceId;
20 import com.android.internal.logging.UiEventLogger;
21 
22 import java.util.ArrayList;
23 import java.util.List;
24 
25 /**
26  * Fake implementation of NotificationRecordLogger, for testing.
27  */
28 class NotificationRecordLoggerFake implements NotificationRecordLogger {
29     static class CallRecord extends NotificationRecordPair {
30         public UiEventLogger.UiEventEnum event;
31 
32         // The following fields are only relevant to maybeLogNotificationPosted() calls.
33         static final int INVALID = -1;
34         public int position = INVALID, buzzBeepBlink = INVALID;
35         public boolean wasLogged;
36         public InstanceId groupInstanceId;
37 
CallRecord(NotificationRecord r, NotificationRecord old, int position, int buzzBeepBlink, InstanceId groupId)38         CallRecord(NotificationRecord r, NotificationRecord old, int position,
39                 int buzzBeepBlink, InstanceId groupId) {
40             super(r, old);
41             this.position = position;
42             this.buzzBeepBlink = buzzBeepBlink;
43             wasLogged = shouldLogReported(buzzBeepBlink);
44             event = wasLogged ? NotificationReportedEvent.fromRecordPair(this) : null;
45             groupInstanceId = groupId;
46         }
47 
CallRecord(NotificationRecord r, UiEventLogger.UiEventEnum event)48         CallRecord(NotificationRecord r, UiEventLogger.UiEventEnum event) {
49             super(r, null);
50             wasLogged = true;
51             this.event = event;
52         }
53     }
54     private List<CallRecord> mCalls = new ArrayList<>();
55 
numCalls()56     public int numCalls() {
57         return mCalls.size();
58     }
59 
getCalls()60     List<CallRecord> getCalls() {
61         return mCalls;
62     }
63 
get(int index)64     CallRecord get(int index) {
65         return mCalls.get(index);
66     }
event(int index)67     UiEventLogger.UiEventEnum event(int index) {
68         return mCalls.get(index).event;
69     }
70 
71     @Override
maybeLogNotificationPosted(NotificationRecord r, NotificationRecord old, int position, int buzzBeepBlink, InstanceId groupId)72     public void maybeLogNotificationPosted(NotificationRecord r, NotificationRecord old,
73             int position, int buzzBeepBlink, InstanceId groupId) {
74         mCalls.add(new CallRecord(r, old, position, buzzBeepBlink, groupId));
75     }
76 
77     @Override
log(UiEventLogger.UiEventEnum event, NotificationRecord r)78     public void log(UiEventLogger.UiEventEnum event, NotificationRecord r) {
79         mCalls.add(new CallRecord(r, event));
80     }
81 
82     @Override
log(UiEventLogger.UiEventEnum event)83     public void log(UiEventLogger.UiEventEnum event) {
84         mCalls.add(new CallRecord(null, event));
85     }
86 }
87