Plugins: Adapt to our settings [2/4]

Make sure Volume panel on left setting is followed
Use Settings observer instead of tuner
Only use settings that work per volume panel
Signed-off-by: Varun Date <date.varun123@gmail.com>
diff --git a/AospPanel/Android.bp b/AospPanel/Android.bp
index ba3da0b..8cd2edf 100644
--- a/AospPanel/Android.bp
+++ b/AospPanel/Android.bp
@@ -4,6 +4,7 @@
 
     static_libs: [
         "VolumePluginCommon",
+        "org.lineageos.platform.internal",
     ],
 
     resource_dirs: ["res"],
diff --git a/AospPanel/src/co/potatoproject/plugin/volume/aosp/VolumeDialogImpl.java b/AospPanel/src/co/potatoproject/plugin/volume/aosp/VolumeDialogImpl.java
index 5b57d95..bad5b0e 100644
--- a/AospPanel/src/co/potatoproject/plugin/volume/aosp/VolumeDialogImpl.java
+++ b/AospPanel/src/co/potatoproject/plugin/volume/aosp/VolumeDialogImpl.java
@@ -34,6 +34,8 @@
 
 import static co.potatoproject.plugin.volume.common.Events.DISMISS_REASON_SETTINGS_CLICKED;
 
+import android.database.ContentObserver;
+import android.os.UserHandle;
 import android.animation.ObjectAnimator;
 import android.annotation.SuppressLint;
 import android.app.ActivityManager;
@@ -95,7 +97,7 @@
 import android.widget.SeekBar.OnSeekBarChangeListener;
 import android.widget.TextView;
 import android.widget.Toast;
-
+import lineageos.providers.LineageSettings;
 import co.potatoproject.plugin.volume.common.*;
 
 import co.potatoproject.plugin.volume.aosp.R;
@@ -187,6 +189,16 @@
 
     private boolean mLeftVolumeRocker;
 
+    private boolean mVolumePanelOnLeft;
+    private SettingsObserver settingsObserver;
+    private boolean isMediaShowing = true;
+    private boolean isRingerShowing = false;
+    private boolean isNotificationShowing = false;
+    private boolean isAlarmShowing = false;
+    private boolean isVoiceShowing = false;
+    private boolean isBTSCOShowing = false;
+    private int mTimeout;
+
     public VolumeDialogImpl() {}
 
     @Override
@@ -203,6 +215,8 @@
         mHasSeenODICaptionsTooltip =
                 Prefs.getBoolean(sysuiContext, Prefs.Key.HAS_SEEN_ODI_CAPTIONS_TOOLTIP, false);
         mLeftVolumeRocker = mSysUIContext.getResources().getBoolean(mSysUIR.bool("config_audioPanelOnLeftSide"));
+        settingsObserver = new SettingsObserver(mHandler);
+        settingsObserver.observe();
     }
 
     public void init(int windowType, Callback callback) {
@@ -218,6 +232,7 @@
     public void destroy() {
         mController.removeCallback(mControllerCallbackH);
         mHandler.removeCallbacksAndMessages(null);
+        settingsObserver.unobserve();
     }
 
     private void initDialog() {
@@ -277,6 +292,7 @@
         if (mRinger != null) {
             mRingerIcon = mRinger.findViewById(R.id.ringer_icon);
             mZenIcon = mRinger.findViewById(R.id.dnd_icon);
+            mRinger.setVisibility(isRingerShowing ? View.VISIBLE : View.GONE);
         }
 
         mODICaptionsView = mDialog.findViewById(R.id.odi_captions);
@@ -362,6 +378,42 @@
         initRingerH();
         initSettingsH();
         initODICaptionsH();
+
+    }
+
+
+    private class SettingsObserver extends ContentObserver {
+        SettingsObserver(Handler handler) {
+            super(handler);
+        }
+
+        void unobserve() {
+            mContext.getContentResolver().unregisterContentObserver(this);
+        }
+
+        void observe() {
+            mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.AUDIO_PANEL_VIEW_VOICE), false, this, UserHandle.USER_ALL);
+            mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.AUDIO_PANEL_VIEW_BT_SCO), false, this, UserHandle.USER_ALL);
+            mContext.getContentResolver().registerContentObserver(LineageSettings.Secure.getUriFor(LineageSettings.Secure.VOLUME_PANEL_ON_LEFT), false, this, UserHandle.USER_ALL);
+            mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.SHOW_RINGER_VOLUME_PANEL), false, this, UserHandle.USER_ALL);
+            mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.AUDIO_PANEL_VIEW_TIMEOUT), false, this, UserHandle.USER_ALL);
+            update();
+        }
+
+        @Override
+        public void onChange(boolean selfChange) {
+            update();
+            initDialog();
+        }
+
+        public void update() {
+             isVoiceShowing = Settings.System.getIntForUser(mContext.getContentResolver(), Settings.System.AUDIO_PANEL_VIEW_VOICE, 0, UserHandle.USER_CURRENT) == 1;
+             isBTSCOShowing = Settings.System.getIntForUser(mContext.getContentResolver(), Settings.System.AUDIO_PANEL_VIEW_BT_SCO, 0, UserHandle.USER_CURRENT) == 1;
+             isRingerShowing = Settings.System.getIntForUser(mContext.getContentResolver(), Settings.System.SHOW_RINGER_VOLUME_PANEL, 1, UserHandle.USER_CURRENT) == 1;
+             mTimeout = Settings.System.getIntForUser(mContext.getContentResolver(), Settings.System.AUDIO_PANEL_VIEW_TIMEOUT, 3, UserHandle.USER_CURRENT) * 1000;
+             mVolumePanelOnLeft = LineageSettings.Secure.getIntForUser(mContext.getContentResolver(), LineageSettings.Secure.VOLUME_PANEL_ON_LEFT, 0, UserHandle.USER_CURRENT) == 0;
+            // updateRowsH(getActiveRow());
+        }
     }
 
     private final OnComputeInternalInsetsListener mInsetsListener = internalInsetsInfo -> {
@@ -887,8 +939,7 @@
                     AccessibilityManager.FLAG_CONTENT_TEXT
                             | AccessibilityManager.FLAG_CONTENT_CONTROLS);
         }
-        return mAccessibilityMgr.getRecommendedTimeoutMillis(DIALOG_TIMEOUT_MILLIS,
-                AccessibilityManager.FLAG_CONTENT_CONTROLS);
+        return mTimeout;
     }
 
     protected void dismissH(int reason) {
@@ -941,6 +992,13 @@
     }
 
     private boolean shouldBeVisibleH(VolumeRow row, VolumeRow activeRow) {
+        if(row.stream == AudioManager.STREAM_VOICE_CALL && isVoiceShowing){
+            return true;
+        }
+        if(row.stream == AudioManager.STREAM_BLUETOOTH_SCO && isBTSCOShowing){
+            return true;
+        }
+
         boolean isActive = row.stream == activeRow.stream;
 
         if (isActive) {
@@ -1593,7 +1651,7 @@
     }
 
     private boolean isAudioPanelOnLeftSide() {
-        return mLeftVolumeRocker;
+        return !mVolumePanelOnLeft;
     }
 
     private static class VolumeRow {
diff --git a/CompactPanel/Android.bp b/CompactPanel/Android.bp
index 9b11fca..2fc1cfe 100644
--- a/CompactPanel/Android.bp
+++ b/CompactPanel/Android.bp
@@ -2,7 +2,10 @@
 
     name: "CompactPanel",
 
-    static_libs: ["VolumePluginCommon"],
+    static_libs: [
+        "VolumePluginCommon",
+        "org.lineageos.platform.internal",
+    ],
 
     resource_dirs: ["res"],
 
diff --git a/CompactPanel/src/co/potatoproject/plugin/volume/compact/VolumeDialogImpl.java b/CompactPanel/src/co/potatoproject/plugin/volume/compact/VolumeDialogImpl.java
index 044e950..ddab6ab 100644
--- a/CompactPanel/src/co/potatoproject/plugin/volume/compact/VolumeDialogImpl.java
+++ b/CompactPanel/src/co/potatoproject/plugin/volume/compact/VolumeDialogImpl.java
@@ -32,7 +32,8 @@
 import static android.view.View.VISIBLE;
 
 import static co.potatoproject.plugin.volume.common.Events.DISMISS_REASON_SETTINGS_CLICKED;
-
+import android.database.ContentObserver;
+import android.os.UserHandle;
 import android.animation.ObjectAnimator;
 import android.annotation.SuppressLint;
 import android.app.ActivityManager;
@@ -107,7 +108,7 @@
 import com.android.systemui.plugins.VolumeDialogController.State;
 import com.android.systemui.plugins.VolumeDialogController.StreamState;
 import com.android.systemui.plugins.annotations.Requires;
-
+import lineageos.providers.LineageSettings;
 import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.List;
@@ -188,7 +189,15 @@
 
     private boolean mLeftVolumeRocker;
     private PanelMode mPanelMode = PanelMode.MINI;
-
+    private boolean mVolumePanelOnLeft;
+    private SettingsObserver settingsObserver;
+    private boolean isMediaShowing = true;
+    private boolean isRingerShowing = false;
+    private boolean isNotificationShowing = false;
+    private boolean isAlarmShowing = false;
+    private boolean isVoiceShowing = false;
+    private boolean isBTSCOShowing = false;
+    private int mTimeout;
     public VolumeDialogImpl() {}
 
     @Override
@@ -205,6 +214,8 @@
         mHasSeenODICaptionsTooltip =
                 Prefs.getBoolean(sysuiContext, Prefs.Key.HAS_SEEN_ODI_CAPTIONS_TOOLTIP, false);
         mLeftVolumeRocker = mSysUIContext.getResources().getBoolean(mSysUIR.bool("config_audioPanelOnLeftSide"));
+        settingsObserver = new SettingsObserver(mHandler);
+        settingsObserver.observe();
     }
 
     @Override
@@ -222,6 +233,7 @@
     public void destroy() {
         mController.removeCallback(mControllerCallbackH);
         mHandler.removeCallbacksAndMessages(null);
+        settingsObserver.unobserve();
     }
 
     private void initDialog() {
@@ -280,6 +292,7 @@
         if (mRinger != null) {
             mRingerIcon = mRinger.findViewById(R.id.ringer_icon);
             mZenIcon = mRinger.findViewById(R.id.dnd_icon);
+            mRinger.setVisibility(isRingerShowing ? View.VISIBLE : View.GONE);
         }
 
         mButtonsGroup = mDialog.findViewById(R.id.buttons_group);
@@ -365,6 +378,40 @@
         initODICaptionsH();
     }
 
+    private class SettingsObserver extends ContentObserver {
+        SettingsObserver(Handler handler) {
+            super(handler);
+        }
+
+        void unobserve() {
+            mContext.getContentResolver().unregisterContentObserver(this);
+        }
+
+        void observe() {
+            mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.AUDIO_PANEL_VIEW_VOICE), false, this, UserHandle.USER_ALL);
+            mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.AUDIO_PANEL_VIEW_BT_SCO), false, this, UserHandle.USER_ALL);
+            mContext.getContentResolver().registerContentObserver(LineageSettings.Secure.getUriFor(LineageSettings.Secure.VOLUME_PANEL_ON_LEFT), false, this, UserHandle.USER_ALL);
+            mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.SHOW_RINGER_VOLUME_PANEL), false, this, UserHandle.USER_ALL);
+            mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.AUDIO_PANEL_VIEW_TIMEOUT), false, this, UserHandle.USER_ALL);
+            update();
+        }
+
+        @Override
+        public void onChange(boolean selfChange) {
+            update();
+            initDialog();
+        }
+
+        public void update() {
+             isVoiceShowing = Settings.System.getIntForUser(mContext.getContentResolver(), Settings.System.AUDIO_PANEL_VIEW_VOICE, 0, UserHandle.USER_CURRENT) == 1;
+             isBTSCOShowing = Settings.System.getIntForUser(mContext.getContentResolver(), Settings.System.AUDIO_PANEL_VIEW_BT_SCO, 0, UserHandle.USER_CURRENT) == 1;
+             isRingerShowing = Settings.System.getIntForUser(mContext.getContentResolver(), Settings.System.SHOW_RINGER_VOLUME_PANEL, 1, UserHandle.USER_CURRENT) == 1;
+             mTimeout = Settings.System.getIntForUser(mContext.getContentResolver(), Settings.System.AUDIO_PANEL_VIEW_TIMEOUT, 3, UserHandle.USER_CURRENT) * 1000;
+             mVolumePanelOnLeft = LineageSettings.Secure.getIntForUser(mContext.getContentResolver(), LineageSettings.Secure.VOLUME_PANEL_ON_LEFT, 0, UserHandle.USER_CURRENT) == 0;
+            // updateRowsH(getActiveRow());
+        }
+    }
+
     private final OnComputeInternalInsetsListener mInsetsListener = internalInsetsInfo -> {
         internalInsetsInfo.touchableRegion.setEmpty();
         internalInsetsInfo.setTouchableInsets(InternalInsetsInfo.TOUCHABLE_INSETS_REGION);
@@ -959,8 +1006,7 @@
                     AccessibilityManager.FLAG_CONTENT_TEXT
                             | AccessibilityManager.FLAG_CONTENT_CONTROLS);
         }
-        return mAccessibilityMgr.getRecommendedTimeoutMillis(DIALOG_TIMEOUT_MILLIS,
-                AccessibilityManager.FLAG_CONTENT_CONTROLS);
+        return mTimeout;
     }
 
     protected void dismissH(int reason) {
@@ -1018,6 +1064,14 @@
     }
 
     private boolean shouldBeVisibleH(VolumeRow row, VolumeRow activeRow) {
+
+        if(row.stream == AudioManager.STREAM_VOICE_CALL && isVoiceShowing){
+            return true;
+        }
+        if(row.stream == AudioManager.STREAM_BLUETOOTH_SCO && isBTSCOShowing){
+            return true;
+        }
+
         boolean isActive = row.stream == activeRow.stream;
 
         if (isActive) {
@@ -1674,7 +1728,7 @@
     }
 
     private boolean isAudioPanelOnLeftSide() {
-        return mLeftVolumeRocker;
+        return !mVolumePanelOnLeft;
     }
 
     private static class VolumeRow {
diff --git a/OreoPanel/src/co/potatoproject/plugin/volume/oreo/VolumeDialogImpl.java b/OreoPanel/src/co/potatoproject/plugin/volume/oreo/VolumeDialogImpl.java
index 332a907..a34c55f 100644
--- a/OreoPanel/src/co/potatoproject/plugin/volume/oreo/VolumeDialogImpl.java
+++ b/OreoPanel/src/co/potatoproject/plugin/volume/oreo/VolumeDialogImpl.java
@@ -24,6 +24,8 @@
 import static android.media.AudioManager.RINGER_MODE_VIBRATE;
 import static android.view.View.ACCESSIBILITY_LIVE_REGION_POLITE;
 
+import android.database.ContentObserver;
+import android.os.UserHandle;
 import android.accessibilityservice.AccessibilityServiceInfo;
 import android.animation.ObjectAnimator;
 import android.annotation.NonNull;
@@ -169,6 +171,15 @@
     private boolean mHovering = false;
     private int mDensity;
 
+    private SettingsObserver settingsObserver;
+    private boolean isMediaShowing = true;
+    private boolean isRingerShowing = false;
+    private boolean isNotificationShowing = false;
+    private boolean isAlarmShowing = false;
+    private boolean isVoiceShowing = false;
+    private boolean isBTSCOShowing = false;
+    private int mTimeout;
+
     public VolumeDialogImpl() {}
 
     @Override
@@ -182,6 +193,8 @@
         mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
         mAccessibilityMgr =
                 (AccessibilityManager) mContext.getSystemService(Context.ACCESSIBILITY_SERVICE);
+        settingsObserver = new SettingsObserver(mHandler);
+        settingsObserver.observe();
     }
 
     public void init(int windowType, Callback callback) {
@@ -204,6 +217,7 @@
         mAccessibility.destroy();
         mController.removeCallback(mControllerCallbackH);
         mHandler.removeCallbacksAndMessages(null);
+        settingsObserver.unobserve();
     }
 
     private void initDialog() {
@@ -260,6 +274,7 @@
         if (mRinger != null) {
             mRingerIcon = mRinger.findViewById(R.id.ringer_icon);
             mZenIcon = mRinger.findViewById(R.id.dnd_icon);
+            mRinger.setVisibility(isRingerShowing ? View.VISIBLE : View.GONE);
         }
         mExpanded = false;
         mExpandButton = (ExpandableIndicator) mDialogView.findViewById(R.id.volume_expand_button);
@@ -310,6 +325,38 @@
         mExpandButtonAnimationDuration = 300;
         initRingerH();
     }
+
+    private class SettingsObserver extends ContentObserver {
+        SettingsObserver(Handler handler) {
+            super(handler);
+        }
+
+        void unobserve() {
+            mContext.getContentResolver().unregisterContentObserver(this);
+        }
+
+        void observe() {
+            mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.AUDIO_PANEL_VIEW_VOICE), false, this, UserHandle.USER_ALL);
+            mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.AUDIO_PANEL_VIEW_BT_SCO), false, this, UserHandle.USER_ALL);
+            mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.SHOW_RINGER_VOLUME_PANEL), false, this, UserHandle.USER_ALL);
+            mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.AUDIO_PANEL_VIEW_TIMEOUT), false, this, UserHandle.USER_ALL);
+            update();
+        }
+
+        @Override
+        public void onChange(boolean selfChange) {
+            update();
+            initDialog();
+        }
+
+        public void update() {
+             isVoiceShowing = Settings.System.getIntForUser(mContext.getContentResolver(), Settings.System.AUDIO_PANEL_VIEW_VOICE, 0, UserHandle.USER_CURRENT) == 1;
+             isBTSCOShowing = Settings.System.getIntForUser(mContext.getContentResolver(), Settings.System.AUDIO_PANEL_VIEW_BT_SCO, 0, UserHandle.USER_CURRENT) == 1;
+             isRingerShowing = Settings.System.getIntForUser(mContext.getContentResolver(), Settings.System.SHOW_RINGER_VOLUME_PANEL, 1, UserHandle.USER_CURRENT) == 1;
+             mTimeout = Settings.System.getIntForUser(mContext.getContentResolver(), Settings.System.AUDIO_PANEL_VIEW_TIMEOUT, 3, UserHandle.USER_CURRENT) * 1000;
+            // updateRowsH(getActiveRow());
+        }
+    }
     
     private final OnComputeInternalInsetsListener mInsetsListener = internalInsetsInfo -> {
         internalInsetsInfo.touchableRegion.setEmpty();
@@ -517,7 +564,7 @@
 
     protected void rescheduleTimeoutH() {
         mHandler.removeMessages(H.DISMISS);
-        final int timeout = computeTimeoutH();
+        final int timeout = mTimeout;
         mHandler.sendMessageDelayed(mHandler
                 .obtainMessage(H.DISMISS, Events.DISMISS_REASON_TIMEOUT, 0), timeout);
         if (D.BUG) Log.d(TAG, "rescheduleTimeout " + timeout + " " + Debug.getCaller());
@@ -530,7 +577,7 @@
         if (mSafetyWarning != null) return 5000;
         if (mExpanded || mExpandButtonAnimationRunning) return 5000;
         if (mActiveStream == AudioManager.STREAM_MUSIC) return 1500;
-        return 3000;
+        return mTimeout;
     }
 
     protected void dismissH(int reason) {
@@ -811,6 +858,14 @@
     }
 
     private boolean shouldBeVisibleH(VolumeRow row, VolumeRow activeRow) {
+
+        if(row.stream == AudioManager.STREAM_VOICE_CALL && isVoiceShowing){
+            return true;
+        }
+        if(row.stream == AudioManager.STREAM_BLUETOOTH_SCO && isBTSCOShowing){
+            return true;
+        }
+
         boolean isActive = row == activeRow;
         if (row.stream == AudioSystem.STREAM_ACCESSIBILITY) {
             return mShowA11yStream;
diff --git a/TiledPanel/Android.bp b/TiledPanel/Android.bp
index e1fe9e4..7b63528 100644
--- a/TiledPanel/Android.bp
+++ b/TiledPanel/Android.bp
@@ -2,7 +2,10 @@
 
     name: "TiledPanel",
 
-    static_libs: ["VolumePluginCommon"],
+    static_libs: [
+        "VolumePluginCommon",
+        "org.lineageos.platform.internal",
+    ],
 
     resource_dirs: ["res"],
 
diff --git a/TiledPanel/src/co/potatoproject/plugin/volume/tiled/VolumeDialogImpl.java b/TiledPanel/src/co/potatoproject/plugin/volume/tiled/VolumeDialogImpl.java
index 9deff63..2cfdbd4 100644
--- a/TiledPanel/src/co/potatoproject/plugin/volume/tiled/VolumeDialogImpl.java
+++ b/TiledPanel/src/co/potatoproject/plugin/volume/tiled/VolumeDialogImpl.java
@@ -33,7 +33,8 @@
 import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
 
 import static co.potatoproject.plugin.volume.common.Events.DISMISS_REASON_SETTINGS_CLICKED;
-
+import android.database.ContentObserver;
+import android.os.UserHandle;
 import android.animation.ObjectAnimator;
 import android.annotation.SuppressLint;
 import android.app.ActivityManager;
@@ -99,7 +100,7 @@
 import android.widget.SeekBar.OnSeekBarChangeListener;
 import android.widget.TextView;
 import android.widget.Toast;
-
+import lineageos.providers.LineageSettings;
 import co.potatoproject.plugin.volume.common.*;
 
 import co.potatoproject.plugin.volume.tiled.R;
@@ -193,6 +194,16 @@
     private Drawable mSwitchStreamSelectedDrawable;
     private boolean mActiveStreamManuallyModified = false;
 
+    private boolean mVolumePanelOnLeft;
+    private SettingsObserver settingsObserver;
+    private boolean isMediaShowing = true;
+    private boolean isRingerShowing = false;
+    private boolean isNotificationShowing = false;
+    private boolean isAlarmShowing = false;
+    private boolean isVoiceShowing = false;
+    private boolean isBTSCOShowing = false;
+    private int mTimeout;
+
     public VolumeDialogImpl() {}
 
     @Override
@@ -209,6 +220,8 @@
         mHasSeenODICaptionsTooltip =
                 Prefs.getBoolean(sysuiContext, Prefs.Key.HAS_SEEN_ODI_CAPTIONS_TOOLTIP, false);
         mLeftVolumeRocker = mSysUIContext.getResources().getBoolean(mSysUIR.bool("config_audioPanelOnLeftSide"));
+        settingsObserver = new SettingsObserver(mHandler);
+        settingsObserver.observe();
     }
 
     public void init(int windowType, Callback callback) {
@@ -224,6 +237,7 @@
     public void destroy() {
         mController.removeCallback(mControllerCallbackH);
         mHandler.removeCallbacksAndMessages(null);
+        settingsObserver.unobserve();
     }
 
     private void initDialog() {
@@ -291,6 +305,7 @@
         if (mRinger != null) {
             mRingerIcon = mRinger.findViewById(R.id.ringer_icon);
             mZenIcon = mRinger.findViewById(R.id.dnd_icon);
+            mRinger.setVisibility(isRingerShowing ? View.VISIBLE : View.GONE);
         }
 
         if(mOutputSwitcher != null)
@@ -359,7 +374,37 @@
         initRingerH();
         initODICaptionsH();
     }
-    
+
+    private class SettingsObserver extends ContentObserver {
+        SettingsObserver(Handler handler) {
+            super(handler);
+        }
+
+        void unobserve() {
+            mContext.getContentResolver().unregisterContentObserver(this);
+        }
+
+        void observe() {
+            mContext.getContentResolver().registerContentObserver(LineageSettings.Secure.getUriFor(LineageSettings.Secure.VOLUME_PANEL_ON_LEFT), false, this, UserHandle.USER_ALL);
+            mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.SHOW_RINGER_VOLUME_PANEL), false, this, UserHandle.USER_ALL);
+            mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.AUDIO_PANEL_VIEW_TIMEOUT), false, this, UserHandle.USER_ALL);
+            update();
+        }
+
+        @Override
+        public void onChange(boolean selfChange) {
+            update();
+            initDialog();
+        }
+
+        public void update() {
+             mTimeout = Settings.System.getIntForUser(mContext.getContentResolver(), Settings.System.AUDIO_PANEL_VIEW_TIMEOUT, 3, UserHandle.USER_CURRENT) * 1000;
+             mVolumePanelOnLeft = LineageSettings.Secure.getIntForUser(mContext.getContentResolver(), LineageSettings.Secure.VOLUME_PANEL_ON_LEFT, 0, UserHandle.USER_CURRENT) == 0;
+             isRingerShowing = Settings.System.getIntForUser(mContext.getContentResolver(), Settings.System.SHOW_RINGER_VOLUME_PANEL, 1, UserHandle.USER_CURRENT) == 1;
+            // updateRowsH(getActiveRow());
+        }
+    }
+
     private final OnComputeInternalInsetsListener mInsetsListener = internalInsetsInfo -> {
         internalInsetsInfo.touchableRegion.setEmpty();
         internalInsetsInfo.setTouchableInsets(InternalInsetsInfo.TOUCHABLE_INSETS_REGION);
@@ -980,8 +1025,7 @@
                     AccessibilityManager.FLAG_CONTENT_TEXT
                             | AccessibilityManager.FLAG_CONTENT_CONTROLS);
         }
-        return mAccessibilityMgr.getRecommendedTimeoutMillis(DIALOG_TIMEOUT_MILLIS,
-                AccessibilityManager.FLAG_CONTENT_CONTROLS);
+        return mTimeout;
     }
 
     protected void dismissH(int reason) {
@@ -1028,6 +1072,13 @@
     }
 
     private boolean shouldBeVisibleH(VolumeRow row, VolumeRow activeRow) {
+
+        if(row.stream == AudioManager.STREAM_VOICE_CALL && isVoiceShowing){
+            return true;
+        }
+        if(row.stream == AudioManager.STREAM_BLUETOOTH_SCO && isBTSCOShowing){
+            return true;
+        }
         boolean isActive = row.stream == activeRow.stream;
 
         if (isActive) {
@@ -1698,7 +1749,7 @@
     }
 
     private boolean isAudioPanelOnLeftSide() {
-        return mLeftVolumeRocker;
+        return !mVolumePanelOnLeft;
     }
 
     private static class VolumeRow {