o
    ðT·jð'  ã                   @  sÎ   U d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	m
Z
 ddlmZ ddlmZ G d	d
„ d
eƒZddd„Ze
dd�ddd„ƒZe dej¡Zded< ddd„Zddd„Ze	ddd„ƒZd
gZdS ) zAndroid.é    )ÚannotationsN)Úsuppress)ÚcacheÚ	lru_cache)ÚFinalé   )ÚPlatformDirsABCc                   @  sŠ  e Zd ZdZed;dd„ƒZed;dd„ƒZed;dd	„ƒZed;d
d„ƒZed;dd„ƒZ	ed;dd„ƒZ
ed;dd„ƒZed;dd„ƒZed;dd„ƒZed;dd„ƒZed;dd„ƒZed;dd„ƒZed;dd„ƒZed;dd„ƒZed;d d!„ƒZed;d"d#„ƒZed;d$d%„ƒZed;d&d'„ƒZed;d(d)„ƒZed;d*d+„ƒZed;d,d-„ƒZed;d.d/„ƒZed;d0d1„ƒZed;d2d3„ƒZed;d4d5„ƒZed;d6d7„ƒZed;d8d9„ƒZd:S )<ÚAndroidaî  Platform directories for Android.

    Follows the guidance `from here <https://android.stackexchange.com/a/216132>`_. Directories are typically located
    under the app's private storage (``/data/user/<userid>/<packagename>/``).

    Makes use of the `appname <platformdirs.api.PlatformDirsABC.appname>`, `version
    <platformdirs.api.PlatformDirsABC.version>`, `opinion <platformdirs.api.PlatformDirsABC.opinion>`, `ensure_exists
    <platformdirs.api.PlatformDirsABC.ensure_exists>`.

    ÚreturnÚstrc                 C  ó   |   tƒ d¡S )z\Data directory tied to the user, e.g. ``/data/user/<userid>/<packagename>/files/<AppName>``.Úfiles©Ú_append_app_name_and_versionÚ_require_android_folder©Úself© r   úW/home/dinkstrade/pdmp-scanner/venv/lib/python3.10/site-packages/platformdirs/android.pyÚuser_data_dir   ó   zAndroid.user_data_dirc                 C  ó   | j S )z8Data directory shared by users, same as `user_data_dir`.©r   r   r   r   r   Úsite_data_dir    ó   zAndroid.site_data_dirc                 C  r   )zeConfig directory tied to the user, e.g. ``/data/user/<userid>/<packagename>/shared_prefs/<AppName>``.Úshared_prefsr   r   r   r   r   Úuser_config_dir%   r   zAndroid.user_config_dirc                 C  r   )z<Config directory shared by users, same as `user_config_dir`.©r   r   r   r   r   Úsite_config_dir*   r   zAndroid.site_config_dirc                 C  r   )z]Cache directory tied to the user, e.g.,``/data/user/<userid>/<packagename>/cache/<AppName>``.r   r   r   r   r   r   Úuser_cache_dir/   r   zAndroid.user_cache_dirc                 C  r   )z:Cache directory shared by users, same as `user_cache_dir`.)r   r   r   r   r   Úsite_cache_dir4   r   zAndroid.site_cache_dirc                 C  r   )z:State directory tied to the user, same as `user_data_dir`.r   r   r   r   r   Úuser_state_dir9   r   zAndroid.user_state_dirc                 C  r   )z:State directory shared by users, same as `user_state_dir`.)r!   r   r   r   r   Úsite_state_dir>   r   zAndroid.site_state_dirc                 C  ó(   | j }| jrtj |d¡}|  |¡ |S )zŸLog directory tied to the user, same as `user_cache_dir` if not opinionated else ``log`` in it, e.g. ``/data/user/<userid>/<packagename>/cache/<AppName>/log``.Úlog©r   ÚopinionÚosÚpathÚjoinÚ_optionally_create_directory©r   r(   r   r   r   Úuser_log_dirC   ó
   
zAndroid.user_log_dirc                 C  r   )z6Log directory shared by users, same as `user_log_dir`.)r,   r   r   r   r   Úsite_log_dirL   r   zAndroid.site_log_dirc                 C  ó   t dƒS )zLDocuments directory tied to the user e.g. ``/storage/emulated/0/Documents``.Ú	Documents©Ú_android_public_folderr   r   r   r   Úuser_documents_dirQ   ó   zAndroid.user_documents_dirc                 C  r/   )zKDownloads directory tied to the user e.g. ``/storage/emulated/0/Download``.ÚDownloadr1   r   r   r   r   Úuser_downloads_dirV   r4   zAndroid.user_downloads_dirc                 C  r/   )zJPictures directory tied to the user e.g. ``/storage/emulated/0/Pictures``.ÚPicturesr1   r   r   r   r   Úuser_pictures_dir[   r4   zAndroid.user_pictures_dirc                 C  r/   )zFVideos directory tied to the user e.g. ``/storage/emulated/0/Movies``.ÚMoviesr1   r   r   r   r   Úuser_videos_dir`   r4   zAndroid.user_videos_dirc                 C  r/   )zDMusic directory tied to the user e.g. ``/storage/emulated/0/Music``.ÚMusicr1   r   r   r   r   Úuser_music_dire   r4   zAndroid.user_music_dirc                 C  ó   t ƒ › d�S )zRDesktop directory tied to the user e.g. ``/storage/emulated/0/Documents/Desktop``.z/Documents/Desktop©Ú_shared_storager   r   r   r   Úuser_desktop_dirk   ó   zAndroid.user_desktop_dirc                 C  r=   )zTProjects directory tied to the user e.g. ``/storage/emulated/0/Documents/Projects``.z/Documents/Projectsr>   r   r   r   r   Úuser_projects_dirp   rA   zAndroid.user_projects_dirc                 C  r=   )zVPublic share directory tied to the user e.g. ``/storage/emulated/0/Documents/Public``.z/Documents/Publicr>   r   r   r   r   Úuser_publicshare_diru   rA   zAndroid.user_publicshare_dirc                 C  r=   )zVTemplates directory tied to the user e.g. ``/storage/emulated/0/Documents/Templates``.z/Documents/Templatesr>   r   r   r   r   Úuser_templates_dirz   rA   zAndroid.user_templates_dirc                 C  r=   )zNFonts directory tied to the user e.g. ``/storage/emulated/0/Documents/fonts``.z/Documents/fontsr>   r   r   r   r   Úuser_fonts_dir   rA   zAndroid.user_fonts_dirc                 C  r   )zCPreference directory tied to the user, same as ``user_config_dir``.r   r   r   r   r   Úuser_preference_dir„   r   zAndroid.user_preference_dirc                 C  s   t j tƒ dd¡S )zUBin directory tied to the user, e.g. ``/data/user/<userid>/<packagename>/files/bin``.r   Úbin)r'   r(   r)   r   r   r   r   r   Úuser_bin_dir‰   s   zAndroid.user_bin_dirc                 C  r   )z6Bin directory shared by users, same as `user_bin_dir`.)rH   r   r   r   r   Úsite_bin_dirŽ   r   zAndroid.site_bin_dirc                 C  r   )zAApplications directory tied to the user, same as `user_data_dir`.r   r   r   r   r   Úuser_applications_dir“   r   zAndroid.user_applications_dirc                 C  r   )zHApplications directory shared by users, same as `user_applications_dir`.)rJ   r   r   r   r   Úsite_applications_dir˜   r   zAndroid.site_applications_dirc                 C  r#   )z£Runtime directory tied to the user, same as `user_cache_dir` if not opinionated else ``tmp`` in it, e.g. ``/data/user/<userid>/<packagename>/cache/<AppName>/tmp``.Útmpr%   r+   r   r   r   Úuser_runtime_dir�   r-   zAndroid.user_runtime_dirc                 C  r   )z>Runtime directory shared by users, same as `user_runtime_dir`.)rM   r   r   r   r   Úsite_runtime_dir¦   r   zAndroid.site_runtime_dirN©r
   r   ) Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úpropertyr   r   r   r   r   r    r!   r"   r,   r.   r3   r6   r8   r:   r<   r@   rB   rC   rD   rE   rF   rH   rI   rJ   rK   rM   rN   r   r   r   r   r	      sp    r	   r
   r   c                  C  s   t ƒ  } d u rd}t|ƒ‚| S )Nzfcannot find the Android app folder: python4android and pyjnius failed and no app folder is on sys.path)Ú_android_folderÚRuntimeError)ÚfolderÚmsgr   r   r   r   ¬   s   r   )Úmaxsizeú
str | Nonec                  C  sŒ   t ƒ } | du r#t dtj¡}tjD ]}| |¡ }r |d }  nqd} | du rDt dtj¡}tjD ]}| |¡ }rA|d }  | S q1d} | S )zF:returns: base folder for the Android OS or None if it cannot be foundNa3  
            (?P<folder>
                /data/(?:data|user/\d+)  # internal storage of the primary user or of user N
                /[^/]+                   # package name, one path segment
            )
            /files                       # the files directory the interpreter runs from
            rW   aˆ  
            (?P<folder>
                /mnt/expand/[a-fA-F0-9-]{36}  # adopted storage volume, named by its UUID
                /(?:data|user/\d+)             # the primary user or user N
                /[^/]+                         # package name, one path segment
            )
            /files                             # the files directory the interpreter runs from
            )Ú_python_for_android_folderÚreÚcompileÚVERBOSEÚsysr(   Úmatch)ÚresultÚpatternr(   r`   r   r   r   rU   ³   s2   ø

þ÷
ûrU   z¼
    /user/         # the per-user data root, under /data or an adopted /mnt/expand volume
    (?P<user>\d+)  # the Android user id
    /              # followed by the package folder
    r   Ú_USER_IDc                  C  s*   t  tƒ pd¡ } r| d nd}d|› �S )NÚ ÚuserÚ0z/storage/emulated/)rc   ÚsearchrU   )r`   re   r   r   r   r?   ë   s    
r?   c               	   C  sÆ   t tƒ�U ddlm} m} t | ƒ�0 |dƒj }d u r |dƒj}|d ur:| ¡  ¡  	¡ W  d   ƒ W  d   ƒ S W d   ƒ n1 sDw   Y  W d   ƒ d S W d   ƒ d S 1 s\w   Y  d S )Nr   ©ÚJavaExceptionÚ	autoclasszorg.kivy.android.PythonActivityzorg.kivy.android.PythonService)
r   ÚImportErrorÚjniusri   rj   Ú	mActivityÚmServiceÚgetFilesDirÚgetParentFileÚgetAbsolutePath)ri   rj   Úcontextr   r   r   r[   ñ   s$   


ûýü
ý	ú
ý	÷	r[   Únamec              	   C  s�   t tƒ�4 ddlm}m} t |ƒ� |dƒ | ¡ ¡ W  d   ƒ W  d   ƒ S 1 s,w   Y  W d   ƒ n1 s;w   Y  tƒ › d| › �S )Nr   rh   zandroid.os.Environmentú/)r   rk   rl   ri   rj   Ú!getExternalStoragePublicDirectoryrq   r?   )rs   ri   rj   r   r   r   r2   þ   s   

ÿýýr2   rO   )r
   rZ   )rs   r   r
   r   )rS   Ú
__future__r   r'   r\   r_   Ú
contextlibr   Ú	functoolsr   r   Útypingr   Úapir   r	   r   rU   r]   r^   rc   Ú__annotations__r?   r[   r2   Ú__all__r   r   r   r   Ú<module>   s0     
-ú



ÿ