示例#1
0
 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);
     }
 }
示例#2
0
 @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);
 }
示例#3
0
 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;
     }
 }
示例#4
0
 @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);
     }
 }