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, int position, int buzzBeepBlink, InstanceId groupId)48 CallRecord(NotificationRecord r, int position, int buzzBeepBlink, InstanceId groupId) { 49 super(r, null); 50 this.position = position; 51 this.buzzBeepBlink = buzzBeepBlink; 52 wasLogged = true; 53 event = NotificationReportedEvent.NOTIFICATION_ADJUSTED; 54 groupInstanceId = groupId; 55 } 56 CallRecord(NotificationRecord r, UiEventLogger.UiEventEnum event)57 CallRecord(NotificationRecord r, UiEventLogger.UiEventEnum event) { 58 super(r, null); 59 wasLogged = true; 60 this.event = event; 61 } 62 } 63 private List<CallRecord> mCalls = new ArrayList<>(); 64 numCalls()65 public int numCalls() { 66 return mCalls.size(); 67 } 68 getCalls()69 List<CallRecord> getCalls() { 70 return mCalls; 71 } 72 get(int index)73 CallRecord get(int index) { 74 return mCalls.get(index); 75 } event(int index)76 UiEventLogger.UiEventEnum event(int index) { 77 return mCalls.get(index).event; 78 } 79 80 @Override maybeLogNotificationPosted(NotificationRecord r, NotificationRecord old, int position, int buzzBeepBlink, InstanceId groupId)81 public void maybeLogNotificationPosted(NotificationRecord r, NotificationRecord old, 82 int position, int buzzBeepBlink, InstanceId groupId) { 83 mCalls.add(new CallRecord(r, old, position, buzzBeepBlink, groupId)); 84 } 85 86 @Override logNotificationAdjusted(NotificationRecord r, int position, int buzzBeepBlink, InstanceId groupId)87 public void logNotificationAdjusted(NotificationRecord r, int position, int buzzBeepBlink, 88 InstanceId groupId) { 89 mCalls.add(new CallRecord(r, position, buzzBeepBlink, groupId)); 90 } 91 92 @Override log(UiEventLogger.UiEventEnum event, NotificationRecord r)93 public void log(UiEventLogger.UiEventEnum event, NotificationRecord r) { 94 mCalls.add(new CallRecord(r, event)); 95 } 96 97 @Override log(UiEventLogger.UiEventEnum event)98 public void log(UiEventLogger.UiEventEnum event) { 99 mCalls.add(new CallRecord(null, event)); 100 } 101 } 102