Erik Kline | 5b25a0f | 2016-04-12 15:31:13 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 android.net.metrics; |
| 18 | |
Hugo Benichi | cf6b12f | 2016-07-04 11:28:05 +0900 | [diff] [blame] | 19 | import android.annotation.IntDef; |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame^] | 20 | import android.annotation.SystemApi; |
| 21 | import android.annotation.TestApi; |
Erik Kline | 5b25a0f | 2016-04-12 15:31:13 +0900 | [diff] [blame] | 22 | import android.os.Parcel; |
| 23 | import android.os.Parcelable; |
Hugo Benichi | 5df9d72 | 2016-04-25 17:16:35 +0900 | [diff] [blame] | 24 | import android.util.SparseArray; |
| 25 | |
| 26 | import com.android.internal.util.MessageUtils; |
Erik Kline | 5b25a0f | 2016-04-12 15:31:13 +0900 | [diff] [blame] | 27 | |
Hugo Benichi | cf6b12f | 2016-07-04 11:28:05 +0900 | [diff] [blame] | 28 | import java.lang.annotation.Retention; |
| 29 | import java.lang.annotation.RetentionPolicy; |
| 30 | |
Erik Kline | 5b25a0f | 2016-04-12 15:31:13 +0900 | [diff] [blame] | 31 | /** |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame^] | 32 | * An event recorded by IpClient when IP provisioning completes for a network or |
Hugo Benichi | cf6b12f | 2016-07-04 11:28:05 +0900 | [diff] [blame] | 33 | * when a network disconnects. |
Erik Kline | 5b25a0f | 2016-04-12 15:31:13 +0900 | [diff] [blame] | 34 | * {@hide} |
| 35 | */ |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame^] | 36 | @SystemApi |
| 37 | @TestApi |
| 38 | public final class IpManagerEvent implements IpConnectivityLog.Event { |
Hugo Benichi | 5df9d72 | 2016-04-25 17:16:35 +0900 | [diff] [blame] | 39 | |
Hugo Benichi | 95cb226 | 2017-01-11 10:11:26 +0900 | [diff] [blame] | 40 | public static final int PROVISIONING_OK = 1; |
| 41 | public static final int PROVISIONING_FAIL = 2; |
| 42 | public static final int COMPLETE_LIFECYCLE = 3; |
| 43 | public static final int ERROR_STARTING_IPV4 = 4; |
| 44 | public static final int ERROR_STARTING_IPV6 = 5; |
| 45 | public static final int ERROR_STARTING_IPREACHABILITYMONITOR = 6; |
Hugo Benichi | a428392 | 2017-07-14 07:25:51 +0900 | [diff] [blame] | 46 | public static final int ERROR_INVALID_PROVISIONING = 7; |
Erik Kline | b152cd0 | 2018-03-02 16:51:13 +0900 | [diff] [blame] | 47 | public static final int ERROR_INTERFACE_NOT_FOUND = 8; |
Hugo Benichi | 5df9d72 | 2016-04-25 17:16:35 +0900 | [diff] [blame] | 48 | |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame^] | 49 | /** @hide */ |
Erik Kline | e452660 | 2016-10-14 18:33:22 +0900 | [diff] [blame] | 50 | @IntDef(value = { |
| 51 | PROVISIONING_OK, PROVISIONING_FAIL, COMPLETE_LIFECYCLE, |
| 52 | ERROR_STARTING_IPV4, ERROR_STARTING_IPV6, ERROR_STARTING_IPREACHABILITYMONITOR, |
Erik Kline | b152cd0 | 2018-03-02 16:51:13 +0900 | [diff] [blame] | 53 | ERROR_INVALID_PROVISIONING, ERROR_INTERFACE_NOT_FOUND, |
Erik Kline | e452660 | 2016-10-14 18:33:22 +0900 | [diff] [blame] | 54 | }) |
Hugo Benichi | cf6b12f | 2016-07-04 11:28:05 +0900 | [diff] [blame] | 55 | @Retention(RetentionPolicy.SOURCE) |
| 56 | public @interface EventType {} |
| 57 | |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame^] | 58 | /** @hide */ |
Hugo Benichi | cf6b12f | 2016-07-04 11:28:05 +0900 | [diff] [blame] | 59 | public final @EventType int eventType; |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame^] | 60 | /** @hide */ |
Hugo Benichi | 627b424 | 2016-04-15 16:56:28 +0900 | [diff] [blame] | 61 | public final long durationMs; |
Erik Kline | 5b25a0f | 2016-04-12 15:31:13 +0900 | [diff] [blame] | 62 | |
Hugo Benichi | 948a859 | 2017-03-16 16:33:47 +0900 | [diff] [blame] | 63 | public IpManagerEvent(@EventType int eventType, long duration) { |
Hugo Benichi | 5df9d72 | 2016-04-25 17:16:35 +0900 | [diff] [blame] | 64 | this.eventType = eventType; |
Hugo Benichi | 627b424 | 2016-04-15 16:56:28 +0900 | [diff] [blame] | 65 | this.durationMs = duration; |
Erik Kline | 5b25a0f | 2016-04-12 15:31:13 +0900 | [diff] [blame] | 66 | } |
| 67 | |
Hugo Benichi | 627b424 | 2016-04-15 16:56:28 +0900 | [diff] [blame] | 68 | private IpManagerEvent(Parcel in) { |
Hugo Benichi | 5df9d72 | 2016-04-25 17:16:35 +0900 | [diff] [blame] | 69 | this.eventType = in.readInt(); |
Hugo Benichi | 627b424 | 2016-04-15 16:56:28 +0900 | [diff] [blame] | 70 | this.durationMs = in.readLong(); |
Erik Kline | 5b25a0f | 2016-04-12 15:31:13 +0900 | [diff] [blame] | 71 | } |
| 72 | |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame^] | 73 | /** @hide */ |
Hugo Benichi | cf6b12f | 2016-07-04 11:28:05 +0900 | [diff] [blame] | 74 | @Override |
Erik Kline | 5b25a0f | 2016-04-12 15:31:13 +0900 | [diff] [blame] | 75 | public void writeToParcel(Parcel out, int flags) { |
Hugo Benichi | 5df9d72 | 2016-04-25 17:16:35 +0900 | [diff] [blame] | 76 | out.writeInt(eventType); |
Hugo Benichi | 627b424 | 2016-04-15 16:56:28 +0900 | [diff] [blame] | 77 | out.writeLong(durationMs); |
| 78 | } |
| 79 | |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame^] | 80 | /** @hide */ |
Hugo Benichi | cf6b12f | 2016-07-04 11:28:05 +0900 | [diff] [blame] | 81 | @Override |
Hugo Benichi | 627b424 | 2016-04-15 16:56:28 +0900 | [diff] [blame] | 82 | public int describeContents() { |
| 83 | return 0; |
Erik Kline | 5b25a0f | 2016-04-12 15:31:13 +0900 | [diff] [blame] | 84 | } |
| 85 | |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame^] | 86 | /** @hide */ |
Erik Kline | 5b25a0f | 2016-04-12 15:31:13 +0900 | [diff] [blame] | 87 | public static final Parcelable.Creator<IpManagerEvent> CREATOR |
| 88 | = new Parcelable.Creator<IpManagerEvent>() { |
| 89 | public IpManagerEvent createFromParcel(Parcel in) { |
| 90 | return new IpManagerEvent(in); |
| 91 | } |
| 92 | |
| 93 | public IpManagerEvent[] newArray(int size) { |
| 94 | return new IpManagerEvent[size]; |
| 95 | } |
| 96 | }; |
| 97 | |
Hugo Benichi | 5df9d72 | 2016-04-25 17:16:35 +0900 | [diff] [blame] | 98 | @Override |
| 99 | public String toString() { |
Hugo Benichi | 948a859 | 2017-03-16 16:33:47 +0900 | [diff] [blame] | 100 | return String.format("IpManagerEvent(%s, %dms)", |
| 101 | Decoder.constants.get(eventType), durationMs); |
Hugo Benichi | 5df9d72 | 2016-04-25 17:16:35 +0900 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | final static class Decoder { |
| 105 | static final SparseArray<String> constants = MessageUtils.findMessageNames( |
Erik Kline | e452660 | 2016-10-14 18:33:22 +0900 | [diff] [blame] | 106 | new Class[]{IpManagerEvent.class}, |
| 107 | new String[]{"PROVISIONING_", "COMPLETE_", "ERROR_"}); |
Erik Kline | 5b25a0f | 2016-04-12 15:31:13 +0900 | [diff] [blame] | 108 | } |
Hugo Benichi | cfddd68 | 2016-05-31 16:28:06 +0900 | [diff] [blame] | 109 | } |