mirror of
https://github.com/adelphes/android-dev-ext.git
synced 2025-12-24 18:41:05 +00:00
* add support for timeout on adb socket reads * add debugger support for attaching to a process * add new launch configuration and support for picking an Android process ID * initial support for attaching to android process * display enhanced quick pick list with pids and names * add flag to prevent disconnect messages when not connected * Retrieve all loaded classes during startup. This allows us to identify breakpoints in anonymous classes that are already loaded. * correct name of process picker command * make PickAndroidProcess command private * selectAndroidProcessID always returns an object * make breakpoint setup a loop instead of recursive * tidy some labels and error messages * use a more consistent command for retrieving process names * show pid list sorted by pid instead of name * refactor some Android and ADB-specific functions Check ANDROID_SDK as replacement for ANDROID_HOME * tidy up logcat launch and refactor target device selection * fix logcat not displaying * filter duplicates and blanks from logcat output
88 lines
2.4 KiB
JavaScript
88 lines
2.4 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const { ADBClient } = require('../adbclient');
|
|
const ADBSocket = require('../sockets/adbsocket');
|
|
const { LOG } = require('../utils/print');
|
|
|
|
function getAndroidSDKFolder() {
|
|
// ANDROID_HOME is deprecated
|
|
return process.env.ANDROID_HOME || process.env.ANDROID_SDK;
|
|
}
|
|
|
|
/**
|
|
* @param {string} api_level
|
|
* @param {boolean} check_is_dir
|
|
*/
|
|
function getAndroidSourcesFolder(api_level, check_is_dir) {
|
|
const android_sdk = getAndroidSDKFolder();
|
|
if (!android_sdk) {
|
|
return null;
|
|
}
|
|
const sources_path = path.join(android_sdk,'sources',`android-${api_level}`);
|
|
if (check_is_dir) {
|
|
try {
|
|
const stat = fs.statSync(sources_path);
|
|
if (!stat || !stat.isDirectory()) {
|
|
return null;
|
|
}
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
return sources_path;
|
|
}
|
|
|
|
function getADBPathName() {
|
|
const android_sdk = getAndroidSDKFolder();
|
|
if (!android_sdk) {
|
|
return '';
|
|
}
|
|
return path.join(android_sdk, 'platform-tools', /^win/.test(process.platform)?'adb.exe':'adb');
|
|
}
|
|
|
|
/**
|
|
* @param {number} port
|
|
*/
|
|
function startADBServer(port) {
|
|
if (typeof port !== 'number' || port <= 0 || port >= 65536) {
|
|
return false;
|
|
}
|
|
|
|
const adb_exe_path = getADBPathName();
|
|
if (!adb_exe_path) {
|
|
return false;
|
|
}
|
|
const adb_start_server_args = ['-P',`${port}`,'start-server'];
|
|
try {
|
|
LOG([adb_exe_path, ...adb_start_server_args].join(' '));
|
|
const stdout = require('child_process').execFileSync(adb_exe_path, adb_start_server_args, {
|
|
cwd: getAndroidSDKFolder(),
|
|
encoding:'utf8',
|
|
});
|
|
LOG(stdout);
|
|
return true;
|
|
} catch (ex) {} // if we fail, it doesn't matter - the device query will fail and the user will have to work it out themselves
|
|
return false
|
|
}
|
|
|
|
/**
|
|
* @param {boolean} auto_start
|
|
*/
|
|
async function checkADBStarted(auto_start) {
|
|
const err = await new ADBClient().test_adb_connection();
|
|
// if adb is not running, see if we can start it ourselves using ANDROID_HOME (and a sensible port number)
|
|
if (err && auto_start) {
|
|
return startADBServer(ADBSocket.ADBPort);
|
|
}
|
|
return !err;
|
|
}
|
|
|
|
module.exports = {
|
|
checkADBStarted,
|
|
getADBPathName,
|
|
getAndroidSDKFolder,
|
|
getAndroidSourcesFolder,
|
|
startADBServer,
|
|
}
|