Test Failed
Push — beta ( 0deaa1...735b0d )
by Dean
03:31
created

AndroidHelper.is_android()   B

Complexity

Conditions 6

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 26
rs 7.5384
cc 6
1
import logging
2
import os
3
import platform
4
5
log = logging.getLogger(__name__)
6
7
8
class AndroidHelper(object):
9
    _is_android = None
10
11
    @classmethod
12
    def is_android(cls):
13
        if cls._is_android is not None:
14
            return cls._is_android
15
16
        try:
17
            # Check android platform criteria
18
            if not os.path.exists('/system/build.prop'):
19
                # Couldn't find "build.prop" file
20
                cls._is_android = False
21
            elif os.path.exists('/system/lib/libandroid_runtime.so'):
22
                # Found "libandroid_runtime.so" file
23
                log.info('Detected android system (found the "libandroid_runtime.so" file)')
24
                cls._is_android = True
25
            elif '-google' in platform.python_compiler():
26
                # Found "-google" in the python compiler attribute
27
                log.info('Detected android system (found "-google" in the python compiler attribute)')
28
                cls._is_android = True
29
            else:
30
                log.warn('Found the "build.prop" file, but could\'t confirm if the system is running android')
31
                cls._is_android = False
32
33
        except Exception, ex:
34
            log.warn('Unable to check if the system is running android: %s', ex, exc_info=True)
35
36
        return cls._is_android
37