Chia-chi Yeh | 2e46764 | 2011-07-04 03:23:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 com.android.internal.net; |
| 18 | |
| 19 | import android.app.PendingIntent; |
Jeff Sharkey | 899223b | 2012-08-04 15:24:58 -0700 | [diff] [blame] | 20 | import android.net.NetworkInfo; |
Chia-chi Yeh | 2e46764 | 2011-07-04 03:23:12 -0700 | [diff] [blame] | 21 | import android.os.Parcel; |
| 22 | import android.os.Parcelable; |
Jeff Sharkey | 899223b | 2012-08-04 15:24:58 -0700 | [diff] [blame] | 23 | import android.util.Log; |
Chia-chi Yeh | 2e46764 | 2011-07-04 03:23:12 -0700 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * A simple container used to carry information of the ongoing legacy VPN. |
| 27 | * Internal use only. |
| 28 | * |
| 29 | * @hide |
| 30 | */ |
| 31 | public class LegacyVpnInfo implements Parcelable { |
Jeff Sharkey | 899223b | 2012-08-04 15:24:58 -0700 | [diff] [blame] | 32 | private static final String TAG = "LegacyVpnInfo"; |
| 33 | |
Chia-chi Yeh | 2e46764 | 2011-07-04 03:23:12 -0700 | [diff] [blame] | 34 | public static final int STATE_DISCONNECTED = 0; |
| 35 | public static final int STATE_INITIALIZING = 1; |
| 36 | public static final int STATE_CONNECTING = 2; |
| 37 | public static final int STATE_CONNECTED = 3; |
| 38 | public static final int STATE_TIMEOUT = 4; |
| 39 | public static final int STATE_FAILED = 5; |
| 40 | |
| 41 | public String key; |
| 42 | public int state = -1; |
Chia-chi Yeh | 2e46764 | 2011-07-04 03:23:12 -0700 | [diff] [blame] | 43 | |
| 44 | @Override |
| 45 | public int describeContents() { |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public void writeToParcel(Parcel out, int flags) { |
| 51 | out.writeString(key); |
| 52 | out.writeInt(state); |
Chia-chi Yeh | 2e46764 | 2011-07-04 03:23:12 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | public static final Parcelable.Creator<LegacyVpnInfo> CREATOR = |
| 56 | new Parcelable.Creator<LegacyVpnInfo>() { |
| 57 | @Override |
| 58 | public LegacyVpnInfo createFromParcel(Parcel in) { |
| 59 | LegacyVpnInfo info = new LegacyVpnInfo(); |
| 60 | info.key = in.readString(); |
| 61 | info.state = in.readInt(); |
Chia-chi Yeh | 2e46764 | 2011-07-04 03:23:12 -0700 | [diff] [blame] | 62 | return info; |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public LegacyVpnInfo[] newArray(int size) { |
| 67 | return new LegacyVpnInfo[size]; |
| 68 | } |
| 69 | }; |
Jeff Sharkey | 899223b | 2012-08-04 15:24:58 -0700 | [diff] [blame] | 70 | |
| 71 | /** |
| 72 | * Return best matching {@link LegacyVpnInfo} state based on given |
| 73 | * {@link NetworkInfo}. |
| 74 | */ |
| 75 | public static int stateFromNetworkInfo(NetworkInfo info) { |
| 76 | switch (info.getDetailedState()) { |
| 77 | case CONNECTING: |
| 78 | return STATE_CONNECTING; |
| 79 | case CONNECTED: |
| 80 | return STATE_CONNECTED; |
| 81 | case DISCONNECTED: |
| 82 | return STATE_DISCONNECTED; |
| 83 | case FAILED: |
| 84 | return STATE_FAILED; |
| 85 | default: |
| 86 | Log.w(TAG, "Unhandled state " + info.getDetailedState() |
| 87 | + " ; treating as disconnected"); |
| 88 | return STATE_DISCONNECTED; |
| 89 | } |
| 90 | } |
Chia-chi Yeh | 2e46764 | 2011-07-04 03:23:12 -0700 | [diff] [blame] | 91 | } |