+
     Gi<$  c                   s    ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIH	t	 R t
R tR tR tR tR	 tR
 tR tR# )i    N)helpers)whichc                 s   a a \         P                  ! 4       p\        R4      p\        V4      o\	        V V3R l^ 4       F  pVP                  SRV 4       K  	  S P                  ^ 4       VP                  4       # )i   c                  s&   < S P                  S4      # )N)Zreadinto)fmvs   )/usr/lib/waydroid/tools/helpers/images.pyZ<lambda>Zsha256sum.<locals>.<lambda>   s    !**R.    Ni   )hashlibZsha256Z	bytearrayZ
memoryviewZiterZupdateZseekZ	hexdigest)r   ZhZbZnr   s   f   @r   	sha256sumr      s]    A(A	AB(!,	BQ -FF1I;;=r   c           
      sT
   \         P                  P                  V 4      pVR ,          R,          p\        P                  P                  V4      pV^ ,          ^8w  d-   \        RP                  V P                  V^ ,          4      4      h\        P                  ! V^,          P                  R4      4      R,          p\        V4      ^8  d   \        R4      hV EF  pVR,          \        VR ,          R,          4      8  g   K+  \        P                  P                  WR,          VR	,          R
R7      p\        P                   ! R4       \#        VR4      ;_uu_ 4       p\%        V4      VR,          8w  d9    \&        P(                  ! V4       \        RP                  TR,          4      4      h\        P                   ! RV P*                  ,           4       \,        P.                  ! VR4      ;_uu_ 4       pVP1                  V P*                  4       RRR4       RRR4       \3        VR,          4      VR ,          R&   \         P                  P5                  W4       \&        P(                  ! V4        M	  VR ,          R,          p	\        P                  P                  V	4      p
V
^ ,          ^8w  d"   \        RP                  W^ ,          4      4      h\        P                  ! V
^,          P                  R4      4      R,          p\        V4      ^8  d   \        R4      hV EF  pVR,          \        VR ,          R,          4      8  g   K+  \        P                  P                  WR,          VR	,          R
R7      p\        P                   ! R4       \#        VR4      ;_uu_ 4       p\%        V4      VR,          8w  d9    \&        P(                  ! V4       \        RP                  TR,          4      4      h\        P                   ! RV P*                  ,           4       \,        P.                  ! VR4      ;_uu_ 4       pVP1                  V P*                  4       RRR4       RRR4       \3        VR,          4      VR ,          R&   \         P                  P5                  W4       \&        P(                  ! V4        M	  \7        V 4       R#     ELD; i  + '       g   i     EL; i  + '       g   i     EL; i    EL*; i  + '       g   i     L; i  + '       g   i     L; i)waydroid
system_otaz/Failed to get system OTA channel: {}, error: {}utf8responsez!No images found on system channelZdatetimesystem_datetimeZurlZfilenameF)ZcachezValidating system imagerbidz8Downloaded system image hash doesn't match, expected: {}zExtracting to rN
vendor_otaz/Failed to get vendor OTA channel: {}, error: {}z!No images found on vendor channelvendor_datetimezValidating vendor imagez8Downloaded vendor image hash doesn't match, expected: {})toolsconfigloadr    httpretrieveZ
ValueErrorZformatr	   jsonloadsdecodeZlenZintZdownloadloggingZinfoopenr   osremoveimages_pathzipfileZipFile
extractallstrsaveremove_overlay)argscfgr	   Zsystem_requestZsystem_responsesZsystem_responseZ
images_zipr   zip_refr   Zvendor_requestZvendor_responsesZvendor_responses   &            r   getr(      s   
,,

D
!CZ.J\\**:6NaC=DDT__VdefVghj 	jzz."3":":6"BCJO
q <==+:&S_=N-O)PP ..e,oj.IQV / XJLL23j$''1Q<?4#88		*- %%_%f%f'-&/ 0 0-0@0@@A__Q,,&&t'7'78 - ( 25_Z5P1QC
O-.LLd(IIj!' ,* Z.J\\**:6NaC=DDZ`aQbce 	ezz."3":":6"BCJO
q <==+:&S_=N-O)PP ..e,oj.IQV / XJLL23j$''1Q<?4#88		*- %%_%f%f'-&/ 0 0-0@0@@A__Q,,&&t'7'78 - ( 25_Z5P1QC
O-.LLd(IIj!' ,( 4S -,, (''D -, ('sz   S(7SA'S(4SS((TS<A'T>TTS	S(S%	S((S9<T	>TTTT'c                 s   \         P                  P                  V 4      pVR ,          V,          p\        P                  P                  V4      pV^ ,          ^8w  d   R# \        P                  ! V^,          P                  R4      4      R,          p\        V4      pV F  pWxR,          8X  g   K   R# 	  \        P                  ! RVP                   RV 24       R# )r   Fr
   r   r   TzCould not verify the image z	 against )r   r   r   r    r   r   r   r   r   r   r   warningZname)	r%   Zchannelr   r&   Zchannel_urlZchannel_requestZchannel_responsesZchksumZbuilds	   &&&      r   validater*   W   s    
,,

D
!Cj/'*Kll++K8OqS 

?1#5#<#<V#DEjQq\F"4[  # OO1!&&;-PQr   c           	      s   \         P                  P                  V 4      pVR ,          R,          V n        \        P
                  P                  V4      '       d   \        VR4      ;_uu_ 4       p\        V RV4      '       dZ   \        P                  ! VR4      ;_uu_ 4       pVP                  V P                  4       RRR4       \        V4      VR ,          R&   M\        P                  ! R4       RRR4       \        P                  ! V4       \        P
                  P                  V4      '       d   \        VR4      ;_uu_ 4       p\        V RV4      '       dZ   \        P                  ! VR4      ;_uu_ 4       pVP                  V P                  4       RRR4       \        V4      VR ,          R	&   M\        P                  ! R
4       RRR4       \        P                  ! V4       \         P                  P!                  W4       \#        V 4       R#   + '       g   i     ELa; i  + '       g   i     ELA; i  + '       g   i     L; i  + '       g   i     L; i)r   r   r   r	   r   Nr   z0Failed to validate update system image, ignoringr   r   z0Failed to validate update vendor image, ignoring)r   r   r   r   r   pathZexistsr   r*   r   r    r!   r"   r   r)   r   r#   r$   )r%   Z
system_zipZsystem_timeZ
vendor_zipZvendor_timer&   r   r'   s   &&&&&   r   replacer,   f   s   
,,

D
!C:}5D	ww~~j!!*d##qlA..__Q,,&&t'7'78 -585EJ 12 RS $ 			*	ww~~j!!*d##qlA..__Q,,&&t'7'78 -585EJ 12 RS $ 			*	LLd 4! -,, $## -, $#sH   .3H)!H	=4H)3I;H=	4IH& 	H))H:	=III 	c                 s   \         P                  P                  \        P                  P
                  R ,          4      '       d6   \        P                  ! \        P                  P
                  R ,          4       \         P                  P                  \        P                  P
                  R,          4      '       d8   \        P                  ! \        P                  P
                  R,          4       R# R# )
overlay_rwoverlay_workN)r   r+   isdirr   r   defaultsshutilZrmtreer%      &r   r$   r$   ~   s    	ww}}U\\**<899ell++L9:	ww}}U\\**>:;;ell++N;< <r   c                 sV  aa \         P                  P                  V P                  R ,           4      '       g   \	        R4      h\        V P                  R ,           4      ;_uu_ 4       pVP                  4       P                  4       oRRR4       S'       g   \	        R4      hVV3R lpV! RR4       V! RR4       V! R	R
4       V! RR4       V! RR4       SP                  R\        P                  P                  R,          ,           4       SP                  R\        P                  P                  R,          ,           4       SP                  R\        P                  P                  R,          ,           4       \        R4      f   SP                  R4       SR,          pVR8w  d   SP                  RV,           4       \        VR4      pS F  pVP                  VR,           4       K  	  VP                  4        \         P                  ! VR4       R#   + '       g   i     EL; i)z/waydroid_base.propzwaydroid_base.prop Not foundNzwaydroid_base.prop is broken!!?c                 s   < SV,          pVR 8w  d4   VP                  RR4      pSP                  V R,           V,           4       R# R# )ZNonez/mnt/z/mnt_extra/Z=N)r,   append)ZkeyZcfg_keyZvaluer&   propss   && r   add_propZmake_prop.<locals>.add_prop   s=    GF?MM'=9ELLsU*+ r   zwaydroid.host.userZ	user_namezwaydroid.host.uidZuser_idzwaydroid.host.gidZgroup_idzwaydroid.host_data_pathZwaydroid_datazwaydroid.background_startZbackground_startzwaydroid.xdg_runtime_dir=Zcontainer_xdg_runtime_dirzwaydroid.pulse_runtime_path=Zcontainer_pulse_runtime_pathzwaydroid.wayland_display=Zcontainer_wayland_displayzwaydroid-sensordzwaydroid.stub_sensors_hal=1Zlcd_densityZ0zro.sf.lcd_density=ZwZ
i  )r   r+   ZisfileworkRuntimeErrorr   ZreadZ
splitlinesr4   r   r   r0   r   ZwriteZcloseZchmod)	r%   r&   Zfull_props_pathr   r6   ZdpiZfinal_propsZpropr5   s	   &f&     @r   	make_propr9      s   77>>$))&;;<<9::	dii//	0	0A##% 
1<==, !;/ ), *-&8(*<=	LL,u||/D/DE`/aab	LL/%,,2G2GHf2ggh	LL,u||/D/DE`/aab (23
m
C
cz)C/0,K$+& HH_e$; 
1	0	0s   (HH(	c                 sV	   \         P                  P                  V 4      p\        P                  P	                  WR ,           \         P                  P
                  R,          RR7       VR,          R,          R8X  d    \        P                  P                  V \         P                  P
                  R,          \         P                  P
                  R,          .\         P                  P
                  R,          \         P                  P
                  R,          R	,           \         P                  P
                  R
,          R	,           R7       \        P                  P	                  WR,           \         P                  P
                  R,          R,           4       VR,          R,          R8X  d   \        P                  P                  V \         P                  P
                  R,          R,           \         P                  P
                  R,          R,           .\         P                  P
                  R,          R,           \         P                  P
                  R,          R,           \         P                  P
                  R
,          R,           R7       R Fp  p\        P                  P                  V4      '       g   K*  \        P                  P                  W\         P                  P
                  R,          V,           4       Kr  	  \        P                  P                  R4      '       dI   \        P                  P                  V R\         P                  P
                  R,          R,           4       Ml\        P                  P                  R4      '       dH   \        P                  P                  V R\         P                  P
                  R,          R,           4       \!        WV P"                  R,           4       \        P                  P%                  W P"                  R,           \         P                  P
                  R,          R,           4       R#   \         dF    RTR,          R&   \         P                  P                  Y4       \        P                  ! R4        ELZi ; i)z/system.imgrootfsT)Zumountr   Zmount_overlaysZTrueZoverlayr-   z/systemr.   )Z	upper_dirZwork_dirZFalsez8Mounting overlays failed. The feature has been disabled.z/vendor.imgz/vendorz/odmz
/odm_extraz/vendor/odmz/waydroid.propz/vendor/waydroid.propN)z/vendor/lib/eglz/vendor/lib64/egl)r   r   r   r    mountr0   Zmount_overlayr8   r#   r   r)   r   r+   r/   ZbindZismountr9   r7   Z	bind_file)r%   Z
images_dirZsessionr&   Zegl_paths   &&&  r   mount_rootfsr<      s    
,,

D
!CMM=8--h7  F
:'(F2		XMM''u||/D/DY/O/4||/D/DX/N/P$)LL$9$9($C.3ll.C.CL.QT].]-2\\-B-B>-RU^-^	 ( ` MM=8 <<00:YFH
:'(F2##D5<<+@+@+Ki+W+0<<+@+@+JY+V+X$)LL$9$9($Ci$O.3ll.C.CL.QT].]-2\\-B-B>-RU^-^	 	$ 	` =77==""MM 5 5h ?( JL = }}V$$&%,,//9LH	J 77==''MMmU\\%:%:8%D|%SU dTYY)99:MMD)).>">!LL11(;>UUW7  	X07C
O,-LLd(OOVW	Xs   >CQ AR('R(c                 s    \         P                  P                  V \        P                  P
                  R ,          4       R# )r:   N)r    r;   Z
umount_allr   r   r0   r2   r3   r   umount_rootfsr=      s%    MMT5<<#8#8#BCr   )r   r   r   r   r1   r   Ztools.configr   r    r   r   r(   r*   r,   r$   r9   r<   r=   ) r   r   <module>r>      sO         	   =~0= %D'WRDr   