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