// Path: main/src/domain/xink/vpn/wrapper/KeyStore.java
// public class KeyStore extends AbstractWrapper {
// 
//     public static final String UNLOCK_ACTION = "android.credentials.UNLOCK";
// 
//     private static final int NO_ERROR = 1;
// 
//     /*
//     private static final int LOCKED = 2;
//     private static final int UNINITIALIZED = 3;
//     private static final int SYSTEM_ERROR = 4;
//     private static final int PROTOCOL_ERROR = 5;
//     private static final int PERMISSION_DENIED = 6;
//     private static final int KEY_NOT_FOUND = 7;
//     private static final int VALUE_CORRUPTED = 8;
//     private static final int UNDEFINED_ACTION = 9;
//     private static final int WRONG_PASSWORD = 10;
//     */
// 
//     public KeyStore(final Context ctx) {
//         super(ctx, "android.security.KeyStore", new StubInstanceCreator() {
//             @Override
//             protected Object newStubInstance(final Class<?> stubClass, final Context ctx) throws Exception {
//                 Method method = stubClass.getMethod("getInstance");
//                 return method.invoke(null);
//             }
//         });
//     }
// 
//     public boolean put(final String key, final String value) {
//         return this.<Boolean> invokeStubMethod("put", key, value);
//     }
// 
//     public boolean contains(final VpnProfile p) {
//         String key = L2tpIpsecPskProfile.KEY_PREFIX_IPSEC_PSK + p.getId();
//         return this.<Boolean> invokeStubMethod("contains", key);
//     }
// 
//     public boolean delete(final String key) {
//         return this.<Boolean> invokeStubMethod("delete", key);
//     }
// 
//     public void unlock(final Activity ctx) {
//         try {
//             Intent intent = new Intent(UNLOCK_ACTION);
//             ctx.startActivity(intent);
//         } catch (ActivityNotFoundException e) {
//             Log.e("xink", "unlock credentials failed", e);
//         }
//     }
// 
//     public boolean isUnlocked() {
//         int err = this.<Integer> invokeStubMethod("test");
//         Log.d("xink", "KeyStore.test result is: " + err);
//         return err == NO_ERROR;
//     }
// 
//     /**
//      * Check whether the keystore is hacked by xink.
//      */
//     public boolean isHacked() {
//         try {
//             Method m = getStubClass().getDeclaredMethod("execute", int.class, byte[][].class);
//             m.setAccessible(true);
//             m.invoke(getStub(), 'x', new byte[0][]);
//         } catch (Throwable e) {
//             throw new AppException("verify failed", e);
//         }
// 
//         int err = invokeStubMethod("getLastError");
//         Log.d("xink", "cmd 'x' result=" + err);
//         return err == NO_ERROR;
//     }
// }
// 
// Path: main/src/domain/xink/vpn/wrapper/PptpProfile.java
// public class PptpProfile extends VpnProfile {
// 
//     public PptpProfile(final Context ctx) {
//         super(ctx, "android.net.vpn.PptpProfile");
//     }
// 
//     @Override
//     public VpnType getType() {
//         return VpnType.PPTP;
//     }
// 
//     /**
//      * Enables/disables the encryption for PPTP tunnel.
//      */
//     public void setEncryptionEnabled(final boolean enabled) {
//         try {
//             Method m = getStubClass().getMethod("setEncryptionEnabled", boolean.class);
//             m.invoke(getStub(), enabled);
//         } catch (Throwable e) {
//             throw new AppException("setEncryptionEnabled failed", e);
//         }
//     }
// 
//     public boolean isEncryptionEnabled() {
//         return this.<Boolean>invokeStubMethod("isEncryptionEnabled");
//     }
// 
//     /*
//      * (non-Javadoc)
//      * 
//      * @see xink.vpn.wrapper.VpnProfile#dulicateToConnect()
//      */
//     @Override
//     public PptpProfile dulicateToConnect() {
//         PptpProfile p = (PptpProfile) super.dulicateToConnect();
//         p.setEncryptionEnabled(isEncryptionEnabled());
//         return p;
//     }
// 
// }


import java.lang.reflect.Method;
import xink.vpn.wrapper.KeyStore;
import xink.vpn.wrapper.PptpProfile;
import xink.vpn.wrapper.VpnManager;
import xink.vpn.wrapper.VpnService;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.test.AndroidTestCase;
/*
 * Copyright 2011 yingxinwu.g@gmail.com
 * 
 * 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 xink.vpn.test;



public class CompatibleTest extends AndroidTestCase {

    public void testVpnManager() throws Exception {
        VpnManager vpnMgr = new VpnManager(getContext());
        Class<?> stubClass = vpnMgr.getStubClass();

        assertMethodDefined(stubClass, VpnManager.METHOD_START_VPN_SERVICE);
        assertMethodDefined(stubClass, VpnManager.METHOD_STOP_VPN_SERVICE);
        assertMethodDefined(stubClass, VpnManager.METHOD_BIND_VPN_SERVICE, ServiceConnection.class);
    }

    public void testVpnService() throws Exception {
        VpnService vpnSrv = new VpnService(getContext());
        Class<?> stubClass = vpnSrv.getStubClass();

        assertMethodDefined(stubClass, "asInterface", IBinder.class);

// Path: main/src/domain/xink/vpn/wrapper/KeyStore.java
// public class KeyStore extends AbstractWrapper {
// 
//     public static final String UNLOCK_ACTION = "android.credentials.UNLOCK";
// 
//     private static final int NO_ERROR = 1;
// 
//     /*
//     private static final int LOCKED = 2;
//     private static final int UNINITIALIZED = 3;
//     private static final int SYSTEM_ERROR = 4;
//     private static final int PROTOCOL_ERROR = 5;
//     private static final int PERMISSION_DENIED = 6;
//     private static final int KEY_NOT_FOUND = 7;
//     private static final int VALUE_CORRUPTED = 8;
//     private static final int UNDEFINED_ACTION = 9;
//     private static final int WRONG_PASSWORD = 10;
//     */
// 
//     public KeyStore(final Context ctx) {
//         super(ctx, "android.security.KeyStore", new StubInstanceCreator() {
//             @Override
//             protected Object newStubInstance(final Class<?> stubClass, final Context ctx) throws Exception {
//                 Method method = stubClass.getMethod("getInstance");
//                 return method.invoke(null);
//             }
//         });
//     }
// 
//     public boolean put(final String key, final String value) {
//         return this.<Boolean> invokeStubMethod("put", key, value);
//     }
// 
//     public boolean contains(final VpnProfile p) {
//         String key = L2tpIpsecPskProfile.KEY_PREFIX_IPSEC_PSK + p.getId();
//         return this.<Boolean> invokeStubMethod("contains", key);
//     }
// 
//     public boolean delete(final String key) {
//         return this.<Boolean> invokeStubMethod("delete", key);
//     }
// 
//     public void unlock(final Activity ctx) {
//         try {
//             Intent intent = new Intent(UNLOCK_ACTION);
//             ctx.startActivity(intent);
//         } catch (ActivityNotFoundException e) {
//             Log.e("xink", "unlock credentials failed", e);
//         }
//     }
// 
//     public boolean isUnlocked() {
//         int err = this.<Integer> invokeStubMethod("test");
//         Log.d("xink", "KeyStore.test result is: " + err);
//         return err == NO_ERROR;
//     }
// 
//     /**
//      * Check whether the keystore is hacked by xink.
//      */
//     public boolean isHacked() {
//         try {
//             Method m = getStubClass().getDeclaredMethod("execute", int.class, byte[][].class);
//             m.setAccessible(true);
//             m.invoke(getStub(), 'x', new byte[0][]);
//         } catch (Throwable e) {
//             throw new AppException("verify failed", e);
//         }
// 
//         int err = invokeStubMethod("getLastError");
//         Log.d("xink", "cmd 'x' result=" + err);
//         return err == NO_ERROR;
//     }
// }
// 
// Path: main/src/domain/xink/vpn/wrapper/PptpProfile.java
// public class PptpProfile extends VpnProfile {
// 
//     public PptpProfile(final Context ctx) {
//         super(ctx, "android.net.vpn.PptpProfile");
//     }
// 
//     @Override
//     public VpnType getType() {
//         return VpnType.PPTP;
//     }
// 
//     /**
//      * Enables/disables the encryption for PPTP tunnel.
//      */
//     public void setEncryptionEnabled(final boolean enabled) {
//         try {
//             Method m = getStubClass().getMethod("setEncryptionEnabled", boolean.class);
//             m.invoke(getStub(), enabled);
//         } catch (Throwable e) {
//             throw new AppException("setEncryptionEnabled failed", e);
//         }
//     }
// 
//     public boolean isEncryptionEnabled() {
//         return this.<Boolean>invokeStubMethod("isEncryptionEnabled");
//     }
// 
//     /*
//      * (non-Javadoc)
//      * 
//      * @see xink.vpn.wrapper.VpnProfile#dulicateToConnect()
//      */
//     @Override
//     public PptpProfile dulicateToConnect() {
//         PptpProfile p = (PptpProfile) super.dulicateToConnect();
//         p.setEncryptionEnabled(isEncryptionEnabled());
//         return p;
//     }
// 
// }


// Path: tests/src/android/xink/vpn/test/CompatibleTest.java
import java.lang.reflect.Method;
import xink.vpn.wrapper.KeyStore;
import xink.vpn.wrapper.PptpProfile;
import xink.vpn.wrapper.VpnManager;
import xink.vpn.wrapper.VpnService;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.test.AndroidTestCase;

/*
 * Copyright 2011 yingxinwu.g@gmail.com
 * 
 * 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 xink.vpn.test;



public class CompatibleTest extends AndroidTestCase {

    public void testVpnManager() throws Exception {
        VpnManager vpnMgr = new VpnManager(getContext());
        Class<?> stubClass = vpnMgr.getStubClass();

        assertMethodDefined(stubClass, VpnManager.METHOD_START_VPN_SERVICE);
        assertMethodDefined(stubClass, VpnManager.METHOD_STOP_VPN_SERVICE);
        assertMethodDefined(stubClass, VpnManager.METHOD_BIND_VPN_SERVICE, ServiceConnection.class);
    }

    public void testVpnService() throws Exception {
        VpnService vpnSrv = new VpnService(getContext());
        Class<?> stubClass = vpnSrv.getStubClass();

        assertMethodDefined(stubClass, "asInterface", IBinder.class);

        Class<?> profileClass = new PptpProfile(getContext()).getGenericProfileClass();