Android-ElectricSheep-Automator
view release on metacpan or search on metacpan
lib/Android/ElectricSheep/Automator/Plugins/Apps/Base.pm view on Meta::CPAN
# see also https://www.reddit.com/r/privacytoolsIO/comments/fit0tr/taking_almost_full_control_of_your_unrooted/
# swipe adb shell input touchscreen swipe 300 1200 100 1200 100
use 5.006;
use strict;
use warnings;
our $VERSION = '0.09';
use Mojo::Log;
use Config::JSON::Enhanced;
use File::Temp qw/tempfile/;
use Cwd;
use FindBin;
use Data::Roundtrip qw/perl2dump no-unicode-escape-permanently/;
use Android::ElectricSheep::Automator;
use Android::ElectricSheep::Automator::ScreenLayout;
use Android::ElectricSheep::Automator::XMLParsers;
my $_DEFAULT_CONFIG = <<'EODC';
</* comments are allowed */>
</* and <% vars %> and <% verbatim sections %> */>
{
"Android::ElectricSheep::Automator" : {
"adb" : {
"path-to-executable" : "/usr/local/android-sdk/platform-tools/adb"
},
"debug" : {
"verbosity" : 0,
</* cleanup temp files on exit */>
"cleanup" : 1
},
"logger" : {
</* log to file if you uncomment this */>
</* "filename" : "..." */>
}
</* config for our plugins (each can go to separate file also) */>
},
"Android::ElectricSheep::Automator::Plugins::Apps::Viber" : {
}
}
EODC
sub new {
my $class = ref($_[0]) || $_[0];
my $params = $_[1] // {};
my $parent = ( caller(1) )[3] || "N/A";
my $whoami = ( caller(0) )[3];
my $self = {
'_private' => {
'child-class' => $class,
'mother' => undef, # the Android::ElectricSheep::Automator object
'confighash' => undef,
'configfile' => '', # this should never be undef
},
};
bless $self => $class;
# this will read the confighash, check our params, confighash params, etc.
# and also instantiate ua etc. and also do the verbosity etc.
if( $self->init($params) ){ print STDERR __PACKAGE__." (via ".$self->child_class.") : ${whoami} (via $parent), line ".__LINE__." : error, call to init() has failed.\n"; return undef }
# do module-specific init
if( $self->init_module_specific($params) ){ print STDERR __PACKAGE__." (via ".$self->child_class.") : ${whoami} (via $parent), line ".__LINE__." : error, call to init_module_specific() has failed.\n"; return undef }
# Now we have a logger
my $log = $self->log();
my $verbosity = $self->verbosity;
if( $verbosity > 0 ){ $log->info("${whoami} (via $parent), line ".__LINE__." : done, success (verbosity is set to ".$self->verbosity." and cleanup to ".$self->cleanup.").") }
return $self;
}
sub is_app_running {
my ($self, $params) = @_;
my $parent = ( caller(1) )[3] || "N/A";
my $whoami = ( caller(0) )[3];
my $log = $self->log();
my $verbosity = $self->verbosity();
my $ret = $self->mother->is_app_running({'appname' => $self->appname});
if( ! defined $ret ){ $log->error("${whoami} (via $parent), line ".__LINE__." : error, call to ".'is_app_running()'." has failed."); return undef }
if( $verbosity > 0 ){ $log->info("${whoami} (via $parent), line ".__LINE__." : app '".$self->appname."' is ".($ret>0?"":"not")." running ...") }
return $ret;
}
sub appname { return $_[0]->{'_private'}->{'appname'} }
sub open_app {
my ($self, $params) = @_;
my $parent = ( caller(1) )[3] || "N/A";
my $whoami = ( caller(0) )[3];
my $log = $self->log();
my $verbosity = $self->verbosity();
my $packagename = $self->appname;
my $ret = $self->mother->open_app({'package' => $packagename});
if( ! defined $ret ){
my $instapps = $self->mother->find_installed_apps();
if( defined $instapps ){
$log->error("All installed apps on current device:\n".join("\n ".$_, sort keys %$instapps)."\n\n");
}
$log->error("${whoami} (via $parent), line ".__LINE__." : failed to open app '$packagename'.");
return undef
}
if( $verbosity > 0 ){ $log->info("${whoami} (via $parent), line ".__LINE__." : app '$packagename' is now opening ...") }
return $ret;
}
sub close_app {
my ($self, $params) = @_;
my $parent = ( caller(1) )[3] || "N/A";
my $whoami = ( caller(0) )[3];
my $log = $self->log();
my $verbosity = $self->verbosity();
( run in 0.426 second using v1.01-cache-2.11-cpan-39bf76dae61 )