Update to new device DB.

This commit is contained in:
Simo Kinnunen
2014-06-18 22:51:39 +09:00
parent 760e09290f
commit b9484019a3
8 changed files with 32 additions and 53 deletions

View File

@@ -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

View File

@@ -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
}
}

View File

@@ -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() {