1 /*
2  * Copyright (C) 2023 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 package com.android.internal.net.ipsec.ike.utils;
17 
18 import android.annotation.IntDef;
19 
20 import java.lang.annotation.Retention;
21 import java.lang.annotation.RetentionPolicy;
22 
23 /** Utility class for logging of IKE metrics. */
24 public class IkeMetrics {
25 
26     /**
27      * Values for Caller from IkeCaller enum proto
28      *
29      * @hide
30      */
31     @Retention(RetentionPolicy.SOURCE)
32     @IntDef(
33             prefix = {"IKE_CALLER_"},
34             value = {
35                 IKE_CALLER_UNKNOWN,
36                 IKE_CALLER_IWLAN,
37                 IKE_CALLER_VCN,
38                 IKE_CALLER_VPN,
39             })
40     public @interface IkeCaller {}
41 
42     /** @hide */
43     public static final int IKE_CALLER_UNKNOWN =
44             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_CALLER__CALLER_UNKNOWN;
45     /** @hide */
46     public static final int IKE_CALLER_IWLAN =
47             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_CALLER__CALLER_IWLAN;
48     /** @hide */
49     public static final int IKE_CALLER_VCN =
50             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_CALLER__CALLER_VCN;
51     /** @hide */
52     public static final int IKE_CALLER_VPN =
53             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_CALLER__CALLER_VPN;
54 
55     /**
56      * Values for SessionType from SessionType enum proto
57      *
58      * @hide
59      */
60     @Retention(RetentionPolicy.SOURCE)
61     @IntDef(
62             prefix = {"IKE_SESSION_TYPE_"},
63             value = {
64                 IKE_SESSION_TYPE_UNKNOWN,
65                 IKE_SESSION_TYPE_IKE,
66                 IKE_SESSION_TYPE_CHILD,
67             })
68     public @interface IkeSessionType {}
69 
70     /** @hide */
71     public static final int IKE_SESSION_TYPE_UNKNOWN =
72             IkeMetricsInterface.IKE_SESSION_TERMINATED__SESSION_TYPE__SESSION_UNKNOWN;
73     /** @hide */
74     public static final int IKE_SESSION_TYPE_IKE =
75             IkeMetricsInterface.IKE_SESSION_TERMINATED__SESSION_TYPE__SESSION_IKE;
76     /** @hide */
77     public static final int IKE_SESSION_TYPE_CHILD =
78             IkeMetricsInterface.IKE_SESSION_TERMINATED__SESSION_TYPE__SESSION_CHILD;
79 
80     /**
81      * Values for DhGroups from DhGroups enum proto
82      *
83      * @hide
84      */
85     @Retention(RetentionPolicy.SOURCE)
86     @IntDef(
87             prefix = {"DH_GROUP_"},
88             value = {
89                 DH_GROUP_UNSPECIFIED,
90                 DH_GROUP_NONE,
91                 DH_GROUP_1024_BIT_MODP,
92                 DH_GROUP_1536_BIT_MODP,
93                 DH_GROUP_2048_BIT_MODP,
94                 DH_GROUP_3072_BIT_MODP,
95                 DH_GROUP_4096_BIT_MODP,
96                 DH_GROUP_CURVE_25519,
97             })
98     public @interface DhGroups {}
99 
100     /** @hide */
101     public static final int DH_GROUP_UNSPECIFIED =
102             IkeMetricsInterface.NEGOTIATED_SECURITY_ASSOCIATION__DH_GROUP__DH_GROUP_UNSPECIFIED;
103 
104     /** @hide */
105     public static final int DH_GROUP_NONE =
106             IkeMetricsInterface.NEGOTIATED_SECURITY_ASSOCIATION__DH_GROUP__DH_GROUP_NONE;
107 
108     /** @hide */
109     public static final int DH_GROUP_1024_BIT_MODP =
110             IkeMetricsInterface.NEGOTIATED_SECURITY_ASSOCIATION__DH_GROUP__DH_GROUP_1024_BIT_MODP;
111 
112     /** @hide */
113     public static final int DH_GROUP_1536_BIT_MODP =
114             IkeMetricsInterface.NEGOTIATED_SECURITY_ASSOCIATION__DH_GROUP__DH_GROUP_1536_BIT_MODP;
115 
116     /** @hide */
117     public static final int DH_GROUP_2048_BIT_MODP =
118             IkeMetricsInterface.NEGOTIATED_SECURITY_ASSOCIATION__DH_GROUP__DH_GROUP_2048_BIT_MODP;
119 
120     /** @hide */
121     public static final int DH_GROUP_3072_BIT_MODP =
122             IkeMetricsInterface.NEGOTIATED_SECURITY_ASSOCIATION__DH_GROUP__DH_GROUP_3072_BIT_MODP;
123 
124     /** @hide */
125     public static final int DH_GROUP_4096_BIT_MODP =
126             IkeMetricsInterface.NEGOTIATED_SECURITY_ASSOCIATION__DH_GROUP__DH_GROUP_4096_BIT_MODP;
127 
128     /** @hide */
129     public static final int DH_GROUP_CURVE_25519 =
130             IkeMetricsInterface.NEGOTIATED_SECURITY_ASSOCIATION__DH_GROUP__DH_GROUP_CURVE_25519;
131 
132     /**
133      * Values for IntegrityAlgorithms from IntegrityAlgorithms enum proto
134      *
135      * @hide
136      */
137     @Retention(RetentionPolicy.SOURCE)
138     @IntDef(
139             prefix = {"INTEGRITY_ALGORITHM_"},
140             value = {
141                 INTEGRITY_ALGORITHM_UNSPECIFIED,
142                 INTEGRITY_ALGORITHM_NONE,
143                 INTEGRITY_ALGORITHM_HMAC_SHA1_96,
144                 INTEGRITY_ALGORITHM_AES_XCBC_96,
145                 INTEGRITY_ALGORITHM_AES_CMAC_96,
146                 INTEGRITY_ALGORITHM_HMAC_SHA2_256_128,
147                 INTEGRITY_ALGORITHM_HMAC_SHA2_384_192,
148                 INTEGRITY_ALGORITHM_HMAC_SHA2_512_256,
149             })
150     public @interface IntegrityAlgorithms {}
151 
152     /** @hide */
153     public static final int INTEGRITY_ALGORITHM_UNSPECIFIED =
154             IkeMetricsInterface
155                     .NEGOTIATED_SECURITY_ASSOCIATION__INTEGRITY_ALGORITHM__INTEGRITY_ALGORITHM_UNSPECIFIED;
156 
157     /** @hide */
158     public static final int INTEGRITY_ALGORITHM_NONE =
159             IkeMetricsInterface
160                     .NEGOTIATED_SECURITY_ASSOCIATION__INTEGRITY_ALGORITHM__INTEGRITY_ALGORITHM_NONE;
161 
162     /** @hide */
163     public static final int INTEGRITY_ALGORITHM_HMAC_SHA1_96 =
164             IkeMetricsInterface
165                     .NEGOTIATED_SECURITY_ASSOCIATION__INTEGRITY_ALGORITHM__INTEGRITY_ALGORITHM_HMAC_SHA1_96;
166 
167     /** @hide */
168     public static final int INTEGRITY_ALGORITHM_AES_XCBC_96 =
169             IkeMetricsInterface
170                     .NEGOTIATED_SECURITY_ASSOCIATION__INTEGRITY_ALGORITHM__INTEGRITY_ALGORITHM_AES_XCBC_96;
171 
172     /** @hide */
173     public static final int INTEGRITY_ALGORITHM_AES_CMAC_96 =
174             IkeMetricsInterface
175                     .NEGOTIATED_SECURITY_ASSOCIATION__INTEGRITY_ALGORITHM__INTEGRITY_ALGORITHM_AES_CMAC_96;
176 
177     /** @hide */
178     public static final int INTEGRITY_ALGORITHM_HMAC_SHA2_256_128 =
179             IkeMetricsInterface
180                     .NEGOTIATED_SECURITY_ASSOCIATION__INTEGRITY_ALGORITHM__INTEGRITY_ALGORITHM_HMAC_SHA2_256_128;
181 
182     /** @hide */
183     public static final int INTEGRITY_ALGORITHM_HMAC_SHA2_384_192 =
184             IkeMetricsInterface
185                     .NEGOTIATED_SECURITY_ASSOCIATION__INTEGRITY_ALGORITHM__INTEGRITY_ALGORITHM_HMAC_SHA2_384_192;
186 
187     /** @hide */
188     public static final int INTEGRITY_ALGORITHM_HMAC_SHA2_512_256 =
189             IkeMetricsInterface
190                     .NEGOTIATED_SECURITY_ASSOCIATION__INTEGRITY_ALGORITHM__INTEGRITY_ALGORITHM_HMAC_SHA2_512_256;
191 
192     /**
193      * Values for PrfAlgorithms from PrfAlgorithms enum proto
194      *
195      * @hide
196      */
197     @Retention(RetentionPolicy.SOURCE)
198     @IntDef(
199             prefix = {"PSEUDORANDOM_FUNCTION_"},
200             value = {
201                 PSEUDORANDOM_FUNCTION_UNSPECIFIED,
202                 PSEUDORANDOM_FUNCTION_HMAC_SHA1,
203                 PSEUDORANDOM_FUNCTION_AES128_XCBC,
204                 PSEUDORANDOM_FUNCTION_SHA2_256,
205                 PSEUDORANDOM_FUNCTION_SHA2_384,
206                 PSEUDORANDOM_FUNCTION_SHA2_512,
207                 PSEUDORANDOM_FUNCTION_AES128_CMAC,
208             })
209     public @interface PrfAlgorithms {}
210 
211     /** @hide */
212     public static final int PSEUDORANDOM_FUNCTION_UNSPECIFIED =
213             IkeMetricsInterface
214                     .NEGOTIATED_SECURITY_ASSOCIATION__PRF_ALGORITHMS__PSEUDORANDOM_FUNCTION_UNSPECIFIED;
215 
216     /** @hide */
217     public static final int PSEUDORANDOM_FUNCTION_HMAC_SHA1 =
218             IkeMetricsInterface
219                     .NEGOTIATED_SECURITY_ASSOCIATION__PRF_ALGORITHMS__PSEUDORANDOM_FUNCTION_HMAC_SHA1;
220 
221     /** @hide */
222     public static final int PSEUDORANDOM_FUNCTION_AES128_XCBC =
223             IkeMetricsInterface
224                     .NEGOTIATED_SECURITY_ASSOCIATION__PRF_ALGORITHMS__PSEUDORANDOM_FUNCTION_AES128_XCBC;
225 
226     /** @hide */
227     public static final int PSEUDORANDOM_FUNCTION_SHA2_256 =
228             IkeMetricsInterface
229                     .NEGOTIATED_SECURITY_ASSOCIATION__PRF_ALGORITHMS__PSEUDORANDOM_FUNCTION_SHA2_256;
230 
231     /** @hide */
232     public static final int PSEUDORANDOM_FUNCTION_SHA2_384 =
233             IkeMetricsInterface
234                     .NEGOTIATED_SECURITY_ASSOCIATION__PRF_ALGORITHMS__PSEUDORANDOM_FUNCTION_SHA2_384;
235 
236     /** @hide */
237     public static final int PSEUDORANDOM_FUNCTION_SHA2_512 =
238             IkeMetricsInterface
239                     .NEGOTIATED_SECURITY_ASSOCIATION__PRF_ALGORITHMS__PSEUDORANDOM_FUNCTION_SHA2_512;
240 
241     /** @hide */
242     public static final int PSEUDORANDOM_FUNCTION_AES128_CMAC =
243             IkeMetricsInterface
244                     .NEGOTIATED_SECURITY_ASSOCIATION__PRF_ALGORITHMS__PSEUDORANDOM_FUNCTION_AES128_CMAC;
245 
246     /**
247      * Values for EncryptionAlgorithms from EncryptionAlgorithms enum proto
248      *
249      * @hide
250      */
251     @Retention(RetentionPolicy.SOURCE)
252     @IntDef(
253             prefix = {"ENCRYPTION_ALGORITHM_"},
254             value = {
255                 ENCRYPTION_ALGORITHM_UNSPECIFIED,
256                 ENCRYPTION_ALGORITHM_3DES,
257                 ENCRYPTION_ALGORITHM_AES_CBC,
258                 ENCRYPTION_ALGORITHM_AES_CTR,
259                 ENCRYPTION_ALGORITHM_AES_GCM_8,
260                 ENCRYPTION_ALGORITHM_AES_GCM_12,
261                 ENCRYPTION_ALGORITHM_AES_GCM_16,
262                 ENCRYPTION_ALGORITHM_CHACHA20_POLY1305,
263             })
264     public @interface EncryptionAlgorithms {}
265 
266     /** @hide */
267     public static final int ENCRYPTION_ALGORITHM_UNSPECIFIED =
268             IkeMetricsInterface
269                     .NEGOTIATED_SECURITY_ASSOCIATION__ENCRYPTION_ALGORITHM__ENCRYPTION_ALGORITHM_UNSPECIFIED;
270 
271     /** @hide */
272     public static final int ENCRYPTION_ALGORITHM_3DES =
273             IkeMetricsInterface
274                     .NEGOTIATED_SECURITY_ASSOCIATION__ENCRYPTION_ALGORITHM__ENCRYPTION_ALGORITHM_3DES;
275 
276     /** @hide */
277     public static final int ENCRYPTION_ALGORITHM_AES_CBC =
278             IkeMetricsInterface
279                     .NEGOTIATED_SECURITY_ASSOCIATION__ENCRYPTION_ALGORITHM__ENCRYPTION_ALGORITHM_AES_CBC;
280 
281     /** @hide */
282     public static final int ENCRYPTION_ALGORITHM_AES_CTR =
283             IkeMetricsInterface
284                     .NEGOTIATED_SECURITY_ASSOCIATION__ENCRYPTION_ALGORITHM__ENCRYPTION_ALGORITHM_AES_CTR;
285 
286     /** @hide */
287     public static final int ENCRYPTION_ALGORITHM_AES_GCM_8 =
288             IkeMetricsInterface
289                     .NEGOTIATED_SECURITY_ASSOCIATION__ENCRYPTION_ALGORITHM__ENCRYPTION_ALGORITHM_AES_GCM_8;
290 
291     /** @hide */
292     public static final int ENCRYPTION_ALGORITHM_AES_GCM_12 =
293             IkeMetricsInterface
294                     .NEGOTIATED_SECURITY_ASSOCIATION__ENCRYPTION_ALGORITHM__ENCRYPTION_ALGORITHM_AES_GCM_12;
295 
296     /** @hide */
297     public static final int ENCRYPTION_ALGORITHM_AES_GCM_16 =
298             IkeMetricsInterface
299                     .NEGOTIATED_SECURITY_ASSOCIATION__ENCRYPTION_ALGORITHM__ENCRYPTION_ALGORITHM_AES_GCM_16;
300 
301     /** @hide */
302     public static final int ENCRYPTION_ALGORITHM_CHACHA20_POLY1305 =
303             IkeMetricsInterface
304                     .NEGOTIATED_SECURITY_ASSOCIATION__ENCRYPTION_ALGORITHM__ENCRYPTION_ALGORITHM_CHACHA20_POLY1305;
305 
306     /**
307      * Values for KeyLengths from KeyLengths enum proto
308      *
309      * @hide
310      */
311     @Retention(RetentionPolicy.SOURCE)
312     @IntDef(
313             prefix = {"KEY_LEN_"},
314             value = {
315                 KEY_LEN_UNSPECIFIED,
316                 KEY_LEN_UNUSED,
317                 KEY_LEN_AES_128,
318                 KEY_LEN_AES_192,
319                 KEY_LEN_AES_256,
320             })
321     public @interface KeyLengths {}
322 
323     /** @hide */
324     public static final int KEY_LEN_UNSPECIFIED =
325             IkeMetricsInterface.NEGOTIATED_SECURITY_ASSOCIATION__KEY_LENGTH__KEY_LEN_UNSPECIFIED;
326 
327     /** @hide */
328     public static final int KEY_LEN_UNUSED =
329             IkeMetricsInterface.NEGOTIATED_SECURITY_ASSOCIATION__KEY_LENGTH__KEY_LEN_UNUSED;
330 
331     /** @hide */
332     public static final int KEY_LEN_AES_128 =
333             IkeMetricsInterface.NEGOTIATED_SECURITY_ASSOCIATION__KEY_LENGTH__KEY_LEN_AES_128;
334 
335     /** @hide */
336     public static final int KEY_LEN_AES_192 =
337             IkeMetricsInterface.NEGOTIATED_SECURITY_ASSOCIATION__KEY_LENGTH__KEY_LEN_AES_192;
338 
339     /** @hide */
340     public static final int KEY_LEN_AES_256 =
341             IkeMetricsInterface.NEGOTIATED_SECURITY_ASSOCIATION__KEY_LENGTH__KEY_LEN_AES_256;
342 
343     /**
344      * Values for State from IkeState enum proto
345      *
346      * @hide
347      */
348     @Retention(RetentionPolicy.SOURCE)
349     @IntDef(
350             prefix = {"IKE_STATE_"},
351             value = {
352                 IKE_STATE_UNKNOWN,
353                 IKE_STATE_IKE_KILL,
354                 IKE_STATE_IKE_INITIAL,
355                 IKE_STATE_IKE_CREATE_LOCAL_IKE_INIT,
356                 IKE_STATE_IKE_CREATE_LOCAL_IKE_AUTH,
357                 IKE_STATE_IKE_CREATE_LOCAL_IKE_AUTH_IN_EAP,
358                 IKE_STATE_IKE_CREATE_LOCAL_IKE_AUTH_POST_EAP,
359                 IKE_STATE_IKE_IDLE,
360                 IKE_STATE_IKE_CHILD_PROCEDURE_ONGOING,
361                 IKE_STATE_IKE_RECEIVING,
362                 IKE_STATE_IKE_REKEY_LOCAL_CREATE,
363                 IKE_STATE_IKE_SIMULTANEOUS_REKEY_LOCAL_CREATE,
364                 IKE_STATE_IKE_SIMULTANEOUS_REKEY_LOCAL_DELETE_REMOTE_DELETE,
365                 IKE_STATE_IKE_SIMULTANEOUS_REKEY_LOCAL_DELETE,
366                 IKE_STATE_IKE_SIMULTANEOUS_REKEY_REMOTE_DELETE,
367                 IKE_STATE_IKE_REKEY_LOCAL_DELETE,
368                 IKE_STATE_IKE_REKEY_REMOTE_DELETE,
369                 IKE_STATE_IKE_DELETE_LOCAL_DELETE,
370                 IKE_STATE_IKE_DPD_LOCAL_INFO,
371                 IKE_STATE_IKE_MOBIKE_LOCAL_INFO,
372                 IKE_STATE_IKE_DPD_ON_DEMAND_LOCAL_INFO,
373                 IKE_STATE_CHILD_KILL,
374                 IKE_STATE_CHILD_INITIAL,
375                 IKE_STATE_CHILD_CREATE_LOCAL_CREATE,
376                 IKE_STATE_CHILD_IDLE,
377                 IKE_STATE_CHILD_IDLE_WITH_DEFERRED_REQUEST,
378                 IKE_STATE_CHILD_CLOSE_AND_AWAIT_RESPONSE,
379                 IKE_STATE_CHILD_DELETE_LOCAL_DELETE,
380                 IKE_STATE_CHILD_DELETE_REMOTE_DELETE,
381                 IKE_STATE_CHILD_REKEY_LOCAL_CREATE,
382                 IKE_STATE_CHILD_MOBIKE_REKEY_LOCAL_CREATE,
383                 IKE_STATE_CHILD_REKEY_REMOTE_CREATE,
384                 IKE_STATE_CHILD_REKEY_LOCAL_DELETE,
385                 IKE_STATE_CHILD_REKEY_REMOTE_DELETE,
386             })
387     public @interface IkeState {}
388 
389     /** @hide */
390     public static final int IKE_STATE_UNKNOWN =
391             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_STATE__STATE_UNKNOWN;
392     /** @hide */
393     public static final int IKE_STATE_IKE_KILL =
394             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_STATE__STATE_IKE_KILL;
395     /** @hide */
396     public static final int IKE_STATE_IKE_INITIAL =
397             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_STATE__STATE_IKE_INITIAL;
398     /** @hide */
399     public static final int IKE_STATE_IKE_CREATE_LOCAL_IKE_INIT =
400             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_STATE__STATE_IKE_CREATE_LOCAL_IKE_INIT;
401     /** @hide */
402     public static final int IKE_STATE_IKE_CREATE_LOCAL_IKE_AUTH =
403             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_STATE__STATE_IKE_CREATE_LOCAL_IKE_AUTH;
404     /** @hide */
405     public static final int IKE_STATE_IKE_CREATE_LOCAL_IKE_AUTH_IN_EAP =
406             IkeMetricsInterface
407                     .IKE_SESSION_TERMINATED__IKE_STATE__STATE_IKE_CREATE_LOCAL_IKE_AUTH_IN_EAP;
408     /** @hide */
409     public static final int IKE_STATE_IKE_CREATE_LOCAL_IKE_AUTH_POST_EAP =
410             IkeMetricsInterface
411                     .IKE_SESSION_TERMINATED__IKE_STATE__STATE_IKE_CREATE_LOCAL_IKE_AUTH_POST_EAP;
412     /** @hide */
413     public static final int IKE_STATE_IKE_IDLE =
414             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_STATE__STATE_IKE_IDLE;
415     /** @hide */
416     public static final int IKE_STATE_IKE_CHILD_PROCEDURE_ONGOING =
417             IkeMetricsInterface
418                     .IKE_SESSION_TERMINATED__IKE_STATE__STATE_IKE_CHILD_PROCEDURE_ONGOING;
419     /** @hide */
420     public static final int IKE_STATE_IKE_RECEIVING =
421             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_STATE__STATE_IKE_RECEIVING;
422     /** @hide */
423     public static final int IKE_STATE_IKE_REKEY_LOCAL_CREATE =
424             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_STATE__STATE_IKE_REKEY_LOCAL_CREATE;
425     /** @hide */
426     public static final int IKE_STATE_IKE_SIMULTANEOUS_REKEY_LOCAL_CREATE =
427             IkeMetricsInterface
428                     .IKE_SESSION_TERMINATED__IKE_STATE__STATE_IKE_SIMULTANEOUS_REKEY_LOCAL_CREATE;
429     /** @hide */
430     public static final int IKE_STATE_IKE_SIMULTANEOUS_REKEY_LOCAL_DELETE_REMOTE_DELETE =
431             IkeMetricsInterface
432                     .IKE_SESSION_TERMINATED__IKE_STATE__STATE_IKE_SIMULTANEOUS_REKEY_LOCAL_DELETE_REMOTE_DELETE;
433     /** @hide */
434     public static final int IKE_STATE_IKE_SIMULTANEOUS_REKEY_LOCAL_DELETE =
435             IkeMetricsInterface
436                     .IKE_SESSION_TERMINATED__IKE_STATE__STATE_IKE_SIMULTANEOUS_REKEY_LOCAL_DELETE;
437     /** @hide */
438     public static final int IKE_STATE_IKE_SIMULTANEOUS_REKEY_REMOTE_DELETE =
439             IkeMetricsInterface
440                     .IKE_SESSION_TERMINATED__IKE_STATE__STATE_IKE_SIMULTANEOUS_REKEY_REMOTE_DELETE;
441     /** @hide */
442     public static final int IKE_STATE_IKE_REKEY_LOCAL_DELETE =
443             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_STATE__STATE_IKE_REKEY_LOCAL_DELETE;
444     /** @hide */
445     public static final int IKE_STATE_IKE_REKEY_REMOTE_DELETE =
446             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_STATE__STATE_IKE_REKEY_REMOTE_DELETE;
447     /** @hide */
448     public static final int IKE_STATE_IKE_DELETE_LOCAL_DELETE =
449             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_STATE__STATE_IKE_DELETE_LOCAL_DELETE;
450     /** @hide */
451     public static final int IKE_STATE_IKE_DPD_LOCAL_INFO =
452             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_STATE__STATE_IKE_DPD_LOCAL_INFO;
453     /** @hide */
454     public static final int IKE_STATE_IKE_MOBIKE_LOCAL_INFO =
455             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_STATE__STATE_IKE_MOBIKE_LOCAL_INFO;
456     /** @hide */
457     public static final int IKE_STATE_IKE_DPD_ON_DEMAND_LOCAL_INFO =
458             IkeMetricsInterface
459                     .IKE_SESSION_TERMINATED__IKE_STATE__STATE_IKE_DPD_ON_DEMAND_LOCAL_INFO;
460     /** @hide */
461     public static final int IKE_STATE_CHILD_KILL =
462             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_STATE__STATE_CHILD_KILL;
463     /** @hide */
464     public static final int IKE_STATE_CHILD_INITIAL =
465             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_STATE__STATE_CHILD_INITIAL;
466     /** @hide */
467     public static final int IKE_STATE_CHILD_CREATE_LOCAL_CREATE =
468             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_STATE__STATE_CHILD_CREATE_LOCAL_CREATE;
469     /** @hide */
470     public static final int IKE_STATE_CHILD_IDLE =
471             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_STATE__STATE_CHILD_IDLE;
472     /** @hide */
473     public static final int IKE_STATE_CHILD_IDLE_WITH_DEFERRED_REQUEST =
474             IkeMetricsInterface
475                     .IKE_SESSION_TERMINATED__IKE_STATE__STATE_CHILD_IDLE_WITH_DEFERRED_REQUEST;
476     /** @hide */
477     public static final int IKE_STATE_CHILD_CLOSE_AND_AWAIT_RESPONSE =
478             IkeMetricsInterface
479                     .IKE_SESSION_TERMINATED__IKE_STATE__STATE_CHILD_CLOSE_AND_AWAIT_RESPONSE;
480     /** @hide */
481     public static final int IKE_STATE_CHILD_DELETE_LOCAL_DELETE =
482             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_STATE__STATE_CHILD_DELETE_LOCAL_DELETE;
483     /** @hide */
484     public static final int IKE_STATE_CHILD_DELETE_REMOTE_DELETE =
485             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_STATE__STATE_CHILD_DELETE_REMOTE_DELETE;
486     /** @hide */
487     public static final int IKE_STATE_CHILD_REKEY_LOCAL_CREATE =
488             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_STATE__STATE_CHILD_REKEY_LOCAL_CREATE;
489     /** @hide */
490     public static final int IKE_STATE_CHILD_MOBIKE_REKEY_LOCAL_CREATE =
491             IkeMetricsInterface
492                     .IKE_SESSION_TERMINATED__IKE_STATE__STATE_CHILD_MOBIKE_REKEY_LOCAL_CREATE;
493     /** @hide */
494     public static final int IKE_STATE_CHILD_REKEY_REMOTE_CREATE =
495             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_STATE__STATE_CHILD_REKEY_REMOTE_CREATE;
496     /** @hide */
497     public static final int IKE_STATE_CHILD_REKEY_LOCAL_DELETE =
498             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_STATE__STATE_CHILD_REKEY_LOCAL_DELETE;
499     /** @hide */
500     public static final int IKE_STATE_CHILD_REKEY_REMOTE_DELETE =
501             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_STATE__STATE_CHILD_REKEY_REMOTE_DELETE;
502 
503     /**
504      * Values for Error from IkeError enum proto
505      *
506      * @hide
507      */
508     @Retention(RetentionPolicy.SOURCE)
509     @IntDef(
510             prefix = {"IKE_ERROR_"},
511             value = {
512                 IKE_ERROR_UNKNOWN,
513                 IKE_ERROR_NONE,
514                 IKE_ERROR_INTERNAL,
515                 IKE_ERROR_NETWORK_LOST,
516                 IKE_ERROR_IO_GENERAL,
517                 IKE_ERROR_IO_TIMEOUT,
518                 IKE_ERROR_IO_DNS_FAILURE,
519                 IKE_ERROR_PROTOCOL_UNKNOWN,
520                 IKE_ERROR_PROTOCOL_UNSUPPORTED_CRITICAL_PAYLOAD,
521                 IKE_ERROR_PROTOCOL_INVALID_IKE_SPI,
522                 IKE_ERROR_PROTOCOL_INVALID_MAJOR_VERSION,
523                 IKE_ERROR_PROTOCOL_INVALID_SYNTAX,
524                 IKE_ERROR_PROTOCOL_INVALID_MESSAGE_ID,
525                 IKE_ERROR_PROTOCOL_NO_PROPOSAL_CHOSEN,
526                 IKE_ERROR_PROTOCOL_INVALID_KE_PAYLOAD,
527                 IKE_ERROR_PROTOCOL_AUTHENTICATION_FAILED,
528                 IKE_ERROR_PROTOCOL_SINGLE_PAIR_REQUIRED,
529                 IKE_ERROR_PROTOCOL_NO_ADDITIONAL_SAS,
530                 IKE_ERROR_PROTOCOL_INTERNAL_ADDRESS_FAILURE,
531                 IKE_ERROR_PROTOCOL_FAILED_CP_REQUIRED,
532                 IKE_ERROR_PROTOCOL_TS_UNACCEPTABLE,
533                 IKE_ERROR_PROTOCOL_INVALID_SELECTORS,
534                 IKE_ERROR_PROTOCOL_TEMPORARY_FAILURE,
535                 IKE_ERROR_PROTOCOL_CHILD_SA_NOT_FOUND,
536             })
537     public @interface IkeError {}
538 
539     /** @hide */
540     public static final int IKE_ERROR_UNKNOWN =
541             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_ERROR__ERROR_UNKNOWN;
542     /** @hide */
543     public static final int IKE_ERROR_NONE =
544             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_ERROR__ERROR_NONE;
545     /** @hide */
546     public static final int IKE_ERROR_INTERNAL =
547             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_ERROR__ERROR_INTERNAL;
548     /** @hide */
549     public static final int IKE_ERROR_NETWORK_LOST =
550             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_ERROR__ERROR_NETWORK_LOST;
551     /** @hide */
552     public static final int IKE_ERROR_IO_GENERAL =
553             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_ERROR__ERROR_IO_GENERAL;
554     /** @hide */
555     public static final int IKE_ERROR_IO_TIMEOUT =
556             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_ERROR__ERROR_IO_TIMEOUT;
557     /** @hide */
558     public static final int IKE_ERROR_IO_DNS_FAILURE =
559             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_ERROR__ERROR_IO_DNS_FAILURE;
560     /** @hide */
561     public static final int IKE_ERROR_PROTOCOL_UNKNOWN =
562             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_ERROR__ERROR_PROTOCOL_UNKNOWN;
563     /** @hide */
564     public static final int IKE_ERROR_PROTOCOL_UNSUPPORTED_CRITICAL_PAYLOAD =
565             IkeMetricsInterface
566                     .IKE_SESSION_TERMINATED__IKE_ERROR__ERROR_PROTOCOL_UNSUPPORTED_CRITICAL_PAYLOAD;
567     /** @hide */
568     public static final int IKE_ERROR_PROTOCOL_INVALID_IKE_SPI =
569             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_ERROR__ERROR_PROTOCOL_INVALID_IKE_SPI;
570     /** @hide */
571     public static final int IKE_ERROR_PROTOCOL_INVALID_MAJOR_VERSION =
572             IkeMetricsInterface
573                     .IKE_SESSION_TERMINATED__IKE_ERROR__ERROR_PROTOCOL_INVALID_MAJOR_VERSION;
574     /** @hide */
575     public static final int IKE_ERROR_PROTOCOL_INVALID_SYNTAX =
576             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_ERROR__ERROR_PROTOCOL_INVALID_SYNTAX;
577     /** @hide */
578     public static final int IKE_ERROR_PROTOCOL_INVALID_MESSAGE_ID =
579             IkeMetricsInterface
580                     .IKE_SESSION_TERMINATED__IKE_ERROR__ERROR_PROTOCOL_INVALID_MESSAGE_ID;
581     /** @hide */
582     public static final int IKE_ERROR_PROTOCOL_NO_PROPOSAL_CHOSEN =
583             IkeMetricsInterface
584                     .IKE_SESSION_TERMINATED__IKE_ERROR__ERROR_PROTOCOL_NO_PROPOSAL_CHOSEN;
585     /** @hide */
586     public static final int IKE_ERROR_PROTOCOL_INVALID_KE_PAYLOAD =
587             IkeMetricsInterface
588                     .IKE_SESSION_TERMINATED__IKE_ERROR__ERROR_PROTOCOL_INVALID_KE_PAYLOAD;
589     /** @hide */
590     public static final int IKE_ERROR_PROTOCOL_AUTHENTICATION_FAILED =
591             IkeMetricsInterface
592                     .IKE_SESSION_TERMINATED__IKE_ERROR__ERROR_PROTOCOL_AUTHENTICATION_FAILED;
593     /** @hide */
594     public static final int IKE_ERROR_PROTOCOL_SINGLE_PAIR_REQUIRED =
595             IkeMetricsInterface
596                     .IKE_SESSION_TERMINATED__IKE_ERROR__ERROR_PROTOCOL_SINGLE_PAIR_REQUIRED;
597     /** @hide */
598     public static final int IKE_ERROR_PROTOCOL_NO_ADDITIONAL_SAS =
599             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_ERROR__ERROR_PROTOCOL_NO_ADDITIONAL_SAS;
600     /** @hide */
601     public static final int IKE_ERROR_PROTOCOL_INTERNAL_ADDRESS_FAILURE =
602             IkeMetricsInterface
603                     .IKE_SESSION_TERMINATED__IKE_ERROR__ERROR_PROTOCOL_INTERNAL_ADDRESS_FAILURE;
604     /** @hide */
605     public static final int IKE_ERROR_PROTOCOL_FAILED_CP_REQUIRED =
606             IkeMetricsInterface
607                     .IKE_SESSION_TERMINATED__IKE_ERROR__ERROR_PROTOCOL_FAILED_CP_REQUIRED;
608     /** @hide */
609     public static final int IKE_ERROR_PROTOCOL_TS_UNACCEPTABLE =
610             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_ERROR__ERROR_PROTOCOL_TS_UNACCEPTABLE;
611     /** @hide */
612     public static final int IKE_ERROR_PROTOCOL_INVALID_SELECTORS =
613             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_ERROR__ERROR_PROTOCOL_INVALID_SELECTORS;
614     /** @hide */
615     public static final int IKE_ERROR_PROTOCOL_TEMPORARY_FAILURE =
616             IkeMetricsInterface.IKE_SESSION_TERMINATED__IKE_ERROR__ERROR_PROTOCOL_TEMPORARY_FAILURE;
617     /** @hide */
618     public static final int IKE_ERROR_PROTOCOL_CHILD_SA_NOT_FOUND =
619             IkeMetricsInterface
620                     .IKE_SESSION_TERMINATED__IKE_ERROR__ERROR_PROTOCOL_CHILD_SA_NOT_FOUND;
621     /** @hide */
622     public static final int IKE_TASK_UNSPECIFIED =
623             IkeMetricsInterface
624                     .IKE_LIVENESS_CHECK_SESSION_VALIDATED__IKE_TASK__IKE_TASK_UNSPECIFIED;
625     /**
626      * Values for UnderlyingNetworkType from IkeUnderlyingNetworkType enum proto
627      *
628      * @hide
629      */
630     @Retention(RetentionPolicy.SOURCE)
631     @IntDef(
632             prefix = {"IKE_UNDERLYING_NETWORK_TYPE_"},
633             value = {
634                 IKE_UNDERLYING_NETWORK_TYPE_UNSPECIFIED,
635                 IKE_UNDERLYING_NETWORK_TYPE_WIFI,
636                 IKE_UNDERLYING_NETWORK_TYPE_CELLULAR,
637             })
638     public @interface IkeUnderlyingNetworkType {}
639 
640     /** @hide */
641     public static final int IKE_UNDERLYING_NETWORK_TYPE_UNSPECIFIED =
642             IkeMetricsInterface
643                     .IKE_LIVENESS_CHECK_SESSION_VALIDATED__IKE_UNDERLYING_NETWORK_TYPE__NETWORK_UNSPECIFIED;
644     /** @hide */
645     public static final int IKE_UNDERLYING_NETWORK_TYPE_WIFI =
646             IkeMetricsInterface
647                     .IKE_LIVENESS_CHECK_SESSION_VALIDATED__IKE_UNDERLYING_NETWORK_TYPE__NETWORK_WIFI;
648     /** @hide */
649     public static final int IKE_UNDERLYING_NETWORK_TYPE_CELLULAR =
650             IkeMetricsInterface
651                     .IKE_LIVENESS_CHECK_SESSION_VALIDATED__IKE_UNDERLYING_NETWORK_TYPE__NETWORK_CELLULAR;
652 
653     /**
654      * Log an atom when an IKE session or a Child Session is terminated.
655      *
656      * <p>This method should not be called if the Child Session is terminated due to IKE Session
657      * closure.
658      */
logSessionTerminated( @keCaller int ikeCaller, @IkeSessionType int ikeSessionType, @IkeState int ikeState, @IkeError int ikeError)659     public void logSessionTerminated(
660             @IkeCaller int ikeCaller,
661             @IkeSessionType int ikeSessionType,
662             @IkeState int ikeState,
663             @IkeError int ikeError) {
664         IkeMetricsInterface.write(
665                 IkeMetricsInterface.IKE_SESSION_TERMINATED,
666                 ikeCaller,
667                 ikeSessionType,
668                 ikeState,
669                 ikeError);
670     }
671 
672     /**
673      * Log an atom when an liveness check is completed.
674      *
675      * <p>This method requests a liveness check from the client and records the associated
676      * information when the liveness check is completed regardless of success of failure.
677      */
logLivenessCheckCompleted( @keCaller int ikeCaller, @IkeState int ikeState, @IkeUnderlyingNetworkType int ikeUnderlyingNetworkType, int elapsedTimeInMillis, int numberOfOnGoing, boolean resultSuccess)678     public void logLivenessCheckCompleted(
679             @IkeCaller int ikeCaller,
680             @IkeState int ikeState,
681             @IkeUnderlyingNetworkType int ikeUnderlyingNetworkType,
682             int elapsedTimeInMillis,
683             int numberOfOnGoing,
684             boolean resultSuccess) {
685         IkeMetricsInterface.write(
686                 IkeMetricsInterface.IKE_LIVENESS_CHECK_SESSION_VALIDATED,
687                 ikeCaller,
688                 IKE_TASK_UNSPECIFIED,
689                 ikeUnderlyingNetworkType,
690                 elapsedTimeInMillis,
691                 numberOfOnGoing,
692                 resultSuccess,
693                 ikeState);
694     }
695 
696     /**
697      * Log an atom when IKE or Child SA negotiation completed (success or failure).
698      *
699      * <p>This method captures negotiated security association transforms or any failures during
700      * negotiation.
701      */
logSaNegotiation( @keCaller int ikeCaller, @IkeSessionType int ikeSessionType, @IkeState int ikeState, @DhGroups int dhGroup, @EncryptionAlgorithms int encryptionAlgorithm, @KeyLengths int keyLength, @IntegrityAlgorithms int integrityAlgorithm, @PrfAlgorithms int prfAlgorithm, @IkeError int ikeError)702     public void logSaNegotiation(
703             @IkeCaller int ikeCaller,
704             @IkeSessionType int ikeSessionType,
705             @IkeState int ikeState,
706             @DhGroups int dhGroup,
707             @EncryptionAlgorithms int encryptionAlgorithm,
708             @KeyLengths int keyLength,
709             @IntegrityAlgorithms int integrityAlgorithm,
710             @PrfAlgorithms int prfAlgorithm,
711             @IkeError int ikeError) {
712         IkeMetricsInterface.write(
713                 IkeMetricsInterface.NEGOTIATED_SECURITY_ASSOCIATION,
714                 ikeCaller,
715                 ikeSessionType,
716                 ikeState,
717                 dhGroup,
718                 encryptionAlgorithm,
719                 keyLength,
720                 integrityAlgorithm,
721                 prfAlgorithm,
722                 ikeError);
723     }
724 }
725