1 /*
2  * Copyright (C) 2024 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;
18 
19 import android.telecom.CallEndpoint;
20 
21 import java.util.Objects;
22 import java.util.Set;
23 
24 public class CachedAvailableEndpointsChange implements CachedCallback {
25     public static final String ID = CachedAvailableEndpointsChange.class.getSimpleName();
26     Set<CallEndpoint> mAvailableEndpoints;
27 
getAvailableEndpoints()28     public Set<CallEndpoint> getAvailableEndpoints() {
29         return mAvailableEndpoints;
30     }
31 
CachedAvailableEndpointsChange(Set<CallEndpoint> endpoints)32     public CachedAvailableEndpointsChange(Set<CallEndpoint> endpoints) {
33         mAvailableEndpoints = endpoints;
34     }
35 
36     @Override
executeCallback(CallSourceService service, Call call)37     public void executeCallback(CallSourceService service, Call call) {
38         service.onAvailableCallEndpointsChanged(call, mAvailableEndpoints);
39     }
40 
41     @Override
getCallbackId()42     public String getCallbackId() {
43         return ID;
44     }
45 
46     @Override
hashCode()47     public int hashCode() {
48         return Objects.hashCode(mAvailableEndpoints);
49     }
50 
51     @Override
equals(Object obj)52     public boolean equals(Object obj) {
53         if (obj == null) {
54             return false;
55         }
56         if (!(obj instanceof CachedAvailableEndpointsChange other)) {
57             return false;
58         }
59         if (mAvailableEndpoints.size() != other.mAvailableEndpoints.size()) {
60             return false;
61         }
62         for (CallEndpoint e : mAvailableEndpoints) {
63             if (!other.getAvailableEndpoints().contains(e)) {
64                 return false;
65             }
66         }
67         return true;
68     }
69 }
70 
71