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.services.telephony.rcs;
18 
19 import android.telephony.ims.DelegateRegistrationState;
20 import android.telephony.ims.DelegateRequest;
21 import android.telephony.ims.FeatureTagState;
22 import android.telephony.ims.SipDelegateConfiguration;
23 import android.telephony.ims.SipDelegateConnection;
24 import android.telephony.ims.SipDelegateImsConfiguration;
25 import android.telephony.ims.SipDelegateManager;
26 import android.telephony.ims.aidl.ISipDelegate;
27 import android.telephony.ims.aidl.ISipDelegateMessageCallback;
28 
29 import com.android.internal.annotations.VisibleForTesting;
30 
31 import java.util.List;
32 import java.util.Set;
33 import java.util.concurrent.Executor;
34 import java.util.function.BiConsumer;
35 import java.util.function.Consumer;
36 
37 /**
38  * Defines the interface to be used to manage the state of a SipDelegate on the ImsService side.
39  */
40 public interface DelegateBinderStateManager {
41 
42     /**
43      * Callback interface that allows listeners to listen to changes in registration or
44      * configuration state.
45      */
46     interface StateCallback {
47         /**
48          * The SipDelegate has notified telephony that the registration state has changed.
49          */
onRegistrationStateChanged(DelegateRegistrationState registrationState)50         void onRegistrationStateChanged(DelegateRegistrationState registrationState);
51 
52         /**
53          * The SipDelegate has notified telephony that the IMS configuration has changed.
54          */
onImsConfigurationChanged(SipDelegateImsConfiguration config)55         void onImsConfigurationChanged(SipDelegateImsConfiguration config);
56 
57         /**
58          * The SipDelegate has notified telephony that the IMS configuration has changed.
59          */
onConfigurationChanged(SipDelegateConfiguration config)60         void onConfigurationChanged(SipDelegateConfiguration config);
61     }
62 
63     /** Allow for mocks to be created for testing. */
64     @VisibleForTesting
65     interface Factory {
66         /**
67          * Create a new instance of this interface, which may change depending on the tags being
68          * denied. See {@link SipDelegateBinderConnectionStub} and
69          * {@link SipDelegateBinderConnection}
70          */
create(int subId, DelegateRequest requestedConfig, Set<FeatureTagState> transportDeniedTags, Executor executor, List<StateCallback> stateCallbacks)71         DelegateBinderStateManager create(int subId, DelegateRequest requestedConfig,
72                 Set<FeatureTagState> transportDeniedTags,
73                 Executor executor, List<StateCallback> stateCallbacks);
74     }
75 
76     /**
77      * Start the process to create a SipDelegate on the ImsService.
78      * @param cb The Binder interface that the SipDelegate should use to notify new incoming SIP
79      *         messages as well as acknowledge whether or not an outgoing SIP message was
80      *         successfully sent.
81      * @param createdConsumer The consumer that will be notified when the creation process has
82      *         completed. Contains the ISipDelegate interface to communicate with the SipDelegate
83      *         and the feature tags the SipDelegate itself denied.
84      * @return true if the creation process started, false if the remote process died. If false, the
85      * consumers will not be notified.
86      */
create(ISipDelegateMessageCallback cb, BiConsumer<ISipDelegate, Set<FeatureTagState>> createdConsumer)87     boolean create(ISipDelegateMessageCallback cb,
88             BiConsumer<ISipDelegate, Set<FeatureTagState>> createdConsumer);
89 
90     /**
91      * Destroy the existing SipDelegate managed by this object.
92      * <p>
93      * This instance should be cleaned up after this call.
94      * @param reason The reason for why this delegate is being destroyed.
95      * @param destroyedConsumer The consumer that will be notified when this operation completes.
96      *         Contains the reason the SipDelegate reported it was destroyed.
97      */
destroy(int reason, Consumer<Integer> destroyedConsumer)98     void destroy(int reason, Consumer<Integer> destroyedConsumer);
99 
100     /**
101      * Called by IMS application, see
102      * {@link SipDelegateManager#triggerFullNetworkRegistration(SipDelegateConnection, int, String)}
103      * for more information about when this is called.
104      */
triggerFullNetworkRegistration(int sipCode, String sipReason)105     void triggerFullNetworkRegistration(int sipCode, String sipReason);
106 }
107