VpnConfig.java revision e9107901ae264de4ff5603d3cfc63a03ca4117d4
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; 24import android.os.SystemClock; 25 26import java.util.List; 27 28/** 29 * A simple container used to carry information in VpnBuilder, VpnDialogs, 30 * and com.android.server.connectivity.Vpn. Internal use only. 31 * 32 * @hide 33 */ 34public class VpnConfig implements Parcelable { 35 36 public static final String ACTION_VPN_REVOKED = "android.net.vpn.action.REVOKED"; 37 38 public static final String LEGACY_VPN = "[Legacy VPN]"; 39 40 public static Intent getIntentForConfirmation() { 41 Intent intent = new Intent(); 42 intent.setClassName("com.android.vpndialogs", "com.android.vpndialogs.ConfirmDialog"); 43 return intent; 44 } 45 46 public static PendingIntent getIntentForNotification(Context context, VpnConfig config) { 47 config.startTime = SystemClock.elapsedRealtime(); 48 Intent intent = new Intent(); 49 intent.setClassName("com.android.vpndialogs", "com.android.vpndialogs.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, PendingIntent.FLAG_CANCEL_CURRENT); 54 } 55 56 public String packageName; 57 public String sessionName; 58 public String interfaceName; 59 public PendingIntent configureIntent; 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 long startTime = -1; 66 67 @Override 68 public int describeContents() { 69 return 0; 70 } 71 72 @Override 73 public void writeToParcel(Parcel out, int flags) { 74 out.writeString(packageName); 75 out.writeString(sessionName); 76 out.writeString(interfaceName); 77 out.writeParcelable(configureIntent, flags); 78 out.writeInt(mtu); 79 out.writeString(addresses); 80 out.writeString(routes); 81 out.writeStringList(dnsServers); 82 out.writeStringList(searchDomains); 83 out.writeLong(startTime); 84 } 85 86 public static final Parcelable.Creator<VpnConfig> CREATOR = 87 new Parcelable.Creator<VpnConfig>() { 88 @Override 89 public VpnConfig createFromParcel(Parcel in) { 90 VpnConfig config = new VpnConfig(); 91 config.packageName = in.readString(); 92 config.sessionName = in.readString(); 93 config.interfaceName = in.readString(); 94 config.configureIntent = in.readParcelable(null); 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.startTime = in.readLong(); 101 return config; 102 } 103 104 @Override 105 public VpnConfig[] newArray(int size) { 106 return new VpnConfig[size]; 107 } 108 }; 109} 110