1 /* 2 * Copyright (C) 2016 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.telecom.callfiltering; 18 19 public class CallFilteringResult { 20 public boolean shouldAllowCall; 21 public boolean shouldReject; 22 public boolean shouldAddToCallLog; 23 public boolean shouldShowNotification; 24 25 public CallFilteringResult(boolean shouldAllowCall, boolean shouldReject, boolean 26 shouldAddToCallLog, boolean shouldShowNotification) { 27 this.shouldAllowCall = shouldAllowCall; 28 this.shouldReject = shouldReject; 29 this.shouldAddToCallLog = shouldAddToCallLog; 30 this.shouldShowNotification = shouldShowNotification; 31 } 32 33 /** 34 * Combine this CallFilteringResult with another, returning a CallFilteringResult with 35 * the more restrictive properties of the two. 36 */ 37 public CallFilteringResult combine(CallFilteringResult other) { 38 if (other == null) { 39 return this; 40 } 41 42 return new CallFilteringResult( 43 shouldAllowCall && other.shouldAllowCall, 44 shouldReject || other.shouldReject, 45 shouldAddToCallLog && other.shouldAddToCallLog, 46 shouldShowNotification && other.shouldShowNotification); 47 } 48 49 @Override 50 public boolean equals(Object o) { 51 if (this == o) return true; 52 if (o == null || getClass() != o.getClass()) return false; 53 54 CallFilteringResult that = (CallFilteringResult) o; 55 56 if (shouldAllowCall != that.shouldAllowCall) return false; 57 if (shouldReject != that.shouldReject) return false; 58 if (shouldAddToCallLog != that.shouldAddToCallLog) return false; 59 return shouldShowNotification == that.shouldShowNotification; 60 } 61 62 @Override 63 public int hashCode() { 64 int result = (shouldAllowCall ? 1 : 0); 65 result = 31 * result + (shouldReject ? 1 : 0); 66 result = 31 * result + (shouldAddToCallLog ? 1 : 0); 67 result = 31 * result + (shouldShowNotification ? 1 : 0); 68 return result; 69 } 70 71 @Override 72 public String toString() { 73 StringBuilder sb = new StringBuilder(); 74 sb.append("["); 75 if (shouldAllowCall) { 76 sb.append("Allow"); 77 } else if (shouldReject) { 78 sb.append("Reject"); 79 } else { 80 sb.append("Ignore"); 81 } 82 83 if (shouldAddToCallLog) { 84 sb.append(", logged"); 85 } 86 87 if (shouldShowNotification) { 88 sb.append(", notified"); 89 } 90 sb.append("]"); 91 92 return sb.toString(); 93 } 94 } 95