blob: 956653b7da5d3b76c5a73decb6a637f9c9c6eb0a [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;
24
Jeff Sharkey899223b2012-08-04 15:24:58 -070025import com.android.internal.util.Preconditions;
26
Chia-chi Yeh8909b102011-07-01 01:09:42 -070027import java.util.List;
28
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -070029/**
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 */
35public class VpnConfig implements Parcelable {
36
Chia-chi Yehfcc1b412011-08-03 15:39:59 -070037 public static final String SERVICE_INTERFACE = "android.net.VpnService";
Chia-chi Yeh7b0b8342011-06-17 14:34:11 -070038
Chia-chi Yehdadc8572012-06-08 13:05:58 -070039 public static final String DIALOGS_PACKAGE = "com.android.vpndialogs";
40
Chia-chi Yehe9107902011-07-02 01:48:50 -070041 public static final String LEGACY_VPN = "[Legacy VPN]";
42
Chia-chi Yeh7b0b8342011-06-17 14:34:11 -070043 public static Intent getIntentForConfirmation() {
44 Intent intent = new Intent();
Chia-chi Yehdadc8572012-06-08 13:05:58 -070045 intent.setClassName(DIALOGS_PACKAGE, DIALOGS_PACKAGE + ".ConfirmDialog");
Chia-chi Yeh7b0b8342011-06-17 14:34:11 -070046 return intent;
47 }
48
Chia-chi Yeh2e467642011-07-04 03:23:12 -070049 public static PendingIntent getIntentForStatusPanel(Context context, VpnConfig config) {
Jeff Sharkey899223b2012-08-04 15:24:58 -070050 Preconditions.checkNotNull(config);
51
Chia-chi Yeh7b0b8342011-06-17 14:34:11 -070052 Intent intent = new Intent();
Chia-chi Yehdadc8572012-06-08 13:05:58 -070053 intent.setClassName(DIALOGS_PACKAGE, DIALOGS_PACKAGE + ".ManageDialog");
Chia-chi Yeh7b0b8342011-06-17 14:34:11 -070054 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 Sharkey899223b2012-08-04 15:24:58 -070057 return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_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;
64 public String addresses;
65 public String routes;
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
72 @Override
73 public int describeContents() {
74 return 0;
75 }
76
77 @Override
78 public void writeToParcel(Parcel out, int flags) {
Chia-chi Yehfcc1b412011-08-03 15:39:59 -070079 out.writeString(user);
Chia-chi Yeh34e78132011-07-03 03:07:07 -070080 out.writeString(interfaze);
81 out.writeString(session);
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -070082 out.writeInt(mtu);
83 out.writeString(addresses);
84 out.writeString(routes);
Chia-chi Yeh8909b102011-07-01 01:09:42 -070085 out.writeStringList(dnsServers);
86 out.writeStringList(searchDomains);
Chia-chi Yeh34e78132011-07-03 03:07:07 -070087 out.writeParcelable(configureIntent, flags);
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -070088 out.writeLong(startTime);
Jeff Sharkey899223b2012-08-04 15:24:58 -070089 out.writeInt(legacy ? 1 : 0);
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -070090 }
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 Yehfcc1b412011-08-03 15:39:59 -070097 config.user = in.readString();
Chia-chi Yeh34e78132011-07-03 03:07:07 -070098 config.interfaze = in.readString();
99 config.session = in.readString();
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -0700100 config.mtu = in.readInt();
101 config.addresses = in.readString();
102 config.routes = in.readString();
Chia-chi Yeh8909b102011-07-01 01:09:42 -0700103 config.dnsServers = in.createStringArrayList();
104 config.searchDomains = in.createStringArrayList();
Chia-chi Yeh34e78132011-07-03 03:07:07 -0700105 config.configureIntent = in.readParcelable(null);
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -0700106 config.startTime = in.readLong();
Jeff Sharkey899223b2012-08-04 15:24:58 -0700107 config.legacy = in.readInt() != 0;
Chia-chi Yeh04ba25c2011-06-15 17:07:27 -0700108 return config;
109 }
110
111 @Override
112 public VpnConfig[] newArray(int size) {
113 return new VpnConfig[size];
114 }
115 };
116}