Perl in your Pocket

Max Maischein

Frankfurt.pm

Who am I

  • Max Maischein

  • Frankfurt am Main

  • Frankfurt.pm

  • DZ BANK, Information management

Overview

  • Why Android?

  • State of Perl on Android

  • Triaging Perl errors/module errors

  • Running Perl programs

  • Interacting with Android

  • Uses for Perl

Expectation management

  • For non-mobile developers

  • No App/Activity development

Making software tangible

  • Share media files

  • No setup, just a device

  • Otherwise responsible for all problems

  • Sysadmin in foreign networks

  • Device on - sharing active

  • Device off - sharing inactive

Devices

  • Raspberry Pi - EUR 30

  • Touchscreen - EUR 30

  • Case - EUR 10

  • Power supply, WLan, ...

  • Soldering + glueing

  • Sysadmin

Android devices

  • Device - EUR 130

  • Touchscreen

  • Case

  • Battery

  • Wlan, USB, Camera, Power supply, ...

  • Sysadmin

Android

"Android is just Linux, right?"

Android vs. Java vs. native

Android has 3 parts

Android vs. Java vs. native

Android has 3 parts

Android vs. Java vs. native

Android has 3 parts

Android vs. Java vs. native

Android has 3 parts

Android vs. Java vs. native

Android has 3 parts

Android vs. Java vs. native

Android has 3 parts

Android vs. Java vs. native

Android has 3 parts

Android vs. Java vs. native

Android has 3 parts

No hands, no cookies

No JVM, no access to Android Core

cctools

  • Native IDE on Android

  • Vi

  • git

  • gcc

  • Perl

  • bash, wget, curl, ...

cctools-Perl

CCtools has Perl

  •  1:  perl -v
     2:  
     3:  This is Perl 5.18.2, ...
  • Perl 5.22 is hopefully more current and works better.

  • Compiling our own perl

Compiling Perl

 1:  sh ./Configure
 2:    -des
 3:    -Dusedevel
 4:    -Dprefix=/data/local/perl/
 5:    -Dsysroot=/data/data/com.pdaxrom.cctools/root/cctools
 6:    -Alibpth=/system/lib /vendor/lib
 7:    -Dman1dir=none
 8:    -Dman3dir=none
 9:    -Dsite1man=none
10:    -Dsite3man=none
11:    -Dvendorman1=none
12:    -Dvendorman3=none
13:    -DNO_LOCALE
14:
15:  make
16:  make test
17:  make install

Errors from make test

  • 50% bad test assumptions

  • 50% environment/OS peculiarities

Selected errors

 1:  cpan/Time-Piece/t/02core ...................................... #   Failed test at t/02core.t line 62.
 2:  #          got: '3600'
 3:  #     expected: '-18000'
 4:  #   Failed test at t/02core.t line 63.
 5:  #          got: 'CET'
 6:  #     expected: 'EST'
 7:  # Looks like you failed 2 tests of 95.
 8:  FAILED at test 36

Selected errors

  • t/io/ioxs.t
  • mktemps() exists but always fails
  • Netcraft^HGoogle confirms it

Running Perl Programs

Using Mojolicious

  •  1:  cpanm --no-wget Mojolicious
  • Sometimes fewer prerequisites is convenient

Mojolicious Webserver Demo

 1:  use Mojolicious::Lite;
 2:  
 3:  get '/' => sub {
 4:      my( $c )= shift;
 5:      $c->render( text => 'Hello YAPC::Europe' );
 6:  }

Mojolicious Webserver Demo

User permissions on Android

  • One Unix-User per app

  • Data protection between apps

  • root for access to all data

Native Access using DBI to Google Keep

  • DBI Installs without problems

  • SQLite is installed on Android

  •  1:  sqlite3 /data/data/com.google.android.keep/data.sqlite

Local Access using Perl

  • Querylet

  • root :-(

 1:  #!perl -w
 2:  use strict;
 3:  use Querylet;
 4:  use Querylet::Output::Text;
 5:  
 6:  database: dbi:SQLite:dbname=/data/data/com.google.android.keep/data/keep.db

Local Access using Perl

 1:  query:
 2:      select 
 3:        title
 4:      , text
 5:      from      tree_entity note
 6:      left join list_item   list on
 7:          (note._id = list.list_parent_id and note.account_id=list.account_id)
 8:      where note._id= 143
 9:      order by list.order_in_parent desc
10:    
11:  output format: text

Output

 1:  # perl5.21.11 02-dump-keep.pl

Output

 1:  # perl5.21.11 02-dump-keep.pl
 2:
 3:  title           text
 4:  Perl on Android Abgrenzung/Erwartungsmanagement
 5:  Perl on Android Historische Einordnung v. PoA: SL4A,native
 6:  Perl on Android Java vs native
 7:  Perl on Android dalvik vs Java -> ART

Interacting with Android

  • Launch Activities

  • Send input

  • Read input

  • Read screen

  • Without JNI

  • open() / Read the right devices

  • system() / launch the right programs

Launch Activity

  • Launch Activity

     1:  system( "am start 'http://act.yapc.eu/ye2015'" );
     2:
     3:  Android::launch_activity('http://act.yapc.eu/ye2015')

What's missing for an App?

  • APK Builder

  • Google Play Store Account

  • Size reduction (App::staticperl)

  • Native UI instead of webserver

Steps for installing Perl

  • Download tarball

  • Copy files

Sample code

All sample code is on Github at

https://github.com/corion/perl-android

Thanks

Thanks

Questions?

Thanks

Questions?

corion@cpan.org

Slides available at

http://corion.net/talks/

Tarball on

http://corion.net/perl-android/index.html

https://github.com/corion/perl-android on Github

Simulate input

Clicks / taps

 1:  Android::send_input_event(
 2:      command => 'tap',
 3:      args => [$x, $y],
 4:  );

Simulate input

Text

 1:  Android::send_input_event(
 2:      command => 'text',
 3:      args => ['Hello Perl'],
 4:  );

Inspect input

 1:  my $fh= Android::input_event_fh();
 2:  while( my $line = <$fh> ) {
 3:      my $ev= Android::decode_input_event( $line );
 4:      if( $ev ) {
 5:          print join("\t", $ev->{type}, $ev->{subtype}, $ev->{value}), "\n";
 6:      };
 7:  };

Capture screenshot

Screenshot

 1:  Android::screenshot('/sdcard/image.png');

Vibrate device

 1:  Android::vibrate(100);

Perl-Support for Android

  • perlandroid.pod

  • cctools

  • perlport.pod

Tethered communication

Own mtpServer/mtpDevice

Android has Fuse built-in

CPAN via http as FUSE Plugin - minicpan-on-usb

fuse-android+Fuse.pm

 1:  libfuse-lite / ntfs-3g

Images used

Raspberry Pi 2 Model B by Multicherry ( https://commons.wikimedia.org/wiki/User:Multicherry )