# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
-on fs
- wait /dev/block/platform/soc/1da4000.ufshc
- symlink /dev/block/platform/soc/1da4000.ufshc /dev/block/bootdevice
+# encryption support
+on init
chmod 0660 /dev/qseecom
chown system drmrpc /dev/qseecom
chmod 0664 /dev/ion
chown system system /dev/ion
+
+on early-fs
+ start setup-decrypt
+
+on fs
+ wait /dev/block/platform/soc/1da4000.ufshc
+ symlink /dev/block/platform/soc/1da4000.ufshc /dev/block/bootdevice
install_keyring
-# Separate copy needed to use /sbin/linker64 instead of /system/bin/linker64
-service sbinqseecomd /sbin/qseecomd
+on property:ro.crypto.state=encrypted
+ start qseecomd
+
+# use decryption libraries from /system if available
+service setup-decrypt /sbin/setup_decrypt
+ oneshot
+ disabled
+ user root
+ group root
+ seclabel u:r:recovery:s0
+
+# use decryption libraries from /system if available
+service setup-decrypt /sbin/setup_decrypt
+ oneshot
disabled
user root
group root
seclabel u:r:recovery:s0
-on boot
- start sbinqseecomd
--- /dev/null
+#!/sbin/sh
+
+log() {
+ echo "$*"
+ (echo "setup_decrypt: $*" > /dev/kmsg) 2> /dev/null
+}
+
+abort() {
+ log "Error: $*"
+ setprop ro.crypto.using_system_libs 0
+ exit 1
+}
+
+restart_crypto() {
+ crypto_state=$(getprop ro.crypto.state)
+ qsee_state=$(getprop init.svc.qseecomd)
+
+ [ "$qsee_state" = "running" ] && {
+ log "Stopping qseecomd"
+ stop qseecomd
+ }
+ [ "$crypto_state" = "encrypted" ] && {
+ log "Starting qseecomd"
+ start qseecomd
+ }
+}
+
+mountpoint -q /system || {
+ mkdir -p /system
+ log "Mounting /system read-only"
+ mount -t ext4 -o ro /dev/block/bootdevice/by-name/system /system
+}
+mountpoint -q /system || abort "Could not mount /system for crypto libs!"
+
+bin=/system/bin
+lib=/system/vendor/lib64
+hw=$lib/hw
+
+ready=true
+
+for f in \
+ "$bin/qseecomd" \
+ "$hw/keystore.msm8998.so" \
+ "$lib/libQSEEComAPI.so" \
+ "$lib/libdiag.so" \
+ "$lib/libdrmfs.so" \
+ "$lib/libdrmtime.so" \
+ "$lib/librpmb.so" \
+ "$lib/libssd.so" \
+ "$lib/libtime_genoff.so"
+do
+ [ -f "$f" ] && continue
+
+ log "Could not find crypto file: $f"
+ ready=false
+done
+
+$ready || abort "Missing one or more decryption libraries!"
+
+mkdir -p /vendor/lib64/hw/
+
+log "Copying decryption libraries from /system"
+cp -f \
+ "$bin/qseecomd" \
+ "$hw/keystore.msm8998.so" \
+ "$lib/libQSEEComAPI.so" \
+ "$lib/libdiag.so" \
+ "$lib/libdrmfs.so" \
+ "$lib/libdrmtime.so" \
+ "$lib/librpmb.so" \
+ "$lib/libssd.so" \
+ "$lib/libtime_genoff.so" \
+ /sbin/
+
+cp -f "$hw/keystore.msm8998.so" /vendor/lib64/hw/
+cp -f "$lib/libQSEEComAPI.so" /vendor/lib64/
+
+chmod 0750 /sbin/qseecomd
+
+# we have to link qseecomd to /sbin/linker64 because /system is unmounted when it starts
+sed -i "s|/system/bin/linker|///////sbin/linker|" /sbin/qseecomd
+
+setprop ro.crypto.using_system_libs 1
+
+log "Using system decryption libraries!"
+
+restart_crypto
+
+exit 0