VpnConfig.java revision 7b0b834c3d12564c44ac134879a6dbc70e74be6e
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 26/** 27 * A simple container used to carry information in VpnBuilder, VpnDialogs, 28 * and com.android.server.connectivity.Vpn. Internal use only. 29 * 30 * @hide 31 */ 32public class VpnConfig implements Parcelable { 33 34 public static final String ACTION_VPN_REVOKED = "android.net.vpn.action.REVOKED"; 35 36 public static void enforceCallingPackage(String packageName) { 37 if (!"com.android.vpndialogs".equals(packageName)) { 38 throw new SecurityException("Unauthorized Caller"); 39 } 40 } 41 42 public static Intent getIntentForConfirmation() { 43 Intent intent = new Intent(); 44 intent.setClassName("com.android.vpndialogs", "com.android.vpndialogs.ConfirmDialog"); 45 return intent; 46 } 47 48 public static PendingIntent getIntentForNotification(Context context, VpnConfig config) { 49 config.startTime = SystemClock.elapsedRealtime(); 50 Intent intent = new Intent(); 51 intent.setClassName("com.android.vpndialogs", "com.android.vpndialogs.ManageDialog"); 52 intent.putExtra("config", config); 53 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY | 54 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); 55 return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); 56 } 57 58 public String packageName; 59 public String sessionName; 60 public String interfaceName; 61 public String configureActivity; 62 public int mtu = -1; 63 public String addresses; 64 public String routes; 65 public String dnsServers; 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(packageName); 76 out.writeString(sessionName); 77 out.writeString(interfaceName); 78 out.writeString(configureActivity); 79 out.writeInt(mtu); 80 out.writeString(addresses); 81 out.writeString(routes); 82 out.writeString(dnsServers); 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.configureActivity = in.readString(); 95 config.mtu = in.readInt(); 96 config.addresses = in.readString(); 97 config.routes = in.readString(); 98 config.dnsServers = in.readString(); 99 config.startTime = in.readLong(); 100 return config; 101 } 102 103 @Override 104 public VpnConfig[] newArray(int size) { 105 return new VpnConfig[size]; 106 } 107 }; 108} 109