#!/system/bin/sh

EXPECTED_DEVICE=ross
EXPECTED_INCREMENTAL=250926144031
DEVICE="$(getprop ro.product.device)"
INCREMENTAL="$(getprop ro.build.version.incremental)"

if [ "$DEVICE" != "$EXPECTED_DEVICE" ] || [ "$INCREMENTAL" != "$EXPECTED_INCREMENTAL" ]; then
  echo "PROFILE_MISMATCH device=$DEVICE incremental=$INCREMENTAL" >&2
  exit 90
fi

/vendor/bin/PQ_ctrl -L 0 >/dev/null 2>&1 || true
setprop vendor.rtk.video.pq.dlsr 0
setprop persist.vendor.rtk.sd.aisr 0

cmd hdmi_control cec_setting set volume_control_enabled 1 >/dev/null 2>&1 || true
settings put global hdmi_control_volume_control_enabled 1

pm enable com.google.android.katniss >/dev/null 2>&1 || true
pm enable com.google.android.tts >/dev/null 2>&1 || true
settings put secure voice_interaction_service \
  com.google.android.katniss/.search.serviceapi.KatnissVoiceInteractionService
settings put secure assistant \
  com.google.android.katniss/.search.serviceapi.KatnissVoiceInteractionService
settings put secure tts_default_synth com.google.android.tts

settings put global device_name 'NEXON X11 STESH(A)TV'

MODIFIER_UID="$(cmd package list packages -U info.technozon.steshmodifier 2>/dev/null | sed -n 's/.*uid://p' | head -n 1)"
MAGISK="$(command -v magisk 2>/dev/null)"
[ -n "$MAGISK" ] || MAGISK=/debug_ramdisk/magisk
if [ -n "$MODIFIER_UID" ] && [ -x "$MAGISK" ]; then
  "$MAGISK" --sqlite "DELETE FROM policies WHERE uid=$MODIFIER_UID;" >/dev/null 2>&1 || true
  "$MAGISK" --sqlite "INSERT INTO policies (uid,policy,until,logging,notification) VALUES($MODIFIER_UID,2,0,1,0);" >/dev/null 2>&1 || true
fi

echo "PROFILE_OK"
echo "device=$DEVICE"
echo "incremental=$INCREMENTAL"
echo "aisr=$(getprop vendor.rtk.video.pq.dlsr)"
echo "voice=$(settings get secure voice_interaction_service)"
echo "tts=$(settings get secure tts_default_synth)"
echo "modifier_uid=$MODIFIER_UID"
