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 android.annotation.Nullable; 20 import android.app.NotificationChannel; 21 import android.app.NotificationChannelGroup; 22 23 import com.google.common.base.MoreObjects; 24 25 import java.util.ArrayList; 26 import java.util.List; 27 import java.util.Objects; 28 29 public class NotificationChannelLoggerFake implements NotificationChannelLogger { 30 static class CallRecord { 31 public final NotificationChannelEvent event; 32 @Nullable public final String channelId; 33 CallRecord(NotificationChannelEvent event, @Nullable String channelId)34 CallRecord(NotificationChannelEvent event, @Nullable String channelId) { 35 this.event = event; 36 this.channelId = channelId; 37 } 38 39 @Override toString()40 public String toString() { 41 return MoreObjects.toStringHelper(this) 42 .add("event", event) 43 .add(channelId, channelId) 44 .toString(); 45 } 46 47 @Override equals(Object obj)48 public boolean equals(Object obj) { 49 return (obj instanceof CallRecord other) 50 && Objects.equals(this.event, other.event) 51 && Objects.equals(this.channelId, other.channelId); 52 } 53 54 @Override hashCode()55 public int hashCode() { 56 return Objects.hash(event, channelId); 57 } 58 } 59 60 private List<CallRecord> mCalls = new ArrayList<>(); 61 getCalls()62 List<CallRecord> getCalls() { 63 return mCalls; 64 } 65 get(int index)66 CallRecord get(int index) { 67 return mCalls.get(index); 68 } 69 clear()70 void clear() { 71 mCalls.clear(); 72 } 73 74 @Override logNotificationChannel(NotificationChannelEvent event, NotificationChannel channel, int uid, String pkg, int oldImportance, int newImportance)75 public void logNotificationChannel(NotificationChannelEvent event, NotificationChannel channel, 76 int uid, String pkg, int oldImportance, int newImportance) { 77 mCalls.add(new CallRecord(event, channel.getId())); 78 } 79 80 @Override logNotificationChannelGroup(NotificationChannelEvent event, NotificationChannelGroup channelGroup, int uid, String pkg, boolean wasBlocked)81 public void logNotificationChannelGroup(NotificationChannelEvent event, 82 NotificationChannelGroup channelGroup, int uid, String pkg, boolean wasBlocked) { 83 mCalls.add(new CallRecord(event, channelGroup.getId())); 84 } 85 86 @Override logAppEvent(NotificationChannelEvent event, int uid, String pkg)87 public void logAppEvent(NotificationChannelEvent event, int uid, String pkg) { 88 mCalls.add(new CallRecord(event, null)); 89 } 90 } 91