script/electric-sheep-close-app.pl untested

filter: Statementstmt 0.0% 0 / 50 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 71 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  
12 use Android::ElectricSheep::Automator;
13  
14 my $VERBOSITY = 0; # we need verbosity of 10 (max), so this is not used
15 my $APPNAME;
16 my $DEVICE;
17 my $CONFIGFILE;
18  
19 if( ! Getopt::Long::GetOptions(
20 'name|n=s' => \$APPNAME,
21 'keyword=s' => sub { $APPNAME = qr/\Q$_[1]\E/i },
22 'device|d=s' => \$DEVICE,
23 'verbosity|v=i' => \$VERBOSITY,
24 'configfile|c=s' => \$CONFIGFILE,
25 'help|h' => sub { print STDOUT usage(); exit(0); }
26 ) ){ die usage() }
27  
28 if( ! defined $APPNAME ){ print STDERR usage(); print STDERR "\n$0 : error, the name of the application to close must be specified with '--name'.\n"; exit(1); }
29 if( ! defined $CONFIGFILE ){ print STDERR usage(); print STDERR "\n$0 : error, a configuration file must be specified with '--configfile'.\n"; exit(1); }
30 if( ! -f $CONFIGFILE ){ die "$0 : failed to find config file '$CONFIGFILE'." }
31  
32 my $params = {
33 'configfile' => $CONFIGFILE,
34 'verbosity' => $VERBOSITY,
35 'device-connected' => 1,
36 };
37 # we assume there is a device connected which the user
38 # must specify by serial, of if just one, we connect to
39 # it without the serial
40 if( defined $DEVICE ){ $params->{'device-serial'} = $DEVICE }
41 else { $params->{'device-is-connected'} = 1 }
42  
43 my $client = Android::ElectricSheep::Automator->new($params);
44 if( ! defined($client) ){ die "$0 : failed to instantiate the automator." }
45  
46 my $ret = $client->close_app({
47 'package' => qr/\Q$APPNAME\E/i
48 });
49 if( ! defined($ret) ){ die "$0 : failed to close app '$APPNAME'." }
50  
51 print "$0 : done, success! App '$APPNAME' must now be closed.\n";
52  
53 sub usage {
54 return "Usage $0 --name APPNAME --configfile CONFIGFILE [--device DEVICE] [--verbosity v]"
55 . "\n\nThis script will close an app on a mobile device connected on your computer given its name exactly (--name) or given a keyword (--keyword) to be matched (case insensitive) against all app names. Note that you can use electric-sheep-find-installed-apps.pl in order to list all apps on device.\n"
56 . "Note that --keyword KEYWORD creates a regular expression from user input as ".'qr/\Q<userinput>\E/i'."\n"
57 . "\nExample:\n"
58 . "$0 --configfile config/myapp.conf --name com.android.settings\n"
59 . "$0 --configfile config/myapp.conf --keyword 'clock'\n"
60 . "\n\nProgram by Andreas Hadjiprocopis (c) 2025 / bliako at cpan.org / andreashad2 at gmail.com\n\n"
61 ;
62 }
63  
64 1;
65