summaryrefslogtreecommitdiff
path: root/services/QualifiedNetworksService/src/com/android/telephony/qns/QnsConstants.java
blob: ba2c2f1950b69e45800aa728ba7450d15d400a00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.telephony.qns;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.telephony.AccessNetworkConstants;
import android.telephony.AccessNetworkConstants.AccessNetworkType;
import android.telephony.Annotation;
import android.telephony.TelephonyManager;
import android.telephony.ims.ImsMmTelManager;

/** This class is a collection of constants */
class QnsConstants {

    static final String QNS_TAG = "QNS";

    static final int INVALID_VALUE = -1;
    static final int INVALID_ID = -1;
    static final int INVALID_SUB_ID = -1;
    static final int KEY_DEFAULT_VALUE = 0;

    static final int KEY_DEFAULT_HYST_TIMER = 30000;
    static final int CONFIG_DEFAULT_MIN_HANDOVER_GUARDING_TIMER = 0;
    static final int CONFIG_DEFAULT_MIN_HANDOVER_GUARDING_TIMER_LIMIT = 5000;

    static final int KEY_DEFAULT_PACKET_LOSS_TIME_MILLIS = 5000;
    static final int KEY_DEFAULT_IWLAN_AVOID_TIME_LOW_RTP_QUALITY_MILLIS = 60000;

    static final int KEY_DEFAULT_THRESHOLD_SSRSRP_GOOD = -99;
    static final int KEY_DEFAULT_THRESHOLD_SSRSRP_BAD = -111;
    static final int KEY_DEFAULT_THRESHOLD_RSRP_GOOD = -99;
    static final int KEY_DEFAULT_THRESHOLD_RSRP_BAD = -111;
    static final int KEY_DEFAULT_THRESHOLD_RSCP_GOOD = -90;
    static final int KEY_DEFAULT_THRESHOLD_RSCP_BAD = -100;
    static final int KEY_DEFAULT_THRESHOLD_GERAN_RSSI_GOOD = -90;
    static final int KEY_DEFAULT_THRESHOLD_GERAN_RSSI_BAD = -100;
    static final int KEY_DEFAULT_THRESHOLD_WIFI_RSSI_GOOD = -70;
    static final int KEY_DEFAULT_THRESHOLD_WIFI_RSSI_BAD = -80;
    static final int KEY_DEFAULT_THRESHOLD_VIDEO_WIFI_RSSI_GOOD = -65;
    static final int KEY_DEFAULT_THRESHOLD_VIDEO_WIFI_RSSI_BAD = -75;

    static final int CALL_TYPE_IDLE = 0;
    static final int CALL_TYPE_VOICE = 1;
    static final int CALL_TYPE_VIDEO = 2;
    static final int CALL_TYPE_EMERGENCY = 3;

    @IntDef(
            value = {
                CALL_TYPE_IDLE,
                CALL_TYPE_VOICE,
                CALL_TYPE_VIDEO,
                CALL_TYPE_EMERGENCY,
            })
    @interface QnsCallType {}

    static final int COVERAGE_HOME = 0;
    static final int COVERAGE_ROAM = 1;
    static final int COVERAGE_BOTH = 2;

    @IntDef(value = {COVERAGE_HOME, COVERAGE_ROAM, COVERAGE_BOTH})
    @interface CellularCoverage {}

    // These(RTP_LOW_QUALITY_) constants are used to @code worseThanBefore(),
    // be caution before change.
    static final int RTP_LOW_QUALITY_REASON_JITTER = 1;
    static final int RTP_LOW_QUALITY_REASON_PACKET_LOSS = 2;
    static final int RTP_LOW_QUALITY_REASON_NO_RTP = 3;

    @IntDef(
            value = {
                RTP_LOW_QUALITY_REASON_JITTER,
                RTP_LOW_QUALITY_REASON_PACKET_LOSS,
                RTP_LOW_QUALITY_REASON_NO_RTP,
            })
    @interface RtpLowQualityReason {}

    static final int FALLBACK_REASON_INVALID = -1;
    static final int FALLBACK_REASON_RTP_ONLY = 0;
    static final int FALLBACK_REASON_WIFI_ONLY = 1;
    static final int FALLBACK_REASON_RTP_OR_WIFI = 2;

    @IntDef(
            value = {
                FALLBACK_REASON_INVALID,
                FALLBACK_REASON_RTP_ONLY,
                FALLBACK_REASON_WIFI_ONLY,
                FALLBACK_REASON_RTP_OR_WIFI,
            })
    @interface QnsFallbackReason {}

    static final int MAX_COUNT_INVALID = -1;

    static final int MIN_THRESHOLD_GAP = 3;

    static final int WIFI_ONLY = ImsMmTelManager.WIFI_MODE_WIFI_ONLY;
    static final int WIFI_PREF = ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED;
    static final int CELL_PREF = ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED;

    @IntDef(
            value = {
                WIFI_ONLY, WIFI_PREF, CELL_PREF,
            })
    @interface WfcModePreference {}

    static final int ROVE_OUT = 0;
    static final int ROVE_IN = 1;

    @IntDef(
            value = {
                ROVE_OUT, ROVE_IN,
            })
    @interface RoveDirection {}

    static final int POLICY_GOOD = 0;
    static final int POLICY_BAD = 1;
    static final int POLICY_TOLERABLE = 2;

    @IntDef(
            value = {
                POLICY_GOOD,
                POLICY_BAD,
                POLICY_TOLERABLE,
            })
    @interface QnsQualityType {}

    static final int GUARDING_NONE = 0;
    static final int GUARDING_CELLULAR = 1;
    static final int GUARDING_WIFI = 2;

    @IntDef(
            value = {
                GUARDING_NONE,
                GUARDING_WIFI,
                GUARDING_CELLULAR,
            })
    @interface QnsGuarding {}

    static final int IMS_REGISTRATION_CHANGED_UNREGISTERED = 0;
    static final int IMS_REGISTRATION_CHANGED_ACCESS_NETWORK_CHANGE_FAILED = 1;
    static final int IMS_REGISTRATION_CHANGED_REGISTERED = 2;

    @IntDef(
            value = {
                IMS_REGISTRATION_CHANGED_UNREGISTERED,
                IMS_REGISTRATION_CHANGED_ACCESS_NETWORK_CHANGE_FAILED,
                IMS_REGISTRATION_CHANGED_REGISTERED,
            })
    @interface QnsImsRegiEvent {}

    static final int THRESHOLD_MATCH_TYPE_EQUAL_TO = 0;
    static final int THRESHOLD_EQUAL_OR_LARGER = 1;
    static final int THRESHOLD_EQUAL_OR_SMALLER = 2;

    static final int SIGNAL_MEASUREMENT_AVAILABILITY = 1 << 7;

    static final int SIGNAL_UNAVAILABLE = 0;
    static final int SIGNAL_AVAILABLE = 1;

    static final int DEFAULT_WIFI_BACKHAUL_TIMER = 3000;
    static final int DEFAULT_MSG_DELAY_TIMER = 1000;

    static final int TRANSPORT_TYPE_ALLOWED_WWAN = 0;
    static final int TRANSPORT_TYPE_ALLOWED_IWLAN = 1;
    static final int TRANSPORT_TYPE_ALLOWED_BOTH = 2;

    /** Type of Rat Preference. Default value , Follow the system preference. */
    static final int RAT_PREFERENCE_DEFAULT = 0;
    /** Type of Rat Preference. choose Wi-Fi always */
    static final int RAT_PREFERENCE_WIFI_ONLY = 1;
    /**
     * Type of Rat Preference. choose Wi-Fi when the Wi-Fi Calling is available.(when IMS is
     * registered through the Wi-Fi)
     */
    static final int RAT_PREFERENCE_WIFI_WHEN_WFC_AVAILABLE = 2;
    /** Type of Rat Preference. choose Wi-Fi when no cellular */
    static final int RAT_PREFERENCE_WIFI_WHEN_NO_CELLULAR = 3;
    /** Type of Rat Preference. choose Wi-Fi when cellular is available at home network. */
    static final int RAT_PREFERENCE_WIFI_WHEN_HOME_IS_NOT_AVAILABLE = 4;

    @IntDef(
            value = {
                RAT_PREFERENCE_DEFAULT,
                RAT_PREFERENCE_WIFI_ONLY,
                RAT_PREFERENCE_WIFI_WHEN_WFC_AVAILABLE,
                RAT_PREFERENCE_WIFI_WHEN_NO_CELLULAR,
                RAT_PREFERENCE_WIFI_WHEN_HOME_IS_NOT_AVAILABLE,
            })
    @interface RatPreference {}

    static String callTypeToString(@QnsConstants.QnsCallType int callType) {
        switch (callType) {
            case CALL_TYPE_IDLE:
                return "IDLE";
            case CALL_TYPE_VOICE:
                return "VOICE";
            case CALL_TYPE_VIDEO:
                return "VIDEO";
            case CALL_TYPE_EMERGENCY:
                return "SOS";
        }
        return "";
    }

    static String coverageToString(@QnsConstants.CellularCoverage int coverage) {
        switch (coverage) {
            case COVERAGE_HOME:
                return "HOME";
            case COVERAGE_ROAM:
                return "ROAM";
        }
        return "";
    }

    static String preferenceToString(@QnsConstants.WfcModePreference int preference) {
        switch (preference) {
            case WIFI_ONLY:
                return "WIFI_ONLY";
            case WIFI_PREF:
                return "WIFI_PREF";
            case CELL_PREF:
                return "CELL_PREF";
        }
        return "";
    }

    static String directionToString(@QnsConstants.RoveDirection int direction) {
        if (direction == ROVE_IN) {
            return "ROVE_IN";
        }
        return "ROVE_OUT";
    }

    static String guardingToString(@QnsConstants.QnsGuarding int guarding) {
        switch (guarding) {
            case GUARDING_NONE:
                return "GUARDING_NONE";
            case GUARDING_CELLULAR:
                return "GUARDING_CELL";
            case GUARDING_WIFI:
                return "GUARDING_WIFI";
        }
        return "";
    }

    /**
     * This method coverts call state value from int to string
     *
     * @param state int value of call state.
     * @return returns the string value for the given int call state in parameter.
     */
    static String callStateToString(@Annotation.CallState int state) {
        switch (state) {
            case TelephonyManager.CALL_STATE_IDLE:
                return "CALL_STATE_IDLE";
            case TelephonyManager.CALL_STATE_RINGING:
                return "CALL_STATE_RINGING";
            case TelephonyManager.CALL_STATE_OFFHOOK:
                return "CALL_STATE_OFFHOOK";
            default:
                return "CALL_STATE_UNKNOWN_" + state;
        }
    }

    static String imsRegistrationEventToString(@QnsConstants.QnsImsRegiEvent int event) {
        switch (event) {
            case IMS_REGISTRATION_CHANGED_UNREGISTERED:
                return "IMS_REGISTRATION_CHANGED_UNREGISTERED";
            case IMS_REGISTRATION_CHANGED_ACCESS_NETWORK_CHANGE_FAILED:
                return "IMS_REGISTRATION_CHANGED_ACCESS_NETWORK_CHANGE_FAILED";
            case IMS_REGISTRATION_CHANGED_REGISTERED:
                return "IMS_REGISTRATION_CHANGED_REGISTERED";
        }
        return "";
    }

    /**
     * This method converts AccessNetworkType from int to string.
     *
     * @param type int value of AccessNetworkType
     * @return String value of the access network type.
     */
    static String accessNetworkTypeToString(int type) {
        switch (type) {
            case AccessNetworkType.UNKNOWN:
                return "UNKNOWN";
            case AccessNetworkType.GERAN:
                return "GERAN";
            case AccessNetworkType.UTRAN:
                return "UTRAN";
            case AccessNetworkType.EUTRAN:
                return "EUTRAN";
            case AccessNetworkType.CDMA2000:
                return "CDMA2000";
            case AccessNetworkType.IWLAN:
                return "IWLAN";
            case AccessNetworkType.NGRAN:
                return "NGRAN";
            default:
                return Integer.toString(type);
        }
    }

    /**
     * This method coverts AccessNetworkType from string to int.
     *
     * @param str String value of AccessNetworkType
     * @return Integer value of AccessNetworkType.
     */
    static int accessNetworkTypeFromString(@NonNull String str) {
        switch (str.toUpperCase()) {
            case "GERAN":
                return AccessNetworkType.GERAN;
            case "UTRAN":
                return AccessNetworkType.UTRAN;
            case "EUTRAN":
                return AccessNetworkType.EUTRAN;
            case "CDMA2000":
                return AccessNetworkType.CDMA2000;
            case "IWLAN":
                return AccessNetworkType.IWLAN;
            case "NGRAN":
                return AccessNetworkType.NGRAN;
            default:
                return AccessNetworkType.UNKNOWN;
        }
    }

    /**
     * This method coverts TransportType from int to string.
     *
     * @param transportType Integer value of TransportType
     * @return String value of TransportType.
     */
    static String transportTypeToString(int transportType) {
        switch (transportType) {
            case AccessNetworkConstants.TRANSPORT_TYPE_WWAN:
                return "WWAN";
            case AccessNetworkConstants.TRANSPORT_TYPE_WLAN:
                return "WLAN";
            case AccessNetworkConstants.TRANSPORT_TYPE_INVALID:
                return "INVALID";
            default:
                return Integer.toString(transportType);
        }
    }

    /**
     * Convert data state to string
     *
     * @return The data state in string format.
     */
    static String dataStateToString(@Annotation.DataState int state) {
        switch (state) {
            case TelephonyManager.DATA_DISCONNECTED:
                return "DISCONNECTED";
            case TelephonyManager.DATA_CONNECTING:
                return "CONNECTING";
            case TelephonyManager.DATA_CONNECTED:
                return "CONNECTED";
            case TelephonyManager.DATA_SUSPENDED:
                return "SUSPENDED";
            case TelephonyManager.DATA_DISCONNECTING:
                return "DISCONNECTING";
            case TelephonyManager.DATA_HANDOVER_IN_PROGRESS:
                return "HANDOVERINPROGRESS";
            case TelephonyManager.DATA_UNKNOWN:
                return "UNKNOWN";
        }
        // This is the error case. The well-defined value for UNKNOWN is -1.
        return "UNKNOWN(" + state + ")";
    }

    /**
     * This method converts Network Type to AccessNetworkType.
     *
     * @param networkType integer value of network type
     * @return integer value of AccessNetworkType.
     */
    static int networkTypeToAccessNetworkType(int networkType) {
        switch (networkType) {
            case TelephonyManager.NETWORK_TYPE_GPRS:
            case TelephonyManager.NETWORK_TYPE_EDGE:
            case TelephonyManager.NETWORK_TYPE_GSM:
                return AccessNetworkType.GERAN;
            case TelephonyManager.NETWORK_TYPE_UMTS:
            case TelephonyManager.NETWORK_TYPE_HSDPA:
            case TelephonyManager.NETWORK_TYPE_HSUPA:
            case TelephonyManager.NETWORK_TYPE_HSPAP:
            case TelephonyManager.NETWORK_TYPE_HSPA:
            case TelephonyManager.NETWORK_TYPE_TD_SCDMA:
                return AccessNetworkType.UTRAN;
            case TelephonyManager.NETWORK_TYPE_1xRTT:
            case TelephonyManager.NETWORK_TYPE_CDMA:
            case TelephonyManager.NETWORK_TYPE_EVDO_0:
            case TelephonyManager.NETWORK_TYPE_EVDO_A:
            case TelephonyManager.NETWORK_TYPE_EVDO_B:
            case TelephonyManager.NETWORK_TYPE_EHRPD:
                return AccessNetworkType.CDMA2000;
            case TelephonyManager.NETWORK_TYPE_LTE:
            case TelephonyManager.NETWORK_TYPE_LTE_CA:
                return AccessNetworkType.EUTRAN;
            case TelephonyManager.NETWORK_TYPE_NR:
                return AccessNetworkType.NGRAN;
            case TelephonyManager.NETWORK_TYPE_IWLAN:
                return AccessNetworkType.IWLAN;
            default:
                return AccessNetworkType.UNKNOWN;
        }
    }
}