private void startVpn() { if (LaunchService.isVpnRunning()) { LogUtils.e("vpn is already running, do not start it again"); return; } Intent intent = VpnService.prepare(MainActivity.this); if (intent == null) { onActivityResult(ASK_VPN_PERMISSION, RESULT_OK, null); } else { startActivityForResult(intent, ASK_VPN_PERMISSION); } }
@Override public void onDownloaded(String url, String downloadTo) { downloaded = true; ActivityCompat.invalidateOptionsMenu(this); updateStatus(_(R.string.status_downloaded) + " " + Uri.parse(url).getLastPathSegment()); setExiting(); try { ManagerProcess.kill(); } catch (Exception e) { LogUtils.e("failed to kill manager", e); } ApkUtils.install(this, downloadTo); }
private String getApnName() { try { ConnectivityManager conManager = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = conManager.getActiveNetworkInfo(); if (null == ni) { return null; } return ni.getExtraInfo(); } catch (Exception e) { LogUtils.e("failed to get apn name", e); return null; } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { try { if (ASK_VPN_PERMISSION == requestCode) { if (resultCode == RESULT_OK) { if (LaunchService.SOCKS_VPN_SERVICE_CLASS == null) { onHandleFatalError("vpn class not loaded"); } else { updateStatus(_(R.string.status_launch_vpn)); stopService(new Intent(this, LaunchService.SOCKS_VPN_SERVICE_CLASS)); startService(new Intent(this, LaunchService.SOCKS_VPN_SERVICE_CLASS)); uninstallOldVersion(); } } else { onHandleFatalError(_(R.string.status_vpn_rejected)); LogUtils.e("failed to start vpn service: " + resultCode); } } else { super.onActivityResult(requestCode, resultCode, data); } } catch (Exception e) { LogUtils.e("failed to handle onActivityResult", e); } }