U
    d+                     @  s   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	 ddl
mZ G dd	 d	eZedd
ddddZedd
ddddZedd
ddddZedd
ddddZedd
ddddZedd
ddddZd	gZdS )zAndroid.    )annotationsN)	lru_cache)cast   )PlatformDirsABCc                   @  s  e Zd ZdZeddddZeddddZedddd	Zeddd
dZeddddZ	eddddZ
eddddZeddddZeddddZeddddZeddddZeddddZeddddZeddddZd S )!Androida$  
    Follows the guidance `from here <https://android.stackexchange.com/a/216132>`_. Makes use of the
    `appname <platformdirs.api.PlatformDirsABC.appname>`,
    `version <platformdirs.api.PlatformDirsABC.version>`,
    `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
    strreturnc                 C  s   |  ttt dS )zd:return: data directory tied to the user, e.g. ``/data/user/<userid>/<packagename>/files/<AppName>``filesZ_append_app_name_and_versionr   r   _android_folderself r   A/tmp/pip-install-xwugzb3_/pip/pip/_vendor/platformdirs/android.pyuser_data_dir   s    zAndroid.user_data_dirc                 C  s   | j S )z@:return: data directory shared by users, same as `user_data_dir`r   r   r   r   r   site_data_dir   s    zAndroid.site_data_dirc                 C  s   |  ttt dS )z
        :return: config directory tied to the user, e.g.         ``/data/user/<userid>/<packagename>/shared_prefs/<AppName>``
        Zshared_prefsr   r   r   r   r   user_config_dir   s    zAndroid.user_config_dirc                 C  s   | j S )zH:return: config directory shared by the users, same as `user_config_dir`)r   r   r   r   r   site_config_dir'   s    zAndroid.site_config_dirc                 C  s   |  ttt dS )zj:return: cache directory tied to the user, e.g. e.g. ``/data/user/<userid>/<packagename>/cache/<AppName>``cacher   r   r   r   r   user_cache_dir,   s    zAndroid.user_cache_dirc                 C  s   | j S )zB:return: cache directory shared by users, same as `user_cache_dir`)r   r   r   r   r   site_cache_dir1   s    zAndroid.site_cache_dirc                 C  s   | j S )zB:return: state directory tied to the user, same as `user_data_dir`r   r   r   r   r   user_state_dir6   s    zAndroid.user_state_dirc                 C  s   | j }| jrtj|d}|S )z
        :return: 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r   r   r   r   r   user_log_dir;   s    zAndroid.user_log_dirc                 C  s   t  S )zT:return: documents directory tied to the user e.g. ``/storage/emulated/0/Documents``)_android_documents_folderr   r   r   r   user_documents_dirF   s    zAndroid.user_documents_dirc                 C  s   t  S )zT:return: downloads directory tied to the user e.g. ``/storage/emulated/0/Downloads``)_android_downloads_folderr   r   r   r   user_downloads_dirK   s    zAndroid.user_downloads_dirc                 C  s   t  S )zR:return: pictures directory tied to the user e.g. ``/storage/emulated/0/Pictures``)_android_pictures_folderr   r   r   r   user_pictures_dirP   s    zAndroid.user_pictures_dirc                 C  s   t  S )zS:return: videos directory tied to the user e.g. ``/storage/emulated/0/DCIM/Camera``)_android_videos_folderr   r   r   r   user_videos_dirU   s    zAndroid.user_videos_dirc                 C  s   t  S )zL:return: music directory tied to the user e.g. ``/storage/emulated/0/Music``)_android_music_folderr   r   r   r   user_music_dirZ   s    zAndroid.user_music_dirc                 C  s   | j }| jrtj|d}|S )z
        :return: 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_   s    zAndroid.user_runtime_dirN)__name__
__module____qualname____doc__propertyr   r   r   r   r   r   r   r"   r$   r&   r(   r*   r,   r.   r   r   r   r   r      s:   
r   )maxsizez
str | Noner	   c                  C  sx   z(ddl m}  | d}|   }W nJ tk
rr   td}tj	D ] }|
|rH|dd } qnqHd}Y nX |S )zE:return: base folder for the Android OS or None if it cannot be foundr   	autoclassandroid.content.Contextz /data/(data|user/\d+)/(.+)/filesz/filesN)jniusr6   ZgetFilesDirZgetParentFilegetAbsolutePath	Exceptionrecompilesysr   matchsplit)r6   contextresultpatternr   r   r   r   r   k   s    



r   r   c                  C  sN   z0ddl m}  | d}| d}||j }W n tk
rH   d}Y nX |S )z,:return: documents folder for the Android OSr   r5   r7   android.os.Environmentz/storage/emulated/0/Documents)r8   r6   getExternalFilesDirZDIRECTORY_DOCUMENTSr9   r:   )r6   r@   environmentZdocuments_dirr   r   r   r#      s    
r#   c                  C  sN   z0ddl m}  | d}| d}||j }W n tk
rH   d}Y nX |S )z,:return: downloads folder for the Android OSr   r5   r7   rC   z/storage/emulated/0/Downloads)r8   r6   rD   ZDIRECTORY_DOWNLOADSr9   r:   )r6   r@   rE   Zdownloads_dirr   r   r   r%      s    
r%   c                  C  sN   z0ddl m}  | d}| d}||j }W n tk
rH   d}Y nX |S )z+:return: pictures folder for the Android OSr   r5   r7   rC   z/storage/emulated/0/Pictures)r8   r6   rD   ZDIRECTORY_PICTURESr9   r:   )r6   r@   rE   Zpictures_dirr   r   r   r'      s    
r'   c                  C  sN   z0ddl m}  | d}| d}||j }W n tk
rH   d}Y nX |S )z):return: videos folder for the Android OSr   r5   r7   rC   z/storage/emulated/0/DCIM/Camera)r8   r6   rD   ZDIRECTORY_DCIMr9   r:   )r6   r@   rE   Z
videos_dirr   r   r   r)      s    
r)   c                  C  sN   z0ddl m}  | d}| d}||j }W n tk
rH   d}Y nX |S )z(:return: music folder for the Android OSr   r5   r7   rC   z/storage/emulated/0/Music)r8   r6   rD   ZDIRECTORY_MUSICr9   r:   )r6   r@   rE   Z	music_dirr   r   r   r+      s    
r+   )r2   
__future__r   r   r;   r=   	functoolsr   typingr   apir   r   r   r#   r%   r'   r)   r+   __all__r   r   r   r   <module>   s,   ^