Pierre Imai | 55618be | 2016-02-19 15:25:54 +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 | 1193a9c | 2017-10-19 14:58:15 +0900 | [diff] [blame] | 19 | import static android.net.ConnectivityManager.NETID_UNSET; |
| 20 | |
Hugo Benichi | 5df9d72 | 2016-04-25 17:16:35 +0900 | [diff] [blame] | 21 | import android.net.NetworkCapabilities; |
Pierre Imai | 55618be | 2016-02-19 15:25:54 +0900 | [diff] [blame] | 22 | |
Pierre Imai | bc9cc50 | 2016-03-29 14:50:51 +0900 | [diff] [blame] | 23 | /** |
Hugo Benichi | cf6b12f | 2016-07-04 11:28:05 +0900 | [diff] [blame] | 24 | * An event recorded by ConnectivityService when there is a change in the default network. |
Pierre Imai | bc9cc50 | 2016-03-29 14:50:51 +0900 | [diff] [blame] | 25 | * {@hide} |
| 26 | */ |
Hugo Benichi | 1193a9c | 2017-10-19 14:58:15 +0900 | [diff] [blame] | 27 | public class DefaultNetworkEvent { |
| 28 | |
Pierre Imai | 6b4e15b | 2016-04-07 12:21:05 +0900 | [diff] [blame] | 29 | // The ID of the network that has become the new default or NETID_UNSET if none. |
Hugo Benichi | 1193a9c | 2017-10-19 14:58:15 +0900 | [diff] [blame] | 30 | public int netId = NETID_UNSET; |
Pierre Imai | 6b4e15b | 2016-04-07 12:21:05 +0900 | [diff] [blame] | 31 | // The list of transport types of the new default network, for example TRANSPORT_WIFI, as |
| 32 | // defined in NetworkCapabilities.java. |
Hugo Benichi | 1193a9c | 2017-10-19 14:58:15 +0900 | [diff] [blame] | 33 | public int[] transportTypes = new int[0]; |
Erik Kline | 48f12f2 | 2016-04-14 17:30:59 +0900 | [diff] [blame] | 34 | // The ID of the network that was the default before or NETID_UNSET if none. |
Hugo Benichi | 1193a9c | 2017-10-19 14:58:15 +0900 | [diff] [blame] | 35 | public int prevNetId = NETID_UNSET; |
Erik Kline | 48f12f2 | 2016-04-14 17:30:59 +0900 | [diff] [blame] | 36 | // Whether the previous network had IPv4/IPv6 connectivity. |
Hugo Benichi | 1193a9c | 2017-10-19 14:58:15 +0900 | [diff] [blame] | 37 | public boolean prevIPv4; |
| 38 | public boolean prevIPv6; |
Pierre Imai | 55618be | 2016-02-19 15:25:54 +0900 | [diff] [blame] | 39 | |
Hugo Benichi | 5df9d72 | 2016-04-25 17:16:35 +0900 | [diff] [blame] | 40 | @Override |
| 41 | public String toString() { |
Hugo Benichi | 1193a9c | 2017-10-19 14:58:15 +0900 | [diff] [blame] | 42 | String prevNetwork = String.valueOf(prevNetId); |
| 43 | String newNetwork = String.valueOf(netId); |
| 44 | if (prevNetId != 0) { |
| 45 | prevNetwork += ":" + ipSupport(); |
| 46 | } |
| 47 | if (netId != 0) { |
| 48 | newNetwork += ":" + NetworkCapabilities.transportNamesOf(transportTypes); |
| 49 | } |
| 50 | return String.format("DefaultNetworkEvent(%s -> %s)", prevNetwork, newNetwork); |
Hugo Benichi | 1654b1d | 2016-05-24 11:50:31 +0900 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | private String ipSupport() { |
| 54 | if (prevIPv4 && prevIPv6) { |
Hugo Benichi | 1193a9c | 2017-10-19 14:58:15 +0900 | [diff] [blame] | 55 | return "IPv4v6"; |
Hugo Benichi | 1654b1d | 2016-05-24 11:50:31 +0900 | [diff] [blame] | 56 | } |
| 57 | if (prevIPv6) { |
| 58 | return "IPv6"; |
| 59 | } |
| 60 | if (prevIPv4) { |
| 61 | return "IPv4"; |
| 62 | } |
| 63 | return "NONE"; |
Hugo Benichi | 5df9d72 | 2016-04-25 17:16:35 +0900 | [diff] [blame] | 64 | } |
Hugo Benichi | cfddd68 | 2016-05-31 16:28:06 +0900 | [diff] [blame] | 65 | } |