diff options
Diffstat (limited to 'vpn/java/android/net')
-rw-r--r-- | vpn/java/android/net/vpn/IVpnService.aidl | 43 | ||||
-rw-r--r-- | vpn/java/android/net/vpn/L2tpIpsecProfile.java | 65 | ||||
-rw-r--r-- | vpn/java/android/net/vpn/L2tpIpsecPskProfile.java | 54 | ||||
-rw-r--r-- | vpn/java/android/net/vpn/L2tpProfile.java | 68 | ||||
-rw-r--r-- | vpn/java/android/net/vpn/PptpProfile.java | 30 | ||||
-rw-r--r-- | vpn/java/android/net/vpn/VpnManager.java | 162 | ||||
-rw-r--r-- | vpn/java/android/net/vpn/VpnProfile.aidl | 19 | ||||
-rw-r--r-- | vpn/java/android/net/vpn/VpnProfile.java | 177 | ||||
-rw-r--r-- | vpn/java/android/net/vpn/VpnState.java | 33 | ||||
-rw-r--r-- | vpn/java/android/net/vpn/VpnType.java | 53 |
10 files changed, 704 insertions, 0 deletions
diff --git a/vpn/java/android/net/vpn/IVpnService.aidl b/vpn/java/android/net/vpn/IVpnService.aidl new file mode 100644 index 0000000..fedccb0 --- /dev/null +++ b/vpn/java/android/net/vpn/IVpnService.aidl @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2009, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.net.vpn; + +import android.net.vpn.VpnProfile; + +/** + * Interface to access a VPN service. + * {@hide} + */ +interface IVpnService { + /** + * Sets up the VPN connection. + * @param profile the profile object + * @param username the username for authentication + * @param password the corresponding password for authentication + */ + boolean connect(in VpnProfile profile, String username, String password); + + /** + * Tears down the VPN connection. + */ + void disconnect(); + + /** + * Makes the service broadcast the connectivity state. + */ + void checkStatus(in VpnProfile profile); +} diff --git a/vpn/java/android/net/vpn/L2tpIpsecProfile.java b/vpn/java/android/net/vpn/L2tpIpsecProfile.java new file mode 100644 index 0000000..4ae2dec --- /dev/null +++ b/vpn/java/android/net/vpn/L2tpIpsecProfile.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2009, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.net.vpn; + +import android.os.Parcel; + +/** + * The profile for certificate-based L2TP-over-IPSec type of VPN. + * {@hide} + */ +public class L2tpIpsecProfile extends L2tpProfile { + private static final long serialVersionUID = 1L; + + private String mUserCertificate; + private String mCaCertificate; + + @Override + public VpnType getType() { + return VpnType.L2TP_IPSEC; + } + + public void setCaCertificate(String name) { + mCaCertificate = name; + } + + public String getCaCertificate() { + return mCaCertificate; + } + + public void setUserCertificate(String name) { + mUserCertificate = name; + } + + public String getUserCertificate() { + return mUserCertificate; + } + + @Override + protected void readFromParcel(Parcel in) { + super.readFromParcel(in); + mCaCertificate = in.readString(); + mUserCertificate = in.readString(); + } + + @Override + public void writeToParcel(Parcel parcel, int flags) { + super.writeToParcel(parcel, flags); + parcel.writeString(mCaCertificate); + parcel.writeString(mUserCertificate); + } +} diff --git a/vpn/java/android/net/vpn/L2tpIpsecPskProfile.java b/vpn/java/android/net/vpn/L2tpIpsecPskProfile.java new file mode 100644 index 0000000..7a03018 --- /dev/null +++ b/vpn/java/android/net/vpn/L2tpIpsecPskProfile.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2009, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.net.vpn; + +import android.os.Parcel; + +/** + * The profile for pre-shared-key-based L2TP-over-IPSec type of VPN. + * {@hide} + */ +public class L2tpIpsecPskProfile extends L2tpProfile { + private static final long serialVersionUID = 1L; + + private String mPresharedKey; + + @Override + public VpnType getType() { + return VpnType.L2TP_IPSEC_PSK; + } + + public void setPresharedKey(String key) { + mPresharedKey = key; + } + + public String getPresharedKey() { + return mPresharedKey; + } + + @Override + protected void readFromParcel(Parcel in) { + super.readFromParcel(in); + mPresharedKey = in.readString(); + } + + @Override + public void writeToParcel(Parcel parcel, int flags) { + super.writeToParcel(parcel, flags); + parcel.writeString(mPresharedKey); + } +} diff --git a/vpn/java/android/net/vpn/L2tpProfile.java b/vpn/java/android/net/vpn/L2tpProfile.java new file mode 100644 index 0000000..dbba0c5 --- /dev/null +++ b/vpn/java/android/net/vpn/L2tpProfile.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2009, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.net.vpn; + +import android.os.Parcel; + +/** + * The profile for L2TP type of VPN. + * {@hide} + */ +public class L2tpProfile extends VpnProfile { + private static final long serialVersionUID = 1L; + + private boolean mSecret; + private String mSecretString; + + @Override + public VpnType getType() { + return VpnType.L2TP; + } + + /** + * Enables/disables the secret for authenticating tunnel connection. + */ + public void setSecretEnabled(boolean enabled) { + mSecret = enabled; + } + + public boolean isSecretEnabled() { + return mSecret; + } + + public void setSecretString(String secret) { + mSecretString = secret; + } + + public String getSecretString() { + return mSecretString; + } + + @Override + protected void readFromParcel(Parcel in) { + super.readFromParcel(in); + mSecret = in.readInt() > 0; + mSecretString = in.readString(); + } + + @Override + public void writeToParcel(Parcel parcel, int flags) { + super.writeToParcel(parcel, flags); + parcel.writeInt(mSecret ? 1 : 0); + parcel.writeString(mSecretString); + } +} diff --git a/vpn/java/android/net/vpn/PptpProfile.java b/vpn/java/android/net/vpn/PptpProfile.java new file mode 100644 index 0000000..c68bb71 --- /dev/null +++ b/vpn/java/android/net/vpn/PptpProfile.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2009, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.net.vpn; + +/** + * The profile for PPTP type of VPN. + * {@hide} + */ +public class PptpProfile extends VpnProfile { + private static final long serialVersionUID = 1L; + + @Override + public VpnType getType() { + return VpnType.PPTP; + } +} diff --git a/vpn/java/android/net/vpn/VpnManager.java b/vpn/java/android/net/vpn/VpnManager.java new file mode 100644 index 0000000..dc70b26 --- /dev/null +++ b/vpn/java/android/net/vpn/VpnManager.java @@ -0,0 +1,162 @@ +/* + * Copyright (C) 2009, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.net.vpn; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.ServiceConnection; +import android.util.Log; + +/** + * The class provides interface to manage all VPN-related tasks, including: + * <ul> + * <li>The list of supported VPN types. + * <li>API's to start/stop the service of a particular type. + * <li>API's to start the settings activity. + * <li>API's to create a profile. + * <li>API's to register/unregister a connectivity receiver and the keys to + * access the fields in a connectivity broadcast event. + * </ul> + * {@hide} + */ +public class VpnManager { + // Action for broadcasting a connectivity state. + private static final String ACTION_VPN_CONNECTIVITY = "vpn.connectivity"; + /** Key to the profile name of a connectivity broadcast event. */ + public static final String BROADCAST_PROFILE_NAME = "profile_name"; + /** Key to the connectivity state of a connectivity broadcast event. */ + public static final String BROADCAST_CONNECTION_STATE = "connection_state"; + + public static final String PROFILES_PATH = "/data/misc/vpn/profiles"; + + private static final String PACKAGE_PREFIX = + VpnManager.class.getPackage().getName() + "."; + + // Action to start VPN service + private static final String ACTION_VPN_SERVICE = PACKAGE_PREFIX + "SERVICE"; + + // Action to start VPN settings + private static final String ACTION_VPN_SETTINGS = PACKAGE_PREFIX + "SETTINGS"; + + private static final String TAG = VpnManager.class.getSimpleName(); + + /** + * Returns all supported VPN types. + */ + public static VpnType[] getSupportedVpnTypes() { + return VpnType.values(); + } + + private Context mContext; + + /** + * Creates a manager object with the specified context. + */ + public VpnManager(Context c) { + mContext = c; + } + + /** + * Creates a VPN profile of the specified type. + * + * @param type the VPN type + * @return the profile object + */ + public VpnProfile createVpnProfile(VpnType type) { + return createVpnProfile(type, false); + } + + /** + * Creates a VPN profile of the specified type. + * + * @param type the VPN type + * @param customized true if the profile is custom made + * @return the profile object + */ + public VpnProfile createVpnProfile(VpnType type, boolean customized) { + try { + VpnProfile p = (VpnProfile) type.getProfileClass().newInstance(); + p.setCustomized(customized); + return p; + } catch (InstantiationException e) { + return null; + } catch (IllegalAccessException e) { + return null; + } + } + + /** + * Starts the VPN service to establish VPN connection. + */ + public void startVpnService() { + mContext.startService(new Intent(ACTION_VPN_SERVICE)); + } + + /** + * Stops the VPN service. + */ + public void stopVpnService() { + mContext.stopService(new Intent(ACTION_VPN_SERVICE)); + } + + /** + * Binds the specified ServiceConnection with the VPN service. + */ + public boolean bindVpnService(ServiceConnection c) { + if (!mContext.bindService(new Intent(ACTION_VPN_SERVICE), c, 0)) { + Log.w(TAG, "failed to connect to VPN service"); + return false; + } else { + Log.d(TAG, "succeeded to connect to VPN service"); + return true; + } + } + + /** Broadcasts the connectivity state of the specified profile. */ + public void broadcastConnectivity(String profileName, VpnState s) { + Intent intent = new Intent(ACTION_VPN_CONNECTIVITY); + intent.putExtra(BROADCAST_PROFILE_NAME, profileName); + intent.putExtra(BROADCAST_CONNECTION_STATE, s); + mContext.sendBroadcast(intent); + } + + public void registerConnectivityReceiver(BroadcastReceiver r) { + IntentFilter filter = new IntentFilter(); + filter.addAction(VpnManager.ACTION_VPN_CONNECTIVITY); + mContext.registerReceiver(r, filter); + } + + public void unregisterConnectivityReceiver(BroadcastReceiver r) { + mContext.unregisterReceiver(r); + } + + /** Starts the VPN settings activity. */ + public void startSettingsActivity() { + Intent intent = new Intent(ACTION_VPN_SETTINGS); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + mContext.startActivity(intent); + } + + /** Creates an intent to start the VPN settings activity. */ + public Intent createSettingsActivityIntent() { + Intent intent = new Intent(ACTION_VPN_SETTINGS); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + return intent; + } +} diff --git a/vpn/java/android/net/vpn/VpnProfile.aidl b/vpn/java/android/net/vpn/VpnProfile.aidl new file mode 100644 index 0000000..edeaef0 --- /dev/null +++ b/vpn/java/android/net/vpn/VpnProfile.aidl @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2009, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.net.vpn; + +parcelable VpnProfile; diff --git a/vpn/java/android/net/vpn/VpnProfile.java b/vpn/java/android/net/vpn/VpnProfile.java new file mode 100644 index 0000000..bd6c809 --- /dev/null +++ b/vpn/java/android/net/vpn/VpnProfile.java @@ -0,0 +1,177 @@ +/* + * Copyright (C) 2009, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.net.vpn; + +import android.content.Context; +import android.os.Parcel; +import android.os.Parcelable; + +import java.io.IOException; +import java.io.Serializable; + +/** + * A VPN profile. + * {@hide} + */ +public abstract class VpnProfile implements Parcelable, Serializable { + private static final long serialVersionUID = 1L; + private String mName; // unique display name + private String mId; // unique identifier + private String mServerName; // VPN server name + private String mDomainSuffices; // space separated list + private String mRouteList; // space separated list + private String mSavedUsername; + private boolean mIsCustomized; + private transient VpnState mState = VpnState.IDLE; + + /** Sets a user-friendly name for this profile. */ + public void setName(String name) { + mName = name; + } + + public String getName() { + return mName; + } + + /** + * Sets an ID for this profile. The caller should make sure the + * uniqueness of the ID. + */ + public void setId(String id) { + mId = id; + } + + public String getId() { + return mId; + } + + /** + * Sets the name of the VPN server. Used for DNS lookup. + */ + public void setServerName(String name) { + mServerName = name; + } + + public String getServerName() { + return mServerName; + } + + /** + * Sets the domain suffices for DNS resolution. + * + * @param entries a comma-separated list of domain suffices + */ + public void setDomainSuffices(String entries) { + mDomainSuffices = entries; + } + + public String getDomainSuffices() { + return mDomainSuffices; + } + + /** + * Sets the routing info for this VPN connection. + * + * @param entries a comma-separated list of routes; each entry is in the + * format of "(network address)/(network mask)" + */ + public void setRouteList(String entries) { + mRouteList = entries; + } + + public String getRouteList() { + return mRouteList; + } + + public void setSavedUsername(String name) { + mSavedUsername = name; + } + + public String getSavedUsername() { + return mSavedUsername; + } + + public void setState(VpnState state) { + mState = state; + } + + public VpnState getState() { + return ((mState == null) ? VpnState.IDLE : mState); + } + + public boolean isIdle() { + return (mState == VpnState.IDLE); + } + + /** + * Returns whether this profile is custom made (as opposed to being + * created by provided user interface). + */ + public boolean isCustomized() { + return mIsCustomized; + } + + /** + * Returns the VPN type of the profile. + */ + public abstract VpnType getType(); + + void setCustomized(boolean customized) { + mIsCustomized = customized; + } + + protected void readFromParcel(Parcel in) { + mName = in.readString(); + mId = in.readString(); + mServerName = in.readString(); + mDomainSuffices = in.readString(); + mRouteList = in.readString(); + mSavedUsername = in.readString(); + } + + public static final Parcelable.Creator<VpnProfile> CREATOR = + new Parcelable.Creator<VpnProfile>() { + public VpnProfile createFromParcel(Parcel in) { + VpnType type = Enum.valueOf(VpnType.class, in.readString()); + boolean customized = in.readInt() > 0; + VpnProfile p = new VpnManager(null).createVpnProfile(type, + customized); + if (p == null) return null; + p.readFromParcel(in); + return p; + } + + public VpnProfile[] newArray(int size) { + return new VpnProfile[size]; + } + }; + + public void writeToParcel(Parcel parcel, int flags) { + parcel.writeString(getType().toString()); + parcel.writeInt(mIsCustomized ? 1 : 0); + parcel.writeString(mName); + parcel.writeString(mId); + parcel.writeString(mServerName); + parcel.writeString(mDomainSuffices); + parcel.writeString(mRouteList); + parcel.writeString(mSavedUsername); + } + + public int describeContents() { + return 0; + } +} diff --git a/vpn/java/android/net/vpn/VpnState.java b/vpn/java/android/net/vpn/VpnState.java new file mode 100644 index 0000000..ebd9364 --- /dev/null +++ b/vpn/java/android/net/vpn/VpnState.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2009, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.net.vpn; + +/** + * Enumeration of all VPN states. + * + * A normal VPN connection lifetime starts in {@link IDLE}. When a new + * connection is about to be set up, it goes to {@link CONNECTING} and then + * {@link CONNECTED} if successful; back to {@link IDLE} if failed. + * When the connection is about to be torn down, it goes to + * {@link DISCONNECTING} and then {@link IDLE}. + * {@link CANCELLED} is a state when a VPN connection attempt is aborted, and + * is in transition to {@link IDLE}. + * {@hide} + */ +public enum VpnState { + CONNECTING, DISCONNECTING, CANCELLED, CONNECTED, IDLE +} diff --git a/vpn/java/android/net/vpn/VpnType.java b/vpn/java/android/net/vpn/VpnType.java new file mode 100644 index 0000000..c7df943 --- /dev/null +++ b/vpn/java/android/net/vpn/VpnType.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2009, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.net.vpn; + +/** + * Enumeration of all supported VPN types. + * {@hide} + */ +public enum VpnType { + PPTP("PPTP", "", PptpProfile.class), + L2TP("L2TP", "", L2tpProfile.class), + L2TP_IPSEC_PSK("L2TP/IPSec PSK", "Pre-shared key based L2TP/IPSec VPN", + L2tpIpsecPskProfile.class), + L2TP_IPSEC("L2TP/IPSec CRT", "Certificate based L2TP/IPSec VPN", + L2tpIpsecProfile.class); + + private String mDisplayName; + private String mDescription; + private Class<? extends VpnProfile> mClass; + + VpnType(String displayName, String description, + Class<? extends VpnProfile> klass) { + mDisplayName = displayName; + mDescription = description; + mClass = klass; + } + + public String getDisplayName() { + return mDisplayName; + } + + public String getDescription() { + return mDescription; + } + + public Class<? extends VpnProfile> getProfileClass() { + return mClass; + } +} |