1 /*
2  * Copyright (C) 2021 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.telephony.qns;
18 
19 import android.annotation.IntDef;
20 import android.annotation.NonNull;
21 import android.telephony.AccessNetworkConstants;
22 import android.telephony.AccessNetworkConstants.AccessNetworkType;
23 import android.telephony.Annotation;
24 import android.telephony.TelephonyManager;
25 import android.telephony.ims.ImsMmTelManager;
26 
27 /** This class is a collection of constants */
28 class QnsConstants {
29 
30     static final String QNS_TAG = "QNS";
31 
32     static final int INVALID_VALUE = -1;
33     static final int INVALID_ID = -1;
34     static final int KEY_DEFAULT_VALUE = 0;
35 
36     static final int KEY_DEFAULT_HYST_TIMER = 30000;
37     static final int CONFIG_DEFAULT_MIN_HANDOVER_GUARDING_TIMER = 3000;
38     static final int CONFIG_DEFAULT_MIN_HANDOVER_GUARDING_TIMER_LIMIT = 5000;
39 
40     static final int KEY_DEFAULT_PACKET_LOSS_TIME_MILLIS = 3000;
41     static final int KEY_DEFAULT_IWLAN_AVOID_TIME_LOW_RTP_QUALITY_MILLIS = 60000;
42     static final int KEY_DEFAULT_WWAN_AVOID_TIME_LOW_RTP_QUALITY_MILLIS = 60000;
43 
44     static final int KEY_DEFAULT_THRESHOLD_SSRSRP_GOOD = -110;
45     static final int KEY_DEFAULT_THRESHOLD_SSRSRP_BAD = -115;
46     static final int KEY_DEFAULT_THRESHOLD_RSRP_GOOD = -115;
47     static final int KEY_DEFAULT_THRESHOLD_RSRP_BAD = -120;
48     static final int KEY_DEFAULT_THRESHOLD_RSCP_GOOD = -105;
49     static final int KEY_DEFAULT_THRESHOLD_RSCP_BAD = -115;
50     static final int KEY_DEFAULT_THRESHOLD_GERAN_RSSI_GOOD = -100;
51     static final int KEY_DEFAULT_THRESHOLD_GERAN_RSSI_BAD = -105;
52     static final int KEY_DEFAULT_THRESHOLD_WIFI_RSSI_GOOD = -75;
53     static final int KEY_DEFAULT_THRESHOLD_WIFI_RSSI_BAD = -80;
54 
55     static final int CALL_TYPE_IDLE = 0;
56     static final int CALL_TYPE_VOICE = 1;
57     static final int CALL_TYPE_VIDEO = 2;
58     static final int CALL_TYPE_EMERGENCY = 3;
59 
60     @IntDef(
61             value = {
62                 CALL_TYPE_IDLE,
63                 CALL_TYPE_VOICE,
64                 CALL_TYPE_VIDEO,
65                 CALL_TYPE_EMERGENCY,
66             })
67     @interface QnsCallType {}
68 
69     static final int COVERAGE_HOME = 0;
70     static final int COVERAGE_ROAM = 1;
71     static final int COVERAGE_BOTH = 2;
72 
73     @IntDef(value = {COVERAGE_HOME, COVERAGE_ROAM, COVERAGE_BOTH})
74     @interface CellularCoverage {}
75 
76     // These(RTP_LOW_QUALITY_) constants are used to @code worseThanBefore(),
77     // be caution before change.
78     static final int RTP_LOW_QUALITY_REASON_JITTER = 1;
79     static final int RTP_LOW_QUALITY_REASON_PACKET_LOSS = 2;
80     static final int RTP_LOW_QUALITY_REASON_NO_RTP = 3;
81 
82     @IntDef(
83             value = {
84                 RTP_LOW_QUALITY_REASON_JITTER,
85                 RTP_LOW_QUALITY_REASON_PACKET_LOSS,
86                 RTP_LOW_QUALITY_REASON_NO_RTP,
87             })
88     @interface RtpLowQualityReason {}
89 
90     static final int FALLBACK_REASON_INVALID = -1;
91     static final int FALLBACK_REASON_RTP_ONLY = 0;
92     static final int FALLBACK_REASON_WIFI_ONLY = 1;
93     static final int FALLBACK_REASON_RTP_OR_WIFI = 2;
94 
95     @IntDef(
96             value = {
97                 FALLBACK_REASON_INVALID,
98                 FALLBACK_REASON_RTP_ONLY,
99                 FALLBACK_REASON_WIFI_ONLY,
100                 FALLBACK_REASON_RTP_OR_WIFI,
101             })
102     @interface QnsFallbackReason {}
103 
104     static final int MAX_COUNT_INVALID = -1;
105 
106     static final int MIN_THRESHOLD_GAP = 3;
107 
108     static final int WIFI_ONLY = ImsMmTelManager.WIFI_MODE_WIFI_ONLY;
109     static final int WIFI_PREF = ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED;
110     static final int CELL_PREF = ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED;
111 
112     @IntDef(
113             value = {
114                 WIFI_ONLY, WIFI_PREF, CELL_PREF,
115             })
116     @interface WfcModePreference {}
117 
118     static final int ROVE_OUT = 0;
119     static final int ROVE_IN = 1;
120 
121     @IntDef(
122             value = {
123                 ROVE_OUT, ROVE_IN,
124             })
125     @interface RoveDirection {}
126 
127     static final int POLICY_GOOD = 0;
128     static final int POLICY_BAD = 1;
129     static final int POLICY_TOLERABLE = 2;
130 
131     @IntDef(
132             value = {
133                 POLICY_GOOD,
134                 POLICY_BAD,
135                 POLICY_TOLERABLE,
136             })
137     @interface QnsQualityType {}
138 
139     static final int GUARDING_NONE = 0;
140     static final int GUARDING_CELLULAR = 1;
141     static final int GUARDING_WIFI = 2;
142 
143     @IntDef(
144             value = {
145                 GUARDING_NONE,
146                 GUARDING_WIFI,
147                 GUARDING_CELLULAR,
148             })
149     @interface QnsGuarding {}
150 
151     static final int IMS_REGISTRATION_CHANGED_UNREGISTERED = 0;
152     static final int IMS_REGISTRATION_CHANGED_ACCESS_NETWORK_CHANGE_FAILED = 1;
153     static final int IMS_REGISTRATION_CHANGED_REGISTERED = 2;
154 
155     @IntDef(
156             value = {
157                 IMS_REGISTRATION_CHANGED_UNREGISTERED,
158                 IMS_REGISTRATION_CHANGED_ACCESS_NETWORK_CHANGE_FAILED,
159                 IMS_REGISTRATION_CHANGED_REGISTERED,
160             })
161     @interface QnsImsRegiEvent {}
162 
163     static final int SIP_DIALOG_SESSION_POLICY_NONE = 0;
164     static final int SIP_DIALOG_SESSION_POLICY_FOLLOW_VOICE_CALL = 1;
165     static final int SIP_DIALOG_SESSION_POLICY_FOLLOW_VIDEO_CALL = 2;
166 
167     @IntDef(
168             value = {
169                     SIP_DIALOG_SESSION_POLICY_NONE,
170                     SIP_DIALOG_SESSION_POLICY_FOLLOW_VOICE_CALL,
171                     SIP_DIALOG_SESSION_POLICY_FOLLOW_VIDEO_CALL,
172             })
173     @interface QnsSipDialogSessionPolicy {}
174 
175     static final int THRESHOLD_MATCH_TYPE_EQUAL_TO = 0;
176     static final int THRESHOLD_EQUAL_OR_LARGER = 1;
177     static final int THRESHOLD_EQUAL_OR_SMALLER = 2;
178 
179     static final int SIGNAL_MEASUREMENT_AVAILABILITY = 1 << 7;
180 
181     static final int SIGNAL_UNAVAILABLE = 0;
182     static final int SIGNAL_AVAILABLE = 1;
183 
184     static final int DEFAULT_WIFI_BACKHAUL_TIMER = 3000;
185 
186     static final int TRANSPORT_TYPE_ALLOWED_WWAN = 0;
187     static final int TRANSPORT_TYPE_ALLOWED_IWLAN = 1;
188     static final int TRANSPORT_TYPE_ALLOWED_BOTH = 2;
189 
190     /** Type of Rat Preference. Default value , Follow the system preference. */
191     static final int RAT_PREFERENCE_DEFAULT = 0;
192     /** Type of Rat Preference. choose Wi-Fi always */
193     static final int RAT_PREFERENCE_WIFI_ONLY = 1;
194     /**
195      * Type of Rat Preference. choose Wi-Fi when the Wi-Fi Calling is available.(when IMS is
196      * registered through the Wi-Fi)
197      */
198     static final int RAT_PREFERENCE_WIFI_WHEN_WFC_AVAILABLE = 2;
199     /** Type of Rat Preference. choose Wi-Fi when no cellular */
200     static final int RAT_PREFERENCE_WIFI_WHEN_NO_CELLULAR = 3;
201     /** Type of Rat Preference. choose Wi-Fi when cellular is available at home network. */
202     static final int RAT_PREFERENCE_WIFI_WHEN_HOME_IS_NOT_AVAILABLE = 4;
203 
204     @IntDef(
205             value = {
206                 RAT_PREFERENCE_DEFAULT,
207                 RAT_PREFERENCE_WIFI_ONLY,
208                 RAT_PREFERENCE_WIFI_WHEN_WFC_AVAILABLE,
209                 RAT_PREFERENCE_WIFI_WHEN_NO_CELLULAR,
210                 RAT_PREFERENCE_WIFI_WHEN_HOME_IS_NOT_AVAILABLE,
211             })
212     @interface RatPreference {}
213 
callTypeToString(@nsConstants.QnsCallType int callType)214     static String callTypeToString(@QnsConstants.QnsCallType int callType) {
215         switch (callType) {
216             case CALL_TYPE_IDLE:
217                 return "IDLE";
218             case CALL_TYPE_VOICE:
219                 return "VOICE";
220             case CALL_TYPE_VIDEO:
221                 return "VIDEO";
222             case CALL_TYPE_EMERGENCY:
223                 return "SOS";
224         }
225         return "";
226     }
227 
coverageToString(@nsConstants.CellularCoverage int coverage)228     static String coverageToString(@QnsConstants.CellularCoverage int coverage) {
229         switch (coverage) {
230             case COVERAGE_HOME:
231                 return "HOME";
232             case COVERAGE_ROAM:
233                 return "ROAM";
234         }
235         return "";
236     }
237 
preferenceToString(@nsConstants.WfcModePreference int preference)238     static String preferenceToString(@QnsConstants.WfcModePreference int preference) {
239         switch (preference) {
240             case WIFI_ONLY:
241                 return "WIFI_ONLY";
242             case WIFI_PREF:
243                 return "WIFI_PREF";
244             case CELL_PREF:
245                 return "CELL_PREF";
246         }
247         return "";
248     }
249 
directionToString(@nsConstants.RoveDirection int direction)250     static String directionToString(@QnsConstants.RoveDirection int direction) {
251         if (direction == ROVE_IN) {
252             return "ROVE_IN";
253         }
254         return "ROVE_OUT";
255     }
256 
guardingToString(@nsConstants.QnsGuarding int guarding)257     static String guardingToString(@QnsConstants.QnsGuarding int guarding) {
258         switch (guarding) {
259             case GUARDING_NONE:
260                 return "GUARDING_NONE";
261             case GUARDING_CELLULAR:
262                 return "GUARDING_CELL";
263             case GUARDING_WIFI:
264                 return "GUARDING_WIFI";
265         }
266         return "";
267     }
268 
269     /**
270      * This method coverts call state value from int to string
271      *
272      * @param state int value of call state.
273      * @return returns the string value for the given int call state in parameter.
274      */
callStateToString(@nnotation.CallState int state)275     static String callStateToString(@Annotation.CallState int state) {
276         switch (state) {
277             case TelephonyManager.CALL_STATE_IDLE:
278                 return "CALL_STATE_IDLE";
279             case TelephonyManager.CALL_STATE_RINGING:
280                 return "CALL_STATE_RINGING";
281             case TelephonyManager.CALL_STATE_OFFHOOK:
282                 return "CALL_STATE_OFFHOOK";
283             default:
284                 return "CALL_STATE_UNKNOWN_" + state;
285         }
286     }
287 
imsRegistrationEventToString(@nsConstants.QnsImsRegiEvent int event)288     static String imsRegistrationEventToString(@QnsConstants.QnsImsRegiEvent int event) {
289         switch (event) {
290             case IMS_REGISTRATION_CHANGED_UNREGISTERED:
291                 return "IMS_REGISTRATION_CHANGED_UNREGISTERED";
292             case IMS_REGISTRATION_CHANGED_ACCESS_NETWORK_CHANGE_FAILED:
293                 return "IMS_REGISTRATION_CHANGED_ACCESS_NETWORK_CHANGE_FAILED";
294             case IMS_REGISTRATION_CHANGED_REGISTERED:
295                 return "IMS_REGISTRATION_CHANGED_REGISTERED";
296         }
297         return "";
298     }
299 
300     /**
301      * This method converts AccessNetworkType from int to string.
302      *
303      * @param type int value of AccessNetworkType
304      * @return String value of the access network type.
305      */
accessNetworkTypeToString(int type)306     static String accessNetworkTypeToString(int type) {
307         switch (type) {
308             case AccessNetworkType.UNKNOWN:
309                 return "UNKNOWN";
310             case AccessNetworkType.GERAN:
311                 return "GERAN";
312             case AccessNetworkType.UTRAN:
313                 return "UTRAN";
314             case AccessNetworkType.EUTRAN:
315                 return "EUTRAN";
316             case AccessNetworkType.CDMA2000:
317                 return "CDMA2000";
318             case AccessNetworkType.IWLAN:
319                 return "IWLAN";
320             case AccessNetworkType.NGRAN:
321                 return "NGRAN";
322             default:
323                 return Integer.toString(type);
324         }
325     }
326 
327     /**
328      * This method coverts AccessNetworkType from string to int.
329      *
330      * @param str String value of AccessNetworkType
331      * @return Integer value of AccessNetworkType.
332      */
accessNetworkTypeFromString(@onNull String str)333     static int accessNetworkTypeFromString(@NonNull String str) {
334         switch (str.toUpperCase()) {
335             case "GERAN":
336                 return AccessNetworkType.GERAN;
337             case "UTRAN":
338                 return AccessNetworkType.UTRAN;
339             case "EUTRAN":
340                 return AccessNetworkType.EUTRAN;
341             case "CDMA2000":
342                 return AccessNetworkType.CDMA2000;
343             case "IWLAN":
344                 return AccessNetworkType.IWLAN;
345             case "NGRAN":
346                 return AccessNetworkType.NGRAN;
347             default:
348                 return AccessNetworkType.UNKNOWN;
349         }
350     }
351 
352     /**
353      * This method coverts TransportType from int to string.
354      *
355      * @param transportType Integer value of TransportType
356      * @return String value of TransportType.
357      */
transportTypeToString(int transportType)358     static String transportTypeToString(int transportType) {
359         switch (transportType) {
360             case AccessNetworkConstants.TRANSPORT_TYPE_WWAN:
361                 return "WWAN";
362             case AccessNetworkConstants.TRANSPORT_TYPE_WLAN:
363                 return "WLAN";
364             case AccessNetworkConstants.TRANSPORT_TYPE_INVALID:
365                 return "INVALID";
366             default:
367                 return Integer.toString(transportType);
368         }
369     }
370 
371     /**
372      * Convert data state to string
373      *
374      * @return The data state in string format.
375      */
dataStateToString(@nnotation.DataState int state)376     static String dataStateToString(@Annotation.DataState int state) {
377         switch (state) {
378             case TelephonyManager.DATA_DISCONNECTED:
379                 return "DISCONNECTED";
380             case TelephonyManager.DATA_CONNECTING:
381                 return "CONNECTING";
382             case TelephonyManager.DATA_CONNECTED:
383                 return "CONNECTED";
384             case TelephonyManager.DATA_SUSPENDED:
385                 return "SUSPENDED";
386             case TelephonyManager.DATA_DISCONNECTING:
387                 return "DISCONNECTING";
388             case TelephonyManager.DATA_HANDOVER_IN_PROGRESS:
389                 return "HANDOVERINPROGRESS";
390             case TelephonyManager.DATA_UNKNOWN:
391                 return "UNKNOWN";
392         }
393         // This is the error case. The well-defined value for UNKNOWN is -1.
394         return "UNKNOWN(" + state + ")";
395     }
396 
397     /**
398      * This method converts Network Type to AccessNetworkType.
399      *
400      * @param networkType integer value of network type
401      * @return integer value of AccessNetworkType.
402      */
networkTypeToAccessNetworkType(int networkType)403     static int networkTypeToAccessNetworkType(int networkType) {
404         switch (networkType) {
405             case TelephonyManager.NETWORK_TYPE_GPRS:
406             case TelephonyManager.NETWORK_TYPE_EDGE:
407             case TelephonyManager.NETWORK_TYPE_GSM:
408                 return AccessNetworkType.GERAN;
409             case TelephonyManager.NETWORK_TYPE_UMTS:
410             case TelephonyManager.NETWORK_TYPE_HSDPA:
411             case TelephonyManager.NETWORK_TYPE_HSUPA:
412             case TelephonyManager.NETWORK_TYPE_HSPAP:
413             case TelephonyManager.NETWORK_TYPE_HSPA:
414             case TelephonyManager.NETWORK_TYPE_TD_SCDMA:
415                 return AccessNetworkType.UTRAN;
416             case TelephonyManager.NETWORK_TYPE_1xRTT:
417             case TelephonyManager.NETWORK_TYPE_CDMA:
418             case TelephonyManager.NETWORK_TYPE_EVDO_0:
419             case TelephonyManager.NETWORK_TYPE_EVDO_A:
420             case TelephonyManager.NETWORK_TYPE_EVDO_B:
421             case TelephonyManager.NETWORK_TYPE_EHRPD:
422                 return AccessNetworkType.CDMA2000;
423             case TelephonyManager.NETWORK_TYPE_LTE:
424             case TelephonyManager.NETWORK_TYPE_LTE_CA:
425                 return AccessNetworkType.EUTRAN;
426             case TelephonyManager.NETWORK_TYPE_NR:
427                 return AccessNetworkType.NGRAN;
428             case TelephonyManager.NETWORK_TYPE_IWLAN:
429                 return AccessNetworkType.IWLAN;
430             default:
431                 return AccessNetworkType.UNKNOWN;
432         }
433     }
434 
435     /**
436      * This method converts QnsSipDialogSessionPolicy to string.
437      *
438      * @param policy int value of QnsSipDialogSessionPolicy.
439      * @return String value of QnsSipDialogSessionPolicy.
440      */
qnsSipDialogSessionPolicyToString( @nsConstants.QnsSipDialogSessionPolicy int policy)441     static String qnsSipDialogSessionPolicyToString(
442             @QnsConstants.QnsSipDialogSessionPolicy int policy) {
443         switch (policy) {
444             case SIP_DIALOG_SESSION_POLICY_NONE:
445                 return "POLICY_NONE";
446             case SIP_DIALOG_SESSION_POLICY_FOLLOW_VOICE_CALL:
447                 return "POLICY_VOICE";
448             case SIP_DIALOG_SESSION_POLICY_FOLLOW_VIDEO_CALL:
449                 return "POLICY_VIDEO";
450             default:
451                 return "NONE";
452         }
453     }
454 }
455