diff --git a/lib/cli.js b/lib/cli.js index 9229b29a..d21d1bae 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -613,19 +613,19 @@ program }) program - .command('generate-fake-device') + .command('generate-fake-device [model]') .description('generates a fake device for testing') .option('-n, --number ' , 'how many devices to create (defaults to 1)' , Number , 1) - .action(function(options) { + .action(function(model, options) { var log = logger.createLogger('cli:generate-fake-device') , fake = require('./util/fakedevice') , n = options.number function next() { - return fake.generate() + return fake.generate(model) .then(function(serial) { log.info('Created fake device "%s"', serial) diff --git a/lib/db/api.js b/lib/db/api.js index 2ba2d2f1..1731c662 100644 --- a/lib/db/api.js +++ b/lib/db/api.js @@ -197,7 +197,7 @@ dbapi.saveDeviceIdentity = function(serial, identity) { , sdk: identity.sdk , display: identity.display , phone: identity.phone - , name: identity.name + , product: identity.product })) } diff --git a/lib/roles/device/plugins/identity.js b/lib/roles/device/plugins/identity.js index 1f46f674..2e9f2b1a 100644 --- a/lib/roles/device/plugins/identity.js +++ b/lib/roles/device/plugins/identity.js @@ -1,4 +1,5 @@ var syrup = require('syrup') +var deviceData = require('stf-device-db') var devutil = require('../../../util/devutil') var logger = require('../../../util/logger') diff --git a/lib/roles/device/plugins/solo.js b/lib/roles/device/plugins/solo.js index 2805a86b..8908788e 100644 --- a/lib/roles/device/plugins/solo.js +++ b/lib/roles/device/plugins/solo.js @@ -27,10 +27,10 @@ module.exports = syrup.serial() , identity.model , identity.version , identity.abi - , identity.name , identity.sdk , new wire.DeviceDisplayMessage(identity.display) , new wire.DevicePhoneMessage(identity.phone) + , identity.product )) ]) }) diff --git a/lib/util/datautil.js b/lib/util/datautil.js index 2a906d5c..b4aee7fe 100644 --- a/lib/util/datautil.js +++ b/lib/util/datautil.js @@ -5,52 +5,28 @@ var logger = require('./logger') var log = logger.createLogger('util:datautil') -var aliases = { - 'KYY22': 'L02' -, 'SH-06DNERV': 'SH-06D_NERV' -} - var datautil = module.exports = Object.create(null) datautil.applyData = function(device) { - var model = device.model - var name = device.name + var match = deviceData.find({ + model: device.model + , name: device.product + }) - if (model) { - var match = deviceData.find({model: model, name: name}) - - if (!match) { - if (aliases[model]) { - match = deviceData.find({model: aliases[model], name: name}) - } - else { - if (!match) { - model = model.replace(/ /g, '_') - match = deviceData.find({model: model, name: name}) - - if (!match) { - model = model.replace(/_/g, '') - match = deviceData.find({model: model, name: name}) - } - } - } - } - - if (match) { - device.name = match.name.id - device.model = match.name.long - device.releasedAt = match.date - device.image = model + '.jpg' // TODO: check for icon/photo file existence - device.cpu = match.cpu - device.memory = match.memory - } - else { - log.warn( - 'Device database does not have a match for device "%s" (model "%s")' - , device.serial - , device.model - ) - } + if (match) { + device.name = match.name.id + device.releasedAt = match.date + device.image = match.image + device.cpu = match.cpu + device.memory = match.memory + } + else { + log.warn( + 'Device database does not have a match for device "%s" (model "%s"/"%s")' + , device.serial + , device.model + , device.product + ) } return device diff --git a/lib/util/devutil.js b/lib/util/devutil.js index 18ca88a0..fa6da22d 100644 --- a/lib/util/devutil.js +++ b/lib/util/devutil.js @@ -133,7 +133,7 @@ devutil.makeIdentity = function(serial, properties) { , version = properties['ro.build.version.release'] , sdk = properties['ro.build.version.sdk'] , abi = properties['ro.product.cpu.abi'] - , name = properties['ro.product.name'] + , product = properties['ro.product.name'] // Remove brand prefix for consistency if (model.substr(0, brand.length) === brand) { @@ -156,6 +156,6 @@ devutil.makeIdentity = function(serial, properties) { , version: version , abi: abi , sdk: sdk - , name: name + , product: product } } diff --git a/lib/util/fakedevice.js b/lib/util/fakedevice.js index 7c8d9947..d40e92ee 100644 --- a/lib/util/fakedevice.js +++ b/lib/util/fakedevice.js @@ -4,9 +4,9 @@ var uuid = require('node-uuid') var _ = require('lodash') var dbapi = require('../db/api') -var devices = require('stf-device-db') +var devices = require('stf-device-db/dist/devices-latest') -module.exports.generate = function() { +module.exports.generate = function(wantedModel) { var serial = util.format( 'fake-%s' , uuid.v4(null, new Buffer(16)).toString('base64') @@ -20,11 +20,12 @@ module.exports.generate = function() { , status: 'OFFLINE' }) .then(function() { + var model = wantedModel || _.sample(Object.keys(devices)) return dbapi.saveDeviceIdentity(serial, { platform: 'Android' , manufacturer: 'Foo Electronics' , operator: 'Loss Networks' - , model: _.sample(Object.keys(devices)) + , model: model , version: '4.1.2' , abi: 'armeabi-v7a' , sdk: 8 + Math.floor(Math.random() * 12) @@ -46,6 +47,7 @@ module.exports.generate = function() { , network: 'LTE' , phoneNumber: '0000000000' } + , product: model }) }) .then(function() { diff --git a/lib/wire/wire.proto b/lib/wire/wire.proto index ceb2601a..c44168f7 100644 --- a/lib/wire/wire.proto +++ b/lib/wire/wire.proto @@ -172,10 +172,10 @@ message DeviceIdentityMessage { required string model = 5; required string version = 6; required string abi = 7; - required string name = 12; required string sdk = 8; required DeviceDisplayMessage display = 9; required DevicePhoneMessage phone = 11; + optional string product = 12; } message DeviceProperty {