blob: f812ad6ae325f62e7d186aee00cf8d4bd8317090 [file] [log] [blame]
Chia-chi Yeh2e467642011-07-04 03:23:12 -07001/*
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
17package com.android.internal.net;
18
19import android.app.PendingIntent;
Jeff Sharkey899223b2012-08-04 15:24:58 -070020import android.net.NetworkInfo;
Chia-chi Yeh2e467642011-07-04 03:23:12 -070021import android.os.Parcel;
22import android.os.Parcelable;
Jeff Sharkey899223b2012-08-04 15:24:58 -070023import android.util.Log;
Chia-chi Yeh2e467642011-07-04 03:23:12 -070024
25/**
26 * A simple container used to carry information of the ongoing legacy VPN.
27 * Internal use only.
28 *
29 * @hide
30 */
31public class LegacyVpnInfo implements Parcelable {
Jeff Sharkey899223b2012-08-04 15:24:58 -070032 private static final String TAG = "LegacyVpnInfo";
33
Chia-chi Yeh2e467642011-07-04 03:23:12 -070034 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 Yeh2e467642011-07-04 03:23:12 -070043
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 Yeh2e467642011-07-04 03:23:12 -070053 }
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 Yeh2e467642011-07-04 03:23:12 -070062 return info;
63 }
64
65 @Override
66 public LegacyVpnInfo[] newArray(int size) {
67 return new LegacyVpnInfo[size];
68 }
69 };
Jeff Sharkey899223b2012-08-04 15:24:58 -070070
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 Yeh2e467642011-07-04 03:23:12 -070091}