diff --git a/lib/roles/app.js b/lib/roles/app.js index a55e8aef..77370f8f 100644 --- a/lib/roles/app.js +++ b/lib/roles/app.js @@ -622,6 +622,16 @@ module.exports = function(options) { ) ]) }) + .on('store.open', function(channel, responseChannel) { + joinChannel(responseChannel) + push.send([ + channel + , wireutil.transaction( + responseChannel + , new wire.StoreOpenMessage() + ) + ]) + }) }) .finally(function() { // Clean up all listeners and subscriptions diff --git a/lib/roles/device.js b/lib/roles/device.js index c28a59a7..4f726d97 100644 --- a/lib/roles/device.js +++ b/lib/roles/device.js @@ -22,6 +22,7 @@ module.exports = function(options) { .dependency(require('./device/plugins/http')) .dependency(require('./device/plugins/service')) .dependency(require('./device/plugins/browser')) + .dependency(require('./device/plugins/store')) .dependency(require('./device/plugins/clipboard')) .dependency(require('./device/plugins/logcat')) .dependency(require('./device/plugins/shell')) diff --git a/lib/roles/device/plugins/store.js b/lib/roles/device/plugins/store.js new file mode 100644 index 00000000..9db23fdd --- /dev/null +++ b/lib/roles/device/plugins/store.js @@ -0,0 +1,40 @@ +var syrup = require('syrup') + +var logger = require('../../../util/logger') +var wire = require('../../../wire') +var wireutil = require('../../../wire/util') + +module.exports = syrup.serial() + .dependency(require('../support/router')) + .dependency(require('../support/push')) + .dependency(require('../support/adb')) + .define(function(options, router, push, adb) { + var log = logger.createLogger('device:plugins:store') + + router.on(wire.StoreOpenMessage, function(channel, message) { + log.info('Opening Play Store') + + var reply = wireutil.reply(options.serial) + adb.startActivity(options.serial, { + action: 'android.intent.action.MAIN' + , component: 'com.android.vending/.AssetBrowserActivity' + // FLAG_ACTIVITY_RESET_TASK_IF_NEEDED + // FLAG_ACTIVITY_BROUGHT_TO_FRONT + // FLAG_ACTIVITY_NEW_TASK + , flags: 0x10600000 + }) + .then(function() { + push.send([ + channel + , reply.okay() + ]) + }) + .catch(function(err) { + log.error('Play Store could not be opened', err.stack) + push.send([ + channel + , reply.fail() + ]) + }) + }) + }) diff --git a/lib/wire/wire.proto b/lib/wire/wire.proto index 6abad464..3aca6e73 100644 --- a/lib/wire/wire.proto +++ b/lib/wire/wire.proto @@ -49,6 +49,7 @@ enum MessageType { ConnectivityEvent = 46; PhoneStateEvent = 47; RotationEvent = 48; + StoreOpenMessage = 49; } message Envelope { @@ -395,6 +396,9 @@ message BrowserClearMessage { optional string browser = 1; } +message StoreOpenMessage { +} + // Events, these must be kept in sync with STFService/wire.proto message AirplaneModeEvent { diff --git a/res/app/components/stf/control/control-service.js b/res/app/components/stf/control/control-service.js index 2c87c599..c9bbdd9d 100644 --- a/res/app/components/stf/control/control-service.js +++ b/res/app/components/stf/control/control-service.js @@ -211,6 +211,12 @@ module.exports = function ControlServiceFactory( browser: browser.id }) } + + this.openStore = function() { + return sendTwoWay('store.open') + } + + window.cc = this } controlService.create = function(target, channel) {