blob: 0d00f411dbc90639f84f14f96d2e9a91181c77b6 [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
Chad Brubaker4ca19e82013-06-14 11:16:51 -070028import java.net.InetAddress;
Chia-chi Yeh8909b102011-07-01 01:09:42 -070029import java.util.List;
Chad Brubaker4ca19e82013-06-14 11:16:51 -070030import java.util.ArrayList;
Chia-chi Yeh8909b102011-07-01 01:09:42 -070031
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -070032/**
33 * A simple container used to carry information in VpnBuilder, VpnDialogs,
34 * and com.android.server.connectivity.Vpn. Internal use only.
35 *
36 * @hide
37 */
38public class VpnConfig implements Parcelable {
39
Chia-chi Yehfcc1b412011-08-03 15:39:59 -070040 public static final String SERVICE_INTERFACE = "android.net.VpnService";
Chia-chi Yeh7b0b8342011-06-17 14:34:11 -070041
Chia-chi Yehdadc8572012-06-08 13:05:58 -070042 public static final String DIALOGS_PACKAGE = "com.android.vpndialogs";
43
Chia-chi Yehe9107902011-07-02 01:48:50 -070044 public static final String LEGACY_VPN = "[Legacy VPN]";
45
Chia-chi Yeh7b0b8342011-06-17 14:34:11 -070046 public static Intent getIntentForConfirmation() {
47 Intent intent = new Intent();
Chia-chi Yehdadc8572012-06-08 13:05:58 -070048 intent.setClassName(DIALOGS_PACKAGE, DIALOGS_PACKAGE + ".ConfirmDialog");
Chia-chi Yeh7b0b8342011-06-17 14:34:11 -070049 return intent;
50 }
51
Chad Brubakerbf6ff2c2013-07-16 18:59:12 -070052 public static PendingIntent getIntentForStatusPanel(Context context) {
Chia-chi Yeh7b0b8342011-06-17 14:34:11 -070053 Intent intent = new Intent();
Chia-chi Yehdadc8572012-06-08 13:05:58 -070054 intent.setClassName(DIALOGS_PACKAGE, DIALOGS_PACKAGE + ".ManageDialog");
Chia-chi Yeh7b0b8342011-06-17 14:34:11 -070055 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY |
56 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Chad Brubakerbf6ff2c2013-07-16 18:59:12 -070057 return PendingIntent.getActivityAsUser(context, 0, intent, 0, null, UserHandle.CURRENT);
Chia-chi Yeh7b0b8342011-06-17 14:34:11 -070058 }
59
Chia-chi Yehfcc1b412011-08-03 15:39:59 -070060 public String user;
Chia-chi Yeh34e78132011-07-03 03:07:07 -070061 public String interfaze;
62 public String session;
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -070063 public int mtu = -1;
Chad Brubaker4ca19e82013-06-14 11:16:51 -070064 public List<LinkAddress> addresses = new ArrayList<LinkAddress>();
65 public List<RouteInfo> routes = new ArrayList<RouteInfo>();
Chia-chi Yeh8909b102011-07-01 01:09:42 -070066 public List<String> dnsServers;
67 public List<String> searchDomains;
Chia-chi Yeh34e78132011-07-03 03:07:07 -070068 public PendingIntent configureIntent;
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -070069 public long startTime = -1;
Jeff Sharkey899223b2012-08-04 15:24:58 -070070 public boolean legacy;
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -070071
Chad Brubaker4ca19e82013-06-14 11:16:51 -070072 public void addLegacyRoutes(String routesStr) {
73 if (routesStr.trim().equals("")) {
74 return;
75 }
76 String[] routes = routesStr.trim().split(" ");
77 for (String route : routes) {
78 //each route is ip/prefix
79 String[] split = route.split("/");
80 RouteInfo info = new RouteInfo(new LinkAddress
81 (InetAddress.parseNumericAddress(split[0]), Integer.parseInt(split[1])), null);
82 this.routes.add(info);
83 }
84 }
85
86 public void addLegacyAddresses(String addressesStr) {
87 if (addressesStr.trim().equals("")) {
88 return;
89 }
90 String[] addresses = addressesStr.trim().split(" ");
91 for (String address : addresses) {
92 //each address is ip/prefix
93 String[] split = address.split("/");
94 LinkAddress addr = new LinkAddress(InetAddress.parseNumericAddress(split[0]),
95 Integer.parseInt(split[1]));
96 this.addresses.add(addr);
97 }
98 }
99
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -0700100 @Override
101 public int describeContents() {
102 return 0;
103 }
104
105 @Override
106 public void writeToParcel(Parcel out, int flags) {
Chia-chi Yehfcc1b412011-08-03 15:39:59 -0700107 out.writeString(user);
Chia-chi Yeh34e78132011-07-03 03:07:07 -0700108 out.writeString(interfaze);
109 out.writeString(session);
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -0700110 out.writeInt(mtu);
Chad Brubaker4ca19e82013-06-14 11:16:51 -0700111 out.writeTypedList(addresses);
112 out.writeTypedList(routes);
Chia-chi Yeh8909b102011-07-01 01:09:42 -0700113 out.writeStringList(dnsServers);
114 out.writeStringList(searchDomains);
Chia-chi Yeh34e78132011-07-03 03:07:07 -0700115 out.writeParcelable(configureIntent, flags);
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -0700116 out.writeLong(startTime);
Jeff Sharkey899223b2012-08-04 15:24:58 -0700117 out.writeInt(legacy ? 1 : 0);
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -0700118 }
119
120 public static final Parcelable.Creator<VpnConfig> CREATOR =
121 new Parcelable.Creator<VpnConfig>() {
122 @Override
123 public VpnConfig createFromParcel(Parcel in) {
124 VpnConfig config = new VpnConfig();
Chia-chi Yehfcc1b412011-08-03 15:39:59 -0700125 config.user = in.readString();
Chia-chi Yeh34e78132011-07-03 03:07:07 -0700126 config.interfaze = in.readString();
127 config.session = in.readString();
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -0700128 config.mtu = in.readInt();
Chad Brubaker4ca19e82013-06-14 11:16:51 -0700129 in.readTypedList(config.addresses, LinkAddress.CREATOR);
130 in.readTypedList(config.routes, RouteInfo.CREATOR);
Chia-chi Yeh8909b102011-07-01 01:09:42 -0700131 config.dnsServers = in.createStringArrayList();
132 config.searchDomains = in.createStringArrayList();
Chia-chi Yeh34e78132011-07-03 03:07:07 -0700133 config.configureIntent = in.readParcelable(null);
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -0700134 config.startTime = in.readLong();
Jeff Sharkey899223b2012-08-04 15:24:58 -0700135 config.legacy = in.readInt() != 0;
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -0700136 return config;
137 }
138
139 @Override
140 public VpnConfig[] newArray(int size) {
141 return new VpnConfig[size];
142 }
143 };
144}