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