简体   繁体   English

使用Android 4.0的VpnService.Builder创建接口时为IllegalState

[英]IllegalState when creating interface with Android 4.0's VpnService.Builder

I am experimenting with the VpnService that was added to Android in SDK 4.0. 我正在尝试在SDK 4.0中添加到Android的VpnService。 I have gotten as far as starting the VpnService, however, I am unable to create the virtual interface. 我已经启动了VpnService,但是,我无法创建虚拟接口。 My code throws an IllegalStateException and I am not able to figure out why. 我的代码引发了IllegalStateException,但我无法弄清原因。 The code is inside a Thread, which is an inner-class of my VPNService-class. 该代码位于Thread内部,这是我的VPNService类的内部类。

My cut down example looks like this: 我的削减示例如下所示:

        ParcelFileDescriptor pfd = null;

        VpnService.Builder b = new VpnService.Builder();
        try{
            b.addAddress("10.0.6.2", 24);
            b.setMtu(1460);
            b.setSession("TunnelTest");
        } catch(IllegalArgumentException e){
            Log.v("Service", "Address is invalid!");
            stopSelf();
            return;
        }

        try{
            pfd = b.establish();
        } catch (IllegalArgumentException e){
            Log.v("Service", "Interface was provided with an illegal argument");
        } catch (IllegalStateException e){
            e.printStackTrace();
            Log.v("Service", "Illegal state");
        } catch (SecurityException e){
            Log.v("Service", "Security exception thrown");

What I try to do here is to create a virtual interface with IP 10.0.6.2, belonging to the 10.6.0.0/24 subnet. 我在这里尝试做的是创建一个IP接口10.0.6.2的虚拟接口,该接口属于10.6.0.0/24子网。 The exception is thrown by the b.establish() call. 该异常由b。Establishment()调用引发。

This is the full stack trace: 这是完整的堆栈跟踪:

11-30 17:51:10.863: W/System.err(2741): java.lang.IllegalStateException: Cannot create interface
11-30 17:51:10.875: W/System.err(2741):     at android.os.Parcel.readException(Parcel.java:1335)
11-30 17:51:10.875: W/System.err(2741):     at android.os.Parcel.readException(Parcel.java:1281)
11-30 17:51:10.875: W/System.err(2741):     at android.net.IConnectivityManager$Stub$Proxy.establishVpn(IConnectivityManager.java:1321)
11-30 17:51:10.875: W/System.err(2741):     at android.net.VpnService$Builder.establish(VpnService.java:472)
11-30 17:51:10.875: W/System.err(2741):     at no.simtel.TestVpnService$TestVpn.run(TestVpnService.java:37)

您可以使用adb logcat来验证您是否遇到了此问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM