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.ims.rcs.uce.presence.publish;
18 
19 import android.annotation.IntDef;
20 import android.annotation.NonNull;
21 import android.annotation.Nullable;
22 import android.telephony.ims.RcsContactUceCapability;
23 import android.telephony.ims.RcsContactUceCapability.CapabilityMechanism;
24 import android.telephony.ims.RcsUceAdapter.PublishState;
25 import android.telephony.ims.SipDetails;
26 import android.telephony.ims.aidl.IRcsUcePublishStateCallback;
27 
28 import com.android.ims.rcs.uce.ControllerBase;
29 
30 import java.io.PrintWriter;
31 import java.lang.annotation.Retention;
32 import java.lang.annotation.RetentionPolicy;
33 import java.time.Instant;
34 import java.util.Set;
35 
36 /**
37  * The interface related to the PUBLISH request.
38  */
39 public interface PublishController extends ControllerBase {
40 
41     /** Publish is triggered by the ImsService */
42     int PUBLISH_TRIGGER_SERVICE = 1;
43 
44     /** Publish trigger type: retry */
45     int PUBLISH_TRIGGER_RETRY = 2;
46 
47     /** Publish trigger type: TTY preferred changes */
48     int PUBLISH_TRIGGER_TTY_PREFERRED_CHANGE = 3;
49 
50     /** Publish trigger type: Mobile data changes */
51     int PUBLISH_TRIGGER_MOBILE_DATA_CHANGE = 4;
52 
53     /** Publish trigger type: VT setting changes */
54     int PUBLISH_TRIGGER_VT_SETTING_CHANGE = 5;
55 
56     /** Publish trigger type: MMTEL registered */
57     int PUBLISH_TRIGGER_MMTEL_REGISTERED = 6;
58 
59     /** Publish trigger type: MMTEL unregistered */
60     int PUBLISH_TRIGGER_MMTEL_UNREGISTERED = 7;
61 
62     /** Publish trigger type: MMTEL capability changes */
63     int PUBLISH_TRIGGER_MMTEL_CAPABILITY_CHANGE = 8;
64 
65     /** Publish trigger type: MMTEL associated uri changes */
66     int PUBLISH_TRIGGER_MMTEL_URI_CHANGE = 9;
67 
68     /** Publish trigger type: RCS registered */
69     int PUBLISH_TRIGGER_RCS_REGISTERED = 10;
70 
71     /** Publish trigger type: RCS unregistered */
72     int PUBLISH_TRIGGER_RCS_UNREGISTERED = 11;
73 
74     /** Publish trigger type: RCS associated uri changes */
75     int PUBLISH_TRIGGER_RCS_URI_CHANGE = 12;
76 
77     /** Publish trigger type: provisioning changes */
78     int PUBLISH_TRIGGER_PROVISIONING_CHANGE = 13;
79 
80     /**The caps have been overridden for a test*/
81     int PUBLISH_TRIGGER_OVERRIDE_CAPS = 14;
82 
83     /** The Carrier Config for the subscription has Changed **/
84     int PUBLISH_TRIGGER_CARRIER_CONFIG_CHANGED = 15;
85 
86     /** MMTEL and RCS are unregistered. **/
87     int PUBLISH_TRIGGER_MMTEL_RCS_UNREGISTERED = 16;
88 
89     @IntDef(value = {
90             PUBLISH_TRIGGER_SERVICE,
91             PUBLISH_TRIGGER_RETRY,
92             PUBLISH_TRIGGER_TTY_PREFERRED_CHANGE,
93             PUBLISH_TRIGGER_MOBILE_DATA_CHANGE,
94             PUBLISH_TRIGGER_VT_SETTING_CHANGE,
95             PUBLISH_TRIGGER_MMTEL_REGISTERED,
96             PUBLISH_TRIGGER_MMTEL_UNREGISTERED,
97             PUBLISH_TRIGGER_MMTEL_CAPABILITY_CHANGE,
98             PUBLISH_TRIGGER_MMTEL_URI_CHANGE,
99             PUBLISH_TRIGGER_RCS_REGISTERED,
100             PUBLISH_TRIGGER_RCS_UNREGISTERED,
101             PUBLISH_TRIGGER_RCS_URI_CHANGE,
102             PUBLISH_TRIGGER_PROVISIONING_CHANGE,
103             PUBLISH_TRIGGER_OVERRIDE_CAPS,
104             PUBLISH_TRIGGER_CARRIER_CONFIG_CHANGED,
105             PUBLISH_TRIGGER_MMTEL_RCS_UNREGISTERED
106     }, prefix="PUBLISH_TRIGGER_")
107     @Retention(RetentionPolicy.SOURCE)
108     @interface PublishTriggerType {}
109 
110     /**
111      * Receive the callback from the sub-components which interact with PublishController.
112      */
113     interface PublishControllerCallback {
114         /**
115          * Request publish from local.
116          */
requestPublishFromInternal(@ublishTriggerType int type)117         void requestPublishFromInternal(@PublishTriggerType int type);
118 
119         /**
120          * Receive the command error callback of the request from ImsService.
121          */
onRequestCommandError(PublishRequestResponse requestResponse)122         void onRequestCommandError(PublishRequestResponse requestResponse);
123 
124         /**
125          * Receive the network response callback fo the request from ImsService.
126          */
onRequestNetworkResp(PublishRequestResponse requestResponse)127         void onRequestNetworkResp(PublishRequestResponse requestResponse);
128 
129         /**
130          * Set the timer to cancel the request. This timer is to prevent taking too long for
131          * waiting the response callback.
132          */
setupRequestCanceledTimer(long taskId, long delay)133         void setupRequestCanceledTimer(long taskId, long delay);
134 
135         /**
136          * Clear the request canceled timer. This api will be called if the request is finished.
137          */
clearRequestCanceledTimer()138         void clearRequestCanceledTimer();
139 
140         /**
141          * Update the publish request result.
142          */
updatePublishRequestResult(int publishState, Instant updatedTimestamp, String pidfXml, SipDetails details)143         void updatePublishRequestResult(int publishState, Instant updatedTimestamp, String pidfXml,
144                 SipDetails details);
145 
146         /**
147          * Update the value of the publish throttle.
148          */
updatePublishThrottle(int value)149         void updatePublishThrottle(int value);
150 
151         /**
152          * Update the device state with the publish request result.
153          */
refreshDeviceState(int SipCode, String reason)154         void refreshDeviceState(int SipCode, String reason);
155 
156         /**
157          * Sent the publish request to ImsService.
158          */
notifyPendingPublishRequest()159         void notifyPendingPublishRequest();
160 
161         /**
162          * Update the Ims unregistered. This api will be called if the IMS unregistered.
163          */
updateImsUnregistered()164         void updateImsUnregistered();
165     }
166 
167     /**
168      * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
169      * <p>
170      * Used for testing ONLY.
171      * @return the new capabilities that will be used for PUBLISH.
172      */
addRegistrationOverrideCapabilities(Set<String> featureTags)173     RcsContactUceCapability addRegistrationOverrideCapabilities(Set<String> featureTags);
174 
175     /**
176      * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
177      * <p>
178      * Used for testing ONLY.
179      * @return the new capabilities that will be used for PUBLISH.
180      */
removeRegistrationOverrideCapabilities(Set<String> featureTags)181     RcsContactUceCapability removeRegistrationOverrideCapabilities(Set<String> featureTags);
182 
183     /**
184      * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
185      * <p>
186      * Used for testing ONLY.
187      * @return the new capabilities that will be used for PUBLISH.
188      */
clearRegistrationOverrideCapabilities()189     RcsContactUceCapability clearRegistrationOverrideCapabilities();
190 
191     /**
192      * @return latest RcsContactUceCapability instance that will be used for PUBLISH.
193      */
getLatestRcsContactUceCapability()194     RcsContactUceCapability getLatestRcsContactUceCapability();
195 
196     /**
197      * Retrieve the RCS UCE Publish state.
198      */
getUcePublishState(boolean isSupportPublishingState)199     @PublishState int getUcePublishState(boolean isSupportPublishingState);
200 
201     /**
202      * @return the last PIDF XML used for publish or {@code null} if the device is not published.
203      */
getLastPidfXml()204     String getLastPidfXml();
205 
206     /**
207      * Notify that the device's capabilities have been unpublished from the network.
208      */
onUnpublish()209     void onUnpublish();
210 
211     /**
212      * Notify that the device's publish status have been changed.
213      */
onPublishUpdated(@onNull SipDetails details)214     void onPublishUpdated(@NonNull SipDetails details);
215     /**
216      * Retrieve the device's capabilities.
217      */
getDeviceCapabilities(@apabilityMechanism int mechanism)218     RcsContactUceCapability getDeviceCapabilities(@CapabilityMechanism int mechanism);
219 
220     /**
221      * Publish the device's capabilities to the Presence server.
222      */
requestPublishCapabilitiesFromService(int triggerType)223     void requestPublishCapabilitiesFromService(int triggerType);
224 
225     /**
226      * Register a {@link PublishStateCallback} to listen to the published state changed.
227      */
registerPublishStateCallback(@onNull IRcsUcePublishStateCallback c, boolean supportPublishingState)228     void registerPublishStateCallback(@NonNull IRcsUcePublishStateCallback c,
229             boolean supportPublishingState);
230 
231     /**
232      * Removes an existing {@link PublishStateCallback}.
233      */
unregisterPublishStateCallback(@onNull IRcsUcePublishStateCallback c)234     void unregisterPublishStateCallback(@NonNull IRcsUcePublishStateCallback c);
235 
236     /**
237      * Setup the timer to reset the device state.
238      */
setupResetDeviceStateTimer(long resetAfterSec)239     void setupResetDeviceStateTimer(long resetAfterSec);
240 
241     /**
242      * Clear the reset device state timer.
243      */
clearResetDeviceStateTimer()244     void clearResetDeviceStateTimer();
245 
246     /**
247      * Dump the state of this PublishController to the printWriter.
248      */
dump(PrintWriter printWriter)249     void dump(PrintWriter printWriter);
250 }
251