예제 #1
0
 def __adb_package_name_from_apk(self, apk_path):
     '''
     returns the package_name by executing
         >>> aapt d permissions file.apk
     '''
     # ./aapt d permissions ~/git/testApps/Ringdroid_2.7.4_apk-dl.com.apk
     util.check_file_directory_exists(apk_path, True)
     result = subprocess.check_output(
         [config.AAPT, 'd', 'permissions', apk_path]).decode()
     return result.split("\n")[0].split('package:')[1].strip()
예제 #2
0
def adb_install_apk(emulator: Emulator, apk: Apk):
    '''
    installs provided apk to specified emulator
    '''
    util.check_file_directory_exists(apk.apk_path, True)
    try:
        result = subprocess.check_output([
            config.adb, '-s', 'emulator-' + emulator.port, 'install',
            apk.apk_path
        ]).decode()
        util.debug_print(result, flag=PRINT_FLAG)
    except subprocess.SubprocessError as error:
        print(error)
        raise ValueError("error installing.")
예제 #3
0
def read_interval_event_from_file(
        file_address: str, event_type: EVENT_TYPES) -> List[IntervalEvent]:
    '''
        imports event from file and returns `List[IntervalEvent]`
    '''
    util.check_file_directory_exists(file_address, True)
    lines: list = open(file_address).read().split('\n')
    step: int = 0
    event_type_name = None
    events: List[IntervalEvent] = []
    total_event_duration: int = 0
    for line in lines:
        in_values = line.split(',')
        if len(in_values) is 3:
            try:
                event_value = int(in_values[0])
                event_interval = int(in_values[1])
                event_type_name = str(in_values[2])
            except ValueError:
                print('Caught Error! Please check value of: ' + in_values)
            if in_values[2] == 'GsmProfile':
                i_event = IntervalEvent(step, event_interval,
                                        GsmProfile(event_value).name,
                                        GsmProfile)
            elif in_values[2] == 'NetworkDelay':
                i_event = IntervalEvent(step, event_interval,
                                        NetworkDelay(event_value).name,
                                        NetworkDelay)
            elif in_values[2] == 'NetworkStatus':
                i_event = IntervalEvent(step, event_interval,
                                        NetworkStatus(event_value).name,
                                        NetworkStatus)
            elif in_values[2] == 'UserRotation':
                i_event = IntervalEvent(step, event_interval,
                                        UserRotation(event_value).name,
                                        UserRotation)
            else:
                raise ValueError("incorrect format of Event type: " +
                                 in_values[2])
            events.append(i_event)
            total_event_duration += event_interval
            if total_event_duration > config.DURATION:
                print("total event interval duration from file (" +
                      str(total_event_duration) + ") can not be larger than " +
                      str(config.DURATION))
                raise ValueError()
    print("successfully imported from file. Type: " + event_type_name +
          "; total duration=" + str(total_event_duration))
    return events
예제 #4
0
def gradle_test(gradlew_path: str, project_path: str):
    '''
    `gradlew_path` is the full path of the gradlew inside the project folder
    '''
    util.check_file_directory_exists(gradlew_path, True)
    util.check_file_directory_exists(project_path, True)
    util.change_file_permission(gradlew_path, 555)
    print(gradlew_path, project_path)
    try:
        subprocess.check_output([
            gradlew_path, '-p', project_path, 'tasks', 'connectedAndroidTest',
            '--info', '--debug', '--stacktrace'
        ])
    except subprocess.CalledProcessError:
        print('error: gradle problem executing: ' + gradlew_path)
예제 #5
0
 def __init__(self, file_path):
     self.file_path = file_path
     if not util.check_file_directory_exists(file_path, False):
         raise ValueError("File path does not exist.")
     self.file_contents = Path(file_path).read_text().split('\n')
     self.unique_warnings = set()
     self.all_warnings = list()
     self.unique_errors = set()
     self.all_errors = list()
     self.unique_fatals = set()
     self.all_fatals = list()
     self.count_warnings = None
     self.count_errors = None
     self.count_fatals = None
     self.count_unique_warnings = None
     self.count_unique_errors = None
     self.count_unique_fatals = None
     self.logs = self.__logfile_to_logs(mode=1)
     self.__calculate_stats()
     if self.count_errors == 0 and\
         self.count_unique_errors == 0 and\
             self.count_unique_warnings == 0 and self.count_warnings == 0:
         print("something went wrong. recalculating")
         self.logs = self.__logfile_to_logs(mode=2)
         self.__calculate_stats()
예제 #6
0
def decode_apk(apk: Apk):
    '''
    decodes provided apk to a folder
    '''
    util.check_file_directory_exists(apk.apk_path, True)
    try:
        result = subprocess.check_output(['apktool', 'if',
                                          apk.apk_path]).decode()
        util.debug_print(result, flag=PRINT_FLAG)

        result = subprocess.check_output([
            'apktool', 'd', apk.apk_path, '-o',
            config.APK_FULL_PATH.split('.apk')[0], '-f'
        ]).decode()
        util.debug_print(result, flag=PRINT_FLAG)
    except subprocess.SubprocessError as error:
        print(error)
        raise ValueError("error decoding.")
예제 #7
0
    def __adb_permissions_from_apk(self, apk_path: str):
        '''
        returns list of permissions defined in APK
        '''
        def extract_permission(value: str):
            '''
            internal function
            '''
            if ".permission." in value:
                if value.endswith('\''):
                    permission = value.split("=")[1].strip('\'')
                else:
                    permission = value.split(": ")[1]
                return permission

        util.check_file_directory_exists(apk_path, True)

        output = subprocess.check_output(
            [config.AAPT, 'd', 'permissions', apk_path]).decode().split('\n')
        result = list(filter(None, map(extract_permission, output)))
        return result
예제 #8
0
 def __init__(self, apk_path: str):
     util.check_file_directory_exists(apk_path, True)
     self.apk_path = apk_path
     self.package_name = self.__adb_package_name_from_apk(apk_path)
     self.permissions = self.__adb_permissions_from_apk(apk_path)