<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

let DEBUG = 1;
if (DEBUG) debug = function(s) {
  dump("-*- adb service worker: " + s + "\n");
};
else
debug = function(s) {};

var device = '';
var ADB_PATH = '';
var LOCAL_PORT = 10010;
var REMOTE_PORT = 10010;
let detectingInterval = null;

var libadb = (function() {
  let library = null;
  let runCmd = null;

  return {
    loadLib: function(path) {
      debug('Lib path: ' + path);
      if (library) {
        return;
      }
      library = ctypes.open(path);
      runCmd = library.declare('runCmd', ctypes.default_abi, ctypes.char.ptr, ctypes.char.ptr);
    },

    findDevice: function() {
      if (runCmd != null) {
        if (ADB_PATH != '') {
          return runCmd(ADB_PATH + ' devices');
        }
      }
      return null;
    },

    setupDevice: function() {
      if (runCmd != null) {
        if (ADB_PATH != '') {
          if (device != '') return runCmd(ADB_PATH + ' -s ' + device + ' forward tcp:' + LOCAL_PORT + ' tcp:' + REMOTE_PORT);
          else
          return runCmd(ADB_PATH + ' forward tcp:' + LOCAL_PORT + ' tcp:' + REMOTE_PORT);
        }
      }
      return null;
    },

    startAdbServer: function() {
      if (runCmd != null) {
        if (ADB_PATH != '') {
          return runCmd(ADB_PATH + ' start-server');
        }
      }
      return null;
    },

    killAdbServer: function() {
      debug('killAdbServer ' + ADB_PATH);
      debug('killAdbServer ' + runCmd);
      if (runCmd != null) {
        if (ADB_PATH != '') {
          return runCmd('adb kill-server');
        }
      }
      return null;
    },

    listAdbService: function() {
      if (runCmd) {
        var pinfo = runCmd('cmd.exe /c netstat -ano | findstr 5037');
        var plisten = pinfo.indexOf("LISTENING");
        if (plisten > 0) {
          var pid = plisten.substring("LISTENING", "\r\n");
          return runCmd('cmd.exe /c Tasklist | findstr ' + pid);<commit_msg>fix adb killserver<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

let DEBUG = 1;
if (DEBUG) debug = function(s) {
  dump("-*- adb service worker: " + s + "\n");
};
else
debug = function(s) {};

var device = '';
var ADB_PATH = '';
var LOCAL_PORT = 10010;
var REMOTE_PORT = 10010;
let detectingInterval = null;

var libadb = (function() {
  let library = null;
  let runCmd = null;

  return {
    loadLib: function(path) {
      debug('Lib path: ' + path);
      if (library) {
        return;
      }
      library = ctypes.open(path);
      runCmd = library.declare('runCmd', ctypes.default_abi, ctypes.char.ptr, ctypes.char.ptr);
    },

    findDevice: function() {
      if (runCmd != null) {
        if (ADB_PATH != '') {
          return runCmd(ADB_PATH + ' devices');
        }
      }
      return null;
    },

    setupDevice: function() {
      if (runCmd != null) {
        if (ADB_PATH != '') {
          if (device != '') return runCmd(ADB_PATH + ' -s ' + device + ' forward tcp:' + LOCAL_PORT + ' tcp:' + REMOTE_PORT);
          else
          return runCmd(ADB_PATH + ' forward tcp:' + LOCAL_PORT + ' tcp:' + REMOTE_PORT);
        }
      }
      return null;
    },

    startAdbServer: function() {
      if (runCmd != null) {
        if (ADB_PATH != '') {
          return runCmd(ADB_PATH + ' start-server');
        }
      }
      return null;
    },

    killAdbServer: function() {
      debug('killAdbServer ' + ADB_PATH);
      debug('killAdbServer ' + runCmd);
      if (runCmd != null) {
        if (ADB_PATH != '') {
          return runCmd(ADB_PATH + ' kill-server');
        }
      }
      return null;
    },

    listAdbService: function() {
      if (runCmd) {
        var pinfo = runCmd('cmd.exe /c netstat -ano | findstr 5037');
        var plisten = pinfo.indexOf("LISTENING");
        if (plisten > 0) {
          var pid = plisten.substring("LISTENING", "\r\n");
          return runCmd('cmd.exe /c Tasklist | findstr ' + pid);
{'fraction_non_alphanumeric': 0.14848698099929628, 'fraction_numerical': 0.009383063570255689, 'mean_word_length': 2.110138584974471, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4180416', 'n_tokens_mistral': 1463, 'n_tokens_neox': 1398, 'n_words': 371}