From d29ea809bacb737306c3db5b6d73375b80c7a882 Mon Sep 17 00:00:00 2001 From: Jonathan Lipps Date: Wed, 6 Nov 2013 11:12:59 -0800 Subject: [PATCH] move logcat code into android-common so that selendroic an use it as well --- lib/devices/android/android-common.js | 44 +++++++++++++++++++++++ lib/devices/android/android-controller.js | 43 ---------------------- 2 files changed, 44 insertions(+), 43 deletions(-) diff --git a/lib/devices/android/android-common.js b/lib/devices/android/android-common.js index a12a8179c..9bbf1012f 100644 --- a/lib/devices/android/android-common.js +++ b/lib/devices/android/android-common.js @@ -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; diff --git a/lib/devices/android/android-controller.js b/lib/devices/android/android-controller.js index 8da15b434..afa82a642 100644 --- a/lib/devices/android/android-controller.js +++ b/lib/devices/android/android-controller.js @@ -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); };