package android.net.vpn;
import java.io.File;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.os.Environment;
import android.os.SystemProperties;
import android.util.Log;
private static final String ACTION_VPN_CONNECTIVITY = "vpn.connectivity";
public static final String BROADCAST_PROFILE_NAME = "profile_name";
public static final String BROADCAST_CONNECTION_STATE = "connection_state";
public static final String BROADCAST_ERROR_CODE = "err";
public static final int VPN_ERROR_AUTH = 51;
public static final int VPN_ERROR_CONNECTION_FAILED = 101;
public static final int VPN_ERROR_UNKNOWN_SERVER = 102;
public static final int VPN_ERROR_CHALLENGE = 5;
public static final int VPN_ERROR_REMOTE_HUNG_UP = 7;
public static final int VPN_ERROR_REMOTE_PPP_HUNG_UP = 48;
public static final int VPN_ERROR_PPP_NEGOTIATION_FAILED = 42;
public static final int VPN_ERROR_CONNECTION_LOST = 103;
public static final int VPN_ERROR_LARGEST = 200;
public static final int VPN_ERROR_NO_ERROR = 0;
public static final String PROFILES_PATH = "/misc/vpn/profiles";
private static final String PACKAGE_PREFIX =
VpnManager.class.getPackage().getName() + ".";
private static final String ACTION_VPN_SERVICE = PACKAGE_PREFIX + "SERVICE";
private static final String ACTION_VPN_SETTINGS =
PACKAGE_PREFIX + "SETTINGS";
public static final String TAG = VpnManager.class.getSimpleName();
return Environment.getDataDirectory().getPath() + PROFILES_PATH;
}
return VpnType.values();
}
private Context mContext;
mContext = c;
}
return createVpnProfile(type, false);
}
try {
VpnProfile p = (VpnProfile) type.getProfileClass().newInstance();
p.setCustomized(customized);
return p;
} catch (InstantiationException e) {
return null;
} catch (IllegalAccessException e) {
return null;
}
}
mContext.startService(new Intent(ACTION_VPN_SERVICE));
}
mContext.stopService(new Intent(ACTION_VPN_SERVICE));
}
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;
}
}
broadcastConnectivity(profileName, s, VPN_ERROR_NO_ERROR);
}
int error) {
Intent intent = new Intent(ACTION_VPN_CONNECTIVITY);
intent.putExtra(BROADCAST_PROFILE_NAME, profileName);
intent.putExtra(BROADCAST_CONNECTION_STATE, s);
if (error != VPN_ERROR_NO_ERROR) {
intent.putExtra(BROADCAST_ERROR_CODE, error);
}
mContext.sendBroadcast(intent);
}
IntentFilter filter = new IntentFilter();
filter.addAction(VpnManager.ACTION_VPN_CONNECTIVITY);
mContext.registerReceiver(r, filter);
}
mContext.unregisterReceiver(r);
}
Intent intent = new Intent(ACTION_VPN_SETTINGS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
}
Intent intent = new Intent(ACTION_VPN_SETTINGS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
return intent;
}
}