| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.internal.net; |
| 18 |
|
| 19 |
import android.app.PendingIntent; |
| 20 |
import android.compat.annotation.UnsupportedAppUsage; |
| 21 |
import android.net.NetworkInfo; |
| 22 |
import android.os.Parcel; |
| 23 |
import android.os.Parcelable; |
| 24 |
import android.util.Log; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public class LegacyVpnInfo implements Parcelable { |
| 33 |
private static final String TAG = "LegacyVpnInfo"; |
| 34 |
|
| 35 |
public static final int STATE_DISCONNECTED = 0; |
| 36 |
public static final int STATE_INITIALIZING = 1; |
| 37 |
public static final int STATE_CONNECTING = 2; |
| 38 |
public static final int STATE_CONNECTED = 3; |
| 39 |
public static final int STATE_TIMEOUT = 4; |
| 40 |
public static final int STATE_FAILED = 5; |
| 41 |
|
| 42 |
@UnsupportedAppUsage |
| 43 |
public String key; |
| 44 |
@UnsupportedAppUsage |
| 45 |
public int state = -1; |
| 46 |
public PendingIntent intent; |
| 47 |
|
| 48 |
@UnsupportedAppUsage |
| 49 |
public LegacyVpnInfo() { |
| 50 |
} |
| 51 |
|
| 52 |
@Override |
| 53 |
public int describeContents() { |
| 54 |
return 0; |
| 55 |
} |
| 56 |
|
| 57 |
@Override |
| 58 |
public void writeToParcel(Parcel out, int flags) { |
| 59 |
out.writeString(key); |
| 60 |
out.writeInt(state); |
| 61 |
out.writeParcelable(intent, flags); |
| 62 |
} |
| 63 |
|
| 64 |
@UnsupportedAppUsage |
| 65 |
public static final Parcelable.Creator<LegacyVpnInfo> CREATOR = |
| 66 |
new Parcelable.Creator<LegacyVpnInfo>() { |
| 67 |
@Override |
| 68 |
public LegacyVpnInfo createFromParcel(Parcel in) { |
| 69 |
LegacyVpnInfo info = new LegacyVpnInfo(); |
| 70 |
info.key = in.readString(); |
| 71 |
info.state = in.readInt(); |
| 72 |
info.intent = in.readParcelable(null, android.app.PendingIntent.class); |
| 73 |
return info; |
| 74 |
} |
| 75 |
|
| 76 |
@Override |
| 77 |
public LegacyVpnInfo[] newArray(int size) { |
| 78 |
return new LegacyVpnInfo[size]; |
| 79 |
} |
| 80 |
}; |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
public static int stateFromNetworkInfo(NetworkInfo.DetailedState state) { |
| 87 |
switch (state) { |
| 88 |
case CONNECTING: |
| 89 |
return STATE_CONNECTING; |
| 90 |
case CONNECTED: |
| 91 |
return STATE_CONNECTED; |
| 92 |
case DISCONNECTED: |
| 93 |
return STATE_DISCONNECTED; |
| 94 |
case FAILED: |
| 95 |
return STATE_FAILED; |
| 96 |
default: |
| 97 |
Log.w(TAG, "Unhandled state " + state + " ; treating as disconnected"); |
| 98 |
return STATE_DISCONNECTED; |
| 99 |
} |
| 100 |
} |
| 101 |
} |