diff options
-rw-r--r-- | core/java/android/net/ConnectivityManager.java | 40 | ||||
-rw-r--r-- | core/java/android/net/IConnectivityManager.aidl | 5 | ||||
-rw-r--r-- | core/java/com/android/internal/net/VpnConfig.aidl | 19 | ||||
-rw-r--r-- | core/java/com/android/internal/net/VpnConfig.java | 80 | ||||
-rw-r--r-- | services/java/com/android/server/ConnectivityService.java | 29 | ||||
-rw-r--r-- | services/java/com/android/server/connectivity/Vpn.java | 20 |
6 files changed, 129 insertions, 64 deletions
diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java index 3025462..2242e9e 100644 --- a/core/java/android/net/ConnectivityManager.java +++ b/core/java/android/net/ConnectivityManager.java @@ -19,7 +19,6 @@ package android.net; import android.annotation.SdkConstant; import android.annotation.SdkConstant.SdkConstantType; import android.os.Binder; -import android.os.Bundle; import android.os.ParcelFileDescriptor; import android.os.RemoteException; @@ -758,43 +757,4 @@ public class ConnectivityManager { } catch (RemoteException e) { } } - - /** - * Protect a socket from routing changes. This method is limited to VPN - * applications, and it is always hidden to avoid direct use. - * @hide - */ - public void protectVpn(ParcelFileDescriptor socket) { - try { - mService.protectVpn(socket); - } catch (RemoteException e) { - } - } - - /** - * Prepare for a VPN application. This method is limited to VpnDialogs, - * and it is always hidden to avoid direct use. - * @hide - */ - public String prepareVpn(String packageName) { - try { - return mService.prepareVpn(packageName); - } catch (RemoteException e) { - return null; - } - } - - /** - * Configure a TUN interface and return its file descriptor. Parameters - * are encoded and opaque to this class. This method is limited to VPN - * applications, and it is always hidden to avoid direct use. - * @hide - */ - public ParcelFileDescriptor establishVpn(Bundle config) { - try { - return mService.establishVpn(config); - } catch (RemoteException e) { - return null; - } - } } diff --git a/core/java/android/net/IConnectivityManager.aidl b/core/java/android/net/IConnectivityManager.aidl index 7f3775d..fba16e1 100644 --- a/core/java/android/net/IConnectivityManager.aidl +++ b/core/java/android/net/IConnectivityManager.aidl @@ -20,10 +20,11 @@ import android.net.LinkProperties; import android.net.NetworkInfo; import android.net.NetworkState; import android.net.ProxyProperties; -import android.os.Bundle; import android.os.IBinder; import android.os.ParcelFileDescriptor; +import com.android.internal.net.VpnConfig; + /** * Interface that answers queries about, and allows changing, the * state of network connectivity. @@ -102,5 +103,5 @@ interface IConnectivityManager String prepareVpn(String packageName); - ParcelFileDescriptor establishVpn(in Bundle config); + ParcelFileDescriptor establishVpn(in VpnConfig config); } diff --git a/core/java/com/android/internal/net/VpnConfig.aidl b/core/java/com/android/internal/net/VpnConfig.aidl new file mode 100644 index 0000000..be1684c --- /dev/null +++ b/core/java/com/android/internal/net/VpnConfig.aidl @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2011 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 com.android.internal.net; + +parcelable VpnConfig; diff --git a/core/java/com/android/internal/net/VpnConfig.java b/core/java/com/android/internal/net/VpnConfig.java new file mode 100644 index 0000000..18d9ec4 --- /dev/null +++ b/core/java/com/android/internal/net/VpnConfig.java @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2011 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 com.android.internal.net; + +import android.os.Parcel; +import android.os.Parcelable; + +/** + * A simple container used to carry information in VpnBuilder, VpnDialogs, + * and com.android.server.connectivity.Vpn. Internal use only. + * + * @hide + */ +public class VpnConfig implements Parcelable { + + public String packageName; + public String sessionName; + public String interfaceName; + public String configureActivity; + public int mtu = -1; + public String addresses; + public String routes; + public String dnsServers; + public long startTime = -1; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeString(packageName); + out.writeString(sessionName); + out.writeString(interfaceName); + out.writeString(configureActivity); + out.writeInt(mtu); + out.writeString(addresses); + out.writeString(routes); + out.writeString(dnsServers); + out.writeLong(startTime); + } + + public static final Parcelable.Creator<VpnConfig> CREATOR = + new Parcelable.Creator<VpnConfig>() { + @Override + public VpnConfig createFromParcel(Parcel in) { + VpnConfig config = new VpnConfig(); + config.packageName = in.readString(); + config.sessionName = in.readString(); + config.interfaceName = in.readString(); + config.configureActivity = in.readString(); + config.mtu = in.readInt(); + config.addresses = in.readString(); + config.routes = in.readString(); + config.dnsServers = in.readString(); + config.startTime = in.readLong(); + return config; + } + + @Override + public VpnConfig[] newArray(int size) { + return new VpnConfig[size]; + } + }; +} diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java index c6f4c20..385448f 100644 --- a/services/java/com/android/server/ConnectivityService.java +++ b/services/java/com/android/server/ConnectivityService.java @@ -48,7 +48,6 @@ import android.net.RouteInfo; import android.net.vpn.VpnManager; import android.net.wifi.WifiStateTracker; import android.os.Binder; -import android.os.Bundle; import android.os.FileUtils; import android.os.Handler; import android.os.HandlerThread; @@ -67,6 +66,7 @@ import android.util.EventLog; import android.util.Slog; import android.util.SparseIntArray; +import com.android.internal.net.VpnConfig; import com.android.internal.telephony.Phone; import com.android.server.connectivity.Tethering; import com.android.server.connectivity.Vpn; @@ -2396,24 +2396,37 @@ public class ConnectivityService extends IConnectivityManager.Stub { return value; } - // @see ConnectivityManager#protectVpn(ParcelFileDescriptor) - // Permission checks are done in Vpn class. + /** + * Protect a socket from VPN routing rules. This method is used by + * VpnBuilder and not available in ConnectivityManager. Permission + * checks are done in Vpn class. + * @hide + */ @Override public void protectVpn(ParcelFileDescriptor socket) { mVpn.protect(socket, getDefaultInterface()); } - // @see ConnectivityManager#prepareVpn(String) - // Permission checks are done in Vpn class. + /** + * Prepare for a VPN application. This method is used by VpnDialogs + * and not available in ConnectivityManager. Permission checks are + * done in Vpn class. + * @hide + */ @Override public String prepareVpn(String packageName) { return mVpn.prepare(packageName); } - // @see ConnectivityManager#establishVpn(Bundle) - // Permission checks are done in Vpn class. + /** + * Configure a TUN interface and return its file descriptor. Parameters + * are encoded and opaque to this class. This method is used by VpnBuilder + * and not available in ConnectivityManager. Permission checks are done + * in Vpn class. + * @hide + */ @Override - public ParcelFileDescriptor establishVpn(Bundle config) { + public ParcelFileDescriptor establishVpn(VpnConfig config) { return mVpn.establish(config); } diff --git a/services/java/com/android/server/connectivity/Vpn.java b/services/java/com/android/server/connectivity/Vpn.java index 941ab80..372ba85 100644 --- a/services/java/com/android/server/connectivity/Vpn.java +++ b/services/java/com/android/server/connectivity/Vpn.java @@ -29,12 +29,12 @@ import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.net.INetworkManagementEventObserver; import android.os.Binder; -import android.os.Bundle; import android.os.ParcelFileDescriptor; import android.os.RemoteException; import android.util.Log; import com.android.internal.R; +import com.android.internal.net.VpnConfig; import com.android.server.ConnectivityService.VpnCallback; /** @@ -108,7 +108,7 @@ public class Vpn extends INetworkManagementEventObserver.Stub { * @param configuration The parameters to configure the interface. * @return The file descriptor of the interface. */ - public synchronized ParcelFileDescriptor establish(Bundle config) { + public synchronized ParcelFileDescriptor establish(VpnConfig config) { // Check the permission of the caller. mContext.enforceCallingPermission(VPN, "establish"); @@ -124,17 +124,9 @@ public class Vpn extends INetworkManagementEventObserver.Stub { throw new SecurityException("Not prepared"); } - // Unpack the config. - // TODO: move constants into VpnBuilder. - int mtu = config.getInt("mtu", -1); - String session = config.getString("session"); - String addresses = config.getString("addresses"); - String routes = config.getString("routes"); - String dnsServers = config.getString("dnsServers"); - // Create and configure the interface. - ParcelFileDescriptor descriptor = - ParcelFileDescriptor.adoptFd(nativeEstablish(mtu, addresses, routes)); + ParcelFileDescriptor descriptor = ParcelFileDescriptor.adoptFd( + nativeEstablish(config.mtu, config.addresses, config.routes)); // Replace the interface and abort if it fails. try { @@ -153,10 +145,10 @@ public class Vpn extends INetworkManagementEventObserver.Stub { throw e; } - dnsServers = (dnsServers == null) ? "" : dnsServers.trim(); + String dnsServers = (config.dnsServers == null) ? "" : config.dnsServers.trim(); mCallback.override(dnsServers.isEmpty() ? null : dnsServers.split(" ")); - showNotification(pm, app, session); + showNotification(pm, app, config.sessionName); return descriptor; } |