Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/cli/device/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ export const builder = function(yargs) {
type: 'boolean',
default: false
})
.option('need-vnc', {
describe: 'Need a running VNC server',
type: 'boolean',
default: false
})
.option('device-name', {
describe: 'Device name',
type: 'string',
Expand Down Expand Up @@ -240,6 +245,7 @@ export const handler = function(argv) {
urlWithoutAdbPort: argv.urlWithoutAdbPort,
deviceCode: argv.deviceCode,
secret: argv.secret,
disableLogsOverWire: argv.disableLogsOverWire
disableLogsOverWire: argv.disableLogsOverWire,
needVnc: argv.needVnc
})
}
10 changes: 8 additions & 2 deletions lib/cli/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ export const builder = function(yargs) {
type: 'boolean',
default: false
})
.option('need-vnc', {
describe: 'Need a running VNC server',
type: 'boolean',
default: false
})
.option('vnc-port', {
describe: 'Port allocated to VNC connections.',
type: 'number',
Expand Down Expand Up @@ -240,7 +245,7 @@ export const handler = function(argv) {
},
allowRemote: argv.allowRemote,
fork: function(device, ports) {
var args = [
const args = [
'device',
'--serial', device.serial,
'--device-name', argv.deviceName,
Expand Down Expand Up @@ -268,7 +273,8 @@ export const handler = function(argv) {
'--url-without-adb-port', argv.urlWithoutAdbPort,
'--device-code', argv.deviceCode,
'--secret', argv.secret,
'--disable-logs-over-wire', argv.disableLogsOverWire
'--disable-logs-over-wire', argv.disableLogsOverWire,
'--need-vnc', argv.needVnc
]
.concat(argv.connectSub.reduce(function(all, val) {
return all.concat(['--connect-sub', val])
Expand Down
2 changes: 1 addition & 1 deletion lib/units/base-device/support/connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default syrup.serial()

/** @param {ConnectorInitOptions} opt*/
init({handlers, serial, storageUrl, deviceType, urlWithoutAdbPort}) {
this.handlers = handlers
this.handlers = {start: handlers.start, stop: handlers.stop}
this.serial = serial
this.reply = wireutil.reply(serial)
this.storageUrl = storageUrl
Expand Down
33 changes: 24 additions & 9 deletions lib/units/device/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ import sd from './plugins/sd.js'
import filesystem from './plugins/filesystem.js'
import mobileService from './plugins/mobile-service.js'
import remotedebug from './plugins/remotedebug.js'
import vnc from './plugins/vnc/index.js'
import {trackModuleReadyness} from './readyness.js'
import wireutil from '../../wire/util.js'
import wire from '../../wire/index.js'
import wireutil, {DEVICE_STATUS_MAP} from '../../wire/util.js'
import push from '../base-device/support/push.js'
import adb from './support/adb.js'
import router from '../base-device/support/router.js'
import {DeviceIntroductionMessage, DeviceRegisteredMessage, ProviderMessage} from "../../wire/wire.js";

export default (function(options: any) {
return syrup.serial()
Expand All @@ -51,19 +52,28 @@ export default (function(options: any) {
let listener: ((...args: any[]) => void) | null = null
const waitRegister = Promise.race([
new Promise(resolve =>
router.on(wire.DeviceRegisteredMessage, listener = (...args: any[]) => resolve(args))
router.on(DeviceRegisteredMessage, listener = (...args: any[]) => resolve(args))
),
new Promise(r => setTimeout(r, 15000))
])

const type = await adb.getDevice(options.serial).getState()
push?.send([
wireutil.global,
wireutil.envelope(new wire.DeviceIntroductionMessage(options.serial, wireutil.toDeviceStatus(type), new wire.ProviderMessage(solo.channel, `standalone-${options.serial}`)))
wireutil.pack(DeviceIntroductionMessage, {
serial: options.serial,

// TODO: Verify that @u4/adbkit statuses are correct
status: wireutil.toDeviceStatus(type as keyof typeof DEVICE_STATUS_MAP),
provider: ProviderMessage.create({
channel: solo.channel,
name: `standalone-${options.serial}`
})
})
])

await waitRegister
router.removeListener(wire.DeviceRegisteredMessage, listener!)
router.removeListener(DeviceRegisteredMessage, listener!)
listener = null
}

Expand All @@ -72,17 +82,18 @@ export default (function(options: any) {
.dependency(trackModuleReadyness('stream', stream))
.dependency(trackModuleReadyness('capture', capture))
.dependency(trackModuleReadyness('service', service))
.dependency(trackModuleReadyness('shell', shell))
.dependency(trackModuleReadyness('touch', touch))
.dependency(trackModuleReadyness('group', group))
.dependency(trackModuleReadyness('vnc', vnc))
.dependency(trackModuleReadyness('browser', browser))
.dependency(trackModuleReadyness('store', store))
.dependency(trackModuleReadyness('airplane', airplane))
.dependency(trackModuleReadyness('clipboard', clipboard))
.dependency(trackModuleReadyness('logcat', logcat))
.dependency(trackModuleReadyness('mute', mute))
.dependency(trackModuleReadyness('shell', shell))
.dependency(trackModuleReadyness('touch', touch))
.dependency(trackModuleReadyness('install', install))
.dependency(trackModuleReadyness('forward', forward))
.dependency(trackModuleReadyness('group', group))
.dependency(trackModuleReadyness('cleanup', cleanup))
.dependency(trackModuleReadyness('reboot', reboot))
.dependency(trackModuleReadyness('connect', connect))
Expand All @@ -94,7 +105,11 @@ export default (function(options: any) {
.dependency(trackModuleReadyness('filesystem', filesystem))
.dependency(trackModuleReadyness('mobileService', mobileService))
.dependency(trackModuleReadyness('remotedebug', remotedebug))
.define((options, heartbeat) => {
.define((options, heartbeat, stream, capture, service, shell, touch, group, vnc) => {
if (options.needVnc) {
vnc.start()
}

if (process.send) {
// Only if we have a parent process
process.send('ready')
Expand Down
69 changes: 0 additions & 69 deletions lib/units/device/plugins/cleanup.js

This file was deleted.

78 changes: 78 additions & 0 deletions lib/units/device/plugins/cleanup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import syrup from '@devicefarmer/stf-syrup'
import logger from '../../../util/logger.js'
import adb from '../support/adb.js'
import group from './group.js'
import service$0 from './service.js'

export default syrup.serial()
.dependency(adb)
.dependency(group)
.dependency(service$0)
.define(async(options, adb, group, service) => {
if (!options.cleanup) {
return
}

const log = logger.createLogger('device:plugins:cleanup')

const getInstalledApps = async() => (
await adb.getDevice(options.serial).execOut('pm list packages -3') || ''
)
.toString()
.trim()
.split('\n')
.map(pkg => pkg.trim().substring(8))

const checkpoint = await getInstalledApps()
log.info('Saved checkpoint of installed apps: %s', checkpoint.join(', '))

const uninstall = (pkg: string) => {
try {
log.info('Cleaning up package "%s"', pkg)
return adb.getDevice(options.serial).uninstall(pkg)
} catch (err: any) {
log.warn('Unable to clean up package "%s": %s', pkg, err?.message)
}
}

const removePackages = async() => {
const apps = await getInstalledApps()
const newApps = apps.filter(app => !checkpoint.includes(app))

if (!newApps.length) return
log.info('Cleaning: %s', newApps.join(', '))

for (const pkg of newApps) {
await uninstall(pkg)
}

log.info('Cleaning completed')
}

const disableBluetooth = async() => {
if (!options.cleanupDisableBluetooth) {
return
}

const enabled = await service.getBluetoothStatus()
if (enabled) {
log.info('Disabling Bluetooth')
return service.setBluetoothEnabled(false)
}
}

const cleanBluetoothBonds = () => {
if (!options.cleanupBluetoothBonds) {
return
}

log.info('Cleanup Bluetooth bonds')
return service.cleanBluetoothBonds()
}

group.on('leave', async() => {
await removePackages()
await cleanBluetoothBonds()
await disableBluetooth()
})
})
5 changes: 0 additions & 5 deletions lib/units/device/plugins/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@ export default syrup.serial()
service.sendCommand('pm clear com.android.chrome'),
service.sendCommand('pm clear com.chrome.beta'),
service.sendCommand('pm clear com.sec.android.app.sbrowser'),
service.sendCommand('pm uninstall com.vkontakte.android'),
service.sendCommand('pm uninstall com.vk.im'),
service.sendCommand('pm uninstall com.vk.clips'),
service.sendCommand('pm uninstall com.vk.calls'),
service.sendCommand('pm uninstall com.vk.admin'),
service.sendCommand('pm clear com.mi.globalbrowser'),
service.sendCommand('pm clear com.microsoft.emmx'),
service.sendCommand('pm clear com.huawei.browser'),
Expand Down
Loading
Loading