• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 import java.util.ArrayList;
20 import java.util.List;
21 import java.util.concurrent.CompletableFuture;
22 import java.util.concurrent.CompletionStage;
23 
24 public class CallFilter {
25     private List<CallFilter> mDependencies;
26     private List<CallFilter> mFollowings;
27     private int mIndegree;
28     public CallFilteringResult mPriorStageResult;
29     public CallFilteringResult result;
30     private CompletableFuture<CallFilteringResult> mResultFuture;
31 
CallFilter()32     public CallFilter() {
33         mDependencies = new ArrayList<>();
34         mFollowings = new ArrayList<>();
35         mPriorStageResult = null;
36     }
37 
startFilterLookup( CallFilteringResult priorStageResult)38     public CompletionStage<CallFilteringResult> startFilterLookup(
39             CallFilteringResult priorStageResult) {
40         return CompletableFuture.completedFuture(priorStageResult);
41     }
42 
getDependencies()43     List<CallFilter> getDependencies() {
44         return mDependencies;
45     }
46 
addDependency(CallFilter filter)47     void addDependency(CallFilter filter) {
48         synchronized (this) {
49             mDependencies.add(filter);
50             mIndegree = mDependencies.size();
51         }
52     }
53 
getFollowings()54     List<CallFilter> getFollowings() {
55         return mFollowings;
56     }
57 
addFollowings(CallFilter filter)58     void addFollowings(CallFilter filter) {
59         mFollowings.add(filter);
60     }
61 
decrementAndGetIndegree()62     int decrementAndGetIndegree() {
63         synchronized (this) {
64             mIndegree--;
65             return mIndegree;
66         }
67     }
68 
getResult()69     public CallFilteringResult getResult() {
70         if (result == null) {
71             throw new NullPointerException("Result of this filter is null. This filter hasn't "
72             + "finished performing");
73         } else {
74             return result;
75         }
76     }
77 }
78