示例#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
 public void updateStatus(String status) {
     LogUtils.i(status);
     TextView textView = (TextView) findViewById(R.id.statusTextView);
     if (!textView.getText().toString().startsWith("Error:")) {
         textView.setText(status);
         if (LaunchService.isVpnRunning()) {
             clearNotification();
         } else {
             showNotification(status);
         }
     }
 }
示例#3
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);
 }
示例#4
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;
     }
 }
示例#5
0
 private void attachLogFiles(Intent i, String... logFileNames) {
   ArrayList<Uri> logFiles = new ArrayList<Uri>();
   for (String logFileName : logFileNames) {
     File logFile = new File(LOG_DIR + "/" + logFileName);
     if (logFile.exists()) {
       logFiles.add(Uri.fromFile(logFile));
     }
   }
   try {
     i.putParcelableArrayListExtra(Intent.EXTRA_STREAM, logFiles);
   } catch (Exception e) {
     LogUtils.e("failed to attach log", e);
   }
 }
示例#6
0
 @Override
 public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.main);
     PreferenceManager.setDefaultValues(this, R.xml.preferences, true);
     setTitle("fqrouter " + LaunchService.getMyVersion(this));
     setupUI();
     LaunchedIntent.register(this);
     UpdateFoundIntent.register(this);
     ExitedIntent.register(this);
     WifiRepeaterChangedIntent.register(this);
     PickAndPlayChangedIntent.register(this);
     FreeInternetChangedIntent.register(this);
     DownloadingIntent.register(this);
     DownloadedIntent.register(this);
     DownloadFailedIntent.register(this);
     HandleFatalErrorIntent.register(this);
     DnsPollutedIntent.register(this);
     HandleAlertIntent.register(this);
     ExitingIntent.register(this);
     blinkStatus(0);
     String apnName = getApnName();
     LogUtils.i("apn name: " + apnName);
     final File ignoredFile = new File("/data/data/fq.router2/etc/apn-alert-ignored");
     if (apnName != null && WAP_APN_LIST.contains(apnName.trim().toLowerCase()) && !ignoredFile.exists()) {
         new AlertDialog.Builder(MainActivity.this)
                 .setIcon(android.R.drawable.ic_dialog_alert)
                 .setTitle(R.string.wap_apn_alert_title)
                 .setMessage(String.format(_(R.string.wap_apn_alert_message), apnName))
                 .setPositiveButton(R.string.wap_apn_alert_change_now, new DialogInterface.OnClickListener() {
                     @Override
                     public void onClick(DialogInterface dialogInterface, int i) {
                         Intent intent = new Intent(Settings.ACTION_APN_SETTINGS);
                         startActivity(intent);
                         clearNotification();
                         MainActivity.this.finish();
                     }
                 })
                 .setNegativeButton(R.string.wap_apn_alert_ignore, new DialogInterface.OnClickListener() {
                     @Override
                     public void onClick(DialogInterface dialogInterface, int i) {
                         IOUtils.writeToFile(ignoredFile, "OK");
                         launch();
                     }
                 })
                 .show();
     } else {
         launch();
     }
 }
示例#7
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);
     }
 }
示例#8
0
    private void uninstallOldVersion() {
        boolean isOldVersionInstalled = ApkUtils.isInstalled(this, "fq.router");
        LogUtils.i("old version is installed: " + isOldVersionInstalled);
        if (isOldVersionInstalled) {
            new AlertDialog.Builder(this)
                    .setIcon(android.R.drawable.ic_dialog_alert)
                    .setTitle(R.string.uninstall_old_version_alert_title)
                    .setMessage(R.string.uninstall_old_version_alert_message)
                    .setPositiveButton(R.string.uninstall_old_version_alert_button, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            ApkUtils.uninstall(MainActivity.this, "fq.router");
                        }

                    })
                    .show();
        }
    }
示例#9
0
 private String copyLog(String logFileName) {
   File destFile = new File(LOG_DIR + "/" + logFileName);
   if (destFile.exists()) {
     destFile.delete();
   }
   try {
     FileInputStream inputStream = new FileInputStream("/data/data/fq.router2/log/" + logFileName);
     try {
       FileOutputStream outputStream = new FileOutputStream(LOG_DIR + "/" + logFileName);
       try {
         IOUtils.copy(inputStream, outputStream);
       } finally {
         outputStream.close();
       }
     } finally {
       inputStream.close();
     }
   } catch (Exception e) {
     LogUtils.e("failed to copy " + logFileName, e);
     return "\n" + "failed to copy " + logFileName + "\n" + e;
   }
   return "";
 }
示例#10
0
 private String createLogFiles() {
   if (!new File(LOG_DIR).exists()) {
     new File(LOG_DIR).mkdir();
   }
   String error = "";
   try {
     ShellUtils.sudo(ShellUtils.findCommand("getprop"), ">", LOG_DIR + "/getprop.log");
   } catch (Exception e) {
     LogUtils.e("failed to execute getprop", e);
     error += "\n" + "failed to execute getprop" + "\n" + e;
   }
   try {
     ShellUtils.sudo(
         ShellUtils.findCommand("logcat"),
         "-d",
         "-v",
         "time",
         "-s",
         "fqrouter:V",
         ">",
         LOG_DIR + "/logcat.log");
   } catch (Exception e) {
     LogUtils.e("failed to execute logcat", e);
     error += "\n" + "failed to execute logcat" + "\n" + e;
   }
   try {
     ShellUtils.sudo(
         ShellUtils.findCommand("iptables"), "-L", "-v", "-n", ">", LOG_DIR + "/iptables.log");
   } catch (Exception e) {
     LogUtils.e("failed to execute iptables for filter table", e);
     error += "\n" + "failed to execute iptables for filter table" + "\n" + e;
   }
   try {
     ShellUtils.sudo(
         ShellUtils.findCommand("iptables"),
         "-t",
         "nat",
         "-L",
         "-v",
         "-n",
         ">>",
         LOG_DIR + "/iptables.log");
   } catch (Exception e) {
     LogUtils.e("failed to execute iptables for nat table", e);
     error += "\n" + "failed to execute iptables for nat table" + "\n" + e;
   }
   try {
     ShellUtils.sudo(
         "/data/data/fq.router2/busybox", "chmod", "0666", "/data/data/fq.router2/log/*.log");
   } catch (Exception e) {
     LogUtils.e("failed to change log file permission", e);
     error += "\n" + "failed to change log file permission using busybox chmod" + "\n" + e;
     try {
       ShellUtils.sudo(ShellUtils.findCommand("chmod"), "0666", "/data/data/fq.router2/log/*.log");
     } catch (Exception e2) {
       LogUtils.e("failed to change log file permission", e2);
       error += "\n" + "failed to change log file permission using system chmod" + "\n" + e2;
     }
   }
   error += copyLog("manager.log");
   error += copyLog("fqsocks.log");
   error += copyLog("fqsocks.log.1");
   error += copyLog("fqdns.log");
   error += copyLog("fqting.log");
   error += copyLog("fqlan.log");
   error += copyLog("scan.log");
   error += copyLog("wifi.log");
   error += copyLog("wifi.log.1");
   error += copyLog("current-java.log");
   error += copyLog("current-python.log");
   return error;
 }