Android-ElectricSheep-Automator
view release on metacpan or search on metacpan
script/electric-sheep-find-installed-apps.pl view on Meta::CPAN
#!/usr/bin/env perl
use strict;
use warnings;
our $VERSION = '0.09';
use lib ('blib/lib');
use Getopt::Long qw(:config no_ignore_case);
use Data::Roundtrip qw/perl2dump perl2json no-unicode-escape-permanently/;
use Android::ElectricSheep::Automator;
my $VERBOSITY = 0; # we need verbosity of 10 (max), so this is not used
my $DEVICE;
my $CONFIGFILE;
my $OUTFILE;
my $PACKAGE_NAME;
my $FAST = 0;
if( ! Getopt::Long::GetOptions(
'device|d=s' => \$DEVICE,
'verbosity|v=i' => \$VERBOSITY,
'fast' => \$FAST, # if fast then it is not full
'package=s' => \$PACKAGE_NAME,
'output|o=s'=> \$OUTFILE,
'configfile|c=s' => \$CONFIGFILE,
'help|h' => sub { print STDOUT usage(); exit(0); }
) ){ die usage() }
if( ! defined $CONFIGFILE ){ print STDERR usage(); print STDERR "\n$0 : error, a configuration file must be specified with '--configfile'.\n"; exit(1); }
if( ! -f $CONFIGFILE ){ die "$0 : failed to find config file '$CONFIGFILE'." }
my $params = {
'configfile' => $CONFIGFILE,
'verbosity' => $VERBOSITY,
'device-connected' => 1,
};
# we assume there is a device connected which the user
# must specify by serial, of if just one, we connect to
# it without the serial
if( defined $DEVICE ){ $params->{'device-serial'} = $DEVICE }
else { $params->{'device-is-connected'} = 1 }
my $client = Android::ElectricSheep::Automator->new($params);
if( ! defined($client) ){ die "$0 : failed to instantiate the automator." }
my $fpars = {};
if( ! $FAST ){
$fpars->{'lazy'} = 0;
}
if( defined $PACKAGE_NAME ){
$fpars->{'packages'} = qr/\Q${PACKAGE_NAME}\E/i;
$fpars->{'lazy'} = 1;
}
my $apps = $client->find_installed_apps($fpars);
if( ! defined($apps) ){ die "$0 : failed to find installed apps on the connected device." }
if( scalar(keys %$apps) == 0 ){ print STDERR "$0 : WARNING, no apps were found, surely there is something wrong.\n"; exit(1) }
# remove the null value (because in FAST mode we have no properties, only keys)
if( $FAST ){
for (keys %$apps){
$apps->{$_} = {} unless defined($apps->{$_})
}
}
# $apps is a hash with keys the package name (e.g. com.google.settings whatever)
# and the value is an AppProperties object.
# you need convert_blessed and TO_JSON!
# if packages were specified we will filter the output
if( defined $PACKAGE_NAME ){
( run in 0.632 second using v1.01-cache-2.11-cpan-39bf76dae61 )