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