move logcat code into android-common

so that selendroic an use it as well
This commit is contained in:
Jonathan Lipps
2013-11-06 11:12:59 -08:00
parent 9bd93ae1f4
commit d29ea809ba
2 changed files with 44 additions and 43 deletions

View File

@@ -1,11 +1,17 @@
"use strict";
var logger = require('../../server/logger.js').get('appium')
, _ = require('underscore')
, status = require("../../server/status.js")
, fs = require('fs')
, path = require('path')
, md5 = require('MD5')
, async = require('async');
var logTypesSupported = {
'logcat' : 'Logs for Android applications on real device and emulators ' +
'via ADB'
};
var androidCommon = {};
androidCommon.prepareDevice = function(onReady) {
@@ -239,5 +245,43 @@ androidCommon.unlockScreen = function(cb) {
}.bind(this));
};
androidCommon.getLog = function(logType, cb) {
// Check if passed logType is supported
if (!_.has(logTypesSupported, logType)) {
return cb(null, {
status: status.codes.UnknownError.code
, value: "Unsupported log type '" + logType + "', supported types : " + JSON.stringify(logTypesSupported)
});
}
var logs;
// Check that current logType and instance is compatible
if (logType == 'logcat') {
try {
logs = this.adb.getLogcatLogs();
} catch (e) {
return cb(e);
}
}
// If logs captured sucessfully send response with data, else send error
if (logs) {
return cb(null, {
status: status.codes.Success.code
, value: logs
});
} else {
return cb(null, {
status: status.codes.UnknownError.code
, value: "Incompatible logType for this device"
});
}
};
androidCommon.getLogTypes = function(cb) {
return cb(null, {
status: status.codes.Success.code
, value: _.keys(logTypesSupported)
});
};
module.exports = androidCommon;

View File

@@ -15,11 +15,6 @@ var errors = require('../../server/errors.js')
var androidController = {};
var logTypesSupported = {
'logcat' : 'Logs for Android applications on real device and emulators via ADB'
};
androidController.keyevent = function(keycode, metastate, cb) {
this.proxy(["pressKeyCode", {keycode: keycode, metastate: metastate}], cb);
};
@@ -666,44 +661,6 @@ androidController.installApp = function(appPackage, cb) {
deviceCommon.installApp(installationCommand, this.udid, appPackage, cb);
};
androidController.getLog = function(logType, cb) {
// Check if passed logType is supported
if (!_.has(logTypesSupported, logType)) {
return cb(null, {
status: status.codes.UnknownError.code
, value: "Unsupported log type '" + logType + "', supported types : " + JSON.stringify(logTypesSupported)
});
}
var logs;
// Check that current logType and instance is compatible
if (logType == 'logcat') {
try {
logs = this.adb.getLogcatLogs();
} catch (e) {
return cb(e);
}
}
// If logs captured sucessfully send response with data, else send error
if (logs) {
return cb(null, {
status: status.codes.Success.code
, value: logs
});
} else {
return cb(null, {
status: status.codes.UnknownError.code
, value: "Incompatible logType for this device"
});
}
};
androidController.getLogTypes = function(cb) {
return cb(null, {
status: status.codes.Success.code
, value: _.keys(logTypesSupported)
});
};
androidController.unpackApp = function(req, cb) {
deviceCommon.unpackApp(req, '.apk', cb);
};