blob: abf99a339f880c180a11f7e36e1b160bc0e7db30 [file] [log] [blame]
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -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
Chia-chi Yeh7b0b8342011-06-17 14:34:11 -070019import android.app.PendingIntent;
20import android.content.Context;
21import android.content.Intent;
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -070022import android.os.Parcel;
23import android.os.Parcelable;
Chad Brubaker4ca19e82013-06-14 11:16:51 -070024import android.net.RouteInfo;
25import android.net.LinkAddress;
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -070026
Jeff Sharkey899223b2012-08-04 15:24:58 -070027import com.android.internal.util.Preconditions;
28
Chad Brubaker4ca19e82013-06-14 11:16:51 -070029import java.net.InetAddress;
Chia-chi Yeh8909b102011-07-01 01:09:42 -070030import java.util.List;
Chad Brubaker4ca19e82013-06-14 11:16:51 -070031import java.util.ArrayList;
Chia-chi Yeh8909b102011-07-01 01:09:42 -070032
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -070033/**
34 * A simple container used to carry information in VpnBuilder, VpnDialogs,
35 * and com.android.server.connectivity.Vpn. Internal use only.
36 *
37 * @hide
38 */
39public class VpnConfig implements Parcelable {
40
Chia-chi Yehfcc1b412011-08-03 15:39:59 -070041 public static final String SERVICE_INTERFACE = "android.net.VpnService";
Chia-chi Yeh7b0b8342011-06-17 14:34:11 -070042
Chia-chi Yehdadc8572012-06-08 13:05:58 -070043 public static final String DIALOGS_PACKAGE = "com.android.vpndialogs";
44
Chia-chi Yehe9107902011-07-02 01:48:50 -070045 public static final String LEGACY_VPN = "[Legacy VPN]";
46
Chia-chi Yeh7b0b8342011-06-17 14:34:11 -070047 public static Intent getIntentForConfirmation() {
48 Intent intent = new Intent();
Chia-chi Yehdadc8572012-06-08 13:05:58 -070049 intent.setClassName(DIALOGS_PACKAGE, DIALOGS_PACKAGE + ".ConfirmDialog");
Chia-chi Yeh7b0b8342011-06-17 14:34:11 -070050 return intent;
51 }
52
Chia-chi Yeh2e467642011-07-04 03:23:12 -070053 public static PendingIntent getIntentForStatusPanel(Context context, VpnConfig config) {
Jeff Sharkey899223b2012-08-04 15:24:58 -070054 Preconditions.checkNotNull(config);
55
Chia-chi Yeh7b0b8342011-06-17 14:34:11 -070056 Intent intent = new Intent();
Chia-chi Yehdadc8572012-06-08 13:05:58 -070057 intent.setClassName(DIALOGS_PACKAGE, DIALOGS_PACKAGE + ".ManageDialog");
Chia-chi Yeh7b0b8342011-06-17 14:34:11 -070058 intent.putExtra("config", config);
59 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY |
60 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Jeff Sharkey899223b2012-08-04 15:24:58 -070061 return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
Chia-chi Yeh7b0b8342011-06-17 14:34:11 -070062 }
63
Chia-chi Yehfcc1b412011-08-03 15:39:59 -070064 public String user;
Chia-chi Yeh34e78132011-07-03 03:07:07 -070065 public String interfaze;
66 public String session;
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -070067 public int mtu = -1;
Chad Brubaker4ca19e82013-06-14 11:16:51 -070068 public List<LinkAddress> addresses = new ArrayList<LinkAddress>();
69 public List<RouteInfo> routes = new ArrayList<RouteInfo>();
Chia-chi Yeh8909b102011-07-01 01:09:42 -070070 public List<String> dnsServers;
71 public List<String> searchDomains;
Chia-chi Yeh34e78132011-07-03 03:07:07 -070072 public PendingIntent configureIntent;
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -070073 public long startTime = -1;
Jeff Sharkey899223b2012-08-04 15:24:58 -070074 public boolean legacy;
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -070075
Chad Brubaker4ca19e82013-06-14 11:16:51 -070076 public void addLegacyRoutes(String routesStr) {
77 if (routesStr.trim().equals("")) {
78 return;
79 }
80 String[] routes = routesStr.trim().split(" ");
81 for (String route : routes) {
82 //each route is ip/prefix
83 String[] split = route.split("/");
84 RouteInfo info = new RouteInfo(new LinkAddress
85 (InetAddress.parseNumericAddress(split[0]), Integer.parseInt(split[1])), null);
86 this.routes.add(info);
87 }
88 }
89
90 public void addLegacyAddresses(String addressesStr) {
91 if (addressesStr.trim().equals("")) {
92 return;
93 }
94 String[] addresses = addressesStr.trim().split(" ");
95 for (String address : addresses) {
96 //each address is ip/prefix
97 String[] split = address.split("/");
98 LinkAddress addr = new LinkAddress(InetAddress.parseNumericAddress(split[0]),
99 Integer.parseInt(split[1]));
100 this.addresses.add(addr);
101 }
102 }
103
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -0700104 @Override
105 public int describeContents() {
106 return 0;
107 }
108
109 @Override
110 public void writeToParcel(Parcel out, int flags) {
Chia-chi Yehfcc1b412011-08-03 15:39:59 -0700111 out.writeString(user);
Chia-chi Yeh34e78132011-07-03 03:07:07 -0700112 out.writeString(interfaze);
113 out.writeString(session);
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -0700114 out.writeInt(mtu);
Chad Brubaker4ca19e82013-06-14 11:16:51 -0700115 out.writeTypedList(addresses);
116 out.writeTypedList(routes);
Chia-chi Yeh8909b102011-07-01 01:09:42 -0700117 out.writeStringList(dnsServers);
118 out.writeStringList(searchDomains);
Chia-chi Yeh34e78132011-07-03 03:07:07 -0700119 out.writeParcelable(configureIntent, flags);
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -0700120 out.writeLong(startTime);
Jeff Sharkey899223b2012-08-04 15:24:58 -0700121 out.writeInt(legacy ? 1 : 0);
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -0700122 }
123
124 public static final Parcelable.Creator<VpnConfig> CREATOR =
125 new Parcelable.Creator<VpnConfig>() {
126 @Override
127 public VpnConfig createFromParcel(Parcel in) {
128 VpnConfig config = new VpnConfig();
Chia-chi Yehfcc1b412011-08-03 15:39:59 -0700129 config.user = in.readString();
Chia-chi Yeh34e78132011-07-03 03:07:07 -0700130 config.interfaze = in.readString();
131 config.session = in.readString();
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -0700132 config.mtu = in.readInt();
Chad Brubaker4ca19e82013-06-14 11:16:51 -0700133 in.readTypedList(config.addresses, LinkAddress.CREATOR);
134 in.readTypedList(config.routes, RouteInfo.CREATOR);
Chia-chi Yeh8909b102011-07-01 01:09:42 -0700135 config.dnsServers = in.createStringArrayList();
136 config.searchDomains = in.createStringArrayList();
Chia-chi Yeh34e78132011-07-03 03:07:07 -0700137 config.configureIntent = in.readParcelable(null);
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -0700138 config.startTime = in.readLong();
Jeff Sharkey899223b2012-08-04 15:24:58 -0700139 config.legacy = in.readInt() != 0;
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -0700140 return config;
141 }
142
143 @Override
144 public VpnConfig[] newArray(int size) {
145 return new VpnConfig[size];
146 }
147 };
148}