Exemple #1
0
    def build(self):
        try:
            if not check_permission('android.permission.ACCESS_FINE_LOCATION'):
                print('Permission Fine Location Access: %s' % str(
                    check_permission(
                        'android.permission.ACCESS_FINE_LOCATION')))
                request_permission('android.permission.ACCESS_FINE_LOCATION')
            else:
                print('Fine Location Access Permission OK')

            if not check_permission(Permission.ACCESS_COARSE_LOCATION):
                print('Permission Coarse Location Access: %s' %
                      str(check_permission(Permission.ACCESS_COARSE_LOCATION)))
                request_permission(Permission.ACCESS_COARSE_LOCATION)
            else:
                print('Coarse Location Access Permission OK')

            gps.configure(on_location=self.on_location,
                          on_status=self.on_status)
        except NotImplementedError:
            import traceback
            traceback.print_exc()
            print('GPS is not implemented for your platform')
            self.gps_status = 'GPS is not implemented for your platform'

        return Builder.load_string(kv)
Exemple #2
0
 def camera_video(self, b):
     if check_permission(Permission.CAMERA) and\
        check_permission(Permission.RECORD_AUDIO):
         if api_version > 28 or\
            check_permission(Permission.WRITE_EXTERNAL_STORAGE):
             self.cameraxf = CameraXF(capture='video',
                                      callback=self.captured)
             self.cameraxf.bind(on_dismiss=self._dismissed)
Exemple #3
0
 def camera_photo(self, b):
     if check_permission(Permission.CAMERA):
         if api_version > 28 or\
            check_permission(Permission.WRITE_EXTERNAL_STORAGE):
             self.cameraxf = CameraXF(capture='photo',
                                      flash='auto',
                                      callback=self.captured)
             self.cameraxf.bind(on_dismiss=self._dismissed)
Exemple #4
0
def get_plugins_list():
    '''
    Load plugin lists, including both built-in and 3rd-party plugins
    '''
    # Update for sdk 21+ for storage permission
    PERMISSION = [
        Permission.READ_EXTERNAL_STORAGE, Permission.WRITE_EXTERNAL_STORAGE,
        Permission.ACCESS_FINE_LOCATION, Permission.ACCESS_COARSE_LOCATION
    ]
    if not check_permission(Permission.ACCESS_COARSE_LOCATION):
        ret = request_permissions(PERMISSION)
        Logger.info("python:request_permissions %s" % ret)

    while not check_permission(Permission.ACCESS_COARSE_LOCATION):
        Logger.info("Waiting for permissions")

    ret = {}  # app_name->(path,with_UI)

    APP_DIR = os.path.join(
        str(current_activity.getFilesDir().getAbsolutePath()), "app/plugins")
    l = os.listdir(APP_DIR)
    for f in l:
        if os.path.exists(os.path.join(APP_DIR, f, "main.mi2app")):
            # ret.append(f)
            ret[f] = (os.path.join(APP_DIR, f), False)

    # Yuanjie: support alternative path for users to customize their own plugin
    APP_DIR = get_mobileinsight_plugin_path()

    if os.path.exists(APP_DIR):
        l = os.listdir(APP_DIR)
        for f in l:
            if os.path.exists(os.path.join(APP_DIR, f, "main_ui.mi2app")):
                if f in ret:
                    tmp_name = f + " (plugin)"
                else:
                    tmp_name = f
                ret[tmp_name] = (os.path.join(APP_DIR, f), True)
            elif os.path.exists(os.path.join(APP_DIR, f, "main.mi2app")):
                if f in ret:
                    tmp_name = f + " (plugin)"
                else:
                    tmp_name = f
                ret[tmp_name] = (os.path.join(APP_DIR, f), False)
    else:  # create directory for user-customized apps
        create_folder()

    return ret
Exemple #5
0
    def convert(self, *args):

        if platform == 'android':
            if check_permission(
                    Permission.WRITE_EXTERNAL_STORAGE
            ) == False:  # check permission takes str not a list
                request_permission(Permission.WRITE_EXTERNAL_STORAGE)
                request_permission(
                    Permission.READ_EXTERNAL_STORAGE
                )  # request_permisssion takes str and request_permissions takes list
                return
            # Make a Folder for Zip
            # Make ChandanVideo Folder in Internal Storage
            if self.zip_path == None or os.path.splitext(
                    self.zip_path)[1] != '.zip':
                self.root.ids.status_label.text = "Select a zip first "
                return
            self._update_status("Please Wait ... Checking Zip")
            self.clips_path = os.path.join(self.app_path, self.zip_name)
            self.video_folder = os.path.join(self.primary_ext_storage, "Zipvy")
            self.video_location = os.path.join(self.video_folder,
                                               self.zip_name + ".mp4")
            Logger.debug("Clips Path : " + str(self.clips_path) +
                         "\n video_folder : " + str(self.video_folder) +
                         "\n video_path:" + str(self.video_location))

            convert_thread = Thread(target=self._convert)
            convert_thread.start()

        else:
            self.root.ids.prog.value = 75
            self.root.ids.status_label.text = " I am running in " + str(
                platform)
            print(" I am running in " + str(platform))
Exemple #6
0
	def build(self):
		if platform=='android':
			while not check_permission('android.permission.WRITE_EXTERNAL_STORAGE'):
				request_permissions([Permission.READ_EXTERNAL_STORAGE, Permission.WRITE_EXTERNAL_STORAGE])
		self.theme_cls.primary_palette = "Red"
		master = Builder.load_file('main.kv')
		return master
Exemple #7
0
def check_write_permission():
    """Android runtime storage permission check."""
    if platform != "android":
        return True
    from android.permissions import Permission, check_permission
    permission = Permission.WRITE_EXTERNAL_STORAGE
    return check_permission(permission)
    def send(self, _):
        print("[myDEBUG] Button pressed")
        if not check_permission('android.permission.SEND_SMS'):
            request_permissions([Permission.SEND_SMS])

        sms.send(self.recipient.text, self.message)
        vibrator.vibrate(0.3)
Exemple #9
0
    def build(self):
        if platform == "android" and not check_permission(
                "android.permission.WRITE_EXTERNAL_STORAGE"):
            request_permissions([Permission.WRITE_EXTERNAL_STORAGE])

        self.ydl_opts["quiet"] = self.config.get("general", "quiet")
        self.ydl_opts["nowarning"] = self.config.get("general", "nowarning")
        self.ydl_opts["ignoreerrors"] = self.config.get(
            "general", "ignoreerrors")
        self.ydl_opts["call_home"] = self.config.get("general", "call_home")
        self.ydl_opts["nocheckcertificate"] = self.config.get(
            "general", "nocheckcertificate")
        self.ydl_opts["prefer_insecure"] = self.config.get(
            "general", "prefer_insecure")
        self.ydl_opts["outtmpl"] = join(
            self.config.get("general", "savedir"),
            self.config.get("general", "filetmpl"),
        )

        if self.config.get("general", "method") == "Preset":
            self.ydl_opts["format"] = self.config.get("general", "preset")
        elif self.config.get("general", "method") == "Custom":
            self.ydl_opts["format"] = self.config.get("general", "custom")

        self.use_kivy_settings = False
        return RootLayout()
Exemple #10
0
 def ask_nicely(self, *permissions):
     from android.permissions import (check_permission, request_permission,
                                      request_permissions)
     request_permissions([
         permission for permission in permissions
         if not check_permission(permission)
     ])
Exemple #11
0
 def check_request_permission():
     if platform != "android":
         return
     from android.permissions import (
         Permission, request_permission, check_permission)
     permission = Permission.CAMERA
     if not check_permission(permission):
         request_permission(permission)
Exemple #12
0
    def build(self):
        if not check_permission(Permission.CAMERA):
            print('Permission for Camera not accepted, will request now')
            request_permission(Permission.CAMERA)
        else:
            print('Permission OK')

        return CameraWidget()
Exemple #13
0
 def ensure_permission(self, permission):
     if platform != 'android':
         return
     from android.permissions import check_permission, request_permission, Permission
     permission = getattr(Permission, permission)
     if check_permission(permission):
         return True
     return request_permission(permission)
Exemple #14
0
 def __init__(self):
     self.register_event_type('on_cube_found')
     self.register_event_type('on_paired_cube_found')
     super().__init__()
     self.default_adapter = BluetoothAdapter.getDefaultAdapter()
     self.gatt_callback = None
     if not check_permission('android.permission.ACCESS_COARSE_LOCATION'):
         request_permissions([Permission.ACCESS_COARSE_LOCATION])
Exemple #15
0
def check_camera_permission():
    """
    Android runtime `CAMERA` permission check.
    """
    if not is_android():
        return True
    from android.permissions import Permission, check_permission
    permission = Permission.CAMERA
    return check_permission(permission)
Exemple #16
0
 def check_request_permission():
     """
     Android runtime storage permission check.
     """
     if platform != "android":
         return
     from android.permissions import (Permission, request_permission,
                                      check_permission)
     permission = Permission.CAMERA
     if not check_permission(permission):
         request_permission(permission)
 def second_thread(self, data):
     print("starting second thread")
     permission_status = check_permission(Permission.WRITE_EXTERNAL_STORAGE)
     print(permission_status)
     
     if permission_status is not None and permission_status:
         print("got permission")
         path = os.environ["SECONDARY_STORAGE"]
         test_path = os.path.join(path, "test_yay")
         os.makedirs(test_path)
     else:
         Clock.schedule_once(self.second_thread, 1)
Exemple #18
0
    def attempt_stream_camera(self, camera):
        """Start streaming from the given camera, if we have the CAMERA
        permission, otherwise request the permission first.
        """

        if check_permission(Permission.CAMERA):
            self.stream_camera(camera)
        else:
            self.camera_permission_state = PermissionRequestStates.AWAITING_REQUEST_RESPONSE
            request_permission(
                Permission.CAMERA,
                partial(self._request_permission_callback, camera))
Exemple #19
0
 def build(self):
     while not check_permission(
             'android.permission.WRITE_EXTERNAL_STORAGE'):
         request_permissions([
             Permission.READ_EXTERNAL_STORAGE,
             Permission.WRITE_EXTERNAL_STORAGE
         ])
     Window.keyboard_anim_args = {'d': .2, 't': 'in_out_expo'}
     Window.softinput_mode = "resize"
     self.theme_cls.primary_palette = "DeepPurple"
     master = Builder.load_file('main.kv')
     self.val = 0
     return master
Exemple #20
0
 def choose(self, is_backup=True, *args):
     """
     Call plyer filechooser API to run a filechooser Activity.
     """
     if platform == "android":
         from android.permissions import request_permissions, Permission, check_permission
         # Check if the permissions still granted.
         if not check_permission(Permission.WRITE_EXTERNAL_STORAGE):
             request_permissions([Permission.WRITE_EXTERNAL_STORAGE])
         else:
             filechooser.open_file(on_selection=self.backup_db
                                   if is_backup else self.restore_db)
     else:
         filechooser.open_file(
             on_selection=self.backup_db if is_backup else self.restore_db)
Exemple #21
0
        def inner_wrapper(*args, **kwargs):
            if PLATFORM == 'android':
                if check_permission(Permission.WRITE_EXTERNAL_STORAGE):
                    return func(*args, **kwargs)

                def callback(permissions, grant_results):
                    if grant_results[0]:
                        return func(*args, **kwargs)
                    else:
                        return fallback_func()

                request_permissions([Permission.WRITE_EXTERNAL_STORAGE],
                                    callback)
                return

            return func(*args, **kwargs)
Exemple #22
0
    def build(self):
        request_permissions(PERMISSIONS, callback=lambda p, r: print(p, r))

        while not all(
                check_permission(permission) for permission in PERMISSIONS):
            print("Waiting for permissions...")
            time.sleep(1)

        with pocket_casts() as api:
            # Get all podcast titles
            titles_by_uuid: t.Dict[str, str] = api.podcasts()

            # Get list of episodes in "up next"
            episodes_from_pocketcasts: t.List[Episode] = api.up_next()

            # Create download screen
            return SyncLayout(episodes_from_pocketcasts, )
Exemple #23
0
    def build(self):
        if platform == 'android' and not check_permission('android.permission.WRITE_EXTERNAL_STORAGE'):
            request_permissions([Permission.WRITE_EXTERNAL_STORAGE])

        self.ydl_opts['quiet'] = self.config.get('general', 'quiet')
        self.ydl_opts['nowarning'] = self.config.get('general', 'nowarning')
        self.ydl_opts['ignoreerrors'] = self.config.get('general', 'ignoreerrors')
        self.ydl_opts['call_home'] = self.config.get('general', 'call_home')
        self.ydl_opts['nocheckcertificate'] = self.config.get('general', 'nocheckcertificate')
        self.ydl_opts['prefer_insecure'] = self.config.get('general', 'prefer_insecure')
        self.ydl_opts['outtmpl'] = join(self.config.get('general', 'savedir'),
                                        self.config.get('general', 'filetmpl'))

        if self.config.get('general', 'method') == 'Preset':
            self.ydl_opts['format'] = self.config.get('general', 'preset')
        elif self.config.get('general', 'method') == 'Custom':
            self.ydl_opts['format'] = self.config.get('general', 'custom')

        self.use_kivy_settings = False
        return RootLayout()
Exemple #24
0
    def get_permissions_and_run_func(self, func, clock=False):
        try:
            write_external_storage = check_permission(
                Permission.WRITE_EXTERNAL_STORAGE)
            print(write_external_storage, flush=True)
            if write_external_storage is not None and write_external_storage:
                print("we")
            else:
                request_permission(Permission.WRITE_EXTERNAL_STORAGE)
                Clock.schedule_once(
                    lambda dt: self.get_permissions_and_run_func(func, clock),
                    0.5)
        except NameError:
            print("not android")

        finally:
            if clock:
                Clock.schedule_once(lambda dt: func())
            else:
                threading.Thread(target=self.build_gallery, args=()).start()
        return
def ask_permission(permission, callback=_on_permission_result):
    """ Necessary on Android to request permission for certain actions.
    Returns immediate check for permissions and doesn't wait for results of request.
    Once results of request are in the callback must handle those.
    
    Note that if the request is interrupted the callback may contain an empty list of permissions,
    without permissions being granted. The App should check that each permission requested has been granted.
    
    :type permission: str
    :type callback: Callable
    :rtype: bool
    """
    if platform == 'android':
        # request_permissions should only be called with a callback
        # if calling check_permission has indicated that it is necessary.
        got_permission = check_permission(permission)
        if not got_permission:
            request_permission(permission, callback=callback)
        # Return doesn't wait for request's results. So it's False if permissions have not yet been granted.
        return got_permission
    # For any other platform assume given permission.
    return True
    def checkPlatform(self, button):
        if platform == "android":
            from android.permissions import (
                check_permission,
                request_permissions,
                Permission,
            )

            if check_permission("android.permission.WRITE_EXTERNAL_STORAGE"):
                if isinstance(button, MDSwitch):
                    self.autoBackupFunction(active=button.active)
                else:
                    self.databaseFunctions(text=button.text)
            else:
                if isinstance(button, MDSwitch):
                    if button.active:  # request_permissions only run when switch active
                        request_permissions(
                            [
                                Permission.READ_EXTERNAL_STORAGE,
                                Permission.WRITE_EXTERNAL_STORAGE,
                            ],
                            partial(self.autoBackupFunction,
                                    active=button.active),
                        )
                else:
                    request_permissions(
                        [
                            Permission.READ_EXTERNAL_STORAGE,
                            Permission.WRITE_EXTERNAL_STORAGE,
                        ],
                        partial(self.databaseFunctions, text=button.text),
                    )

        else:
            if isinstance(button, MDSwitch):
                self.autoBackupFunction(active=button.active)
            else:
                self.databaseFunctions(text=button.text)
Exemple #27
0
    def select_zip(self, *args):
        if platform == 'android':

            if check_permission(
                    Permission.WRITE_EXTERNAL_STORAGE
            ) == False:  # check permission takes str not a list
                request_permission(Permission.WRITE_EXTERNAL_STORAGE)
                request_permission(Permission.READ_EXTERNAL_STORAGE)
                request_permission(Permission.MANAGE_EXTERNAL_STORAGE)
                request_permission(Permission.MANAGE_DOCUMENTS)

                #request_permisssion takes str and request_permissions takes list
                return
            self.secondary_ext_storage = secondary_external_storage_path()
            self.primary_ext_storage = primary_external_storage_path()
            self.app_path = app_storage_path()

            Logger.debug(" Storages are \n" + str(self.app_path) + "\n" +
                         str(self.primary_ext_storage))
        else:
            #self.root.ids.status_label.text = " I am not running in android "
            pass
        self.file_manager_open()
Exemple #28
0
def get_permission():
    if not check_permission(Permission.WRITE_EXTERNAL_STORAGE):
        request_permissions([Permission.WRITE_EXTERNAL_STORAGE])
Exemple #29
0
 def camera_mirror(self, b):
     if check_permission(Permission.CAMERA):
         self.cameraxf = CameraXF(capture='none', facing='front')
         self.cameraxf.bind(on_dismiss=self._dismissed)
Exemple #30
0
    def show_first_form(self):
        global STORAGE

        ip_tab = []
        if netifaces:
            interfaces = netifaces.interfaces()
            for interface in interfaces:
                if interface[:2] in ('wl', 'en', 'et'):
                    ifaddress = netifaces.ifaddresses(interface)
                    if netifaces.AF_INET in ifaddress:
                        inets = ifaddress[netifaces.AF_INET]
                        for inet in inets:
                            if 'addr' in inet:
                                addr = inet['addr']
                                if len(addr.split('.')) == 4:
                                    ip_tab.append(addr)
        else:
            try:
                ip_address = get_ip_address(b'wlan0')
                ip_tab.append(ip_address)
            except:
                pass

        if ip_tab:
            ip_address = ', '.join(ip_tab)
        else:
            ip_address = '-'

        label = Label(text=f"[size=18sp][color=88f][b]PYTIGON - select the application:[/b][/color][/size]\n[size=15sp][color=448](my ip addresses: {ip_address})[/b][/color][/size]",
                      markup=True, halign = 'center')
        self.add_widget(label)

        if not check_permission(Permission.WRITE_EXTERNAL_STORAGE):
            ret = request_permissions(PERMISSION)
            print("python::pytigon::request_permissions", ret)

        init("_schall", schserw_settings.ROOT_PATH, schserw_settings.DATA_PATH, schserw_settings.PRJ_PATH,
             schserw_settings.STATIC_APP_ROOT, [schserw_settings.MEDIA_ROOT, schserw_settings.UPLOAD_PATH])

        base_apps_path = os.path.join(os.path.join(STORAGE, "pytigon"), "prj")
        l = [pos for pos in os.listdir(base_apps_path) if not pos.startswith('_')]
        apps = []
        for prj in l:
            base_apps_path2 = os.path.join(base_apps_path, prj)
            try:
                x = __import__(prj + ".apps")
                if hasattr(x.apps, 'PUBLIC') and x.apps.PUBLIC:
                    apps.append(prj)
            except:
                print("Error importing module: ", prj + ".apps")

        if len(apps) > 1:
            if len(apps) > MAX_SEL_APP:
                dy = MAX_SEL_APP - 1
            else:
                dy = len(apps)

            for pos in apps[:dy]:
                button = Button(id=pos, text=pos, size_hint=(1, 1))
                button.bind(on_release=self.chose_callback)
                self.add_widget(button)

            if len(apps) > MAX_SEL_APP:
                spinner = Spinner(
                    text='Other applications',
                    values=apps[dy:],
                    size_hint=(.5, 1),
                    pos_hint={'center_x': 0.5, }
                )
                spinner.bind(text=self.spinner_callback)
                self.add_widget(spinner)
        else:
            if len(apps) > 0:
                self.on_app_chosen(apps[0])
            else:
                self.on_app_chosen()
Exemple #31
0
 def camera_qrcode(self, b):
     if check_permission(Permission.CAMERA):
         self.cameraxf = CameraXF(capture='data', callback=self.analyze)
         if add_qrreader:
             self.qrreader = QRReader(self.cameraxf)
         self.cameraxf.bind(on_dismiss=self._dismissed)