Skip to content

Commit 596d17d

Browse files
e-khalilovDaniilSmirnovirdkwmnsbe.khalilovAlk2017
authored
Minitouch refactoring (#388)
* Develop to Master for 1.5.1 (#364) * Wire initial typescript (#338) * Wire initial typescript * Fix types * Something works * Finishing touches * Linter fixes * Build problems * hotfix (#361) Co-authored-by: e.khalilov <e.khalilov@vkteam.ru> * Remove all DB connections from device side (#368) * hotfix imei * Decrease apt install list in dockerfile (#365) * remove gm and jdk11 * remove libs * Remove console-feed & react dependencies [backend only] (#366) * remove dep console-feed * minor fix * linter fix --------- Co-authored-by: e.khalilov <e.khalilov@vkteam.ru> * fix default quotas hierarchy QA-19255 (#367) * -fix quotas -fix lock -fix test -fix lint * -fix test --------- Co-authored-by: a.chistov <a.chistov@vk.team> * dev units without db conn * fix types * minor fix * minor fix * minor fix * remove useless sockets --------- Co-authored-by: Maksim Alzhanov <m.alzhanov@vk.team> Co-authored-by: Maxim <me@alzhanov.ru> Co-authored-by: Daniil <8039921+DaniilSmirnov@users.noreply.github.com> Co-authored-by: e.khalilov <e.khalilov@vkteam.ru> Co-authored-by: Alexey Chistov <33050834+Alk2017@users.noreply.github.com> Co-authored-by: a.chistov <a.chistov@vk.team> * fix device type & types (#374) Co-authored-by: e.khalilov <e.khalilov@vkteam.ru> * reconnect in ADBObserver (#376) Co-authored-by: e.khalilov <e.khalilov@vkteam.ru> * QA-10057 Remove users watcher groups-engine (#369) * -fix after rebase -remove user watcher -user handler for alert message default quotas handler -fix merge del handler update quoats handler user handler method some fix -move without change method of devices to separate class -fix after move users method -move db.users method to separate class * add missing db method --------- Co-authored-by: a.chistov <a.chistov@vk.team> Co-authored-by: e.khalilov <e.khalilov@vkteam.ru> * fix heartbeat (#377) Co-authored-by: e.khalilov <e.khalilov@vkteam.ru> * overrides dependencies (#378) Co-authored-by: e.khalilov <e.khalilov@vkteam.ru> * Automatic removal of disabled devices (#379) * clear dead devices * minor fix * revert api edits * revert ui (types) edits --------- Co-authored-by: e.khalilov <e.khalilov@vkteam.ru> * fix linkifyjs issue (#380) Co-authored-by: e.khalilov <e.khalilov@vkteam.ru> * Resolve conflicts (#381) * Hotfix: device imei issue (#371) * hotfix * minor fix * fix types * minor fix --------- Co-authored-by: e.khalilov <e.khalilov@vkteam.ru> * increase ram for v8 (#372) * hotfix (#373) Co-authored-by: e.khalilov <e.khalilov@vkteam.ru> * hotfix ADBObserver (#375) Co-authored-by: e.khalilov <e.khalilov@vkteam.ru> --------- Co-authored-by: e.khalilov <e.khalilov@vkteam.ru> Co-authored-by: Daniil <8039921+DaniilSmirnov@users.noreply.github.com> * Fixed transactions & minor optimizations (#382) * minor edits * fix transactions * minor fix * fix ts types --------- Co-authored-by: e.khalilov <e.khalilov@vkteam.ru> * Fix lint issues --------- Co-authored-by: Maxim <me@alzhanov.ru> Co-authored-by: Elmir Khalilov <52529096+e-khalilov@users.noreply.github.com> Co-authored-by: e.khalilov <e.khalilov@vkteam.ru> Co-authored-by: Maksim Alzhanov <m.alzhanov@vk.team> Co-authored-by: Alexey Chistov <33050834+Alk2017@users.noreply.github.com> Co-authored-by: a.chistov <a.chistov@vk.team> * Hotfix: Fix broken import in ios Co-authored-by: e.khalilov <e.khalilov@vkteam.ru> * minitouch refactoring + TS --------- Co-authored-by: Daniil <8039921+DaniilSmirnov@users.noreply.github.com> Co-authored-by: Maxim <me@alzhanov.ru> Co-authored-by: e.khalilov <e.khalilov@vkteam.ru> Co-authored-by: Maksim Alzhanov <m.alzhanov@vk.team> Co-authored-by: Alexey Chistov <33050834+Alk2017@users.noreply.github.com> Co-authored-by: a.chistov <a.chistov@vk.team>
1 parent 34ccd1d commit 596d17d

9 files changed

Lines changed: 826 additions & 621 deletions

File tree

lib/units/device/plugins/touch/index.js

Lines changed: 0 additions & 473 deletions
This file was deleted.

lib/units/device/plugins/touch/index.ts

Lines changed: 642 additions & 0 deletions
Large diffs are not rendered by default.

lib/units/device/resources/minitouch.js

Lines changed: 0 additions & 75 deletions
This file was deleted.
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import util from 'util'
2+
import fs from 'fs'
3+
import syrup from '@devicefarmer/stf-syrup'
4+
import type {Client} from '@u4/adbkit'
5+
import logger from '../../../util/logger.js'
6+
import * as pathutil from '../../../util/pathutil.cjs'
7+
import devutil from '../../../util/devutil.js'
8+
import Resource from './util/resource.js'
9+
import adb from '../support/adb.js'
10+
import abi from '../support/abi.js'
11+
import lifecycle from '../../../util/lifecycle.js'
12+
13+
interface MinitouchOptions {
14+
serial: string
15+
}
16+
17+
interface MinitouchResource {
18+
bin: Resource
19+
}
20+
21+
interface MinitouchResult {
22+
bin: string
23+
run: (cmd?: string) => Promise<NodeJS.ReadableStream>
24+
}
25+
26+
export default syrup.serial()
27+
.dependency(adb)
28+
.dependency(abi)
29+
.dependency(devutil)
30+
.define(async (options: MinitouchOptions, adb: Client, abi: any, devutil: any): Promise<MinitouchResult> => {
31+
const log = logger.createLogger('device:resources:minitouch')
32+
const resources: MinitouchResource = {
33+
bin: new Resource({
34+
src: pathutil.requiredMatch(abi.all.map((supportedAbi: string) =>
35+
pathutil.module(util.format('@devicefarmer/minitouch-prebuilt/prebuilt/%s/bin/minitouch%s', supportedAbi, abi.pie ? '' : '-nopie'))
36+
)),
37+
dest: [
38+
'/data/local/tmp/minitouch',
39+
'/data/data/com.android.shell/minitouch'
40+
],
41+
comm: 'minitouch',
42+
mode: 0o755
43+
})
44+
}
45+
46+
const removeResource = async (res: Resource) => {
47+
await adb.getDevice(options.serial).execOut(['rm', '-f', res.dest])
48+
}
49+
50+
const pushResource = async (res: Resource) => {
51+
const transfer = await adb.getDevice(options.serial).push(res.src, res.dest, res.mode)
52+
await transfer.waitForEnd()
53+
}
54+
55+
const checkExecutable = async (res: Resource) => {
56+
const stats = await adb.getDevice(options.serial).stat(res.dest)
57+
return (stats.mode & fs.constants.S_IXUSR) === fs.constants.S_IXUSR
58+
}
59+
60+
const installResource = async (res: Resource): Promise<void> => {
61+
if (await checkExecutable(res)) return;
62+
63+
log.info('Installing "%s" as "%s"', res.src, res.dest)
64+
65+
await removeResource(res)
66+
await pushResource(res)
67+
const ok = await checkExecutable(res)
68+
69+
if (!ok) {
70+
log.error('Pushed "%s" not executable, attempting fallback location', res.comm)
71+
res.shift()
72+
return installResource(res)
73+
}
74+
}
75+
76+
const plugin = {
77+
bin: resources.bin.dest,
78+
run: (cmd?: string) =>
79+
adb.getDevice(options.serial).shell(`exec ${resources.bin.dest} ${cmd || ''}`),
80+
81+
stop: async () => {
82+
const pid = (await adb.getDevice(options.serial).execOut('pidof minitouch')).toString().trim()
83+
if (!pid?.length) return;
84+
85+
log.info('Stopping minitouch process %s', pid)
86+
return adb.getDevice(options.serial).execOut(['kill', '-9', pid])
87+
}
88+
}
89+
90+
lifecycle.observe(() => plugin.stop())
91+
92+
await plugin.stop()
93+
await installResource(resources.bin)
94+
95+
return plugin
96+
})

lib/units/ios-device/plugins/install.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {v4 as uuidv4} from 'uuid'
22
import syrup from '@devicefarmer/stf-syrup'
33
import logger from '../../../util/logger.js'
4-
import wire from '../../../wire/index.js'
54
import wireutil from '../../../wire/util.js'
65
import Promise from 'bluebird'
76
import {exec} from 'child_process'
@@ -10,7 +9,7 @@ import router from '../../base-device/support/router.js'
109
import push from '../../base-device/support/push.js'
1110
import storage from '../../base-device/support/storage.js'
1211
import deviceutil from '../../../util/deviceutil.js'
13-
import {InstallMessage} from '../../../wire/wire.js'
12+
import {InstallMessage, UninstallIosMessage} from '../../../wire/wire.js'
1413

1514
function execShellCommand(cmd) {
1615
return new Promise((resolve, reject) => {

lib/util/failcounter.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

lib/util/failcounter.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import EventEmitter from 'events'
2+
3+
class FailCounter extends EventEmitter {
4+
private threshold: number
5+
private time: number
6+
private values: number[] = []
7+
8+
constructor(threshold: number, time: number) {
9+
super()
10+
this.threshold = threshold
11+
this.time = time
12+
}
13+
14+
inc(): void {
15+
const now = Date.now()
16+
while (this.values.length) {
17+
if (now - this.values[0] >= this.time) {
18+
this.values.shift()
19+
} else {
20+
break
21+
}
22+
}
23+
this.values.push(now)
24+
if (this.values.length > this.threshold) {
25+
this.emit('exceedLimit', this.threshold, this.time)
26+
}
27+
}
28+
}
29+
30+
export default FailCounter
31+

lib/util/riskystream.js

Lines changed: 0 additions & 46 deletions
This file was deleted.

lib/util/riskystream.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import EventEmitter from 'events'
2+
3+
class RiskyStream extends EventEmitter {
4+
stream: NodeJS.ReadableStream | NodeJS.WritableStream | any
5+
expectingEnd: boolean = false
6+
ended: boolean = false
7+
private endListener: () => void
8+
9+
constructor(stream: NodeJS.ReadableStream | NodeJS.WritableStream | any) {
10+
super()
11+
12+
this.endListener = () => {
13+
this.ended = true
14+
this.stream.removeListener('end', this.endListener)
15+
if (!this.expectingEnd) {
16+
this.emit('unexpectedEnd')
17+
}
18+
this.emit('end')
19+
}
20+
21+
this.stream = stream.on('end', this.endListener)
22+
}
23+
24+
end(): any {
25+
this.expectEnd()
26+
return this.stream.end()
27+
}
28+
29+
expectEnd(): this {
30+
this.expectingEnd = true
31+
return this
32+
}
33+
34+
async waitForEnd(): Promise<boolean> {
35+
const stream = this.stream
36+
this.expectEnd()
37+
38+
return new Promise<boolean>((resolve) => {
39+
if (stream.ended) {
40+
return resolve(true)
41+
}
42+
43+
const endListener = () => {
44+
stream.removeListener('end', endListener)
45+
resolve(true)
46+
}
47+
48+
stream.on('end', endListener)
49+
// Make sure we actually have a chance to get the 'end' event.
50+
stream.resume()
51+
})
52+
}
53+
}
54+
55+
export default RiskyStream
56+

0 commit comments

Comments
 (0)