script/electric-sheep-emulator-geofix.pl untested

filter: Statementstmt 0.0% 0 / 54 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 81 CC 1 SCAR 6.9
CC
1
Cov
0%
usage
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/bin/env perl
2  
3 use strict;
4 use warnings;
5  
6 our $VERSION = '0.09';
7  
8 use lib ('blib/lib');
9  
10 use Getopt::Long qw(:config no_ignore_case);
11 use Data::Roundtrip qw/perl2dump no-unicode-escape-permanently/;
12  
13 use Android::ElectricSheep::Automator;
14  
15 my $VERBOSITY = 0; # we need verbosity of 10 (max), so this is not used
16 my $COORDINATES = {
17 'latitude' => undef,
18 'longitude' => undef,
19 };
20 my $DEVICE;
21 my $CONFIGFILE;
22 if( ! Getopt::Long::GetOptions(
23 'latitude|lat=s' => sub { $COORDINATES->{'latitude'} = $_[1] },
24 'longitude|lon=s' => sub { $COORDINATES->{'longitude'} = $_[1] },
25 'device|d=s' => \$DEVICE,
26 'verbosity|v=i' => \$VERBOSITY,
27 'configfile|c=s' => \$CONFIGFILE,
28 'help|h' => sub { print STDOUT usage(); exit(0); }
29 ) ){ die usage() }
30  
31 for (qw/latitude longitude/){ if( ! exists($COORDINATES->{$_}) || ! defined($COORDINATES->{$_}) ){ print STDERR usage(); print STDERR "\n$0 : error, $_ of the GPS coordinates is missing, it must be specified with '--$_'.\n"; exit(1); } }
32 if( ! defined $CONFIGFILE ){ print STDERR usage(); print STDERR "\n$0 : error, a configuration file must be specified with '--configfile'.\n"; exit(1); }
33 if( ! -f $CONFIGFILE ){ die "$0 : failed to find config file '$CONFIGFILE'." }
34  
35 my $params = {
36 'configfile' => $CONFIGFILE,
37 'verbosity' => $VERBOSITY,
38 'device-connected' => 1,
39 };
40 # we assume there is a device connected which the user
41 # must specify by serial, of if just one, we connect to
42 # it without the serial
43 if( defined $DEVICE ){ $params->{'device-serial'} = $DEVICE }
44 else { $params->{'device-is-connected'} = 1 }
45  
46 my $client = Android::ElectricSheep::Automator->new($params);
47 if( ! defined($client) ){ die "$0 : failed to instantiate the automator." }
48  
49 my $ret = $client->geofix($COORDINATES);
50 if( ! defined($ret) ){ die perl2dump($COORDINATES, {terse=>1})."$0 : failed to fix GPS coordinates of device to above. NOTE: only emulators' can have their GPS coordinates fixed!" }
51  
52 print perl2dump($COORDINATES, {terse=>1})."$0 : done, success! GPS coordinates of the device are now fixed to above.\n";
53  
54 sub usage {
55 return "Usage $0 --name APPNAME --configfile CONFIGFILE [--device DEVICE] [--verbosity v]"
56 . "\n\nThis script will fix the GPS coordinates of an EMULATOR Android device to the provided coordinates (--latitude, --longitude). Note: only emulators' can have their GPS location fixed!\n"
57 . "\nExample:\n"
58 . "$0 --configfile config/myapp.conf --latitude 12.3 --longitude 45.6\n"
59 . "\n\nProgram by Andreas Hadjiprocopis (c) 2025 / bliako at cpan.org / andreashad2 at gmail.com\n\n"
60 ;
61 }
62  
63 1;
64