Chia-chi Yeh | 04ba25c | 2011-06-15 17:07:27 -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 | |
Chia-chi Yeh | 7b0b834 | 2011-06-17 14:34:11 -0700 | [diff] [blame] | 19 | import android.app.PendingIntent; |
| 20 | import android.content.Context; |
| 21 | import android.content.Intent; |
Chia-chi Yeh | 04ba25c | 2011-06-15 17:07:27 -0700 | [diff] [blame] | 22 | import android.os.Parcel; |
| 23 | import android.os.Parcelable; |
| 24 | |
Jeff Sharkey | 899223b | 2012-08-04 15:24:58 -0700 | [diff] [blame] | 25 | import com.android.internal.util.Preconditions; |
| 26 | |
Chia-chi Yeh | 8909b10 | 2011-07-01 01:09:42 -0700 | [diff] [blame] | 27 | import java.util.List; |
| 28 | |
Chia-chi Yeh | 04ba25c | 2011-06-15 17:07:27 -0700 | [diff] [blame] | 29 | /** |
| 30 | * A simple container used to carry information in VpnBuilder, VpnDialogs, |
| 31 | * and com.android.server.connectivity.Vpn. Internal use only. |
| 32 | * |
| 33 | * @hide |
| 34 | */ |
| 35 | public class VpnConfig implements Parcelable { |
| 36 | |
Chia-chi Yeh | fcc1b41 | 2011-08-03 15:39:59 -0700 | [diff] [blame] | 37 | public static final String SERVICE_INTERFACE = "android.net.VpnService"; |
Chia-chi Yeh | 7b0b834 | 2011-06-17 14:34:11 -0700 | [diff] [blame] | 38 | |
Chia-chi Yeh | dadc857 | 2012-06-08 13:05:58 -0700 | [diff] [blame] | 39 | public static final String DIALOGS_PACKAGE = "com.android.vpndialogs"; |
| 40 | |
Chia-chi Yeh | e910790 | 2011-07-02 01:48:50 -0700 | [diff] [blame] | 41 | public static final String LEGACY_VPN = "[Legacy VPN]"; |
| 42 | |
Chia-chi Yeh | 7b0b834 | 2011-06-17 14:34:11 -0700 | [diff] [blame] | 43 | public static Intent getIntentForConfirmation() { |
| 44 | Intent intent = new Intent(); |
Chia-chi Yeh | dadc857 | 2012-06-08 13:05:58 -0700 | [diff] [blame] | 45 | intent.setClassName(DIALOGS_PACKAGE, DIALOGS_PACKAGE + ".ConfirmDialog"); |
Chia-chi Yeh | 7b0b834 | 2011-06-17 14:34:11 -0700 | [diff] [blame] | 46 | return intent; |
| 47 | } |
| 48 | |
Chia-chi Yeh | 2e46764 | 2011-07-04 03:23:12 -0700 | [diff] [blame] | 49 | public static PendingIntent getIntentForStatusPanel(Context context, VpnConfig config) { |
Jeff Sharkey | 899223b | 2012-08-04 15:24:58 -0700 | [diff] [blame] | 50 | Preconditions.checkNotNull(config); |
| 51 | |
Chia-chi Yeh | 7b0b834 | 2011-06-17 14:34:11 -0700 | [diff] [blame] | 52 | Intent intent = new Intent(); |
Chia-chi Yeh | dadc857 | 2012-06-08 13:05:58 -0700 | [diff] [blame] | 53 | intent.setClassName(DIALOGS_PACKAGE, DIALOGS_PACKAGE + ".ManageDialog"); |
Chia-chi Yeh | 7b0b834 | 2011-06-17 14:34:11 -0700 | [diff] [blame] | 54 | intent.putExtra("config", config); |
| 55 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY | |
| 56 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
Jeff Sharkey | 899223b | 2012-08-04 15:24:58 -0700 | [diff] [blame] | 57 | return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); |
Chia-chi Yeh | 7b0b834 | 2011-06-17 14:34:11 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Chia-chi Yeh | fcc1b41 | 2011-08-03 15:39:59 -0700 | [diff] [blame] | 60 | public String user; |
Chia-chi Yeh | 34e7813 | 2011-07-03 03:07:07 -0700 | [diff] [blame] | 61 | public String interfaze; |
| 62 | public String session; |
Chia-chi Yeh | 04ba25c | 2011-06-15 17:07:27 -0700 | [diff] [blame] | 63 | public int mtu = -1; |
| 64 | public String addresses; |
| 65 | public String routes; |
Chia-chi Yeh | 8909b10 | 2011-07-01 01:09:42 -0700 | [diff] [blame] | 66 | public List<String> dnsServers; |
| 67 | public List<String> searchDomains; |
Chia-chi Yeh | 34e7813 | 2011-07-03 03:07:07 -0700 | [diff] [blame] | 68 | public PendingIntent configureIntent; |
Chia-chi Yeh | 04ba25c | 2011-06-15 17:07:27 -0700 | [diff] [blame] | 69 | public long startTime = -1; |
Jeff Sharkey | 899223b | 2012-08-04 15:24:58 -0700 | [diff] [blame] | 70 | public boolean legacy; |
Chia-chi Yeh | 04ba25c | 2011-06-15 17:07:27 -0700 | [diff] [blame] | 71 | |
| 72 | @Override |
| 73 | public int describeContents() { |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public void writeToParcel(Parcel out, int flags) { |
Chia-chi Yeh | fcc1b41 | 2011-08-03 15:39:59 -0700 | [diff] [blame] | 79 | out.writeString(user); |
Chia-chi Yeh | 34e7813 | 2011-07-03 03:07:07 -0700 | [diff] [blame] | 80 | out.writeString(interfaze); |
| 81 | out.writeString(session); |
Chia-chi Yeh | 04ba25c | 2011-06-15 17:07:27 -0700 | [diff] [blame] | 82 | out.writeInt(mtu); |
| 83 | out.writeString(addresses); |
| 84 | out.writeString(routes); |
Chia-chi Yeh | 8909b10 | 2011-07-01 01:09:42 -0700 | [diff] [blame] | 85 | out.writeStringList(dnsServers); |
| 86 | out.writeStringList(searchDomains); |
Chia-chi Yeh | 34e7813 | 2011-07-03 03:07:07 -0700 | [diff] [blame] | 87 | out.writeParcelable(configureIntent, flags); |
Chia-chi Yeh | 04ba25c | 2011-06-15 17:07:27 -0700 | [diff] [blame] | 88 | out.writeLong(startTime); |
Jeff Sharkey | 899223b | 2012-08-04 15:24:58 -0700 | [diff] [blame] | 89 | out.writeInt(legacy ? 1 : 0); |
Chia-chi Yeh | 04ba25c | 2011-06-15 17:07:27 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | public static final Parcelable.Creator<VpnConfig> CREATOR = |
| 93 | new Parcelable.Creator<VpnConfig>() { |
| 94 | @Override |
| 95 | public VpnConfig createFromParcel(Parcel in) { |
| 96 | VpnConfig config = new VpnConfig(); |
Chia-chi Yeh | fcc1b41 | 2011-08-03 15:39:59 -0700 | [diff] [blame] | 97 | config.user = in.readString(); |
Chia-chi Yeh | 34e7813 | 2011-07-03 03:07:07 -0700 | [diff] [blame] | 98 | config.interfaze = in.readString(); |
| 99 | config.session = in.readString(); |
Chia-chi Yeh | 04ba25c | 2011-06-15 17:07:27 -0700 | [diff] [blame] | 100 | config.mtu = in.readInt(); |
| 101 | config.addresses = in.readString(); |
| 102 | config.routes = in.readString(); |
Chia-chi Yeh | 8909b10 | 2011-07-01 01:09:42 -0700 | [diff] [blame] | 103 | config.dnsServers = in.createStringArrayList(); |
| 104 | config.searchDomains = in.createStringArrayList(); |
Chia-chi Yeh | 34e7813 | 2011-07-03 03:07:07 -0700 | [diff] [blame] | 105 | config.configureIntent = in.readParcelable(null); |
Chia-chi Yeh | 04ba25c | 2011-06-15 17:07:27 -0700 | [diff] [blame] | 106 | config.startTime = in.readLong(); |
Jeff Sharkey | 899223b | 2012-08-04 15:24:58 -0700 | [diff] [blame] | 107 | config.legacy = in.readInt() != 0; |
Chia-chi Yeh | 04ba25c | 2011-06-15 17:07:27 -0700 | [diff] [blame] | 108 | return config; |
| 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public VpnConfig[] newArray(int size) { |
| 113 | return new VpnConfig[size]; |
| 114 | } |
| 115 | }; |
| 116 | } |