DefaultNetworkEvent.java revision 5f16f760ad2469c8d5636f45974a2f725ef289be
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 17package android.net.metrics; 18 19import android.annotation.SystemApi; 20import android.os.Parcel; 21import android.os.Parcelable; 22 23/** 24 * {@hide} 25 */ 26@SystemApi 27public final class DefaultNetworkEvent extends IpConnectivityEvent implements Parcelable { 28 // The ID of the network that has become the new default or NETID_UNSET if none. 29 public final int netId; 30 // The list of transport types of the new default network, for example TRANSPORT_WIFI, as 31 // defined in NetworkCapabilities.java. 32 public final int[] transportTypes; 33 // The ID of the network that was the default before or NETID_UNSET if none. 34 public final int prevNetId; 35 // Whether the previous network had IPv4/IPv6 connectivity. 36 public final boolean prevIPv4; 37 public final boolean prevIPv6; 38 39 private DefaultNetworkEvent(int netId, int[] transportTypes, 40 int prevNetId, boolean prevIPv4, boolean prevIPv6) { 41 this.netId = netId; 42 this.transportTypes = transportTypes; 43 this.prevNetId = prevNetId; 44 this.prevIPv4 = prevIPv4; 45 this.prevIPv6 = prevIPv6; 46 } 47 48 private DefaultNetworkEvent(Parcel in) { 49 this.netId = in.readInt(); 50 this.transportTypes = in.createIntArray(); 51 this.prevNetId = in.readInt(); 52 this.prevIPv4 = (in.readByte() > 0); 53 this.prevIPv6 = (in.readByte() > 0); 54 } 55 56 public void writeToParcel(Parcel out, int flags) { 57 out.writeInt(netId); 58 out.writeIntArray(transportTypes); 59 out.writeInt(prevNetId); 60 out.writeByte(prevIPv4 ? (byte) 1 : (byte) 0); 61 out.writeByte(prevIPv6 ? (byte) 1 : (byte) 0); 62 } 63 64 public int describeContents() { 65 return 0; 66 } 67 68 public static final Parcelable.Creator<DefaultNetworkEvent> CREATOR 69 = new Parcelable.Creator<DefaultNetworkEvent>() { 70 public DefaultNetworkEvent createFromParcel(Parcel in) { 71 return new DefaultNetworkEvent(in); 72 } 73 74 public DefaultNetworkEvent[] newArray(int size) { 75 return new DefaultNetworkEvent[size]; 76 } 77 }; 78 79 public static void logEvent( 80 int netId, int[] transports, int prevNetId, boolean hadIPv4, boolean hadIPv6) { 81 final DefaultNetworkEvent ev = 82 new DefaultNetworkEvent(netId, transports, prevNetId, hadIPv4, hadIPv6); 83 logEvent(IPCE_CONSRV_DEFAULT_NET_CHANGE, ev); 84 } 85}; 86