Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async pushAppBundle (app, timeout = DEFAULT_ITEM_PUSH_TIMEOUT) {
const timer = new timing.Timer().start();
const afcService = await services.startAfcService(this.udid);
// We are pushing serially due to this https://github.com/appium/appium/issues/13115. There is nothing else we can do besides this
try {
const bundlePathOnPhone = await this.createAppPath(afcService, app);
await fs.walkDir(app, true, async (itemPath, isDir) => {
const pathOnPhone = path.join(bundlePathOnPhone, path.relative(app, itemPath));
if (isDir) {
await afcService.createDirectory(pathOnPhone);
} else {
const readStream = fs.createReadStream(itemPath, {autoClose: true});
const writeStream = await afcService.createWriteStream(pathOnPhone, {autoDestroy: true});
writeStream.on('finish', writeStream.destroy);
const itemPushWait = new B((resolve, reject) => {
writeStream.on('close', resolve);
const onStreamError = (e) => {
readStream.unpipe(writeStream);
reject(e);
this.serverSocket = net.createServer(async (localSocket) => {
try {
const remoteSocket = await utilities.connectPort(this.udid, this.deviceport);
remoteSocket.on('close', () => localSocket.end());
remoteSocket.on('error', (e) => {
// not all remote socket errors are critical for the user
this.log.info(e.message);
this.log.debug(e);
});
localSocket.on('close', () => remoteSocket.end());
localSocket.on('error', (e) => this.log.warn(e.message));
localSocket.pipe(remoteSocket);
remoteSocket.pipe(localSocket);
} catch (e) {
this.log.error(e);
localSocket.end();
}
});
const status = new B((resolve, reject) => {
async getCrashes () {
let crashLogsRoot = this.logDir;
if (this.udid) {
this.phoneName = this.phoneName || await utilities.getDeviceName(this.udid);
crashLogsRoot = path.resolve(crashLogsRoot, this.phoneName);
}
if (!await fs.exists(crashLogsRoot)) {
log.debug(`Crash reports root '${crashLogsRoot}' does not exist. Got nothing to gather.`);
return [];
}
const foundFiles = await fs.glob(`${crashLogsRoot}/**/*.crash`);
if (this.udid) {
return foundFiles;
}
// For Simulator only include files, that contain current UDID
return await B.filter(foundFiles, async (x) => {
try {
const content = await fs.readFile(x, 'utf8');
return content.toUpperCase().includes(this.sim.udid.toUpperCase());
} catch (err) {
this.socket.connect(this.port, this.host);
}
this.socket.setNoDelay(true);
this.socket.setKeepAlive(true);
this.socket.on('close', () => {
if (this.connected) {
log.debug('Debugger socket disconnected');
}
this.connected = false;
this.socket = null;
});
this.socket.on('end', () => {
this.connected = false;
});
this.service = await services.startWebInspectorService(this.udid, {
socket: this.socket,
isSimulator: true,
osVersion: this.platformVersion,
verbose: this.logAllCommunication,
verboseHexDump: this.logAllCommunicationHexDump,
});
this.service.listenMessage(this.receive.bind(this));
// connect the socket
return await new B((resolve, reject) => {
// only resolve this function when we are actually connected
this.socket.on('connect', () => {
log.debug(`Debugger socket connected`);
this.connected = true;
resolve();
async function getAvailableBundleIds (udid) {
const service = await services.startInstallationProxyService(udid);
try {
const applications = await service.listApplications({applicationType: 'User'});
const bundleIds = [];
for (const [key, value] of Object.entries(applications)) {
if (!value.UIFileSharingEnabled) {
continue;
}
bundleIds.push(key);
}
return bundleIds;
} finally {
service.close();
}
}
async isAppInstalled (bundleid) {
const service = await services.startInstallationProxyService(this.udid);
try {
const applications = await service.lookupApplications({ bundleIds: bundleid });
return !!applications[bundleid];
} finally {
service.close();
}
}
async remove (bundleid) {
const service = await services.startInstallationProxyService(this.udid);
try {
await service.uninstallApplication(bundleid);
} finally {
service.close();
}
}
async installApplication (bundlePathOnPhone) {
const notificationService = await services.startNotificationProxyService(this.udid);
const installationService = await services.startInstallationProxyService(this.udid);
const appInstalledNotification = new B((resolve) => {
notificationService.observeNotification(APPLICATION_INSTALLED_NOTIFICATION, {notification: resolve});
});
try {
await installationService.installApplication(bundlePathOnPhone, {PackageType: 'Developer'});
try {
await appInstalledNotification.timeout(APPLICATION_NOTIFICATION_TIMEOUT, `Could not get the application installed notification within ${APPLICATION_NOTIFICATION_TIMEOUT}ms but we will continue`);
} catch (e) {
log.warn(`Failed to receive the notification. Error: ${e.message}`);
}
} finally {
installationService.close();
notificationService.close();
}
}
async getUserInstalledBundleIdsByBundleName (bundleName) {
const service = await services.startInstallationProxyService(this.udid);
try {
const applications = await service.listApplications({applicationType: 'User'});
return _.reduce(applications, (acc, {CFBundleName}, key) => {
if (CFBundleName === bundleName) {
acc.push(key);
}
return acc;
}, []);
} finally {
service.close();
}
}
async function createAfcClient (udid, bundleId, containerType) {
if (!bundleId) {
return await services.startAfcService(udid);
}
const service = await services.startHouseArrestService(udid);
if (isDocuments(containerType)) {
return await service.vendDocuments(bundleId);
} else {
return await service.vendContainer(bundleId);
}
}