Brothers and sisters, fellow Monks (lend me your ears),

I have recently discovered that there is still quite a lot of hope for using a smartphone as a tool for empowering people and not enterprises. Android is providing a very potent program: the Android Debug Bridge (ADB) which communicates with an Android device connected to your desktop (via USB or in same wifi network). With this program, one can tell the device to wake up, to enter the passcode of the screensaver, to navigate to the home screen, to open apps, to close apps, to swipe, to click, to input text. To get readings from sensors, to get a screenshot or a screenvideo and finally to dump the current screen's UI as XML which can then be parsed to find widgets of interest, e.g. a button to click, a textbox to enter text, a list of contacts, etc.

The two main problems with controlling your smart device in such a way are: 1) Android API differences between versions, so standard apps or widgets are named differently. 2) Android remembers to notify you about something when in the middle of controlling an app and steals the focus. But neither of these problems is insurmountable.

The idea of controlling a device from my desktop is very appealing. In fact, I do not use a real device but an emulator (A note of warning here, better use an emulator or an unimportant phone).

At first a friend wanted to keep tapping on an app in order to gain some points for an idiotic competition. Then I wanted to send viber and skype messages from the command line of my linux terminal. And so I have set out to make a thin wrapper to the ADB for Perl. There are a lot of such wrappers for a lot of environments but I did not see one for Perl yet. So here it is : Android::ElectricSheep::Automator

use Android::ElectricSheep::Automator; my $mother = Android::ElectricSheep::Automator->new({ 'configfile' => $configfile, 'verbosity' => 1, # we already have a device connected and ready to control 'device-is-connected' => 1, }); $mother->tap({position=>[1,2]}); use Android::ElectricSheep::Automator::Plugins::Viber; my $vib = Android::ElectricSheep::Automator::Plugins::Viber->new({ configfile=>'config/plugins/viber.conf', 'device-is-connected' => 1 +}); $vib->open_viber_app(); $vib->send_message({recipient=>'My Notes', message=>'hello%sMonkees +'}); $vib->close_viber_app();

bw, bliako

  • Comment on Do Androids Dream of Electric Sheep? Control your smartphone from the desktop
  • Download Code

Replies are listed 'Best First'.
Re: Do Androids Dream of Electric Sheep? Control your smartphone from the desktop
by choroba (Cardinal) on Apr 19, 2025 at 15:47 UTC
    Skype messages? What you need to know.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

      one more crime to be added to the others committed by the pitiful M$. Skype will be going to to the big chatroom in the sky and M$ will seek more profitableq cows.

Re: Do Androids Dream of Electric Sheep? Control your smartphone from the desktop
by cavac (Prior) on Apr 25, 2025 at 09:43 UTC

      Thanks! I forgot to say that one can extend the functionality of this package with plugins. For example look at the one I did for viber. Android::ElectricSheep::Automator::Plugins::Apps::Viber. Plugins inherit from a Base class which does the heavy lifting. The Plugin developer must search the UI of the app for the names of buttons to click etc.