mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-20 15:55:16 +02:00
Save devices to database.
This commit is contained in:
@@ -1,33 +1,68 @@
|
||||
module.exports = {
|
||||
makeIdentity: function(serial, properties) {
|
||||
var model = properties['ro.product.model']
|
||||
, brand = properties['ro.product.brand']
|
||||
, manufacturer = properties['ro.product.manufacturer']
|
||||
, version = properties['ro.build.version.release']
|
||||
, sdk = +properties['ro.build.version.sdk']
|
||||
, abi = properties['ro.product.cpu.abi']
|
||||
var util = require('util')
|
||||
|
||||
// Remove brand prefix for consistency
|
||||
if (model.substr(0, brand.length) === brand) {
|
||||
model = model.substr(brand.length)
|
||||
}
|
||||
var wire = require('../wire')
|
||||
|
||||
// Remove manufacturer prefix for consistency
|
||||
if (model.substr(0, manufacturer.length) === manufacturer) {
|
||||
model = model.substr(manufacturer.length)
|
||||
}
|
||||
var devutil = module.exports = Object.create(null)
|
||||
|
||||
// Clean up remaining model name
|
||||
model = model.replace(/[_ ]/g, '')
|
||||
|
||||
return {
|
||||
platform: 'android'
|
||||
, serial: serial
|
||||
, manufacturer: manufacturer
|
||||
, model: model
|
||||
, version: version
|
||||
, sdk: sdk
|
||||
, abi: abi
|
||||
}
|
||||
devutil.platform = function(platform) {
|
||||
switch (platform) {
|
||||
case 'android':
|
||||
return wire.DevicePlatform.ANDROID
|
||||
default:
|
||||
throw new Error(util.format('Unmapped platform "%s"', platform))
|
||||
}
|
||||
}
|
||||
|
||||
devutil.manufacturer = function(manufacturer) {
|
||||
switch (manufacturer.toUpperCase()) {
|
||||
case 'SONY':
|
||||
case 'SONY ERICSSON':
|
||||
return wire.DeviceManufacturer.SONY
|
||||
case 'FUJITSU':
|
||||
return wire.DeviceManufacturer.FUJITSU
|
||||
case 'HTC':
|
||||
return wire.DeviceManufacturer.HTC
|
||||
case 'SHARP':
|
||||
return wire.DeviceManufacturer.SHARP
|
||||
case 'LGE':
|
||||
return wire.DeviceManufacturer.LG
|
||||
case 'SAMSUNG':
|
||||
return wire.DeviceManufacturer.SAMSUNG
|
||||
case 'ASUS':
|
||||
return wire.DeviceManufacturer.ASUS
|
||||
default:
|
||||
throw new Error(util.format('Unmapped manufacturer "%s"', manufacturer))
|
||||
}
|
||||
}
|
||||
|
||||
devutil.makeIdentity = function(serial, properties) {
|
||||
var model = properties['ro.product.model']
|
||||
, brand = properties['ro.product.brand']
|
||||
, manufacturer = properties['ro.product.manufacturer']
|
||||
, version = properties['ro.build.version.release']
|
||||
, sdk = properties['ro.build.version.sdk']
|
||||
, abi = properties['ro.product.cpu.abi']
|
||||
|
||||
// Remove brand prefix for consistency
|
||||
if (model.substr(0, brand.length) === brand) {
|
||||
model = model.substr(brand.length)
|
||||
}
|
||||
|
||||
// Remove manufacturer prefix for consistency
|
||||
if (model.substr(0, manufacturer.length) === manufacturer) {
|
||||
model = model.substr(manufacturer.length)
|
||||
}
|
||||
|
||||
// Clean up remaining model name
|
||||
// model = model.replace(/[_ ]/g, '')
|
||||
|
||||
return {
|
||||
serial: serial
|
||||
, platform: devutil.platform('android')
|
||||
, manufacturer: devutil.manufacturer(manufacturer)
|
||||
, model: model
|
||||
, version: version
|
||||
, abi: abi
|
||||
, sdk: sdk
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +76,19 @@ module.exports = function(wire) {
|
||||
var message = new wire.DevicePokeMessage(serial, channel)
|
||||
return wireutil.envelope(wire.MessageType.DEVICE_POKE, message)
|
||||
}
|
||||
, makeDeviceIdentityMessage: function(serial, identity) {
|
||||
var message = new wire.DeviceIdentityMessage(
|
||||
serial
|
||||
, identity.platform
|
||||
, identity.manufacturer
|
||||
, identity.model
|
||||
, identity.version
|
||||
, identity.abi
|
||||
, identity.sdk
|
||||
)
|
||||
|
||||
return wireutil.envelope(wire.MessageType.DEVICE_IDENTITY, message)
|
||||
}
|
||||
, makeDevicePropertiesMessage: function(serial, properties) {
|
||||
var message = new wire.DevicePropertiesMessage(
|
||||
serial
|
||||
|
||||
Reference in New Issue
Block a user