2 qqgzch qqgzch 于 2014.08.31 18:48 提问

安卓平台的vpn调用系统net.vpn类连接失败

类库来源`Github.

APK

大部分代码是系统settings-vpn页面的

    onError()
    java.io.IOException: cannot start service: mtpd
    at com.android.server.vpn.DaemonProxy.start(DaemonProxy.java:75)
    at com.android.server.vpn.VpnDaemons.startDaemon(VpnDaemons.java:106)
    at com.android.server.vpn.VpnDaemons.startMtpd(VpnDaemons.java:127)
    at com.android.server.vpn.VpnDaemons.startPptp(VpnDaemons.java:56)
    at com.android.server.vpn.PptpService.connect(PptpService.java:32)
    at com.android.server.vpn.VpnService.onConnect(VpnService.java:137)
    at com.android.server.vpn.VpnServiceBinder$2.run(VpnServiceBinder.java:114)
    at java.lang.Thread.run(Thread.java:838)


    (VpnServiceBinder.java:114)
    private synchronized boolean connect(final VpnProfile p,
            final String username, final String password) {
        if (mService != null) return false;
        final VpnService s = mService = createService(p);

        new Thread(new Runnable() {
            public void run() {
                s.onConnect(username, password);
            }
        }).start();
        return true;
    }

    (VpnService.java:137)
        synchronized boolean onConnect(String username, String password) {
        try {
            setState(VpnState.CONNECTING);

            mDaemons.stopAll();
            String serverIp = getIp(getProfile().getServerName());
            saveLocalIpAndInterface(serverIp);
            onBeforeConnect();
            connect(serverIp, username, password);
            waitUntilConnectedOrTimedout();
            return true;
        } catch (Throwable e) {
            onError(e);
            return false;
        }
    }




    (PptpService.java:32)
    class PptpService extends VpnService<PptpProfile> {
    @Override
    protected void connect(String serverIp, String username, String password)
            throws IOException {
        System.err.println(serverIp+"  "+username+"  "+password);
        PptpProfile p = getProfile();
        getDaemons().startPptp(serverIp, username, password,
                p.isEncryptionEnabled());
    }
    }



     (VpnDaemons.java:56)
        public DaemonProxy startPptp(String serverIp, String username,
            String password, boolean encryption) throws IOException {
        return startMtpd(PPTP, serverIp, PPTP_PORT, null, username, password,
                encryption);
    }



      (VpnDaemons.java:127)
         private DaemonProxy startMtpd(String protocol,
            String serverIp, String port, String secret, String username,
            String password, boolean encryption) throws IOException {
        ArrayList<String> args = new ArrayList<String>();
        args.addAll(Arrays.asList(protocol, serverIp, port));
        if (secret != null) args.add(secret);
        args.add(PPP_ARGS_SEPARATOR);
        addPppArguments(args, serverIp, username, password, encryption);

        DaemonProxy mtpd = startDaemon(MTPD);
        mtpd.sendCommand(args.toArray(new String[args.size()]));
        return mtpd;
    }


       (VpnDaemons.java:106)
        private synchronized DaemonProxy startDaemon(String daemonName)
            throws IOException {
        DaemonProxy daemon = new DaemonProxy(daemonName);
        mDaemonList.add(daemon);
        daemon.start();
        return daemon;
    }



     (DaemonProxy.java:75)
        void start() throws IOException {
        String svc = mName;

        Log.i(mTag, "Start VPN daemon: " + svc);
        SystemProperties.set(SVC_START_CMD, svc);

        if (!blockUntil(SVC_STATE_RUNNING, WAITING_TIME)) {
            throw new IOException("cannot start service: " + svc);
        } else {
            mControlSocket = createServiceSocket();
        }
    }
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!