# we need a mother object (Android::ElectricSheep::Automator)
if( (! exists$params->{'mother'})
|| (! defined$params->{'mother'})
|| (! defined$params->{'mother'}->adb())
){ $log->error("${whoami} (via $parent), line ".__LINE__." : error, input parameter 'mother' with our parent Android::ElectricSheep::Automator object was not specified."); returnundef}
# else caller must run ->enquire() to enquire the real device
if( exists$params->{'data'} ){
my$d= $self->{'data'};
my$p= $params->{'data'};
formy$k(sortkeys%$d){
if( exists($p->{$k}) && defined($p->{$k}) ){
if( $self->set($k, $p->{$k}) ){ $log->error("${whoami} (via $parent), line ".__LINE__." : error, call to ".'set()'." has failed for input parameter '$k', is its type as expected (".ref($d->{$k}).")?"); returnundef}
}
}
}
return$self;
}
# does a adb shell dumpsys and reads various things from it
# it may also do a adb shell wm density
# returns 0 on success, 1 on failure
subenquire {
my($self, $params) = @_;
$params//= {};
my$parent= ( caller(1) )[3] || "N/A";
my$whoami= ( caller(0) )[3];
my$log= $self->log;
my$verbosity= $self->verbosity;
# first get the serial of the device
my@cmd= ('get-serialno');
my$res= $self->adb->run(@cmd);
if( ! defined$res){ $log->error(join(" ", @cmd)."\n${whoami} (via $parent), line ".__LINE__." : error, above shell command has failed, got undefined result, most likely shell command did not run at all, this should not be happening."); return1 }
$self->set('serial', $res->[1]=~s/\s*$//gmr); # it has a newline at the end
# here we could also save to a file on device and then
# fetch it locally. We will do that if there are problems
# getting the dump from STDOUT
@cmd= qw/dumpsys window/;
$res= $self->adb->shell(@cmd);
if( ! defined$res){ $log->error(join(" ", @cmd)."\n${whoami} (via $parent), line ".__LINE__." : error, above shell command has failed, got undefined result, most likely shell command did not run at all, this should not be happening."); return1 }
} else{ $log->error("DUMPSYS:\n".$res->[1]."\nEND DUMPSYS\n${whoami} (via $parent), line ".__LINE__." : error, failed to find screen density in above dumpsys."); return1 }
if( $res->[1] =~ /DisplayFrames w=.+?r=(\d+)/ ){
$self->set('orientation', $1);
} else{ $log->error("DUMPSYS:\n".$res->[1]."\nEND DUMPSYS\n${whoami} (via $parent), line ".__LINE__." : error, failed to find orientation in above dumpsys."); return1 }
){ $_[0]->log()->error(__PACKAGE__."::set(), line ".__LINE__." : error, the type of parameter '$_[1]' is '".ref($_[2])."' but '".ref($_[0]->{'data'}->{$_[1]})."'was expected."); return1 }