PHP WebShell
Текущая директория: /usr/lib/node_modules/bitgo/node_modules/@expo/cli/build/src/start/platforms/android
Просмотр файла: adb.js
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getServer = getServer;
exports.logUnauthorized = logUnauthorized;
exports.isPackageInstalledAsync = isPackageInstalledAsync;
exports.launchActivityAsync = launchActivityAsync;
exports.openAppIdAsync = openAppIdAsync;
exports.openUrlAsync = openUrlAsync;
exports.uninstallAsync = uninstallAsync;
exports.getPackageInfoAsync = getPackageInfoAsync;
exports.installAsync = installAsync;
exports.adbArgs = adbArgs;
exports.getAttachedDevicesAsync = getAttachedDevicesAsync;
exports.getAdbNameForDeviceIdAsync = getAdbNameForDeviceIdAsync;
exports.isDeviceBootedAsync = isDeviceBootedAsync;
exports.isBootAnimationCompleteAsync = isBootAnimationCompleteAsync;
exports.getDeviceABIsAsync = getDeviceABIsAsync;
exports.getPropertyDataForDeviceAsync = getPropertyDataForDeviceAsync;
exports.DeviceABI = void 0;
var _chalk = _interopRequireDefault(require("chalk"));
var _os = _interopRequireDefault(require("os"));
var Log = _interopRequireWildcard(require("../../../log"));
var _errors = require("../../../utils/errors");
var _link = require("../../../utils/link");
var _adbserver = require("./ADBServer");
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
function _interopRequireWildcard(obj) {
if (obj && obj.__esModule) {
return obj;
} else {
var newObj = {};
if (obj != null) {
for(var key in obj){
if (Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
if (desc.get || desc.set) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
}
}
newObj.default = obj;
return newObj;
}
}
var DeviceABI;
exports.DeviceABI = DeviceABI;
(function(DeviceABI) {
DeviceABI[// The arch specific android target platforms are soft-deprecated.
// Instead of using TargetPlatform as a combination arch + platform
// the code will be updated to carry arch information in [DarwinArch]
// and [AndroidArch].
"arm"] = "arm";
DeviceABI["arm64"] = "arm64";
DeviceABI["x64"] = "x64";
DeviceABI["x86"] = "x86";
DeviceABI["armeabiV7a"] = "armeabi-v7a";
DeviceABI["armeabi"] = "armeabi";
DeviceABI["universal"] = "universal";
})(DeviceABI || (exports.DeviceABI = DeviceABI = {}));
const CANT_START_ACTIVITY_ERROR = "Activity not started, unable to resolve Intent";
// http://developer.android.com/ndk/guides/abis.html
const PROP_CPU_NAME = "ro.product.cpu.abi";
const PROP_CPU_ABI_LIST_NAME = "ro.product.cpu.abilist";
// Can sometimes be null
// http://developer.android.com/ndk/guides/abis.html
const PROP_BOOT_ANIMATION_STATE = "init.svc.bootanim";
let _server;
function getServer() {
_server != null ? _server : _server = new _adbserver.ADBServer();
return _server;
}
function logUnauthorized(device) {
Log.warn(`\nThis computer is not authorized for developing on ${_chalk.default.bold(device.name)}. ${_chalk.default.dim((0, _link).learnMore("https://expo.fyi/authorize-android-device"))}`);
}
async function isPackageInstalledAsync(device, androidPackage) {
const packages = await getServer().runAsync(adbArgs(device.pid, "shell", "pm", "list", "packages", androidPackage));
const lines = packages.split(/\r?\n/);
for(let i = 0; i < lines.length; i++){
const line = lines[i].trim();
if (line === `package:${androidPackage}`) {
return true;
}
}
return false;
}
async function launchActivityAsync(device, { launchActivity }) {
return openAsync(adbArgs(device.pid, "shell", "am", "start", "-a", "android.intent.action.RUN", // FLAG_ACTIVITY_SINGLE_TOP -- If set, the activity will not be launched if it is already running at the top of the history stack.
"-f", "0x20000000", // Activity to open first: com.bacon.app/.MainActivity
"-n", launchActivity));
}
async function openAppIdAsync(device, { applicationId }) {
return openAsync(adbArgs(device.pid, "shell", "monkey", "-p", applicationId, "-c", "android.intent.category.LAUNCHER", "1"));
}
async function openUrlAsync(device, { url }) {
return openAsync(adbArgs(device.pid, "shell", "am", "start", "-a", "android.intent.action.VIEW", "-d", url));
}
/** Runs a generic command watches for common errors in order to throw with an expected code. */ async function openAsync(args) {
const results = await getServer().runAsync(args);
if (results.includes(CANT_START_ACTIVITY_ERROR) || results.match(/Error: Activity class .* does not exist\./g)) {
throw new _errors.CommandError("APP_NOT_INSTALLED", results.substring(results.indexOf("Error: ")));
}
return results;
}
async function uninstallAsync(device, { appId }) {
return await getServer().runAsync(adbArgs(device.pid, "uninstall", appId));
}
async function getPackageInfoAsync(device, { appId }) {
return await getServer().runAsync(adbArgs(device.pid, "shell", "dumpsys", "package", appId));
}
async function installAsync(device, { filePath }) {
// TODO: Handle the `INSTALL_FAILED_INSUFFICIENT_STORAGE` error.
return await getServer().runAsync(adbArgs(device.pid, "install", "-r", "-d", filePath));
}
function adbArgs(pid, ...options) {
const args = [];
if (pid) {
args.push("-s", pid);
}
return args.concat(options);
}
async function getAttachedDevicesAsync() {
const output = await getServer().runAsync([
"devices",
"-l"
]);
const splitItems = output.trim().replace(/\n$/, "").split(_os.default.EOL);
// First line is `"List of devices attached"`, remove it
// @ts-ignore: todo
const attachedDevices = splitItems.slice(1, splitItems.length).map((line)=>{
// unauthorized: ['FA8251A00719', 'unauthorized', 'usb:338690048X', 'transport_id:5']
// authorized: ['FA8251A00719', 'device', 'usb:336592896X', 'product:walleye', 'model:Pixel_2', 'device:walleye', 'transport_id:4']
// emulator: ['emulator-5554', 'offline', 'transport_id:1']
const props = line.split(" ").filter(Boolean);
const isAuthorized = props[1] !== "unauthorized";
const type = line.includes("emulator") ? "emulator" : "device";
return {
props,
type,
isAuthorized
};
}).filter(({ props: [pid] })=>!!pid
);
const devicePromises = attachedDevices.map(async (props)=>{
const { type , props: [pid, ...deviceInfo] , isAuthorized , } = props;
let name = null;
if (type === "device") {
if (isAuthorized) {
// Possibly formatted like `model:Pixel_2`
// Transform to `Pixel_2`
const modelItem = deviceInfo.find((info)=>info.includes("model:")
);
if (modelItem) {
name = modelItem.replace("model:", "");
}
}
// unauthorized devices don't have a name available to read
if (!name) {
// Device FA8251A00719
name = `Device ${pid}`;
}
} else {
var ref;
// Given an emulator pid, get the emulator name which can be used to start the emulator later.
name = (ref = await getAdbNameForDeviceIdAsync({
pid
})) != null ? ref : "";
}
return {
pid,
name,
type,
isAuthorized,
isBooted: true
};
});
return Promise.all(devicePromises);
}
async function getAdbNameForDeviceIdAsync(device) {
const results = await getServer().runAsync(adbArgs(device.pid, "emu", "avd", "name"));
if (results.match(/could not connect to TCP port .*: Connection refused/)) {
// Can also occur when the emulator does not exist.
throw new _errors.CommandError("EMULATOR_NOT_FOUND", results);
}
var ref;
return (ref = results.trim().split(/\r?\n/).shift()) != null ? ref : null;
}
async function isDeviceBootedAsync({ name } = {}) {
const devices = await getAttachedDevicesAsync();
if (!name) {
var ref;
return (ref = devices[0]) != null ? ref : null;
}
var ref1;
return (ref1 = devices.find((device)=>device.name === name
)) != null ? ref1 : null;
}
async function isBootAnimationCompleteAsync(pid) {
try {
const props = await getPropertyDataForDeviceAsync({
pid
}, PROP_BOOT_ANIMATION_STATE);
return !!props[PROP_BOOT_ANIMATION_STATE].match(/stopped/);
} catch {
return false;
}
}
async function getDeviceABIsAsync(device) {
const cpuAbiList = (await getPropertyDataForDeviceAsync(device, PROP_CPU_ABI_LIST_NAME))[PROP_CPU_ABI_LIST_NAME];
if (cpuAbiList) {
return cpuAbiList.trim().split(",");
}
const abi = (await getPropertyDataForDeviceAsync(device, PROP_CPU_NAME))[PROP_CPU_NAME];
return [
abi
];
}
async function getPropertyDataForDeviceAsync(device, prop) {
// @ts-ignore
const propCommand = adbArgs(...[
device.pid,
"shell",
"getprop",
prop
].filter(Boolean));
try {
// Prevent reading as UTF8.
const results = await getServer().getFileOutputAsync(propCommand);
// Like:
// [wifi.direct.interface]: [p2p-dev-wlan0]
// [wifi.interface]: [wlan0]
if (prop) {
Log.debug(`[ADB] property data: (device pid: ${device.pid}, prop: ${prop}, data: ${results})`);
return {
[prop]: results
};
}
const props = parseAdbDeviceProperties(results);
Log.debug(`[ADB] parsed data:`, props);
return props;
} catch (error) {
// TODO: Ensure error has message and not stderr
throw new _errors.CommandError(`Failed to get properties for device (${device.pid}): ${error.message}`);
}
}
function parseAdbDeviceProperties(devicePropertiesString) {
const properties = {};
const propertyExp = /\[(.*?)\]: \[(.*?)\]/gm;
for (const match of devicePropertiesString.matchAll(propertyExp)){
properties[match[1]] = match[2];
}
return properties;
}
//# sourceMappingURL=adb.js.mapВыполнить команду
Для локальной разработки. Не используйте в интернете!