From ec64c2b23f52e7fed74cdf76297719c4866c8818 Mon Sep 17 00:00:00 2001
From: Asriel Dreemurr <asriel.danctnix@gmail.com>
Date: Thu, 2 May 2019 09:12:15 +0700
Subject: [PATCH] device-xiaomi-santoni: Added (hacky) udev rule for jack
 detection.

---
 .../90-device-xiaomi-santoni-audio.rules               | 10 +++++++++-
 device/device-xiaomi-santoni/APKBUILD                  |  2 +-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/device/device-xiaomi-santoni/90-device-xiaomi-santoni-audio.rules b/device/device-xiaomi-santoni/90-device-xiaomi-santoni-audio.rules
index eca93584f2b..7e140d4b5bb 100644
--- a/device/device-xiaomi-santoni/90-device-xiaomi-santoni-audio.rules
+++ b/device/device-xiaomi-santoni/90-device-xiaomi-santoni-audio.rules
@@ -1 +1,9 @@
-ATTRS{id}=="msm8920sku7sndc", RUN+="/usr/bin/alsaucm -c msm8920-sku7-snd-card set _verb HiFi set _enadev Headphones"
+# This udev rule is probably a workaround, udev doesn't care about the headphone jack input events :(
+# Perhaps we need a more better workaround, perhaps a daemon for jack detection?
+
+# Init
+ATTRS{id}=="msm8920sku7sndc", RUN+="/usr/bin/alsaucm -c msm8920-sku7-snd-card set _verb HiFi set _enadev Speaker"
+
+# Jack detection
+SUBSYSTEM=="switch",ATTRS{state}=="[1-4]",RUN+="/usr/bin/alsaucm -c msm8920-sku7-snd-card set _verb HiFi set _enadev Headphones"
+SUBSYSTEM=="switch",ATTRS{state}=="0",RUN+="/usr/bin/alsaucm -c msm8920-sku7-snd-card set _verb HiFi set _enadev Speaker"
diff --git a/device/device-xiaomi-santoni/APKBUILD b/device/device-xiaomi-santoni/APKBUILD
index 83039ee3777..a2dd9c3bf3e 100644
--- a/device/device-xiaomi-santoni/APKBUILD
+++ b/device/device-xiaomi-santoni/APKBUILD
@@ -54,7 +54,7 @@ nonfree_firmware() {
 }
 
 sha512sums="4a7ba291c30cc5c05cee60f1d54d026b92b270f6499ceb83111cd5c05fe6c6c8182401abc99a8c10d81f0ee95b1414fd72d0aa7f635226f44b9cf659e3cc3471  deviceinfo
-f2aeed56b4442ba3d02a06fda69bfc90ffb0128488131cbc96cd1e4d0fc5d3c7e4d08478f7af2c8ee4793462e934307d6607cf4cd32e335a9b0db47f7bd1c3c6  90-device-xiaomi-santoni-audio.rules
+9a5cbfe8304aeb266839d77abe892b6534abe3f42d09a07ed4978f3ae79edfe21fdcc6a6a9acad206f0c3f6bc1238d7980d5f7fc8b2bc7f5ab845702ca2e17ca  90-device-xiaomi-santoni-audio.rules
 1d2f98a9570212d3026c9565754337574ae046ad4de90265029b7e4a7cd4a2df473ca18ea41d1730f0a01046b40d343446fc88f5d70a1050e0dc578ad460f941  HiFi
 b634d13cac1f10535a31c142c7391986ab402ae9910d8093989920f4c2dbd63722ee8595f11962bffd9d314e2835a1ead955a91355856f044911ddcf1e428427  fb.modes
 3db3ec596e159be926ea2b5b2496c18e9bc7be24a64a232a56c89a0c9ee710aa2efb2b6fa9fc08efa34759e8242e6c629d08a4ce688ec8aa125830717c191515  directfbrc
-- 
GitLab