blob: 98599d01873f025d125f4124ce9c7a454f565b1f [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 Brubakerbf6ff2c2013-07-16 18:59:12 -070024import android.os.UserHandle;
Chad Brubaker4ca19e82013-06-14 11:16:51 -070025import android.net.RouteInfo;
26import android.net.LinkAddress;
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -070027
Jeff Sharkey899223b2012-08-04 15:24:58 -070028import com.android.internal.util.Preconditions;
29
Chad Brubaker4ca19e82013-06-14 11:16:51 -070030import java.net.InetAddress;
Chia-chi Yeh8909b102011-07-01 01:09:42 -070031import java.util.List;
Chad Brubaker4ca19e82013-06-14 11:16:51 -070032import java.util.ArrayList;
Chia-chi Yeh8909b102011-07-01 01:09:42 -070033
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -070034/**
35 * A simple container used to carry information in VpnBuilder, VpnDialogs,
36 * and com.android.server.connectivity.Vpn. Internal use only.
37 *
38 * @hide
39 */
40public class VpnConfig implements Parcelable {
41
Chia-chi Yehfcc1b412011-08-03 15:39:59 -070042 public static final String SERVICE_INTERFACE = "android.net.VpnService";
Chia-chi Yeh7b0b8342011-06-17 14:34:11 -070043
Chia-chi Yehdadc8572012-06-08 13:05:58 -070044 public static final String DIALOGS_PACKAGE = "com.android.vpndialogs";
45
Chia-chi Yehe9107902011-07-02 01:48:50 -070046 public static final String LEGACY_VPN = "[Legacy VPN]";
47
Chia-chi Yeh7b0b8342011-06-17 14:34:11 -070048 public static Intent getIntentForConfirmation() {
49 Intent intent = new Intent();
Chia-chi Yehdadc8572012-06-08 13:05:58 -070050 intent.setClassName(DIALOGS_PACKAGE, DIALOGS_PACKAGE + ".ConfirmDialog");
Chia-chi Yeh7b0b8342011-06-17 14:34:11 -070051 return intent;
52 }
53
Chad Brubakerbf6ff2c2013-07-16 18:59:12 -070054 public static PendingIntent getIntentForStatusPanel(Context context) {
Chia-chi Yeh7b0b8342011-06-17 14:34:11 -070055 Intent intent = new Intent();
Chia-chi Yehdadc8572012-06-08 13:05:58 -070056 intent.setClassName(DIALOGS_PACKAGE, DIALOGS_PACKAGE + ".ManageDialog");
Chia-chi Yeh7b0b8342011-06-17 14:34:11 -070057 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY |
58 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Chad Brubakerbf6ff2c2013-07-16 18:59:12 -070059 return PendingIntent.getActivityAsUser(context, 0, intent, 0, null, UserHandle.CURRENT);
Chia-chi Yeh7b0b8342011-06-17 14:34:11 -070060 }
61
Chia-chi Yehfcc1b412011-08-03 15:39:59 -070062 public String user;
Chia-chi Yeh34e78132011-07-03 03:07:07 -070063 public String interfaze;
64 public String session;
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -070065 public int mtu = -1;
Chad Brubaker4ca19e82013-06-14 11:16:51 -070066 public List<LinkAddress> addresses = new ArrayList<LinkAddress>();
67 public List<RouteInfo> routes = new ArrayList<RouteInfo>();
Chia-chi Yeh8909b102011-07-01 01:09:42 -070068 public List<String> dnsServers;
69 public List<String> searchDomains;
Chia-chi Yeh34e78132011-07-03 03:07:07 -070070 public PendingIntent configureIntent;
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -070071 public long startTime = -1;
Jeff Sharkey899223b2012-08-04 15:24:58 -070072 public boolean legacy;
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -070073
Chad Brubaker4ca19e82013-06-14 11:16:51 -070074 public void addLegacyRoutes(String routesStr) {
75 if (routesStr.trim().equals("")) {
76 return;
77 }
78 String[] routes = routesStr.trim().split(" ");
79 for (String route : routes) {
80 //each route is ip/prefix
81 String[] split = route.split("/");
82 RouteInfo info = new RouteInfo(new LinkAddress
83 (InetAddress.parseNumericAddress(split[0]), Integer.parseInt(split[1])), null);
84 this.routes.add(info);
85 }
86 }
87
88 public void addLegacyAddresses(String addressesStr) {
89 if (addressesStr.trim().equals("")) {
90 return;
91 }
92 String[] addresses = addressesStr.trim().split(" ");
93 for (String address : addresses) {
94 //each address is ip/prefix
95 String[] split = address.split("/");
96 LinkAddress addr = new LinkAddress(InetAddress.parseNumericAddress(split[0]),
97 Integer.parseInt(split[1]));
98 this.addresses.add(addr);
99 }
100 }
101
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -0700102 @Override
103 public int describeContents() {
104 return 0;
105 }
106
107 @Override
108 public void writeToParcel(Parcel out, int flags) {
Chia-chi Yehfcc1b412011-08-03 15:39:59 -0700109 out.writeString(user);
Chia-chi Yeh34e78132011-07-03 03:07:07 -0700110 out.writeString(interfaze);
111 out.writeString(session);
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -0700112 out.writeInt(mtu);
Chad Brubaker4ca19e82013-06-14 11:16:51 -0700113 out.writeTypedList(addresses);
114 out.writeTypedList(routes);
Chia-chi Yeh8909b102011-07-01 01:09:42 -0700115 out.writeStringList(dnsServers);
116 out.writeStringList(searchDomains);
Chia-chi Yeh34e78132011-07-03 03:07:07 -0700117 out.writeParcelable(configureIntent, flags);
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -0700118 out.writeLong(startTime);
Jeff Sharkey899223b2012-08-04 15:24:58 -0700119 out.writeInt(legacy ? 1 : 0);
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -0700120 }
121
122 public static final Parcelable.Creator<VpnConfig> CREATOR =
123 new Parcelable.Creator<VpnConfig>() {
124 @Override
125 public VpnConfig createFromParcel(Parcel in) {
126 VpnConfig config = new VpnConfig();
Chia-chi Yehfcc1b412011-08-03 15:39:59 -0700127 config.user = in.readString();
Chia-chi Yeh34e78132011-07-03 03:07:07 -0700128 config.interfaze = in.readString();
129 config.session = in.readString();
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -0700130 config.mtu = in.readInt();
Chad Brubaker4ca19e82013-06-14 11:16:51 -0700131 in.readTypedList(config.addresses, LinkAddress.CREATOR);
132 in.readTypedList(config.routes, RouteInfo.CREATOR);
Chia-chi Yeh8909b102011-07-01 01:09:42 -0700133 config.dnsServers = in.createStringArrayList();
134 config.searchDomains = in.createStringArrayList();
Chia-chi Yeh34e78132011-07-03 03:07:07 -0700135 config.configureIntent = in.readParcelable(null);
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -0700136 config.startTime = in.readLong();
Jeff Sharkey899223b2012-08-04 15:24:58 -0700137 config.legacy = in.readInt() != 0;
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -0700138 return config;
139 }
140
141 @Override
142 public VpnConfig[] newArray(int size) {
143 return new VpnConfig[size];
144 }
145 };
146}